要在51单片机上实现100秒的计时,可以使用定时器来实现。以下是一个基于AT89C51单片机的100秒倒计时的示例程序,使用两位数码管静态显示倒计时秒值。
```c
include
define uchar unsigned char
define uint unsigned int
uchar duan = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e}; // 共阴
uchar wei={0XEf,0XDf,0XBf,0X7f}; // 位的控制端
uint setfen,setmiao,runfen,runmiao;
uint z,x,c,v;
uint fs,fg,ms,mg;
uint setwz;
sbit KEYSTOP=P3^7; // 停止键
sbit KEYSET=P1^7; // 设置键
sbit KEYUP=P1^6; // 上调
sbit KEYDOWN=P1^5; // 下调
sbit KEYRUN=P1^4; // 开始
sbit LEDSET=P1^3; // 设置灯
sbit LEDRUN=P1^2; // 运行灯
sbit LEDSTOP=P1^1; // 停止灯
sbit LABA=P1^0; // 喇叭
uint runmod=0; // 状态,0是等待运行(停止),1是运行,2是设置,3是刚刚完成
void Timer0Init(void) //1毫秒@11.0592MHz {
TMOD &= 0xF0; //设置定时器模式
Timer0 = 0x30; //设置定时初值
TH0 = 0xE3; //设置定时初值
TL0 = 0; //设置定时初值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
}
void DIGdisplay() {
u8 i;
for (i=0; i<2; i++){
switch(i){
case(0): LSA = 1 ;LSB = 0 ; break;
case(1): LSA = 0 ; LSB = 0 ; break;
}
}
}
void delay(unsigned int time) {
unsigned int i, j;
for(i=0; i