12864LCD带中文字库(PIC程序)
扫描二维码
随时随地手机看文章
#include
;__CONFIG_DEBUG_OFF&_CP_ALL&_WRT_HALF&_CPD_ON&_LVP_OFF&_BODEN_OFF&_PWRTE_ON&_WDT_OFF&_HS_OSC
;芯片配置字,看门狗关,上电延时开,掉电检测关,低压编程关,加密,4M晶体HS振荡
#defineRSPORTA,5;命令/数据选择
#DEFINERWPORTA,4;读/写选择
#DEFINEEPORTA,3;使能信号
#DEFINEPSBPORTA,2;并口/串口选择(H/L)
#DEFINERSTPORTA,0;复位信号
;-----------------------------------------------
LCD_XEQU30H;页地址
LCD_YEQU31H;Y地址
COUNTEQU32H;循环计数用
COUNT1EQU33H;循环计数用
COUNT2EQU34H;循环计数用
COUNT3EQU35H
POINTEQU36H;查表偏移地址
POINT1EQU37H;查表偏移地址
POINT2EQU38H;查表偏移地址
POINT3EQU40H
TEMPEQU39H;临时寄存器
TEMP1EQU3AH;临时寄存器
;-----------------------------------------------
ORG0000H;复位地址
NOP;ICD需要的空指令
GOTOMAIN;跳转到主程序
;**********************主程序************************
MAIN
BANKSELTRISA
CLRFTRISA;A口输出
CLRFTRISD;D口输出
BANKSELADCON1
MOVLW06H
MOVWFADCON1;A口全为数字口
CLRFSTATUS
BCFRST;复位LCD
CALLDELAY;延时一段时间
BSFRST;清除复位信号
NOP
BSFPSB;并口通讯
;**************************初始化**********************
MOVLW30H;基本指令操作
CALLSEND_I
MOVLW01H;清除显示
CALLSEND_I
MOVLW06H;指定在写入或读取时,光标的移动方向
CALLSEND_I
MOVLW0CH;开显示,关光标,不闪烁
CALLSEND_I
;***********************显示汉字************************
HAN_WR2
CALLCLEAR_P;清屏
HAN_WR2A;“深圳乾龙盛电子”
CALLQUSHU
GOTO$
;************************写准备****************************
WR_ZB
MOVLW34H
CALLSEND_I
MOVFWLCD_Y;Y地址
CALLSEND_I
MOVFWLCD_X;页地址
CALLSEND_I
MOVLW30H
CALLSEND_I
RETURN
;***********************清屏*******************************
CLEAR_P
MOVLW1H;清除显示
CALLSEND_I
RETURN
;***********************取数显示程序***********************
QUSHU
CLRFPOINT;取数地址低8位
CLRFPOINT+1;取数地址高8位(因为一共需要(128/8)*64个数据)
CLRFPOINT2;POINT的临时寄存器
CLRFPOINT3;POINT+1的临时寄存器
MOVLW02H;整块屏分为上下两个小屏(每小屏共32行)
MOVWFCOUNT3
MOVLW80H;上半屏的起始地址
MOVWFLCD_X
QUSHU1
MOVLW80H;每一行的第一个字节的地址
MOVWFLCD_Y
MOVLW20H;每一小屏共32行
MOVWFCOUNT2
QUSHU2
MOVLW10H;每一行共16个字节(16*8=128)
MOVWFCOUNT1
CALLWR_ZB;调用写准备函数
QUSHU3
CALLTAB1;查表
CALLSEND_D;写入到LCD的GDROM里
CLRFPOINT3
INCFPOINT,1;偏移地址加1,查找下一个数据
BTFSCSTATUS,Z;低8位是否有溢出
INCFPOINT+1,1;有,高8位+1
DECFSZCOUNT1,1;是否写完一行16个字节
GOTOQUSHU3;否,返回去继续写
INCFLCD_Y,1;是,写下一行
DECFSZCOUNT2,1;是否写完32行
GOTOQUSHU2;否,继续写
MOVLW88H;是,写下半屏
MOVWFLCD_X
DECFSZCOUNT3,1;是否写完下半屏
GOTOQUSHU1;否,继续写
;是,开显示
MOVLW36H;扩展指令,图形显示开
CALLSEND_I
MOVLW30H;基本指令
CALLSEND_I
RETURN
;************************送数据到LCD***********************
;写数据子程序
;RS=1,RW=0,E=高脉冲,D0-D7=数据
;**********************************************************
SEND_D
MOVWFTEMP1;暂存数据
CALLCHK_BUSY;判断总线是否忙
BSFRS
BCFRW
MOVFWTEMP1
MOVWFPORTD;送出数据
BSFE
NOP
NOP
BCFE
RETURN
;************************送命令到LCD***********************
;写指令子程序
;RS=0,RW=0,E=高脉冲,D0-D7=指令码
;**********************************************************
SEND_I
MOVWFTEMP1;暂存命令
CALLCHK_BUSY;判断总线是否忙
BCFRS
BCFRW
MOVFWTEMP1
MOVWFPORTD;送命令
BSFE
NOP
NOP
BCFE
RETURN
;************************判断总线是否忙********************
;测忙碌子程序
;RS=0,RW=1,E=H,D0-D7=状态字
;**********************************************************
CHK_BUSY
BANKSELTRISD
MOVLW0FFH
MOVWFTRISD;D口设置为输入
CLRFSTATUS
MOVLW0FFH
MOVWFPORTD
BCFRS
BSFRW
CHECK_BUSY_1
NOP
NOP
NOP
BSFE
NOP
NOP
NOP
BTFSSPORTD,7;D7为高表示总线忙,为低表示总线空闲
GOTO$+6
NOP
NOP
NOP
BCFE
GOTOCHECK_BUSY_1
BCFE
BANKSELTRISD
CLRFTRISD;恢复D口为输出
CLRFSTATUS
RETURN
;***************************延时程序***************************
DELAY
MOVLW0afH
MOVWF20H
MOVLW0ffh
MOVWF21H
DECFSZ21H,1
GOTO$-1
DECFSZ20H,1
GOTO$-5
RETURN
;***************************延时程序1**************************
;显示闪烁用
DELAY1
MOVLW05H
MOVWF22H
CALLDELAY
DECFSZ22H,1
GOTO$-2
RETURN
;***************************数据表格**************************
TAB1
MOVLWLOW(TAB1A);获取数据表头的低8位地址
ADDWFPOINT,0;并上取数的低8位
MOVWFPOINT2;转存到POINT2里
BTFSCSTATUS,C;判断低8位是否有溢出
INCFPOINT3,1;是,高8位+1
MOVLWHIGH(TAB1A);获取数据表头的高8位地址
ADDWFPOINT3,0
ADDWFPOINT+1,0;并上取数的高8位
MOVWFPCLATH;准备PC的高5位
MOVFWPOINT2
MOVWFPCL;准备PC的低8位
TAB1A:;数据表
DT0X0F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XC0,0X00,0X00
DT0X18,0XFC,0XB7,0X80,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFF,0XFF,0XE0,0X00,0X00
DT0X1E,0X7F,0X0C,0X00,0X00,0X07,0XFF,0XFF,0X80,0X00,0X0F,0XF8,0X7F,0XE0,0X03,0XC0
DT0X1F,0XE7,0X80,0X00,0X00,0X7F,0XFF,0XFF,0XC0,0X00,0X7F,0XE1,0XFF,0XE0,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00,0X07,0XC9,0XFE,0X00,0X07,0X1F,0XE0,0X06,0X00
DT0X1F,0XFF,0XC0,0X0F,0XE0,0X00,0X00,0X03,0XC1,0XFE,0X00,0XFF,0XFF,0XE0,0X06,0X00
DT0X1F,0XC0,0X40,0X0F,0XC0,0X00,0X00,0X03,0XE7,0XFE,0X00,0X9F,0XFF,0X20,0X06,0X00
DT0X1F,0X00,0X00,0X0F,0XC0,0X00,0X00,0X07,0XE7,0XFC,0X00,0X0B,0XCF,0X20,0X06,0X00
DT0X1F,0X78,0X00,0X0F,0XC0,0X00,0X00,0X07,0XE7,0XFC,0X00,0X00,0X0F,0XE0,0X06,0X00
DT0X1F,0XFF,0X80,0X07,0XF0,0X00,0X00,0X03,0XEF,0XFC,0X00,0X00,0X3F,0XE0,0X06,0X00
DT0X13,0XFF,0XE0,0X07,0XFE,0X01,0XE0,0X01,0XCF,0XFC,0X00,0X00,0X3F,0XE0,0X06,0X60
DT0X1F,0XFC,0X00,0X07,0XE3,0X03,0XF8,0X06,0XDF,0XFC,0X00,0X1F,0XFE,0X60,0X06,0X60
DT0X1F,0X80,0X00,0X03,0X80,0X80,0XC0,0X01,0XFF,0XF8,0X00,0X0F,0X3F,0XE0,0X0F,0XE0
DT0X1C,0X00,0X00,0X01,0X80,0X41,0XC0,0X06,0XFF,0XF8,0X00,0X00,0XF3,0XE0,0X00,0X00
DT0X13,0XFC,0X00,0X03,0XFC,0X41,0XFC,0X03,0X7F,0XF0,0X00,0X00,0X0F,0XE0,0X00,0X00
DT0X1F,0XFF,0X00,0X03,0XFE,0X40,0XFF,0X00,0XFF,0XF0,0X00,0X07,0XFF,0XE0,0X07,0XC0
DT0X1F,0XC0,0X00,0X02,0XF0,0X40,0XE1,0X00,0X78,0XF0,0X00,0X3C,0XFC,0X20,0X0C,0X60
DT0X1E,0X00,0X00,0X02,0XC0,0XC0,0X60,0X00,0XF3,0X70,0X00,0X03,0XFF,0XE0,0X00,0X60
DT0X10,0X00,0X00,0X02,0X00,0X80,0X60,0X00,0X67,0X30,0X00,0X00,0X7F,0XE0,0X00,0XC0
DT0X17,0XFF,0X00,0X03,0X01,0X80,0X30,0X00,0XFC,0XB0,0X00,0X3F,0XCF,0XE0,0X01,0X80
DT0X1F,0XFA,0X00,0X03,0X03,0X80,0X18,0X01,0XFC,0X70,0X00,0X3C,0X8F,0XE0,0X03,0X00
DT0X1F,0XB0,0X00,0X03,0X0F,0X00,0X0C,0X02,0XFE,0X30,0X00,0X0D,0X3F,0X60,0X06,0X00
DT0X1F,0X00,0X00,0X03,0X0F,0X00,0X04,0X05,0XEE,0X30,0X00,0X03,0XDF,0X20,0X0C,0X00
DT0X1C,0X00,0X00,0X02,0X01,0X06,0X00,0X07,0XE3,0X30,0X01,0X00,0XDF,0XE0,0X0C,0X60
DT0X10,0X1E,0X00,0X03,0X03,0X03,0X80,0X07,0XF1,0X30,0X00,0XE0,0X33,0XE0,0X0F,0XE0
DT0X1F,0XEC,0X00,0X02,0X03,0X01,0XE0,0X09,0XF0,0X60,0X00,0X3C,0X8E,0X60,0X00,0X00
DT0X1F,0X30,0X00,0X03,0X03,0X9D,0X30,0X13,0XFC,0X60,0X00,0X1F,0X3F,0XA0,0X00,0X00
DT0X1F,0XC1,0X8C,0X02,0X81,0XF3,0X10,0X0F,0XF0,0XC0,0X03,0X87,0XC7,0XE0,0X03,0X80
DT0X1A,0X06,0X30,0X03,0X03,0X80,0X08,0X13,0XE0,0XC0,0X00,0XE3,0XF1,0XE0,0X06,0XC0
DT0X1C,0X1C,0X40,0X01,0X82,0X00,0X04,0X0F,0XE1,0X80,0X00,0X78,0XFE,0X60,0X0C,0X60
DT0X13,0XF8,0X80,0X01,0X46,0X00,0X00,0X07,0XE3,0X00,0X00,0X3E,0X7F,0XE0,0X0C,0X60
DT0X1F,0X63,0X00,0X01,0X8C,0X00,0X00,0X07,0XFE,0X00,0X00,0X0F,0X9F,0XE0,0X0D,0X60
DT0X1F,0X8E,0X04,0X01,0X47,0XEE,0X00,0X07,0XFE,0X00,0X00,0X87,0XEF,0XE0,0X0D,0X60
DT0X1E,0X3C,0X1C,0X00,0XA7,0XFF,0X8C,0X03,0XF8,0X00,0X00,0XC1,0XFF,0XE0,0X0C,0X60
DT0X1F,0X78,0X38,0X00,0XC3,0X93,0X8E,0X07,0XF0,0X00,0X00,0X78,0X7F,0XE0,0X0C,0X60
DT0X1F,0XF1,0X60,0X00,0XE3,0X80,0X06,0X07,0XF0,0X00,0X00,0X3A,0X1F,0XE0,0X06,0XC0
DT0X1F,0XE1,0X40,0X00,0X13,0XC8,0X00,0X0B,0XF0,0X00,0X00,0X1E,0X13,0XE0,0X03,0X80
DT0X17,0X8F,0X84,0X00,0X61,0XF8,0X00,0X17,0XF0,0X00,0X00,0X0F,0XB0,0XE0,0X00,0X00
DT0X1F,0X1E,0X29,0X80,0X33,0X00,0X00,0X0F,0XFC,0X00,0X00,0X43,0XFD,0X60,0X00,0X00
DT0X1E,0X7C,0X73,0X00,0X3A,0X10,0X00,0X0F,0XF4,0X00,0X00,0X21,0XFF,0XA0,0X03,0X80
DT0X15,0XF8,0XE3,0X00,0X1E,0X18,0X00,0X1F,0XF6,0X00,0X00,0X18,0XFF,0XE0,0X06,0XC0
DT0X1B,0XE1,0X86,0X00,0X1E,0X00,0X00,0X3F,0XE6,0X00,0X03,0X0E,0X7F,0XE0,0X0C,0X60
DT0X1F,0XC7,0X8C,0X00,0X1E,0X00,0X00,0X7F,0XE7,0X00,0X03,0X85,0X1B,0XE0,0X0C,0X60
DT0X1F,0X0F,0X39,0X20,0X07,0X00,0X01,0XFF,0XCF,0X00,0X01,0XC3,0XCD,0XE0,0X0D,0X60
DT0X1E,0X3E,0X73,0X40,0X03,0X80,0X0F,0XFF,0X9F,0X80,0X00,0XF1,0XF0,0X60,0X0D,0X60
DT0X18,0X7C,0XF6,0X20,0X01,0XE0,0X3F,0XFE,0X3F,0XE0,0X00,0X78,0XFE,0X60,0X0C,0X60
DT0X11,0XFB,0XE6,0X40,0X01,0XFF,0XFF,0XFC,0X7F,0XFC,0X08,0X3C,0X7F,0XE0,0X0C,0X60
DT0X1F,0XF7,0XFE,0X40,0X02,0XFF,0XFF,0XF9,0XFF,0XFF,0X00,0X0F,0X3F,0XE0,0X06,0XC0
DT0X1F,0XFF,0XFC,0X88,0X06,0XFF,0XFD,0XF3,0XFF,0XFF,0XC1,0X8F,0X9F,0XE0,0X03,0X80
DT0X1F,0XFF,0XB9,0X38,0X0E,0XFE,0X71,0XE7,0XFF,0XFF,0XE8,0XC3,0XEF,0XE0,0X00,0X00
DT0X0F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XC0,0X00,0X00
;***************************源程序结束************************
end