用STC89C52RC单片机写的,郭天祥的程序。不显示计时呢
时间:10-02
整理:3721RD
点击:
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit duan=P2^6;
sbit wei=P2^7;
sbit led1=P1^0;
uchar code table[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void delay(uint);
void display(uchar,uchar);
uchar num,num1,num2,shi,ge;
void main()
{
TMOD=0x11; //设置定时器0和1为工作方式1
TH0=(65536-45872)/256; //装初值
TL0=(65536-45872)%256;
TH1=(65536-45872)/256; //装初值
TL1=(65536-45872)%256;
EA=1;
ET0=1;
ET1=1;
TR0=1;
TR1=1;
while(1)
{
display(shi,ge);
}
}
void display(uchar shi,uchar ge)
{
duan=1;
P0=table[shi];
duan=0;
P0=0xff;
wei=1;
P0=0xfe;
wei=0;
delay(5);
duan=1;
P0=table[ge];
duan=0;
P0=0xff;
wei=1;
P0=0xfd;
wei=0;
delay(5);
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void T0_time()interrupt 1
{
TH0=(65536-45872)/256; //重装初值
TL0=(65536-45872)%256;
num1++;
if(num1==4)
{
num1==0;
led1=~led1;
}
}
void T1_time()interrupt 3
{
TH1=(65536-45872)/256; //重装初值
TL1=(65536-45872)%256;
num2++;
if(num2==20)
{
num2=0;
num++;
if(num==60)
{
num=0;
shi=num/10;
ge=num%10;
}
}
}
#define uint unsigned int
#define uchar unsigned char
sbit duan=P2^6;
sbit wei=P2^7;
sbit led1=P1^0;
uchar code table[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void delay(uint);
void display(uchar,uchar);
uchar num,num1,num2,shi,ge;
void main()
{
TMOD=0x11; //设置定时器0和1为工作方式1
TH0=(65536-45872)/256; //装初值
TL0=(65536-45872)%256;
TH1=(65536-45872)/256; //装初值
TL1=(65536-45872)%256;
EA=1;
ET0=1;
ET1=1;
TR0=1;
TR1=1;
while(1)
{
display(shi,ge);
}
}
void display(uchar shi,uchar ge)
{
duan=1;
P0=table[shi];
duan=0;
P0=0xff;
wei=1;
P0=0xfe;
wei=0;
delay(5);
duan=1;
P0=table[ge];
duan=0;
P0=0xff;
wei=1;
P0=0xfd;
wei=0;
delay(5);
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void T0_time()interrupt 1
{
TH0=(65536-45872)/256; //重装初值
TL0=(65536-45872)%256;
num1++;
if(num1==4)
{
num1==0;
led1=~led1;
}
}
void T1_time()interrupt 3
{
TH1=(65536-45872)/256; //重装初值
TL1=(65536-45872)%256;
num2++;
if(num2==20)
{
num2=0;
num++;
if(num==60)
{
num=0;
shi=num/10;
ge=num%10;
}
}
}
直接执行display可以显示吗?比如先把shi,ge都赋值的情况下
[em:1:][em:1:][em:1:][em:1:][em:1:]
谢谢,我找到问题在哪了。应该吧最后一句的if语句括号去掉的。
不错。值得学习!