八路AD采集电压表
扫描二维码
随时随地手机看文章
/*****************************************************************************
* 八路AD采集电压表
* 单片机采用AT89S52,晶振频率为:12.00MHz。
/******************************************************************************/
#include
unsigned char code dispbitcode[]={0xfe,0xfd,0xfb,0xf7,
0xef,0xdf,0xbf,0x7f};
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f,0x00};
unsigned char dispbuf[8]={0,0,0,0,0,0,0,0};
unsigned char dispcount;
unsigned char getdata;
unsigned int temp;
unsigned char i,m=1;
sbit ST=P3^0;
sbit OE=P3^1;
sbit EOC=P3^2;
sbit CLK=P3^3;
/********延时字程序************/
void delay10ms()
{
unsigned char j,k;
for(j=20;j>0;j--)
for(k=248;k>0;k--);
}
/********延时字程序************/
void delay(unsigned char delay)
{
unsigned char j,k;
for(delay;delay>0;delay--)
for(j=200;j>0;j--)
for(k=248;k>0;k--);
}
/********键盘扫描************/
void scan_key()
{
if((P3!=0xff))
{
if(P3_6==0)
{delay10ms();
if(P3_6==0)
{m++;
if(m>8) m=1;
}
while(P3_6==0);
}
if(P3_7==0)
{ delay10ms();
if(P3_7==0)
{m--;
if(m<1) m=8;
}
while(P3_7==0);
}
if(m==1)
{
P2_5=0;
P2_6=0;
P2_7=0;
}
if(m==2)
{
P2_5=1;
P2_6=0;
P2_7=0;
}
if(m==3)
{
P2_5=0;
P2_6=1;
P2_7=0;
}
if(m==4)
{
P2_5=1;
P2_6=1;
P2_7=0;
}
if(m==5)
{
P2_5=0;
P2_6=0;
P2_7=1;
}
if(m==6)
{
P2_5=1;
P2_6=0;
P2_7=1;
}
if(m==7)
{
P2_5=0;
P2_6=1;
P2_7=1;
}
if(m==8)
{
P2_5=1;
P2_6=1;
P2_7=1;
}
}
}
/********循环扫描************/
void scan_in()
{
for(m=8;m>0;m--)
{
delay(10);
if(m==1)break;
}
}
/********主程序************/
void main(void)
{
ST=0;
OE=0;
ET0=1;
ET1=1;
EA=1;
TMOD=0x12;
TH0=216;
TL0=216;
TH1=(65536-2000)/256;
TL1=(65536-2000)%256;
TR1=1;
TR0=1;
ST=1;
ST=0;
while(1)
{
if(EOC==1)
{
OE=1;
getdata=P0;
OE=0;
temp=getdata*250;
temp=temp/128;
i=0;
dispbuf[0]=0;
dispbuf[1]=0;
dispbuf[2]=0;
dispbuf[3]=0;
dispbuf[4]=10;
dispbuf[5]=10;
dispbuf[6]=10;
dispbuf[7]=10;
scan_key();
while(temp/10)
{
dispbuf=temp%10;
temp=temp/10;
i++;
}
dispbuf=temp;
ST=1;
ST=0;
}
}
}
/********中断程序************/
void t0(void) interrupt 1 using 0
{
CLK=~CLK;
}
void t1(void) interrupt 3 using 0
{
TH1=(65536-4000)/256;
TL1=(65536-4000)%256;
P1=dispcode[dispbuf[dispcount]];
P2=dispbitcode[dispcount];
dispcount++;
if(dispcount>2)
{
P1=P1 | 0x80;
}
if(dispcount==4)
{
P1=dispcode[m];
}
if(dispcount==8)
{
dispcount=0;
}
}