代码:
#include "iocc2530.h"
#define uchar unsigned char
#define uint unsigned int
#define D3 P1_0
#define D4 P1_1
#define D5 P1_3
#define D6 P1_4
#define SW1 P1_2
#define SW2 P0_1
#define LIGHT P1_7
void delay_ms(int x){
for(int i=0;i<x;i++)
for(int j=0;j<535;j++);
}
uint keyFlag =0;
void keyScan(){
if(SW1==0){
delay_ms(10);
if(SW1==0){
keyFlag++;
if(keyFlag==5) keyFlag=4;
while(SW1==0);
}
}
if(SW2==0){
delay_ms(10);
if(SW2==0){
keyFlag=0;
while(SW2==0);
}
}
}
void main(){
P1DIR |= 0X9B;
D3=D4=D5=D6=1;
while(1){
keyScan();
switch(keyFlag){
case 1: D4=1;
D3=1;
D6=0;
D5=0;
LIGHT = 0;
break;
case 2: D4=0;
D3=1;
D6=1;
D5=0;
LIGHT = 0;
break;
case 3: D4=0;
D3=0;
D6=1;
D5=1;
LIGHT = 0;
break;
case 4: D4=1;
D3=0;
D6=0;
D5=1;
LIGHT = 1;
break;
case 0: D4=1;
D3=1;
D6=1;
D5=1;
LIGHT = 0;
break;
}
}
}