嵌入式課程設(shè)計(jì)---電子詞典硬件設(shè)計(jì)_第1頁(yè)
嵌入式課程設(shè)計(jì)---電子詞典硬件設(shè)計(jì)_第2頁(yè)
嵌入式課程設(shè)計(jì)---電子詞典硬件設(shè)計(jì)_第3頁(yè)
嵌入式課程設(shè)計(jì)---電子詞典硬件設(shè)計(jì)_第4頁(yè)
嵌入式課程設(shè)計(jì)---電子詞典硬件設(shè)計(jì)_第5頁(yè)
已閱讀5頁(yè),還剩25頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、上海電力學(xué)院嵌入式系統(tǒng)課程設(shè)計(jì)報(bào)告題目: 電子詞典的設(shè)計(jì) 姓 名: 學(xué) 號(hào): 院系: 專業(yè)年級(jí): 同組成員: 年月日一、實(shí)驗(yàn)內(nèi)容及要求在LCD屏幕左側(cè)繪制出單詞輸入框和釋義顯示框以及一個(gè)搜索鍵,右側(cè)繪制4*4鍵盤(pán)按鈕,模擬出簡(jiǎn)易電子詞典的功能,按鈕操作用觸摸屏或鍵盤(pán)實(shí)現(xiàn)均可。實(shí)現(xiàn)功能:(1)LCD屏幕上顯示4*4鍵盤(pán),顯示單詞及其翻譯、例句。(2)一個(gè)鍵可完成2個(gè)英文字母的輸入,如左上角第一個(gè)鍵可實(shí)現(xiàn)輸入a,b兩個(gè)字母,第一次按下時(shí)為輸入a,如果需輸入b,只需連續(xù)快速按鍵兩次即可。(3)在輸入完單詞后,點(diǎn)擊搜索鍵,即可在釋義顯示框中顯示該單詞的詞性、中文解釋、示例詞組和句子等。(4)當(dāng)發(fā)現(xiàn)輸入

2、的單詞在庫(kù)中不存在時(shí),可實(shí)現(xiàn)將該單詞添加入庫(kù)的操作。二、設(shè)計(jì)思路(1)通過(guò)LCD顯示模塊畫(huà)出電子詞典操作界面。(2)對(duì)應(yīng)界面中各鍵的位置設(shè)置鍵盤(pán)對(duì)應(yīng)鍵值。(3)設(shè)定功能鍵,實(shí)現(xiàn)以下3個(gè)功能:退格鍵:刪除最后一位字母;搜索保存鍵:對(duì)輸入框的單詞進(jìn)行判斷,若單詞存在于詞庫(kù)中,則顯示單詞詞性、詞義、例句;若單詞不存在則自動(dòng)進(jìn)行保存;轉(zhuǎn)換鍵:按下后,字母鍵輸出對(duì)應(yīng)的第二個(gè)字母。(4)按鍵后賦值并顯示。三、軟件構(gòu)架開(kāi)始LCD模塊鍵盤(pán)模塊結(jié)束四、模塊分析(1)鍵盤(pán)模塊流程圖:開(kāi)始鍵盤(pán)初始化鍵盤(pán)是否按下Y讀取鍵值是否是功能鍵YN執(zhí)行功能賦值顯示結(jié)束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 *)0x;/*- function declare -*/void init_keyboard();void close_keyboard();void KeyboardInt(void);/ _attribute_ (interrupt (IRQ);void Eint4567Isr(void);/ _attribute_ (interrupt (IRQ);/*- function

5、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();/* name:in

6、it_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); pISR_EINT1

7、= (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 keyboard i

8、nterrupt* 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 KeyboardInt(void)

9、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; case 3:

10、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-; break; /*

11、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_DspAscII

12、8x16(15,80,BLUE,vocabk.f);/#elseLcd_DspHz16(15,100,BLUE,vocabk.e);/#endif else Lcd_DspHz16(15,120,BLUE,未找到相應(yīng)的單詞); DelayMs(600); Lcd_DspHz16(15,120,WHITE,未找到相應(yīng)的單詞); 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,BLUE,vo

13、cabx.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; case 4: bb

14、yte=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;break; case

15、 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+; /n+=10

16、; 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( temp & KE

17、Y_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 = *(keyboar

18、d_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 = *(keyboard_base

19、+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 & KEY_VALUE

20、_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 )value = 0xd

21、;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 pressed a

22、nd 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模塊流程圖:開(kāi)始LCD初始化顯示開(kāi)機(jī)畫(huà)面顯示操作界面結(jié)束源代碼:/* File:lcd.c* Author:em

23、best* 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()* func:Initia

24、lize 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)|(MVA

25、L_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/2) | (

26、(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)|(0x310)|(C

27、LKVAL_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()* func

28、: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)INT32U i

29、, 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 - appointed colo

30、r 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

31、) | ucColor;if(usRight-usLeft)=8)for(i=usTop;i=usBottom;i+)for(m=usLeft;m=usRight;m+)LCD_PutPixel(m, i, ucColor);return;if(usLeft%8)=0)k=usLeft;elsek=(usLeft/8)*8+8;if( usRight%8)=0)l= usRight;elsel=( usRight/8)*8;for(i=usTop;i=usBottom;i+)for(m=usLeft;m=(k-1);m+)LCD_PutPixel(m, i, ucColor);for(m=k;ml;m+=8)(*(INT32U*)(aLcdActiveBuffer + i * SCR_XSIZE / 2 + m / 2) = ulColor;for(m=l;m= usDy & (usX0 usX1) | (usDy usDx) & (usY0 usY1) ) GUISWAP(usX1, usX0); GUISWAP(usY1, usY0); y_sign = (usY1 - usY0) / usDy; x_sign = (usX1 - usX0) / usDx; if( usDx = usDy )

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論