资源描述
上海电力学院
嵌入式系统
课程设计汇报
题 目: 电子词典设计
姓 名:
学 号:
院 系:
专业年级:
同组组员:
年 月 日
一、试验内容及要求
在LCD屏幕左侧绘制出单词输入框和释义显示框和一个搜索键,右侧绘制4*4键盘按钮,模拟出简易电子词典功效,按钮操作用触摸屏或键盘实现均可。
实现功效:
(1)LCD屏幕上显示4*4键盘,显示单词及其翻译、例句。
(2)一个键可完成2个英文字母输入,如左上角第一个键可实现输入a,b两个字母,第一次按下时为输入a,假如需输入b,只需连续快速按键两次即可。
(3)在输入完单词后,点击搜索键,即可在释义显示框中显示该单词词性、汉字解释、示例词组和句子等。
(4)当发觉输入单词在库中不存在时,可实现将该单词添加入库操作。
二、设计思绪
(1)经过LCD显示模块画出电子词典操作界面。
(2)对应界面中各键位置设置键盘对应键值。
(3)设定功效键,实现以下3个功效:①退格键:删除最终一位字母;②搜索∕保留键:对输入框单词进行判定,若单词存在于词库中,则显示单词词性、词义、例句;若单词不存在则自动进行保留;③转换键:按下后,字母键输出对应第二个字母。
(4)按键后赋值并显示。
三、软件构架
开始
LCD模块
键盘模块
结束
四、模块分析
(1)键盘模块
步骤图:
开始
键盘初始化
键盘是否按下
Y
读取键值
是否是功效键
Y
N
实施功效
赋值
显示
结束
N
源代码:/*********************************************************************************************
* File: keyboard.c
* Author: 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 word[20];
int wordIndex=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")));
/*--- function code ---*/
/*********************************************************************************************
* name: Test_Keyboard
* func: test keyboard
* para: none
* ret: none
* modify:
* comment:
********************************************************************************************/
void Test_Keyboard()
{
Uart_Printf("\n Keyboard Test Example\n");
Uart_Printf("\n Please press one key on keyboard and look at LED ...\n");
// init keyboard
init_keyboard();
while(1);
// close keyboard
// close_keyboard();
}
/*********************************************************************************************
* 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);
pISR_EINT1 = (int)isrEINT1;
pISR_EINT4567 = (int)isrEint4567;
/* PORT G */
rPCONG = 0xffff; // EINT7~0
rPUPG = 0x0; // pull up enable
rEXTINT = rEXTINT|0x20; // EINT1 falling edge mode
rI_ISPC = BIT_EINT1|BIT_EINT4567; // clear pending bit
rEXTINTPND = 0xf; // clear EXTINTPND reg
}
/*********************************************************************************************
* name: close_keyboard
* func: close keyboard 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 KeyboardInt(void)
{
int nTemp,i,j,k,m=0;
char bbyte;
rI_ISPC = BIT_EINT1; // clear pending bit
char pbyte[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)
{
case 0:
num=1;break;
case 1:
num=2;break;
case 2:
num=3;break;
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;
word[wordIndex]='\0';
wordIndex--;
break;
/*if(n==0)
{
word[20]=0;
wordIndex=0;
Lcd_Draw_HLine(10, 310,85, WHITE, 160);
}break;*/
case 13:
word[wordIndex]='\0';
wordIndex=0;
for(i=0;i<20;i++)
{
if(strcmp(word,vocab[i].c)==0)
{
j=0;
k=i;
break;
}
else
j=1;
}
if(j==0)
{
//#ifdef Eng_v
Lcd_DspAscII8x16(15,40,BLUE,vocab[k].c);
Lcd_DspAscII8x16(15,60,BLUE,vocab[k].d);
Lcd_DspAscII8x16(15,80,BLUE,vocab[k].f);
//#else
Lcd_DspHz16(15,100,BLUE,vocab[k].e);
//#endif
}
else
{
Lcd_DspHz16(15,120,BLUE,"未找到对应单词");
DelayMs(600);
Lcd_DspHz16(15,120,WHITE,"未找到对应单词");
}
break;
case 14:
word[wordIndex]='\0';
wordIndex=0;
for(i=0;i<20;i++)
{
if(strcmp(word,vocab[i].c)==0)
{
j=0;
k=i;
break;
}
else
j=1;
}
if(j==0)
{
//#ifdef Eng_v
Lcd_DspAscII8x16(15,40,BLUE,vocab[k].c);
Lcd_DspAscII8x16(15,60,BLUE,vocab[k].d);
Lcd_DspAscII8x16(15,80,BLUE,vocab[k].f);
//#else
Lcd_DspHz16(15,100,BLUE,vocab[k].e);
//#endif
}
else
{
if(20>x>0)
{
for(i = 0; i < 20; i++)
vocab[x].c[i]=word[i];
word[i]='\0';
Lcd_DspAscII8x16(15,40,BLUE,vocab[x].c);
x++;
}
else
x=15;
//Lcd_DspAscII8x16(15,45,BLUE,word);
for(i = 0; i < 20; i++)
word[i]='\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:
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';break;
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)
{
word[wordIndex]=bbyte;
wordIndex++;
//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(( temp & 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) // release
temp = *(keyboard_base+0xfd);
return value;
}
/* read line 2 */
temp = *(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) // release
temp = *(keyboard_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 & KEY_VALUE_MASK) != KEY_VALUE_MASK) // release
temp = *(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;
else if( (temp&0x8) == 0 )
value = 0xc;
while(( temp & KEY_VALUE_MASK) != KEY_VALUE_MASK) // release
temp = *(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 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
* Author: embest
* Desc: LCD control and display functions
* History:
*********************************************************************************************/
/*--- include files ---*/
#include "lcd.h"
//#include "bmp.h"
#include "44b.h"
/*--- global variables ---*/
INT32U aLcdActiveBuffer[LCD_YSIZE][LCD_XSIZE/4];
/*--- extern variables ---*/
extern const INT8U aucTempBitmap[][76800];
/*--- function code ---*/
/*********************************************************************************************
* name: Lcd_Init()
* func: 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)|(2<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_COLOR<<12);
// LINEBLANK=10 (without any calculation)
rLCDCON2=(LINEVAL)|(HOZVAL_COLOR<<10)|(10<<21);
rLCDCON3=0;
// 256-color, LCDBANK, LCDBASEU
rLCDSADDR1= (0x3<<27) | ( ((unsigned int)aLcdActiveBuffer>>22)<<21 ) | M5D((unsigned int)aLcdActiveBuffer>>1);
rLCDSADDR2= M5D((((unsigned int)aLcdActiveBuffer+(SCR_XSIZE*LCD_YSIZE))>>1)) | (MVAL<<21);
rLCDSADDR3= (LCD_XSIZE/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 0000
rGREENLUT=0xfdb96420; // 1111 1101 1011 1001 0110 0100 0010 0000
rBLUELUT =0xfb40; // 1111 1011 0100 0000
rLCDCON1=(0x1)|(2<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_COLOR<<12);
// 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: fill appointed area with appointed color
* para: usLeft,usTop,usRight,usBottom -- area's 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, 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 -- area's 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)
{
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++)
{
for(m=usLeft;m<
展开阅读全文