/*************************************************************************
** 文件名: LSD-TEST430F5529-01-LCD.c
** 相关文件: lcdoperate.h;
**************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <msp430x552x.h>
#include "lcdoperate.h"
#include <math.h>
#define pi 3.1415926
void Init_Clk(void);
void systeminit(void);
void TA_init(void);
void port1_init(void);
unsigned char Scan(void); // 矩阵键盘扫描
void ClearScreen();
void delay(int); //声明延时函数
void Result();
void exp_correct( );
char *function(char a[]);
/*************************************************************/
/*全局变量定义*/
/*************************************************************/
uchar str[30];
uchar *value;
int count=0;
int flag=0;
int flag1=0;
int resultflag=0;
char rec_res[];
unsigned char key_code; // 返回的键盘扫描码
//unsigned int key_value; 键盘对应的数字
int shift=0; // 复用标志位
double ret_res;
/*************************************************************************
** 功能: 主函数
*************************************************************************/
void main()
{
WDTCTL = WDTPW + WDTHOLD; //关看门狗
systeminit(); //系统初始化
initLCDM();
TA_init();
port1_init();
ClearRAM(0,0,128,8); //清屏
_EINT();
WriteScreen(gImage_128x64LSD); //显示logo
LPM0;
ClearRAM(0,0,128,8);
while(1)
{
if (flag==1) //键盘按下标志,判断是否有键按下
{
flag=0;
key_code = Scan(); // 调用扫描程序,返回扫描码
switch(key_code)
{ //清除键盘按下标志
case 0x8E:
delay(30);
value="0";
count++;
strcat(str,value);
Display_String((count-1)%16,2*((count-1)/16),value);
break;
case 0x8D:
if(shift==1)
{
count--;
ClearRAM(count%16,2*(count/16),8,8);//清除块yiwei
str[count]='\0';
shift=0;
break;
}
else
value=".";
count++;
strcat(str,value);
Display_String((count-1)%16,2*((count-1)/16),value);
break;
case 0x8B:
if(shift==1)
{
ClearScreen();
shift=0;
break;
}
else
value="=";
count++;
strcat(str,value);
Display_String((count-1)%16,2*((count-1)/16),value);
exp_correct();
Result();
break;
case 0x87: shift=1; //shift为复用键
break;
case 0x4E:
delay(30);
value="1";
count++;
strcat(str,value);
Display_String((count-1)%16,2*((count-1)/16),value);
break;
case 0x4D:
value="2";
count++;
strcat(str,value);
Display_String((count-1)%16,2*((count-1)/16),value);
break;
case 0x4B:
if(shift==1)
{
value="log";
count=count+3;
strcat(str,value);
Display_String((count-1)%16,2*((count-1)/16),value);
shift=0;
break;
}
else
value="3";
count++;
strcat(str,value);
Display_String((count-1)%16,2*((count-1)/16),value);
break;
case 0x47:
delay(6);
if(shift==1)
{
value="/";
count++;
strcat(str,value);
Display_String((count-1)%16,2*((count-1)/16),value);
shift=0;
break;
}
else
value="*";
count++;
strcat(str,value);
Display_String((count-1)%16,2*((count-1)/16),value);
break;
case 0x2E:
value="4";
count++;
strcat(str,value);
Display_String((count-1)%16,2*((count-1)/16),value);
break;
case 0x2D:
if(shift==1)
{
value="cot";
count=count+3;
strcat(str,value);
Display_String((count-1)%16,2*((count-1)/16),value);
shift=0;
break;
}
else
value="5";
count++;
strcat(str,value);
Display_String((count-1)%16,2*((count-1)/16),value);
break;
case 0x2B:
delay(30);
if(shift==1)
{
value="tan";
count=count+3;
strcat(str,value);
Display_String((count-1)%16,2*((count-1)/16),value);
shift=0;
break;
}
else
value="6";