【文件属性】:
文件名称:单片机之秒表编程文档
文件大小:1KB
文件格式:TXT
更新时间:2012-08-23 11:54:02
秒表 编程
利用单片机技术编一个秒表程序,感觉很酷
#include
#define uint unsigned int
#define uchar unsigned char
uint jishu,sec,fen;
uchar i=0;
uint array1[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8, 0x80,0x90,0x88,0x83, 0xc6,0xa1,0x86,0x8e};
uint array2[]={0x1f,0x2f,0x4f,0x8f};
uint cunshu[]={0,0,0,0};
void init(){
TMOD=0x11;
ET0=1;
TR0=1;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
ET1=1;
TR1=1;
TH1=(65536-1000)/256;
TL1=(65536-1000)%256;
EA=1;
}
void zhongduan0() interrupt 1{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
jishu++;
}
void zhongduan1() interrupt 3{
TH1=(65536-1000)/256;
TL1=(65536-1000)%256;
if(i<=3){
P2=array2[i];
P0=array1[cunshu[i]];
}
i++;
if(i>=4) i=0;
}
void renew(){
if(jishu>=20){
sec++;
jishu=0;
}
if(sec>=60){
fen++;
sec=0;
}
if(fen>=60)
fen=0;
cunshu[0]=sec%10;
cunshu[1]=sec/10;
cunshu[2]=fen%10;
cunshu[3]=fen/10;
}
void main(){
init();
while(1){
renew();
}
}