atmega16/8 ADC-USART C code

Status
Not open for further replies.

decapitary

Banned
Joined
Jul 16, 2014
Messages
62
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Visit site
Activity points
0
i need a c file to program my micro for A2D. I have 1 analog input and just ONE serial output please help me Fast
 

Hi,
There are example codes in the avr datasheet and a huge ammount of threads in the forum and the internet.

If you need something special, then you need to specify it.

Asking for fast help, but giving no details is resulting in no answers..

Klaus
 


I need something like this but it has to send serial data to just 1 output! i want to connect it to opto-coupler and then to PC (USB) .can u change the output to USART output PortB pin0?

Code:
#define F_CPU 16000000UL
#include <util/delay.h>
#include <avr/io.h>

int main(void)
{
DDRA=0;
//Declaring Port A as input
   
DDRB=255;
//Declaring port B as output
   
ADCSRA|=(1<<ADEN)|(1<<ADPS2) |(1<<ADPS1) |(1<<ADPS0);
// Enabled ADC and set prescaler division factor as 128
    ADMUX|=(0<<REFS1)|(1<<REFS0)|(0<<MUX4)|(0<<MUX3)|(0<<MUX2)|(0<<MUX1)|(0<<MUX0)|(1<<ADLAR);
/*Vref is same as Vcc, Input constantly at Pin 0 of port A and Setting ADLAR to 1 left shifts the bits for an 8-bit precision*/
   
    while(1)   
   {
       ADCSRA|=(1<<ADSC);
       //Start ADC
       
       while((ADCSRA& (1<<6))!=0);
     /*Do nothing till the conversion is over. Here,          the condition that ADSC is cleared after conversion has been used. You can also use ADIF*/
       
       PORTB = ADCH;
 /*The ADC value stored in ADCH has been sent to PORT B as output.*/
       
        _delay_ms(100);
   };
}
 
Last edited by a moderator:

How can I Connect my analog input to ATMEGA8 -> 6n137 -> USB

I programmed A atmega8(ADC,USART) to send my EKG/ECG analog input into my PC to process.Do You Have any Idea how should I connect AVR and optocoupler Pins? For example Should I connect a RC circuit for RESET pin? how i should connect my Analog into Atmega8 pin? Which pins need +5 and which for GND? Help me PLease
 

Hi,

again:
Asking for fast help, but giving no details is resulting in no answers..

Do You Have any Idea how should I connect AVR and optocoupler Pins?
google for "atmega uart optocoupler"
then decide what else you want to know.

Should I connect a RC circuit for RESET pin?
look into datasheet

how i should connect my Analog into Atmega8 pin?
We do not know:
* what is your analog signal: Source, voltage, frequency...

Which pins need +5 and which for GND?
of what device?

Klaus
 

EKG signal of MY device.I GooGled it but there is no such thing.No data on datasheet that used ADC and USART together to an optocoupler then to USB
 

The ECG signal can be connected to AVR-ADC after being amplified to 5V. I presume you have a suitable preamplifier.

Connecting "UART to optocoupler then to USB" is less clear. You need an USB interface chip like FT232 to connect UART to USB, maybe with optical isolation by an optocoupler.
 

my signal amplified by 2 instrumental amps. Look at his work.I want something like this
PHP:
people.ece.cornell.edu/land/courses/ece4760/FinalProjects/s2012/cwm55/cwm55_mj294/
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…