Loading ...
Sorry, an error occurred while loading the content.

1820Re: [booksbybibin,www.booksbybibin.tk] Re: HAVING PROBLEM WITH ADC

Expand Messages
  • alexandru sorin
    Aug 16, 2009
    • 0 Attachment
      You can use this for float to char: (didn't test for int)
       

      void aff_float(float number) //afficher float avec 1 decimal

      {         

                  unsigned char aff[16];

                  sprintf(aff,"%.1f",number);

                  aff_data(aff);

      }
       

      void aff_data(unsigned char data[])

      {

       

                  PORTB |= (1 << 2);                //RS=1; //envoie un octet de donnée.

                  for(int i=0;i<strlen(data);i++)

                  {

                             

                              aff_char(data[i]);

                 

                  }

                 

      }

       

      void aff_char(unsigned char caracter)

      {

                  PORTB |= (1 << 2);                //RS=1; //envoie un octet de donnée.

                  PORTC=caracter;

                  enable();

                  _delay_ms(5);

      }

       

       




      From: nitin chaudhary <nitin2162000@...>
      To: booksbybibin@yahoogroups.com
      Sent: Saturday, August 15, 2009 1:11:55 AM
      Subject: Re: [booksbybibin,www.booksbybibin.tk] Re: HAVING PROBLEM WITH ADC

       

      If you want to display the result on lcd connected to the microcontroller then you have to convert int in to char as lcd takes character. If your result is 201 the algo is
      x=210;//your data
      for (i=0;i<2;i++)
      {
       y=x%10;
      z='0';
      for(j= 0; j<=9; j++)
      {
       if(y==j)
      {
         lcdprint(z);
         break();
      }
      else
       z+=1;
      }
      x=x/10;
      }
      I am in hury so plze consider it before usage (it is simply int to char conversion);
      best of lck......... ....
      --- On Thu, 13/8/09, Saeed Ahmed <danial_1000@ yahoo.com> wrote:

      From: Saeed Ahmed <danial_1000@ yahoo.com>
      Subject: Re: [booksbybibin, www.booksbybibin .tk] Re: HAVING PROBLEM WITH ADC
      To: booksbybibin@ yahoogroups. com
      Date: Thursday, 13 August, 2009, 7:46 AM

       

      hi,
      u help me n communicating with pc and now i having problem to read the analouge voltage from ranging 0 to 5v and any other value deponding upon the requirements .i m confused when i read the adch then how i will display it at the the lcd or monitor display.plz help me with a simple code  i will be thankfull.
       
      thanks
      dany


      --- On Mon, 8/3/09, Mihai Galos <mihaigalos@yahoo. com> wrote:

      From: Mihai Galos <mihaigalos@yahoo. com>
      Subject: [booksbybibin, www.booksbybibin .tk] Re: HAVING PROBLEM WITH ADC
      To: booksbybibin@ yahoogroups. com
      Date: Monday, August 3, 2009, 8:07 PM

       
      see my project on adc. Perhaps i will help.

      http://www.mihaigalos.ro/work/Embedded/Advanced/temp2lcd/readOn.html

      Regards,
      Mihai G.

      --- In booksbybibin@ yahoogroups. com, "danial_1000" <danial_1000@ ...> wrote:
      >
      > hi,
      > i m actually new to avr ,i want to read the analog voltage through avr
      > adc using avcc as a refrence and want to display it on terminal window
      > using UART of avr.i tried to do so but i don,t sucess to display the
      > correct digits on the bray's terminal window ,i connect a multi turn
      > potentometer to vary the analog level from 0 volts to +5 volts.when i
      > turn the pot i gets 00 ascii charcters on the screen .plz any body help
      > me i will be thankfull.
      > regards
      > dany
      >
      >
      >
      >
      > /*---------- --------- --------- --------- --------- --------- ---
      > ------------ -----HEADER FILES------- --------- --------- --------- ---
      > ------------ --------- --------- --------- --------- --------- -*/
      > #include <avr/io.h>
      > /*---------- --------- --------- --------- --------- --------- ---
      > ------------ -----PROTOTYPES- --------- --------- --------- --------
      > ------------ --------- --------- --------- --------- --------- -*/
      > void Init_ADC(void) ;
      > int Read_ADC(void) ;
      > void InitUART( unsigned char baudrate );
      > unsigned char ReceiveByte( void );
      > void TransmitByte( unsigned char data );
      > /*---------- --------- --------- --------- --------- --------- ---
      > ------------ -----MAIN FUNCTION---- --------- --------- --------- -----
      > ------------ --------- --------- --------- --------- --------- -*/
      >
      > int main(void)
      > {
      > int b,i,k;
      > unsigned char str[7]={'V', 'O','L',' T',':',' ',' '};//at starting some
      > backspace occurs
      > unsigned char del[2]={0x08, 0X08}; //for deleting previous reading
      > //serial port initiliasation
      > InitUART( 207 ); //8Mhz 2400 8n1
      > //ADC startups
      > Init_ADC();
      > //Read_ADC(void)
      > //sending the string
      >
      > for(i=0;i<7; i++)
      > {
      > TransmitByte( str[i]);
      > }
      > b=0;
      >
      > do
      > {
      > k=Read_ADC() ;
      > if(k!=b)
      > {
      > //first delete the previous values for uart
      > for(i=0;i<2; i++)
      > {
      > TransmitByte( del[i]);
      > }
      >
      > k=(((ADCL=0* 256+ADCH) *4..5)/512) ;
      > TransmitByte( k+0x30); //0x30 have been added to display ascii
      > TransmitByte( k+0x30);
      > TransmitByte( k+0x30);
      > }
      > }
      > while(1);
      > return o;
      > }
      > /*---------- --------- --------- --------- --------- --------- ---
      > ------------ --FUNCTION TO INIT_ADC---- --------- --------- --------- -----
      > ------------ --------- --------- --------- --------- --------- -*/
      > void Init_ADC(void)
      > {
      >
      > ADMUX=0;//SELECTING CHANNEL0
      > ADCSRA=0;
      > ADMUX|=(1<<ADLAR) | (1<<REFS0)) ;
      > // AREF IS AVCC AND THE CONVERSION IS LEFT ADJUSTED
      > ADCSRA|=(1<< ADEN) | (1<<ADPS2) | (1<<ADPS0) | (1<<ADPS1) ; //ADC
      > PRESCALLER IS 128
      > }
      > /*---------- --------- --------- --------- --------- --------- ---
      > ------------ --FUNCTION TO READ_ADC---- --------- --------- --------- -----
      > ------------ --------- --------- --------- --------- --------- -*/
      > int Read_ADC(void)
      > {
      > ADCSRA|=(1<< ADSC); //start conversion
      > while(!((ADCSRA & (1<<ADIF));
      > return ADCH;
      > }
      > /*---------- --------- --------- --------- --------- --------- ---
      > ------------ FUNCTIONS TO Initialize UART-------- --------- ---------
      > ------------ --------- --------- --------- --------- --------- -*/
      >
      > void InitUART( unsigned char baudrate )
      > {
      > UBRRL = baudrate; /* Set the baud rate */
      > UCSRB = (UCSRB | (1<<RXEN) | (1<<TXEN) ); /* Enable UART receiver
      > and transmitter */
      > }
      > /*---------- --------- --------- --------- --------- --------- ---
      > ------------ FUNCTIONS TO READ UART-------- --------- --------- -----
      > ------------ --------- --------- --------- --------- --------- -*/
      > unsigned char ReceiveByte( void )
      > {
      > while ( !(UCSRA & (1<<RXC))); /* Wait for incomming data */
      > return UDR;/* Return the data */
      > }
      >
      > /*---------- --------- --------- --------- --------- --------- ---
      > ------------ FUNCTIONS TO WRITE UART-------- --------- --------- -----
      > ------------ --------- --------- --------- --------- --------- -*/
      > void TransmitByte( unsigned char data )
      > {
      > while ( !(UCSRA & (1<<UDRE))); /* Wait for empty transmit
      > buffer */
      > UDR = data; /* Start transmittion */
      > }
      >




      Looking for local information? Find it on Yahoo! Local


    • Show all 9 messages in this topic