Saturday 28 December 2013

ADC code using KEIL programer

#include <REGX51.H>
#include<LCD.c>

sbit EOC=P3^0;    // End Of Conversion;
sbit STR=P3^1;    // Start;
sbit OE=P3^2;    // Output Enable;
sbit ALE=P3^3;    // Address Latch Enable;

void adc_con(unsigned char);
       
void main()
{
 
  P1=0XFF;
  OE=0;
  ALE=0;
  STR=0;
  EOC=1;
  ini();                                                                          
  address(0x80);
  string("adc:");

  while(1)
  {
   ALE=1;
   STR=1;
   ALE=0;
   STR=0;

   while(EOC==0);
   OE=1;
   adc_con(P1);
   OE=0;
  }
}
void adc_con(unsigned char a)
{
  unsigned char c1,c2,c3;
  address(0x85);  // address of the LCD display

  c1=(a/100)+48;
  c2=((a%100)/10)+48;
  c3=a%10+48;
 
  write(c1);  // write value to lcd display
  write(c2);
  write(c3);
}

No comments:

Post a Comment