|
按鍵控制中斷時(shí)鐘
單片機(jī)源程序如下:
- #include"STC15F2K60S2.H"
- #include"INTRINS.H"
- #define uchar unsigned char
- #define uint unsigned int
- #define dula 0xef
- #define wela 0xcf
- uchar gang = 0xbf;
- uchar temp,num;
- uchar shi=11,fen=0,miao=11;
- uchar code table[]=
- {
- 0xc0,0xf9,0xa4,0xb0,0x99,
- 0x92,0x82,0xf8,0x80,0x90
- };
- uchar code table1[]=
- {
- 0x01,0x02,0x04,0x08,
- 0x10,0x20,0x40,0x80
- };
- void Delay1ms(uint m) //@11.0592MHz
- {
- unsigned char i, j;
- uint z;
- for(z=m;z>0;z--)
- {
- _nop_();
- _nop_();
- _nop_();
- i = 11;
- j = 190;
- do
- {
- while (--j);
- } while (--i);
- }
- }
- void show()
- {
- P2 = ((P2&0x1f)|dula);
- P0 = table[shi/10];
- P2 &= 0x1f;
- P2 = ((P2&0x1f)|wela); //shi
- P0 = table1[0];
- P2 &= 0x1f;
- Delay1ms(1);
- P2 = ((P2&0x1f)|dula);
- P0 = table[shi%10];
- P2 &= 0x1f; //shi
- P2 = ((P2&0x1f)|wela);
- P0 = table1[1];
- P2 &= 0x1f;
- Delay1ms(1);
- P2 = ((P2&0x1f)|dula);
- P0 = gang;
- P2 &= 0x1f; //-
- P2 = ((P2&0x1f)|wela);
- P0 = table1[2];
- P2 &= 0x1f;
- Delay1ms(1);
- P2 = ((P2&0x1f)|dula);
- P0 = table[fen/10];
- P2 &= 0x1f; //fen
- P2 = ((P2&0x1f)|wela);
- P0 = table1[3];
- P2 &= 0x1f;
- Delay1ms(1);
- P2 = ((P2&0x1f)|dula);
- P0 = table[fen%10]; //fen
- P2 &= 0x1f;
- P2 = ((P2&0x1f)|wela);
- P0 = table1[4];
- P2 &= 0x1f;
- Delay1ms(1);
- P2 = ((P2&0x1f)|dula);
- P0 = gang;
- P2 &= 0x1f; //-
- P2 = ((P2&0x1f)|wela);
- P0 = table1[5];
- P2 &= 0x1f;
- Delay1ms(1);
- P2 = ((P2&0x1f)|dula);
- P0 = table[miao/10]; //miao
- P2 &= 0x1f;
- P2 = ((P2&0x1f)|wela);
- P0 = table1[6];
- P2 &= 0x1f;
- Delay1ms(1);
- P2 = ((P2&0x1f)|dula); //miao
- P0 = table[miao%10];
- P2 &= 0x1f;
- P2 = ((P2&0x1f)|wela);
- P0 = table1[7];
- P2 &= 0x1f;
- Delay1ms(1);
-
- }
- void show_1()
- {
- P2 = ((P2&0x1f)|0x80);
- P0 = 0xff;
- P2 &= 0x1f;
- Delay1ms(1);
- }
- void init()
- {
- TMOD = 0X01;
- TL0 = 0X00;
- TH0 = 0X4C;
- TR0 = 1;
- ET0 = 1;
- EA = 1;
- }
- void key()
- {
- if(P30==0)
- {
- EA = 0;
- Delay1ms(20);
-
- if(P30==0)
- {
- while(!P30);
- fen++;
- if(fen==60)
- {
- fen=0;
- shi++;
- }
- }
-
- }
- if(P31==0)
- {
- EA = 0;
- Delay1ms(20);
- if(P31==0)
- {
- while(!P31);
- fen--;
- if(fen==-1)
- {
- fen=59;
- shi--;
- }
- }
- }
- if(P32==0)
- {
- EA=1;
- while(!P32);
- Delay1ms(1);
- }
- }
- void main()
- {
- show_1();
- init();
- while(1)
- {
- show();
- key();
- }
- }
- void time() interrupt 1
- {
- TL0 = 0X00;
- TH0 = 0X4C;
- temp++;
-
- if(temp==20)
- {
- temp=0;
- ……………………
- …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
按鍵控制中斷時(shí)鐘.rar
(30.59 KB, 下載次數(shù): 12)
2018-1-24 22:12 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|