《IAP15F2K61S2液晶1602显示.docx》由会员分享,可在线阅读,更多相关《IAP15F2K61S2液晶1602显示.docx(4页珍藏版)》请在三一办公上搜索。
1、IAP15F2K61S2液晶1602显示#include stc15f2k60s2.h int i; sbit rw=P36; /1602 IO口定义 这里用的数据口是P0口 sbit rs=P35; sbit ep=P37; unsigned char code d = stc15f2k60s2; unsigned char code a = /汉字 0x04,0x0f,0x09,0x0f,0x08,0x0f,0x15,0x07 , /启 0x04,0x15,0x0e,0x1f,0x04,0x05,0x0b,0x13, /光 0x04,0x1f,0x15,0x1f,0x15,0x1f,0x0
2、5,0x07, /电 0x0f,0x02,0x04,0x1f,0x04,0x04,0x14,0xc ; /子 /* 延时函数 */ void delay(unsigned int a) while(a-); /*/ /*/ /* 1602 */ bit lcd_busy /查忙 这部很重要 否则有的显示容易出现乱码 bit result; rs = 0; rw = 1; ep = 1; delay(50); result = (bit)(P0&0x80); ep = 0; return result; /返回值 void lcd_com(unsigned char com)/ 地址 while
3、(lcd_busy); rs=0; ep=0; rw=0; P0=com; delay(50); ep=1; delay(50); ep=0; void lcd_date(unsigned char date)/采集输出数据 while(lcd_busy); rs=1; /1是些数据 0是写指令 rw=0; / 1是读 0是写 ep=0; /E端为使能端,当E端由高电平跳变成低电平时,液晶模块执行命令 P0=date; delay(5); ep=1; delay(5); ep=0; void lcd_pos(unsigned char pos) lcd_com(pos|0x80); /数据指针
4、=80+地址变量 void writetab / 写 汉字函数 unsigned char m; lcd_com(0x40); /写CGRAM 此处是指令 for (m = 0; m 32; m+) lcd_date(am); void init/1602初始化 lcd_com(0x38); delay(50); lcd_com(0x38); delay(50); lcd_com(0x38); delay(50); lcd_com(0x0c); delay(50); lcd_com(0x06); delay(50); lcd_com(0x01); delay(6000); writetab ;
5、 / 汉字初始化 /*/ /*/ /*/ void hanzi /汉字显示 lcd_pos(0x00); /启光 lcd_date(0x00); lcd_pos(0x00+1); lcd_date(0x01); lcd_pos(0x00+2); /电子 lcd_date(0x02); lcd_pos(0x00+3); lcd_date(0x03); /*/ void main(void) init; /1602初始化 hanzi ; /显示汉字 delay(100); lcd_pos(0x40); i=0; while(di!=0) /显示字母 lcd_date(di); i+; while(1);