看看吧 反正又不要钱- #include <reg52.h>
- #include <intrins.h>
- #define uint unsigned int
- #define uchar unsigned char
- #define nop _nop_()
- #define LCD_data P0 //数据口
-
- 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; //液晶复位端口
-
- 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() //忙检测函数
- {
- 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) //写指令函数
- {
- // 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) //写数据函数
- {
- // 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)//设置页,要那一页直接是那个数字就行了
- { //总共有 8页,一页是 8 行点阵点,即 128*8
- page=0xb8|page; //页得首地址为 0xB8 1011 1XXX
- LCD_write_cmmand(page);
- }
-
- void set_line(uchar startline) //设置显示的起始行
- {
- startline=0xc0|startline; //起始行地址为 0xc0
- LCD_write_cmmand(startline); //设置从哪一行开始,共 0--63 11XX XXXX
- }
-
- void set_column(uchar column) //设置显示的列
- {
- column=column&0x3f; //列的最大值为 64,因为分成两个屏了
- column=0x40|column; //列的首地址为 0x40; 01XX XXXX
- LCD_write_cmmand(column); //设置列位置
- }
-
- void setonoff(uchar onoff) //显示开关函数,1 为开,0 为关
- { onoff=0x3e|onoff; //0x3e是关显示,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++) //控制页数 0--7,共8 页
- {
- set_page(i);
- // set_column(0);
- for(j=0;j<64;j++) //控制列数 0-63,共 64 列
- {
- LCD_write_data(0x00); //写入 0,地址指针自加 1
- }
- }
- }
-
- void LCD_init() //lcd 的初始化
- {
- // LCD_busy(); //忙检测
- delay(100);
- selectscreen(0); //两个屏都选
- setonoff(0); //关显示
- 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列的数据输出,因为一个汉字是 16*16 点阵的
- {
- LCD_write_data(p[i]); //汉字的上半部分
- }
- set_page(page+1); //写下半页
- set_column(column); //控制列
- for(i=0;i<16;i++) //控制16 列数据的输出
- {
- LCD_write_data(p[i+16]);//汉字的下半部分
- }
- }
-
- void main()
- {
- LCD_init(); //lcd 初始化
- clearscreen(0);
- set_line(0);
- while(1)
- {
- display(0,0,4,wo); //我
- }
- }
复制代码
|