以下是我整理的程序,想实现的功能是三个按键,一个是按一下增加10,一个是按一下减少10,最后个是复位到0。但是错误报告identifier “ key” is undefined,dentifier “ keys” is undefined.
#include<msp430g2553.h>
#include"NOKIA_LCD_BSP.H"
#define KEY_UP 1 //0000 0001b
#define KEY_DOWN 2 //0000 0010b
#define KEY_RET 4 //0000 0100b
unsigned char DISP_V[]={"input:"};
void key_scan(void);
void main(void)
{
unsigned char DISP_NumberD[]={"0000 mA"};
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR=0xf8; // P1.4-P1.7输出
LCD_INIT(); //LCD初始化
LCD_write_byte(0x20,COMMAND); //LCD基本指令设置
key_scan();
while(1)
{
LCD_write_string_8_5(DISP_V,0,0);
LCD_write_string_8_5(DISP_NumberD,3,1);
}
}
unsigned char kEY;
unsigned char kEYS; //p1.0,P1.1 KEY
void key_scan(void)
{
KEY=(P1IN&0x07);
if(KEY==KEY_UP) //按下增加键
{
if(KEYS==0)
KEYS+=100;
else KEYS+=10;
}
if(KEY==KEY_DOWN) //按下减小键
{
if(KEYS==0)
KEYS=0;
else KEYS-=10;
}
if(KEY==KEY_RET) //按下复位键
{
KEYS=0;
}
}
此帖出自
小平头技术问答
一周热门 更多>