|
以下是程序问题可能出在启动ad的那部分
#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit dot=P1^7;
sbit EOC=P3^0;
sbit OE2=P3^5;
sbit clock=P3^1;
sbit P2_0=P2^0;
sbit P2_1=P2^1;
sbit P2_2=P2^2;
sbit P2_3=P2^3;
sbit key1=P2^4;
sbit key2=P2^5;
sbit key3=P2^6;
sbit P2_7=P2^7;
sbit key4=P3^3;
sbit key5=P3^2;
sbit ALE=P3^4;
sbit wr=P3^6;
sbit rd=P3^7;
uchar aa,bb,cc,dd,tongdao,getdate,date;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f};
void delay(uint x) //延时ms
{
uchar i,j;
for(i=x;i>0;i--)
for(j=125;j>0;j--);
}
void init() //定时器初始化
{
TMOD=0x01;
TH0=(65536-20)/256;
TL0=(65536-20)%256;
EA=1;
ET0=1;
TR0=1;
tongdao=0x00; //通道ABC为低
}
void display()
{
P2_3=0;
P1=table[dd]; //显示第四位数码管
dot=1;
delay(1);
P1=0x00;
P2_3=1;
P2_2=1;
P1=table[cc];
delay(1);
P1=0x00;
P2_2=0;
P2_1=1;
P1=table[bb];
delay(1);
P1=0x00;
P2_1=0;
P2_0=1;
P1=table[aa]; //显示第一位
delay(1);
P1=0x00;
P2_0=0;
}
void ad_start() //启动ad
{
ALE=0;
OE2=0;
P0=tongdao;
_nop_();
OE2=1;
ALE=1;
P2_7=1;
_nop_();
P2_7=0;
while(EOC==0);
rd=0;
date=P0;
_nop_();
rd=1;
getdate=date*(5000/255);
aa=getdate%10;
bb=getdate%100/10;
cc=getdate/100%10;
dd=getdate/1000;
}
void keyscan()
{
if(key1==0)
{
delay(10);
if(key1==0);
{
tongdao=0x00;
}
}
if(key2==0)
{
delay(10);
if(key2==0);
{
tongdao=0x01;
}
}
if(key3==0)
{
delay(10);
if(key3==0);
{
tongdao=0x02;
}
}
if(key4==0)
{
delay(10);
if(key4==0);
{
tongdao=0x03;
}
}
}
void main()
{
init();
while(1);
{
ad_start();
keyscan();
display();
}
}
void timer() interrupt 1
{
TH0=(65536-20)/256;
TL0=(65536-20)%256;
clock=~clock;
}
|
|