51的12864串行显示(本人亲测,内含接线方法)
12864液晶屏(带字库)51单片机3线串口驱动程序
#include<reg51.h>typedef unsigned char uint8; typedef unsigned int uint16; typedef unsigned long uitn32;sbit CS = P1^0;//片选信号引脚sbit SDA = P1^1;//数据线sbit SCK = P1^2;//串行时钟线//sbit RST = P1^3;//复位引脚//sbit PSB = P1^4;//串并控制引脚code uint8 strint1[] = "I Love You !";/*void delay5ms(void) //误差0us {unsigned char a,b;for(b=185;b>0;b--)for(a=12;a>0;a--);}*///发送一个字节void Send_Byte(uint8 dat){uint8 i;SCK = 0;for(i=0;i<8;i++){SDA = dat&0x80;SCK = 1;dat <<= 1;SCK = 0;}}//读取一个字节数据uint8 Read_Byte(void){uint8 i;uint16 byte = 0;SCK = 0;for(i=0;i<16;i++){byte <<= 1;SCK = 1;if(SDA)byte |= 0x0001;SCK = 0;}byte = ((byte>>4)|(byte>>8))&0x00ff;return ((uint8)(byte));}//读忙标志void Read_Busy(void){uint8 temp;CS = 1;do{Send_Byte(0xfc);//发送读命令temp = Read_Byte();//读取数据}while(temp&0x80);CS = 0;}//发送命令void Write_Cmd(uint8 cmd){uint8 temph = 0;uint8 templ = 0;//制作发送命令格式temph = cmd & 0xf0;templ = (cmd & 0x0f) << 4;Read_Busy();CS = 1;Send_Byte(0XF8);//发送命令命令//发送命令Send_Byte(temph);Send_Byte(templ);CS = 0;}//发送数据void Write_Dat(uint8 dat){uint8 temph = 0;uint8 templ = 0;//制作发送数据格式temph = dat & 0xf0;templ = (dat & 0x0f) << 4;Read_Busy();CS = 1;Send_Byte(0XFA);//发送数据命令Send_Byte(temph);//发送数据Send_Byte(templ);CS = 0;}//在指定位置显示半字宽字符void Dis_HCGROM(uint8 x,uint8 y,uint8 dat) {uint8 addr;switch(y){case 0:addr = 0x80 + x;break;case 1:addr = 0x90 + x;break;case 2:addr = 0x88 + x;break;case 3:addr = 0x98 + x;break;default:break;}Write_Cmd(addr);Write_Dat(dat);}//指定位置显示字符串void Dis_String(uint8 x, uint8 y, uint8 len, uint8 *dat) {uint8 addr,i;switch(y){case 0:addr = 0x80 + x;break;case 1:addr = 0x90 + x;break;case 2:addr = 0x88 + x;break;case 3:addr = 0x98 + x;break;default:break;}Write_Cmd(addr);for(i = 0;i < len;i++){Write_Dat(*dat++);}}//制定位置显示8位无符号数字void Dis_UNum8(uint8 x,uint8 y,uint8 dat){uint8 addr;switch(y){case 0:addr = 0x80 + x;break;case 1:addr = 0x90 + x;break;case 2:addr = 0x88 + x;break;case 3:addr = 0x98 + x;break;default:break;}Write_Cmd(addr);Write_Dat(dat/100%10+'0');Write_Dat(dat/10%10+'0');Write_Dat(dat/1%10+'0');}//制定位置显示16位无符号数字void Dis_UNum16(uint8 x,uint8 y,uint8 dat) {uint8 addr;switch(y){case 0:addr = 0x80 + x;break;case 1:addr = 0x90 + x;break;case 2:addr = 0x88 + x;break;case 3:addr = 0x98 + x;break;default:break;}Write_Cmd(addr);Write_Dat(dat/10000%10+'0');Write_Dat(dat/1000%10+'0');Write_Dat(dat/100%10+'0');Write_Dat(dat/10%10+'0');Write_Dat(dat/1%10+'0');}//在指定位置显示汉字//x范围:0-7,y范围:0-3//dat:汉字字形码void Dis_GB(uint8 x,uint8 y,uint16 dat) {uint8 addr;switch(y){case 0:addr = 0x80 + x;break;case 1:addr = 0x90 + x;break;case 2:addr = 0x88 + x;break;case 3:addr = 0x98 + x;break;default:break;}Write_Cmd(addr);Write_Dat((uint8)(dat >> 8));Write_Dat((uint8)(dat));}//LCD初始化void LCD_Init(void){/*RST = 0;delay5ms();delay5ms();RST = 1;PSB = 0;*/Write_Cmd(0X30);Write_Cmd(0X01);Write_Cmd(0X02);Write_Cmd(0X0C);}void main(void){LCD_Init();while(1){Dis_GB(0,0,0xc9b5);Dis_HCGROM(1,0,0x03);Dis_String(0,1,13,strint1);Dis_UNum8(0,2,250);} }。
12864程序(51总线方式)
; 12864接口程序(MCS51总线方式);*************************************************************************** ;连线图: *LCM---8031* *LCM---8031* *LCM------------8031* *LCM----------8031* ; *DB0---P0.0* *DB4---P0.4* *C/D-------------P2.0* */RD---------P3.7* ; *DB1---P0.1* *DB5---P0.5* *CE--------------P2.1*; *DB2---P0.2* *DB6---P0.6* */RW-------------P3.6; *DB3---P0.3* *DB7---P0.7* */RST------------VDD (详见说明书);注:8031的晶振频率为12MHz;************************************************************************** XPOS EQU 20H ;列方向地址指针(用于LCDPOS子程序)YPOS EQU 21H ;行方向地址指针(用于LCDPOS子程序)BUFFER EQU 22HBUFFERH EQU 23H;CEPIN P2.1;C/DPIN P2.0 0:DATA 1:COMMANDCADDR EQU 0100HDADDR EQU 0000HORG 0000HJMP STARTSTART: MOV SP,#60HMAIN:CALL LCDRESETMOV A,#55HCALL LCDFILLMOV A,#0FFHCALL LCDFILLCALL MAPMOV A,#01HCALL LCDFILLMOV DPTR,#STRING1CALL PUTSTRCALL PUTSTRMOV A,#00HCALL LCDFILLCALL TEXTONJMP STARTTEXTON:MOV A,#97H ;TEXT ONCALL LCDWC ;(文本显示打开)MOV R2,#30MOV R3,#00HMOV A,#41H ;TEXT AREA SETCALL LCDWC3 ;(文本区域设置)MOV R2,#00HMOV R3,#00HMOV A,#40H ;TEXT HOME ADDRESS SETCALL LCDWC3 ;(文本区首地址)MOV DPTR,#0000HMOV R1,#00HMOV XPOS,#0MOV YPOS,#0TEXT: MOV 20H,R1MOV A,20HMOV 20H,ACALL LCDWRITEINC R1CALL DELAYCJNE R1,#80H,TEXTRETDELAY400MS:MOV R0,#20 ;延时子程序(400MS)DL4_PA: MOV R1,#100DL4_PB: MOV R2,#100DJNZ R2,$DJNZ R1,DL4_PBDJNZ R0,DL4_PARETDELAY:MOV R6,#2DLY_PA: MOV R5,#0DLY_PB: MOV R4,#0DJNZ R4,$DJNZ R5,DLY_PBDJNZ R6,DLY_PARETGETSTRCHAR:GSC_PA:CLR AMOVC A,@A+DPTRINC DPTRMOV B,AINC ACLR CJZ GSC_LAXCLR AMOVC A,@A+DPTRINC DPTRSETB CGSC_LAX:RETPUTSTR:CALL DELAYCALL GETSTRCHARPUSH DPLPUSH DPHJNC PSR_LAXJNB B.7,PSR_LBY ;CHINESE:CALL HZKPOSCALL PUTCHARDOTCALL PUTCHARDOTJMP PSR_LBX PSR_LBY:;ENGLISH:CALL HZKPOSCALL PUTCHARDOT PSR_LBX:POP DPHPOP DPLJMP PUTSTRPSR_LAX:POP DPHPOP DPLRET PUTCHARDOT:MOV R7,#16PAC_PA:CLR AMOVC A,@A+DPTRCALL LCDWRITEINC YPOSINC DPTRDJNZ R7,PAC_PACLR CMOV A,XPOSSUBB A,#29JNZ PAC_LAYMOV XPOS,#0JMP PAC_LAX PAC_LAY:INC XPOSCLR CMOV A,YPOSSUBB A,#16MOV YPOS,APAC_LAX:RETHZKPOS:MOV R2,#5HTP_PA:CLR CRLC AXCH A,BRLC AXCH A,BDJNZ R2,HTP_PAMOV DPTR,#HZKDOTADD A,DPLMOV DPL,AMOV A,BADDC A,DPHMOV DPH,ARETLCDFILL: ;LCD整屏显示A的内容 MOV R7,AMOV YPOS,#0LFL_PB: MOV XPOS,#0LFL_PA: MOV A,R7CALL LCDWRITE ;定位并写数据CALL CUSORNEXTMOV A,XPOSJNZ LFL_PA ;XPOS。
51单片机 12864液晶显示并口和串口连接程序
sent((DATA&0X0F)<<4); //低位
}
void AUTO(uchar *add)
{
uchar cnt=0;
while(*(add+cnt)!='\0')
{
writLCD(1,*(add+cnt));
cnt++;
}
}
void wirtthings(uchar lines,uchar *add)//writ data to which line
else
RW=0;
delay(10);
SCK=1;
DATA=DATA<<1;
}
}
void writLCD(bit flag,uchar DATA) //writ COM or data in address
{
if(flag)
sent(0xfa);//1写数据
else
sent(0xf8);//0写指令
//writLCD(0,0x01);
wirtthings(4,"什么,only You!");
//writLCD(0,0x01);
wirtthings(1,"联系方式:");
//writLCD(0,0x01);
wirtthings(2,"QQ:452658536");
delay(100);
writLCD(0,0x01);
}
}
void delay(uchar i)
{
uchar j;
while(i--)
51单片机串行12864显示.c
{
CH = 0;
delay(1);
lcdinit();
delay(10);
while(1)
{
Test();
delay(5000);
}
}
* 名称 : write_com()
* 功能 : 写串口指令
* 输入 : cmdcode
* 输出 : 无
***********************************************************************/
void write_com(unsigned char cmdcode)
* 输入 : t
* 输出 : 无
***********************************************************************/
void delay(unsigned int t)
{
unsigned int i,j;
for(i=0; i<t; i++)
* 名称 : hzkdis()
* 功能 : 显示字符串
* 输入 : *s
* 输出 : 无
***********************************************************************/
void hzkdis(unsigned char code *s)
* 名称 : lcdinit()
* 功能 : 初始化函数
* 输入 : cmdcode
* 输出 : 无
***********************************************************************/
51单片机12864液晶字符显示
51单片机12864液晶字符显示51 单片机的12864 液晶字符显示,采用液晶的并行接法#include#include#include#define uchar unsigned char#define uint unsigned int#define LCD_data P0 //定义数据口sbit LCD_RS=P3 ; //数据命令选择端,高电平为写数据,低电平写命令sbit LCD_RW=P3;//读写控制端,高电平读信息,低电平写信息sbit LCD_EN=P3;// 使能端sbit LCD_PSB=P3;//拉高,选择并行//单片机特殊功能位声明uchar code dis1[]={“姓名:浩泉”};uchar code dis2[]={“性别:男”};uchar code dis3[]={“卡号:050817”};uchar code dis4[]={“”};void delay_1ms(uint x) //延时函数1ms{ uint i,j; for(j=0;jvoid write_cmd(uchar cmd) //写命令函数,请参考12864 液晶手册{ LCD_RS=0; //低电平,写入命令LCD_RW=0;P0=cmd; // 赋值delay_1ms(5); LCD_EN=1;//使能端拉高送入命令delay_1ms(5); LCD_EN=0;}void write_date(uchar date) //写数据{ LCD_RS=1; LCD_RW=0;P0=date; delay_1ms(5); LCD_EN=1; //使能端拉高送入数据delay_1ms(5); LCD_EN=0;}void lcd_pose(uchar X,uchar Y) //液晶显示位置函数{ uchar S,pose; switch (X) { case 0: S=0x80; //液晶第一行显示break;case 1: S=0x90; //第二行显示break;case 2: //第三行显示S=0x88; break;case 3: //第四行显示S=0x98; break;} pose=S+Y; write_cmd(pose);}。
9--12864液晶显示原理+电路图+程序
带中文字库的128X64是一种具有4位/8位并行、2线或3线串行多种接口方式,内部含有国标一级、二级简体中文字库的点阵图形液晶显示模块;其显示分辨率为128×64,内置8192个16*16点汉字,和128个16*8点ASCII字符集.利用该模块灵活的接口方式和简单、方便的操作指令,可构成全中文人机交互图形界面。
可以显示8×4行16×16点阵的汉字.也可完成图形显示.低电压低功耗是其又一显著特点。
由该模块构成的液晶显示方案与同类型的图形点阵液晶显示模块相比,不论硬件电路结构或显示程序都要简洁得多,且该模块的价格也略低于相同点阵的图形液晶模块。
基本特性:l低电源电压(VDD:+3.0--+5.5V)l显示分辨率:128×64点l内置汉字字库,提供8192个16×16点阵汉字(简繁体可选)l内置128个16×8点阵字符l2MHZ时钟频率l显示方式:STN、半透、正显l驱动方式:1/32DUTY,1/5BIASl视角方向:6点l背光方式:侧部高亮白色LED,功耗仅为普通LED的1/5—1/10 l通讯方式:串行、并口可选l内置DC-DC转换电路,无需外加负压l无需片选信号,简化软件设计l工作温度:0℃-+55℃,存储温度:-20℃-+60℃模块接口说明*注释1:如在实际应用中仅使用串口通讯模式,可将PSB接固定低电平,也可以将模块上的J8和“GND”用焊锡短接。
*注释2:模块内部接有上电复位电路,因此在不需要经常复位的场合可将该端悬空。
*注释3:如背光和模块共用一个电源,可以将模块上的JA、JK用焊锡短接。
2.2并行接口管脚号管脚名称电平管脚功能描述1VSS0V电源地2VCC 3.0+5V电源正3V0-对比度(亮度)调整4RS(CS)H/LRS=“H”,表示DB7——DB0为显示数据RS=“L”,表示DB7——DB0为显示指令数据5R/W(SID)H/L R/W=“H”,E=“H”,数据被读到DB7——DB0R/W=“L”,E=“H→L”,DB7——DB0的数据被写到IR或DR6E(SCLK)H/L使能信号7DB0H/L三态数据线8DB1H/L三态数据线是用于模块屏幕显示开和关的控制。
12864串行显示中文讲解
12864串行显示中文,按键选择显示页面,并且可调数值。
单片机P1口接矩阵按键,其它接口按程序中定义去接只需要接12864LCD上GND VCC RS RW E PSB RST A K程序如下/********************************12864.h头文件*******************************/ #ifndef _12864_h#define _12864_h/*****包含头文件**************/#include<reg51.h>/********定义I/0口**********/#define GPIO_KEY P1sbit LCD12864_SCLK = P2^7; //Esbit LCD12864_SID = P2^5; //RWsbit LCD12864_CS = P2^6; //RSsbit LCD12864_RET= P2^0;sbit LCD12864_PSB =P2^2;/*声明全局变量*/extern unsigned char keyvalue;/******声明全局函数*********/void Delay1ms(unsigned int); //声明延时函数unsigned char KeyDown(void);void LCD_sendbyte(unsigned char);void WrCom(unsigned char);void WrDat(unsigned char);void LcdInit(void);//void Print(unsigned char);void SetAddress( unsigned char,unsigned char );void DisplayString(unsigned char x ,unsigned char y,unsigned char *add);#endif/********************************12864.C*************************************/ #include"12864.h"#include<reg51.h>#include"string.h"//#define LCM_ST7920_FIRST_LINE_ADDRESS 0x80//#define LCM_ST7920_SECOND_LINE_ADDRESS 0x90//#define LCM_ST7920_THIRD_LINE_ADDRESS 0x88//#define LCM_ST7920_FOURTH_LINE_ADDRESS 0x98/*定义全局变量*/unsigned char keyvalue=0;/****************************************************************************** ** 函数名: Delay1ms* 函数功能: 延时函数,延时1ms* 输入: c* 输出 e : 无* 说名: 该函数是在12MHZ晶振下,12分频单片机的延时。
基于51单片机的12864显示温度(ds18b20)
#ifndef __LCD12864_H#define __LCD12864_H//---包含头文件---//#include<reg51.h>//---重定义关键词---//#ifndef uchar#define uchar unsigned char#endif#ifndef uint#define uint unsigned int#endif//---如果使用画图模式定义这个---//#define LCD12864_PICTURE//---定义使用的IO口---//#define LCD12864_DATAPORT P1 //数据IO口sbit LCD12864_RS = P2^6; //(数据命令)寄存器选择输入sbit LCD12864_RW = P2^5; //液晶读/写控制sbit LCD12864_EN = P2^7; //液晶使能控制sbit LCD12864_PSB = P3^2; //串/并方式控制sbit LCD12864_RST = P3^4; //复位端//---声明全局函数---//void LCD12864_Delay1ms(uint c);uchar LCD12864_Busy(void);void LCD12864_WriteCmd(uchar cmd);void LCD12864_WriteData(uchar dat);void LCD12864_Init();void LCD12864_ClearScreen(void);void LCD12864_SetWindow(uchar x, uchar y);void LCD12864_DrowPic(uchar *a);void LCD12864_DrowPoint(uchar x, uchar y);#endif#ifndef __TEMP_H_#define __TEMP_H_#include<reg51.h>//---重定义关键词---//#ifndef uchar#define uchar unsigned char#endif#ifndef uint#define uint unsigned int#endif//--定义使用的IO口--//sbit DSPORT=P3^3;//--声明全局函数--//void Delay1ms(uint );uchar Ds18b20Init();void Ds18b20WriteByte(uchar com);uchar Ds18b20ReadByte();void Ds18b20ChangTemp();void Ds18b20ReadTempCom();int Ds18b20ReadTemp();#endif#include"lcd12864.h"/****************************************************************************** ** 函数名: LCD12864_Delay1ms* 函数功能: 延时1MS* 输入: c* 输出: 无******************************************************************************* /void LCD12864_Delay1ms(uint c)uchar a,b;for(; c>0; c--){for(b=199; b>0; b--){for(a=1; a>0; a--);}}}/****************************************************************************** ** 函数名: LCD12864_Busy* 函数功能: 检测LCD是否忙* 输入: 无* 输出: 1或0(1表示不忙,0表示忙)******************************************************************************* /uchar LCD12864_Busy(void){uchar i = 0;LCD12864_RS = 0; //选择命令LCD12864_RW = 1; //选择读取LCD12864_EN = 1;LCD12864_Delay1ms(1);while((LCD12864_DA TAPORT & 0x80) == 0x80) //检测读取到的值{i++;if(i > 100){LCD12864_EN = 0;return 0; //超过等待时间返回0表示失败}}LCD12864_EN = 0;return 1;}/****************************************************************************** ** 函数名: LCD12864_WriteCmd* 函数功能: 写命令* 输入: cmd* 输出: 无******************************************************************************* /void LCD12864_WriteCmd(uchar cmd){uchar i;i = 0;while( LCD12864_Busy() == 0){LCD12864_Delay1ms(1);i++;if( i>100){return; //超过等待退出}}LCD12864_RS = 0; //选择命令LCD12864_RW = 0; //选择写入LCD12864_EN = 0; //初始化使能端LCD12864_DATAPORT = cmd; //放置数据LCD12864_EN = 1; //写时序LCD12864_Delay1ms(1);LCD12864_EN = 0;}/****************************************************************************** ** 函数名: LCD12864_WriteData* 函数功能: 写数据* 输入: dat* 输出: 无******************************************************************************* /void LCD12864_WriteData(uchar dat){uchar i;i = 0;while( LCD12864_Busy() == 0){LCD12864_Delay1ms(1);i++;if( i>100){return; //超过等待退出}}LCD12864_RS = 1; //选择数据LCD12864_RW = 0; //选择写入LCD12864_EN = 0; //初始化使能端LCD12864_DATAPORT = dat; //放置数据LCD12864_EN = 1; //写时序LCD12864_Delay1ms(1);LCD12864_EN = 0;}/****************************************************************************** ** 函数名: LCD12864_ReadData* 函数功能: 读取数据* 输入: 无* 输出: 读取到的8位数据******************************************************************************* /#ifdef LCD12864_PICTUREuchar LCD12864_ReadData(void){uchar i, readValue;i = 0;while( LCD12864_Busy() == 0){LCD12864_Delay1ms(1);i++;if( i>100){return 0; //超过等待退出}}LCD12864_RS = 1; //选择命令LCD12864_RW = 1;LCD12864_EN = 0;LCD12864_Delay1ms(1); //等待LCD12864_EN = 1;LCD12864_Delay1ms(1);readValue = LCD12864_DA TAPORT;LCD12864_EN = 0;return readValue;}#endif/****************************************************************************** ** 函数名: LCD12864_Init* 函数功能: 初始化LCD12864* 输入: 无* 输出: 无******************************************************************************* /void LCD12864_Init(){LCD12864_PSB = 1; //选择并行输入LCD12864_RST = 1; //复位LCD12864_WriteCmd(0x30); //选择基本指令操作LCD12864_WriteCmd(0x0c); //显示开,关光标LCD12864_WriteCmd(0x01); //清除LCD12864的显示内容}/****************************************************************************** ** 函数名: LCD12864_ClearScreen* 函数功能: 在画图模式下,LCD12864的01H命令不能清屏,所以要自己写一* * 屏函数* 输入: 无* 输出: 无******************************************************************************* /#ifdef LCD12864_PICTUREvoid LCD12864_ClearScreen(void){uchar i,j;LCD12864_WriteCmd(0x34); //开启拓展指令集for(i=0;i<32;i++) //因为LCD有纵坐标32格所以写三十二次{LCD12864_WriteCmd(0x80+i); //先写入纵坐标Y的值LCD12864_WriteCmd(0x80); //再写入横坐标X的值for(j=0;j<32;j++) //横坐标有16位,每位写入两个字节的的数据,也{ //就写入32次以为当写入两个字节之后横坐标会自LCD12864_WriteData(0x00); //动加1,所以就不用再次写入地址了。
基于 51 单片机的程控放大器设计 12864 显示
基于51单片机的程控放大器设计12864显示一、设计要求1. AB间电压为从100mV到1V间变化,频率为1kHz的正弦交流电,然后通过VCA810后得到Vo,按下按键1,Vo有效值始终为1V;按下按键2,Vo有效值始终为2V;2.自制有效值检测电路(参考万用表交流电压检测电路)3. 12864及以上以上分辨率单色或者彩色液晶显示。
二、所用芯片VCA810 TL084 TLC2543 REF5040 TLV5618 REF5020 二、设计思路根据设计要求,根据vca810的特性,我们利用DA进行对输出交流电压倍数的控制,并充分利用TL084芯片的作用,将TL084的四个运放都分别用于DA的反向比例、vca810出来的正向放大、有效电路的应用和有效值出来的电压跟随,达到了很好的效果,交流波形显示很精确。
并且由于vca810交流信号出来经过了一个放大,很好的弥补了其输出电压为正负1.8V的影响,能够达到设计要求的稳定在2V的基本条件,并且图像没有失真。
最后利用PID算法,将设定的值与输出的电压值进行比较,整定参数,利用按键使输出的电压稳定在1V和2V。
我们小组人员经过长时间的调试,虽然没有将其调到最好,最终还是又很小幅度的跳动,但基本满足老师的要求。
三、设计原理图Pcb图四、调试在设计电路板时,我将每个模块分的很清楚,因此,在调试时,我们分小块测试,当每个小模块都通过时,再用跳帽将他们连接起来,避免了盲目的调试,所以,在硬件方面我们很快就测试成功了,剩下的就是PID的控制,由于是第一次用,所以,对其参数的整定还不怎么会调,也花了一些时间在上面,最终能勉强的将输出电压稳定下来,基本达到要求。
但今后我们肯定还会对PID进行更多的学习,以希望真正掌握PID算法。
五、实物图。
LCD12864电路接法[转摘]
LCD12864电路接法[转摘]就刚接触单片机驱动液晶屏的同志们所碰到的问题,现在做一总结一、无任何显示A:硬件问题1:这种情况是新手最常碰到的问题,碰到这种情况首先对应硬件pdf文档,确定你的接线没有任何问题,如果是51单片机,用P0口一定要加10K的上拉电阻,不然程序正常了也显示不出来。
2:另外要注意第三脚VO的连接方式,这个是对比度电位引脚,实际中常采用10k的可变电阻滑动端连接vo脚,固定端的一段接vcc,另外一端应根据实际硬件连接。
如果用的是1602,另一端直接接到gnd就可以了,但是对于12864就应该看18脚的标记了,如果写的是NC ,那么另一端直接接地,如果是VEE,那么就应该接到18脚,因为这时的18脚是负压输出端。
根据这点确定你的对比对调节电路接法正确无误。
3:关于串并行选择的问题。
串并行选择对于有字库的12864适用(1602的四线驱动也可以叫做串行驱动),如果有PSB引脚,那么你的屏应该可以支持串并行了。
串并行的选择决定于PSB引脚的电位,一般是低电平为串行模式,高电平为并行模式。
有些同志在使用的时候对PSB进行了电位定义但是没有任何显示,这是你应该注意一下LCM板上焊点,尤其是和PSB引脚相连的那些起跳线作用的焊点。
因为大多厂家在出厂的时候就预先设置为并行模式,也就是接到高电位上(VCC)。
碰到这种情况把焊点跳线重新焊接一下,接到低电位上就可以了。
模式选择错误不显示是小问题,由于屏电路的不同,可能你在驱动的时候损坏屏或者单片机,因为选择不对,定义的电位相当于短路,明白了吧。
B:软件问题软件问题一般也就是定义的引脚不对,这种情况出现于真正的初学者,在copy别人的程序或者屏本身的模板程序没有修改引脚的定义,这种情况比较简单,只需要把引脚对应的端口重新定义一下就可以了。
二、显示不清楚A:屏上的vo引脚(3脚)电位不对如果你按照我上面的说法接了对比度电路,这时你只需要调节电位器的旋钮就可以了,最终可以得到你满意的对比度,使显示最清晰。
51单片机实现定时器2、12864液晶显示、显示图片、滚动字符、DS18B20、转速、超声波测距、速度实时显示
//*******************资源配置***********************////******计数器0用于超声波记录接收端高电平时长*******////******计数器1用于记录1s内外部脉冲数目即转速*******////********定时器2用于精确定时,定时时间50ms*********////*****************P3^5用于脉冲计数*****************//#include <reg52.H>#include <intrins.h>//*************特殊引脚定义*****************//sbit RX = P1^0; //超声波接收端sbit TX = P1^1; //超声波触发端sbit RS = P2^6;//LCD数据/命令控制端sbit RW = P2^5;//读写控制端sbit EN = P2^7; //使能端sbit RES= P2^4; //复位端sbit PSB= P2^3; //并口/串口选择端sbit DQ = P3^7; //DS18B20数据端sbit BEEP=P1^5; //蜂鸣器#define DataPort P0 //MCU P0<------> LCM#define uchar unsigned char#define uint unsigned int//***********Function Definition*********************////****************函数声明***************************//void LCD_Write_number(uchar s);void Write_char(bit start, uchar ddata); //写入某坐标void Send_byte(uchar bbyte);void Lcd_init(void);//lcd初始化void Disp_img(uchar *img);//显示图片void LCD_Write_string(uchar X,uchar Y,uchar*s); //写入某字符串void LCD_set_xy( uchar x,uchar y );void Lcd_Mark3(void); //画面3void Lcd_Mark2(void); //画面2bit temp_flag; //判断DS18B20正常工作位DS18B20_init();//DS18B20初始化void delay(uint num);//DS18B20延时函数void Delaynms(uint di);//短延时void delayms(uint x);//1ms延时函数readonebyte(void);//读一个字节函数void writeonebyte(uchar dat); //写一个字节函数void gettemperture(void);//获取温度值void temperture_display(); //温度显示函数void tempconv(); //温度转换void beep(); //蜂鸣器响一声函数void timer_init(); //中断初始化函数(计数器0,计数器1,定时器2)void zhuansu_display(); //转速显示函数void speed_conv(); //速度转换函数void speed_display(); //速度显示函数void chaoshengbo_conv(void); //超声波转换//***************变量定义*****************//uchar data temp_dat[2]={0}; //temp[0],temp[1]用来存放温度的低、高8位uchar data DQdisp_buf[5]={0}; //温度显示缓冲区uchar zhuansu_buff[6]={0}; //转速显示缓存uchar speed_buff[6]={0};//速度显示缓存uchar temp_comp; //存放温度整数部分uchar DS18B20_OK,speed2;//DS18B20_OK=0复位正常uchar t2=0,T,L,H,WENDU; //t2代表timer2中断次数,T代表温度整数部分//H:温度高8位,L:温度低8位uint time=0; //超声波往返时间long S=0,num1=0,speed; //s表示超声波距离,num1表示发动机转速// speed表示车轮转速=》速度bit flag =0; //超声波中断溢出标志位uchar disbuff[4]={0}; //超声波数据显示缓存uchar code num[]={"09 :.-℃"};uchar code line1_data[]={"速度:km/h"};uchar code line2_data[]={"转速:r/min"};uchar code line3_data[]={"前方车距:m"};uchar code line4_data[]={"车内温度: "};uchar code line5_data[]={" #**欢迎使用**# "};uchar code line6_data[]={" 您的安全"};uchar code line7_data[]={" 是全家人"};uchar code line8_data[]={" 最大的幸福···"};uchar code picture[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x06,0x30,0x01,0xE0,0x00,0x00,0x2A,0x00,0x00,0xD8,0x00,0x00,0x00,0x00,0x 00,0x00,0x0F,0x7B,0x63,0xE0,0x00,0x00,0x22,0x00,0x01,0x24,0x00,0x00,0x00,0x00,0x0 0,0x00,0x0F,0xFB,0x63,0x07,0x34,0x00,0x14,0x00,0x01,0x04,0x00,0x00,0x00,0x00,0x0 0,0x00,0x0D,0xDB,0x63,0x01,0xBC,0x00,0x08,0x00,0x00,0x88,0x00,0x00,0x00,0x00,0x0x00,0x0C,0x1B,0x63,0x07,0xB0,0x00,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x00,0x0 0,0x00,0x0C,0x1B,0x63,0xED,0xB0,0xDB,0x00,0x01,0x00,0x20,0x00,0x00,0x00,0x00,0x 00,0x00,0x0C,0x19,0xE1,0xE7,0xB0,0xDB,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x 00,0x00,0x0C,0x19,0xE1,0xE7,0xB0,0xDB,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x 00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x05,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x0A,0x80,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x0A,0x00,0x00,0xFF,0xF8,0xE0,0x05,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x06,0xC0,0x15,0x00,0x1F,0xFF,0xFF,0xC0,0x02,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x09,0x20,0x11,0x00,0xFB,0xFF,0xE1,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x08,0x20,0x0A,0x03,0x9F,0x00,0x9E,0x3E,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x04,0x40,0x04,0x0E,0x70,0x00,0x81,0xC7,0x80,0x01,0x40,0x00,0x00,0x00,0x0 0,0x00,0x02,0x80,0x00,0x1D,0x80,0x00,0xE0,0x61,0xE0,0x02,0xA0,0x00,0x00,0x00,0x 00,0x00,0x01,0x00,0x00,0x77,0x9F,0xFC,0xF0,0x18,0xF8,0x02,0x20,0x00,0x00,0x00,0x00x00,0x00,0x00,0x01,0xDF,0x00,0x00,0xF3,0x0C,0x3C,0x01,0x40,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x03,0x9E,0x00,0x00,0xF8,0x06,0x1E,0x00,0x80,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x07,0x0E,0x30,0x01,0xFC,0x7F,0x07,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x07,0x0E,0x30,0x01,0xFC,0x7F,0x07,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x7E,0xFF,0xFF,0xFF,0xFF,0xFF,0x83,0xC0,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x0F,0xFD,0xFF,0xFF,0xFF,0xFF,0xFC,0x01,0xF0,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x3F,0x81,0xFF,0x00,0x00,0x00,0x00,0x1F,0xF0,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0xFE,0xF0,0x00,0x00,0x01,0x00,0x00,0xC0,0x1C,0x00,0x00,0x00,0x00,0x0 0,0x00,0x03,0xC0,0x07,0x80,0x00,0x03,0xE0,0x07,0x00,0x1C,0x00,0x00,0x00,0x00,0x0 0,0x00,0x03,0x80,0x03,0x40,0x00,0x03,0xE0,0x0C,0x00,0x0E,0x00,0x00,0x00,0x00,0x0 0,0x00,0x07,0x00,0x00,0xC0,0x00,0x00,0x20,0x18,0x00,0x07,0x00,0x00,0x00,0x00,0x0 0,0x00,0x09,0x01,0x80,0x60,0x00,0x00,0x20,0x73,0x9F,0x03,0x80,0x00,0x00,0x00,0x0 0,0x00,0x1E,0x0F,0xF2,0x20,0x00,0x00,0x20,0x67,0xFF,0xC1,0xC0,0x00,0x00,0x00,0x0 0,0x00,0x1E,0x1F,0xF9,0x30,0x00,0x00,0x20,0xEF,0xFF,0xE0,0xE0,0x00,0x00,0x00,0x00 ,0x00,0x38,0x3F,0xFC,0x90,0x00,0x00,0x20,0xCB,0xFF,0xF9,0xF0,0x00,0x00,0x00,0x00 ,0x00,0x7F,0x7F,0xFE,0x10,0x00,0x00,0x20,0xDB,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x00, 0x00,0x6E,0xF9,0xBF,0x10,0x00,0x00,0x20,0xF7,0xED,0xFF,0xF0,0x00,0x00,0x00,0x00 ,0x00,0x7C,0xFC,0x3F,0x10,0x00,0x00,0x20,0x67,0xE1,0xFD,0xE0,0x00,0x00,0x00,0x0 0,0x00,0x7C,0xFC,0x3F,0x10,0x00,0x00,0x20,0x67,0xE1,0xFD,0xE0,0x00,0x00,0x00,0x0 0,0x00,0x38,0xFC,0x3F,0x18,0x00,0x00,0x20,0x87,0xE0,0xFD,0xC0,0x00,0x00,0x00,0x0 0,0x00,0x38,0xF1,0x8F,0x18,0x00,0x1F,0xE7,0x87,0x9C,0x7D,0xC0,0x00,0x00,0x00,0x0 0,0x00,0x1C,0xFE,0x1F,0x81,0xFF,0xFF,0xC0,0x0F,0xE0,0xFF,0x80,0x00,0x00,0x00,0x00, 0x00,0x0C,0xFC,0x3F,0x80,0x00,0x00,0x00,0x0F,0xE1,0xF8,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0xF9,0xBF,0xFF,0xFF,0xFF,0xFF,0xFF,0xEC,0xFE,0x00,0x00,0x00,0x00,0x00, 0x00,0x03,0xF9,0xBF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00, 0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,0x00,0x00,0x00,0x00,0x00};//************************************************////********** DS18B20 ********////************************************************////************************************************////************蜂鸣器响一声函数*******//void beep(){BEEP=0; //开蜂鸣器delayms(500); //延时半秒BEEP=1; //关蜂鸣器delayms(500); //延时半秒}//************温度转换***************//void tempconv(){uchar sign=0; //定义符号标志位uchar temp; //定义温度数据暂存if(H>127) //大于127,即高4位全为1,即温度为负值{L=(~L)+1; //取反加1,将补码变成原码if((~L)>=0xff) //H=(~L)+1; //取反加一else H=~H; //否则只取反sign=1; //置符号标志位为1}temp=L&0x0f; //取小数位DQdisp_buf[0]=temp*0.625; //所获得的是四位数,所测温度加大了10倍DQdisp_buf[0]=DQdisp_buf[0]%1000%100%10;//将小数部分转换成ASCII码temp_comp=((L&0xf0)>>4|(H&0x0f)<<4); //取温度整数部分DQdisp_buf[3]=temp_comp/100; //温度百位temp=temp_comp%100; //温度的十位和个位一起DQdisp_buf[2]=temp/10; //温度十位DQdisp_buf[1]=temp%10; //温度个位if(DQdisp_buf[3]==0) //如果温度的百位为0{DQdisp_buf[3]=17; //则不显示,if(DQdisp_buf[2]==0) //在这种前提下,如果十位也为0的话,DQdisp_buf[2]=17; //不显示十位}if(sign)DQdisp_buf[3]=13; //如果符号标志位为1,则显示负号}//************温度显示函数**************//void temperture_display(){LCD_set_xy(4,4); //从第四行第5列开始显示LCD_Write_number(11);LCD_Write_number(DQdisp_buf[3]); //显示百位LCD_Write_number(DQdisp_buf[2]); //显示十位LCD_Write_number(DQdisp_buf[1]); //显示个位LCD_Write_number(12); //小数点LCD_Write_number(DQdisp_buf[0]); //十分位LCD_set_xy(4,7);Write_char(1,num[14]);Write_char(1,num[15]);}//************获取温度值*****************//void gettemperture(void){uchar i;DS18B20_init(); //DS18B20初始化if(DS18B20_OK==0) //如果正常{writeonebyte(0xcc); //跳过读序列号的操作writeonebyte(0x44); //启动温度转换for(i;i<100;i++) //调用显示函数延时,等待A/D转换完成,分辨率为12位的需要延时750ms以上temperture_display();DS18B20_init(); //DS18B20初始化writeonebyte(0xcc); //跳过读序列号的操作writeonebyte(0xbe); //读取温度寄存器temp_dat[0]=readonebyte(); //温度低8位放入temp_dat[0]temp_dat[1]=readonebyte(); //温度高8位放入temp_dat[1]L=temp_dat[0]; //温度低8位H=temp_dat[1]; //温度高8位temp_flag=1; //接收正常}else temp_flag=0; //否则接收不正常}//************写一个字节函数*****************//void writeonebyte(uchar dat){uchar i=0;for(i=8;i>0;i--){DQ=0;DQ=dat&0x01;delay(5);DQ=1;dat>>=1;}}//************读一个字节函数***************//readonebyte(void){uchar i=0;uchar dat=0;for(i=8;i>0;i--){DQ=0;dat>>=1;DQ=1;if(DQ)dat|=0x80;delay(4);}return (dat);}//***************DS18B20延时函数************//void delay(uint num){while(--num);}//***************DS18B20初始化*******************//DS18B20_init(void){DQ=1; //DQ复位delay(8); //延时DQ=0; //单片机将DQ拉低delay(90); //等待至少480us的时间DQ=1; //拉高总线delay(8); //等待DS18B20反馈存在低脉冲,单片机检测DS18B20_OK=DQ; //如果为0,则初始化成功,为1,初始化失败delay(100);DQ=1;return (DS18B20_OK); //返回信号,若DS18B20_OK为0,则存在,若DS18B20_OK=1;则不存在}//************************************************////********** LCD 12864 ********////************************************************////************************************************/void Lcd_init(void) //初始化LCD{delayms(40); //大于40MS的延时程序PSB=1; //设置为8BIT并口工作模式delayms(1); //延时RES=0; //复位delayms(1); //延时RES=1; //复位置高delayms(1);Write_char(0,0x30); //选择基本指令集delayms(1); //延时大于100usWrite_char(0,0x30); //选择8bit数据流delayms(1); //延时大于37usWrite_char(0,0x0c); //开显示(无游标、不反白)delayms(1); //延时大于100usWrite_char(0,0x01); //清除显示,并且设定地址指针为00Hdelayms(1); //延时大于10msWrite_char(0,0x06); //指定在资料的读取及写入时,设定游标的移动方向及指定显示的移位,光标从右向左加1位移动delayms(1); //延时大于100us}/******************************************************************** **********//*------------------------------------------------检测忙位------------------------------------------------*/void Check_Busy(){RS=0;RW=1;EN=1;DataPort=0xff;while((DataPort&0x80)==0x80);//忙则等待EN=0;}void Write_char(bit start, uchar ddata) //start=0写指令,start=1写数据{if(start==0) //如果start==0,检查忙碌位后写指令{ Check_Busy(); //忙碌则等待RS=0;RW=0;EN=0;DataPort=ddata; //发送指令_nop_();_nop_();EN=1;_nop_();_nop_();_nop_();_nop_();EN=0;}else //如果start==1,即可以开始{ Check_Busy(); //再次检查,进行些数据操作RS=1;RW=0;EN=1;DataPort=ddata;EN=0;}}/******************************************************************** **********/void Delaynms(uint di) //延时0.1ms左右{uint da,db;for(da=0;da<di;da++)for(db=0;db<10;db++);}/******************************************************************** **********/void Disp_img(uchar *img) //图形方式12864显示字模221 横向取膜{uchar i,j;uint k = 0;Write_char(0,0x34); //图形方式,关闭for(i=0;i<32;i++) //每行128位。
51单片机控制LCD12864液晶屏显示图形菜单
51单片机控制LCD12864液晶屏显示图形菜单想了很久,每次做菜单都受限于12864字符模式的各种限制,比如字体大小,不能显示图标等等,没有任何效果,这次就来个彻底的解脱,写一个单函数就能完成所有功能的函数,只需要2个图片就能完成任意菜单内容的菜单,可以有2的8次方=256个选择结果,应该能满足所有的要求了吧?菜单的内容就是图片的内容,因此可以显示任意大小的图形文字混合的菜单条目,比如使用字符模式,一屏只能显示4行菜单(64/16=4),且只能显示汉字和字符等,显示位置等等的都受限,而这个方法可以显示比如12*12(64/12=5行)的字符,8*8(64/8=8行)的字符,甚至不是字符,可以是图标+文字+任意其他的图像,只要是图片能显示的,都可以。
哈哈,比较复杂,现在只写了一少半,预期能够提供多种显示效果,希望我能完成。
void Lcd_Draw_BmpMenu(UINT8 *pMenu,UINT8*pTitleBmp,UINT8 *pMenuBmp){/*使用2张图片作为纯图形菜单来选择和操作,返回被选择的项,pMenu是一个指向菜单的各种参数的结构体的指针,pTitleBmp指向作为菜单标题的一张图片,pMenuBmp指向作为菜单内容的图片(液晶的控制芯片是ST7920)yx-->;>;|\|/*/xdata struct { //除非另有说明x坐标均为大列的坐标,一个大列是16个像素,一行共有8大列数据//========= 以下是入参基本参数,一旦确定,最好不要随意更改 ======UINT8 Title_x;//标题图片在屏幕上的显示起始位置X UINT8 Title_y;//标题图片在屏幕上的显示起始位置Y UINT8 Title_Len_x;//标题图片的宽UINT8 Title_Len_y;//标题图片的高UINT8 Menu_x;//菜单在屏幕上的显示起始位置XUINT8 Menu_y;//菜单在屏幕上的显示起始位置YUINT8 Menu_End_y;//菜单在屏幕上的显示结束位置Y UINT8 Menu_Bmp_x;//菜单图片的宽UINT8 Menu_Bmp_y;//菜单图片的高UINT8 Menu_Item_Height;//每一菜单项的高度(像素为单位)UINT8 Line_x;//最后下划线的起始坐标xUINT8 Line_y;//最后下划线的起始坐标YUINT8 Line_Len;//最后下划线的长度,如果为0,则表示不画出这条线(像素为单位)//====== 以下是菜单的风格设置 ========UINT8 Scroll_Speed;//菜单滚动的速度,0~9个级别,越低越快,越高越慢(液晶屏显示速度有快有慢,调整这个参数用于适用不同的液晶屏UINT8 Continue_Scroll;//指定菜单是否可以形成一个连续滚动选择的效果;0不连续,背景和反白位置都会根据实际情况滚动 1菜单连续滚动,反白位置不动UINT8 RePaint;//=0不重画菜单,=1重画整个菜单的图像,一般都是首次调用本函数的时候置1,用于画出整个菜单,以后调用置0就可以了UINT8 MenuEffect;//菜单运动的效果;0没有任何效果,只是最普通的菜单形态,1平滑滚动,2平滑滚动,具有惯性效果,3具有减速效果,没有惯性效果,4具有减速和惯性效果//====== 以下用于控制菜单的选择参数 =======UINT8 Last_Select_Item;//上次执行本函数后,所选择的菜单项UINT8 Select_Item;//本次执行本函数,要选择的菜单项}M;//============== 以下是变量定义 =============== UINT8 xdata Menu_Item_Count;//总共有几个菜单项UINT8 xdata Menu_Screen_Count;//当前一屏最多可以显示几个菜单项UINT8 xdataMenu_Box_x,Menu_Box_y,Menu_Box_End_x,Menu_Box_End _y;//需要刷新的区域的坐标UINT8 *pMenu_Box_Bmp;//需要显示的菜单项的指针StructCopy(&M.Title_x,pMenu,19);//把参数复制到本函数内,便于操作Menu_Item_Count=M.Menu_Bmp_y/M.Menu_Item_Height;/ /总共有几个菜单项Menu_Screen_Count=(M.Menu_End_y-M.Menu_y)/M.Menu_ Item_Height;//一屏最多可以显示多少项菜单//---------------------------------------------------------------------------if(M.RePaint==1)//如果需要重画整个菜单图像{Lcd_Draw_BMP(M.Title_x,M.Title_y,M.Title_x+M.Title_Len_x,M.Title_y+M.Title_Len_y,pTitleBmp);//画出标题的图片if(M.Line_Len!=0)Lcd_DrawRowLine(M.Line_x,M.Line_y,M.Line_Len,1);/ /画出最下面的线}//---------------------------------------------------------------------------//-----------需要刷新的图像的区域Menu_Box_x=M.Menu_x;Menu_Box_y=M.Menu_y;Menu_Box_End_x=M.Menu_x+M.Menu_Bmp_x;Menu_Box_End_y=M.Menu_End_y;。
超声波测距51单片机12864液晶显示
超声波测距51单片机12864液晶显示超声波测距的模块,51单片机接上12864液晶,HC-SR04超声波模块,就可以了。
超声波测距51单片机12864液晶显示源程序:#include <reg52.h>#include<intrins.h>//引脚定义sbit RX = P1 ^ 1;sbit TX = P1 ^ 2;sbit CS = P3 ^ 3; //片选高电平有效单片LCD使用时可固定高电平sbit SID = P3 ^ 4; //数据sbit SCLK = P3 ^ 5; //时钟//Function Definition 函数声明void Delay(int num);void Init_DS18B20(void);unsigned char ReadOneChar(void);void WriteOneChar(unsigned char dat);unsigned int ReadTemperature(void);void clock_out(unsigned char dd);unsigned char clock_in(void);unsigned char read_clock(unsigned char ord);void write_clock(unsigned char ord, unsigned char dd); void Disp(void);void id_case1_key(void);void id_case2_key(void);void Set_time(unsigned char sel,bit sel_1);void Timer0_Init(void);void Init_1302(void);void Set_Bell(unsigned char sel, bit sel_1);void Bell(void);//12864void Write_char(bit start, unsigned char ddata);void Send_byte(unsigned char bbyte);void Delaynms(unsigned int di);void Lcd_init(void);void Disp_img(unsigned char *img);void LCD_Write_string(unsigned char X,unsigned char Y,unsigned char *s);void LCD_set_xy( unsigned char x, unsigned char y );unsigned char code num[]={"0123456789 :.-"};unsigned char code waves[]={"超声波测距系统"};unsigned char code znwk[] ={"智能微控工作室"};unsigned char code CM[] = {"M"};unsigned int time=0;long S=0;bit flag =0;unsigned char disbuff[4] ={ 0,0,0,0,};unsigned char code logo[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0xE0,0x00,0x00,0x0C,0x00,0x00,0x40,0x70,0x00,0x00,0x00,0x80,0x00, 0x00,0x00,0x00,0xE0,0x00,0x00,0x1E,0x00,0x00,0x60,0x70,0x00,0x00,0x0F,0xE0,0x00, 0x00,0x00,0x01,0xC0,0x00,0x60,0x3C,0x00,0x00,0xE0,0x60,0x00,0x1F,0xFF,0xE0,0x00, 0x00,0x00,0x03,0x80,0x00,0x70,0x70,0x40,0x00,0xE0,0x7E,0x00,0x1F,0xE0,0xC0,0x00,0x00,0x00,0x03,0x00,0x00,0x73,0xC3,0xF0,0x01,0xC3,0xFC,0x00,0x38,0xE1,0xC0,0x00, 0x00,0x03,0xC6,0x3C,0x00,0x33,0x9F,0xF0,0x03,0x8F,0xC0,0x00,0x30,0xC1,0xC0,0x00, 0x00,0x3F,0xEF,0xFE,0x00,0x03,0x1C,0xE0,0x07,0x01,0xCC,0x00,0x31,0xF1,0x80,0x00, 0x00,0x79,0xDF,0xBC,0x00,0x06,0x18,0xC0,0x0E,0x01,0xFE,0x00,0x77,0xF9,0x80,0x00, 0x00,0x01,0xB0,0x30,0x01,0xC6,0x19,0xC0,0x1E,0x7F,0xDE,0x00,0x6F,0x83,0x80,0x00, 0x00,0x23,0xAC,0x60,0x0F,0xE6,0xF1,0x80,0x3E,0x7B,0x38,0x00,0x61,0x83,0x00,0x00, 0x00,0x37,0x0E,0x00,0x0F,0xC7,0xB7,0x80,0xEC,0x63,0x30,0x00,0xE3,0x03,0x00,0x00, 0x00,0x3E,0x0E,0x00,0x01,0x8F,0x37,0x01,0xCC,0x6F,0xF0,0x00,0xC7,0xF7,0x00,0x00, 0x00,0x1E,0x0C,0x00,0x03,0x1E,0x66,0x03,0x0C,0x7F,0x00,0x01,0xFF,0xE6,0x00,0x00, 0x00,0x1E,0x1C,0x00,0x03,0x1C,0x60,0x02,0x19,0xAC,0x00,0x01,0x96,0x06,0x00,0x00, 0x00,0x3E,0x3E,0x00,0x03,0x18,0x60,0x00,0x19,0xFC,0x00,0x03,0x86,0x0E,0x00,0x00, 0x00,0x7E,0x36,0x00,0x03,0x00,0xC0,0x00,0x38,0x78,0x00,0x03,0x06,0x0C,0x00,0x00, 0x00,0xE6,0x67,0x00,0x03,0x00,0xC0,0x00,0x30,0x78,0x00,0x06,0x0C,0x0C,0x00,0x00, 0x01,0xC6,0xC3,0x80,0x7F,0xF0,0xC0,0x00,0x30,0xFE,0x00,0x0E,0x0C,0x1C,0x00,0x00, 0x03,0x81,0x83,0xC0,0x78,0xFF,0x80,0x00,0x61,0xCF,0x80,0x1C,0x08,0x18,0x00,0x00, 0x06,0x07,0x03,0xE0,0x00,0x1F,0xFF,0xE0,0x67,0x07,0xE0,0x38,0x18,0xF8,0x00,0x00, 0x08,0x0E,0x01,0xF8,0x00,0x07,0xFF,0x80,0xCE,0x03,0xF8,0x60,0x00,0x70,0x00,0x00, 0x00,0x18,0x01,0xF8,0x00,0x01,0xFC,0x00,0xC0,0x01,0xFC,0xC0,0x00,0x70,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x06,0x00,0x00,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x07,0x00,0x00,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x06,0x00,0x00,0x00,0x0C,0xE0,0x00,0x01,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x00,0x00,0x00,0x3F,0xE0,0x00,0xFF,0xF0,0x00,0x38,0x00,0xE0,0x00, 0x00,0x00,0x0C,0x00,0x00,0x0F,0xFF,0x80,0x00,0xF8,0xF0,0x00,0x38,0x00,0xE0,0x00, 0x00,0x00,0x0C,0xF0,0x00,0x0F,0xC7,0x00,0x00,0x60,0xE0,0x00,0x38,0x00,0xE0,0x00, 0x00,0x00,0x1F,0xF0,0x00,0x01,0x8E,0x00,0x00,0x60,0xC0,0x00,0x70,0x01,0xC0,0x00, 0x00,0x07,0xFF,0x80,0x00,0x01,0x8C,0x00,0x00,0xE1,0x80,0x00,0x70,0x01,0xC0,0x00, 0x00,0x07,0xF8,0x00,0x00,0x01,0x98,0x00,0x00,0xDF,0xC0,0x00,0x70,0x01,0xC0,0x00, 0x00,0x00,0x78,0x00,0x00,0x01,0xBF,0xE0,0x00,0xFF,0x00,0x00,0x60,0x01,0x80,0x00, 0x00,0x00,0xFC,0x00,0x00,0x7F,0xFF,0xE0,0x00,0xC0,0x00,0x00,0xE0,0x03,0x80,0x00, 0x00,0x01,0xFE,0x00,0x00,0x7F,0xF8,0x00,0x00,0x00,0x00,0x00,0xC0,0x03,0x00,0x00, 0x00,0x03,0xB7,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x3C,0x00,0xC0,0x03,0x00,0x00, 0x00,0x07,0x67,0x00,0x00,0x60,0x00,0x00,0x03,0x9F,0xFE,0x00,0x80,0x02,0x00,0x00, 0x00,0x0E,0x63,0x80,0x00,0xE0,0x00,0x01,0xFF,0xCF,0x1E,0x01,0x80,0x06,0x00,0x00, 0x00,0x1C,0xE1,0xE0,0x00,0xC0,0x00,0x00,0xE3,0x9C,0x38,0x01,0x80,0x06,0x00,0x00, 0x00,0x38,0xC1,0xF8,0x01,0xC0,0x00,0x00,0xC3,0x18,0x30,0x00,0x00,0x00,0x00,0x00, 0x00,0xE0,0xFC,0xFE,0x03,0x80,0x00,0x01,0xC7,0x18,0x60,0x00,0x00,0x00,0x00,0x00, 0x01,0xDF,0xF8,0xFE,0x03,0x00,0x00,0x01,0x8E,0x1B,0xE0,0x07,0x00,0x1C,0x00,0x00, 0x07,0x07,0x80,0x00,0x07,0x00,0x00,0x01,0xFF,0x3F,0xE0,0x07,0x00,0x1C,0x00,0x00, 0x0C,0x03,0x80,0x00,0x0E,0x00,0x00,0x01,0xF0,0x38,0x00,0x0F,0x00,0x3C,0x00,0x00, 0x00,0x03,0x00,0x00,0x1C,0x00,0x00,0x01,0x00,0x20,0x00,0x06,0x00,0x18,0x00,0x00, 0x00,0x03,0x00,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x03,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x02,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, };void Lcd_init(void) //初始化LCD{Delaynms(10); //启动等待,等LCM讲入工作状态CS=1;Write_char(0,0x30); //8 位介面,基本指令集Write_char(0,0x0c); //显示打开,光标关,反白关Write_char(0,0x01); //清屏,将DDRAM的地址计数器归零}void Write_char(bit start, unsigned char ddata) //写指令或数据{unsigned char start_data,Hdata,Ldata;if(start==0)start_data=0xf8; //写指令elsestart_data=0xfa; //写数据Hdata=ddata&0xf0; //取高四位Ldata=(ddata<<4)&0xf0; //取低四位Send_byte(start_data); //发送起始信号Delaynms(5); //延时是必须的Send_byte(Hdata); //发送高四位Delaynms(1); //延时是必须的Send_byte(Ldata); //发送低四位Delaynms(1); //延时是必须的}void Send_byte(unsigned char bbyte) //发送一个字节{unsigned char i;for(i=0;i<8;i++){SID=bbyte&0x80; //取出最高位SCLK=1;SCLK=0;bbyte<<=1; //左移}}void Delaynms(unsigned int di) //延时{unsigned int da,db;for(da=0;dafor(db=0;db<10;db++);}void Disp_img(unsigned char *img) //图形方式12864显示字模221 横向取膜{unsigned char i,j;unsigned int k = 0;Write_char(0,0x36); //图形方式for(i=0;i<32;i++){Write_char(0,0x80+i);Write_char(0,0x80);for(j=0;j<16;j++){Write_char(1,img[k++]);}}for(i=0;i<32;i++){Write_char(0,0x80+i);Write_char(0,0x88);for(j=0;j<16;j++){Write_char(1,img[k++]);}}}void Clr_Scr(void)//清屏函数{Write_char(0,0x01);}void LCD_set_xy( unsigned char x, unsigned char y ) { //设置LCD显示的起始位置,X为行,Y为列unsigned char address;switch(x){case 0: address = 0x80 + y; break;case 1: address = 0x80 + y; break;case 2: address = 0x90 + y; break;case 3: address = 0x88 + y; break;case 4: address = 0x98 + y; break;default:address = 0x80 + y; break;}Write_char(0, address);}void LCD_Write_string(unsigned char X,unsigned char Y,unsigned char *s) { // 中英文字符串显示函数LCD_set_xy( X, Y );while (*s){Write_char( 1, *s );s ++;Delaynms(1);}}void LCD_Write_number(unsigned char s)// 数字显示函数{Write_char(1,num[s]);Delaynms(1);}void Lcd_Mark2(void){Clr_Scr();//清屏LCD_Write_string(1,0,znwk);//LCD_Write_string(2,0,waves);//LCD_Write_string(3,7,CM);//}void Conut(void){time=TH0*256+TL0;TH0=0;TL0=0;S=time*1.87/100; //算出来是CM 11。
12864串口C51程序
}
//串行发送一字节数据
void SendByte(unsigned ch
for(i=0;i <8;i++)
sbit RW_SID=P3^1;//data input/output 串行数据输入、输出端
//sbit RS_CS =P3^5;//chip select 片选端
// SendCMD(0x0F);//显示设定,开显示,显示光标,当前显示位反白闪动
}
void main(void)
{
initlcm();
SendCMD(0x81);//1000,0001 设定DDRAM 7位地址000,0001到地址计数器AC
delay(100);
display(0x90,0xb0,0xb2);//安
display(0x91,0xbb,0xD5);//徽
display(0x92,0xb5,0xe7);//电
display(0x93,0xc1,0xA6);//力
display(0x94,0xc5,0xe0);//培
display(0x95,0xD1,0xb5);//训
display(0x8B,0xc1,0xA6);//力
display(0x8C,0xc5,0xe0);//培
display(0x8D,0xD1,0xb5);//训
//sbit PSB =P3^6;//serial mode select 串口模式
sbit RST =P1^2;
void delay(unsigned int n)
{
unsigned int i;
用51单片机做的万年历,显示用12864液晶
LCD12864.c#include "reg52.h"#include "intrins.h"#define uchar unsigned char#define uint unsigned int#define LCD_DB_PORT P0 //液晶DB0~DB7 #define LCD_START_ROW 0xc0 //起始行#define LCD_PAGE 0xb8 //页指令#define LCD_COL 0x40 //列指令//液晶引脚定义sbit LCD_DI=P2^0;sbit LCD_RW=P2^1;sbit LCD_E=P2^2;sbit LCD_CS1=P2^3;sbit LCD_CS2=P2^4;sbit LCD_RST=P2^5;bit Reverse_Display=0;//检查LCD是否忙bit LCD_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发送命令void LCD_Write_Command(uchar c){ while(LCD_Check_Busy());LCD_DB_PORT=0xff; LCD_RW=0; _nop_(); LCD_DI=0;LCD_DB_PORT=c; LCD_E=1; _nop_(); LCD_E=0;}//向LCD发送数据void LCD_Write_Data(uchar d){ while(LCD_Check_Busy());LCD_DB_PORT=0xff;LCD_RW=0;_nop_();LCD_DI=1;//根据Reverse_Display决定是否反相显示if(!Reverse_Display)LCD_DB_PORT=d;else LCD_DB_PORT=~d;LCD_E=1;_nop_();LCD_E=0;}//初始化LCDvoid LCD_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的右半屏构成void Common_Show(uchar P,uchar L,uchar W,uchar *r){ uchar i;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;i<W;i++)LCD_Write_Data(r[i]);}else //如果越界则跨左右半屏显示{ for(i=0;i<64-L;i++)LCD_Write_Data(r[i]); //左半屏显示LCD_CS1=0;LCD_CS2=1; //右半屏显示LCD_Write_Command(LCD_PAGE+P);LCD_Write_Command(LCD_COL);for(i=64;i<W;i++)LCD_Write_Data(r[i]);}}else //全部显示在右半屏{ LCD_CS1=0;LCD_CS2=1;LCD_Write_Command(LCD_PAGE+P);LCD_Write_Command(LCD_COL+L-61);for(i=0;i<W;i++)LCD_Write_Data(r[i]);}}//显示8*16点阵字符void Display_A_Char_8X16(uchar P,uchar L,uchar *M) { Common_Show(P,L,8,M);Common_Show(P+1,L,8,M+8);}//显示一个16*16点阵汉字void Display_A_WORD(uchar P,uchar L,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 "string.h"#include "LCD_12864.c"#define uchar unsigned char#define uint unsigned int/*extern void LCD_Initialize(void);extern void Display_A_Char_8X16(uchar P,uchar L,uchar *M); extern void Display_A_WORD(uchar P,uchar L,uchar *M);//在调整日期时间时,用该位决定是否反白显示extern bit Reverse_Display=0;*/sbit SDA=P1^0; //DS1302数据线sbit CLK=P1^1; //DS1302时钟线sbit RST=P1^2; //DS1302复位线sbit k1=P3^4; //选择sbit k2=P3^5; //加sbit k3=P3^6; //减sbit k4=P3^7; //确定uchar tCount=0;//一年中每个月的天数,2月的天数由年份决定uchar MonthsDays[]={0,31,0,31,30,31,30,31,31,30,31,30,31};//所读取的日期时间uchar DateTime[7];//当前调整的时间对象:秒,分,时,日,月,年(0,1,2,3,4,6)//5对应星期,星期调节由年月日调整自动完成char Adjust_Index=-1;//水平与垂直偏移uchar H_Offset=10,V_Page_Offset=0;//年月日,星期,时分秒汉字点阵(16*16)------------------------------- uchar code DATE_TIME_WORDS[]={/*-- 文字: 年--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x20,0x18,0xC7,0x44,0x44,0x44,0x44,0xFC,0x44,0x44,0x44,0x44,0x 04,0x00,0x00,0x04,0x04,0x04,0x07,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x 04,0x04,0x00,/*-- 文字: 月--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0x00,0xFE,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0xFE,0x 00,0x00,0x00,0x80,0x40,0x30,0x0F,0x02,0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x/*-- 文字: 日--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0x00,0xFE,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0xFE,0x00,0x 00,0x00,0x00,0x00,0x00,0x00,0xFF,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0xFF,0x00,0x 00,0x00,0x00,/*-- 文字: 星--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0x00,0xBE,0x2A,0x2A,0x2A,0xEA,0x2A,0x2A,0x2A,0x3E,0x00, 0x00,0x00,0x00,0x00,0x44,0x42,0x49,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x49,0x41,0x 40,0x00,0x00,/*-- 文字: 期--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x04,0xFF,0x24,0x24,0x24,0xFF,0x04,0x00,0xFE,0x22,0x22,0x22,0xF E,0x00,0x00,0x88,0x48,0x2F,0x09,0x09,0x19,0xAF,0x48,0x30,0x0F,0x02,0x42,0x82,0x 7F,0x00,0x00,/*-- 文字: 时--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0xFC,0x84,0x84,0x84,0xFC,0x00,0x10,0x10,0x10,0x10,0x10,0xFF,0x0x00,0x3F,0x10,0x10,0x10,0x3F,0x00,0x00,0x01,0x06,0x40,0x80,0x7F,0x0 0,0x00,0x00,/*-- 文字: 分--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x80,0x40,0x20,0x90,0x88,0x86,0x80,0x80,0x80,0x83,0x8C,0x10,0x20,0x 40,0x80,0x00,0x00,0x80,0x40,0x20,0x18,0x07,0x00,0x40,0x80,0x40,0x3F,0x00,0x00,0x 00,0x00,0x00,/*-- 文字: 秒--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x24,0x24,0xA4,0xFE,0x23,0x22,0x00,0xC0,0x38,0x00,0xFF,0x00,0x08,0x 10,0x60,0x00,0x08,0x06,0x01,0xFF,0x01,0x06,0x81,0x80,0x40,0x40,0x27,0x10,0x0C,0x 03,0x00,0x00,};//星期几的汉字点阵(16*16)----------------------------------uchar code WEEDDAY_WORDS[]={/*-- 文字: 日--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0x00,0xFE,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0xFE,0x00,0x 00,0x00,0x00,0x00,0x00,0x00,0xFF,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0xFF,0x00,0x 00,0x00,0x00,/*-- 文字: 一--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x 80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x 00,0x00,0x00,/*-- 文字: 二--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x 00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x 10,0x10,0x00,/*-- 文字: 三--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x04,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x 04,0x00,0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x 20,0x20,0x00,/*-- 文字: 四--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0xFC,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0x FC,0x00,0x00,0x00,0x7F,0x28,0x24,0x23,0x20,0x20,0x20,0x20,0x21,0x22,0x22,0x22,0x 7F,0x00,0x00,/*-- 文字: 五--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x02,0x42,0x42,0x42,0xC2,0x7E,0x42,0x42,0x42,0x42,0xC2,0x02,0x 02,0x00,0x00,0x40,0x40,0x40,0x40,0x78,0x47,0x40,0x40,0x40,0x40,0x40,0x7F,0x40,0x 40,0x40,0x00,/*-- 文字: 六--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x20,0x20,0x20,0x20,0x20,0x20,0x21,0x22,0x2C,0x20,0x20,0x20,0x20,0x 20,0x20,0x00,0x00,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x00,0x01,0x02,0x04,0x18,0x 60,0x00,0x00,};//半角数字点阵(8*16)---------------------------------------------------- uchar code DIGITS[]={/*-- 文字: 0 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,/*-- 文字: 1 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x 20,0x00,0x00,/*-- 文字: 2 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x 21,0x30,0x00,/*-- 文字: 3 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x 11,0x0E,0x00,/*-- 文字: 4 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x 3F,0x24,0x00,/*-- 文字: 5 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x 11,0x0E,0x00,/*-- 文字: 6 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x 11,0x0E,0x00,/*-- 文字: 7 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x 00,0x00,0x00,/*-- 文字: 8 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x 22,0x1C,0x00,/*-- 文字: 9 --*//*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x 11,0x0F,0x00,};//向DS1302写入一字节void Write_A_Byte_TO_DS1302(uchar x){ uchar i;for(i=0;i<8;i++){ SDA=x&1; CLK=1; CLK=0; x>>=1;}}//从DS1302读取一字节uchar Get_A_Byte_FROM_DS1302(void) { uchar i,b,t;for(i=0;i<8;i++){ b>>=1; t=SDA; b|=t<<7; CLK=1; CLK=0;}//BCD码转换return(b/16*10+b%16);}//从DS1302指定位置读数据uchar Read_Data(uchar addr){ uchar dat;RST=0; CLK=0; RST=1;Write_A_Byte_TO_DS1302(addr);dat=Get_A_Byte_FROM_DS1302();CLK=1; RST=0;return(dat);}//向DS1302某地址写入数据void Write_DS1302(uchar addr,uchar dat){ CLK=0; RST=1;Write_A_Byte_TO_DS1302(addr);Write_A_Byte_TO_DS1302(dat);CLK=0; RST=0;}//设置时间void SET_DS1302(void){ uchar i;Write_DS1302(0x8e,0x00);//秒分时日月年依次写入for(i=0;i<7;i++){ //秒的起始地址1000 0000(0x80)//后续依次是分,时,月,周,年,写入地址每次递增2Write_DS1302(0x80+2*i,(DateTime[i]/10<<4)|(DateTime[i]%10));}Write_DS1302(0x8e,0x80);}//读取当前日期时间void GetTime(void){ uchar i;for(i=0;i<7;i++){ DateTime[i]=Read_Data(0x81+2*i);}}//半断是否为闰年uchar isLeapYear(uint y){ return((y%4==0&&y%100!=0)||(y%400==0)); }//--------------------------------------------//求自2000.1.1开始的任何一天是星期几//函数没有通过,求出总天数后在求出星期几//因为求总天数可能会月出uint的范围//--------------------------------------------void RefreshWeekDay(void){ uint i,d,w=5; //已知1999.12.31是周五for(i=2000;i<2000+DateTime[6];i++){ d=isLeapYear(i)?366:365;w=(w+d)%7;}d=0;for(i=1;i<DateTime[4];i++)d+=MonthsDays[i];d+=DateTime[3];//保存星期,0~6表示星期日,星期一,二,、、、六,为了与DS1302的星期格式匹配,返回值需要加1DateTime[5]=(w+d)%7+1;}//年月日时分秒++/--void DateTime_Adjust(char x){ switch(Adjust_Index){ case 6: //年00-99if(x==1&&DateTime[6]<99)DateTime[6]++;if(x==-1&&DateTime[6]>0)DateTime[6]--;//获取2月天数MonthsDays[2]=isLeapYear(2000+DateTime[6])?29:28;//如果年份变化后当前月份的天数大于上限则设为上限if(DateTime[3]>MonthsDays[DateTime[4]])DateTime[3]=MonthsDays [DateTime[4]];RefreshWeekDay(); //刷新星期break;case 4: //月01-12if(x==1&&DateTime[4]<12)DateTime[4]++;if(x==-1&&DateTime[4]>1)DateTime[4]--;//获取2月份天数MonthsDays[2]=isLeapYear(2000+DateTime[6])?29:28;//如果月份变化后当前月份的天数大于上限则设为上限if(DateTime[3]>MonthsDays[DateTime[4]])DateTime[3]=MonthsDays [DateTime[4]];RefreshWeekDay(); //刷新星期break;case 3: //日00-28/29/30/31;调节之前首先根据年份得出该年中2月的天数MonthsDays[2]=isLeapYear(2000+DateTime[6])?29:28;//根据当前月份决定调节日期的上限if(x==1&&DateTime[3]<MonthsDays[DateTime[4]])DateTime[3]++;if(x==-1&&DateTime[3]>1)DateTime[3]--;RefreshWeekDay(); //刷新星期break;case 2: //时if(x==1&&DateTime[2]<23)DateTime[2]++;if(x==-1&&DateTime[3]>1)DateTime[2]--;break;case 1: //分if(x==1&&DateTime[1]<59)DateTime[1]++;if(x==-1&&DateTime[1]>1)DateTime[1]--;break;case 0: //秒if(x==1&&DateTime[0]<59)DateTime[0]++;if(x==-1&&DateTime[0]>1)DateTime[0]--;}}//定时器0每秒刷新LCD显示void T0_INT(void) interrupt 1{ TH0=-50000/256;TL0=-50000%256;if(++tCount!=2)return;tCount=0;if(Adjust_Index==-1)GetTime(); //如果未执行调整操作则正常读取当前时间//年后两位Reverse_Display=Adjust_Index==6; /*等同于{ if(Adjust_Index==6)Reverse_Display=1;else Reverse_Display=0; } */Display_A_Char_8X16(V_Page_Offset,16+H_Offset,DIGITS+DateTime [6]/10*16);Display_A_Char_8X16(V_Page_Offset,24+H_Offset,DIGITS+DateTime [6]%10*16);//月Reverse_Display=Adjust_Index==4;Display_A_Char_8X16(V_Page_Offset,48+H_Offset,DIGITS+DateTime [4]/10*16);Display_A_Char_8X16(V_Page_Offset,56+H_Offset,DIGITS+DateTime [4]%10*16);//日Reverse_Display=Adjust_Index==3;Display_A_Char_8X16(V_Page_Offset,80+H_Offset,DIGITS+DateTime [3]/10*16);Display_A_Char_8X16(V_Page_Offset,88+H_Offset,DIGITS+DateTime [3]%10*16);//星期Reverse_Display=Adjust_Index==5;Display_A_WORD(V_Page_Offset+2,96+H_Offset,WEEDDAY_WORDS +(DateTime[5]-1)*32);//时Reverse_Display=Adjust_Index==2;Display_A_Char_8X16(V_Page_Offset+5,16+H_Offset,DIGITS+DateTi me[2]/10*16);Display_A_Char_8X16(V_Page_Offset+5,24+H_Offset,DIGITS+DateTi me[2]%10*16);//分Reverse_Display=Adjust_Index==1;Display_A_Char_8X16(V_Page_Offset+5,48+H_Offset,DIGITS+DateTi me[1]/10*16);Display_A_Char_8X16(V_Page_Offset+5,56+H_Offset,DIGITS+DateTi me[1]%10*16);//秒Reverse_Display=Adjust_Index==0;Display_A_Char_8X16(V_Page_Offset+5,80+H_Offset,DIGITS+DateTi me[0]/10*16);Display_A_Char_8X16(V_Page_Offset+5,88+H_Offset,DIGITS+DateTi me[0]%10*16);}//键盘中断(INT0)void EX_INT0(void) interrupt 0{ if(k1==0) //选择调整对象{ if(Adjust_Index==-1||Adjust_Index==0)Adjust_Index=7;Adjust_Index--;if(Adjust_Index==5)Adjust_Index=4; //跳过对星期的调整}else if(k2==0)DateTime_Adjust(1); //加else if(k3==0)DateTime_Adjust(-1); //减else if(k4==0) //确定{ SET_DS1302(); //将调整后的时间写入DS1302Adjust_Index=-1; //操作索引重设为-1,时间继续正常显示}}//主程序void main(){ //液晶初始化LCD_Initialize();//显示年的固定前两位Display_A_Char_8X16(V_Page_Offset,0+H_Offset,DIGITS+2*16);Display_A_Char_8X16(V_Page_Offset,8+H_Offset,DIGITS);//显示固定汉字:年月日,星期,时分秒Display_A_WORD(V_Page_Offset,32+H_Offset,DATE_TIME_WORDS+ 0*32);Display_A_WORD(V_Page_Offset,64+H_Offset,DATE_TIME_WORDS+ 1*32);Display_A_WORD(V_Page_Offset,96+H_Offset,DATE_TIME_WORDS+ 2*32);Display_A_WORD(V_Page_Offset+2,64+H_Offset,DATE_TIME_WORD S+3*32);Display_A_WORD(V_Page_Offset+2,80+H_Offset,DATE_TIME_WORD S+4*32);Display_A_WORD(V_Page_Offset+5,32+H_Offset,DATE_TIME_WORD S+5*32);Display_A_WORD(V_Page_Offset+5,64+H_Offset,DATE_TIME_WORD S+6*32);Display_A_WORD(V_Page_Offset+5,96+H_Offset,DATE_TIME_WORD S+7*32);//允许INT0,T0中断IE=0x83;IP=0x01;IT0=0x01;TH0=-50000/256;TL0=-50000%256;TR0=1;while(1);}。
51单片机12864LCD显示
C SR=1:AC5—AC0为垂直卷动地址
72us
址
5 4 32
1 SR=0:AC3—AC0为ICON IRAM地址
设定绘图 RAM地址
A A A AA A A 0 0 1 C C C C C C C 设定CGRAM地址到地址计数器(AC)
6 5 4 32 1 0
72us
VCC 0 V Vss Vdd 4 6 8 2 1 T SS DB0DB1DB2DB3DB4DB5DB6DB7BR/WER 01234567 BBBBBBBBSW DDDDDDDDRRE 0.1pF D K N 0 G 1 01234567 BBBBBBBB DDDDDDDD 12345678234567890 1234567822222222333333334 VCC P1.0/T2 P2.0/A8P2.1/A9 P1.2/ECI P2.2/A10P2.3/A11P2.4/A12P2.5/A13P2.6/A14P2.7/A15 P0.7/AD7P0.6/AD6P0.5/AD5P0.4/AD4P0.3/AD3P0.2/AD2P0.1/AD1P0.0/AD0 P1.1/T2EXP1.3/CEX0P1.4/CEX1P1.5/CEX2P1.6/CEX3P1.7/CEX4 1 5 0 8 RSTP3.0/RxDP3.1/TxDP3.2/INT0P3.3/INT1P3.4/T0P3.5/T1P3.6/WRP3.7/RDXTAL2XTAL1VSSPSENALE/PROGEA/VPP 01234567890901 9 11111111112233 SW RRE
CL
72us
功能设定
0
0
0
0
1
D L
X
R E
X
X
12864串行驱动
/*-------------------------------------------------------------------------------------
* 功能:
向 LCD12864 写入 1Byte 数据
--------------------------------------------------------------------------------------*/
由于串行操作12864无法读取内部ram所以画图操作在单片机内部开辟1664字节ram充当缓存经测试整屏刷新速度大于5接线方法
STM32 单片机 12864 串行驱动
说明:测试单片机型号 STM32F103C8T6,由于单片机 IO 资源不充分, 故采用串行驱动 12864。由于串行操作 12864 无法读取内部 RAM,所 以画图操作在单片机内部开辟 16*64 字节 RAM 充当缓存,经测试整 屏刷新速度大于 5 次/s。 接线方法: PSB 接地
* 说明:
LCD12864 PSB(15 脚)需接低电平,RS(4 脚)需接高电平
* 文件调用: 需调用 Delay_us()、Delay_ms()
--------------------------------------------------------------------------------------*/
extern unsigned char PicBuff[16*64];
void LCD12864_ClearPicBuff(unsigned char *Buff); void LCD12864_DisPlayFont(sFont *font, unsigned char x, unsigned char y, unsigned char len, unsigned char *pData); void LCD12864_DisPlayPic(unsigned char *Buff,PicStruct *Pic,unsigned char x,unsigned char y); void LCD12864_DrawCircle(unsigned char *Buff,unsigned char x0,unsigned char y0,unsigned char r); void LCD12864_DrawPoint(unsigned char *Buff, unsigned char x, unsigned char y, unsigned char color); void LCD12864_Line_X(unsigned char *Buff,unsigned char X0,unsigned char X1,unsigned char
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
sbit CH = P2^4; //并行、串行选择信号PSB
/**************************************
* 名称 : delay()
* 功能 : 延时,延时时间为 100us * t。这是通过软件延时,有一定误差。
write_com(0x81);
hzkdis("51单片机");
write_com(0x91);
hzkdis("湖南科技大学");
write_com(0x89);
hzkdis(" ");
write_com(0x98);
hzkdis("信息与电气工程");
* 名称 : write_com()
* 功能 : 写串口指令
* 输入 : cmdcode
* 输出 : 无
***********************************************************************/
void write_com(unsigned char cmdcode)
* 名称 : hzkdis()
* 功能 : 显示字符串
* 输入 : *s
* 输出 : 无
***********************************************************************/
void hzkdis(unsigned char code *s)
* 输入 : t
* 输出 : 无
***********************************************************************/
void delay(unsigned int t)
{
unsigned int i,j;
for(i=0; i<t; i++)
* 输出 : 无
***********************************************************************/
void sendbyte(unsigned char zdata)
{
unsigned int i;
for(i=0; i<8; i++)
{
if((zdata << i) & 0x80)
{
SID = 1;
}
else
{
SID = 0;
}
SCLK = 0;
SCLK = 1;
}
}
/********************************************************************
}
/********************************************************************
* 名称 : Main()
* 功能 : 主函数
* 输入 : 无
* 输出 : 无
***********************************************************************/
* 功能 : 显示子函数
* 输入 : 无
* 输出 : 无
***********************************************************************/
void Test()
{
write_com(0x03);
delay(50);
* 名称 : write_data()
* 功能 : 写串口指令
* 输入 : cmdcode
* 输出 : 无
***********************************************************************/
void write_data(unsigned char Dispdata)
// delay(100);
// RST = 1;
// delay(20000);
write_com(0x30);
delay(50);
write_com(0x0c);
delay(50);
}
/********************************************************************
{
CS = 1;
sendbyte(0xfa);
sendbyte(Dispdata & 0xf0);
sendbyte((Dispdata << 4) & 0xf0);
delay(2);
}
/********************************************************************
void Main()
{
CH = 0;
delay(1);
lcdinit();
delay(10);
while(1)
{
Test();
delay(5000);
}
}
{
while(*s > 0)
{
write_data(*s);
s++;
delay(50);
}
}
/********************************************************************
* 名称 : Test()
* 名称 : lcdinit()
* 功能 : 初始化函数
* 输入 : cmdcode
* 输出 : 无
***********************************************************************/
void lcdinit()
{
// RST = 0;
for(j=0; j<10; j++);
}
/********************************************************************
* 名称 : sendbyte()
* 功能 : 按照液晶的串口通信协议,发送数据
* 输入 : zdata
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit CS=P2^5; //片选信号rs/cs
sbit SID=P2^6; //数据信号r/w
{
CS = 1;
sendbyte(0xf8);
sendbyte(cmdcode & 0xf0);
sendbyte((cmdcode << 4) & 0xf0);
delay(2);
}
/********************************************************************