本帖最后由 smzcky 于 2016-12-23 21:23 编辑
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "lcd.h"
#include "key.h"
#include "usmart.h"
#include "malloc.h"
#include "MMC_SD.h"
#include "ff.h"
#include "exfuns.h"
#include "fontupd.h"
#include "text.h"
int main(void)
{
u8 static i=0,j=0;
char *C;
u8 key;
u32 a[4]={0};
float b[4]={0};
//u32 c[4]={0};
//int k=0;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);// ÉèÖÃÖжÏÓÅÏȼ¶·Ö×é2
delay_init(); //ÑÓʱº¯Êý³õʼ»¯
uart_init(115200); //´®¿Ú³õʼ»¯Îª9600
LCD_Init(); //³õʼ»¯Òº¾§
LED_Init(); //LED³õʼ»¯
KEY_Init(); //°´¼ü³õʼ»¯
usmart_dev.init(72); //usmart³õʼ»¯
mem_init(); //³õʼ»¯ÄÚ´æ³Ø
exfuns_init(); //ΪfatfsÏà¹Ø±äÁ¿ÉêÇëÄÚ´æ
f_mount(fs[0],"0:",1); //¹ÒÔØSD¿¨
f_mount(fs[1],"1:",1); //¹ÒÔØFLASH.
font_init();
while(1)
{
POINT_COLOR=BLACK;
LCD_DrawRectangle(0,0,240,50);
LCD_DrawRectangle(20,140,100,230);
LCD_DrawRectangle(140,140,220,230);
key=KEY_Scan(0);
//Òƶ¯¹â±ê
if(key==KEY0_PRES)
i++;
if(i>4)
i=0;
if(i==1)
{
POINT_COLOR=RED;
LCD_ShowxNum(40,170,a[0],1,24,0);
}
if(i==2)
{
POINT_COLOR=RED;
LCD_ShowxNum(60,170,a[1],1,24,0);
}
if(i==3)
{
LCD_ShowxNum(160,170,a[2],1,24,0);
}
if(i==4)
{
POINT_COLOR=RED;
LCD_ShowxNum(180,170,a[3],1,24,0);
}
//¶Ôÿλ½øÐмÓÒ»²Ù×÷
if(i==1)
{
if(key==KEY1_PRES)
a[0]++;
if(a[0]>9)
a[0]=0;
}
if(i==2)
{
if(key==KEY1_PRES)
a[1]++;
if(a[1]>9)
a[1]=0;
}
if(i==3)
{
if(key==KEY1_PRES)
a[2]++;
if(a[2]>9)
a[2]=0;
}
if(i==4)
{
if(key==KEY1_PRES)
a[3]++;
if(a[3]>9)
a[3]=0;
}
//½øÐÐÔËËã²¢ÏÔʾ
POINT_COLOR=BLACK;
if(key==WKUP_PRES)
j++;
if(j==0)
{
Show_Str(120,170,200,16,"+",24,0);
b[0]=(a[0]*10+a[1])+(a[2]*10+a[3]);
LCD_ShowxNum(50,25,b[0],4,24,0);
}
if(j==1)
{
Show_Str(120,170,200,16,"-",24,0);
if((a[0]*10+a[1])<(a[2]*10+a[3]))
{
b[1]=(a[2]*10+a[3])-(a[0]*10+a[1]);
Show_Str(120,170,200,24,"-",24,0);
LCD_ShowxNum(50,25,b[1],4,24,0);
}
else
{
b[1]=(a[0]*10+a[1])-(a[2]*10+a[3]);
LCD_ShowxNum(50,25,b[1],4,24,0);
}
}
if(j==2)
{
Show_Str(120,170,200,16,"*",24,0);
b[2]=(a[0]*10+a[1])*(a[2]*10+a[3]);
LCD_ShowxNum(50,25,b[2],4,24,0);
}
if(j==3)
{
Show_Str(120,170,200,16,"/",24,0);
b[3]=(a[0]*10+a[1])/(a[2]*10+a[3]);
/*if(k!=0)
{
b[3]=(float)(a[0]*10+a[1])/(a[2]*10+a[3]);
b[3]=b[3]*100;
c[0]=b[3]/100;
c[1]=b[3]-c[0]*100;
LCD_ShowxNum(50,25,c[0],1,24,0);
Show_Str(65,25,200,24,".",24,0);
LCD_ShowxNum(70,25,c[1],2,24,0);
}
else
{
b[3]=(a[0]*10+a[1])/(a[2]*10+a[3]);
LCD_ShowxNum(50,25,b[3],4,24,0);
}*/
sprintf(C,"%f",b[3]);
LCD_ShowString(50,25,200,16,24,C);
}
if(j>3)
j=0;
POINT_COLOR=BLUE;
LCD_ShowxNum(40,170,a[0],1,24,0);
LCD_ShowxNum(60,170,a[1],1,24,0);
LCD_ShowxNum(160,170,a[2],1,24,0);
LCD_ShowxNum(180,170,a[3],1,24,0);
}
}
|