嵌入式课程设计电子词典硬件设计.docx

上传人:小飞机 文档编号:2059941 上传时间:2023-01-05 格式:DOCX 页数:30 大小:380.32KB
返回 下载 相关 举报
嵌入式课程设计电子词典硬件设计.docx_第1页
第1页 / 共30页
嵌入式课程设计电子词典硬件设计.docx_第2页
第2页 / 共30页
嵌入式课程设计电子词典硬件设计.docx_第3页
第3页 / 共30页
嵌入式课程设计电子词典硬件设计.docx_第4页
第4页 / 共30页
嵌入式课程设计电子词典硬件设计.docx_第5页
第5页 / 共30页
点击查看更多>>
资源描述

《嵌入式课程设计电子词典硬件设计.docx》由会员分享,可在线阅读,更多相关《嵌入式课程设计电子词典硬件设计.docx(30页珍藏版)》请在三一办公上搜索。

1、上海电力学院嵌入式系统课程设计报告题目: 电子词典的设计 姓 名: 学 号: 院系: 专业年级: 同组成员: 年月日一、实验内容及要求在LCD屏幕左侧绘制出单词输入框和释义显示框以及一个搜索键,右侧绘制4*4键盘按钮,模拟出简易电子词典的功能,按钮操作用触摸屏或键盘实现均可。实现功能:(1)LCD屏幕上显示4*4键盘,显示单词及其翻译、例句。(2)一个键可完成2个英文字母的输入,如左上角第一个键可实现输入a,b两个字母,第一次按下时为输入a,如果需输入b,只需连续快速按键两次即可。(3)在输入完单词后,点击搜索键,即可在释义显示框中显示该单词的词性、中文解释、示例词组和句子等。(4)当发现输入

2、的单词在库中不存在时,可实现将该单词添加入库的操作。二、设计思路(1)通过LCD显示模块画出电子词典操作界面。(2)对应界面中各键的位置设置键盘对应键值。(3)设定功能键,实现以下3个功能:退格键:删除最后一位字母;搜索保存键:对输入框的单词进行判断,若单词存在于词库中,则显示单词词性、词义、例句;若单词不存在则自动进行保存;转换键:按下后,字母键输出对应的第二个字母。(4)按键后赋值并显示。三、软件构架开始LCD模块键盘模块结束四、模块分析(1)键盘模块流程图:开始键盘初始化键盘是否按下Y读取键值是否是功能键YN执行功能赋值显示结束N源代码:/* File:keyboard.c* Autho

3、r:embest* Desc:keyboard source code* History:*/*- include files -*/#include 44b.h#include 44blib.h#include def.h#include keyboard.h#include lcd.h#include dict.h#ifndef KEY_INT#define KEY_INT#endif#ifndef BUT_INT#define BUT_INT#endif/*- global variables -*/int input_char,n=0;char word20;int wordIndex

4、=0;int x = 15;int num=0;int counter=0;/* keyboard control address */volatile UCHAR *keyboard_base = (UCHAR *)0x06000000;/*- function declare -*/void init_keyboard();void close_keyboard();void KeyboardInt(void);/ _attribute_ (interrupt (IRQ);void Eint4567Isr(void);/ _attribute_ (interrupt (IRQ);/*- f

5、unction code -*/* name:Test_Keyboard* func:test keyboard* para:none* ret:none* modify:* comment:*/void Test_Keyboard()Uart_Printf(n Keyboard Test Examplen);Uart_Printf(n Please press one key on keyboard and look at LED .n);/ init keyboardinit_keyboard();while(1);/ close keyboard/ close_keyboard();/*

6、 name:init_keyboard* func:init keyboard interrupt* para:none* ret:none* modify:* comment:*/extern void isrEINT1(void);extern void isrEint4567(void);void init_keyboard()/* enable interrupt */rINTMOD = 0x0;rINTCON = 0x1;/* set EINT1 interrupt handler */rINTMSK =(BIT_GLOBAL|BIT_EINT1|BIT_EINT4567); pIS

7、R_EINT1 = (int)isrEINT1; pISR_EINT4567 = (int)isrEint4567; /* PORT G */ rPCONG = 0xffff;/ EINT70rPUPG = 0x0;/ pull up enable rEXTINT = rEXTINT|0x20;/ EINT1 falling edge moderI_ISPC = BIT_EINT1|BIT_EINT4567;/ clear pending bitrEXTINTPND = 0xf;/ clear EXTINTPND reg/* name:close_keyboard* func:close ke

8、yboard interrupt* para:none* ret:none* modify:* comment:*/void close_keyboard()pISR_EINT1 = NULL;pISR_EINT4567 = NULL;/* Mask interrupt */rINTMSK = rINTMSK | BIT_EINT1 | BIT_EINT4567;/* name:KeyboardInt* func:keyboard interrupt handler function* para:none* ret:none* modify:* comment:*/void KeyboardI

9、nt(void)int nTemp,i,j,k,m=0;char bbyte;rI_ISPC = BIT_EINT1;/ clear pending bitchar pbyte10;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) case 0: num=1;break; case 1: num=2;break; case 2: num=3;break;

10、case 3: num=4;break; case 4: num=5;break; case 5: num=6;break; case 6: num=7;break; case 7: num=8;break; case 8: num=9;break; case 9: counter=1;break; case 10: counter=2;break; case 11: counter=3;break; case 12: m=1; Lcd_Draw_HLine(15+n-10, 15+n, 45, WHITE, 16); n-=10; wordwordIndex=0; wordIndex-; b

11、reak; /*if(n=0) word20=0; wordIndex=0; Lcd_Draw_HLine(10, 310,85, WHITE, 160); break;*/ case 13: wordwordIndex=0; wordIndex=0; for(i=0;i20;i+) if(strcmp(word,vocabi.c)=0) j=0; k=i; break; else j=1; if(j=0) /#ifdef Eng_v Lcd_DspAscII8x16(15,40,BLUE,vocabk.c);Lcd_DspAscII8x16(15,60,BLUE,vocabk.d);Lcd_

12、DspAscII8x16(15,80,BLUE,vocabk.f);/#elseLcd_DspHz16(15,100,BLUE,vocabk.e);/#endif else Lcd_DspHz16(15,120,BLUE,未找到相应的单词); DelayMs(600); Lcd_DspHz16(15,120,WHITE,未找到相应的单词); break; case 14: wordwordIndex=0; wordIndex=0; for(i=0;ix0) for(i = 0; i 20; i+) vocabx.ci=wordi; wordi=0; Lcd_DspAscII8x16(15,40

13、,BLUE,vocabx.c); x+; else x=15; /Lcd_DspAscII8x16(15,45,BLUE,word); for(i = 0; i 20; i+) wordi=0; break; case 15: /Lcd_Draw_Box(10,40,310,80,GREEN); break; if(num!=0&counter!=0) switch(3*(num-1)+counter-1) case 0: bbyte=a;break; case 1: bbyte=b;break; case 2: bbyte=c;break; case 3: bbyte=d;break; ca

14、se 4: bbyte=e;break; case 5: bbyte=f;break; case 6: bbyte=g;break; case 7: bbyte=h;break; case 8: bbyte=i;break; case 9: bbyte=j;break; case 10: bbyte=k;break; case 11: bbyte=l;break; case 12: bbyte=m;break; case 13: bbyte=n;break; case 14: bbyte=o;break; case 15: bbyte=p;break; case 16: bbyte=q;bre

15、ak; case 17: bbyte=r;break; case 18: bbyte=s;break; case 19: bbyte=t;break; case 20: bbyte=u;break; case 21: bbyte=v;break; case 22: bbyte=w;break; case 23: bbyte=x;break; case 24: bbyte=y;break; case 25: bbyte=z;break; case 26: bbyte=y;break; num=0;counter=0; if(m=0) wordwordIndex=bbyte; wordIndex+

16、; /n+=10; Lcd_DspAscII8x16(15,210,BLUE,word); / Uart_Printf(Key is:%x r,input_char); /* name:key_read* func:read key value* para:none* ret:key value, -1 - error* modify:* comment:*/inline int key_read()int value;char temp;/* read line 1 */temp = *(keyboard_base+0xfd);/* not 0xF mean key down */if( t

17、emp & KEY_VALUE_MASK) != KEY_VALUE_MASK)if( (temp&0x1) = 0 )value = 3;else if( (temp&0x2) = 0 )value = 2;else if( (temp&0x4) = 0 )value = 1;else if( (temp&0x8) = 0 )value = 0;while( temp & KEY_VALUE_MASK) != KEY_VALUE_MASK) / releasetemp = *(keyboard_base+0xfd);return value;/* read line 2 */temp = *

18、(keyboard_base+0xfb);/* not 0xF mean key down */if( temp & KEY_VALUE_MASK) != KEY_VALUE_MASK)if( (temp&0x1) = 0 )value = 7;else if( (temp&0x2) = 0 )value = 6;else if( (temp&0x4) = 0 )value = 5;else if( (temp&0x8) = 0 )value = 4;while( temp & KEY_VALUE_MASK) != KEY_VALUE_MASK) / releasetemp = *(keybo

19、ard_base+0xfb);return value;/* read line 3 */temp = *(keyboard_base+0xf7);/* not 0xF mean key down */if( temp & KEY_VALUE_MASK) != KEY_VALUE_MASK)if( (temp&0x1) = 0 )value = 0xb;else if( (temp&0x2) = 0 )value = 0xa;else if( (temp&0x4) = 0 )value = 9;else if( (temp&0x8) = 0 )value = 8;while( temp & K

20、EY_VALUE_MASK) != KEY_VALUE_MASK) / releasetemp = *(keyboard_base+0xf7);return value;/* read line 4 */temp = *(keyboard_base+0xef);/* not 0xF mean key down */if( temp & KEY_VALUE_MASK) != KEY_VALUE_MASK)if( (temp&0x1) = 0 )value = 0xf;else if( (temp&0x2) = 0 )value = 0xe;else if( (temp&0x4) = 0 )val

21、ue = 0xd;else if( (temp&0x8) = 0 )value = 0xc;while( temp & KEY_VALUE_MASK) != KEY_VALUE_MASK) / releasetemp = *(keyboard_base+0xef);return value;return -1;/* name:Eint4567Isr* func:* para:none* ret:none* modify:* comment:*/void Eint4567Isr(void)unsigned char which_int;Uart_Printf(n SB2 or SB3 had p

22、ressed and light LED.); which_int=rEXTINTPND; rEXTINTPND=0xf;/clear EXTINTPND reg. rI_ISPC=BIT_EINT4567;/clear pending_bit if(which_int = 4)/ SB2 Led_Display(0x0); Led_Display(0x1); else if(which_int = 8)/ SB3 Led_Display(0x0); Led_Display(0x2); (2)LCD模块流程图:开始LCD初始化显示开机画面显示操作界面结束源代码:/* File:lcd.c* A

23、uthor:embest* Desc:LCD control and display functions* History:*/*- include files -*/#include lcd.h/#include bmp.h#include 44b.h/*- global variables -*/INT32U aLcdActiveBufferLCD_YSIZELCD_XSIZE/4;/*- extern variables -*/extern const INT8U aucTempBitmap76800;/*- function code -*/* name:Lcd_Init()* fun

24、c:Initialize LCD Controller* para:none* ret:none* modify:* comment:*/void Lcd_Init (void) rDITHMODE=0x12210;rDP1_2 =0xa5a5; rDP4_7 =0xba5da65;rDP3_5 =0xa5a5f;rDP2_3 =0xd6b;rDP5_7 =0xeb7b5ed;rDP3_4 =0x7dbe;rDP4_5 =0x7ebdf;rDP6_7 =0x7fdfbfe; / disable,8B_SNGL_SCAN,WDLY=16clk,WLH=16clk,rLCDCON1=(0x0)|(

25、25)|(MVAL_USED7)|(0x38)|(0x310)|(CLKVAL_COLOR12);/ LINEBLANK=10 (without any calculation) rLCDCON2=(LINEVAL)|(HOZVAL_COLOR10)|(1021); rLCDCON3=0;/ 256-color, LCDBANK, LCDBASEUrLCDSADDR1= (0x322)1);rLCDSADDR2= M5D(unsigned int)aLcdActiveBuffer+(SCR_XSIZE*LCD_YSIZE)1) | (MVAL21);rLCDSADDR3= (LCD_XSIZE

26、/2) | ( (SCR_XSIZE-LCD_XSIZE)/2)9 );/The following value has to be changed for better display.rREDLUT =0xfdb96420; / 1111 1101 1011 1001 0110 0100 0010 0000rGREENLUT=0xfdb96420; / 1111 1101 1011 1001 0110 0100 0010 0000rBLUELUT =0xfb40; / 1111 1011 0100 0000rLCDCON1=(0x1)|(25)|(MVAL_USED7)|(0x38)|(0

27、x310)|(CLKVAL_COLOR12);/rPDATE=rPDATE&0x0e;rPDATE=0xfe;Lcd_Clr();/* name:Lcd_Clr()* func:clear LCD screen* para:none * ret:none* modify:* comment:*/void Lcd_Clr(void)INT32U i;INT32U *pDisp = (INT32U*)aLcdActiveBuffer;for (i = 0; i (SCR_XSIZE * SCR_YSIZE / 4); i+)*pDisp+ = ALLWHITE;/* name:LcdClrRect

28、()* func:fill appointed area with appointed color* para:usLeft,usTop,usRight,usBottom - areas rectangle acme coordinate*ucColor - appointed color value* ret:none* modify:* comment:also as clear screen function */void LcdClrRect(INT16 usLeft, INT16 usTop, INT16 usRight, INT16 usBottom, INT8U ucColor)

29、INT32U i, j;INT8U *pDisp = (INT8U*)aLcdActiveBuffer;for(i=usTop;i=usBottom;i+)for(j=usLeft;j=usRight;j+)LCD_PutPixel(j, i, ucColor);#ifdef MON_LCD/* name:LcdClrRect()* func:fill appointed area with appointed color* para:usLeft,usTop,usRight,usBottom - areas rectangle acme coordinate*ucColor - appoin

30、ted color value* ret:none* modify:* comment:also as clear screen function */void LcdClrRect(INT16 usLeft, INT16 usTop, INT16 usRight, INT16 usBottom, INT8U ucColor)INT16 i=0;INT16 k,l;INT16 m;INT32U ulColor = (ucColor 28) | (ucColor 24) | (ucColor 20) | (ucColor 16) | (ucColor 12) | (ucColor 8) | (ucColor 4) | ucColor;if(usRight-usLeft)=8)for(i=usTop;i=usBottom;i+)f

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号