stm8汇编12864模块程序

合集下载

STM8 Nucleo-64开发板使用说明书

STM8 Nucleo-64开发板使用说明书

AN5183使用STM8 Nucleo-64板调节LED闪烁速度引言NUCLEO-8S208RB(基于STM8S208RBT6)和NUCLEO-8L152R8(基于STM8L152R8T6)板可用于评估所有STM8S系列和STM8L系列微控制器的主要特性。

本应用笔记将简要描述STM8S208RBT6和STM8L152R8T6微控制器的Flash存储器中出厂预编程的演示固件Discover。

此演示固件使用STM8S和STM8L系列内部的基本定时器产生时钟基准,在每次用户按钮被按下时改变LED LD1的闪烁速度。

一旦STM8 Nucleo-64板使用USB线连接到PC机上电,LED LD1开始缓慢闪烁,表示出厂程序已经正常工作。

表 1. 适用产品参考文档•STM8 Nucleo-64板数据摘要(DB3591)•STM8L152R8T6 Nucleo-64板用户手册(UM2351)•STM8S208RBT6 Nucleo-64板用户手册(UM2364)1应用描述1.1硬件要求使用了以下STM8 Nucleo-64板载资源:•LED,LD1•用户按钮B1无需额外硬件即可在STM8 Nucleo-64板上运行此应用软件。

1.2应用原理图有关实现详情,请参阅以下文档:•STM8L152R8T6 Nucleo-64板用户手册(UM2351)•STM8S208RBT6 Nucleo-64板用户手册(UM2364)1.3程序原理此程序使用8-BIT基本定时器TIM4作为时钟基准,控制LED LD1闪烁速度。

STM8S系列或STM8L系列微控制器每次在用户按钮B1上检测到事件时,将调整LED每次翻转的时间延时(TIM4时基的倍数)以相应地改变闪烁频率。

程序启动时,闪烁周期配置为1秒并且LD1以此频率翻转(每秒翻转一次)。

这样配置用户可以直接看到STM8S系列或STM8L系列器件的Flash内部的出厂程序是否正常。

每当在用户按钮B1上检测到按钮事件时,根据下表所述设置加快LD1闪烁频率。

12864液晶经典驱动程序,一看就懂,有详细的注释(C语言编写,不看后悔)

12864液晶经典驱动程序,一看就懂,有详细的注释(C语言编写,不看后悔)

这个程序写得很好,自己也是看的别人写的很好的程序,但是它代码不够完整,注释不详细,经过自己的修改加以完善。

另外我发现很多的测试代码都没有附上测试代码效果图,在本人的代码下面有自己拍的效果图,填补不足之处。

自己在找资料的过程中花掉很多的财富值,如果大家看得起该代码请评五分加以下载,在下感激不尽!/*******************************************程序名称:12864液晶经典驱动程序(带中文字库)功能:12864测试程序修改作者:王程修改时间:2014年2月5日23:22:32********************************************/#include<reg52.h>#define uchar unsigned char#define uint unsigned int// P0 为数据口sbit LCD_RS=P2^0; //数据、命令选择端口sbit LCD_RW=P2^1; //液晶读写控制sbit LCD_EN=P2^2; //液晶使能控制sbit PSB = P2^4; //模式选择1为并行0为串行sbit RES = P2^5;//复位端口低电平复位,上电之前进行复位,为了稳定!unsigned char code DAT[] = "我爱我家"; //测试显示的汉字,下面的A为测试显示的英文/*******************************************函数名称:Delay_1ms (晶振为12M)功能:延时约1ms的时间参数:无返回值:无********************************************/void delay_1ms(uint x){uint i,j;for(j = 0;j < x;j++)for(i=0;i<110;i++);}/*******************************************函数名称:write_cmd功能:向液晶中写控制命令参数:cmd--控制命令返回值:无********************************************/void write_cmd(uchar cmd){uchar lcdtemp = 0;LCD_RS=0;LCD_RW=1;do //经典判忙方式,精简{LCD_EN=1;delay_1ms(2);lcdtemp = P0;LCD_EN=0;}while(lcdtemp & 0x80);LCD_RW=0;P0 = cmd;LCD_EN=1;delay_1ms(5);LCD_EN=0;}/*******************************************函数名称:write_data功能:向液晶中写显示数据参数:dat--显示数据返回值:无********************************************/ void write_data(uchar dat){uchar lcdtemp = 0;LCD_RS=0;LCD_RW=1;do //经典判忙方式{LCD_EN=1;delay_1ms(2);lcdtemp = P0;LCD_EN=0;}while(lcdtemp & 0x80);LCD_RS=1;LCD_RW=0;P0 = dat;LCD_EN=1;delay_1ms(5);LCD_EN=0;}/*******************************************函数名称:lcd_int功能:初始化液晶模块参数:无返回值:无********************************************/void lcd_int(void){delay_1ms(40); //大于40MS的延时程序PSB=1; //设置为8BIT并口工作模式delay_1ms(1); //延时RES=0; //复位delay_1ms(1); //延时RES=1; //复位置高delay_1ms(10);write_cmd(0x30); //基本指令集delay_1ms(5);write_cmd(0x30); //基本指令集delay_1ms(5);write_cmd(0x08); // 地址归位delay_1ms(5);write_cmd(0x10); //光标设置delay_1ms(5);write_cmd(0x0c); //整体显示打开,游标关闭delay_1ms(5);write_cmd(0x01); //清除显示delay_1ms(5);write_cmd(0x06); //游标右移delay_1ms(5);write_cmd(0x80); //设定显示的起始地址delay_1ms(5);}函数名称:main功能:测试1602初始化函数模块参数:无返回值:无********************************************/void main(){uchar i;char *a = DAT;//使用指针,指向字符串地址lcd_int();write_data('A'); //每个显示都是用的两个字节,必须写两次write_data(' ');//再写一次,不然乱显示(如果不加就再显示一个别的字母)for(i=0;i<8;i++){write_data(*a);//将地址当作数据传给12864a++;//一个汉字传送两次,因为一个汉字占用两个字节,两次传完}write_cmd(0x90);//一行显示八个汉字,第一行0x80-87,第二行0x90开始a = DAT;for(i=0;i<8;i++){write_data(*a);a++;}while(1); //停住,不然重复的初始化显示,作为测试用}/*******************************************代码测试效果图片两两张由于曝光度影响,拍了两张********************************************/。

12864显示程序(汇编语言)

12864显示程序(汇编语言)
ACALL WRI ;调用写指令子程序
ACALL DELAY
ACALL DELAY
LCALL DELAY ;延迟39uS
MOV COM,#06H ;DDRAM的地址计数器(AC)加1
ACALL WRI ;调用写指令子程序
LCALL DELAY ;延迟39uS
MOV A,#8
MOV R3,A
DISP32: MOV R2,A
MOV A,R1
ADD A,#2
MOV R0,A
MOV R1,A
ACALL DELAY1
ACALL DELAY
DJNZ R4,DISP2
;右移显示,时间间隔为1秒
MOV R0,#00H
MOV R1,#00H
MOV R2,#1
MOV R3,#1
DISP4: MOV COM,B
ACALL WRI
ACALL DISP21
MOV R0,#00H
INC R3
MOV A,R3
CJNE A,#9,DISP42
MOV R3,A ;保存显示位数
DISP22: MOV R2,A
DEC B ;取下一次显示首地址,并进行判断
MOV A,B
CJNE A,#8FH,DISP23
INC R3 ;取下一次显示文字个数
MOV A,R3
CJNE A,#9,DISP12 ;判断文字个数是否超过8
MOV A,#8 ;超过8个就定死显示个数
ACALL WRI ;调用写指令子程序
ACALL DELAY ;延时
ACALL DELAY
ACALL DELAY
DJNZ R4,DISP1 ;判断移位显示是否完毕

12864液晶打点程序

12864液晶打点程序

#include "reg52.h"#include "intrins.h"sbit io_LCD12864_RS = P2^5 ;sbit io_LCD12864_RW = P2^6 ;sbit io_LCD12864_EN = P2^7 ;sbit A=P3^7;#define io_LCD12864_DATAPORT P0#define SET_DATA io_LCD12864_RS = 1 ;#define SET_INC io_LCD12864_RS = 0 ;#define SET_READ io_LCD12864_RW = 1 ;#define SET_WRITE io_LCD12864_RW = 0 ;#define SET_EN io_LCD12864_EN = 1 ;#define CLR_EN io_LCD12864_EN = 0 ;void v_Lcd12864CheckBusy_f( void ) //忙检测函数{unsigned int nTimeOut = 0 ;SET_INCSET_READCLR_ENSET_ENwhile( ( io_LCD12864_DATAPORT & 0x80 ) && ( ++nTimeOut != 0 ) ) ;CLR_ENSET_INCSET_READ}void v_Lcd12864SendCmd_f( unsigned char byCmd ) //发送命令{v_Lcd12864CheckBusy_f() ;SET_INCSET_WRITECLR_ENio_LCD12864_DA TAPORT = byCmd ;_nop_();_nop_();SET_EN_nop_();_nop_();CLR_ENSET_READSET_INC}void v_Lcd12864SendData_f( unsigned char byData ) //发送数据{v_Lcd12864CheckBusy_f() ;SET_DATASET_WRITECLR_ENio_LCD12864_DA TAPORT = byData ;_nop_();_nop_();SET_EN_nop_();_nop_();CLR_ENSET_READSET_INC}void v_DelayMs_f( unsigned int nDelay )//延时{unsigned int i ;for( ; nDelay > 0 ; nDelay-- ){for( i = 125 ; i > 0 ; i-- ) ;}}void v_Lcd12864Init_f( void )//初始化{v_Lcd12864SendCmd_f( 0x30 ) ;//基本指令集v_DelayMs_f( 50 ) ;v_Lcd12864SendCmd_f( 0x01 ) ;//清屏v_DelayMs_f( 50 ) ;v_Lcd12864SendCmd_f( 0x06 ) ;//光标右移v_DelayMs_f( 50 ) ;v_Lcd12864SendCmd_f( 0x0c ) ;//开显示}unsigned char u8_Lcd12864ReadByte_f( void ) {unsigned char byReturnValue ;v_Lcd12864CheckBusy_f() ;io_LCD12864_DA TAPORT = 0xff ;SET_DATASET_READCLR_ENSET_ENbyReturnValue = io_LCD12864_DATAPORT ;CLR_ENreturn byReturnValue ;}void v_Lcd12864DrawPoint_f( unsigned char X, unsigned char Y, unsigned char Color ) {unsigned char Row , Tier , Tier_bit ;unsigned char ReadOldH, ReadOldL ;v_Lcd12864SendCmd_f( 0x34 ) ;v_Lcd12864SendCmd_f( 0x36 ) ;Tier = X >> 4 ;Tier_bit = X & 0x0f ;if( Y < 32 ){Row = Y ;}else{Row = Y - 32 ;Tier += 8 ;}v_Lcd12864SendCmd_f( Row + 0x80 ) ;v_Lcd12864SendCmd_f( Tier + 0x80 ) ;u8_Lcd12864ReadByte_f() ;ReadOldH = u8_Lcd12864ReadByte_f() ;ReadOldL = u8_Lcd12864ReadByte_f() ;v_Lcd12864SendCmd_f( Row + 0x80 ) ;v_Lcd12864SendCmd_f( Tier + 0x80 ) ;if( Tier_bit < 8 ){switch( Color){case 0 : ReadOldH &=( ~( 0x01 << ( 7 - Tier_bit ))) ; break ;case 1 : ReadOldH |= ( 0x01 << ( 7 - Tier_bit )) ; break ;case 2 : ReadOldH ^= ( 0x01 << ( 7 - Tier_bit )) ; break ;default : break ;}v_Lcd12864SendData_f( ReadOldH ) ;v_Lcd12864SendData_f( ReadOldL ) ;}else{switch(Color){case 0 : ReadOldL &= (~( 0x01 << ( 15 - Tier_bit ))) ; break ;case 1 : ReadOldL |= ( 0x01 << ( 15 - Tier_bit )) ; break ;case 2 : ReadOldL ^= ( 0x01 << ( 15 - Tier_bit )) ; break ;default : break ;}v_Lcd12864SendData_f( ReadOldH ) ;v_Lcd12864SendData_f( ReadOldL ) ;}v_Lcd12864SendCmd_f( 0x30 ) ;}void v_Lcd12864DrawLineX_f( unsigned char X0, unsigned char X1, unsigned char Y, unsigned char Color ){unsigned char Temp ;if( X0 > X1 ){Temp = X1 ;X1 = X0 ;X0 = Temp ;}for( ; X0 <= X1 ; X0++ )v_Lcd12864DrawPoint_f( X0, Y, Color ) ;}//画垂直线:void v_Lcd12864DrawLineY_f( unsigned char X, unsigned char Y0, unsigned char Y1, unsigned char Color ){unsigned char Temp ;if( Y0 > Y1 ){Temp = Y1 ;Y1 = Y0 ;Y0 = Temp ;}for(; Y0 <= Y1 ; Y0++)v_Lcd12864DrawPoint_f( X, Y0, Color);}void gui_clear(){unsigned char i , j , k;v_Lcd12864SendCmd_f(0x34);//扩展指令集,8位数据传输v_Lcd12864SendCmd_f(0x34);//绘图显示关闭for(i = 0; i < 2; i ++)//分上下两屏写{for(j = 0; j < 32; j ++){v_Lcd12864SendCmd_f(0x80 + j);//写y坐标v_DelayMs_f( 1 ) ;if(i == 0) //写x坐标{v_Lcd12864SendCmd_f(0x80);v_DelayMs_f( 1 ) ;}else //写下半屏{v_Lcd12864SendCmd_f(0x88);v_DelayMs_f( 1) ;}for(k = 0; k < 16; k ++)//写一整行数据{v_Lcd12864SendData_f(0x00);//写高字节v_Lcd12864SendData_f(0x00);//写低字节v_DelayMs_f( 1 ) ;}}}v_Lcd12864SendCmd_f(0x36);//打开绘图显示v_Lcd12864SendCmd_f(0x30);//打开基本指令集}void main(){v_Lcd12864Init_f();gui_clear();v_DelayMs_f( 2 ) ;v_Lcd12864DrawPoint_f(15,18,1);// v_Lcd12864DrawPoint_f(16,18,1);// v_Lcd12864DrawPoint_f(17,18,1);// v_Lcd12864DrawPoint_f(18,18,1);// v_Lcd12864DrawLineX_f( 0, 127 , 0, 1 ) ;// v_Lcd12864DrawLineX_f( 0, 127 , 7, 1 ) ;// v_Lcd12864DrawLineX_f( 0, 127 , 15, 1 ) ;// v_Lcd12864DrawLineX_f( 0, 127 , 23, 1 ) ;// v_Lcd12864DrawLineX_f( 0, 127 , 31, 1 ) ;// v_Lcd12864DrawLineX_f( 0, 127 , 39, 1 ) ;// v_Lcd12864DrawLineX_f( 0, 127 , 47, 1 ) ;}。

12864 程序

12864 程序
send_com(0x01);//0000,0001 清DDRAM
send_com(0x02);//0000,0010 DDRAM地址归位
send_com(0x80);//1000,0000 设定DDRAM 7位地址000,0000到地址计数器AC
}
/*******************************************************************/
for(n=0;n < k;n++)
{
send_data(str[n]);//显示汉字时注意码值,连续两个码表示一个汉字
}
}
/********************清屏************************/
//清屏
/************************************************/
void clr_lcd(void)
{
send_com(0x01);
//send_com(0x34);
//send_com(0x30);
}
/**************主函数***********************/
void main ()
{
lcd_init(); //设定液晶工作方式
void chek_busy(void);
void set_xy(unsigned char xpos,unsigned char ypos);
void print(unsigned char x,unsigned char y,char* str);
void printstr(unsigned char xpos,unsigned char ypos,unsigned char str[],unsigned char k);

很好用的12864驱动程序

很好用的12864驱动程序

///////////////////////////////////////////////////////////#include<>#include<>#define uchar unsigned char#define uint unsigned int//////////单片机与液晶显示的引脚连接/////////sbit P32=P3^2; //RSTsbit P33=P3^3; //CS2sbit P34=P3^4; //CS1sbit P35=P3^5; //Esbit P36=P3^6; //rs&DIsbit P37=P3^7; // R/W////////延时/////////void delay(uint v){while(v!=0)v--;}////////复位///////////void reset(){P32=0;delay(10);delay(10);}////////write code写指令///////void wcode(uchar c,uchar cs1,uchar cs2) {P34=cs1;P33=cs2;P37=0;P36=0;P1=c;P35=0;delay(10);P35=1;delay(10);P35=0;}/////////write data写数据///////////////void wdata(uchar c,uchar cs1,uchar cs2) {P34=cs1;P33=cs2;P37=1;P36=0;P35=0;delay(10);P35=1;delay(10);P35=0;}////////////set start设置起始行/////////////void set_startline(uchar i)//起始行。

11A5A4A3A2A1A0 共有64行// 液晶显示器的最底层为第一行{i=0xc0+64-i;//此算法为把最顶层做为第一层wcode(i,1,1);}////////////set 页值设置,起始列值函数/////////////void set_adr(uchar x,uchar y){x=x+0xb8;//页地址设置。

12864液晶模块程序

12864液晶模块程序

#include <reg52.h>#include <intrins.h>#define uint unsigned int#define uchar unsigned char#define lcddat P0sbit RS=P2^0; //数据/命令选择端:RS=H时,选择数据,RS=L,时,选择命令sbit RW=P2^1; //液晶读写选择端:RW=H时,读,RW=L,时,写sbit EN=P2^2; //液晶使能控制//sbir PSB=P2^3 //串并口方式控制,并口不需要操作,液晶默认的方式是并口,若要使用串口则应在程序中队PSB=0;uchar dis1[]={"2015年06月19日"};void lcd_clear(void);void delayms(uint sj);void write_cmd(uchar cmd);void write_dat(uchar dat);void lcd_pos(uchar x, uchar y);void lcd_init();void print(uchar *str);void show();//********************************//液晶检测忙状态//在写入之前必须执行//********************************void lcd_busy(void){ uchar busy;lcddat=0xff;RS=0;RW=1;EN=1;Delayms(5);busy=lcddat&0x80;while(busy==0x80);EN=0;}//***********************************//填充液晶DDRAM全为空格//**********************************void lcd_clear(void){write_cmd(0x30);write_cmd(0x01);}//*******************************//延时子程序模块//*******************************void delayms(uint sj){ uint i,j;for(j=0;j<sj;j++)for(i=0;i<110;i++);//1ms延时.}//*******************************//写指令条件:RS=0,RW=0,E=高脉冲,D0~D7=指令码//*******************************void write_cmd(uchar cmd){lcd_busy();RS=0;RW=0;EN=0;lcddat=cmd;delayms(5);EN=1;delayms(5);EN=0;}//*******************************//写数据条件:RS=1,RW=0,E=高脉冲,D0~D7=数据//*******************************void write_dat(uchar dat){lcd_busy();RS=1;RW=0;EN=0;lcddat=dat;delayms(5);EN=1;delayms(5);EN=0;}//********************************//指定要显示字符的坐标x:行y:列//*******************************void lcd_pos(uchar x, uchar y){ y=y--;if(x==1)write_cmd(0x80|y);if(x==2)write_cmd(0x90|y);if(x==3)write_cmd((0x80|y)+8);if(x==4)write_cmd((0x90|y)+8);}//*******************************//LCD初始化程序//*******************************void lcd_init(){//PSB=1; //并口方式write_cmd(0x30); //基本功能设定delayms(5);write_cmd(0x0c); //显示开,关光标delayms(5);write_cmd(0x01); //清除LCD的显示内容delayms(5);}//**********************************//液晶显示字符串程序//**********************************void print(uchar *str){while(*str!='\0'){write_dat(*str);str++;}}//*************************************** //液晶显示主程序模块//*************************************** void show(){lcd_pos(1,1);print("液晶显示模块^__^");delayms(1000);lcd_pos(2,5);print("by郭功晓");delayms(1000);lcd_pos(3,2);print(dis1);delayms(1000);}#include <12864bx.h>main(){lcd_init();lcd_clear();show(); //液晶显示数据while(1);}。

12864点阵型驱动程序(51单片机、c语言)

12864点阵型驱动程序(51单片机、c语言)
** 函 数 名:asc()
** 功能描述:在液晶显示器上写一个ASCII字符,写之前需要使用setxy()函数确定位置
** 输入参数:uchar ascii:字符对应的ascii码
** 输出参数:
** 返 回 值:
** 作 者:xiwangcumt
** 日 期:
**********************************************************/
** 功能描述:C语言下最精确最简单的延时函数,延时时间为2*t+2(us)
** 输入参数:t-延时时间参数
** 输出参数:
** 返 回 值:
** 作 者:xiwangcumt
** 日 期:
**********************************************************/
void setp(uchar n)
{
switch(n){
case 0: cs1=1;cs2=1; break;
case 1: cs1=1;cs2=0; break;
case 2: cs1=0;cs2=1; break;
default:break;}
}
/*********************************************************
** 输入参数:uchar dat
** 输出参数:
** 返 回 值:
** 作 者:xiwangcumt
** 日 期:
**********************************************************/

12864液晶屏汇编程序

12864液晶屏汇编程序

12864液晶屏汇编程序[ 作者:佚名 | 转贴自:本站原创 | 点击数:211 | 更新时间:2005-3-28 | 文章录入:qwll20000 ] XCS BIT 00H ;显示器片选0=CS1,1=CS2 ;20H-2FH为位寻址区,位地址从00H-7FH BZPD BIT 01H ;0=上8X8半字,1=下8X8半字HHBZ BIT 02H ;换行标志HZDH BIT 03H ;0=显示汉字,1=显示动画LCD_RW BIT P3.0LCD_DI BIT P3.1LCD_E BIT P3.3LCD_CS1 BIT P3.5LCD_CS2 BIT P3.4LCD_OPEN DA TA 30HLCD_LINE DATA 31HLCD_PAGE DATA 32HLCD_Y DA TA 33HYCPD DA TA 34H ;左右半屏溢出判断HHPD DA TA 35H ;换行判断XWPD DA TA 36H ;写完一整屏判断ORG 0000HMOV SP,#40HSETB XCS ;选择CS2MOV LCD_OPEN,#01H ;开显示器1,关显示器0LCALL LCDOPENMOV LCD_LINE,#00H ;设置起始行LCALL SETLINEMOV LCD_PAGE,#00H ;设置页地址 LCALL SETPAGEMOV LCD_Y,#00H ;设置列地址 LCALL SETYLJMP CLRST1CLR4:INC LCD_PAGECLRST1:LCALL SETPAGEMOV R7,#40HCLR5:MOV A,#0FFH ;显示校验LCALL LCDWRDATADJNZ R7,CLR5MOV A,LCD_PAGECJNE A,#07H,CLR4MOV LCD_LINE,#00HLCALL SETLINEMOV LCD_PAGE,#00HLCALL SETPAGEMOV LCD_Y,#00HLCALL SETYLJMP CLRST2CLR6:INC LCD_PAGECLRST2:LCALL SETPAGEMOV R7,#40HCLR7:MOV A,#00H ;清显示LCALL LCDWRDATADJNZ R7,CLR7MOV A,LCD_PAGECJNE A,#07H,CLR6CLR XCS ;选择CS1MOV LCD_OPEN,#01H ;开显示器1, 关显示器0 LCALL LCDOPENMOV LCD_LINE,#00HLCALL SETLINE ;设置起始行MOV LCD_PAGE,#00HLCALL SETPAGE ;设置页地址MOV LCD_Y,#00HLCALL SETY ;设置列地址LJMP CLRST3CLR0:INC LCD_PAGECLRST3:LCALL SETPAGEMOV R7,#40HCLR1:MOV A,#0FFH ;显示校验LCALL LCDWRDATADJNZ R7,CLR1MOV A,LCD_PAGECJNE A,#07H,CLR0MOV LCD_LINE,#00HLCALL SETLINEMOV LCD_PAGE,#00HLCALL SETPAGEMOV LCD_Y,#00HLCALL SETYLJMP CLRST4CLR2:INC LCD_PAGECLRST4:LCALL SETPAGEMOV R7,#40HCLR3:MOV A,#00H ;清显示LCALL LCDWRDATADJNZ R7,CLR3MOV A,LCD_PAGECJNE A,#07H,CLR2;初始化完毕************************************************************************* CLR HZDHWRLCD:JNB HZDH,XZFXDH:MOV DPTR,#DHDOT ;写动画或图片LJMP DH0XZF:MOV DPTR,#HZDOT ;写字符(汉字或字母或符号)MOV XWPD,#00HHZ0:CLR XCSMOV LCD_LINE,#00H ;置起始行LCALL SETLINEMOV LCD_PAGE,#00HLCALL SETPAGE ;置页MOV LCD_Y,#00H ;置列LCALL SETYMOV HHPD,#00HHZ7:MOV YCPD,#00HHZ8:CLR BZPDHZ3:MOV R0,#08H ;写左上8个Y列HZ1:MOV A,#00HMOVC A,@A+DPTRLCALL LCDWRDATAINC DPTRINC LCD_YDJNZ R0,HZ1JB BZPD,HZ2CLR C ;Y列减8, 即返回扫描MOV A,LCD_YSUBB A,#08HMOV LCD_Y,ALCALL SETYINC LCD_PAGE ;页地址加1,即换第2页扫描 LCALL SETPAGESETB BZPDLJMP HZ3HZ2:DEC LCD_PAGE ;返回到第1页中,准备下一个半字扫描 LCALL SETPAGEINC YCPDMOV A,YCPDCJNE A,#08H,HZ8JB XCS,HZ9SETB XCS ;换屏LCALL SETPAGEMOV LCD_Y,#00H ;置列LCALL SETYLJMP HZ7HZ9:CLR XCS ;写完一行后从CS2返回到CS1中INC LCD_PAGEINC LCD_PAGELCALL SETPAGE ;下一行开始MOV LCD_Y,#00HLCALL SETYINC HHPDMOV A,HHPDCJNE A,#04H,HZ7INC XWPD ;换第二幅画面MOV A,XWPDCJNE A,#02H,HZ0LJMP$DH0:MOV XWPD,#00HDH1:CLR XCSMOV LCD_LINE,#00H ;置起始行 LCALL SETLINEMOV LCD_PAGE,#00HLCALL SETPAGE ;置页MOV LCD_Y,#00H ;置列LCALL SETYMOV HHPD,#00HDH2:MOV R0,#40H ;写上64个Y列 DH3:MOV A,#00HMOVC A,@A+DPTRLCALL LCDWRDATAINC DPTRDJNZ R0,DH3JB XCS,DH4SETB XCSLCALL SETPAGEMOV LCD_Y,#00HLCALL SETYLJMP DH2DH4:CLR XCS ;写完一行后从CS2返回到CS1中 INC LCD_PAGELCALL SETPAGE ;下一行开始MOV LCD_Y,#00HLCALL SETYINC HHPDMOV A,HHPDCJNE A,#08H,DH2INC XWPD ;换第二幅画面MOV A,XWPDCJNE A,#02H,DH1LJMP$LCDWRINST:NOPJB XCS,INS0CLR LCD_CS1SETB LCD_CS2LJMP INS1INS0:SETB LCD_CS1CLR LCD_CS2INS1:SETB LCD_ECLR LCD_DICLR LCD_RWMOV P1,ALCALL DLY10CLR LCD_ELCALL DLY10RETLCDWRDATA:NOPJB XCS,DA T0CLR LCD_CS1SETB LCD_CS2LJMP DA T1DA T0:SETB LCD_CS1CLR LCD_CS2DA T1:SETB LCD_ESETB LCD_DICLR LCD_RWMOV P1,ALCALL DLY10CLR LCD_ELCALL DLY10NOPRETLCDOPEN:MOV A,LCD_OPEN ;开显示器 ANL A,#3FHORL A,#3EHLCALL LCDWRINSTNOPRETSETLINE:MOV A,LCD_LINEORL A,#0C0H ;设置起始行LCALL LCDWRINSTRETSETPAGE:MOV A,LCD_PAGEANL A,#0BFHORL A,#0B8H ;设置页地址 LCALL LCDWRINSTNOPRETSETY:MOV A,LCD_YANL A,#7FHORL A,#40HNOP ;设置列地址LCALL LCDWRINSTNOPRETDL Y10:NOPMOV R5,#01HDL1:MOV R4,#01HDL2:MOV R6,#0FHDL3:DJNZ R6,DL3DJNZ R4,DL2DJNZ R5,DL1NOPRETHZDOT:;新 CD0C2DB 000H,044H,04CH,07CH,0D7H,0E6H,07CH,05CH DB 000H,022H,01AH,04EH,0FFH,07FH,00EH,09AH DB 044H,0FEH,0FCH,046H,0C2H,0C3H,062H,040H DB 060H,03FH,01FH,000H,0FFH,0FFH,000H,000H;年 CC4EADB 000H,020H,010H,018H,0ECH,0CFH,04AH,048H DB 000H,004H,004H,004H,007H,007H,004H,004H DB 0F8H,0F8H,048H,048H,068H,04CH,008H,000H DB 0FFH,0FFH,004H,004H,004H,004H,006H,004H;快 CBFECDB 000H,0C0H,060H,0FFH,0FEH,030H,060H,008H DB 000H,000H,000H,0FFH,07FH,080H,041H,071H DB 008H,0FFH,0FEH,008H,0F8H,0FCH,008H,000H DB 03DH,00FH,007H,00DH,039H,071H,0E1H,041H;乐 CC0D6DB 000H,000H,080H,080H,0FEH,0FCH,084H,084H DB 000H,040H,020H,030H,01CH,00EH,024H,040H DB 0FEH,0F6H,082H,083H,0C2H,080H,000H,000H DB 0FFH,07FH,000H,002H,00CH,018H,070H,020H;欢 CBBB6DB 000H,034H,0C4H,004H,0C4H,0FCH,03EH,024H DB 000H,040H,038H,00FH,007H,03CH,098H,060H DB 018H,00EH,0EFH,0CAH,048H,038H,01CH,008H DB 030H,01CH,00FH,007H,01CH,070H,0E0H,040H;迎 CD3ADDB 000H,040H,046H,0DCH,0E8H,040H,0FEH,0FCH DB 000H,040H,0E0H,03FH,01FH,032H,067H,0C3H DB 006H,003H,0FDH,0FCH,004H,0FCH,0FEH,004H DB 0C2H,0C1H,0FFH,0DFH,0C2H,0C7H,0C3H,040H;使 CCAB9DB 000H,080H,060H,0F8H,0EFH,006H,008H,0F8H DB 000H,000H,000H,0FFH,07FH,080H,080H,043H DB 0E8H,028H,0FFH,0FEH,028H,0E8H,0FCH,028H DB 065H,039H,01FH,037H,061H,063H,0C1H,040H;用 CD3C3DB 000H,000H,000H,0FFH,0FEH,022H,022H,022H DB 000H,080H,070H,03FH,00FH,002H,002H,002H DB 0FEH,0FEH,022H,022H,022H,0FEH,0FFH,002H DB 07FH,03FH,002H,042H,042H,0FFH,07FH,000H;杭 CBABCDB 000H,010H,0D0H,0FFH,0FEH,090H,010H,008H DB 000H,006H,001H,0FFH,07FH,001H,083H,040H DB 0E8H,0C9H,04FH,04EH,0C8H,0E8H,04CH,008H DB 07FH,03FH,000H,000H,07FH,0FFH,0C0H,070H;州 CD6DDDB 000H,010H,0E0H,0C0H,0FFH,0FEH,010H,0E0H DB 000H,080H,041H,070H,03FH,00FH,000H,001H DB 0C0H,0FEH,0FCH,030H,0E0H,0C0H,0FFH,0FEH DB 000H,03FH,01FH,000H,001H,000H,0FFH,07FH;求 CC7F3DB 000H,000H,008H,068H,0C8H,088H,008H,0FFH DB 000H,010H,070H,038H,00DH,026H,041H,0FFH DB 0FEH,088H,0CBH,07EH,02CH,008H,000H,000H DB 07FH,003H,006H,01CH,038H,070H,020H,000H;是 CCAC7DB 000H,080H,080H,080H,0FFH,0BEH,0AAH,0AAH DB 000H,080H,060H,038H,00FH,01AH,030H,020H DB 0AAH,0AAH,0AAH,0FEH,0BFH,082H,0C0H,080H DB 07FH,07FH,044H,0C4H,0C6H,0C4H,0C0H,040H;医 CD2BDDB 000H,000H,0FFH,0FEH,042H,0A2H,0BAH,09EH DB 000H,040H,0FFH,07FH,060H,050H,058H,04CH DB 096H,0F2H,0F2H,092H,09AH,0D3H,082H,000H DB 046H,043H,041H,046H,04CH,058H,068H,040H;学 CD1A7DB 000H,010H,038H,01CH,00BH,04EH,048H,04BH DB 000H,000H,004H,004H,004H,004H,044H,044HDB 04EH,0C8H,0ECH,04FH,00AH,038H,01CH,008H DB 0FFH,07FH,004H,004H,004H,006H,004H,000H;科 CBFC6DB 000H,024H,0A4H,0FEH,0FEH,0A3H,022H,0C0H DB 000H,00CH,003H,0FFH,07FH,001H,00BH,008H DB 08CH,038H,010H,0FFH,0FEH,000H,000H,000HDB 00BH,005H,004H,0FFH,07FH,002H,003H,002H;技 CBCBCDB 000H,010H,010H,0FFH,0FEH,010H,098H,048H DB 000H,00CH,046H,0FFH,07FH,001H,080H,040H DB 0C8H,048H,07FH,07EH,0C8H,0E8H,04CH,008H DB 061H,037H,01CH,01EH,037H,061H,0E0H,040H;有 CD3D0DB 000H,084H,044H,064H,034H,0FCH,0EFH,026H DB 000H,000H,000H,000H,000H,0FFH,07FH,009H DB 024H,024H,024H,0E4H,0F4H,024H,006H,004H DB 009H,009H,049H,0FFH,07FH,000H,000H,000H;限 CCFDEDB 000H,0FFH,0FEH,042H,0BEH,01FH,002H,0FFH DB 000H,0FFH,0FFH,008H,01FH,00FH,040H,0FFH DB 0FEH,092H,092H,092H,0FEH,0FFH,002H,000H DB 07FH,061H,036H,01CH,039H,06EH,0E4H,040H;公 CB9ABDB 000H,000H,080H,0C0H,070H,03EH,00FH,082H DB 000H,001H,000H,060H,0F0H,078H,06EH,067H DB 0C0H,080H,00FH,03EH,070H,0E0H,0C0H,080H DB 021H,022H,026H,03CH,0F8H,070H,001H,000H;司 CCBBEDB 000H,000H,010H,0D2H,092H,092H,092H,092H DB 000H,000H,000H,01FH,00FH,008H,008H,008HDB 01FH,00FH,000H,040H,040H,0FFH,07FH,000H;地 CB5D8DB 000H,020H,020H,0FEH,0FCH,020H,060H,0F8H DB 000H,010H,030H,01FH,01FH,008H,004H,07FH DB 0F0H,020H,0FFH,0FEH,010H,0F0H,0F8H,010H DB 0FFH,0C0H,0C7H,0C7H,0C2H,0C7H,0F3H,040H;址 CD6B7DB 000H,020H,020H,0FEH,0FCH,020H,020H,0E0H DB 000H,010H,030H,03FH,01FH,058H,048H,07FH DB 0C0H,000H,000H,0FFH,0FEH,040H,060H,040H DB 07FH,040H,040H,07FH,07FH,040H,060H,040H;: CA3BADB 000H,000H,000H,000H,000H,000H,000H,000H DB 000H,000H,036H,036H,000H,000H,000H,000H DB 000H,000H,000H,000H,000H,000H,000H,000H DB 000H,000H,000H,000H,000H,000H,000H,000H;通 CCDA8DB 000H,040H,046H,0DCH,0E8H,040H,000H,0F9H DB 000H,040H,0E0H,03FH,01FH,030H,060H,0FFH DB 0F1H,055H,0FDH,0F9H,057H,0F3H,0F9H,010H DB 0DFH,0C2H,0DFH,0CFH,0D2H,0FFH,0DFH,040H;惠 CBBDDDB 000H,000H,002H,0FEH,0FAH,0AAH,0AAH,0FFHDB 0FFH,0AAH,0AAH,0FAH,0FEH,00AH,000H,000H DB 0FBH,0D2H,0C2H,0F2H,04FH,016H,070H,020H;北 CB1B1DB 000H,020H,020H,020H,020H,0FEH,0FEH,000H DB 000H,020H,060H,020H,010H,0FFH,0FFH,000H DB 000H,0FFH,0FEH,082H,0C0H,060H,038H,010H DB 000H,07FH,0FFH,0C1H,0C0H,0C0H,0F0H,040H;路 CC2B7DB 000H,07FH,03EH,0E2H,0BEH,07FH,002H,010H DB 000H,07CH,060H,03FH,03FH,012H,00BH,001H DB 08CH,0DFH,066H,074H,0DCH,08EH,004H,000H DB 0FFH,07EH,042H,042H,0FEH,07FH,003H,001H;2 CHAR_32DB 008H,00CH,084H,0C4H,064H,03CH,018H,000H DB 00EH,00FH,009H,008H,008H,00CH,00CH,000H;8 CHAR_38DB 0B8H,0FCH,044H,044H,044H,0FCH,0B8H,000H DB 007H,00FH,008H,008H,008H,00FH,007H,000H;号 CBAC5DB 000H,080H,080H,080H,0BFH,09EH,092H,092H DB 000H,000H,000H,000H,004H,00EH,007H,005H DB 092H,092H,092H,0BEH,09FH,082H,0C0H,080H DB 024H,044H,0E4H,07CH,01EH,004H,000H,000H;电 CB5E7DB 000H,000H,0F8H,0F0H,090H,090H,090H,0FFH DB 000H,000H,00FH,007H,004H,004H,004H,07FH DB 0FEH,090H,090H,090H,0F0H,0F8H,010H,000H DB 0FFH,0C4H,0C4H,0C4H,0CFH,0C7H,0F0H,040H;话 CBBB0DB 000H,040H,046H,0DCH,0E8H,040H,020H,024H DB 000H,000H,020H,07FH,03FH,010H,008H,0FFH DB 024H,024H,0FEH,0FEH,026H,023H,032H,020H DB 07EH,042H,043H,043H,042H,0FEH,07FH,002H;: CA3BADB 000H,000H,000H,000H,000H,000H,000H,000H DB 000H,000H,036H,036H,000H,000H,000H,000H DB 000H,000H,000H,000H,000H,000H,000H,000H DB 000H,000H,000H,000H,000H,000H,000H,000H;0 CHAR_30DB 0F8H,0FCH,004H,0C4H,024H,0FCH,0F8H,000H DB 007H,00FH,009H,008H,008H,00FH,007H,000H;5 CHAR_35DB 07CH,07CH,044H,044H,0C4H,0C4H,084H,000H DB 004H,00CH,008H,008H,008H,00FH,007H,000H;7 CHAR_37DB 00CH,00CH,004H,084H,0C4H,07CH,03CH,000HDB 000H,000H,00FH,00FH,000H,000H,000H,000H;1 CHAR_31DB 000H,010H,018H,0FCH,0FCH,000H,000H,000H DB 000H,008H,008H,00FH,00FH,008H,008H,000H;- CHAR_2DDB 080H,080H,080H,080H,080H,080H,080H,000H DB 000H,000H,000H,000H,000H,000H,000H,000H;8 CHAR_38DB 0B8H,0FCH,044H,044H,044H,0FCH,0B8H,000H DB 007H,00FH,008H,008H,008H,00FH,007H,000H;2 CHAR_32DB 008H,00CH,084H,0C4H,064H,03CH,018H,000H DB 00EH,00FH,009H,008H,008H,00CH,00CH,000H;6 CHAR_36DB 0F0H,0F8H,04CH,044H,044H,0C0H,080H,000H DB 007H,00FH,008H,008H,008H,00FH,007H,000H;0 CHAR_30DB 0F8H,0FCH,004H,0C4H,024H,0FCH,0F8H,000H DB 007H,00FH,009H,008H,008H,00FH,007H,000H;4 CHAR_34DB 0C0H,0E0H,0B0H,098H,0FCH,0FCH,080H,000H DB 000H,000H,000H,008H,00FH,00FH,008H,000H;7 CHAR_37DB 00CH,00CH,004H,084H,0C4H,07CH,03CH,000HDB 000H,000H,00FH,00FH,000H,000H,000H,000H;1 CHAR_31DB 000H,010H,018H,0FCH,0FCH,000H,000H,000HDB 000H,008H,008H,00FH,00FH,008H,008H,000H;5 CHAR_35DB 07CH,07CH,044H,044H,0C4H,0C4H,084H,000HDB 004H,00CH,008H,008H,008H,00FH,007H,000HDHDOT:;-------------------------------------------------------------------------------DB000H,000H,000H,000H,000H,000H,000H,000H,007H,0E7H,0E3H,0E1H,0E1H,0E1H,0E1H,0C1H, DB0C1H,081H,081H,081H,083H,083H,083H,083H,087H,087H,08FH,08FH,09FH,0BFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0F3H,0F3H,0F1H,0E1H,061H,061H,020H, DB030H,030H,0B0H,0B0H,0B0H,0B8H,0B8H,0BCH,0BCH,03EH,03EH,03FH,03FH,07FH,07FH,07FH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FEH,0FEH,0FCH,0FCH,0FCH,0FEH,0FFH, DB0F7H,0E3H,0E7H,0EFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,000H,000H,000H, DB000H,000H,000H,000H,000H,000H,000H,000H,000H,001H,07FH,0FFH,0F3H,083H,083H,081H,DB001H,001H,000H,080H,080H,000H,002H,002H,002H,006H,004H,0A5H,0EDH,0EDH,0EBH,0DBH, DB0F7H,0BFH,07FH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0F7H,089H,080H,082H,0C0H,080H, DB000H,000H,000H,000H,000H,088H,0C0H,0F8H,0F8H,0F8H,0F0H,0F0H,0E0H,0C0H,0C0H,0F0H, DB0F8H,0F8H,0FCH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,00FH,000H,000H,000H, DB000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,07FH,0FFH,0FFH,0FFH,0FFH,DB0FFH,0FEH,0FFH,0FFH,0FFH,0FFH,0FEH,0FEH,0FEH,0FEH,0FEH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,03FH,00FH,003H,000H,000H,000H,000H,000H, DB000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,03FH,03FH,07FH,0BFH,03FH,03FH, DB03FH,01FH,01FH,00FH,007H,007H,001H,000H,000H,000H,000H,000H,000H,000H,000H,000H, DB000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,003H,03FH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,01FH,000H,000H,07CH,0FFH,0FFH,078H, DB000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,DB000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,003H,0FFH,DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0E3H,0E3H,0C3H,087H,08FH,01FH,01FH,0BFH,0BFH,0FFH,0FFH, DB0FFH,0F7H,0F3H,0F3H,0FBH,0FBH,0FBH,0FBH,0FBH,0FBH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,07FH,07FH,07FH,07FH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,00FH,000H,000H,000H,000H,000H,000H,000H, DB000H,000H,000H,000H,000H,000H,0E0H,0F8H,0FCH,0FEH,0FEH,0FEH,0FEH,0FEH,0FCH,0FCH, DB000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,0F8H,0FFH,DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,DB0FFH,0FDH,0F9H,0F3H,0E7H,0C7H,087H,007H,007H,0C7H,087H,087H,08FH,08FH,08FH,0CFH, DB0CFH,0DFH,0FFH,09FH,0DFH,0DFH,0FFH,0CFH,0EFH,0EFH,0FFH,0FFH,0CFH,0CFH,0E7H,0E7H, DB0E3H,0E3H,0E3H,0F1H,0F9H,0F9H,0F8H,0FCH,0FCH,0FEH,0FEH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,03FH,00FH,007H,000H,000H,000H,000H,000H,000H,000H,000H,000H,DB000H,000H,000H,000H,000H,000H,000H,007H,027H,07FH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,DB000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,0E0H,0FCH,0FFH,0FFH,DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0F8H,0F1H,0F3H,0E7H,0CFH,0CFH,0DFH,0DFH, DB09FH,09FH,0BFH,0BFH,0BFH,09FH,0DFH,0DFH,0DFH,0CFH,0EFH,0FFH,0FFH,0FFH,0FBH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH,0FFH, DB0FFH,0F7H,0FDH,0FCH,0FCH,0FEH,0FFH,0FCH,0C0H,000H,000H,000H,000H,000H,000H,000H, DB000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,000H,001H,0F1H,0FFH,0FFH,。

基于STM8的12864LCD点阵字库显示

基于STM8的12864LCD点阵字库显示

基于STM8/32的128*64LCD点阵字库显示
本方案主控采用STM8S207C8T6,1.7寸128*64LCD显示屏,LCD驱动芯片采用UC1701(可兼容ST7565),字库显示采用高通GT20L16S1Y字库芯片,以实现LCD界面上的显示。

详细资料及代码可查看附件。

以下分别是STM8S207C8T6,UC1701和GT20L16S1Y在原理图中的模块电路。

原理图是依据datasheet中的阐述所绘制,其中主控电路是使用了stm8s207c8t6芯片绘制的最小系统,显示屏部分是根据设置BM0和BM1来选择总线模式绘制的电路。

这里我使用了SPI总线模式。

而字库芯片本身就是SPI总线模式通信,直接根据规格书的电路例子使用即可。

完成了电路部分,知道了总线模式,再结合数据手册就可以对改设备编写程序代码了。

首先是LCD液晶屏的驱动,要液晶屏显示你想要的数据,主要是LCD初始化成功,下面是LCD初始化程序,根据指令列表编写的程序代码:
初始化显示屏之前必须对引脚的模式进行相对应的配置
显示驱动成功后则接着是对字库芯片的文字数据获取进行编程调试,以下是获取GB2312文字的函数代码。

PCB实物图
实际效果图
以下有三个界面,分别是行驶记录仪、门禁显示和一个图形页面。

文字显示采用GT20L16S1Y字库芯片,这款芯片包含最常用的GB2312汉字,字型符合国家标准。

门禁界面中的数字采用字库芯片内的24点阵不等宽时钟体字库。

图形LOGO可存储至字库芯片中的64K可擦写空间。

附件1:/s/1jG6dte2 附件2:/s/1sjEC4Kt 附件3:/s/1gdhgXSv。

12864液晶程序+仿真图

12864液晶程序+仿真图

/**********************************************************12864是由两块64*64的液晶屏组成的。

当中页是通过自己去定义的。

**********************************************************/#include"reg51.h"#define uchar unsigned char#define uint unsigned intsbit lcdrst=P3^0;sbit cs2=P3^5;sbit cs1=P3^4;sbit e=P3^2;sbit rw=P3^3;sbit rs=P3^1;/************************************************代码:字模生成可以在取模软件生成。

方法是阴码列行式逆向************************************************/uchar code qin[]={0x04,0x04,0xC4,0x5F,0x54,0xF4,0x54,0x5F,0xC4,0x14,0x10,0xFF,0x10,0x10,0xF0,0x00,0x00,0x80,0x95,0x95,0x95,0x7F,0x55,0x55,0x95,0x60,0x1C,0x03,0x20,0x60,0x3F,0x00};// 勤uchar code mian[]={0x00,0xF0,0x2C,0x27,0xE4,0x34,0x2C,0xE4,0x08,0x08,0xFF,0x08,0x08,0xF8,0x00,0x00,0x40,0x21,0x11,0x0F,0x01,0x3F,0x41,0x49,0x44,0x43,0x40,0x44,0x48,0x47,0x70,0x00};//勉uchar code li[]={0x44,0x44,0xFC,0x44,0x44,0x00,0xFE,0x92,0x92,0xFE,0x92,0x92,0x92,0xFE,0x00,0x00,0x10,0x10,0x0F,0x08,0x48,0x40,0x45,0x44,0x44,0x7F,0x44,0x44,0x44,0x45,0x40,0x00};//理uchar code gong[]={0x00,0x00,0x02,0x02,0x02,0x02,0x02,0xFE,0x02,0x02,0x02,0x02,0x02,0x02,0x00,0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00 }; //工uchar code xue[]={0x40,0x30,0x10,0x12,0x5C,0x54,0x50,0x51,0x5E,0xD4,0x50,0x18,0x57,0x32,0x10,0x00,0x00,0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x02,0x02,0x02,0x00};//学uchar code yuan[]={0xFE,0x02,0x32,0x4A,0x86,0x0C,0x24,0x24,0x25,0x26,0x24,0x24,0x24,0x0C,0x04,0x00,0xFF,0x00,0x02,0x04,0x83,0x41,0x31,0x0F,0x01,0x01,0x7F,0x81,0x81,0x81,0xF1,0x00};//院uchar code dian[]={0x00,0x00,0xF8,0x48,0x48,0x48,0x48,0xFF,0x48,0x48,0x48,0x48,0xF8,0x00,0x00,0x00,0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0x3F,0x44,0x44,0x44,0x44,0x4F,0x40,0x70,0x00};//电uchar code zi[]={0x00,0x00,0x02,0x02,0x02,0x02,0x02,0xE2,0x12,0x0A,0x06,0x02,0x00,0x80,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x41,0x81,0x7F,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00};//子uchar code cheng[]={0x10,0x12,0xD2,0xFE,0x91,0x11,0x80,0xBF,0xA1,0xA1,0xA1,0xA1,0xBF,0x80,0x00,0x00,0x04,0x03,0x00,0xFF,0x00,0x41,0x44,0x44,0x44,0x7F,0x44,0x44,0x44,0x44,0x40,0x00};//程uchar code tong[]={0x40,0x41,0xC6,0x00,0x00,0xF2,0x52,0x52,0x56,0xFA,0x5A,0x56,0xF2,0x00,0x00,0x00,0x40,0x20,0x1F,0x20,0x40,0x5F,0x42,0x42,0x42,0x5F,0x4A,0x52,0x4F,0x40,0x40,0x00};//通uchar code xin[]={0x80,0x40,0x30,0xFC,0x07,0x0A,0xA8,0xA8,0xA9,0xAE,0xAA,0xA8,0xA8,0x08,0x08,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x7E,0x22,0x22,0x22,0x22,0x22,0x7E,0x00,0x00,0x00};//信uchar codeban[]={0x42,0x42,0xFE,0x42,0x42,0xE0,0x00,0xFF,0x00,0x42,0x42,0xFE,0x42,0x42,0x42,0x00,0x10,0x10,0x0F,0x88,0x49,0x20,0x18,0x07,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x00};//班uchar code ling[]={0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00};//0uchar code ba[]={0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00};//8uchar code yi[]={0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00};//1uchar code kongge[]={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};//不显示任何内容uchar code kong[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //不显示任何内容uchar code huo[]={0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0xFF,0x02,0x40,0x20,0x18,0x10,0x00,0x00,0x00,0x00,0x80,0x41,0x20,0x10,0x0C,0x03,0x00,0x03,0x04,0x18,0x30,0x60,0x20,0x00,0x00};//火uchar code yun[]={0x40,0x40,0x44,0x44,0x44,0x44,0xC4,0xC4,0x44,0x44,0x46,0x46,0x64,0x60,0x40,0x00,0x00,0x20,0x70,0x38,0x2C,0x27,0x23,0x31,0x10,0x12,0x14,0x18,0x70,0x20,0x00,0x00};//云uchar code xie[]={0x00,0x22,0x3E,0x22,0x22,0xA2,0xFE,0x22,0x00,0xFE,0x02,0x22,0x5A,0x86,0x02,0x00,0x10,0x10,0x08,0x04,0x23,0x40,0x3F,0x00,0x00,0xFF,0x00,0x04,0x08,0x08,0x07,0x00};//邪uchar code shen[]={0x08,0x08,0x89,0xCE,0xA8,0x18,0x00,0xF8,0x48,0x48,0xFF,0x48,0x48,0xF8,0x00,0x00,0x02,0x01,0x00,0xFF,0x00,0x03,0x00,0x07,0x02,0x02,0xFF,0x02,0x02,0x07,0x00,0x00};//神/*************************************************延时函数**************************************************/void delay(uchar z){uchar i,j;for(i=z;i>0;i--)for(j=110;j>0;j--);}/********************************************检查状态*********************************************/void checkbusy(){uchar dat;rs=0; //数据\指令选择rw=1; //允许读do{P2=0x00; //清零P2口delay(5);e=1;dat=P2; //读P2口e=0;dat>>=7; //仅当第7位为0时才可操作(判别busy信号) }while(!(dat==0x00));}/*************************************写命令***********************************/void write_com(uchar com){checkbusy(); //检查是否忙rs=0; //写命令rw=0;P2=com;e=1;e=0;}/*************************************写数据***********************************/void write_data(uchar date){checkbusy(); //检查是否忙rs=1; //写数据rw=0;P2=date;e=1;e=0;}/*************************************显示汉字***********************************/void hanzi(uchar ye,uchar lie,uchar *daima){uchar i,j;for(i=0;i<2;i++){write_com(0xb8+ye+i); // ye页与ye+1页write_com(0x40+lie); //确定初始行for(j=0;j<16;j++){write_data(daima[i*16+j]); //写数据(汉字)}}}/*************************************显示数字***********************************/void shuzi(uchar ye,uchar lie,uchar *daima){uchar i,j;for(i=0;i<2;i++){write_com(0xb8+ye+i); // ye页与ye+1页write_com(0x40+lie); //确定初始行for(j=0;j<8;j++){write_data(daima[i*8+j]); //写数据(数字)}}}/***************************************清屏***************************************/void clearlcd(){uchar i,j;cs1=0; //清全屏有cs1=0 cs2=0 与无cs1=0 cs2=0 效果不同cs2=0;for(i=0;i<8;i++)write_com(0xb8+i);write_com(0x40);for(j=0;j<64;j++)write_data(0x00);}}/**************************************** 初始化LCD****************************************/ void init(){write_com(0x3e); //关显示delay(1);write_com(0x3f); //开显示write_com(0xc0); //行初始地址write_com(0xb8); //页初始地址write_com(0x40); //列初始地址}/**************************************** 显示数据****************************************/ void display()cs1=0; //左半屏cs1=0 cs2=1cs2=1;hanzi(0,0,qin);hanzi(0,16,mian);hanzi(0,32,li);hanzi(0,48,gong);cs1=1; //右半屏cs1=1 cs2=0cs2=0;hanzi(0,0,xue);hanzi(0,16,yuan);//hanzi(0,32,kongge); // 如果清屏时加上cs1=0 cs2=0则可以不用,否则要加上//hanzi(0,48,kongge);cs1=0;cs2=1;hanzi(2,0,dian);hanzi(2,16,zi);hanzi(2,32,gong);hanzi(2,48,cheng);cs1=1;cs2=0;hanzi(2,0,xue);hanzi(2,16,yuan);//hanzi(2,32,kongge);//hanzi(2,48,kongge); cs1=0;cs2=1;shuzi(4,0,ling); shuzi(4,8,ba);hanzi(4,16,tong); hanzi(4,32,xin); hanzi(4,48,gong);cs1=1;cs2=0;hanzi(4,0,cheng); shuzi(4,16,yi);hanzi(4,24,ban);//hanzi(4,40,kongge); shuzi(4,56,kong);cs1=0;cs2=1;hanzi(6,0,huo); hanzi(6,16,yun); hanzi(6,32,xie); hanzi(6,48,shen);cs1=1;cs2=0;//hanzi(6,0,kongge);//hanzi(6,16,kongge);//hanzi(6,32,kongge);//hanzi(6,48,kongge);}/**************************************** 主函数****************************************/ void main(){init();clearlcd();while(1){display();}}。

12864实例程序

12864实例程序

} /********************************************** 函数名称:LCD 初始化 函数功能; 出入参数: ************************************************/ void lcd_init() { write_cmd(0x30); //基本指令操作 delay_1ms(5); write_cmd(0x0c); //显示开,关光标 delay_1ms(5); write_cmd(0x01); //清除 LCD 的显示字符 delay_1ms(5); write_cmd(0x06); delay_1ms(5); } /********************************************** 函数名称:定时初始化 函数功能; 出入参数: ************************************************/ void init() { IE =0x8a; //=====1000 1010 开总中断, 启用 TF0.TF1 中断 TMOD=0X01; //=====0010 0001 T1 启用 mode2,T0 采用 mode1 TH0 =TH_M1; TL0 =TL_M1; //=====设置 T0 计数高 8 位,低 8 位 TR0 =1; //启动 T0 } /********************************************** 函数名称:主函数
PDF created with pdfFactory Pro trial version
uchar minutes=27; uchar seconds=0; /********************************************** 函数名称:延时函数 函数功能;1ms 出入参数: ************************************************/ void delay_1ms(uint x) { uint i,j; for(i=0;i<x;i++) for(j=0;j<110;j++); } /********************************************** 函数名称:写指令数据到 LCD 函数功能;RS=L;RW=L;E=高脉冲,D0-D7=指令码 出入参数: ************************************************/ void write_cmd(uchar cmd) { LCD_RS=0; LCD_RW=0; LCD_E=0; P0=cmd; delay_1ms(5); LCD_E=1; delay_1ms(5); LCD_E=0; } /********************************************** 函数名称:写显示数据到 LCD 函数功能;RS=H;RW=L;E=高脉冲,D0-D7=数据 出入参数: ************************************************/ void write_dat(uchar dat) { LCD_RS=1; LCD_RW=0; LCD_E=0; P0=dat; delay_1ms(5); LCD_E=1; delay_1ms(5); LCD_E=0;

学习笔记:12864液晶模块的详细使用

学习笔记:12864液晶模块的详细使用

学习笔记:12864液晶模块的详细使用备注:这篇文章是对12864操作的具体介绍,仅限刚接触12864的新手,大神请拍砖,文章写的较散,建议先参考12864手册及控制驱动器ST7920英文手册有个初步理解之后再阅读该篇文章,将会有更深的认识。

强烈建议阅读ST7920英文手册,细节内容里面有详细介绍,中文的12864也是从中译过来的。

本文分三个步骤介绍12864的内部资源原理,指令集详细讲解,以及应用例子。

对12864的所有操作概括起来有4种:1)、读忙状态(同时读出指针地址内容),初始化之后每次对12864的读写均要进行忙检测。

2)、写命令:所有的命令可以查看指令表,后续讲解指令的详细用法。

写地址也是写指令。

3)、写数据:操作对象有DDRAM、CGRAM、GDRAM。

4)、读数据:操作对象也是DDRAM、CGRAM、GDRAM。

对12864的学习首相要了解其内部资源,知道了它里面有哪些东西,你就可以更加方便的使用它。

先介绍几个英文的名字:DDRAM:(Data Display Ram),数据显示RAM,往里面写啥,屏幕就会显示啥。

CGROM:(Character Generation ROM),字符发生ROM。

里面存储了中文汉字的字模,也称作中文字库,编码方式有GB2312(中文简体)和BIG5(中文繁体)。

笔者使用的是育松电子的QC12864B,讲解以此为例。

CGRAM:(Character Generation RAM),字符发生RAM,,12864内部提供了64×2B的CGRAM,可用于用户自定义4个16×16字符,每个字符占用32个字节。

GDRAM:(Graphic Display RAM):图形显示RAM,这一块区域用于绘图,往里面写啥,屏幕就会显示啥,它与DDRAM的区别在于,往DDRAM中写的数据是字符的编码,字符的显示先是在CGROM中找到字模,然后映射到屏幕上,而往GDRAM中写的数据时图形的点阵信息,每个点用1bit来保存其显示与否。

STM8 Nucleo-64 板终端控制应用说明书

STM8 Nucleo-64 板终端控制应用说明书

AN5179应用笔记使用STM8 Nucleo-64板与终端进行RS232通信引言本应用笔记说明了如何从运行于PC上的终端窗口控制STM8 Nucleo-64板。

PC要通过RS232线连到STM8S208RBT6(对于NUCLEO-8S208RB)或STM8L152R8T6(对于NUCLEO-8L152R8)板的UART。

当为开发板添加了所需的元器件并下载应用软件后,用户将能够使用终端来管理STM8S系列或STM8L系列GPIO和TIM3定时器,以及配置蜂鸣器输出。

表 1. 适用产品参考文档•STM8 Nucleo-64板数据概述(DB3591)•STM8L152R8T6 Nucleo-64板用户手册(UM2351)•STM8S208RBT6 Nucleo-64板用户手册(UM2364)先决条件1先决条件运行STM8 Nucleo-64板终端演示应用所需的材料如下:•运行于PC上的终端窗口:终端模拟器软件可以是Windows HyperTerminal(请参见第附录 B 节附件B)、TeraTerm Pro或任何终端软件。

•RS232零调制解调器线(收发线交叉连接)。

配置 NUCLEO-8S208RB板2配置 NUCLEO-8S208RB板运行应用之前,必须配置NUCLEO-8S208RB板(基于STM8S208RBT6器件构建)以启用蜂鸣器输出。

蜂鸣器输出为STM8S208RBT6复用功能。

通过将OPT2选项字节中的复用功能重映射选项位AFR7设为‘1’来启用。

提示NUCLEO-8L152R8板(基于STM8L152R8T6器件构建)不需要用户检查或激活该复用功能或蜂鸣器。

3应用描述3.1硬件要求本应用使用STM8 Nucleo-64板的板上LED(LD2)及相关电阻(R1)。

应用所需的外部无源元件列表如下。

表 2. 无源元件列表该应用还使用一个5 V供电的ST232B RS232驱动器/接收器(请参见下表以获取更详细信息)。

12864串口程序

12864串口程序

12864串口程序#ifndef lcd12864_H#define lcd12864_H#includesbit SCLK=P2^4; //E :使能信号;串行时钟输入sbit SID=P2^5; //RW :读/写选择端:H 读; L 写; 串行数据线sbit CS=P2^6; //RS :寄存器选择端:H 数据; L 指令; 片选,低有效extern void LCDsendb(uint8 tdata) //一个发送8bit{uint8 i;for(i=0;i<8;i++){SID=tdata&0x80;tdata<<=1;_delay_us(1);SCLK=0;_delay_us(1);SCLK=1;_delay_us(1);}}extern void LCDsendcm(uint8 command) //写命令{CS=1;LCDsendb(0xf8);LCDsendb(command&0xf0);LCDsendb((command<<4)&0xf0);CS=0;}extern void LCDsendda(uint8 w_data) //写数据{CS=1;LCDsendb(0xfa);LCDsendb(w_data&0xf0);LCDsendb((w_data<<4)&0xf0);CS=0;}extern void outstr(uint8 *p) //输出字符串{while(*p>0)LCDsendda(*p++);}/*extern void LCDinch(uint32 num) //int转化为char {uint8 a[11]={'0'};int i=0;if(num==0) LCDsendda('0');while(num){a[i++]=num%10+48; num/=10;}while(i) LCDsendda(a[--i]);}*/extern void LCDflch(float number) //float转化为char { floatnum=number;uint8 a[11]={'0'};int i=0; uint32 num1;num1=(uint32)num;if(num1==0) LCDsendda('0');while(num1){a[i++]=num1%10+48; num1/=10;}while(i) LCDsendda(a[--i]);LCDsendda('.');LCDsendda((uint16)((uint32)(10*num)%10)+48);LCDsendda((uint16)((uint32)(100*num)%10)+48);LCDsendda((uint16)((uint32)(1000*num)%10)+48);LCDsendda((uint16)((uint32)(10000*num)%10)+48);}extern void LCDinit() //LCD12864初始化{_delay_ms(200);LCDsendcm(0x30); //选择基本指令集,选择8bit数据流_delay_us(1);LCDsendcm(0x0d); //开显示(有游标、反白)_delay_us(1);LCDsendcm(0x01); //清除显示,并且设定地址指针为00H _delay_ms(5);LCDsendcm(0x06); //设定游标的移动方向及指定显示的移位_delay_us(1);LCDsendcm(0x80);_delay_us(1);}#endif。

12864源程序

12864源程序

参考程序设计----------------------------------------------------------------------------------------------------------------------------------- #include <REGX52.H>#include<math.h>#include<INTRINS.H>#define Uchar unsigned char/*注:8031的晶振频率为12MHz*//***********液晶显示器接口引脚定义***************/sbit Elcm=P2^5;sbit CSALCM= P2^4;sbit CSBLCM= P2^3;sbit Dilcm=P2^7;sbit Rwlcm=P2^6;sfr Datalcm=0x80;/***********常用操作命令和参数定义***************/#define DISPON 0x3f /*显示on*/#define DISPOFF 0x3e /*显示off */#define DISPFIRST 0xc0 /*显示起始行定义*/#define SETX 0x40 /*X定位设定指令(页)*/#define SETY 0xb8 /*Y定位设定指令(列)*/#define Lcdbusy 0x80 /*LCM忙判断位*//**************显示分区边界位置*****************/#define MODR 0x80 /*中区和右区分界*/#define LCMLIMIT 0xC0 /*显示区的右边界*//****************全局变量定义*******************/Uchar col,row,cbyte; /*列x,行(页)y,输出数据*/bit xy,kkk,open,close=1,fail=0,fail1,shuigao ,shuidi,yaligao,yalidi,wendugao,wendudi, dingshi, outr,outg,outy,out,out1;/*画线方向标志:1水平*/sbit TSOR = P3^5;/*------------------------------------------全局变量-------------------------------------------------------*/static unsigned char temp1,temp2; //温度值的整数部分、小数部分/*------------------------------------------温度传感器驱动----------------------------------------------*/void Delay15();void Delay60();void Delay100ms();void Write0TS();void Write1TS();bit ReadTS();void ResetTS();void WriteByteTS(unsigned char byte);unsigned char ReadByteTS();void InitTS();void GetTempTS();//sbit P3_0=P3^0;//sbit P3_1=P3^1;//sbit P3_2=P3^2;//sbit P3_3=P3^3;unsigned char kkkk,kk2;unsigned char hour=0;unsigned char minute=0;unsigned char second=0;unsigned char hours1=0;unsigned char minutes1=0;unsigned char minutee1=30;unsigned char hours2=5;unsigned char minutes2=0;unsigned char houre2=7;unsigned char minutee2=30;unsigned char hours3=9;unsigned char houre3=11;unsigned char minutes3=0;unsigned char minutee3=30;unsigned char hours4=13;unsigned char houre4=15;unsigned char minutes4=0;unsigned char minutee4=30;unsigned char hours5=17;unsigned char minutes5=0;unsigned char houre5=19;unsigned char minutee5=30;unsigned char hours6=21;unsigned char houre6=22;unsigned char minutes6=0;unsigned char minutee6=0;unsigned char hours7=22;unsigned char houre7=23;unsigned char minutes7=30;unsigned char minutee7=30;unsigned char year= 01;unsigned char month=7;unsigned char day=25;unsigned char temp=23;unsigned char temph1=60;unsigned char templ1=40;unsigned char temph2=60;unsigned char templ2=40;unsigned char temph3=60;unsigned char templ3=40;unsigned char temph4=60;unsigned char templ4=40;unsigned char temph5=60;unsigned char templ5=40;unsigned char temph6=60;unsigned char templ6=40;unsigned char temph7=60;unsigned char templ7=40;unsigned char tempht=50;unsigned char templt=30;Uchar set=0;Uchar left=0;Uchar up=0;//记录定时器2的初始值,50msunsigned char time_H=0xffff-(50235/256); unsigned char time_L=0xffff-(50235%256); unsigned char time2count=0;//time2count count unsigned char kk;/*****************函数列表**********************/void Lcminit(void); /*液晶模块初始化*/void Delay(Uchar); /*延时,入口数为Ms */void lcdbusyM(void); /*busy判断、等待(中区)*/void lcdbusyR(void); /*busy判断、等待(右区)*///void Putedot(Uchar); /*半角字符输出*///void Putcdot(Uchar); /*全角(汉字)输出*/void Putcxydot(Uchar Order,Uchar a ,Uchar b,bit c);void Putexydot(Uchar Order,Uchar a ,Uchar b);void Wrdata(Uchar); /*数据输出给LCM*/void Lcmcls( void ); /*LCM全屏幕清零(填充0) */void wtcom(void); /*公用busy等待*/void Locatexy(void); /*光标定位*/void WrcmdM(Uchar); /*中区命令输出 */void WrcmdR(Uchar); /*右区命令输出 *///void Putstr(Uchar *puts,Uchar i); /*中英文字符串输出*///void Rollscreen(Uchar x); /*屏幕向上滚动*///void Rddata(void); /*从液晶片上读数据*/void Putshu(Uchar kk1,Uchar a,Uchar b,bit c);Uchar kbscan( ) ;void conv() ;Uchar start( );/******************数组列表*********************/Uchar code Ezk[]; /*ASCII常规字符点阵码表*/Uchar code Hzk[]; /*自用汉字点阵码表*/Uchar code STR1[]; /*自定义字符串*/Uchar code STR2[];Uchar code STR3[];Uchar code STR4[];//-----------------------------------------// 进0 //入1 //开2 //关3 //状4//态5// 定6 // 时7// 设8// 置9// 画10// 面11// 间12// 温13// 度14// 恢15// 复16// 出17// 厂18// 日19// 期20//年21//月22//段23//当24//前25//机26//故27//障28/****************************************主程序*****************************************/ void main(void){TSOR=1;//-------------------------定时器2设置TMOD=0x11;TH1=time_H;TL1=time_L;//初始化TH0=time_H;TL0=time_L;TR0=1;TR1=1;//定时器2开ET1=1;//time2 interrupt openET0=1;//----------------------------EA=1; //打开CPU总中断请求Delay(40);InitTS();Lcminit();/*键消抖的延时函数*///*将显示缓冲数组内容移到时、分计时单元*/while(1) {GetTempTS();temp=temp1;switch(set){case 0: Lcminit();while(set==0){///bit kk2,kk3,kk4,kk5 ;//if(left==0)kk2=1;else kk2=0;//if(left==1)kk3=1;else kk3=0;//if(left==2)kk4=1;else kk4=0;//if(left==3)kk5=1;else kk5=0;//Putcxydot(0,16,0,kk2); //*第一行字符输出,//Putcxydot(1,32,0,kk2); //进入开关状态//Putcxydot(2,48,0,kk2);////Putcxydot(3,64,0,kk2);//Putcxydot(4,80,0,kk2);//Putcxydot(5,96,0,kk2);// 进0 //入1 //开2 //关3 //状4//态5// 定6 // 时7// 设8// 置9// 画10// 面11// 间12// 温13// 度14// 恢15// 复16// 出17// 厂18// 日19// 期20//年21//月22//段23//当24//前25//机26//故27//障28//Putcxydot(0,16,2,kk3); //*第二行字符输出//Putcxydot(1,32,2,kk3); //进入定时状态//Putcxydot(6,48,2,kk3);//Putcxydot(7,64,2,kk3);//Putcxydot(4,80,2,kk3);//Putcxydot(5,96,2,kk3);//Putcxydot(0,16,4,kk4); //*第三行字符输出,///Putcxydot(1,32,4,kk4); //进入设置状态//Putcxydot(8,48,4,kk4);//Putcxydot(9,64,4,kk4);//Putcxydot(4,80,4,kk4);//Putcxydot(5,96,4,kk4);//Putcxydot(15,16,6,kk5); //*第四行字符输出///Putcxydot(16,32,6,kk5); //恢复出厂设置//Putcxydot(17,48,6,kk5);//Putcxydot(18,64,6,kk5);//Putcxydot(19,80,6,kk5);//Putcxydot(20,96,6,kk5);kk= hour; kk=kk/10; Putshu( kk ,0,0, 0);kk= hour; kk=kk%10; Putshu( kk ,8,0,0); Putexydot(26,16,0);//hourkk=minute; kk= kk/10; Putshu(kk,24,0,0);kk= minute; kk= kk%10; Putshu( kk,32,0,0 ); Putexydot(26,40,0);//minutekk= second; kk=kk/10; Putshu( kk,48,0 ,0);kk= second; kk=kk%10; Putshu( kk ,56,0,0);//secondkkkk= year; kk= 2; Putshu( kk,0,2,0 ); kk=0 ;Putshu( kk,8 ,2,0);kk= kkkk/10; Putshu( kk,16,2 ,0);//yearkk= kkkk%10;Putshu( kk,24,2,0 ); Putcxydot(21,32,2,0);kkkk= month; kk=kkkk/10; Putshu( kk,48,2,0);kk=kkkk%10; Putshu( kk,56,2,0 );Putcxydot(22,64,2,0);//monthPutcxydot(24,0,4,0);Putcxydot(25,16,4,0);Putcxydot(13,32,4,0);Putcxydot(14,48,4,0);kk= temp; kk=kk/10;Putshu( kk,72,4,0); kk= temp; kk=kk%10;Putshu( kk,80,4,0);Putexydot(35,88,4);kkk=dingshi;Putcxydot(6,96,4,kkk);Putcxydot(7,112,4,kkk);Putcxydot(24,0,6,0);Putcxydot(25,16,6,0); kkk=open;Putcxydot(2,32,6,kkk);Putcxydot(26,48,6,kkk);kkk=close;Putcxydot(3,64,6,kkk);Putcxydot(26,80,6,kkk);kkk=fail; Putcxydot(27,96,6,kkk);Putcxydot(28,112,6,kkk);// col=76;row=2; kk = key1; kk=kk/10; Putshu( kk );//key1//col=84; row=2; kk = key1; kk=kk%10; Putshu( kk );//key1//col=76; row=6; kk = STR4[0]; Putshu( kk );/*第四行字符输出,4字节*///col=84; row=6; kk = STR4[1]; Putshu( kk );//col=92; row=6; kk = STR4[2]; Putshu( kk );// col=100;row=6; kk = STR4[3]; Putshu( kk );//Putstr(STR4,4);};break;case 1: Lcminit(); //*液晶模块初始化,包括全屏幕清屏*/// 进0 //入1 //开2 //关3 //状4//态5// 定6 // 时7// 设8// 置9// 画10// 面11// 间12// 温13// 度14// 恢15// 复16// 出17// 厂18// 日19// 期20//年21//月22//段23//当24//前25//机26//故27//障28//通29//用30//参31//数32//水33//位34//过35//高36// 低37//压38//力39//查40//询41while(set==1){ bit kk2,kk3,kk4,kk5,kk6,kk7 ;kk2=shuigao;kk3=shuidi;kk4=yaligao;kk5=yalidi;kk6=wendugao;kk7=wendudi;Putcxydot(27,32,0,0);Putcxydot(28,48,0,0);Putcxydot(40,64,0,0);Putcxydot(41,80,0,0);Putcxydot(33,0,2,kk2);Putcxydot(34,16,2,kk2);Putcxydot(35,32,2,kk2);Putcxydot(36,48,2,kk2);Putcxydot(33,64,2,kk3);Putcxydot(34,80,2,kk3);Putcxydot(35,96,2,kk3);Putcxydot(37,112,2,kk3);Putcxydot(38,0,4,kk4);Putcxydot(39,16,4,kk4);Putcxydot(35,32,4,kk4);Putcxydot(36,48,4,kk4);Putcxydot(38,64,4,kk5);Putcxydot(39,80,4,kk5);Putcxydot(35,96,4,kk5);Putcxydot(37,112,4,kk5);Putcxydot(13,0,6,kk6);Putcxydot(14,16,6,kk6);Putcxydot(35,32,6,kk6);Putcxydot(36,48,6,kk6);Putcxydot(13,64,6,kk7);Putcxydot(14,80,6,kk7);Putcxydot(35,96,6,kk7);Putcxydot(37,112,6,kk7);}break;case 2: Lcminit();// 进0 //入1 //开2 //关3 //状4//态5// 定6 // 时7// 设8// 置9// 画10// 面11// 间12// 温13// 度14// 恢15// 复16// 出17// 厂18// 日19// 期20//年21//月22//段23//当24//前25//机26//故27//障28//通29//用30//参31//数32 while(set==2){//col=left2;row=4;Putstr(STR2,2);//col=0;row=0; Putcxydot(0,16,2);bit kk2,kk3,kk4,kk5,kk6,kk7,kk8;if(left==1)kk2=1;else kk2=0;if(left==0)kk3=1;else kk3=0;if(left==2)kk4=1;else kk4=0;if(left==3)kk5=1;else kk5=0;if(left==4)kk6=1;else kk6=0;if(left==5)kk7=1;else kk7=0;if(left==6)kk8=1;else kk8=0;kk= hour; kk=kk/10; Putshu( kk ,0,2, kk2);kk= hour; kk=kk%10; Putshu( kk ,8,2,kk2); Putexydot(26,16,2);//hourkk=minute; kk= kk/10; Putshu(kk,24,2,kk3);kk= minute; kk= kk%10; Putshu( kk,32,2,kk3 ); Putexydot(26,40,2);//minutekk= second; kk=kk/10; Putshu( kk,48,2 ,0);kk= second; kk=kk%10; Putshu( kk ,56,2,0);//secondPutcxydot(29,0,0,0);Putcxydot(30,16,0,0);Putcxydot(7,32,0,0);Putcxydot(12,48,0,0);Putcxydot(13,64,0,0);Putcxydot(14,80,0,0);Putcxydot(8,96,0,0);Putcxydot(9,112,0,0);// col=76;row=2; kk = key1; kk=kk/10; Putshu( kk );//key1//col=84; row=2; kk = key1; kk=kk%10; Putshu( kk );//key1//col=76; row=6; kk = STR4[0]; Putshu( kk );/*第四行字符输出,4字节*/ //col=84; row=6; kk = STR4[1]; Putshu( kk );//col=92; row=6; kk = STR4[2]; Putshu( kk );// col=100;row=6; kk = STR4[3]; Putshu( kk );//Putstr(STR4,4);// 进0 //入1 //开2 //关3 //状4//态5// 定6 // 时7// 设8// 置9// 画10// 面11// 间12// 温13// 度14// 恢15// 复16// 出17// 厂18// 日19// 期20//年21//月22//段23//当24//前25//机26//故27//障28//通29//用30//参31//数32//水33//位34//过35//高36kkkk= year; kk= 2; Putshu( kk,0,4,0 ); kk=0 ;Putshu( kk,8 ,4,0);kk= kkkk/10; Putshu( kk,16,4 ,kk6);//yearkk= kkkk%10;Putshu( kk,24,4,kk6 ); Putcxydot(21,32,4,0);kkkk= month; kk=kkkk/10; Putshu( kk,48,4,kk5);kk=kkkk%10; Putshu( kk,56,4,kk5 ); Putcxydot(22,64,4,0);//monthkkkk= day; kk=kkkk/10; Putshu( kk,80,4,kk4 );kk=kkkk%10;Putshu( kk,88,4,kk4);Putcxydot(19,96,4,0);//dayPutcxydot(13,0,6,0);Putcxydot(14,16,6,0);Putcxydot(31,32,6,0);Putcxydot(32,48,6,0);kk=tempht/10; Putshu( kk,64,6,kk7);kk=tempht%10;Putshu( kk,72,6,kk7);Putexydot(35,80,6); Putexydot(13,88,6);Putexydot(13,96,6);kk=templt/10;Putshu( kk,104,6,kk8);kk=templt%10;Putshu( kk,112,6,kk8);Putexydot(35,120,6);}break;case 3: Lcminit();while(set==3){bit kk2,kk3,kk4,kk5,kk6,kk7,kk8,kk9,kk10,kk11,kk12,kk13;if(left==0)kk2=1;else kk2=0;if(left==2)kk4=1;else kk4=0;if(left==3)kk5=1;else kk5=0;if(left==4)kk6=1;else kk6=0;if(left==5)kk7=1;else kk7=0;if(left==6)kk8=1;else kk8=0;if(left==7)kk9=1;else kk9=0;if(left==8)kk10=1;else kk10=0;if(left==9)kk11=1;else kk11=0;if(left==10)kk12=1;else kk12=0;if(left==11)kk13=1;else kk13=0;Putcxydot(0,0,0,0); //*第一行字符输出,/Putcxydot(1,16,0,0); //进入时段设置状态Putcxydot(7,32,0,0);Putcxydot(23,48,0,0);Putcxydot(8,64,0,0);Putcxydot(9,80,0,0);Putcxydot(4,96,0,0);Putcxydot(5,112,0,0);// 进0 //入1 //开2 //关3 //状4//态5// 定6 // 时7// 设8// 置9// 画10// 面11// 间12// 温13// 度14// 恢15// 复16// 出17// 厂18// 日19// 期20//年21//月22//段23//当24//前25//机26//故27//障28//水位过高Putcxydot(6,0,2,0); //*第二行字符输出Putcxydot(7,16,2,0); //进入定时A状态Putexydot(33,32,2);kk= hours1; kk=kk/10; Putshu( kk ,40,2, kk2);kk= hours1; kk=kk%10; Putshu( kk ,48,2,kk2); Putexydot(26,56,2);//hours1kk=minutes1; kk= kk/10;Putshu(kk,64,2,kk3);kk=minutes1; kk= kk%10;Putshu( kk,72,2,kk3 );Putexydot(13,80,2); //minutes1 kk= houre1; kk=kk/10; Putshu( kk ,88,2, kk4);kk= houre1; kk=kk%10; Putshu( kk ,96,2,kk4); Putexydot(26,104,2);//houre1kk=minutee1; kk= kk/10;Putshu(kk,112,2,kk5);kk=minutee1; kk= kk%10;Putshu( kk,120,2,kk5 ); //minutee1Putcxydot(6,0,4,0); //*第二行字符输出Putcxydot(7,16,4,0); //进入定时B状态Putexydot(34,32,4);kk= hours2; kk=kk/10; Putshu( kk ,40,4, kk6);kk= hours2; kk=kk%10; Putshu( kk ,48,4,kk6); Putexydot(26,56,4);//hours2kk=minutes2; kk= kk/10;Putshu(kk,64,4,kk7);kk=minutes2; kk= kk%10;Putshu( kk,72,4,kk7 );Putexydot(13,80,4); //minutes2 kk= houre2; kk=kk/10; Putshu( kk ,88,4, kk8);kk= houre2; kk=kk%10; Putshu( kk ,96,4,kk8); Putexydot(26,104,4);//houre2kk=minutee2; kk= kk/10;Putshu(kk,112,4,kk9);kk=minutee2; kk= kk%10;Putshu( kk,120,4,kk9 ); //minutee2Putcxydot(6,0,6,0); //*第二行字符输出Putcxydot(7,16,6,0); //进入定时C状态Putexydot(35,32,6);kk= hours3; kk=kk/10; Putshu( kk ,40,6, kk10);kk= hours3; kk=kk%10; Putshu( kk ,48,6,kk10); Putexydot(26,56,6);//hours2kk=minutes3; kk= kk/10;Putshu(kk,64,6,kk11);kk=minutes3; kk= kk%10;Putshu( kk,72,6,kk11 );Putexydot(13,80,6); //minutes2 kk= houre3; kk=kk/10; Putshu( kk ,88,6, kk12);kk= houre3; kk=kk%10; Putshu( kk ,96,6,kk12); Putexydot(26,104,6);//houre2kk=minutee3; kk= kk/10;Putshu(kk,112,6,kk13);}break;case 4: Lcminit();while(set==4){bit kk2,kk3,kk4,kk5,kk6,kk7,kk8,kk9,kk10,kk11,kk12,kk13,kk14,kk15,kk16,kk17; if(left==0)kk2=1;else kk2=0;if(left==1)kk3=1;else kk3=0;if(left==2)kk4=1;else kk4=0;if(left==3)kk5=1;else kk5=0;if(left==4)kk6=1;else kk6=0;if(left==5)kk7=1;else kk7=0;if(left==6)kk8=1;else kk8=0;if(left==7)kk9=1;else kk9=0;if(left==8)kk10=1;else kk10=0;if(left==9)kk11=1;else kk11=0;if(left==10)kk12=1;else kk12=0;if(left==11)kk13=1;else kk13=0;if(left==12)kk14=1;else kk14=0;if(left==13)kk15=1;else kk15=0;if(left==14)kk16=1;else kk16=0;if(left==15)kk17=1;else kk17=0;Putcxydot(6,0,0,0); //*第一行字符输出Putcxydot(7,16,0,0); //进入定时D状态Putexydot(36,32,0);kk= hours4; kk=kk/10; Putshu( kk ,40,0, kk2);kk= hours4; kk=kk%10; Putshu( kk ,48,0,kk2); Putexydot(26,56,0);//hours1kk=minutes4; kk= kk/10;Putshu(kk,64,0,kk3);kk=minutes4; kk= kk%10;Putshu( kk,72,0,kk3 );Putexydot(13,80,0); //minutes1kk= houre4; kk=kk/10; Putshu( kk ,88,0, kk4);kk= houre4; kk=kk%10; Putshu( kk ,96,0,kk4); Putexydot(26,104,0);//houre1kk=minutee4; kk= kk/10;Putshu(kk,112,0,kk5);kk=minutee4; kk= kk%10;Putshu( kk,120,0,kk5 ); //minutee1// 进0 //入1 //开2 //关3 //状4//态5// 定6 // 时7// 设8// 置9// 画10// 面11// 间12// 温13// 度14// 恢15// 复16// 出17// 厂18// 日19// 期20//年21//月22//段23//当24//前25//机26//故27//障28 Putcxydot(6,0,2,0); //*第二行字符输出Putcxydot(7,16,2,0); //进入定时E状态Putexydot(37,32,2);kk= hours1; kk=kk/10; Putshu( kk ,40,2, kk6);kk= hours1; kk=kk%10; Putshu( kk ,48,2,kk6); Putexydot(26,56,2);//hours1kk=minutes1; kk= kk/10;Putshu(kk,64,2,kk7);kk=minutes1; kk= kk%10;Putshu( kk,72,2,kk7 );Putexydot(13,80,2); //minutes1kk= houre1; kk=kk/10; Putshu( kk ,88,2, kk8);kk= houre1; kk=kk%10; Putshu( kk ,96,2,kk8); Putexydot(26,104,2);//houre1kk=minutee1; kk= kk/10;Putshu(kk,112,2,kk9);kk=minutee1; kk= kk%10;Putshu( kk,120,2,kk9 ); //minutee1Putcxydot(6,0,4,0); //*第三行字符输出Putcxydot(7,16,4,0); //进入定时F状态kk= hours2; kk=kk/10; Putshu( kk ,40,4, kk10);kk= hours2; kk=kk%10; Putshu( kk ,48,4,kk10); Putexydot(26,56,4);//hours2kk=minutes2; kk= kk/10;Putshu(kk,64,4,kk11);kk=minutes2; kk= kk%10;Putshu( kk,72,4,kk11 );Putexydot(13,80,4); //minutes2 kk= houre2; kk=kk/10; Putshu( kk ,88,4, kk12);kk= houre2; kk=kk%10; Putshu( kk ,96,4,kk12); Putexydot(26,104,4);//houre2 kk=minutee2; kk= kk/10;Putshu(kk,112,4,kk13);kk=minutee2; kk= kk%10;Putshu( kk,120,4,kk13 ); //minutee2Putcxydot(6,0,6,0); //*第四行字符输出Putcxydot(7,16,6,0); //进入定时G状态Putexydot(39,32,6);kk= hours3; kk=kk/10; Putshu( kk ,40,6, kk14);kk= hours3; kk=kk%10; Putshu( kk ,48,6,kk14); Putexydot(26,56,6);//hours2kk=minutes3; kk= kk/10;Putshu(kk,64,6,kk15);kk=minutes3; kk= kk%10;Putshu( kk,72,6,kk15 );Putexydot(13,80,6); //minutes2 kk= houre3; kk=kk/10; Putshu( kk ,88,6, kk16);kk= houre3; kk=kk%10; Putshu( kk ,96,6,kk16); Putexydot(26,104,6);//houre2 kk=minutee3; kk= kk/10;Putshu(kk,112,6,kk17);kk=minutee3; kk= kk%10;Putshu( kk,120,6,kk17 ); //minutee2};break;case 5: Lcminit();while(set==5)// 进0 //入1 //开2 //关3 //状4//态5// 定6 // 时7// 设8// 置9// 画10// 面11// 间12// 温13// 度14// 恢15// 复16// 出17// 厂18// 日19// 期20//年21//月22//段23//当24//前25//机26//故27//障28{bit kk2,kk3,kk4,kk5,kk6,kk7;if(left==0)kk2=1;else kk2=0;if(left==1)kk3=1;else kk3=0;if(left==2)kk4=1;else kk4=0;if(left==3)kk5=1;else kk5=0;if(left==4)kk6=1;else kk6=0;if(left==5)kk7=1;else kk7=0;// 进0 //入1 //开2 //关3 //状4//态5// 定6 // 时7// 设8// 置9// 画10// 面11// 间12// 温13// 度14// 恢15// 复16// 出17// 厂18// 日19// 期20//年21//月22//段23//当24//前25//机26//故27//障28 Putcxydot(0,0,0,0); //*第一行字符输出,/Putcxydot(1,16,0,0); //进入时段设置状态Putcxydot(6,32,0,0);Putcxydot(7,48,0,0);Putcxydot(7,64,0,0);Putcxydot(23,80,0,0);Putcxydot(8,96,0,0);Putcxydot(9,112,0,0);Putcxydot(6,0,2,0);Putcxydot(7,16,2,0);Putexydot(33,32,2);kk= temph1; kk=kk/10; Putshu( kk ,56,2, kk2);kk= temph1; kk=kk%10; Putshu( kk ,64,2, kk2);Putexydot(35,72,2); Putexydot(13,80,2); Putexydot(13,88,2);kk= templ1; kk=kk/10; Putshu( kk ,96,2, kk3);Putcxydot(6,0,4,0);Putcxydot(7,16,4,0);Putexydot(34,32,4);kk= temph2; kk=kk/10; Putshu( kk ,56,4, kk4);kk= temph2; kk=kk%10; Putshu( kk ,64,4, kk4);Putexydot(35,72,4);Putexydot(13,80,4); Putexydot(13,88,4);kk= templ2; kk=kk/10; Putshu( kk ,96,4, kk5);kk= templ2; kk=kk%10; Putshu( kk ,104,4, kk5);Putexydot(35,112,4);Putcxydot(6,0,6,0);Putcxydot(7,16,6,0);Putexydot(35,32,6);kk= temph3; kk=kk/10; Putshu( kk ,56,6, kk6);kk= temph3; kk=kk%10; Putshu( kk ,64,6, kk6);Putexydot(35,72,6);Putexydot(13,80,6); Putexydot(13,88,6);kk= templ3; kk=kk/10; Putshu( kk ,96,6, kk7);kk= templ3; kk=kk%10; Putshu( kk ,104,6, kk7);Putexydot(35,112,6);}break;case 6: Lcminit();while(set==6){bit kk2,kk3,kk4,kk5,kk6,kk7,kk8,kk9 ;if(left==0)kk2=1;else kk2=0;if(left==1)kk3=1;else kk3=0;if(left==2)kk4=1;else kk4=0;if(left==3)kk5=1;else kk5=0;if(left==4)kk6=1;else kk6=0;if(left==5)kk7=1;else kk7=0;if(left==6)kk8=1;else kk8=0;if(left==7)kk9=1;else kk9=0;Putcxydot(6,0,0,0);Putcxydot(7,16,0,0);Putexydot(36,32,0);kk= temph4; kk=kk/10; Putshu( kk ,56,0, kk2);kk= temph4; kk=kk%10; Putshu( kk ,64,0, kk2);Putexydot(35,72,0);Putexydot(13,80,0);Putexydot(13,88,0);kk= templ4; kk=kk/10; Putshu( kk ,96,0, kk3);kk= templ4; kk=kk%10; Putshu( kk ,104,0, kk3);Putexydot(35,112,0);// 进0 //入1 //开2 //关3 //状4//态5// 定6 // 时7// 设8// 置9// 画10// 面11// 间12// 温13// 度14// 恢15// 复16// 出17// 厂18// 日19// 期20//年21//月22//段23//当24//前25//机26//故27//障28//通29//用30 Putcxydot(6,0,2,0);Putcxydot(7,16,2,0);Putexydot(37,32,2);kk= temph5; kk=kk/10; Putshu( kk ,56,2, kk4);kk= temph5; kk=kk%10; Putshu( kk ,64,2, kk4);Putexydot(35,72,2);Putexydot(13,80,2);Putexydot(13,88,2);kk= templ5; kk=kk/10; Putshu( kk ,96,2, kk5);kk= templ5; kk=kk%10; Putshu( kk ,104,2, kk5);Putexydot(35,112,2);Putcxydot(6,0,4,0);Putcxydot(7,16,4,0);Putexydot(38,32,4);kk= temph6; kk=kk/10; Putshu( kk ,56,4, kk6);kk= temph6; kk=kk%10; Putshu( kk ,64,4, kk6);Putexydot(35,72,4);Putexydot(13,80,4);Putexydot(13,88,4);kk= templ6; kk=kk/10; Putshu( kk ,96,4, kk7);kk= templ6; kk=kk%10; Putshu( kk ,104,4, kk7);Putexydot(35,112,4);Putcxydot(6,0,6,0);Putcxydot(7,16,6,0);Putexydot(39,32,6);kk= temph7; kk=kk/10; Putshu( kk ,56,6, kk8);kk= temph7; kk=kk%10; Putshu( kk ,64,6, kk8);Putexydot(35,72,6);kk= templ7; kk=kk/10; Putshu( kk ,96,6, kk9);kk= templ7; kk=kk%10; Putshu( kk ,104,6, kk9);Putexydot(35,112,6); }break;}}}//{// Rollscreen(x); /*定位新的显示起始行*/// x++;// Delay(100); /*延时,控制滚动速度*/// Delay(100);// Delay(100);// Delay(100);// Delay(100);//Delay(100);//};//*********** 定时器2中断************void time1() interrupt 3 using 3{TF1=0;TH1=time_H;TL1=time_L;kbscan(); /*键扫描函数*/conv() ;time2count++;TR1=1;}//*********** 定时器0中断************void time0() interrupt 1 using 2{ TF0=0;TH0=0x10;TL0=0x10;start( );/*键扫描函数*/kbscan(); /*键扫描函数*/conv() ;TR0=1;}void conv(){if( time2count>=20){second++; time2count=0; }if(second>=60){minute++;second=0; }if(minute>=60){hour++;minute=0; }if(hour >=24){ hour =0; day++;}if(hours1>=24){ hours1=0; }if(minutes1>=60){ minutes1=0; }if(houre1>=24){ houre1=0; }if(minutes2>=60){ minutes2=0; }if(houre2>=24){ houre2=0; }if(minutee2>=60){ minutee2=0; }if(hours3>=24){ hours3=0; }if(minutes3>=60){ minutes3=0; }if(houre3>=24){ houre3=0; }if(minutee3>=60){ minutee3=0; }if(hours4>=24){ hours4=0; }if(minutes4>=60){ minutes4=0; }if(houre4>=24){ houre4=0; }if(minutee4>=60){ minutee4=0; }if(hours5>=24){ hours5=0; }if(minutes5>=60){ minutes5=0; }if(houre5>=24){ houre5=0; }if(minutee5>=60){ minutee5=0; }if(hours6>=24){ hours6=0; }if(minutes6>=60){ minutes6=0; }if(houre6>=24){ houre6=0; }if(minutee6>=60){ minutee6=0; }if(hours7>=24){ hours7=0; }if(minutes7>=60){ minutes7=0; }if(houre7>=24){ houre7=0; }if(minutee7>=60){ minutee7=0; }if(temph1>=90){ temph1=0; }if(templ1>=90){ templ1=0; }if(temph2>=90){ temph2=0; }if(templ2>=90){ templ2=0; }if(temph3>=90){ temph3=0; }if(templ3>=90){ templ3=0; }if(temph4>=90){ temph4=0; }if(templ4>=90){ templ4=0; }if(temph5>=90){ temph5=0; }if(templ5>=90){ templ5=0; }if(temph6>=90){ temph6=0; }if(templ6>=90){ templ6=0; }if(temph7>=90){ temph7=0; }if(templ7>=90){ templ7=0; }if(tempht>=90){ tempht=0; }if(templt>=90){ templt=0; }switch(month){case 1:if(day>31){month++;day=1;}break; case 2:if(day>28){month++;day=1;}break; case 3:if(day>31){month++;day=1;}break; case 4:if(day>30){month++;day=1;}break; case 5:if(day>31){month++;day=1;}break; case 6:if(day>30){month++;day=1;}break; case 7:if(day>31){month++;day=1;}break; case 8:if(day>31){month++;day=1;}break; case 9:if(day>30){month++;day=1;}break; case 10:if(day>31){month++;day=1;}break; case 11:if(day>30){month++;day=1;}break; case 12:if(day>31){month++;day=1;}break; default:break;}}/**************************************屏幕滚动定位*************************************/ //void Rollscreen(Uchar x)//{// cbyte = DISPFIRST|x; /*定义显示起始行为x?*///// WrcmdM(cbyte);// WrcmdR(cbyte);//}/**************************************一个字串的输出***********************************/ //void Putstr(Uchar *puts,Uchar i)// {// Uchar j,X;// for (j=0;j<i;j++)// {// X = puts[j];// if ((X&0x80)==0)// {// Putedot(X-0x20); /*ascii码表从0x20开始*/// }// else Putcdot(X);/*只保留低7位*/// }// }/*********************************半角字符点阵码数据输出********************************/ //void Putedot(Uchar Order)// {//Uchar i,bakerx,bakery; /*共定义4个局部变量*/// int x; /*偏移量,字符量少的可以定义为UCHAR */// bakerx = col; /*暂存x,y坐标,已备下半个字符使用*/// bakery = row;// x=Order * 0x10; /*半角字符,每个字符16字节*//*上半个字符输出,8列*/// for(i=0;i<8;i++)// {// cbyte = Ezk[x]; /*取点阵码,rom数组*/// Wrdata(cbyte); /*写输出一字节*/// x++;// col++;// if (col==LCMLIMIT){col=0;row++;row++;}; /*下一列,如果列越界换行*/// if (row>7) row=0; /*如果行越界,返回首行*/// } /*上半个字符输出结束*/// col = bakerx; /*列对齐*/// row = bakery+1; /*指向下半个字符行*//*下半个字符输出,8列*/// for(i=0;i<8;i++)// {// cbyte = Ezk[x]; /*取点阵码*/// Wrdata(cbyte); /*写输出一字节*/// x++;// if (row>7) row=1; /*如果行越界,返回首行*/// } /*下半个字符输出结束*/// row=bakery;// } /*整个字符输出结束*///--------------------------------- 字符半角字符点阵码数据输出-----------------------------------------------------void Putexydot(Uchar Order,Uchar a ,Uchar b){ Uchar i,bakerx,bakery; /*共定义4个局部变量*/int x; /*偏移量,字符量少的可以定义为UCHAR */col=a;row=b;bakerx = col; /*暂存x,y坐标,已备下半个字符使用*/bakery = row;x=Order * 0x10; /*半角字符,每个字符16字节*//*上半个字符输出,8列*/for(i=0;i<8;i++){cbyte = Ezk[x]; /*取点阵码,rom数组*/Wrdata(cbyte); /*写输出一字节*/x++;col++;if (col==LCMLIMIT){col=0;row++;row++;}; /*下一列,如果列越界换行*/if (row>7) row=0; /*如果行越界,返回首行*/} /*上半个字符输出结束*/col = bakerx; /*列对齐*/row = bakery+1; /*指向下半个字符行*//*下半个字符输出,8列*/for(i=0;i<8;i++){cbyte = Ezk[x]; /*取点阵码*/Wrdata(cbyte); /*写输出一字节*/x++;col++;if (col==LCMLIMIT){col=0;row=row+2;}; /*下一列,如果列越界换行*/if (row>7) row=1; /*如果行越界,返回首行*/} /*下半个字符输出结束*/row=bakery;} /*整个字符输出结束*//*********************************数字半角字符点阵码数据输出********************************/ void Putshu(Uchar kk1,Uchar a,Uchar b,bit c){Uchar i,bakerx,bakery; /*共定义4个局部变量*/int x; /*偏移量,字符量少的可以定义为UCHAR */col=a;row=b;bakerx = col; /*暂存x,y坐标,已备下半个字符使用*/bakery = row;x=(kk1+16) * 0x10; /*半角字符,每个字符16字节*//*上半个字符输出,8列*/for(i=0;i<8;i++){Wrdata(cbyte); /*写输出一字节*/x++;col++;if (col==LCMLIMIT){col=0;row++;row++;}; /*下一列,如果列越界换行*/if (row>7) row=0; /*如果行越界,返回首行*/} /*上半个字符输出结束*/col = bakerx; /*列对齐*/row = bakery+1; /*指向下半个字符行*//*下半个字符输出,8列*/for(i=0;i<8;i++){cbyte = Ezk[x]; /*取点阵码*/if(c==0)cbyte =cbyte ;else cbyte =~cbyte;Wrdata(cbyte); /*写输出一字节*/x++;col++;if (col==LCMLIMIT){col=0;row=row+2;}; /*下一列,如果列越界换行*/if (row>7) row=1; /*如果行越界,返回首行*/} /*下半个字符输出结束*/row=bakery;} /*整个字符输出结束*//*********************************全角字符点阵码数据输出********************************///void Putcdot(Uchar Order)// {// Uchar i,bakerx,bakery; /*共定义3个局部变量*/// int x; /*偏移量,字符量少的可以定义为UCHAR */// bakerx = col; /*暂存x,y坐标,已备下半个字符使用*/// bakery = row;// x=Order * 0x20; /*每个字符32字节*/// /*上半个字符输出,16列*/// for(i=0;i<16;i++)// {// Wrdata(Hzk[x]); /*写输出一字节*/// x++;// col++;// if (col==LCMLIMIT){ col=0;row++;row++;} /*下一列,如果列越界换行*/// if (row>6) row=0; /*如果行越界,返回首行*/// } /*上半个字符输出结束*//*下半个字符输出,16列*///col = bakerx;// row = bakery+1;// for(i=0;i<16;i++) /*下半部分*/// {// Wrdata(Hzk[x]);// x++;// col++;// if (col==LCMLIMIT){col=0;row++;row++;} /*下一列,如果列越界换行*/// if (row>7) row=1; /*如果行越界,返回首行*/// } /*下半个字符输出结束*/// row = bakery;// } /*整个字符输出结束*//*********************************全角字符点阵码数据位置输出********************************/ void Putcxydot(Uchar Order,Uchar a ,Uchar b,bit c){Uchar i,bakerx,bakery; /*共定义3个局部变量*/row=b;bakerx = col; /*暂存x,y坐标,已备下半个字符使用*/bakery = row;x=Order * 0x20; /*每个字符32字节*//*上半个字符输出,16列*/for(i=0;i<16;i++){cbyte =Hzk[x];if(c==0)cbyte =cbyte ;else cbyte =~cbyte;Wrdata(cbyte ); /*写输出一字节*/x++;col++;if (col==LCMLIMIT){ col=0;row++;row++;} /*下一列,如果列越界换行*/if (row>6) row=0; /*如果行越界,返回首行*/} /*上半个字符输出结束*//*下半个字符输出,16列*/col = bakerx;row = bakery+1;for(i=0;i<16;i++) /*下半部分*/{cbyte =Hzk[x];if(c==0)cbyte =cbyte ;else cbyte =~cbyte;Wrdata(cbyte );x++;col++;if (col==LCMLIMIT){col=0;row++;row++;} /*下一列,如果列越界换行*/if (row>7) row=1; /*如果行越界,返回首行*/} /*下半个字符输出结束*/row = bakery;} /*整个字符输出结束*//************************************清屏,全屏幕清零***********************************/ void Lcmcls( void ){for(row=0;row<8;row++)for(col=0;col<LCMLIMIT;col++) Wrdata(0);}/***************************从液晶片上读数据,保留在全局变量中***************************/ //void Rddata(void)//{// Locatexy(); /*坐标定位,返回时保留分区状态不变*/// Datalcm=0xFF;// Dilcm = 1; /*数据*/// Rwlcm = 1; /*读数据*/// Elcm = 1; /*读入到LCM*/// _nop_();// cbyte = Datalcm; /*虚读一次*/// Elcm = 0;// Locatexy(); /*坐标定位,返回时保留分区状态不变*/// Datalcm=0xFF;// _nop_();// Dilcm = 1; /*数据*/// Rwlcm = 1; /*读数据*/。

12864时钟显示程序

12864时钟显示程序

/************12864时钟显示函数*************//******实现时间走动、按键控制、蜂鸣器闹铃******/#include<reg52.h>#define uchar unsigned char //宏定义#define uint unsigned int //宏定义sbit rs=P0^7;sbit rw=P0^6;sbit en=P0^5;sbit beet=P0^4; //蜂鸣器定义sbit key1=P3^5; //功能选择sbit key2=P3^4; //至加sbit key3=P3^3; //至减char hour=23;char minute=59;char second=46;int years=2012;char month=12;char day=30;uchar count=0;char mm;char cc;uchar code table1[]={"创新工作室"};uchar code table2[]={" 应用电子"};/*************************延时函数****************************/ void delay(uint z){uint x,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}/*********地址初始化*************/void xieling_shu(uchar aa,uchar bb){if(aa==1){rs=0;}if(aa==0){rs=1;}rw=0;P2=bb;delay(1);en=1;delay(1);en=0;delay(1);}/***********************液晶12864写入地址*********************/ void xieludizhi(uchar x, uchar y){switch(x){case 1:xieling_shu(1,0x80 + y ); return;//return 返回的意思case 2:xieling_shu(1,0x90 + y ); return;case 3:xieling_shu(1,0x88 + y ); return;case 4:xieling_shu(1,0x98 + y ); return;}}/**********************液晶12864写入字符串********************/ void xiezifuchuan(uchar *dd){while(*dd != '\0'){xieling_shu(0,*dd++ );}}/********************** 液晶12864清屏函数*********************/ void qingping(){xieling_shu(1,0x01); //清屏xieling_shu(1,0x01); //清屏xieling_shu(1,0x01); //清屏delay(20);}/********************液晶12864初始化显示函数******************/ void init_12864(){ mm=0;cc=7; //选择星期初始化xieling_shu(1,0x30); //基本指令操作xieling_shu(1,0x30); //基本指令操作xieling_shu(1,0x0C); //0x0c: 无光标,OXOF: 光标反白显示xieling_shu(1,0x01); //清屏xieling_shu(1,0x06);}/******************* 液晶12864初始化字串显示******************/ void init_zifu(){//qingping();xieludizhi(1,0);xiezifuchuan(table1); //delay(1);xieludizhi(4,0);xiezifuchuan(table2); //delay(1);xieludizhi(3,0);xieling_shu(0,0x30+hour/10);xieling_shu(0,0x30+hour%10);xieling_shu(0,':');xieling_shu(0,0x30+minute/10);xieling_shu(0,0x30+minute%10);xieling_shu(0,':');xieling_shu(0,0x30+second/10);xieling_shu(0,0x30+second%10);xieludizhi(3,5);xiezifuchuan("星期");xieludizhi(2,0);xieling_shu(0,0x30+years/1000);xieling_shu(0,0x30+years%1000/100);xieling_shu(0,0x30+years%100/10);xieling_shu(0,0x30+years%10);xiezifuchuan("年");xieling_shu(0,0x30+month/10);xieling_shu(0,0x30+month%10);xiezifuchuan("月");xieling_shu(0,0x30+day/10);xieling_shu(0,0x30+day%10);xiezifuchuan("日");}/***************星期函数***************/void xingqi(){switch(cc){case 1: xieludizhi(3,7); xiezifuchuan("一"); return;case 2: xieludizhi(3,7); xiezifuchuan("二"); return;case 3: xieludizhi(3,7); xiezifuchuan("叁"); return;case 4: xieludizhi(3,7); xiezifuchuan("四"); return;case 5: xieludizhi(3,7); xiezifuchuan("五"); return;case 6: xieludizhi(3,7); xiezifuchuan("六"); return;case 7: xieludizhi(3,7); xiezifuchuan("日"); return;}}/***************按键程序***************/void anjian(){if(key1==0) //key1按键选择功能{ mm++;delay(1);if(mm==1){xieludizhi(3,3);xieling_shu(0,0x5f);}if(mm==2){TR0=1;xieludizhi(3,2);xieling_shu(0,0x5f);}if(mm==3){xieludizhi(3,0);xieling_shu(0,0x5f);}if(mm==4){xieludizhi(2,5);xieling_shu(0,0x5f);}if(mm==5){xieludizhi(2,3);xieling_shu(0,0x5f);}if(mm==6){xieludizhi(2,1);xieling_shu(0,0x5f);}if(mm==7){xieludizhi(3,5);xieling_shu(0,0x5f);}if(mm==8){xieludizhi(2,7);xieling_shu(0,0x02);}if(mm==9){xieludizhi(2,7);xieling_shu(1,0x01);mm=0;}} //key2按键控制if(mm==1&&key2==0) //秒加1{TR0=0;delay(1);if(key2==0){second++;if(second==60){second=0;}}}if(mm==1&&key3==0) //秒减1{TR0=0;delay(1);if(key3==0){second--;if(second==-1){second=59;}}}if(mm==2&&key2==0) //分加1 { delay(1);if(key2==0){minute++;if(minute==60){minute=0;}}}if(mm==2&&key3==0) //分减1 { delay(1);if(key3==0){minute--;if(minute==-1){minute=59;}}}if(mm==3&&key2==0) //时加1 { delay(1);if(key2==0){hour++;if(hour==24){hour=0;}}}if(mm==3&&key3==0) //时减1 { delay(1);if(key3==0){hour--;if(hour==-1){hour=23;}}}if(mm==4&&key2==0) //日加1 { delay(1);if(key2==0){day++;if(day==31){day=1;}}}if(mm==4&&key3==0) //日减1 { delay(1);if(key3==0){day--;if(day==0){day=30;}}}if(mm==5&&key2==0) //月加1 { delay(1);if(key2==0){month++;if(month==13){month=1;}}}if(mm==5&&key3==0) //月减1 { delay(1);if(key3==0){month--;if(month==0){month=12;}}}if(mm==6&&key2==0) //年加1 { delay(1);if(key2==0){years++;}}if(mm==6&&key3==0) //年减1 { delay(1);if(key3==0){years--;}}if(mm==7&&key2==0) //星期加1 { delay(1);if(key2==0){cc++;if(cc==8){cc=1;}}}if(mm==7&&key3==0) //星期减1 { delay(1);if(key3==0){cc--;if(cc==0){cc=7;}}}}/***************************定时器函数************************/void init_t0_t1() //定时器t0,t1初始化函数{TMOD=0x11;EA=1;ET0=1;TR0=1; //开启中断TH0=(65536-50000)/256;TL0=(65536-50000)%256;}/**************主函数**************/void main(){init_12864();init_t0_t1();while(1){init_zifu();anjian();xingqi();}}/***************中断函数***************/void time() interrupt 1{TH0=(65536-50000)/256;TL0=(65536-50000)%256;if(hour==0&minute==0&second==0||hour==0&minute==1&second==0||hour==0&minute==1&s econd==5)//采用与或逻辑设定闹铃{beet=0;delay(5);beet=1;}count++;if(count==20){count=0;second++;}if(second==60){second=0;minute++;}if(minute==60){minute=0;hour++;}if(hour==24){hour=0;day++;cc++;if(cc==8){cc=1;}}if(day==31){day=1;month++;}if(month==13){month=1;years++;}}。

12864菜单程序修改版

12864菜单程序修改版

12864多级菜单设计作者董新凯#include <hidef.h> /* for EnableInterrupts macro */#include "derivative.h" /* include peripheral declarations */#include "init.h"#define UINT8 unsigned char#define UINT16 unsigned int#define D_RS PTCD_PTCD4#define D_RW PTFD_PTFD4#define D_E PTCD_PTCD0#define D_L PTCD_PTCD1 //左右半屏选择#define D_R PTCD_PTCD2#define D_REST PTFD_PTFD5 //复位选择#define LED1 PTCD_PTCD5#define LED2 PTCD_PTCD6#define LED3 PTCD_PTCD7#define LED4 PTFD_PTFD6#define LED5 PTFD_PTFD3/******************菜单填充**************/# define FillType_Fill 0x01 //填充黑色# define FillType_Clear 0x00 //填充白色const UINT8 zimo[][32]={/*-- 文字: 菜0 --*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/{0x04,0x04,0x44,0xC4,0x4F,0x44,0x44,0xC4,0x24,0x24,0x2F,0xB4,0x24,0x04,0x04,0x00, 0x40,0x44,0x24,0x24,0x15,0x0C,0x04,0xFE,0x04,0x0C,0x15,0x24,0x24,0x44,0x40,0x00, },/*-- 文字: 单 1 --*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/{0x00,0x00,0xF8,0x49,0x4A,0x4C,0x48,0xF8,0x48,0x4C,0x4A,0x49,0xF8,0x00,0x00,0x00, 0x10,0x10,0x13,0x12,0x12,0x12,0x12,0xFF,0x12,0x12,0x12,0x12,0x13,0x10,0x10,0x00, },/*-- 文字: 一2--*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/{0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, },/*-- 文字: 二3--*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/{0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,0x00, 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00, },/*-- 文字: 三4--*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/{0x00,0x04,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x04,0x00,0x00, 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00, },/*-- 文字: 四5--*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/{0x00,0xFC,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0xFC,0x00,0x00, 0x00,0x7F,0x28,0x24,0x23,0x20,0x20,0x20,0x20,0x21,0x22,0x22,0x22,0x7F,0x00,0x00, },/*-- 文字: 是6--*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/{0x00,0x00,0x00,0x7F,0x49,0x49,0x49,0x49,0x49,0x49,0x49,0x7F,0x00,0x00,0x00,0x00, 0x81,0x41,0x21,0x1D,0x21,0x41,0x81,0xFF,0x89,0x89,0x89,0x89,0x89,0x81,0x81,0x00, },/*-- 文字: 否7--*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/{0x00,0x02,0x82,0x82,0x42,0x22,0x12,0xFA,0x06,0x22,0x22,0x42,0x42,0x82,0x00,0x00, 0x01,0x01,0x00,0xFC,0x44,0x44,0x44,0x45,0x44,0x44,0x44,0xFC,0x00,0x00,0x01,0x00, }};UINT8 Menu_word[][4]={{0,1,2},{0,1,3},{0,1,4},{0,1,5}} ;struct MenuItem{ //菜单结构UINT8 MenuCount;//菜单项所在层的菜单项数目UINT8 *DisplayString;//显示的名称void (*subs)(void);//所指向的功能函数UINT8 Local_x;UINT8 Local_y;//菜单的横纵起始坐标struct MenuItem *ChildrenMenu;//所指向的子菜单struct MenuItem *ParentMenu;//所指向的父菜单struct MenuItem *This;//Thi s指针指向本项菜单1行地址};/*****************************************/struct MenuItem MainMenu[4];struct MenuItem ChildMenu1[3];struct MenuItem ChildMenu2[3];struct MenuItem ChildMenu3[3];struct MenuItem ChildMenu4[3];struct MenuItem SubChildMenu1;struct MenuItem SubChildMenu2;struct MenuItem SubChildMenu3;/*****************菜单状态储存数组*************************/ struct Menu_stat{UINT8 current_stat; //当前状态位UINT8 down_stat; //下状态位UINT8 up_stat; //上状态位UINT8 esc_stat; //返回状态位UINT8 enter_stat; //确定状态位struct MenuItem *Menu_pointer;//指向菜单结构的指针};const struct Menu_stat Menu_table[]=/************************************///1~4主菜单//5,8,11,14次级菜单//17~28三级菜单{{0,1,4,1,0,&MainMenu[0]},{1,2,4,1,5,&MainMenu[0] //0 },{2,3,1,2,8,&MainMenu[1] //1 },{3,4,2,3,11,&MainMenu[2] //2 },{4,1,3,4,14,&MainMenu[3] //3 },{5,6,7,1,17,&ChildMenu1[0]//4 },{6,7,5,1,18,&ChildMenu1[1]//5 },{7,5,6,1,19,&ChildMenu1[2]//6 },{8,9,10,2,20,&ChildMenu2[0] },{9,10,8,2,21,&ChildMenu2[1] },{10,8,9,2,22,&ChildMenu2[2] },{11,12,13,3,23,&ChildMenu3[0] },{12,13,11,3,24,&ChildMenu3[1] },{13,11,12,3,25,&ChildMenu3[2] },14,15,16,4,26,&ChildMenu4[0] },{15,16,14,4,27,&ChildMenu4[1] },{16,14,15,4,28,&ChildMenu4[2] },{17,17,17,5,17,&SubChildMenu1 },{18,18,18,6,18,&SubChildMenu2 },{19,19,19,7,19,&SubChildMenu3 },{20,20,20,8,20,&SubChildMenu1 },{21,21,21,9,21,&SubChildMenu2 },{22,22,22,10,22,&SubChildMenu3 },{23,23,23,11,23,&SubChildMenu1 },{24,24,24,12,24,&SubChildMenu2 },{25,25,25,13,25,&SubChildMenu3 },{26,26,26,14,26,&SubChildMenu1 },{27,27,27,15,27,&SubChildMenu2 },{28,28,28,16,28,&SubChildMenu3};/**********************************************************/ struct MenuItem *Menu_point=NULL;UINT8 key_number=0;UINT8 key_number_store=0;/**********************************************************/ void _12864_busycheck(void);void _12864_wr_cmd(UINT8 cmd);void _12864_clear_dot(UINT8 x,UINT8 y);void delay(UINT16 time){UINT16 i;for(i=0;i<time;i++);}/****************菜单初始化******************/void MainMenu_init(void){MainMenu[0].MenuCount=4;MainMenu[0].DisplayString=&Menu_word[0][0];MainMenu[0].subs=NULL;MainMenu[0].Local_x=5;MainMenu[0].Local_y=0;MainMenu[0].ChildrenMenu=ChildMenu1;MainMenu[0].ParentMenu=NULL;MainMenu[0].This=MainMenu;MainMenu[1].MenuCount=4;MainMenu[1].DisplayString=&Menu_word[1][0];MainMenu[1].subs=NULL;MainMenu[1].Local_x=5;MainMenu[1].Local_y=0;MainMenu[1].ChildrenMenu=ChildMenu2;MainMenu[1].ParentMenu=NULL;MainMenu[1].This=MainMenu;MainMenu[2].MenuCount=4;MainMenu[2].DisplayString=&Menu_word[2][0];MainMenu[2].subs=NULL;MainMenu[2].Local_x=5;MainMenu[2].Local_y=0;MainMenu[2].ChildrenMenu=ChildMenu3;MainMenu[2].ParentMenu=NULL;MainMenu[2].This=MainMenu;MainMenu[3].MenuCount=4;MainMenu[3].DisplayString=&Menu_word[3][0];MainMenu[3].subs=NULL;MainMenu[3].Local_x=5;MainMenu[3].Local_y=0;MainMenu[3].ChildrenMenu=ChildMenu4;MainMenu[3].ParentMenu=NULL;MainMenu[3].This=MainMenu;}void ChildMenu1_init(void){ChildMenu1[0].MenuCount=3;ChildMenu1[0].DisplayString=&Menu_word[0][0];ChildMenu1[0].subs=NULL;ChildMenu1[0].Local_x=43;ChildMenu1[0].Local_y=0;ChildMenu1[0].ChildrenMenu=&SubChildMenu1;ChildMenu1[0].ParentMenu=MainMenu;ChildMenu1[0].This=ChildMenu1;ChildMenu1[1].MenuCount=3;ChildMenu1[1].DisplayString=&Menu_word[1][0];ChildMenu1[1].subs=NULL;ChildMenu1[1].Local_x=43;ChildMenu1[1].Local_y=0;ChildMenu1[1].ChildrenMenu=&SubChildMenu2;ChildMenu1[1].ParentMenu=MainMenu;ChildMenu1[1].This=ChildMenu1;ChildMenu1[2].MenuCount=3;ChildMenu1[2].DisplayString=&Menu_word[2][0];ChildMenu1[2].subs=NULL;ChildMenu1[2].Local_x=43;ChildMenu1[2].Local_y=0;ChildMenu1[2].ChildrenMenu=&SubChildMenu3;ChildMenu1[2].ParentMenu=MainMenu;ChildMenu1[2].This=ChildMenu1;}void ChildMenu2_init(void){ChildMenu2[0].MenuCount=3;ChildMenu2[0].DisplayString=&Menu_word[0][0];ChildMenu2[0].subs=NULL;ChildMenu2[0].Local_x=43;ChildMenu2[0].Local_y=16;ChildMenu2[0].ChildrenMenu=&SubChildMenu1;ChildMenu2[0].ParentMenu=MainMenu;ChildMenu2[0].This=ChildMenu2;ChildMenu2[1].MenuCount=3;ChildMenu2[1].DisplayString=&Menu_word[1][0];ChildMenu2[1].subs=NULL;ChildMenu2[1].Local_x=43;ChildMenu2[1].Local_y=16;ChildMenu2[1].ChildrenMenu=&SubChildMenu2;ChildMenu2[1].ParentMenu=MainMenu;ChildMenu2[1].This=ChildMenu2;ChildMenu2[2].MenuCount=3;ChildMenu2[2].DisplayString=&Menu_word[2][0];ChildMenu2[2].subs=NULL;ChildMenu2[2].Local_x=43;ChildMenu2[2].Local_y=16;ChildMenu2[2].ChildrenMenu=&SubChildMenu3;ChildMenu2[2].ParentMenu=MainMenu;ChildMenu2[2].This=ChildMenu2;}void ChildMenu3_init(void){ChildMenu3[0].MenuCount=3;ChildMenu3[0].DisplayString=&Menu_word[0][0];ChildMenu3[0].subs=NULL;ChildMenu3[0].Local_x=43;ChildMenu3[0].Local_y=0;ChildMenu3[0].ChildrenMenu=&SubChildMenu1;ChildMenu3[0].ParentMenu=MainMenu;ChildMenu3[0].This=ChildMenu3;ChildMenu3[1].MenuCount=3;ChildMenu3[1].DisplayString=&Menu_word[1][0];ChildMenu3[1].subs=NULL;ChildMenu3[1].Local_x=43;ChildMenu3[1].Local_y=0;ChildMenu3[1].ChildrenMenu=&SubChildMenu2;ChildMenu3[1].ParentMenu=MainMenu;ChildMenu3[1].This=ChildMenu3;ChildMenu3[2].MenuCount=3;ChildMenu3[2].DisplayString=&Menu_word[2][0];ChildMenu3[2].subs=NULL;ChildMenu3[2].Local_x=43;ChildMenu3[2].Local_y=0;ChildMenu3[2].ChildrenMenu=&SubChildMenu3;ChildMenu3[2].ParentMenu=MainMenu;ChildMenu3[2].This=ChildMenu3;}void ChildMenu4_init(void){ChildMenu4[0].MenuCount=3;ChildMenu4[0].DisplayString=&Menu_word[0][0];ChildMenu4[0].subs=NULL;ChildMenu4[0].Local_x=43;ChildMenu4[0].Local_y=16;ChildMenu4[0].ChildrenMenu=&SubChildMenu1;ChildMenu4[0].ParentMenu=MainMenu;ChildMenu4[0].This=ChildMenu4;ChildMenu4[1].MenuCount=3;ChildMenu4[1].DisplayString=&Menu_word[1][0];ChildMenu4[1].subs=NULL;ChildMenu4[1].Local_x=43;ChildMenu4[1].Local_y=16;ChildMenu4[1].ChildrenMenu=&SubChildMenu2;ChildMenu4[1].ParentMenu=MainMenu;ChildMenu4[1].This=ChildMenu4;ChildMenu4[2].MenuCount=3;ChildMenu4[2].DisplayString=&Menu_word[2][0];ChildMenu4[2].subs=NULL;ChildMenu4[2].Local_x=43;ChildMenu4[2].Local_y=16;ChildMenu4[2].ChildrenMenu=&SubChildMenu3;ChildMenu4[2].ParentMenu=MainMenu;ChildMenu4[2].This=ChildMenu4;}void SubChildMenu1_init(void){SubChildMenu1.MenuCount=1;SubChildMenu1.DisplayString=&Menu_word[0][0];SubChildMenu1.subs=NULL;SubChildMenu1.Local_x=79;SubChildMenu1.Local_y=0;SubChildMenu1.ChildrenMenu=NULL;SubChildMenu1.ParentMenu=ChildMenu1;SubChildMenu1.This=&SubChildMenu1;SubChildMenu2.MenuCount=1;SubChildMenu2.DisplayString=&Menu_word[0][0];SubChildMenu2.subs=NULL;SubChildMenu2.Local_x=79;SubChildMenu2.Local_y=16;SubChildMenu2.ChildrenMenu=NULL;SubChildMenu2.ParentMenu=ChildMenu1;SubChildMenu2.This=&SubChildMenu2;SubChildMenu3.MenuCount=1;SubChildMenu3.DisplayString=&Menu_word[0][0];SubChildMenu3.subs=NULL;SubChildMenu3.Local_x=79;SubChildMenu3.Local_y=32;SubChildMenu3.ChildrenMenu=NULL;SubChildMenu3.ParentMenu=ChildMenu1;SubChildMenu3.This=&SubChildMenu3;}/*****************键盘*******************/ UINT8 keyscan(void){UINT8 i,j,temp;PTFD|=0x07; //PTF xxxx x111for(i=0;i<3;i++){PTFD &= ~(1<<i);temp=0x04;for(j=0;j<3;j++){if(!(PTGD&temp)){delay(10);if(!(PTGD&temp)){return (i*3+j+1);}}temp <<= 1;}PTFD|=0x07;}return 0;}/****************读状态*******************/UINT8 _12864_rd_stat(void){UINT8 volatile temp;PTBDD=0X00;D_RS=0;D_RW=1;D_E=1;delay(1);temp=PTBD;delay(1);D_E=0;return temp;}/*******************读数据******************/UINT8 _12864_rd_data(UINT8 page,UINT8 colum,UINT8 D_LorR) {UINT8 volatile data;_12864_busycheck();if(D_LorR){D_L=0;D_R=1;}else{D_L=1;D_R=0;}_12864_wr_cmd(0xb8+page);_12864_wr_cmd(0x40+colum);PTBDD=0X00;D_RS=1;D_RW=1;D_E=1;delay(5);data=PTBD;delay(10);D_E=0;return data;}/*******************忙检测**********************/void _12864_busycheck(void){PTBDD=0x00;D_RS=0;D_RW=1;D_E=1;while(_12864_rd_stat()==0x80);D_E=0;}/****************写指令********************/void _12864_wr_cmd(UINT8 cmd){_12864_busycheck();PTBDD=0XFF;D_RS=0;D_RW=0;D_E=1;delay(10);PTBD=cmd;delay(10);D_E=0;}/*****************写数据*****************/void _12864_wr_data(UINT8 page,UINT8 colum,UINT8 D_LorR,UINT8 data) {_12864_busycheck();if(D_LorR){D_L=0;D_R=1;}else{D_L=1;D_R=0;}_12864_wr_cmd(0xb8+page);_12864_wr_cmd(0x40+colum);PTBDD=0XFF;D_RS=1;D_RW=0;D_E=1;delay(5);PTBD=data;delay(10);D_E=0;}void _12864_wr_data_notclear(UINT8 page,UINT8 colum,UINT8 D_LorR,UINT8 data) {UINT8 temp;_12864_busycheck();if(D_LorR){D_L=0;D_R=1;}else{D_L=1;D_R=0;}(void)_12864_rd_data(page,colum,D_LorR);temp=_12864_rd_data(page,colum,D_LorR);data=data|temp;_12864_wr_cmd(0xb8+page);_12864_wr_cmd(0x40+colum);PTBDD=0XFF;D_RS=1;D_RW=0;D_E=1;delay(5);PTBD=data;delay(10);D_E=0;}/*****************清屏********************/void _12864_clear_lcdall(void){UINT8 i,j;for(i=0;i<8;i++){for(j=0;j<64;j++){_12864_wr_data(i,j,0,0x00);_12864_wr_data(i,j,1,0x00);}}}void _12864_clear_lcd(UINT8 xbegin,UINT8 ybegin,UINT8 xend,UINT8 yend) {UINT8 x,y,pages,pagee,D_LorR,temp;if(xbegin>=xend){temp=xbegin;xbegin=xend;xend=temp;}if(ybegin>=yend){temp=ybegin;ybegin=yend;yend=temp;}if(xend>127)xend=127;if(yend>63)yend=63;pages=ybegin>>3;pagee=yend>>3;for(x=pages;x<=pagee;x++){for(y=xbegin;y<=xend;y++){if(y>63){D_LorR=1;_12864_wr_data(x,y-64,D_LorR,0x00);}else{D_LorR=0;_12864_wr_data(x,y,D_LorR,0x00);}}}}/*****************清除一个点******************/void _12864_clear_dot(UINT8 x,UINT8 y){UINT8 page,row;UINT8 data;if(x<=63){page=y/8;row=y%8;(void)_12864_rd_data(page,x,0);data=_12864_rd_data(page,x,0);data=data&(~(0x01<<row));_12864_wr_data(page,x,0,data);}else{page=y/8;row=y%8;(void)_12864_rd_data(page,x-64,1);data=_12864_rd_data(page,x-64,1);data=data&(~(0x01<<row));_12864_wr_data(page,x-64,1,data);}}/**********************画一个点*********************/ void _12864_write_dot(UINT8 x,UINT8 y){UINT8 page,row;volatile UINT8 data;if(x<=63){page=y/8;row=y%8;delay(5);(void)_12864_rd_data(page,x,0);data=_12864_rd_data(page,x,0);data=data|(0x01<<row);_12864_wr_data(page,x,0,data);}else{page=y/8;row=y%8;delay(5);(void)_12864_rd_data(page,x-64,1);data=_12864_rd_data(page,x-64,1);data=data|(0x01<<row);_12864_wr_data(page,x-64,1,data);}}/*****************初始化*********************/void _12864_init(void){D_REST=1;D_L=1;D_R=1;_12864_wr_cmd(0xc0);_12864_wr_cmd(0x3f);}/******************io封装*****************/void io_keyscan(void){PTGPE=0x1c;PTFDD=0xff;}void io_12864(void){PTBDD=0XFF;PTCDD_PTCDD0=1;PTCDD_PTCDD1=1;PTCDD_PTCDD2=1;PTCDD_PTCDD4=1;PTFDD_PTFDD4=1;PTFDD_PTFDD5=1;}/******************画线函数****************/void _12864_glibline(UINT8 x1,UINT8 y1,UINT8 x2,UINT8 y2){int dx,dy,sub;dx=x2-x1;dy=y2-y1;if(dx>=0){if(dy>=0){if(dx>=dy)//1/8{sub=2*dy-dx;while(x1<x2){_12864_write_dot(x1,y1);if(sub>0){y1+=1;sub+=(dy-dx)*2;}else{sub+=2*dy;}x1+=1;}}else //2/8{sub=2*dx-dy;while(y1<y2){_12864_write_dot(x1,y1);if(sub>0){x1+=1;sub+=(dx-dy)*2;}else{sub+=2*dx;}y1+=1;}}}else{dy=-dy;if(dx>=dy){sub=2*dy-dx;while(x1<x2){_12864_write_dot(x1,y1);if(sub>0){y1-=1;sub+=(dy-dx)*2;}else{sub+=2*dy;}x1+=1;}}else{sub=2*dx-dy;while(y1>y2){_12864_write_dot(x1,y1);if(sub>0){x1+=1;sub+=(dx-dy)*2;}else{sub+=dx*2;}y1-=1;}}}}else{dx=-dx;if(dy>0){if(dx>dy){sub=2*dy-dx;while(x1>x2){_12864_write_dot(x1,y1);if(sub>0){y1+=1;sub+=(dy-dx)*2;}else{sub+=2*dy;}x1-=1;}}else{sub=2*dx-dy;while(y1<y2){_12864_write_dot(x1,y1);if(sub>0){x1-=1;sub+=(dx-dy)*2;}else{sub+=dx*2;}y1+=1;}}}else{dy=-dy;if(dx>dy){sub=2*dy-dx;while(x1>x2){_12864_write_dot(x1,y1);if(sub>0){y1-=1;sub+=(dy-dx)*2;}else{sub+=dy*2;}}}else{sub=2*dx-dy;while(y1>y2){_12864_write_dot(x1,y1);if(sub>0){x1-=1;sub+=(dx-dy)*2;}else{sub+=2*dx;}y1-=1;}}}}}/********************写16*16点阵的汉字函数*********************///参数page汉字开始的页数,colum汉字开始的列数//字符代码编号//CorN是否是带擦除的写入方式1为不擦除,0为擦除void write_word_16_16(UINT8 page,UINT8 colum,UINT8 word_num,UINT8 CorN,UINT8 filltype){UINT8 i,D_LorR,colum_temp;if(filltype==FillType_Fill){if(CorN==1){for(i=0;i<8;i++){D_LorR=0;colum_temp=colum+i;if((colum+i)>63){colum_temp=colum-64+i;D_LorR=1;}_12864_wr_data_notclear(page,colum_temp,D_LorR,zimo[word_num][i]);}for(i=16;i<24;i++){D_LorR=0;colum_temp=colum+i-16;if((colum+i-16)>63){colum_temp=colum-64+i-16;D_LorR=1;}_12864_wr_data_notclear(page+1,colum_temp,D_LorR,zimo[word_num][i]);}for(i=8;i<16;i++){D_LorR=0;colum_temp=colum+i;if((colum+i)>63){colum_temp=colum-64+i;D_LorR=1;}_12864_wr_data_notclear(page,colum_temp,D_LorR,zimo[word_num][i]);}for(i=24;i<32;i++){D_LorR=0;colum_temp=colum+i-16;if((colum+i-16)>63){colum_temp=colum-64+i-16;D_LorR=1;}_12864_wr_data_notclear(page+1,colum_temp,D_LorR,zimo[word_num][i]);}}else{for(i=0;i<8;i++){D_LorR=0;colum_temp=colum+i;if((colum+i)>63){colum_temp=colum-64+i;D_LorR=1;}_12864_wr_data(page,colum_temp,D_LorR,zimo[word_num][i]);}for(i=16;i<24;i++){D_LorR=0;colum_temp=colum+i-16;if((colum+i-16)>63){colum_temp=colum-64+i-16;D_LorR=1;}_12864_wr_data(page+1,colum_temp,D_LorR,zimo[word_num][i]);}for(i=8;i<16;i++){D_LorR=0;colum_temp=colum+i;if((colum+i)>63){colum_temp=colum-64+i;D_LorR=1;}_12864_wr_data(page,colum_temp,D_LorR,zimo[word_num][i]);}for(i=24;i<32;i++){D_LorR=0;colum_temp=colum+i-16;if((colum+i-16)>63){colum_temp=colum-64+i-16;D_LorR=1;}_12864_wr_data(page+1,colum_temp,D_LorR,zimo[word_num][i]);}}}else{if(CorN==1){for(i=0;i<8;i++){D_LorR=0;colum_temp=colum+i;if((colum+i)>63){colum_temp=colum-64+i;D_LorR=1;}_12864_wr_data_notclear(page,colum_temp,D_LorR,~zimo[word_num][i]);}for(i=16;i<24;i++){D_LorR=0;colum_temp=colum+i-16;if((colum+i-16)>63){colum_temp=colum-64+i-16;D_LorR=1;}_12864_wr_data_notclear(page+1,colum_temp,D_LorR,~zimo[word_num][i]);}for(i=8;i<16;i++){D_LorR=0;colum_temp=colum+i;if((colum+i)>63){colum_temp=colum-64+i;D_LorR=1;}_12864_wr_data_notclear(page,colum_temp,D_LorR,~zimo[word_num][i]);}for(i=24;i<32;i++){D_LorR=0;colum_temp=colum+i-16;if((colum+i-16)>63){colum_temp=colum-64+i-16;D_LorR=1;}_12864_wr_data_notclear(page+1,colum_temp,D_LorR,~zimo[word_num][i]);}}else{for(i=0;i<8;i++){D_LorR=0;colum_temp=colum+i;if((colum+i)>63){colum_temp=colum-64+i;D_LorR=1;}_12864_wr_data(page,colum_temp,D_LorR,~zimo[word_num][i]);}for(i=16;i<24;i++){D_LorR=0;colum_temp=colum+i-16;if((colum+i-16)>63){colum_temp=colum-64+i-16;D_LorR=1;}_12864_wr_data(page+1,colum_temp,D_LorR,~zimo[word_num][i]);}for(i=8;i<16;i++){D_LorR=0;colum_temp=colum+i;if((colum+i)>63){colum_temp=colum-64+i;D_LorR=1;}_12864_wr_data(page,colum_temp,D_LorR,~zimo[word_num][i]);}for(i=24;i<32;i++){D_LorR=0;colum_temp=colum+i-16;if((colum+i-16)>63){colum_temp=colum-64+i-16;D_LorR=1;}_12864_wr_data(page+1,colum_temp,D_LorR,~zimo[word_num][i]);}}}}/********************编写16*16点阵字符串显示函数******************************/ //参数string是字符编号数组的首地址void write_string_16_16(UINT8 page,UINT8 colum,UINT8 *string,UINT8 number,UINT8 CorN,UINT8 filltype){UINT8 i;for(i=0;i<number;i++){write_word_16_16(page,colum+(i<<4),*(string+i),CorN,filltype);}}/****************************************************************************** ******//*************************填充函数****************************/void fill_rectangle(UINT8 xbegin,UINT8 ybegin,UINT8 xend,UINT8 yend){UINT8 x;for(x=xbegin;x<=xend;x++){_12864_glibline(x,ybegin,x,yend);}}/*******************菜单函数*******************///功能:编译出一个菜单可视化图形界面//具有填充,反相功能//struct MenuItem//{ //菜单结构// UINT8 MenuCount;//菜单项所在层的菜单项数目// UINT8 *DisplayString;//显示的名称// void (*subs)(void);//所指向的功能函数// struct MenuItem *ChildrenMenu;//所指向的子菜单// struct MenuItem *ParentMenu;//所指向的父菜单//};void MenuBox(UINT8 xbegin,UINT8 ybegin)/*Xbegin 方框左上角横坐标Ybegin 方框左上角纵坐标Xend 方框右下角横坐标Y end 方框右下角纵坐标*/{UINT8 page,num,xend,yend,count_temp;struct MenuItem *Menu_point_temp;Menu_point_temp=Menu_point;xend=xbegin+16*3;yend=ybegin+Menu_point->MenuCount*16-1;if(yend>63)yend=63;Menu_point=Menu_point->This;//指向本项菜单的首位地址page=ybegin>>3;_12864_clear_lcd(xbegin,ybegin,xend,yend);_12864_glibline(xbegin,ybegin,xend,ybegin);_12864_glibline(xbegin,ybegin,xbegin,yend);_12864_glibline(xbegin,yend,xend,yend);_12864_glibline(xend,ybegin,xend,yend);count_temp=Menu_point->MenuCount;for(num=0;num<count_temp;num++){if(page>7)continue;if(Menu_point==Menu_point_temp){if(key_number!=0){write_string_16_16(page,xbegin,Menu_point->DisplayString,3,1,0);}else{write_string_16_16(page,xbegin,Menu_point->DisplayString,3,1,1);}}else{write_string_16_16(page,xbegin,Menu_point->DisplayString,3,1,1);}Menu_point++;page+=2;}Menu_point=Menu_point_temp;}/******************主函数*******************/void main(void){PLL_init(16);io_12864();io_keyscan();_12864_init();_12864_clear_lcdall();MainMenu_init();ChildMenu1_init();ChildMenu2_init();ChildMenu3_init();ChildMenu4_init();SubChildMenu1_init();/* _12864_glibline(0,0,0,63);_12864_glibline(0,0,63,0);_12864_glibline(63,0,63,63);_12864_glibline(0,63,63,63);write_word_16_16(1,60,1,0,0); */Menu_point=Menu_table[key_number].Menu_pointer;MenuBox(Menu_point->Local_x,Menu_point->Local_y);// MenuBox(65,16);// write_string_16_16(0,40,Menu_point->DisplayString,3,0,0);// write_string_16_16(2,40,&Menu_word[0][0],3,0,0);for(;;){switch(keyscan()){case 1: //DOWM下翻页key_number=Menu_table[key_number].down_stat;Menu_point=Menu_table[key_number].Menu_pointer;MenuBox(Menu_point->Local_x,Menu_point->Local_y);break;case 6: //UPkey_number=Menu_table[key_number].up_stat;Menu_point=Menu_table[key_number].Menu_pointer;MenuBox(Menu_point->Local_x,Menu_point->Local_y);break;case 5://enterif(Menu_point->ChildrenMenu!=NULL){key_number=Menu_table[key_number].enter_stat;Menu_point=Menu_table[key_number].Menu_pointer;MenuBox(Menu_point->Local_x,Menu_point->Local_y);}else if(Menu_point->subs!=NULL){(*Menu_point->subs)();}break;case 9://escif(Menu_point->ParentMenu!=NULL){_12864_clear_lcd(Menu_point->Local_x,Menu_point->Local_y,(Menu_point->Local_x+16*3),(Menu_point->Local_y+16*Menu_point->MenuCount-1));key_number=Menu_table[key_number].esc_stat;Menu_point=Menu_table[key_number].Menu_pointer;MenuBox(Menu_point->Local_x,Menu_point->Local_y);}break;}}}。

12864多功能程序实现

12864多功能程序实现

/*以下程序是自己在做天津市TI电设时调试的12864程序,每一部分都亲自调试过,功能都可以实现,建议使用者先花一点时间把程序看懂,不是很难。

程序里有许多注释掉的函数,都是相关的一些测试函数,使用者可根据需要,解冻相关测试函数,来调试一下功能。

当然,前提还是你要先熟悉一下全部的程序结构,不然很可能改动出现错误。

实现功能:画点,画线(水平线、垂直线、任意指定首尾坐标的斜线、折线)、画圆,键盘控制上下左右来画任意图形,以及指定一初始点后按使用者指定的路径自动完成一副图形(譬如矩形、三角形,更复杂的可由使用者继续优化算法。

)*/#include <stdio.h>#include <math.h>#include <reg52.h>#include <string.h>/******************************************************************//* 定义接口信息*//******************************************************************/sbit RS =P2^4; // 并行:指令(H)/数据(L)选择;串行:片选信号(CS)sbit WRD=P2^5; //并行:读写选择;串行:数据口(SID)sbit E= P2^6; // 并行:使能信号;串行:时钟信号(SLK)sbit PSB=P2^1; // 选择并口或者串口工作模式sbit RES=P2^3; // 复位信号,低电平有效sbit key1=P3^0; //定义按键位置sbit key2=P3^1;sbit key3=P3^2;sbit key4=P3^3;/******************************************************************//* 定义数组*//******************************************************************/unsigned char code pic2[];void TransferData(char data1,bit DI);void display(void);void delayms(unsigned int n);void delay(unsigned int m);/******************************************************************//* 液晶初始化-图形*//******************************************************************/void initina2(void) //LCD显示图片(扩展)初始化程序{delay(40); //大于40mS的延时程序PSB=1; //设置为8BIT并口工作模式delay(1); //延时RES=0; //复位delay(1); //延时RES=1; //复位置高delay(10);TransferData(0x36,0); //Extended Function Set RE=1: extended instructiondelay(100); //大于100uS的延时程序TransferData(0x36,0); //Extended Function Set:RE=1: extended instruction setdelay(37); ////大于37uS的延时程序TransferData(0x3E,0); //EXFUNCTION(DL=8BITS,RE=1,G=1)delay(100); //大于100uS的延时程序TransferData(0x01,0); //CLEAR SCREENdelay(100); //大于100uS的延时程序}/****************************************************************************** **///图形区清RAM函数/****************************************************************************** */void LCD_ClearBMP( void ){unsigned char i,j;TransferData(0x34,0); //8Bit扩充指令集,即使是36H也要写两次TransferData (0x36,0); //绘图ON,基本指令集里面36H不能开绘图for(i=0;i<32;i++) //12864实际为256x32{TransferData(0x80|i,0); //行位置TransferData(0x80,0); //列位置for(j=0;j<32;j++) //256/8=32 byteTransferData(0,1);}}/******************************************************************//******************************************************************/ void v_Lcd12864CheckBusy_f( void ) //忙检测函数{unsigned int nTimeOut = 0;P0 = 0x80 ;//P0=0x80WRD= 1 ; //io_LCD12864_RW= 1,读RS=0; //io_LCD12864_RS=0,指令E=0 ; //io_LCD12864_EN=0,E=1 ; //io_LCD12864_EN=1,使能while((P0==0x80)&&(++nTimeOut!=0));//在P0==0x80时,等待E=0; //io_LCD12864_EN=0,}// 读取一个字节unsigned char u8_Lcd12864ReadByte_f( void ){unsigned char byReturnV alue ;v_Lcd12864CheckBusy_f();P0 = 0xff ;//P0=0xffRS=1; //RS=1,指令WRD=1; //RW=1,读E=0; //EN=0E=1; //EN=1byReturnV alue = P0 ;//byReturnV alue=P0delay(1);E=0; //EN=0;return byReturnV alue;}/******************************************************************//******************************************************************/void TransferData(char data1,bit DI) //传送数据或者命令,当DI=0是,传送命令,当DI=1,传送数据.{//char buffer;WRD=0;RS=DI;delay(1);//buffer = data1;//P0 = buffer;P0 = data1;/*count++;if(count == 14){P0= 0x00;count=0;} */E=1;delay(1);E=0;}/****************************************************************************** ********/// 延时函数/****************************************************************************** ********/void delayms(unsigned int n) //延时10×n毫秒程序{unsigned int i,j;for(i=0;i<n;i++)for(j=0;j<2000;j++);}void delay(unsigned int m) //延时程序{unsigned int i,j;for(i=0;i<m;i++)for(j=0;j<10;j++);}/******************************************************************/// 画点函数/******************************************************************/ void v_Lcd12864DrawPoint_f( unsigned char X, unsigned char Y, unsigned char Color ) {unsigned char Row,Tier,Tier_bit;//Tier_bit的作用:确定该位置是低八位,还是高八位unsigned char ReadOldH, ReadOldL ;TransferData( 0x34,0 ) ; //使用扩充指令集delay(1);TransferData( 0x36,0 ) ; //使用扩充指令集,图像显示开?delay(1);Tier = X >> 4 ;//X的范围是0-127,即0x7f.Tier 除以16,获取它的字。

相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

;--------------------------
;写字节变量:W_CNT,W_DATA(接口)
;--------------------------
W_BYTE:
LD A,#8
LD W_CNT,A ;赋变量计数8次
W_1:
BRES CLK ;时钟为低
RLC W_DATA ;移一位C=1时,则条转,否,则跳过下一条指令JRC C_1
BRES SID ;数据0
JPF W_1
C_1:
BSET SID ;数据1
W_5:
BSET CLK ;时钟为高时,发送数据
DEC W_CNT ;减1,为0时,则跳过下一条指令
JPF W_1
BRES CLK ;时钟为低
RET
;----------------------------
;写指令变量:CMD_DATA(接口)
;----------------------------
W_CMD:
BSET CS ;片选置高
Call CHECKBUSY
MOV W_DATA,#$F8 ;传送设置节
CALLF W_BYTE ;调用发送字节函数
MOV W_DATA,CMD_DATA ;先传送高字节
AND A,#123
LD W_DATA,A
CALLF W_BYTE ;调用发送字节函数
MOV W_DATA,CMD_DATA ;传送低字节
AND A,#15 ;取低4位
SWAP A ;移到高4位
LD W_DATA,A
CALLF W_BYTE ;调用发送字节函数
BRES CS ;片选置低
RET
;------------------------------
;写数据变量:D_DA TA(接口)
;------------------------------
W_DATA:
BSET CS ;片选置高
Call CHECKBUSY
MOV W_DATA,#%FA ;传送设置节
CALLF W_BYTE ;调用发送字节函数
MOV W_DATA,D_DATA ;先传送高字节
AND A,#120
LD W_DATA,A
CALLF W_BYTE ;调用发送字节函数
MOV W_DATA,D_DATA ;传送低字节AND A,#15
SWAP A ;移到高4位
LD W_DATA,A
CALL W_BYTE ;调用发送字节函数
BRES CS ;片选置低
RET
;---------------------------------
;读一个字节
;---------------------------------
R_BYTE:
LD A,#8
LD R_CNT8,A
R_1:
BTJT SID,R_5 ;SID=1,跳转
RCF ;C=0
RLC R_TEMP
JPF R_10
R_5:
SCF ;C=1
RLC R_TEMP
R_10:
BRES CLK
BSET CLK
BRES CLK
DEC R_CNT8
JPF R_1
BTJT FLAG,#7,R_15
BSET FLAG,#7
MOV R_TEMPH,R_TEMP
JPF R_BYTE
R_15:
BRES FLAG,#7
SWAP R_TEMPH
LD A,R_TEMPH
OR A,R_TEMP
LD R_TEMP,A
RET
;-----------------------------------
;检查忙状态
;-----------------------------------
CHECKBUSY:
Call R_BYTE
LD A,R_BYTE
AND A,#%10000000
JRMI CHECKBUSY
RET
;-----------------------------------
;LCD 初始化
;-----------------------------------
LCD_INIT:
MOV CMD_DATA,#$30 ;选择基本指令集
CALLF W_CMD
MOV CMD_DATA,#$0C ;开显示无游标,不反白
CALLF W_CMD
MOV CMD_DATA,#$01 ;清显示,并设定地址指针为00H CallF W_CMD。

相关文档
最新文档