兩年前買的屏,現在官網下載已經失效,還好在論壇里找到了pdf,對照自己寫了驅動完成測試。
測試了三種字體分別是宋體8x8,8x16和黑體16X24加粗。
效果如下:
51hei圖片_20200220170506.jpg (101.87 KB, 下載次數: 79)
下載附件
2020-2-20 17:08 上傳
51hei.png (14.09 KB, 下載次數: 62)
下載附件
2020-2-20 20:33 上傳
單片機源程序如下:
- #include <reg51.h>
- #include <intrins.h>
- sbit HX_RST=P1^0;
- sbit HX_CE=P3^7;
- sbit HX_DIN=P3^6;
- sbit HX_CLK=P3^5;
- sbit HX_BL=P3^4;
- //陰碼,逆向,列行式
- unsigned char code tab8x8[][8] =
- {
- {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",32*/
- {0x00,0x00,0x00,0x4E,0x44,0x00,0x00,0x00},/*"!",33*/
- {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0xFE,0x02,0x02,0xFE,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x0F,0x08,0x08,0x0F,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"",127*/
- };
- void clr_HX(void);
- void delay(unsigned int t)
- {
- unsigned int x;
- while (t--)
- {
- x = 600;
- while (x--);
- }
- }
- void write_HX(unsigned char value, bit DC)//寫入一個指令或數據
- {
- int i;
- HX_CE = 0;
- HX_DIN = DC;
- HX_CLK = 1;
- HX_CLK = 0;
-
- for(i=0;i<8;i++)
- {
- if (value&0x80)
- {
- HX_DIN = 1;
- }
- else
- {
- HX_DIN = 0;
- }
-
- HX_CLK = 1;
- value = value<<1;
- HX_CLK = 0;
- }
- }
- void init_HX(void)
- {
- HX_CLK = 0;
- HX_RST = 0;
- delay(100);
- HX_RST = 1;
- HX_CE = 0;
- delay(10);
- HX_CE = 1;
- delay(10);
-
- write_HX(0x2f,0);
- write_HX(0x90,0);
- write_HX(0xa6,0);
- write_HX(0xa4,0);
- write_HX(0xaf,0);
- write_HX(0x40,0);
- write_HX(0xb0,0);
- write_HX(0x10,0);
- write_HX(0x00,0);
-
- clr_HX();
- }
- void set_XY(unsigned char x, unsigned char y)
- {
- write_HX(0xb0+y,0);
- write_HX(0x10|((x & 0x7f) >> 4),0);
- write_HX(0x0f&x,0);
- }
- void clr_HX(void)
- {
- unsigned char i,j;
- set_XY(0,0);
- for (i=0;i<9;i++)
- {
- for (j=0;j<96;j++)
- {
- write_HX(0x00,1);
- }
- }
- }
- void display_char8x8(unsigned char x, unsigned char y, unsigned char input)
- {
- char i,*ch;
- ch=tab8x8[input-32];
- set_XY(x,y);
- for(i=0;i<8;i++)
- {
- write_HX(*(ch+i),1);
- }
- }
- void display_string8x8(unsigned char x, unsigned char y, unsigned char *string)
- {
- unsigned char i = 0;
- while(*(string+i)!='\0')
- {
- display_char8x8(x+8*i,y,*(string+i));
- i++;
- }
- }
- void display_char8x16(unsigned char x, unsigned char y, unsigned char input)
- {
- char i,*ch;
- ch=tab8x16[input-32];
-
- /*上半部*/
- set_XY(x,y);
- for(i=0;i<8;i++)
- {
- write_HX(*(ch+i),1);
- }
-
- /*下半部*/
- set_XY(x,y+1);
- for(i=8;i<16;i++)
- {
- write_HX(*(ch+i),1);
- }
- }
- void display_string8x16(unsigned char x, unsigned char y, unsigned char *string)
- {
- unsigned char i = 0;
- while(*(string+i)!='\0')
- {
- display_char8x16(x+8*i,y,*(string+i));
- i++;
- }
- }
- void display_char16x24(unsigned char x, unsigned char y, unsigned char input)
- {
- char i,*ch;
- ch=tab16x24[input-32];
-
- /*上半部*/
- set_XY(x,y);
- for(i=0;i<16;i++)
- {
- write_HX(*(ch+i),1);
- }
-
- /*中半部*/
- set_XY(x,y+1);
- for(i=16;i<32;i++)
- {
- write_HX(*(ch+i),1);
- }
-
- /*中半部*/
- set_XY(x,y+2);
- for(i=32;i<48;i++)
- {
- write_HX(*(ch+i),1);
- }
- }
- void display_string16x24(unsigned char x, unsigned char y, unsigned char *string)
- {
- unsigned char i = 0;
- while(*(string+i)!='\0')
- {
- display_char16x24(x+16*i,y,*(string+i));
- i++;
- }
- }
- int main()
- {
- init_HX();
-
- display_string8x8(0,0,"Hello");
- display_string8x16(0,1,"Hello");
- display_string16x24(0,3,"Hello");
-
- while(1);
- return 0;
- }
復制代碼
示例代碼已打包,有需要可下載:
lcd_hx1230_demo.rar
(51.4 KB, 下載次數: 12)
2020-2-20 17:10 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|