1上海电力学院嵌入式系统课程设计报告题目:电子词典的设计姓名:学号:院系:专业年级:同组成员:年月日2一、实验内容及要求在LCD屏幕左侧绘制出单词输入框和释义显示框以及一个搜索键,右侧绘制4*4键盘按钮,模拟出简易电子词典的功能,按钮操作用触摸屏或键盘实现均可。实现功能:(1)LCD屏幕上显示4*4键盘,显示单词及其翻译、例句。(2)一个键可完成2个英文字母的输入,如左上角第一个键可实现输入a,b两个字母,第一次按下时为输入a,如果需输入b,只需连续快速按键两次即可。(3)在输入完单词后,点击搜索键,即可在释义显示框中显示该单词的词性、中文解释、示例词组和句子等。(4)当发现输入的单词在库中不存在时,可实现将该单词添加入库的操作。二、设计思路(1)通过LCD显示模块画出电子词典操作界面。(2)对应界面中各键的位置设置键盘对应键值。(3)设定功能键,实现以下3个功能:①退格键:删除最后一位字母;②搜索∕保存键:对输入框的单词进行判断,若单词存在于词库中,则显示单词词性、词义、例句;若单词不存在则自动进行保存;③转换键:按下后,字母键输出对应的第二个字母。(4)按键后赋值并显示。三、软件构架开始LCD模块键盘模块结束3四、模块分析(1)键盘模块流程图:源代码:/**********************************************************************************************File:keyboard.c*Author:embest*Desc:keyboardsourcecode*History:*********************************************************************************************//*---includefiles---*/开始键盘初始化键盘是否按下Y读取键值是否是功能键YN执行功能赋值显示结束N4#include44b.h#include44blib.h#includedef.h#includekeyboard.h#includelcd.h#includedict.h#ifndefKEY_INT#defineKEY_INT#endif#ifndefBUT_INT#defineBUT_INT#endif/*---globalvariables---*/intinput_char,n=0;charword[20];intwordIndex=0;intx=15;intnum=0;intcounter=0;/*keyboardcontroladdress*/volatileUCHAR*keyboard_base=(UCHAR*)0x06000000;/*---functiondeclare---*/voidinit_keyboard();voidclose_keyboard();voidKeyboardInt(void);//__attribute__((interrupt(IRQ)));voidEint4567Isr(void);//__attribute__((interrupt(IRQ)));/*---functioncode---*//**********************************************************************************************name:Test_Keyboard*func:testkeyboard*para:none*ret:none*modify:*comment:********************************************************************************************/voidTest_Keyboard()5{Uart_Printf(\nKeyboardTestExample\n);Uart_Printf(\nPleasepressonekeyonkeyboardandlookatLED...\n);//initkeyboardinit_keyboard();while(1);//closekeyboard//close_keyboard();}/**********************************************************************************************name:init_keyboard*func:initkeyboardinterrupt*para:none*ret:none*modify:*comment:********************************************************************************************/externvoidisrEINT1(void);externvoidisrEint4567(void);voidinit_keyboard(){/*enableinterrupt*/rINTMOD=0x0;rINTCON=0x1;/*setEINT1interrupthandler*/rINTMSK=~(BIT_GLOBAL|BIT_EINT1|BIT_EINT4567);pISR_EINT1=(int)isrEINT1;pISR_EINT4567=(int)isrEint4567;/*PORTG*/rPCONG=0xffff;//EINT7~0rPUPG=0x0;//pullupenablerEXTINT=rEXTINT|0x20;//EINT1fallingedgemoderI_ISPC=BIT_EINT1|BIT_EINT4567;//clearpendingbitrEXTINTPND=0xf;//clearEXTINTPNDreg}6/**********************************************************************************************name:close_keyboard*func:closekeyboardinterrupt*para:none*ret:none*modify:*comment:********************************************************************************************/voidclose_keyboard(){pISR_EINT1=NULL;pISR_EINT4567=NULL;/*Maskinterrupt*/rINTMSK=rINTMSK|BIT_EINT1|BIT_EINT4567;}/**********************************************************************************************name:KeyboardInt*func:keyboardinterrupthandlerfunction*para:none*ret:none*modify:*comment:********************************************************************************************/voidKeyboardInt(void){intnTemp,i,j,k,m=0;charbbyte;rI_ISPC=BIT_EINT1;//clearpendingbitcharpbyte[10];nTemp=key_read();if(nTemp-1){//Lcd_Draw_HLine(10,310,80,WHITE,50);input_char=nTemp;Lcd_DspAscII8x16(15,45,WHITE,word);switch(input_char){case0:num=1;break;7case1:num=2;break;case2:num=3;break;case3:num=4;break;case4:num=5;break;case5:num=6;break;case6:num=7;break;case7:num=8;break;case8:num=9;break;case9:counter=1;break;case10:counter=2;break;case11:counter=3;break;case12:m=1;Lcd_Draw_HLine(15+n-10,15+n,45,WHITE,16);n-=10;word[wordIndex]='\0';wordIndex--;break;/*if(n==0){word[20]=0;8wordIndex=0;Lcd_Draw_HLine(10,310,85,WHITE,160);}break;*/case13:word[wordIndex]='\0';wordIndex=0;for(i=0;i20;i++){if(strcmp(word,vocab[i].c)==0){j=0;k=i;break;}elsej=1;}if(j==0){//#ifdefEng_vLcd_DspAscII8x16(15,40,BLUE,vocab[k].c);Lcd_DspAscII8x16(15,60,BLUE,vocab[k].d);Lcd_DspAscII8x16(15,80,BLUE,vocab[k].f);//#elseLcd_DspHz16(15,100,BLUE,vocab[k].e);//#endif}else{Lcd_DspHz16(15,120,BLUE,未找到相应的单词);DelayMs(600);Lcd_DspHz16(15,120,WHITE,未找到相应的单词);}break;case14:word[wordIndex]='\0';wordIndex=0;for(i=0;i20;i++){if(strcmp(word,vocab[i].c)==0){j=0;k=i;break;9}elsej=1;}if(j==0){//#ifdefEng_vLcd_DspAscII8x16(15,40,BLUE,vocab[k].c);Lcd_DspAscII8x16(15,60,BLUE,vocab[k].d);Lcd_DspAscII8x16(15,80,BLUE,vocab[k].f);//#elseLcd_DspHz16(15,100,BLUE,vocab[k].e);//#endif}else{if(20x0){for(i=0;i20;i++)vocab[x].c[i]=word[i];word[i]='\0';Lcd_DspAscII8x16(15,40,BLUE,vocab[x].c);x++;}elsex=15;//Lcd_DspAscII8x16(15,45,BLUE,word);for(i=0;i20;i++)word[i]='\0';}break;case15://Lcd_Draw_Box(10,40,310,80,GREEN);break;}if(num!=0&&counter!=0){switch(3*(num-1)+counter-1){10case0:bbyte='a';break;case1:bbyte='b';break;case2:bbyte='c';break;case3:bbyte='d';break;case4:bbyte='e';break;case5:bbyte='f';break;case6:bbyte='g';break;case7:b