缘由c51单片机,程序,仿真图,求帮助-编程语言-CSDN问答
#include "REG52.h"
sbit K1 = P1^0;
sbit K2 = P1^1;
sbit K3 = P1^2;
sbit K4 = P1^3;
sbit P1_0=P2^0;
sbit P1_1=P2^1;
sbit P1_2=P2^2;
sbit P1_3=P2^3;
sbit P1_4=P2^4;
sbit P1_5=P2^5;
sbit P1_6=P2^6;
sbit P1_7=P2^7;
bit k=1,wk1=0,wk2=0;
unsigned char code SmZiFu[]={63,6,91,79,102,109,125,7,127,111,119,124,57,94,121,113,128,255,64};//0-9A-F.消隐-
unsigned char Js=0,miao=0,fen=0,shi=0,y=6,t=23,ls=0;//中断计时
//unsigned int n=2021;
//void smxs(unsigned char mz,unsigned char w,unsigned char d)
//{
// unsigned char Xd=0;
// P1=~255;
// P1=~(255-(d==1?SmZiFu[mz]:(SmZiFu[mz]|0x80)));//小数点闪烁
// P2=~w;
// while(++Xd);
//}
void ZhongDuanSheZhi()
{
TH0+=0X4c;/*定时器赋初值,定时50ms触发中断,自动补偿方式*/
TL0+=0X00;
TMOD=0X01;
TR0=1;
ET0=1; //开启定时器
EA=1; //全局中断开关
IT0 = 1;//下降沿触发
EX0 = 1;//开外部中断
}
void main()
{
unsigned char Xd=0,xz=1,cs=0,ss=0;
unsigned int wei=0;P0=1;
ZhongDuanSheZhi();k=0;
while(1)
{
if(K1==0&&++Xd==0)
{
k=~k;
while(!K1);
}
if(K2==0&&++Xd==0)
{
cs=ss=0;
k=~k;
while(!K2);
}
P2=SmZiFu[cs]; P3=SmZiFu[ss];
if(Js==20)//设置定时器50毫秒
{
if(k)if(++ss>9){ss=0;if(++cs>9)cs=0;}
Js=0;
}
}
}
void ZhongDuan() interrupt 1
{
++Js;
TH0+=0X4c;
TL0+=0X00;
}
void WaiBuZhongDuan0() interrupt 0//外部中断0=0,1=2,引脚P3.2,INT0
{
wk1=1;
}