如下即可:
#include
sbita0 = P2^2;
sbita1 = P2^6;
sbita2 = P1^5;
sbita3 = P3^4;
charbdatabb;
sbitb0 = bb^0;
sbitb1 = bb^1;
sbitb2 = bb^2;
sbitb3 = bb^3;
void main()
{
while(1){
bb = 0;
b0 = a0;
b1 = a1;
b2 = a2;
b3 = a3;
switch(bb)x05{
case 0x01: P0 = 0xC0; break;//显示0
case 0x02: P0 = 0xF9; break;//1
case 0x04: P0 = 0xA4; break;//2
case 0x08: P0 = 0xB0; break;//3
case 0x03: P0 = 0x99; break;//4
case 0x06: P0 = 0x92; break;//5
case 0x0C: P0 = 0x82; break;//6
case 0x09: P0 = 0xF8; break;//7
default:P0 = 0x8E;//F
}
}
}
仿真运行如下: