可以,只是基本的顯示:
- #include <STC8H.H>
- #include "5x8_dot.h"
- #include "HZFONT.h"
- #define uchar unsigned char
- #define uint unsigned int
- #define DATABus P1
- #define CSBus P3
- sbit RS = P3^7; //指令數據選擇 =>pin4
- sbit RW = P3^6; //讀寫控制 =>pin5
- sbit ENABLE = P3^5; //指令數據控制 =>pin6
- sbit Reset = P5^4; //復位 =>pin16
- sbit CS1 = P3^4; //左屏幕選擇,低電平有效 =>pin15
- sbit CS2 = P3^3; //中屏幕選擇 =>pin17
- sbit CS3 = P3^2; //右屏幕選擇 =>pin18
- #define start_line 0xC0 //起始行,可以用于圖形上下滾動
- #define start_page 0xb8 //起始頁
- #define start_column 0x40 //起始列
- #define display_on 0x3f //顯示開
- #define display_off 0x3e //顯示關
- #define screen_left 0 //左屏
- #define screen_mid 1 //左屏
- #define screen_right 2 //右屏
- #define com 0 //命令標志
- #define dat 1 //數據標志
- void LCD_Show_Chinese(uchar x,uchar y,uchar index);
- void lcd_show_string(uchar x,uchar y,uchar *ustr);
- void lcd_show_char(uchar x,uchar y,uchar ustr);
- void LCD_SendData(char data_byte,char data_type,char Screen);
- void LCD_Init();
- void LCD_Fill(uchar fill);
- void Delay1ms(unsigned int T);
- uchar butterfly(uchar byte) ;
- void test();
- void Delay1ms(unsigned int T) //延時1ms
- {
- uchar j;
- while (T)
- {
- for (j=12;j>0;j--);
- T--;
- }
- }
- void main (void) //主程序
- {
- P3M0 = 0x00; P3M1 = 0x00;
- P1M0 = 0x00; P1M1 = 0x00;
- P5M0 = 0x00; P5M1 = 0x00;
- LCD_Init(); //LCD初始化
- LCD_Fill(0); //清屏
- LCD_Show_Chinese(0,0,0);
- LCD_Show_Chinese(16,0,1);
- LCD_Show_Chinese(160,0,2);
- LCD_Show_Chinese(176,0,3);
- LCD_Show_Chinese(168,2,4);
- lcd_show_string(50,0,"LCD_19264 DEMO ");
- lcd_show_string(42,1,"Designed By zhuls");
- lcd_show_string(0,2,"Show a string in LCD screen");
- lcd_show_string(0,3,"if(col<=63) is left;");
- lcd_show_string(0,4,"if(col>63 && col<=127) is middle");
- lcd_show_string(0,5,"if(col>127 && col<=191) is right");
- lcd_show_string(0,6,"if(col>=192) display is invalid!!");
-
- while(1)//主循環
- {
- test();
- }
- }
- //***********************************************
- //一次送一個字節數據,存于data_byte//
- //數據類型由data_type決定,為1是數據,為0是命令
- //左中右屏選擇由screen決定,為0是左屏,為1是中屏,為2是右屏
- //
- //*******************************************
- void LCD_SendData(char data_byte,char data_type,char Screen)//
- {
- switch (Screen)//screen為0是左屏,為1是中屏,為2是右屏
- {
- case 0: CS1=0;CS2=1;CS3=1;break;
- case 1: CS1=1;CS2=0;CS3=1;break;
- case 2: CS1=1;CS2=1;CS3=0;break;
- }
- RW=0;
- RS=data_type;
- DATABus=data_byte;
- Delay1ms(1);
- ENABLE=1;
- Delay1ms(1);
- ENABLE=0;
- Delay1ms(1);
- }
- //*******************************************
- //初始化LCD
- //******************************************
- void LCD_Init()
- {
- char Screen;
- Delay1ms(10);
- for (Screen=0;Screen<3;Screen++)
- {
- LCD_SendData(display_on,com,Screen);//開顯示
- }
- }
- //*******************************************
- //填充數據FILL,
- //fill是要填充的數據
- //******************************************
- void LCD_Fill(uchar fill)
- {
- char column,page;
- char Screen;
- for (Screen=0;Screen<3;Screen++)//0是左屏,1是中屏,2是右屏
- {
- for (page=0;page<8;page++) //清屏
- {
- LCD_SendData(start_page+page,com,Screen);//清屏
- LCD_SendData(start_column,com,Screen);//定位到0列
- for (column=0;column<64;column++)
- {
- LCD_SendData(fill,dat,Screen);
- }
- }
- }
- }
- //*******************************************************
- // 一個字節中的8bit高低互換,
- //bit0=bit7,bit1=bit6...bit6=bit1,bit7=bit0
- //蝶形算法
- uchar butterfly(uchar byte)
- {
- uchar half_h,half_l;
- half_h= (byte & 0x55)<<1;
- half_l= (byte & 0xAA)>>1;
- byte=half_h | half_l;
- half_h= (byte & 0x33)<<2;
- half_l= (byte & 0xcc)>>2;
- byte=half_h | half_l;
- half_h= (byte & 0x0f)<<4;
- half_l= (byte & 0xf0)>>4;
- byte=half_h | half_l;
- return byte;
- }
- //測試顯示
- void test()
- {
- uchar i,j;
- for (j=0;j<3;j++)
- {
- LCD_SendData(start_page+7,com,j);
- LCD_SendData(start_column,com,j);
- for (i=0;i<32;i++)
- {
- LCD_SendData(0x55,dat,j);
- LCD_SendData(0xaa,dat,j);
- Delay1ms(10000);
- }
- }
- Delay1ms(50000);
- for(j=0;j<3;j++)
- {
- LCD_SendData(start_page+7,com,j);
- LCD_SendData(start_column,com,j);
- for (i=0;i<64;i++)
- {
- LCD_SendData(0xff,dat,j);
- Delay1ms(5000);
- }
- }
- }
- //***功能:顯示一個ASCII,5*8字體 ;
- //*** x: 列坐標,0-191列,0-63,左屏,64-127,中屏,128-191,右屏 ;
- //*** y:行坐標,0~7頁,真實地址是 start_page+row;
- //***ustr: 待顯示字符;
- void lcd_show_char(uchar x,uchar y,uchar ustr)
- {
- char i;
- uchar temp;
- uchar cs;
- if (y>=8) return; //頁大于7,無效;
- ustr=ustr-' ';
- for (i=0;i<6;i++)
- {
- if(x<=63) cs=0;
- if(x>63 && x<=127) cs=1;
- if(x>127 ) cs=2;
- if (x>191) return;//列大于191,無效
- LCD_SendData(start_page+y,com,cs);
- LCD_SendData(start_column+x % 64,com,cs);
- temp=dot5x8[ustr][i];
- temp=butterfly(temp);
- LCD_SendData(temp,dat,cs);
- x++;
- }
- }
- //***功能:顯示一個ASCII的字符串,5*8字體 ;
- //*** x: 列坐標,0-191列,0-63,左屏,64-127,中屏,128-191,右屏 ;
- //*** y:行坐標,0~7頁,真實地址是 start_page+row;
- //***ustr: 待顯示字符串;
- void lcd_show_string(uchar x,uchar y,uchar *ustr)
- {
- while(*ustr!='\0')
- {
- lcd_show_char(x,y,*ustr);
- x+=6;
- ustr++;
- }
- }
- /******************************************************************************
- 函數說明:顯示單個16x16漢字
- 入口數據:x,y顯示坐標
- index 要顯示的漢字索引
- 返回值: 無
- ******************************************************************************/
- void LCD_Show_Chinese(uchar x,uchar y,uchar index)
- {
- uchar i,temp,cs;
-
- for (i=0;i<16;i++)
- {
- if(x<=63) cs=0;
- if(x>63 && x<=127) cs=1;
- if(x>127 ) cs=2;
- if (x>191) return;//列大于191,無效
- LCD_SendData(start_page+y,com,cs);
- LCD_SendData(start_column+x % 64,com,cs);
- temp=font16[index][i*2];
- LCD_SendData(temp,dat,cs);
- LCD_SendData(start_page+y+1,com,cs);
- LCD_SendData(start_column+x % 64,com,cs);
- temp=font16[index][i*2+1];
- LCD_SendData(temp,dat,cs);
- x++;
- }
- }
復制代碼 |