缘由
cpp
#include "REG52.h"
unsigned char code smgduan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0,64}; //共阴0~F消隐减号
unsigned char Js=0, miao=0;//中断计时 秒 分 时 毫秒
sbit k0=P3^0;
sbit k1=P3^1;
void smxs(unsigned char mz, unsigned char w)
{
unsigned char Xd=0;
P0=255;
P0=255-smgduan[mz];
P2=w;
while(++Xd);
}
void ZhongDuanSheZhi()
{
TH0+=(65536-9216/2)/256;/*11.0592MHz定时器赋初值,定时5ms触发中断,自动补偿方式*/
TL0+=(65536-9216/2)%256;
TMOD=0X01;//16位定时器/计数器
TR0=1; //启动定时器T0。
ET0=1; //开启定时器
EA=1; //全局中断开关
}
void main()
{
unsigned char Xd=0,qh=0,ci=0;//消抖
unsigned int shu=0;P1=0;
ZhongDuanSheZhi();
while(1)
{
if(k0==0&&++Xd==0)
{
if(++qh>4)qh=0;
(qh==1?P1=240:qh==2?P1=3:qh==3?P1=128:qh==4?P1=1:qh==0?P1=0:0);
while(k0==0);
}
if(k1==0&&++Xd==0){P1=0;if(qh==0)qh=5;else qh=0;smxs(qh,1);while(k1==0);}
if(qh>0&&qh<5)smxs(qh,1);else smxs(qh,16);
if(Js>=100)
{
Js=0;
if(qh==0){if(P1==1)P1=0;else P1=1;}
else if(qh==1){if(P1==240)P1=15;else P1=240;}
else if(qh==2){if(P1<192)P1*=2;else P1=3;}
else if(qh==3){if((P1/=2)==0)P1=128;else;}
else if(qh==4)++P1;else;
}
}
}
void ZhongDuan() interrupt 1
{
++Js;
TH0+=(65536-9216/2)/256;
TL0+=(65536-9216/2)%256;
}
