这个程序运行时,在不按下按键的时候也会进入中断。不知道什么原因!求帮助!
#include <msp430X16X.h>
#include "delay.h"
#include "data.h"
#include "cry12864.h"
#include "d1302.h"
#define keyin (P1IN & 0x0f)
int keyval=0;
int flag= 1;
unsigned char w=7;
int fen,shi,miao;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; //关狗
P1IES = 0x0f; //p2.0-p2.3下降沿中断
P1IE = 0x0f; //打开中断使能
P1IFG = 0x00;
P1DIR = BIT4;//设置p2.0-p2.3为输入状态,p2.4为输出
P1OUT = 0;
Ini_Lcd(); //初始化液晶
Write_Cmd(0x01); //清屏
Clear_GDRAM();
Reset_DS1302(); //初始化时
//Set_DS1302(wdata);
_EINT();
while(1)
{
if(flag==1)
{
// Write_Cmd(0x01); //清屏
BurstRead1302(rdata);
fen=rdata[1]&0x0f;fen+=(rdata[1]>>4)*10;
shi=rdata[2]&0x0f;shi+=(rdata[2]>>4)*10;
miao=rdata[0]&0x0f;miao+=(rdata[0]>>4)*10;
shu(0,7,shi,2); //显示小时
shu(0,10,fen,2); //显示分钟
shu(0,13,miao,2); //显示分钟
//zifu(0,9,2,1);
// shu(0,7,shi,2);
}
else
{
shu(0,7,shi,2); //显示小时
shu(0,10,fen,2); //显示分钟
shu(0,13,miao,2); //显示分钟
}
}
}
#pragma vector = PORT1_VECTOR
__interrupt void PORT1_ISR(void)
{
switch(P1IFG)
{
case 0x01:
if(keyin == 0x0e)
{
delay_ms(12);
if(keyin == 0x0e)
{
while(keyin != 0x0f);
flag=0;
Write_Cmd(0x01); //清屏
DrowAnywhere(w*8,0,8,16,fanhei);
if(w<12)
w=w+0x03;
else
w=7;
DrowAnywhere(w*8,0,8,16,fanbai);
P1IFG = 0x00;
}
}
case 0x02:
if(keyin == 0x0d)
{
delay_ms(12);
if(keyin == 0x0d)
{
while(keyin != 0x0f);
Write_Cmd(0x01); //清屏
DrowAnywhere(w*8,0,8,16,fanbai);
if(w==7)
{
shi++;
if(shi == 24)
shi = 0;
shu(0,7,shi,2);
}
if(w==10)
{
fen++;
if(fen == 60)
fen = 0;
shu(0,10,fen,2);
}
else
{
miao++;
if(miao == 60)
miao = 0;
shu(0,10,miao,2);
}
}
P1IFG = 0x00;
}
case 0x04:
if(keyin == 0x0b)
{
delay_ms(12);
if(keyin == 0x0b)
{
while(keyin != 0x0f);
Write_Cmd(0x01); //清屏
DrowAnywhere(w*8,0,8,16,fanbai);
if(w==7)
{
shi--;
if(shi < 0)
shi = 23;
shu(0,7,shi,2);
}
if(w==10)
{
fen--;
if(fen < 0)
fen = 59;
shu(0,10,fen,2);
}
else
{
miao--;
if(miao < 0)
miao = 59;
shu(0,10,miao,2);
}
}
P1IFG = 0x00;
}
case 0x08:
if(keyin == 0x07)
{
delay_ms(12);
if(keyin == 0x07)
{
while(keyin != 0x0f);
wdata[0] = 0x00;
wdata[1] = (fen%10)&0x0f;wdata[1] += (fen/10)<<4;
wdata[2] = (shi%10)&0x0f;wdata[2] += (shi/10)<<4;
Set_DS1302(wdata);
flag = 1;
Write_Cmd(0x01); //清屏
}
P1IFG = 0x00;
}
break;
default:
while(keyin != 0x0f);
P1IFG = 0x00;
break;
}
}
此帖出自
小平头技术问答
一周热门 更多>