|
- #include<reg52.h>
- unsigned char code Tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//段碼表
- unsigned char x;
-
- sbit P34=P3^4; //T0控制管腳
- void delay1ms(unsigned int n) //1ms基準(zhǔn)延時
- {
- unsigned char i;
- while(n--)
- for(i=0;i<125;i++);
- }
- void display(unsigned char x) //顯示函數(shù)
- {
- P2=0xbf;
- P0=Tab[x/10]; //顯示十位
- delay1ms(1);
- P2=0x7f;
- P0=Tab[x%10]; //顯示個位
- delay1ms(1);
-
- }
- void main()
- {
-
- x=0;
- TMOD=0x06; //T0的計數(shù)器工作模式2 0000 0110 C/T'=1為計數(shù)器
- EA=1; //開放總中斷
- EX0=1; //允許INT0中斷
- ET0=1; //允許T0中斷
-
- IT0=1; //INT0為負(fù)跳變觸發(fā)中斷
- TR0=1; //將T0的高,低位賦值255,只要按鍵一次就溢出,觸發(fā)中斷
- TH0=TL0=255;
- while(1) //無限循環(huán)等待中斷
- display(x);
-
-
- }
- void int0() interrupt 1 //T0的中斷編號為1
- {
- if(P34==0){
- delay1ms(20); //消陡
- if(P34==0){
- x=(x+1)%100;
- }
- }
- }
- void clear0() interrupt 0 //INT0的中斷編號為0
- {
- x=0;
- }
復(fù)制代碼
|
|