80C51F020单片机关于外部中断的简单问题
#include <c8051f020.h> #define uchar unsigned char
#define uint unsigned int
void SYSCLK_Init (void);
void PORT_Init (void);
sbit lcdrs=P2^5;
sbit lcden=P2^7;
sbit lcdwr=P2^6;
sbit key1=P2^0;
sbit key2=P2^1;
sbit key3=P2^2;
sbit key4=P2^3;
uchar k=0;
uchar i=1;
void delay(void)
{
int a=10000;
while(a!=0)
{
a--;
}
}
void write_com(uchar com)
{
lcdrs=0;
P3=com;
delay();
lcden=1;
delay();
lcden=0;
}
void write_date(uchar dat)
{
lcdrs=1;
P3=dat;
delay();
lcden=1;
delay();
lcden=0;
}
void init()
{
lcdwr=0;
lcden=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
}
void main()
{
WDTCN = 0xde;
WDTCN = 0xad;
SYSCLK_Init ();
PORT_Init ();
init();
EA=1;
EX0=1;
IT0=1;
while(1)
{
for(i=1;i<=233;i++)
{write_com(0x80);
write_date(0x31+i);
if(key1==0)
{
key1=1;
delay();
if(key1==0)
{
P0=0XFF;
} }
}
i++;}
}
void SYSCLK_Init (void)
{
OSCICN = 0x05;
}
void PORT_Init (void)
{
XBR0 = 0x00;
XBR1=0X04;
XBR2 = 0x40;
P0MDOUT = 0xFF;
P1MDOUT = 0xFF;
P2MDOUT = 0xFF;
P3MDOUT = 0xFF;
}
void timer0 () interrupt 0
{
write_com(0X01);
}
我的程序是按下外部中断的键就清屏不知道为什么我按下了,KEY1键没反应,我不知道是不是我交叉开关设错了,我要将交叉开关的外部中断0连到P0.0去。是不是我写错了代码呢