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 / Topics / avr adc reading to 7 segment

avr adc reading to 7 segment

|

Microcontroller › AVR › avr adc reading to 7 segment

  • This topic has 1 reply, 2 voices, and was last updated 13 years, 7 months ago by srinu.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • November 10, 2011 at 10:23 am #1391
    udgish patel
    Participant

    hi all i am new at atmega i need to help in c code how to display adc reading in 7segment

     

    i hav LVDt sensor and i hav adc voltage span of 2v

     i hav scale 0 to 100kg load can any buddy help me in start coding.

    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);
     
    }
     
    }
     
  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • What is correct names for GOOD user friendly circuit drawing program? June 18, 2025
  • Curved lines in PCB design June 18, 2025
  • using a RTC in SF basic June 18, 2025
  • Is AI making embedded software developers more productive? June 18, 2025
  • Why can't I breadboard this oscillator? June 18, 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