欢迎来到天天文库
浏览记录
ID:47519836
大小:161.40 KB
页数:23页
时间:2020-01-12
《用51单片机做的万年历,显示用12864液晶》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、LCD12864.c#include"reg52.h"#include"intrins.h"#defineucharunsignedchar#defineuintunsignedint#defineLCD_DB_PORTP0//液晶DB0~DB7#defineLCD_START_ROW0xc0//起始行#defineLCD_PAGE0xb8//页指令#defineLCD_COL0x40//列指令//液晶引脚定义sbitLCD_DI=P2^0;sbitLCD_RW=P2^1;sbitLCD_E=P2^2;sbitLCD_CS1=P2^3;sb
2、itLCD_CS2=P2^4;sbitLCD_RST=P2^5;bitReverse_Display=0;//检查LCD是否忙bitLCD_Check_Busy(void){LCD_DB_PORT=0xff;LCD_RW=1;_nop_();LCD_DI=0;LCD_E=1;_nop_();LCD_E=0;return(bit)(P0&0x80);}//向LCD发送命令voidLCD_Write_Command(ucharc){while(LCD_Check_Busy());LCD_DB_PORT=0xff;LCD_RW=0;_nop_()
3、;LCD_DI=0;LCD_DB_PORT=c;LCD_E=1;_nop_();LCD_E=0;}//向LCD发送数据voidLCD_Write_Data(uchard){while(LCD_Check_Busy());LCD_DB_PORT=0xff;LCD_RW=0;_nop_();LCD_DI=1;//根据Reverse_Display决定是否反相显示if(!Reverse_Display)LCD_DB_PORT=d;elseLCD_DB_PORT=~d;LCD_E=1;_nop_();LCD_E=0;}//初始化LCDvoidLCD
4、_Initialize(void){LCD_CS1=1;LCD_CS2=1;LCD_Write_Command(0x38);LCD_Write_Command(0x0f);LCD_Write_Command(0x01);LCD_Write_Command(0x06);LCD_Write_Command(LCD_START_ROW);}//通用显示函数//从第P页第L列开始显示W个字节数据,数据在r所指向的缓冲//每字节8位是垂直显示的,高位在下,低位在上//每个8*128的矩形区域为一页//整个LCD右由64*64的左半屏和64*64的右半
5、屏构成voidCommon_Show(ucharP,ucharL,ucharW,uchar*r){uchari;if(L<64)//显示在左半屏或左右半屏{LCD_CS1=1;LCD_CS2=0;LCD_Write_Command(LCD_PAGE+P);LCD_Write_Command(LCD_COL+L);if(L+W<64)//全部显示在左右半屏{for(i=0;i6、]);//左半屏显示LCD_CS1=0;LCD_CS2=1;//右半屏显示LCD_Write_Command(LCD_PAGE+P);LCD_Write_Command(LCD_COL);for(i=64;i7、示8*16点阵字符voidDisplay_A_Char_8X16(ucharP,ucharL,uchar*M){Common_Show(P,L,8,M);Common_Show(P+1,L,8,M+8);}//显示一个16*16点阵汉字voidDisplay_A_WORD(ucharP,ucharL,uchar*M){Common_Show(P,L,16,M);//显示汉字上半部分Common_Show(P+1,L,16,M+16);}Main.c#include"reg52.h"#include"intrins.h"#include"st8、ring.h"#include"LCD_12864.c"#defineucharunsignedchar#defineuintunsignedint/*externvoidLCD
6、]);//左半屏显示LCD_CS1=0;LCD_CS2=1;//右半屏显示LCD_Write_Command(LCD_PAGE+P);LCD_Write_Command(LCD_COL);for(i=64;i7、示8*16点阵字符voidDisplay_A_Char_8X16(ucharP,ucharL,uchar*M){Common_Show(P,L,8,M);Common_Show(P+1,L,8,M+8);}//显示一个16*16点阵汉字voidDisplay_A_WORD(ucharP,ucharL,uchar*M){Common_Show(P,L,16,M);//显示汉字上半部分Common_Show(P+1,L,16,M+16);}Main.c#include"reg52.h"#include"intrins.h"#include"st8、ring.h"#include"LCD_12864.c"#defineucharunsignedchar#defineuintunsignedint/*externvoidLCD
7、示8*16点阵字符voidDisplay_A_Char_8X16(ucharP,ucharL,uchar*M){Common_Show(P,L,8,M);Common_Show(P+1,L,8,M+8);}//显示一个16*16点阵汉字voidDisplay_A_WORD(ucharP,ucharL,uchar*M){Common_Show(P,L,16,M);//显示汉字上半部分Common_Show(P+1,L,16,M+16);}Main.c#include"reg52.h"#include"intrins.h"#include"st
8、ring.h"#include"LCD_12864.c"#defineucharunsignedchar#defineuintunsignedint/*externvoidLCD
此文档下载收益归作者所有