EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Replies /  hi….udgisham give u one

 hi….udgisham give u one

|

Microcontroller › AVR › avr adc reading to 7 segment ›  hi….udgisham give u one

November 16, 2011 at 6:10 am #6841
srinu
Participant

 

hi….udgish
am give u one adc code.. 
but it is in atmega8.
 
in this project am sending AADC values to UART…..
 
i hope u  undstd this code………
 
 
 
 
#define F_CPU 8000000UL
#include<avr/io.h>
#include<util/delay.h>
 
#include “lcd.h”
 
 
/*************************************************************
********** adc init                                     ******
*************************************************************/
 
void InitADC()
{
ADMUX=(1<<REFS0);
ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
 
}
 
/************************************************
**** READING ADC BITS  ***
************************************************/
 
uint16_t ReadADC(uint8_t ch)
{
ch=ch&0b00000111;
ADMUX =ch | (1<<REFS0);
ADCSRA|=(1<<ADSC);
while(!(ADCSRA & (1<<ADIF)));
ADCSRA|=(1<<ADIF);
return(ADC);
}
/****************************************************
***** UART*******************************************
****************************************************/
 
void uart_init()
{
// SETTING BIT PARITY (8BIT OR 9 BIT)
UCSRC=(1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0); //8 BIT
 
 //FOR TX AND RX
UCSRB=(1<<RXEN)|(1<<TXEN);// ENABLING TX,RX.  
 
UBRRL=0x33; // baud rate(51 for 9600)
}
 
void tx_data(unsigned char c)
{
//SENDING DATA;
UDR=c;
while(!(UCSRA & (1<<TXC)));  //set the TX flag
//clear the TX flag
UCSRA=(1<<TXC);
}
 
unsigned char rx_data()
{
 
// Wait for data to be received 
while ( !(UCSRA & (1<<RXC)) ); // set the rx flag
UCSRA=(0<<RXC);// CLEAR THE rx flag
/* Get and return received data from buffer */
return UDR;
}
 
 
 
void Tx_String(unsigned char *str)
{
while(*str)
{
tx_data(*str);
str++;
}
 
}
/*******************************************************
**MAIN PROGRAM ** ** ** ** ** ** ** ** ** ** *
********************************************************/
 
void main()
{
int adc_result0;
uart_init();
InitADC();
InitLCD(LS_BLINK|LS_ULINE);
LCDWriteStringXY(0,0,”adc_test”);
while(1)
{
_delay_ms(1000);
ReadADC(0);
   adc_result0=ReadADC(0);
 
LCDWriteIntXY(0,1,adc_result0,4);
tx_data(adc_result0);
 
}
 
}
 

RSS Recent Posts

  • WTB: "The Theory Of Servicing AM, FM, And FM Receivers" by Clarence R. Green and Robert M. Bourque November 10, 2025
  • Anyone In The US Ordered From AliExpress Recently? November 10, 2025
  • Calculation of A Class amplifier November 10, 2025
  • strange laptop problem November 10, 2025
  • restarting this Christmas project November 10, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise