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 / ADC interface with atmega32 with eight different sensors

ADC interface with atmega32 with eight different sensors

|

Microcontroller › AVR › ADC interface with atmega32 with eight different sensors

  • This topic has 1 reply, 2 voices, and was last updated 8 years, 1 month ago by Ashutosh Bhatt.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • March 24, 2017 at 5:55 am #4627
    s.manisrinivas
    Participant

    Hi friends,

     I want to display 8 sensors values in a LCD one after another and one only one sensor should display in LCD .How can I do that,please this regards my project.

     my code 

    #define F_CPU 16000000UL
    #include<avr/io.h>
    #include<util/delay.h>
     
    /**************************************************************************************
                                   FUNCTION DECLARATIONS
    ***************************************************************************************/
    void Command(unsigned char cmd);
    void Data(unsigned char dat);
    int Adc_Conversion(unsigned char channel);
    void Int_ASCII(int);
    void Display(char loc, const char *LCD);
    void timer0_init();
     
    /**************************************************************************************
                                   VARIABLE DECLARATIONS
    ***************************************************************************************/
    volatile unsigned char a=0;
    int Adc_Check=0,j=0,i,temp[];
     
    /**************************************************************************************
                                       MAIN FUNCTION
    ***************************************************************************************/
    int main()
    {
     DDRA = 0b00000000;                         /* Set PA0 PIN as input                         */
     DDRB = 0xFF;                         /* Set LCD data lines(PORTB) as output          */
     DDRD = 0X62;                         /* RS(PD5),EN(PD6) set as Output                */
     
     ADCSRA = 0X85;                       /* ADEN=1,ADPS2=1,ADPS1=0,ADPS0=0               */
     
     _delay_us(15);                       /* Min Delay To Power On LCD To RX Mode         */
     Command(0x30);                       /* LCD Specification Command                    */
     _delay_us(5);  
     Command(0x30);                       /* LCD Specification Command                    */
     _delay_us(2);
     Command(0x30);                       /* LCD Specification Command                    */
     Command(0x38);                       /* Double Line Display Command                  */
     Command(0x06);                       /* Auto Increment Location Address Command      */
     Command(0x0C);                       /* Display ON Command                           */
     Command(0x01);                       /* Clear Display Command                        */
     _delay_us(1200);
     //Display(0x80, "ADC");
      Display(0x80, "pot1=");
       Display(0xC0, "pot2=");
     //Display(0xC6, ",");
     
      timer0_init();
      
      while(1)
      {
       if (TCNT0 >= 191)
    {
    {
       //while(1)
       //{    
          Adc_Check = Adc_Conversion(0X40);   /* Reading sensor out from PA0 pin              */
          Command(0X85);                      /* Command to set display position              */
          Int_ASCII(Adc_Check);               /* Display adc reading                          */
          _delay_ms(500);
       }    
     
         Adc_Check = Adc_Conversion(0X41);   /* Reading sensor out from PA1 pin              */
         Command(0XC5);                      /* Command to set display position              */
         Int_ASCII(Adc_Check);
        // _delay_ms(500);
      
      
         Adc_Check = Adc_Conversion(0x42);
    Command(0xCA);
    Int_ASCII(Adc_Check);
     
     
         TCNT0 = 0;
       }
        //}
    }
     
    } 
    /**************************************************************************************
    * Function    : Adc_Conversion                                                        *
    *                                                                                     *
    * Description : Function to convert analog value to digital                           *
    *                                                                                     * 
    * Parameters  : channel – channel for ADC conversion                                  *
    ***************************************************************************************/
    int Adc_Conversion(unsigned char channel)
    {
     volatile int b;
     volatile int ad = 0;
     ADMUX  = channel;                    /* Channel selection                            */
     ADCSRA = ADCSRA|0X40;                /* ADSC=1,start conversion                      */
     while((ADCSRA & 0x40) == 0x40);      /* Check if ADIF is set i.e, conversion is over */
     b  = ADCL;                           /* Read LSB result                              */
     ad = ADCH;                           /* Read MSB result                              */
     ad = ad<<8;                          /* Shift MSB  8 times                           */
     ad = ad|b;                           /* Combine MSB and LSB                          */
     return ad;                           /* Return adc reading                           */
    }
     
    /**************************************************************************************
    * Function    : Int_ASCII                                                             *
    *                                                                                     *                                                                                                                                          
    * Description : Function to convert integer value to ASCII                            *
    *                                                                                     *                                                                                                                                          
    * Parameters  : ab – integer to be converted                                          *
    ***************************************************************************************/
    void Int_ASCII(int ab)
    {
     char i;
     char array[4];       
     for(i=1; i<=4; i++)                  /* Convert decimal to ASCII                     */
     {
      array = ab%10;                   /* Separate each integer                        */
      ab       = ab/10;
     }
     for(i=4; i>=1; i–)
     {
      Data(array+'0');                 /* Display on LCD                               */
     }
    }
     
    /**************************************************************************************
    * Function    : Command                                                               *
    *                                                                                     *
    * Description : Function to send a command to LCD                                     *
    *                                                                                     *
    * Parameters  : cmd – command to be sent                                              *
    ***************************************************************************************/
    void Command(unsigned char cmd)
    {
     PORTD |= 0X40;                        /* RS-0 for command register,
                                                           E-1,Enable pin made high       */
     PORTB  = cmd;                         /* Command loaded to data lines                */
     _delay_us(50);
     PORTD  = 0X00;                        /* E-0, Enable pin made low                    */
    }
     
    /**************************************************************************************
    * Function    : Data                                                                  *
    *                                                                                     *
    * Description : Function to display a character on LCD                                *
    *                                                                                     *
    * Parameters  : dat – Character to be displayed                                       *
    ***************************************************************************************/
    void Data(unsigned char dat)
    {
     PORTD |= 0X60;                       /* RS-1 for data register,
                                                           E-1,Enable pin made high       */
     PORTB  = dat;                        /* Data loaded to data lines                    */
     _delay_us(50);
     PORTD  = 0X00;                       /* E-0, Enable pin made low                     */
    }
     
    /**************************************************************************************
    * Function    : Display                                                               *
    *                                                                                     *                                                      
    * Description : Function to display string on LCD                                     *
    *                                                                                     *          
    * Parameters  : loc – location                                                        *
    *               LCD – String to be displayed                                          *
    ***************************************************************************************/
    void Display(char loc, const char *LCD)
    {
     Command(loc);                        /* Address of location to display data          */
     while(*LCD!='')                    /* Check for termination character              */    
     {    
      Data(*LCD);                         /* Display the character on LCD                 */    
      LCD++;                              /* Increment the pointer                        */
     }
    }
     
    /**************************************************************************************
                                      END OF PROGRAM
    ***************************************************************************************/
    void timer0_init()
    {
    // set up timer with no prescalling
    TCCR0 |= (1 << CS00);
     
    // initialize counter
    TCNT0 = 0;
    }
    March 27, 2017 at 10:08 am #14530
    Ashutosh Bhatt
    Participant

    1) select ADC channel

    2) read converted value

    3) convert value from HEX to ASCII

    4) display it on LCD

    5) wait for 5 second

    6) repeat the cycle

    thats all

  • 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

  • LED circuit for 1/6 scale diorama May 15, 2025
  • stud mount Schottky diodes May 14, 2025
  • using a RTC in SF basic May 14, 2025
  • Hi Guys May 14, 2025
  • Can I use this charger in every country? May 14, 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