《嵌入式系统与接口技术实验》综合设计报告班级13物联网姓名邓浩明学号1308040103指导教师沈兰【综合应用实验目的】【综合应用实验题目】利用GEC2410实验板,设计并实现一个综合应用系统【综合应用实验要求】要用到已学过的所有GEC2410模块,包括:GPIO端口控制:LED灯模块中断控制:按键外部中断,内部中断(TimerorTicktime)UART串口:键盘输入,显示器输出PWM定时器:定时中断,tout0输出驱动蜂鸣器蜂鸣器:实时时钟:当前时间,闹钟,节拍中断看门狗定时器:WTD中断,Reset【相关理论知识】【实现方案】主函数#include2410addr.h#include2410lib.h#includedef.hexternvoidwatchdog_test(void);externvoid__irqwatchdog_int(void);externvoid__irqTick_Isr(void);externvoidOpenRtc(void);externvoidBUZZER_PWM_Test(void);externvoidEint_Init(void);externvoidEnable_Eint(void);externvoidwatchdog_test(void);externchart;intMain(void){chara,b,c;ChangeClockDivider(1,1);ChangeMPllValue(0xa1,0x3,0x1);Port_Init();Uart_Select(0);Uart_Init(0,115200);Eint_Init();//外部中断初始化OpenRtc();//打开实时时钟节拍中断watchdog_test();Uart_Printf(**********HELLO**********\n);Uart_Printf(1.PlanowhitLED\n);Uart_Printf(2.Piano2\n);DisableIrq(BIT_WDT);DisableIrq(BIT_EINT0);DisableIrq(BIT_EINT2);DisableIrq(BIT_EINT8_23);//关这4个中断,为了在键盘没按'1'或'3'之前拒绝产生这4种中断Uart_Printf(\n1.2.3\n);//1是键盘电子琴,2是开发板按键电子琴while(1){a=Uart_Getch();Delay(300);if(a=='1'){Uart_Printf(ESCbacktomenu\n);BUZZER_PWM_Test();}if(a=='2'){Uart_Printf(ESCbacktomenu\n);Enable_Eint();{b=Uart_Getch();Delay(300);if(b==ESC_KEY)break;}}elseUart_Printf(Error!pleasetryagain);}}#include2410addr.h#include2410lib.h#includedef.h//使用K1按键触发EINT0,EINT0-GPF0//使用K3按键触发EINT2,EINT2-GPF2//使用K5按键触发EINT11,EINT11-GPG3//使用K7按键触发EINT19,EINT19-GPG11//KSCAN0-GPE11intk=1;chart;char*week[8]={,SUN,MON,TUES,WED,THURS,FRI,SAT};intyear,month,date,weekday,hour,min,sec;void__irqwatchdog_int(void);void__irqTick_Isr(void);voidGet_Rtc(void);voidBuzzer_Freq_Set(U32freq);voidBuzzer_Stop(void);void__irqEint0_ISR(void);void__irqEint2_ISR(void);void__irqEint11_19_ISR(void);voidwatchdog_test(void){//initializeinterruptregisters允许WatchDog中断ClearPending(BIT_WDT);//往中断向量表填WatchDog中断向量pISR_WDT=(unsigned)watchdog_int;//Prescalervalue=100、clockdivisionfactor=128//t_watchdog=1/[PCLK/(Prescalervalue+1)/Division_factor]=0.00025856//disablewatchdogrWTCON=((1008)|(33));//看门狗时钟周期T=WTCNT*t_watchdog=4S//看门狗喂狗rWTDAT=15000;rWTCNT=15000;rWTCON|=((15)|(12));//enableWatchdogtimerangwatchdoginterrupt//开中断EnableIrq(BIT_WDT);}/****watchdog_int****/void__irqwatchdog_int(void){//清除中断rGPFDAT=rGPFDAT&~(17);Delay(2000);rGPFDAT=rGPFDAT|(17);rGPFDAT=rGPFDAT&~(16);Delay(2000);rGPFDAT=rGPFDAT|(16);rGPFDAT=rGPFDAT&~(15);Delay(2000);rGPFDAT=rGPFDAT|(15);rGPFDAT=rGPFDAT&~(14);Delay(2000);rGPFDAT=rGPFDAT|(14);}void__irqTick_Isr(void){k=-k;if(k==1)rGPFDAT=rGPFDAT&~(154);if(k==-1)rGPFDAT=rGPFDAT|(154);//Get_Rtc();//Uart_Printf(RTCTIME:%4x-%02x-%02x-%s-%02x:%02x:%02x\n,year,month,date,week[weekday],hour,min,sec);ClearPending(BIT_TICK);}voidOpenRtc(void){pISR_TICK=(unsigned)Tick_Isr;rTICNT=0xBF;//Ticktimeinterruptenable;Ticktimecountvalue=63EnableIrq(BIT_TICK);//openRTCTICKINTERRUPT}voidGet_Rtc(void){rRTCCON=0x01;//RTC读写使能,选择BCD时钟、计数器,无复位,1/32768if(rBCDYEAR==0x99)year=0x1999;elseyear=0x2000+rBCDYEAR;month=rBCDMON;date=rBCDDATE;weekday=rBCDDAY;hour=rBCDHOUR;min=rBCDMIN;sec=rBCDSEC;rRTCCON=0x0;//RTC读写禁止,选择BCD时钟、计数器,无复位,1/32768}voidBUZZER_PWM_Test(void){//U16freq;//Uart_Printf(\nKEYCONTROLBUZZER\n);//Uart_Printf(Press'ESC'keytoExitthisprogram!\n\n);while(1){U8key=Uart_Getch();//通过异步串行通道Uart输入按键值switch(key){case'1':Buzzer_Freq_Set(200);rGPFDAT=rGPFDAT&~(14);Delay(800);rGPFDAT=rGPFDAT|(14);Buzzer_Stop();break;case'2':Buzzer_Freq_Set(300);rGPFDAT=rGPFDAT&~(15);Delay(800);rGPFDAT=rGPFDAT|(15);Buzzer_Stop();break;case'3':Buzzer_Freq_Set(500);rGPFDAT=rGPFDAT&~(16);Delay(800);rGPFDAT=rGPFDAT|(16);Buzzer_Stop();break;case'4':Buzzer_Freq_Set(800);rGPFDAT=rGPFDAT&~(17);Delay(800);rGPFDAT=rGPFDAT|(17);Buzzer_Stop();break;case'5':Buzzer_Freq_Set(1000);rGPFDAT=rGPFDAT&~(14);Delay(800);rGPFDAT=rGPFDAT|(14);Buzzer_Stop();break;case'6':Buzzer_Freq_Set(1200);rGPFDAT=rGPFDAT&~(15);Delay(800);rGPFDAT=rGPFDAT|(15);Buzzer_Stop();break;case'7':Buzzer_Freq_Set(1400);rGPFDAT=rGPFDAT&~(16);Delay(200);rGPFDAT=rGPFDAT|(16);Buzzer_Stop();break;}//Buzzer_Freq_Set(freq);//Uart_Printf(\tFreq=%d\n,freq);//通过异步串行通道Uart输出频率if(key==ESC_KEY){Buzzer_Stop();//停止蜂鸣器//{break;}//Uart_Printf(\nChoiceagain\n);return;}}}voidBuzzer_Freq_Set(U32freq){rGPBCON=rGPBCON&~(30)|(11);//setGPB0astout0,pwmoutputrTCFG0=rTCFG0&~0xff|15;//prescaler=15rTCFG1=rTCFG1&~0xf|2;//divider=1/8rTCNTB0=(PCLK7)/freq;//rTCNTB0=PCLK/{(prescaler+1)*divider*freq}rTCMPB0=rTCNTB01;//占空比50%//disabledeadzone,auto-reload,inv-off,updateTCNTB0&TCMPB0,starttimer0rTCON=rTCON&~0x1f|(04)|(13)|(02)|(11)|(1);rTCON&=~(11);//clearmanualupdatebit}voidBuzzer_Stop(void){rGPBCON|=1;rGPBCON=rGPBCON&~3|1;//setGPB0asoutputrGPBDAT&=~1;//output0}/***********外部中断初始化************/voidEint_Init(void){//设置GPE11为输出0rGPECON=(rGPECON|(322))&~(222);rGPEUP|=(111);rGPEDAT&=~(111);rGPFCON=rGPFCON&~(3)|(11);//GPF0设置为EINT0rGPFCON=rGPFCON&~(34)|(15);//GPF2设置为EINT2rGPGCON=rGPGCON&~(36)|(17);//GPG3设置为EINT11rGPGCON=rGPGCON&~(322)|(123);//G