任务:
12864显示来自Ds1302的时钟信号,用定时器0固定时间采集信号
定时器1产生9600波特率,接收串口信息
定时器2 定时采集AD信号,在数码管显示
问题:每步分开用都可以,放在一个程序后,数码管不能稳定,一直闪动
这是主程序
while(1)
{
if(flag1)
{
flag1 = 0;
DS1302_write(0x8e, 0x00); //DS1302写保护关
miao = (DS1302_read (0x81) ); //读秒
fen = (DS1302_read(0x83)); //读分
shi = (DS1302_read(0x85)); //读时
ri = (DS1302_read(0x87)); //读日
yue = (DS1302_read(0x89)); //读月
week = (DS1302_read(0x8b)); //读周
write_time(4, miao); //在LCD显示秒
delay();
write_time(2, fen); //在LCD显示分
delay();
write_time(0, shi); //在LCD显示时
delay();
write_day(5, ri); //在LCD显示日
delay();
write_month(3, yue); //在LCD显示月
delay();
write_week(week); //在LCD显示周
delay();
}
if(RI)
{
EA = 0;
dat1 = SBUF;
LCD_PLACE(4, 7);
LCD_DATA(dat1+0x30);
RI = 0;
EA = 1;
}
if(flag2 == 1)
{
flag2 = 0;
EA = 0;
DATA = read_add(0x42); //读取AD芯片数据
display2(DATA); //在数码管显示
EA = 1;
}
}
}
void timer0() interrupt 1
{
t1++;
if(t1 == 5000)
{ t1 = 0;
flag1 = 1; }
}
void timer2() interrupt 5
{
n++;
TF2 = 0;
if(n == 30)
{
n = 0;
flag2 = 1;
}
}
void ser2() interrupt 4
{
}
|