adc + usart microC

General discussion on mikroC.
Post Reply
Author
Message
slimebdx
Posts: 1
Joined: 25 Feb 2012 00:22

adc + usart microC

#1 Post by slimebdx » 25 Feb 2012 01:12

hello
t whant to send adc result to usart serial port i have problem in program help me please i use 16f876a

Code: Select all

//////////*************************************************************////////
///////data acquisition program ////programed by eng.s.slimane //////////////
      unsigned int temp_res;
     unsigned char  ch;
     long tlong;

  //////////////////////Lecture de la Temperature//////////////////////
  void adc()
  {
  temp_res = ADC_Read(2);   // Get 10-bit results of AD conversion
   tlong = (long)temp_res * 5000;           // covert adc reading to milivolts
    tlong = tlong / 1023;                  // 0..1023 -> 0-5000mV

  }
 /////////// transfert du text à l'interface graphique ///////////////
  void Text_To_Usart(unsigned char *m)
  {
    unsigned char j;

    j = 0;
    while(m[j] != 0)
    {
       Usart_Write(m[j]);
       j++;
    }
  }


  ///////////////////Le Pregramme Principale////////////////////////
  void main()
  {
  TRISB =0x00;
  TRISA =0b000100;
  TRISC =0b10110000;
  // Initialize USART module at 9600 bps
  Usart_init(9600);
  // Wait for USART module to stabilize
  delay_ms(100);

  while(1)
    {


    // transfet à l'interface


      PORTB =  temp_res  ;
     ch  = tlong / 1000;

      Delay_ms(10);
      Text_To_Usart("R");
      Usart_Write(ch);
        Usart_Write(ch1);
      Usart_Write(0x0D);
      Usart_Write(0x0A);

    delay_ms(10);

        adc();
    }
    }
///////////////////////////**********************//////////////////////////////

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: adc + usart microC

#2 Post by filip » 02 Mar 2012 11:46

Hi,

Did you establish the UART communication successfully ?

Regards,
Filip.

Post Reply

Return to “mikroC General”