sbit P2^0 =key0;
sbit P2^1 =key1;
sbit P2^2 =key2;
sbit P2^3 =key3;
sbit P2^4 =key4;
sbit P2^5 =key5;
sbit P2^6 =key6;
sbit P2^7 =key7;
sbit P0^0 =led0;
sbit P0^1 =led1;
sbit P0^2 =led2;
sbit P0^3 =led3;
sbit P0^4 =led4;
sbit P0^5 =led5;
sbit P0^6 =led6;
sbit P0^7 =led7;
假設按鍵按下為低電平,點亮LED用高電平,則示意程式碼如下
if(key0 == 0)
led0 = 1;
if(key1 == 0)
led1 = 1;
if(key2 == 0)
led2 = 1;
if(key3 == 0)
led3 = 1;
...........
............
if(key7 == 0)
led7 = 1;
sbit P2^0 =key0;
sbit P2^1 =key1;
sbit P2^2 =key2;
sbit P2^3 =key3;
sbit P2^4 =key4;
sbit P2^5 =key5;
sbit P2^6 =key6;
sbit P2^7 =key7;
sbit P0^0 =led0;
sbit P0^1 =led1;
sbit P0^2 =led2;
sbit P0^3 =led3;
sbit P0^4 =led4;
sbit P0^5 =led5;
sbit P0^6 =led6;
sbit P0^7 =led7;
假設按鍵按下為低電平,點亮LED用高電平,則示意程式碼如下
if(key0 == 0)
led0 = 1;
if(key1 == 0)
led1 = 1;
if(key2 == 0)
led2 = 1;
if(key3 == 0)
led3 = 1;
...........
............
if(key7 == 0)
led7 = 1;