看看吧 反正又不要錢- #include <reg52.h>
- #include <intrins.h>
- #define uint unsigned int
- #define uchar unsigned char
- #define nop _nop_()
- #define LCD_data P0 //數(shù)據(jù)口
-
- sbit LCD_RS = P2^6; //寄存器選擇輸入
- sbit LCD_RW = P2^5; //液晶讀/寫控制
- sbit LCD_EN = P2^7; //液晶使能控制
- sbit LCD_CS1 = P3^2; //低電平有效 控制左半屏
- sbit LCD_CS2 = P3^3; //低電平有效 控制右半屏
- //sbit LCD_RST = P3^4; //液晶復(fù)位端口
-
- uchar code wo[]={0x20,0x24,0x24,0x24,0xFE,0x23,0x22,0x20,0x20,0xFF,0x20,0x22,0x2C,0xA0,
- 0x20,0x00,
- 0x00,0x08,0x48,0x84,0x7F,0x02,0x41,0x40,0x20,0x13,0x0C,0x14,0x22,0x41,0xF8,0x00,};
-
- void delay(uchar a) //延時
- {
- uchar x,y;
- for(x=0;x<a;x++)
- for(y=0;y<10;y++);
- }
-
- void LCD_busy() //忙檢測函數(shù)
- {
- LCD_data=0x00;
- LCD_RS = 0;
- LCD_RW = 1;
- LCD_EN = 1;
- while( LCD_data & 0x80 );
- LCD_EN = 0;
- LCD_RS = 0;
- LCD_RW = 1;
- }
-
- void LCD_write_cmmand(uchar cmd) //寫指令函數(shù)
- {
- // LCD_busy();
- LCD_RS = 0;
- LCD_RW = 0;
- LCD_EN = 0;
- LCD_data = cmd; // nop;
- // nop;
- delay(2);
- LCD_EN = 1;
- // nop;
- // nop;
- delay(2);
- LCD_EN = 0;
- }
-
- void LCD_write_data(uchar dat) //寫數(shù)據(jù)函數(shù)
- {
- // LCD_busy();
- LCD_RS = 1;
- LCD_RW = 0;
- LCD_EN = 0;
- LCD_data = dat;
- delay(2);
- LCD_EN = 1;
- delay(2);
- LCD_EN = 0;
- }
-
- void set_page(uchar page)//設(shè)置頁,要那一頁直接是那個數(shù)字就行了
- { //總共有 8頁,一頁是 8 行點陣點,即 128*8
- page=0xb8|page; //頁得首地址為 0xB8 1011 1XXX
- LCD_write_cmmand(page);
- }
-
- void set_line(uchar startline) //設(shè)置顯示的起始行
- {
- startline=0xc0|startline; //起始行地址為 0xc0
- LCD_write_cmmand(startline); //設(shè)置從哪一行開始,共 0--63 11XX XXXX
- }
-
- void set_column(uchar column) //設(shè)置顯示的列
- {
- column=column&0x3f; //列的最大值為 64,因為分成兩個屏了
- column=0x40|column; //列的首地址為 0x40; 01XX XXXX
- LCD_write_cmmand(column); //設(shè)置列位置
- }
-
- void setonoff(uchar onoff) //顯示開關(guān)函數(shù),1 為開,0 為關(guān)
- { onoff=0x3e|onoff; //0x3e是關(guān)顯示,0x3f 是開顯示 0011 111X onoff 只能為0 或者1;
- LCD_write_cmmand(onoff);
- }
-
- void selectscreen(uchar screen) //選屏
- {
- switch(screen)
- {
- case 0:LCD_CS1=0;LCD_CS2=0;break; //全屏
- case 1:LCD_CS1=0;LCD_CS2=1;break; //選左半屏
- case 2:LCD_CS1=1;LCD_CS2=0;break; //選右半屏
- default:break;
- }
- }
-
- void clearscreen(uchar screen) //清屏
- {
- uchar i,j;
- selectscreen(screen);
- LCD_write_cmmand((0xb8)+0);
- LCD_write_cmmand((0x40)+0);
- for(i=0;i<8;i++) //控制頁數(shù) 0--7,共8 頁
- {
- set_page(i);
- // set_column(0);
- for(j=0;j<64;j++) //控制列數(shù) 0-63,共 64 列
- {
- LCD_write_data(0x00); //寫入 0,地址指針自加 1
- }
- }
- }
-
- void LCD_init() //lcd 的初始化
- {
- // LCD_busy(); //忙檢測
- delay(100);
- selectscreen(0); //兩個屏都選
- setonoff(0); //關(guān)顯示
- selectscreen(0); //選屏
- setonoff(1); //開顯示
- clearscreen(0); //清屏
- set_line(0); //開始行為 0
- // set_column(0); //開始列為 0
- // set_page(0); //開始頁為0 }
-
- void display(uchar ss,uchar page,uchar column,uchar *p) //顯示漢字
- {
- uchar i;
- selectscreen(ss); //選屏
- delay(2);
- set_page(page); //寫上半頁
- set_column(column); //控制列
- for(i=0;i<16;i++) //控制 16列的數(shù)據(jù)輸出,因為一個漢字是 16*16 點陣的
- {
- LCD_write_data(p[i]); //漢字的上半部分
- }
- set_page(page+1); //寫下半頁
- set_column(column); //控制列
- for(i=0;i<16;i++) //控制16 列數(shù)據(jù)的輸出
- {
- LCD_write_data(p[i+16]);//漢字的下半部分
- }
- }
-
- void main()
- {
- LCD_init(); //lcd 初始化
- clearscreen(0);
- set_line(0);
- while(1)
- {
- display(0,0,4,wo); //我
- }
- }
復(fù)制代碼
|