#include
#define ch1 0xE8;
#define ch2 0xE9;
#define ch3 0xEA;
#define ch4 0xEB;
#define ch5 0xEC;
#define ch6 0xED;
#define ch7 0xEE;
#define ch8 0xEF;
xdata volatile unsigned char CONTROL _at_ 0xFC00;
sbit b=P3^2;
void Send(unsigned char x)
{
SBUF=x;
while(!TI);
TI=0;
}
void Send_String(char* string, unsigned char no_of_bytes)
{
int i, stringlength = no_of_bytes;
for(i=1; i<=stringlength; i++)
{
Send(*string++);
}
}
void hex2ascii(unsigned char i)
{
unsigned char tmp;
unsigned char ASCII[2];
tmp = i>>4;
if(tmp <= 0x09)
ASCII[0] = tmp+0x30;
else
{
ASCII[0] = tmp-0x9;
ASCII[0] += 0x40;
}
tmp = (i & 0x0f);
if(tmp <= 0x09)
ASCII[1] = tmp+0x30;
else
{
ASCII[1] = tmp-0x9;
ASCII[1] += 0x40;
}
Send_String(ASCII,2);
}
unsigned char Read_ADC(unsigned char x)
{
b=1;
if(x=='1')
{
CONTROL=ch1;
while(!b);
return CONTROL;
}
if(x=='2')
{
CONTROL=ch2;
while(!b);
b = 0;
return CONTROL;
}
if(x=='3')
{
CONTROL=ch3;
while(!b);
return CONTROL;
}
if(x=='4')
{
CONTROL=ch4;
while(!b);
return CONTROL;
}
if(x=='5')
{
CONTROL=ch5;
while(!b);
return CONTROL;
}
if(x=='6')
{
CONTROL=ch6;
while(!b);
return CONTROL;
}
if(x=='7')
{
CONTROL=ch7;
while(!b);
return CONTROL;
}
if(x=='8')
{
CONTROL=ch8;
while(!b);
return CONTROL;
}
}
void delay(void)
{
unsigned int k;
for (k=0;k<0xfffe;k++)
{
_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();_nop_();
}
}
void main(void)
{
SCON = 0x50;
TMOD = 0x21;
TH1 = 0xfd;
TL1 = 0xfd;
TCON = 0x45;
TR1=1;
while(1)
{
hex2ascii(Read_ADC('1'));
delay();
}
}
No comments:
Post a Comment