- #include "12232.h"
-
- #define A0_0() LCD_A0 = 0
- #define A0_1() LCD_A0 = 1
- #define E1_0() LCD_E1 = 0
- #define E1_1() LCD_E1 = 1
- #define E2_0() LCD_E2 = 0
- #define E2_1() LCD_E2 = 1
- #define LCD_DISPLAYON 0xaf //af 開顯示
- #define LCD_DISPLAYOFF 0xae //ae 關顯示
- #define LCD_DRIVERON 0xa5 //a5 靜態顯示驅動
- #define LCD_DRIVEROFF 0xa4 //a4 正常驅動
- #define LCD_DUTY16 0xa8 //占空比1/16
- #define LCD_DUTY32 0xa9 //占空比1/32
- #define LCD_END 0xee
- /*關閉“讀-修改-寫”模式,并把列地址指針
- 恢復到打開“讀-修改-寫”模式前的位置。*/
- #define LCD_RESET 0xe2
- /*初始化。① 設置顯示初始行為第一行;
- ②頁地址設置為第三頁。*/
- #define LCD_RWMODE 0xe0
- /*“讀-修改-寫”模式 。執行該指令以后,
- 每執行一次寫數據,指令列地址自動加1;
- 但執行讀數據指令時列地址不會改變。
- 這個狀態一直持續到執行“END”指令。
- 注意:在“讀-修改-寫”模式下,
- 除列地址設置指令之外,其他指令照常執行。 */
-
- #define LCD_STARTLINE0 0xc0 //設置顯示起始行 可以加0-31
- #define LCD_PAGE0 0xb8 //頁地址設置 可以加0-3
- #define LCD_COLUMNADDR0 0x00 //列地址設置 可以加0-60
- #define LCD_ON() LCD_Command(LCD_DISPLAYON)
- #define LCD_OFF() LCD_Command(LCD_DISPLAYOFF)
- #define LCD_StaticON() LCD_Command(LCD_DRIVERON)
- #define LCD_StaticOFF() LCD_Command(LCD_DRIVEROFF)
- #define LCD_Select16() LCD_Command(LCD_DUTY16)
- #define LCD_Select32() LCD_Command(LCD_DUTY32)
- #define LCD_StartRW() LCD_Command(LCD_RWMODE)
- #define LCD_EndRW() LCD_Command(LCD_END)
- #define LCD_Reset() LCD_Command(LCD_RESET)
- #define LCD_SetStartLine(i) LCD_Command(LCD_STARTLINE0|i)
- #define LCD_SetPage(i) LCD_Command(LCD_PAGE0|i)
- #define LCD_SetColumn(i) LCD_Command(LCD_COLUMNADDR0|i)
- unsigned char code ascii[][6]={
- {0x00,0x00,0x00,0x00,0x00,0x00},/*0 SPACE*/
- {0x00,0x00,0x00,0x4f,0x00,0x00},/*1 !*/
- {0x00,0x00,0x00,0x07,0x00,0x07},/*2 "*/
- {0x00,0x14,0x7f,0x14,0x7f,0x14},/*3 #*/
- {0x00,0x24,0x2a,0x7f,0x2a,0x12},/*4 $*/
- {0x00,0x23,0x13,0x08,0x62,0x61},/*5 %*/
- {0x00,0x36,0x49,0x55,0x22,0x50},/*6 &*/
- {0x00,0x00,0x00,0x05,0x03,0x00},/*7 '*/
- {0x00,0x00,0x1c,0x22,0x41,0x00},/*8 (*/
- {0x00,0x00,0x41,0x22,0x1c,0x00},/*9 )*/
- {0x00,0x14,0x08,0x3e,0x08,0x14},/*10 **/
- {0x00,0x08,0x08,0x3e,0x08,0x08},/*11 +*/
- {0x00,0x00,0x00,0x28,0x18,0x00},/*12 ,*/
- {0x00,0x08,0x08,0x08,0x08,0x08},/*13 -*/
- {0x00,0x00,0x00,0x60,0x60,0x00},/*14 .*/
- {0x00,0x20,0x10,0x08,0x04,0x02},/*15 /*/
- {0x00,0x3e,0x51,0x49,0x45,0x3e},/*16 0*/
- {0x00,0x00,0x42,0x7f,0x40,0x40},/*17 1*/
- {0x00,0x62,0x51,0x51,0x49,0x46},/*18 2*/
- {0x00,0x21,0x41,0x45,0x4b,0x31},/*19 3*/
- {0x00,0x18,0x14,0x12,0x7f,0x10},/*20 4*/
- {0x00,0x27,0x45,0x45,0x45,0x39},/*21 5*/
- {0x00,0x3c,0x4a,0x49,0x49,0x30},/*22 6*/
- {0x00,0x01,0x71,0x09,0x05,0x03},/*23 7*/
- {0x00,0x36,0x49,0x49,0x49,0x36},/*24 8*/
- {0x00,0x06,0x49,0x49,0x29,0x1e},/*25 9*/
- {0x00,0x00,0x36,0x36,0x00,0x00},/*26 :*/
- {0x00,0x00,0x56,0x36,0x00,0x00},/*27 ;*/
- {0x00,0x08,0x14,0x22,0x41,0x00},/*28 <*/
- {0x00,0x14,0x14,0x14,0x14,0x14},/*29 =*/
- {0x00,0x00,0x41,0x22,0x14,0x08},/*30 >*/
- {0x00,0x02,0x01,0x51,0x09,0x06},/*31 ?*/
- {0x00,0x3e,0x59,0x55,0x79,0x3e},/*32 @*/
- {0x00,0x7e,0x21,0x21,0x21,0x7e},/*33 A*/
- {0x00,0x7f,0x49,0x49,0x49,0x36},/*34 B*/
- {0x00,0x3e,0x41,0x41,0x41,0x22},/*35 C*/
- {0x00,0x7f,0x41,0x41,0x22,0x1c},/*36 D*/
- {0x00,0x7f,0x49,0x49,0x49,0x49},/*37 E*/
- {0x00,0x7f,0x09,0x09,0x09,0x01},/*38 F*/
- {0x00,0x3e,0x41,0x49,0x49,0x7a},/*39 G*/
- {0x00,0x7f,0x08,0x08,0x08,0x7f},/*40 H*/
- {0x00,0x41,0x7f,0x41,0x00,0x00},/*41 I*/
- {0x00,0x20,0x40,0x41,0x3f,0x01},/*42 J*/
- {0x00,0x7f,0x08,0x14,0x22,0x41},/*43 K*/
- {0x00,0x7f,0x40,0x40,0x40,0x40},/*44 L*/
- {0x00,0x7f,0x02,0x0c,0x02,0x7f},/*45 M*/
- {0x00,0x7f,0x04,0x08,0x10,0x7f},/*46 N*/
- {0x00,0x3e,0x41,0x41,0x41,0x3e},/*47 O*/
- {0x00,0x7f,0x09,0x09,0x09,0x06},/*48 P*/
- {0x00,0x3E,0x41,0x51,0x21,0x5E},/*49 Q*/
- {0x00,0x7f,0x09,0x19,0x29,0x46},/*50 R*/
- {0x00,0x46,0x49,0x49,0x49,0x31},/*51 S*/
- {0x00,0x01,0x01,0x7f,0x01,0x01},/*52 T*/
- {0x00,0x3f,0x40,0x40,0x40,0x3f},/*53 U*/
- {0x00,0x1f,0x20,0x40,0x20,0x1f},/*54 V*/
- {0x00,0x3f,0x40,0x38,0x40,0x3f},/*55 W*/
- {0x00,0x63,0x14,0x08,0x14,0x63},/*56 X*/
- {0x00,0x07,0x08,0x70,0x08,0x07},/*57 Y*/
- {0x00,0x61,0x51,0x49,0x45,0x43},/*58 Z*/
- {0x00,0x00,0x7f,0x41,0x41,0x00},/*59 [*/
- {0x00,0x01,0x02,0x08,0x10,0x20},/*50 \*/
- {0x00,0x00,0x41,0x41,0x7f,0x00},/*61 ]*/
- {0x00,0x04,0x02,0x01,0x02,0x04},/*62 ^*/
- {0x00,0x40,0x40,0x40,0x40,0x40},/*63 _*/
- {0x00,0x00,0x01,0x02,0x04,0x00},/*64 `*/
- {0x00,0x20,0x54,0x54,0x54,0x7c},/*65 a*/
- {0x00,0x7f,0x48,0x44,0x44,0x38},/*66 b*/
- {0x00,0x38,0x44,0x44,0x44,0x20},/*67 c*/
- {0x00,0x38,0x44,0x44,0x48,0x7f},/*68 d*/
- {0x00,0x38,0x54,0x54,0x54,0x18},/*69 e*/
- {0x00,0x08,0x7e,0x09,0x01,0x02},/*70 f*/
- {0x00,0x0c,0x52,0x52,0x52,0x3e},/*71 g*/
- {0x00,0x7f,0x08,0x04,0x04,0x78},/*72 h*/
- {0x00,0x00,0x44,0x7d,0x40,0x00},/*73 i*/
- {0x00,0x40,0x40,0x44,0x3d,0x00},/*74 j*/
- {0x00,0x7f,0x10,0x28,0x44,0x00},/*75 k*/
- {0x00,0x00,0x41,0x7e,0x40,0x00},/*76 l*/
- {0x00,0x7c,0x04,0x18,0x04,0x78},/*77 m*/
- {0x00,0x7c,0x08,0x04,0x04,0x78},/*78 n*/
- {0x00,0x38,0x44,0x44,0x44,0x38},/*79 o*/
- {0x00,0x7c,0x14,0x14,0x14,0x08},/*80 p*/
- {0x00,0x08,0x14,0x14,0x14,0x7c},/*81 q*/
- {0x00,0x7c,0x08,0x04,0x04,0x08},/*82 r*/
- {0x00,0x48,0x54,0x54,0x54,0x20},/*83 s*/
- {0x00,0x04,0x3f,0x44,0x44,0x24},/*84 t*/
- {0x00,0x3c,0x40,0x40,0x20,0x7c},/*85 u*/
- {0x00,0x1c,0x20,0x40,0x20,0x1c},/*86 v*/
- {0x00,0x3c,0x40,0x30,0x40,0x3c},/*87 w*/
- {0x00,0x44,0x28,0x10,0x28,0x44},/*88 x*/
- {0x00,0x06,0x48,0x48,0x48,0x3e},/*89 y*/
- {0x00,0x44,0x64,0x54,0x4c,0x44},/*80 z*/
- {0x00,0x00,0x08,0x36,0x41,0x00},/*91 {*/
- {0x00,0x00,0x00,0x7e,0x00,0x00},/*92 |*/
- {0x00,0x00,0x41,0x36,0x08,0x00},/*93 }*/
- {0x00,0x04,0x08,0x04,0x08,0x04},/*94 ~*/
- {0x10,0x20,0x40,0x20,0x10,0x08},//95對號一半
- {0x04,0x02,0x00,0x00,0x00,0x00},//96對號一半
- };
-
- unsigned char target1,target2,target3,target4;
- /******************************************************************************************
- * 函數名稱 :LCD_Command
- * 功能描述 :寫命令
- * 參數 : 參數名稱: 輸入/輸出? 類型 描述
- *
- * 返回值 :
- * 作者 :
- * 創建日期 :2006-12-19
- * 全局變量 :
- * 全局靜態變量:
- * 局部靜態變量:
- *----------------------------------------修改歷史------------------------------------------
- * 當前版本 : 修改人: 修改日期:
- * 修改說明 :
- ******************************************************************************************/
- void LCD_Command(unsigned char nCommand)
- {
- A0_0();
- // asm("nop");
- // asm("nop");
- E1_1();
- E2_1();
- // asm("nop");
- // asm("nop");
- DATA=nCommand;
- // asm("nop");
- // asm("nop");
- E1_0();
- E2_0();
- }
- /******************************************************************************************
- * 函數名稱 :LCD_SetRam
- * 功能描述 :送顯示數據ndata,setMS為0主,1從
- * 參數 : 參數名稱: 輸入/輸出? 類型 描述
- *
- * 返回值 :
- * 作者 :
- * 創建日期 :2006-12-19
- * 全局變量 :
- * 全局靜態變量:
- * 局部靜態變量:
- *----------------------------------------修改歷史------------------------------------------
- * 當前版本 : 修改人: 修改日期:
- * 修改說明 :
- ******************************************************************************************/
- void LCD_SetRam(unsigned char ChipSelect,unsigned char ndata)
- {
- A0_1();
- // asm("nop");
- // asm("nop");
- if( ChipSelect )
- {
- E1_0();
- E2_1(); //選擇左半屏
- }
- else
- {
- E1_1(); //選擇右半屏
- E2_0();
- }
- // asm("nop");
- // asm("nop");
- DATA=ndata;
- // asm("nop");
- // asm("nop");
- E1_0();
- E2_0();
- }
- /******************************************************************************************
- * 函數名稱 :LCD_Init
- * 功能描述 :
- * 參數 : 參數名稱: 輸入/輸出? 類型 描述
- *
- * 返回值 :
- * 作者 :
- * 創建日期 :2006-12-19
- * 全局變量 :
- * 全局靜態變量:
- * 局部靜態變量:
- *----------------------------------------修改歷史------------------------------------------
- * 當前版本 : 修改人: 修改日期:
- * 修改說明 :
- ******************************************************************************************/
- void LCD_init(void)
- {
- LCD_OFF(); //關閉顯示
- LCD_Command(LCD_RESET); //復位
- LCD_Command(0xa0); //列與段驅動反方向
- LCD_Command(LCD_DUTY32); //1/32
- LCD_Command(0xa4); //關閉靜態顯示 打開正常驅動
- LCD_EndRW(); //關閉自動列加1
- LCD_SetStartLine(0); //設置起始行
- LCD_SetColumn(0); //起始列
- LCD_SetPage(0); //起始頁
- LCD_ON(); //開顯示
- }
- /******************************************************************************************
- * 函數名稱 :clrscr
- * 功能描述 :清屏
- * 參數 : 參數名稱: 輸入/輸出? 類型 描述
- *
- * 返回值 :
- * 作者 :
- * 創建日期 :2006-12-19
- * 全局變量 :
- * 全局靜態變量:
- * 局部靜態變量:
- *----------------------------------------修改歷史------------------------------------------
- * 當前版本 : 修改人: 修改日期:
- * 修改說明 :
- ******************************************************************************************/
- void clrscr(unsigned char hdata)
- {
- unsigned char i;
- unsigned char page;
- for(page=0;page<4;page++)
- {
- LCD_SetPage(page);
- for(i=0;i<61;i++)
- {
- LCD_SetColumn(i);
- LCD_SetRam(0,hdata);
- LCD_SetRam(1,hdata);
- }
- }
- }
- /******************************************************************************************
- * 函數名稱 :drawword
- * 功能描述 ://layer 值為0,2;wenzi 碼表中的幾個字
- * 參數 : 參數名稱: 輸入/輸出? 類型 描述
- *
- * 返回值 :
- * 作者 :
- * 創建日期 :2006-12-19
- * 全局變量 :
- * 全局靜態變量:
- * 局部靜態變量:
- *----------------------------------------修改歷史------------------------------------------
- * 當前版本 : 修改人: 修改日期:
- * 修改說明 :
- ******************************************************************************************/
- /*
- void drawword(unsigned char liedizhi,unsigned char layer,unsigned char *buff)
- {
- unsigned char column,i;//layer 值為0,2;wenzi 碼表中的幾個字
- unsigned char cs;
- for(i=0;i<16;i++)
- {
- column=liedizhi+i;
- if(column>60)
- {
- cs=1;
- column-=61;
- }
- else
- cs=0;
-
- //LCD_SetStartLine(0);//設置起始行
- LCD_SetColumn(column);//設置起始列
- LCD_SetPage(layer);
- LCD_SetRam(cs,*(buff+i));
- //LCD_SetStartLine(0);//設置起始行
- LCD_SetColumn(column);//設置起始列
- LCD_SetPage(layer+1);
- LCD_SetRam(cs,*(buff+16+i));
- }
- }
- */
- void drawascii(unsigned char liedizhi,unsigned char layer,unsigned char *text)
- {
- unsigned char column,i;//layer 值為0,2;wenzi 碼表中的幾個字
- unsigned char cs;
-
- while(*text)
- {
- for(i=0;i<6;i++)
- {
- column=liedizhi+i;
- if(column>60)
- {
- cs=1;
- column-=61;
- }
- else cs=0;
-
- //LCD_SetStartLine(0);//設置起始行
- LCD_SetColumn(column);//設置起始列
- LCD_SetPage(layer);
- LCD_SetRam(cs,ascii[*text-32][i]);
- }
- text++;
- liedizhi+=6;
- }
- }
- void make_ascii_big(unsigned char c)
- {
- target1 = 0;
- target2 = 0;
- if((c&0x80) != 0)
- {
- target1 += 192;
- }
- if((c&0x40) != 0)
- {
- target1 += 48;
- }
- if((c&0x20) != 0)
- {
- target1 += 12;
- }
- if((c&0x10) != 0)
- {
- target1 += 3;
- }
- if((c&0x08) != 0)
- {
- target2 += 192;
- }
- if((c&0x04) != 0)
- {
- target2 += 48;
- }
- if((c&0x02) != 0)
- {
- target2 += 12;
- }
- if((c&0x01) != 0)
- {
- target2 += 3;
- }
- }
- void make_ascii_very_big(unsigned char c)
- {
- target1 = 0;
- target2 = 0;
- target3 = 0;
- target4 = 0;
- if((c&0x80) != 0)
- {
- target1 += 240;
- }
- if((c&0x40) != 0)
- {
- target1 += 15;
- }
- if((c&0x20) != 0)
- {
- target2 += 240;
- }
- if((c&0x10) != 0)
- {
- target2 += 15;
- }
- if((c&0x08) != 0)
- {
- target3 += 240;
- }
- if((c&0x04) != 0)
- {
- target3 += 15;
- }
- if((c&0x02) != 0)
- {
- target4 += 240;
- }
- if((c&0x01) != 0)
- {
- target4 += 15;
- }
- }
- void draw_big_ascii(unsigned char liedizhi,unsigned char layer,unsigned char *text)
- {
- unsigned char column,i;
- unsigned char cs;
-
- while(*text)
- {
- for(i=0;i<6;i++)
- {
- column=liedizhi+i+i;
- if(column>60)
- {
- cs=1;
- column-=61;
- }
- else cs=0;
- make_ascii_big(ascii[*text-32][i]);
-
- LCD_SetColumn(column);//設置起始列
- LCD_SetPage(layer);
- LCD_SetRam(cs,target2);
- LCD_SetColumn(column);//設置起始列
- LCD_SetPage(layer+1);
- LCD_SetRam(cs,target1);
- LCD_SetColumn(column+1);//設置起始列
- LCD_SetPage(layer);
- LCD_SetRam(cs,target2);
- LCD_SetColumn(column+1);//設置起始列
- LCD_SetPage(layer+1);
- LCD_SetRam(cs,target1);
- }
- text++;
- liedizhi+=12;
- }
- }
- void draw_very_big_ascii(unsigned char liedizhi,unsigned char *text)
- {
- unsigned char column,i,j;
- unsigned char cs;
-
- while(*text)
- {
- for(i=0;i<6;i++)
- {
- column=liedizhi+i+i+i+i;
- make_ascii_very_big(ascii[*text-32][i]);
-
- for(j=0;j<4;j++)
- {
- column=liedizhi+i+i+i+i;
- if(column+j>60)
- {
- cs=1;
- column-=61;
- }
- else cs=0;
- LCD_SetColumn(column+j);
- LCD_SetPage(0);
- LCD_SetRam(cs,target4);
- LCD_SetColumn(column+j);
- LCD_SetPage(1);
- LCD_SetRam(cs,target3);
- LCD_SetColumn(column+j);
- LCD_SetPage(2);
- LCD_SetRam(cs,target2);
- LCD_SetColumn(column+j);
- LCD_SetPage(3);
- LCD_SetRam(cs,target1);
- }
- }
- text++;
- liedizhi+=24;
- }
- }
復制代碼 |