- #include <REG51.H>
- sbit S1=P2^0;
- sbit S2=P2^1;
- sbit S3=P2^2;
- sbit S4=P2^3;
- //順序共陽極數碼管段碼表"0~f"
- unsigned char code table[]={
- 0xc0,0xf9,0xa4,0xb0,
- 0x99,0x92,0x82,0xf8,
- 0x80,0x90,0x88,0x83,
- 0xc6,0xa1,0x86,0x8e};
- unsigned char num;
- void main()
- {
- while(1)
- {
- if(!S1||!S2||!S3||!S4)
- num=~P2;
- P0=table[num];
- }
- }
復制代碼
|