緣由單片機控制數碼管及LED燈-嵌入式-CSDN問答
#include "REG52.h"
sbit k1=P3^0;
unsigned char Js=0;//計時
unsigned char code smgduan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07
,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0,64,15,56}; //共陰0~F消隱減號
void ZhongDuanSheZhi()
{TH0+=(65536-9216)/256;/*定時器賦初值,定時10ms觸發中斷,自動補償方式*/TL0+=(65536-9216)%256; TMOD=0X01;//16位定時器/計數器ET0=TR0=1; //啟動定時器T0開啟定時器。EA=1; //全局中斷開關
}
void main()
{unsigned char miao=0,xd=0,den=0,k=0,w=0;ZhongDuanSheZhi();while(1){P0=~smgduan[w];//一位靜態數碼管顯示0-F秒增if(k1==0&&++xd==0)if(k==1)if(++w>15)w=0;P1=(k1?255:1);//LED組第一個燈控制按下亮釋放熄if(Js==100){Js=0;k=1;}}
}
void ZhongDuan() interrupt 1
{++Js;TH0+=(65536-9216)/256;TL0+=(65536-9216)%256;
}