1、#include #include #define uchar unsigned char#define uint unsigned inttypedef struct typFNT_GB16 / 汉字字模数据结构signed char Index2; / 汉字内码索引char Msk32; / 点阵码数据;/*TS12864A-3 端口定义*/#define LCD_data P0 /数据口sbit LCD_RS = P35; /寄存器选择输入 sbit LCD_RW = P36; /液晶读/ 写控制sbit LCD_EN = P34; /液晶使能控制sbit LCD_PSB = P37;
2、/串/并方式控制sbit cs = P32;sbit wela = P26;sbit dula = P27;uchar t0;uchar code dis = “0123456789“;#define delayNOP(); _nop_();_nop_();_nop_();_nop_();/uchar IRDIS2;/uchar IRCOM4;/void lcd_pos(uchar X,uchar Y); /确定显示位置delay_50us(uint t)uchar j;for(;t0;t-)for(j=19;j0;j-);void delay(int ms)while(ms-)uchar i
3、;for(i=0;i250;i+) _nop_(); _nop_();_nop_();_nop_();bit lcd_busy() bit result;LCD_RS = 0;LCD_RW = 1;LCD_EN = 1;delayNOP();result = (bit)(P0LCD_EN = 0;return(result); void lcd_wcmd(uchar cmd) while(lcd_busy();LCD_RS = 0;LCD_RW = 0;LCD_EN = 0;_nop_();_nop_(); P0 = cmd;delayNOP();LCD_EN = 1;delayNOP();L
4、CD_EN = 0; void lcd_wdat(uchar dat) while(lcd_busy();LCD_RS = 1;LCD_RW = 0;LCD_EN = 0;P0 = dat;delayNOP();LCD_EN = 1;delayNOP();LCD_EN = 0; void lcd_init() LCD_PSB = 1; /并口方式 lcd_wcmd(0x34); /扩充指令操作delay(5);lcd_wcmd(0x30); /基本指令操作delay(5);lcd_wcmd(0x0C); /显示开,关光标delay(5);lcd_wcmd(0x01); /清除 LCD 的显示内
5、容delay(5); /延时void main()uchar v;uchar j,k,m,n;wela=0;dula=0;cs=0;LCD_RW=0;delay_50us(2);LCD_RW=1;cs=1;delay_50us(10);cs=0;LCD_RW=0;delay_50us(1);v=P0;delay_50us(2);LCD_RW=1;cs=1;j=v/100;k=v%100;m=k/10;n=k%10;lcd_init();while(1) uchar i;lcd_wcmd(0x80);for(i=0;i3;i+)if(i=0) lcd_wdat(disj);else if(i=1) lcd_wdat(dism); else if(i=2) lcd_wdat(disn);delay_50us(20);