注册会员
- 积分
- 108
- 威望
- 172
- 贡献
- 26
- 兑换币
- 0
- 注册时间
- 2011-5-12
- 在线时间
- 0 小时
|
1贡献
#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
unsigned char code table[]={
0x28,0x6f,0x58,0x4a,0x0f,
0x8a,0x88,0x6e,0x08,0x0a,
0x0c,0x89,0xb8,0x49,0x98,0x9c};//数字1~9 字母A~F
uchar code table2[]={
0xf7,0xfb,0xfd,0xfe};//数码管选择
uchar temp,aa,bai,shi,ge,shu=432;
uint i=5,j,t0=0,t1=0;
void display(uchar aa,uchar bai,uchar shi,uchar ge);
void main()
{
temp=0xfe;
TMOD=0x11;//定时器工作方式
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;//给定时器0装初值
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;//给定时器1装初值
EA=1;//开总中断
ET0=1;//开定时器0外部中断
ET1=1;//开定时器1外部中断
TR0=1;
TR1=1;//启动定时器1
while(1)
{
display(5,bai,shi,ge);
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
t0++;
if(t0==10)
{t0=1;
P1=temp;
temp=_crol_(temp,1);
P1=temp;}
}
void timer1() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
t1++;
if(t1==3)
{
t1=0;
shu--;
bai=shu/100;
shi=shu%100/10;
ge=shu%10;
if(shu==398)
{
TR0=0;
TR1=0;
}
}
}
void display(uchar aa,uchar bai,uchar shi,uchar ge)
{
P2=0xf7;
P0=table[aa];
P2=0xfb;
P0=table[bai];
P2=0xfd;
P0=table[shi];
P2=0xfe;
P0=table[ge];
} |
|