代码是这样的,但实现不了SW1的按键1的功能,我中断实现不了
#include"iocc2530.h"
#define D3 P1_0
#define D4 P1_1
#define SW1 P1_2
#define D5 P1_3
#define D6 P1_4
#define SW2 P0_1
unsigned char count=0;
unsigned char k_num=0;
unsigned char Count=0;
unsigned char K_num=0;
int i;
void delay(int t){
for(int i=0;i<t;i++){
for(int j=0;j<240;j++);
}
}
void init_LED(){
for(i=0;i<2;i++){
P1SEL &=~0x1b;
P1DIR |=0x1b;
D3=1;
D4=1;
D5=1;
D6=1;
delay(1000);
D3=0;
D4=0;
D5=0;
D6=0;
delay(1000);
}
D3=1;
D4=1;
D5=1;
D6=1;
}
void Init_SW(){
P1SEL &=~0X04;
P1DIR &=~0X04;
P0SEL &=~0x01;
P0DIR &=~0x01;
}
void Init_T1(){
EA=1;
T1IE=1;
T1CCTL0|=0X04;
T1CC0L=0X30;
T1CC0H=0XFA;
T1CTL|=0X0e;
}
void Scan_Key(){
if(SW1==0){
delay(10);
if(SW1==0){
while(SW1==0);
count=0;
k_num++;
if(k_num>3){
k_num=3;
}
}
}
if(count >4){
switch(k_num){
case 2:
D4=~D4;
delay(10);
break;
case 3:
D3=~D3;
delay(10);
break;
}
k_num=0;
count=0;
}
}
void Scan_key(){
if(SW2==0){
delay(10);
if(SW2==0){
while(!SW2);
Count++;
K_num++;
if(K_num>3){
K_num=3;
}
}
}
if(Count>4){
switch(K_num){
case 2:
D6=~D6;
delay(10);
break;
case 3:
D5=~D5;
delay(10);
break;
}
K_num=0;
Count=0;
}
}
void IAR_Init(){
IEN2 |= 0X10; //选择P1端口 使P1
P1IEN |= 0X04;
PICTL |= 0X02;
EA = 1;//总中断
}
void main(){
Init_T1();
init_LED();
Init_SW();
Init_T1();
while(1){
Scan_Key();
Scan_key();
}
}
#pragma vector=T1_VECTOR
__interrupt void T1_SIR(void){
T1STAT &=~0x20;
if(k_num !=0&&SW1 !=0){
count++;
}
if(K_num !=0&&SW2 !=0){
Count++;
}
}
#pragma vector = P1INT_VECTOR
__interrupt void SW1_ISR(void){
if(P1IF==1){
if(P1IFG & 0X04){
if(k_num==1){
delay(500);
if(k_num==1){
D3=1;
D4=1;
D5=1;
D6=1;
delay(1000);
D3=0;
D4=0;
D5=0;
D6=0;
}
}
}
}
count=0;
k_num=0;
P1IF = 0;
P1IFG &= ~0X04;
}
|