#include "led.h"
#include "delay.h"
#include "sys.h"
#include "uart.h"
#include "tsensor.h"
#include "rtc.h"
#include "key.h"
#include "adc.h"
//#include "exti.h"
void time_scr(void)
{
char str[20];
sprintf(str,"%d",calendar.w_year);
// putStr(110, 100,2, 1,str);
printf(str,"");
printf("_year");
sprintf(str,"%d",calendar.w_month);
// putStr(150, 100,2, 1,str);
printf(str,"");
printf("_month");
sprintf(str,"%d",calendar.w_date);
// putStr(170, 100,2, 1,str);
printf(str,"");
printf("_date");
switch(calendar.week)
{
case 0:
// putStr(110, 120,2, 1,"Sunday ");
printf(" Sunday ");
break;
case 1:
// putStr(110, 120,2, 1,"Monday ");
printf(" Monday ");
break;
case 2:
// putStr(110, 120,2, 1,"Tuesday ");
printf(" Tuesday ");
break;
case 3:
// putStr(110, 120,2, 1,"Wednesday");
printf(" Wednesday ");
break;
case 4:
// putStr(110, 120,2, 1,"Thursday ");
printf(" Thursday ");
break;
case 5:
// putStr(110, 120,2, 1,"Friday ");
printf(" Friday ");
break;
case 6:
// putStr(110, 120,2, 1,"Saturday ");
printf(" Saturday ");
break;
}
sprintf(str,"%d",calendar.hour);
printf(str,"");
printf("_hour:");
// putStr(110, 140,2, 1,str);
sprintf(str,"%d",calendar.min);
printf(str,"");
printf("min:");
// putStr(135, 140,2, 1,str);
sprintf(str,"%d",calendar.sec);
printf(str,"");
printf("sec");
printf("rnrn");//插入换行
// putStr(160, 140,2, 1,str);
}
void time_i(void)
{
char str[20];
u8 t,tymdhm=0,tmo=0,td=0,th=0,tmi=0,tend=0;
u16 ty=0;
printf( "time set:");
printf("rnrn");//插入换行
printf( "KEY1_PRES:print timernrn");
printf( "KEY2_PRES:switch set year,mon,day,hour,minrnrn");
printf( "KEY3_PRES:plusrnrn");
printf( "KEY4_PRES:set timernrn");
time_scr();
printf( "set time:");
switch(tymdhm)
{
case 0://K1默认不连PC13,默认连接reset复位按键,所以按下K1会复位
sprintf(str,"%d",calendar.w_year);
printf(str,"");
printf( "yearrn");
break;
case 1:
sprintf(str,"%d",calendar.w_month);
printf(str,"");
printf("monthrn");
break;
case 2:
sprintf(str,"%d",calendar.w_date);
printf(str,"");
printf("datern");
break;
case 3:
sprintf(str,"%d",calendar.hour);
printf(str,"");
printf( "hourrn");
break;
case 4:
sprintf(str,"%d",calendar.min);
printf(str,"");
printf( "minrn");
break;
case 5:
sprintf(str,"%d",calendar.sec);
printf(str,"");
printf( "secrn");
break;
// default:
// delay_ms(1);
}
while(1){
t=KEY_Scan(0); //得到键值
switch(t)
{
case KEY1_PRES://K1默认不连PC13,默认连接reset复位按键,所以按下K1会复位
tymdhm=0,ty=0,tmo=0,td=0,th=0,tmi=0;
time_scr();
break;
case WKUP_PRES:
LED2=!LED2;
tymdhm+=1;
if (tymdhm==5 )tymdhm=0;
printf( "set time:");
switch(tymdhm)
{
case 0://K1默认不连PC13,默认连接reset复位按键,所以按下K1会复位
sprintf(str,"%d",calendar.w_year);
printf(str,"");
printf( "yearrn");
break;
case 1:
sprintf(str,"%d",calendar.w_month);
printf(str,"");
printf("monthrn");
break;
case 2:
sprintf(str,"%d",calendar.w_date);
printf(str,"");
printf("datern");
break;
case 3:
sprintf(str,"%d",calendar.hour);
printf(str,"");
printf( "hourrn");
break;
case 4:
sprintf(str,"%d",calendar.min);
printf(str,"");
printf( "minrn");
break;
case 5:
sprintf(str,"%d",calendar.sec);
printf(str,"");
printf( "secrn");
break;
// default:
// delay_ms(1);
}
break;
case KEY3_PRES:
LED3=!LED3;
switch(tymdhm)
{
case 0://K1默认不连PC13,默认连接reset复位按键,所以按下K1会复位
ty+=1;
sprintf(str,"%d",calendar.w_year+ty);
printf( str,"year");
printf("year");
break;
case 1:
tmo+=1;
sprintf(str,"%d",calendar.w_month+tmo);
printf( str,"month");
printf( "month");
break;
case 2:
td+=1;
sprintf(str,"%d",calendar.w_date+td);
printf( str,"date");
printf( "date");
break;
case 3:
th+=1;
sprintf(str,"%d",calendar.hour+th);
printf( str,"hour");
printf( "hour");
break;
case 4:
tmi+=1;
sprintf(str,"%d",calendar.min+tmi);
printf( str,"min");
printf( ":min:");
break;
case 5:
sprintf(str,"%d",calendar.sec);
printf( str,"sec");
break;
// default:
// delay_ms(1);
}
break;
case KEY4_PRES:
ty+=calendar.w_year;
tmo+=calendar.w_month;
while((tmo-12)>0)tmo-=12;
td+=calendar.w_date;
switch(tmo)
{
case 1:case 3:case 5:case 7:case 8:case 10:case 12://K1默认不连PC13,默认连接reset复位按键,所以按下K1会复位
while((td-31)>0)td-=31;
break;
case 4:case 6:case 9:case 11:
while((td-30)>0)td-=30;
break;
case 2:
while((td-29)>0)td-=29;
break;
// default:
// delay_ms(1);
}
th+=calendar.hour;
while((th-24)>0)th-=24;
tmi+=calendar.min;
while((tmi-60)>0)tmi-=60;
RTC_Set(ty,tmo,td,th,tmi,0);
tend=1;
// return 0;
break;
// default:
// delay_ms(1);
}
if(tend==1)break;
}
}
//开发板范例代码3
//串口实验
void KEY2_main(void)
{
printf( "adc set:");
printf("rnrn");//插入换行
printf( "KEY1_PRES:adc1,3,5路采集rnrn");
printf( "KEY2_PRES:adc2路采集rnrn");
printf( "KEY3_PRES:Temperature采集 rnrn");
printf( "KEY4_PRES:回主菜单rnrn");
// unsigned char tem[20];
// initLCD();
//
// printf( "MM32 Board");
// printf("rnrn");//插入换行
while(1){
unsigned char ucFlag=0;
unsigned int uiADData=0;
float fValue = 0;
u16 average=0;
u8 i,t,tend;
t=KEY_Scan(0); //得到键值
switch(t)
{
case KEY1_PRES://K1默认不连PC13,默认连接reset复位按键,所以按下K1会复位
LED1=!LED1;
// time_scr();
ADC1_SingleChannel( ADC_Channel_1);
// initLCD();
//
// putStr(110, 20,2,1, "MM32 Dev Board");
// putStr(110, 40,2,1, "ADC TEST");
// putStr(110, 60,2,1, "@MindMotion");
// putStr(110, 80,2,1, "2016/09/02");
// putStr(110, 120,2,1, "ADC_CH1_VAL:");
// putStr(110, 140,2,1, "ADC_CH1_VOL:0.000V");
for(i=0;i<4;i++)
{
/*读取当前转换数据*/
ucFlag=ADC1_SingleChannel_Get( ADC_Channel_1, &uiADData);
if(ucFlag==1)
{
ucFlag=0;
fValue = ((float)uiADData/4096)*3.3;
printf( "ADC_1_VAL:");
printf("%d",uiADData);
printf("rn");//插入换行
printf( "ADC_1_VOL:");
printf("%.3f",fValue);
printf("rn");//插入换行
// sprintf(val,"%d",uiADData);
// sprintf(vol,"%.3f",fValue);
// putStr(205, 120,2,1, " ");
// putStr(205, 120,2,1, val);
// putStr(205, 140,2,1, vol);
delay_ms(300);
}
}
ADC1_SingleChannel( ADC_Channel_5);
// initLCD();
//
// putStr(110, 20,2,1, "MM32 Dev Board");
// putStr(110, 40,2,1, "ADC TEST");
// putStr(110, 60,2,1, "@MindMotion");
// putStr(110, 80,2,1, "2016/09/02");
// putStr(110, 120,2,1, "ADC_CH1_VAL:");
// putStr(110, 140,2,1, "ADC_CH1_VOL:0.000V");
for(i=0;i<4;i++)
{
/*读取当前转换数据*/
ucFlag=ADC1_SingleChannel_Get( ADC_Channel_5, &uiADData);
if(ucFlag==1)
{
ucFlag=0;
fValue = ((float)uiADData/4096)*3.3;
printf( "ADC_3_VAL:");
printf("%d",uiADData);
printf("rn");//插入换行
printf( "ADC_3_VOL:");
printf("%.3f",fValue);
printf("rn");//插入换行
// sprintf(val,"%d",uiADData);
// sprintf(vol,"%.3f",fValue);
// putStr(205, 120,2,1, " ");
// putStr(205, 120,2,1, val);
// putStr(205, 140,2,1, vol);
delay_ms(300);
}
}
ADC1_SingleChannel( ADC_Channel_7);
// initLCD();
//
// putStr(110, 20,2,1, "MM32 Dev Board");
// putStr(110, 40,2,1, "ADC TEST");
// putStr(110, 60,2,1, "@MindMotion");
// putStr(110, 80,2,1, "2016/09/02");
// putStr(110, 120,2,1, "ADC_CH1_VAL:");
// putStr(110, 140,2,1, "ADC_CH1_VOL:0.000V");
for(i=0;i<4;i++)
{
/*读取当前转换数据*/
ucFlag=ADC1_SingleChannel_Get( ADC_Channel_7, &uiADData);
if(ucFlag==1)
{
ucFlag=0;
fValue = ((float)uiADData/4096)*3.3;
printf( "ADC_5_VAL:");
printf("%d",uiADData);
printf("rn");//插入换行
printf( "ADC_5_VOL:");
printf("%.3f",fValue);
printf("rn");//插入换行
// sprintf(val,"%d",uiADData);
// sprintf(vol,"%.3f",fValue);
// putStr(205, 120,2,1, " ");
// putStr(205, 120,2,1, val);
// putStr(205, 140,2,1, vol);
delay_ms(300);
}
}
break;
case WKUP_PRES:
LED2=!LED2;
ADC1_SingleChannel( ADC_Channel_4);
// initLCD();
//
// putStr(110, 20,2,1, "MM32 Dev Board");
// putStr(110, 40,2,1, "ADC TEST");
// putStr(110, 60,2,1, "@MindMotion");
// putStr(110, 80,2,1, "2016/09/02");
// putStr(110, 120,2,1, "ADC_CH1_VAL:");
// putStr(110, 140,2,1, "ADC_CH1_VOL:0.000V");
for(i=0;i<4;i++)
{
/*读取当前转换数据*/
ucFlag=ADC1_SingleChannel_Get( ADC_Channel_4, &uiADData);
if(ucFlag==1)
{
ucFlag=0;
fValue = ((float)uiADData/4096)*3.3;
printf( "ADC_2_VAL:");
printf("%d",uiADData);
printf("rn");//插入换行
printf( "ADC_2_VOL:");
printf("%.3f",fValue);
printf("rn");//插入换行
// sprintf(val,"%d",uiADData);
// sprintf(vol,"%.3f",fValue);
// putStr(205, 120,2,1, " ");
// putStr(205, 120,2,1, val);
// putStr(205, 140,2,1, vol);
delay_ms(300);
}
}
break;
case KEY3_PRES:
LED3=!LED3;
T_Adc_Init(); //ADC初始化
printf( "Temperature TEST");
printf("rnrn");//插入换行
printf( "@MindMotion");
printf("rnrn");//插入换行
printf( "TEMP_VAL:");
printf( "C");
printf("rnrn");//插入换行
for(i=0;i<10;i++)
{
T_Get_Adc_Average(ADC_Channel_8,&uiADData);
average+=uiADData;
if(i==9)
average=average/10;
}
fValue=(float)average*(3.3/4096); //电压值
fValue=(fValue-1.5)/0.00478+25; //转换为温度值
printf( "TEMP_VAL:");
printf("%.2f",fValue);
printf("rnrn");//插入换行
// putStr(185, 120,2,1,tem);
// delay_ms(1250);
// average=0;
break;
case KEY4_PRES:
LED4=!LED4;
tend=1;
// return 0;
break;
// default:
// delay_ms(1);
}
if(tend==1)break;
}
}
////////////////////////////////////////////////////////////////////////////////
int main(void)
{
u8 t,t1;
delay_init(); //延时函数初始化
uart_initwBaudRate(9600); //串口初始化为9600
LED_Init(); //初始化与LED连接的硬件接口
KEY_Init(); //初始化与按键连接的硬件接口
T_Adc_Init(); //ADC初始化
// initLCD();
//
// putStr(110, 20,2, 1, "MM32 Dev Board");
// putStr(110, 40,2, 1, "RTC TEST");
// putStr(110, 60,2, 1, "@MindMotion");
// putStr(110, 80,2, 1, "2016/09/02");
printf( "MM32 Board");
printf("rn");//插入换行
while(RTC_Init()) //RTC初始化 ,一定要初始化成功
{
// putStr(110, 100,2, 1,"RTC ERROR! ");
delay_ms(800);
printf("RTC Trying...");
// putStr(110, 100,2, 1,"RTC Trying...");
}
// EXTIX_Init();
printf("rn");//插入换行
// putStr(110, 100,2, 1," - - ");
// putStr(110, 140,2, 1," : : ");
while(1)
{
t=KEY_Scan(0); //得到键值
// if (t==0){}else{printf("%d",t);}//插入换行 }
// printf(" KEY down rnrn");
switch(t)
{
case KEY1_PRES://K1默认不连PC13,默认连接reset复位按键,所以按下K1会复位
printf("KEY1_PRES down rn");
printf("KEY1_PRES ");
time_i();
break;
case WKUP_PRES:
printf("KEY2_PRES down rn");
KEY2_main();
LED2=!LED2;
break;
case KEY3_PRES:
printf("KEY3_PRES down rn");
LED3=!LED3;
break;
case KEY4_PRES:
printf("KEY4_PRES down rn");
LED4=!LED4;
break;
// default:
// delay_ms(1);
}
if(t1!=calendar.min)
{
t1=calendar.min;
time_scr();
LED1=!LED1;
}
// delay_ms(1);
}
// while(1);
}
更多回帖