原程序是從proteus的示例工程里的,修改了一個函數.
本來需要自己寫的這下省了不少事
- /****************************************************************************
- * Filename: T6963C.h
- * Description: T6963C driver
- ****************************************************************************/
- #include "Config.h"
- #include "Target.h"
- #define width 16 //Display width LCD的最大寬度以16*16為單位
- #define addr_w 0x0000 //Text display buffer base address 文本區首址
- #define addr_t 0x0100 //Graphics display buffer base address 圖形區首址
- // T6963C Pin definition
- #define fs (1<<8) //LCD驅動引腳設置
- #define cd (1<<12)
- #define ce (1<<13)
- #define rd (1<<10)
- #define wr (1<<11)
- #define rst (1<<9)
- #define bf0 (1<<0) //LCD忙狀態標志位
- #define bf1 (1<<1)
- #define bf3 (1<<3)
- // Function declare
- void wr_comm (uint8 comm);
- void wr_data (uint8 dat);
- void chk_busy (uint8 autowr); //test busy flag 獲取LCD狀態標記并等待LCD空閑
- typedef struct typFNT_GB16 // Chinese font structure 16*16中文字模結構體
- { char Index[2]; // font index 字符編碼
- char Msk[32]; // font table 字模
- } typFNT_GB16;
- struct typFNT_GB16 const GB_16[] = // Windway Font table 字模定義
- { "驅", 0x00,0x00,0xF9,0xFE,0x09,0x00,0x49,0x04,0x49,0x84,0x49,0x48,0x49,0x28,0x7D,0x10,
- 0x05,0x18,0x05,0x28,0x35,0x24,0xC5,0x44,0x05,0x84,0x29,0x00,0x11,0xFE,0x00,0x00,
- "動", 0x00,0x20,0x00,0x20,0x7E,0x20,0x00,0x20,0x00,0xFC,0xFF,0x24,0x10,0x24,0x10,0x24,
- 0x24,0x24,0x22,0x24,0x4F,0x44,0xFA,0x44,0x40,0x84,0x01,0x14,0x02,0x08,0x00,0x00,
- "了", 0x00,0x00,0x7F,0xFC,0x00,0x18,0x00,0x60,0x01,0x80,0x01,0x00,0x01,0x00,0x01,0x00,
- 0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x05,0x00,0x02,0x00,
- "嗎", 0x00,0x00,0x03,0xF8,0x78,0x08,0x49,0x08,0x49,0x08,0x49,0x08,0x49,0x08,0x4B,0xFC,
- 0x49,0x04,0x78,0x04,0x4B,0xF4,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x14,0x00,0x08,
-
- };
- // Bitmap table 圖片點陣模
- // Picture: C:\..\Desktop\223.bmp
- // Picture Size: 128 * 64
- uint8 const nBitmapDot[] = // data table
- { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0......................................................
- };
- /*---------------Delay function----------------*/
- void delay (uint16 us)
- { while(us--);
- }
- void delay1 (uint16 ms)
- { uint16 i,j;
- for(i=0;i<ms;i++)
- for(j=0;j<3000;j++)
- ;
- }
- /*---------------LCD init----------------*/
- void init_lcd (void)
- { IO0CLR=rst;
- IO0SET=rst;
- delay1(50);
- IO0CLR=ce;
- IO0SET=wr;
- IO0SET=rd;
- wr_xd(addr_w,0x40); // Set text display buffer base address 設置文本區首地址
- wr_xd(addr_t,0x42); // Set graphics display buffer base address 設置圖形區首地址
- wr_td(width,0x00,0x41); // Set text display width 文本區寬度 字節數/行
- wr_td(width,0x00,0x43); // Set graphics display width 圖形區寬度 字節數/行
- wr_comm(0x81); // Set display mode: text xor graphics 內部字符發生器有效
- wr_td(0x56,0x00,0x22); // Set CGRAM offset address CGRAM偏置地址設置
- wr_comm(0x9c); // Set text and graphic display on 文本顯示啟用 圖形顯示啟用 光標禁止
- }
- /*------------Write data or command to LCD--------------*/
- void wr_od (uint8 dat,uint8 comm) //write one byte data and one byte command 寫單參指令
- { wr_data(dat);
- wr_comm(comm);
- }
- void wr_td (uint8 datl,uint8 dath,uint8 comm) //write two bytes data and one byte command 寫雙參指令通過兩個char
- { wr_data(datl);
- wr_data(dath);
- wr_comm(comm);
- }
- void wr_xd (uint16 dat,uint8 comm) //write a 16 bits data and one byte command 寫雙參指令通過一個int16
- { wr_data(dat);
- wr_data(dat>>8);
- wr_comm(comm);
- }
- void wr_auto (uint8 dat) //Auto write 向當前地址追加一字節數據
- { chk_busy (1);
- IO0CLR=cd;
- IO0SET=rd;
- IO0PIN=(IO0PIN&0XFFFFFF00|dat);
- IO0CLR=wr;
- IO0SET=wr;
- }
- void wr_comm (uint8 comm) //write command 寫一條指令 時序在這里實現
- { chk_busy (0);
- IO0SET=cd;
- IO0SET=rd;
- IO0PIN=(IO0PIN&0XFFFFFF00|comm);
- IO0CLR=wr;
- IO0SET=wr;
- }
- void wr_data (uint8 dat) //write data 寫一字節數據
- { chk_busy (0);
- IO0CLR=cd;
- IO0SET=rd;
- IO0PIN=(IO0PIN&0XFFFFFF00|dat);
- IO0CLR=wr;
- IO0SET=wr;
- }
- void chk_busy (uint8 autowr) //test busy flag 獲取LCD狀態標記并等待LCD空閑
- { IO0SET=0xff;
- IO0SET=cd;
- IO0SET=wr;
- IO0DIR &= 0xFFFFFF00;
- IO0CLR=rd;
- if(autowr)
- { while((IO0PIN&bf3)==0);
- }
- else
- { while((IO0PIN&bf0)==0||(IO0PIN&bf1)==0);
- }
- IO0SET=rd;
- IO0DIR |= 0x000000FF;
- }
- /*--------------Clear RAM------------------*/ //清屏
- void clrram (void)
- { uint8 i,j;
- wr_xd(addr_w,0x24); //T6963C 指令 0x24:設置指針 0xb0:開始自動寫 0xb2:退出自動寫
- wr_comm(0xb0);
- for(j=0;j<144;j++)
- { for(i=0;i<width;i++)
- wr_auto(0x00);
- }
- wr_comm(0xb2);
- }
- /*--------------Display matrix------------------*/
- void disp_dz (uint8 data1,uint8 data2) //兩行交替繪圖
- { uint8 i,j;
- wr_xd(addr_t,0x24);
- wr_comm(0xb0);
- for(j=0;j<64;j++) //j控制繪制行數
- { for(i=0;i<width;i++)
- wr_auto(data1);
- for(i=0;i<width;i++)
- wr_auto(data2);
- }
- wr_comm(0xb2);
- }
- /*--------------Draw a (8*l)*yl picture at addr-------------*/
- void disp_img (uint8 addr,uint8 xl,uint8 yl,uint8 const *img) //顯示一副點陣圖
- { uint8 i,j;
- for(j=0;j<yl;j++)
- { for(i=0;i<xl;i++)
- { wr_xd(addr+0X100+j*width+i,0x24); //T6963C 指令 0x24:設置指針 0xc0: 數據一次寫
- wr_od(img[j*xl+i],0xc0);
- }
- }
- }
- /*----------Draw a Chinese character at addr----------*/
- void disp_chn (uint16 addr,uint8 xl,uint8 yl,uint8 row_xl,uint8 row_yl,uint8 const *chn) //顯示一個漢字16*16
- { uint8 i,j,k,m;
- for(m=0;m<row_yl;m++)
- { for(k=0;k<row_xl;k++)
- { for(j=0;j<yl;j++)
- { for(i=0;i<xl;i++)
- { wr_xd(addr+m*yl*width+k*xl+j*width+i,0x24);
- wr_od(chn[(m*row_xl*xl*yl)+(k*xl*yl)+(j*xl)+i],0xc0);
- }
- }
- }
- }
- }
- /*--------------Draw string------------------*/
- void disp_eng (uint8 const *eng)
- { uint8 i,j;
- wr_xd(addr_w,0x24);
- wr_comm(0xb0);
- for(j=0;j<10;j++)
- { for(i=0;i<width;i++)
- wr_auto(eng[j*width+i]);
- }
- wr_comm(0xb2);
- }
- /*----------Draw a Chinese character at position (x,y)----------*/
- void disp_hz(uint32 x,uint32 y,uint8 *str,uint8 size_str) //顯示一個漢字字符串 size_str為中文字符的個數 X+1表示位移8點Y+1表示下移16點
- { uint8 i,j,n,c1,c2,slen,m=0;
- uint32 tempx,tempy;
- tempx=x;
- tempy=y;
- slen =size_str*2;//strlen((char const*)str); 原版程序的 strlen函數在運行時會卡死所以用一個SIZE參數來替代
- while(m<slen-1)
- {
- c1=str[m+0];c2=str[m+1];
- for(n=0;n<sizeof(GB_16)/sizeof(GB_16[0]);n++)
- { if(c1 == GB_16[n].Index[0]&&c2 == GB_16[n].Index[1])
- break;
- }
- y=tempy;
- x=tempx;
- for(i=0;i<16;i++)
- { for (j=0;j<2;j++)
- { wr_xd((0x0100+256*y+width*i+x+j),0x24);
- wr_od(GB_16[n].Msk[i*2+j],0xc0);
- }
- }
- m=m+2;//one Chinese charecter has two bytes, LCDSIZE/8
- tempx += 2;
- if(tempx>=width)
- { tempx = 0;
- tempy += 1;
- }
- }
- }
- /*----------Draw a character at position (x,y)----------*/
- void disp_zf(uint32 x,uint32 y,uint8 *str) //顯示英文字符串
- { char c;
- wr_xd((addr_w+16*y+x),0x24);
- wr_comm(0xb0);
- while(*str!='\0')
- { c = (*str);
- wr_auto(c-32);
- str++;
- }
- wr_comm(0xb2);
- }
復制代碼
|