?? lcd.c
字號:
}
}
}
gCurCol++;
}
/********************************************************************/
//功能: 在屏幕上顯示一個漢字
// str指向這個漢字的顯示矩陣
// reverse為是否要反顯 reverse = 0 為正顯, reverse = 1 為反顯.
//
/********************************************************************/
void print_chinese(unsigned char * str,int reverse)
{
unsigned char j,k;
if(gCurCol >= 15)//一共有十六列, 每個漢字占用兩列
{
gCurCol = 0;
gCurRow++;
}
if(gCurRow >= 6) //一共有六行(編號從零開始).
{
gCurRow = 0;
}
set_cursor(gCurRow,gCurCol);
for(j = 0; j < 2; j++)
{
set_pos(gCurRow * 2 + j, gCurCol * 8);
if(reverse == 0)//正顯
{
for(k = 0; k < 16; k++) //漢字的寬度是十六個點陣
{
wdata(str[j*16 +k]);
wdata(str[j*16 +k]);
}
}
else if(reverse == 1)//反顯
{
for(k=0;k<16;k++)
{
wdata(~str[j*16 +k]);
wdata(~str[j*16 +k]);
}
}
}
gCurCol+=2;
}
/**********************************************************************/
//將一個字符的編碼轉換成符合HY-12896A-T01顯示器編碼
//
//ASCII 字符的矩陣為 8*16 以下是字庫中字符的的編碼模式
// 0 (7,6,5,4,3,2,1,0)
// 2 (7,6,5,4,3,2,1,0)
// : ...............
// : ...............
// 14 (7,6,5,4,3,2,1,0)
// 15 (7,6,5,4,3,2,1,0)
//
//
//而且字符字庫中的編碼是反面顯示的.
/**********************************************************************/
void disp_character( char * str, int reverse)
{
unsigned char j,k;
unsigned char ldata,result;
unsigned char printf_buffer[16];
for(j = 0; j < 8; j++)//
{
result = 0;
//for(k = 0; k < 8; k++) //closed by ChengDong Lu at 03/27/2006
for(k = 2; k < 8; k++)//added by ChengDong Lu at 03/27/2006
{
//ldata = str[k]; //closed by ChengDong Lu at 03/27/2006
ldata = str[ k - 2 ];//added by ChengDong Lu at 03/27/2006
ldata = ldata << j;
ldata = ldata & 0x80;
result = result >> 1;
result = result | ldata;
}
printf_buffer[ 7 - j ] = result;
}
for(j = 0; j < 8; j++)//顯示字符的下半部位
{
result = 0;
//for(k = 0; k < 4; k++)//closed by ChengDong Lu at 03/27/2006
for(k = 0; k < 6; k++) //added by ChengDong Lu at 03/27/2006
{
//ldata = str[8 + k];//closed by ChengDong Lu at 03/27/2006
ldata = str[8 + k - 2 ];//added by ChengDong Lu at 03/27/2006
ldata = ldata << j;
ldata = ldata & 0x80;
result = result >> 1;
result = result | ldata;
}
//result = result >> 4;//closed by ChengDong Lu at 03/27/2006
result = result >> 2;//added by ChengDong Lu at 03/27/2006
printf_buffer[ 15 - j] = result;
}
print_character(printf_buffer,reverse);
}
/*********************************************************************/
//將字庫中的漢字編碼轉換成符合 HY-12896A-T01 顯示的編碼.
// 字庫中的漢字的編碼
//0(15,14,13,12,11,10,9,8) 1 (7,6,5,4,3,2,1,0)
//2(15,14,13,12,11,10,9,8) 3 (7,6,5,4,3,2,1,0)
//4(15,14,13,12,11,10,9,8) 5 (7,6,5,4,3,2,1,0)
// :
// :
//30(15,14,13,12,11,10,9,8) 31 (7,6,5,4,3,2,1,0)
//
//
/*********************************************************************/
void disp_chinese(unsigned char * str, int reverse)
{
unsigned char j,k;
unsigned char ldata,result;
unsigned char printf_buffer[32];
for(j = 0; j < 8; j++)//換算漢字的上半部分的左部分
{
result = 0;
for(k = 0; k < 8; k++)
{
ldata = str[2 * k ];
ldata = ldata << j;
ldata = ldata & 0x80;
result = result >> 1;
result = result | ldata;
}
printf_buffer[ j ] = result;
}
for(j = 0; j < 8; j++)//換算漢字的上半部分的右部分
{
result = 0;
for(k = 0; k < 8; k++)
{
ldata = str[2 * k + 1];
ldata = ldata << j;
ldata = ldata & 0x80;
result = result >> 1;
result = result | ldata;
}
printf_buffer[ 8 + j] = result;
}
for(j = 0; j < 8; j++)//換算漢字的下半部分的左部分
{
result = 0;
for(k = 0; k < 8; k++)
{
ldata = str[16 + 2 * k ];
ldata = ldata << j;
ldata = ldata & 0x80;
result = result >> 1;
result = result | ldata;
}
printf_buffer[16 + j] = result;
}
for(j = 0; j < 8; j++)//換算漢字的下半部分的右部分
{
result = 0;
for(k = 0; k < 8; k++)
{
ldata = str[16 + 2 * k + 1];
ldata = ldata << j;
ldata = ldata & 0x80;
result = result >> 1;
result = result | ldata;
}
printf_buffer[ 24 + j] = result;
}
print_chinese(printf_buffer,reverse);//將轉換好的編碼寫入到相應的顯存中去.
}
/*****************************************************/
//從漢字庫中找出當前該漢字的編碼
//返回值: i = -1 沒有找到
// i >= 0 當前該漢字在字庫character_dots[]中的位置
/******************************************************/
int get_hzk_dots(unsigned char hightbyte,unsigned char lowbyte)
{
int i;
int j;
j = get_charactor_dots_size();
for(i = 0; i < j; i++)
{
if(hightbyte == charactor_dots[i].index[0] && lowbyte == charactor_dots[i].index[1])
{
return i;
}
}
return ( -1);
}
/*************************************************************/
//應用層調用這個函數在顯示屏上顯示字符
//row : 為要顯示的行號(一共有六行,行號從零開始編號)
//col : 為要顯示的列號(一共有十六列,每個漢字占用兩列,字符占用一列)
//pstr : 為要顯示的字符串
//reverse : 為是否是么顯 reverse = 0時為正顯 ,reverse = 1時為反顯
//flash : 為是否閃爍 flash = 0 時為不閃爍 flash = 1 時閃爍
/**************************************************************/
int lcd_print(int row, int col, char *pStr, int reverse, int flash)
{
unsigned char c1,c2;//cData;
//unsigned char tmpBuf[64];
unsigned char tmpBuf[96];//changed by ChengDong Lu at 04/03/2006
unsigned char i,uLen;
unsigned char uRow,uCol;
unsigned char *pDots;
int location;
if(row <6 && row >=0 && col < 16 && col >=0 )
{
set_cursor(row,col);
}
strcpy(tmpBuf,pStr);
uLen=strlen(tmpBuf);
i=0;
while(i<uLen)
{
c1 = tmpBuf[i];
c2 = tmpBuf[i+1];
uRow = fnGetRow();
uCol = fnGetCol();
if( c1<0x80) // ASCII
{
if(c1 < 0x20)
{
switch(c1)
{
case CR:
case LF: // ??3μ?ò??DD
i++;
if(uRow < 5)
{
set_cursor(uRow + 1,0);
}
else
{
set_cursor(0,0);
}
continue;
case BS: // í???
if(uCol > 0)
{
uCol--;
}
set_cursor(uRow,uCol);
// cData = 0x00;
break;
default: // ????
c1 = 0x1f;
break;
}
}
//pDots=get_asc_dots(c1)£? //é????a??oˉêyμ?1|?üê???μ?μ±?°×?·?μ?±à???ú×??a?Dμ?ê×μ??·
// disp_character(pDots);
disp_character(ASC_MSK + (c1-0x1f) * 12, reverse);
if(c1 != BS) // ·?í???
{
uCol++;
}
}
else
{ // ?D??
// pDots=get_hzk_dots(c1,c2); //closed by ChengDong Lu at 03/12/2006
// é????a??oˉêyμ?1|?üê???μ?μ±?°oo×?μ?±à???ú×??a?Dμ?ê×μ??·
// μ?ê??ò??×?oóòa?¨×??oμ?×??a£?μ??ù?Yêμ?ê?é??è¥D′3ìDò
location = get_hzk_dots(c1, c2);
if(location >= 0)
{
pDots = &charactor_dots[location].dots[0];
print_chinese(pDots, reverse);
}
uCol += 2;
i++;
}
i++;
}
return uLen;
}
/******************************************************************************/
//PB2 RST 重啟
//PB3 CS 片選
//PB4 SCK 時鐘
//PB1 SDA Serial data
//PB0 A0 Register selection
/*****************************************************************************/
void lcd_main(void)
{
lcd_init();
lcd_EnLight( );
/*
set_cursor(2,4);
disp_chinese(GB_16, 1);
lcd_delay(50);//??ê??°2a?±
disp_chinese(GB_16 + 32, 1);
lcd_delay(50);//??ê??°ê??±
disp_chinese(GB_16 + 64, 0);
lcd_delay(50);//??ê??°?D?±
disp_chinese(GB_16 + 96, 0);
lcd_delay(50);//??ê??°???±
// lcd_print(0,1,"WELLCOME !",1,0);
// lcd_print(1,1,"GOOD FRIEND !",1,0);
*/
lcd_DisLight( );
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -