按键控制数码管显示数字加减.docx
#include<reg52.h>#define uchar unsigned char #define uint unsigned intuint num=0,num1=0;sbit key1=P30;sbit key2=P31;sbit key3=P32;sbit key4=P33;uchar table=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f;void delayms(uint x) uint i,j; for(i=x;i>0;i-) for(j=110;j>0;j-);void display(uint num) uint shi,ge; shi=num/10; ge=num%10; P0=tableshi; P1=0xfd; delayms(5);P0=tablege; P1=0xfe; delayms(5);void keyscan() if(key1=0) delayms(10); if(key1=0) num1+; if(num1=60) num1=0; while(!key1) display(num1);if(key2=0) delayms(10); if(key2=0) if(num1=0) num1=60; num1-; while(!key2)display(num1);if(key3=0) delayms(10); if(key3=0) num1=0; while(!key3)display(num1); if(key4=0) delayms(10); if(key4=0) TR0=TR0;while(!key4)display(num1);void main() TMOD=0x01; TH0=(65536-45872)/256; TL0=(65536-45872)%256; EA=1; ET0=1; while(1) keyscan(); display(num1);void T()interrupt 1 TH0=(65536-45872)/256; TL0=(65536-45872)%256; num+; if(num=20) num1+; num=0; if(num1=60) num1=0;第 4 页