1602的简单显示程序,为什么我把程序里所有的NOP都去掉了,程序还是能够正常运行,1602还正常显示呢?
按道理他的时序不是被破坏了,应该不能正常显示才对啊,高手指点指点。
#include<reg52.h> //包含单片机寄存器的头文件 #include<intrins.h> //包含_nop_()函数定义的头文件 sbit RS=P3^0; //寄存器选择位,将RS位定义为P3.0引脚 sbit RW=P3^1; //读写选择位,将RW位定义为P3.1引脚 sbit E=P3^2; //使能信号位,将E位定义为P3.2引脚 sbit BF=P0^7; //忙碌标志位,,将BF位定义为P0.7引脚 /********************** 延时函数 **********************/ delay() { char i,j; for(i=0;i<4;i++) for(j=0;j<33;j++) ; } delayn(char i) { for(;i!=0;i--) delay(); } delaym(char i) { int j; for(j=0;j<400;j++) {delayn(i);} } /******************* 忙碌测试 *******************/ bit busytest() { bit result; RS=0; RW=1; E=1; _nop_(); _nop_(); _nop_(); _nop_(); //单片机等待液晶模块的BF建立 result=BF; E=0; return result;
} /******************** 读指令/数据地址 ********************/ writeinstruction(unsigned char dictate) { while(busytest()^0); RS=0; RW=0; E=0; _nop_(); _nop_(); P0=dictate; _nop_(); _nop_(); _nop_(); _nop_(); E=1; _nop_(); _nop_(); _nop_(); _nop_(); E=0; } /********************* 初始化 *********************/ csh() { delayn(15); writeinstruction(0x38); delayn(5); writeinstruction(0x38); delayn(5); writeinstruction(0x38); delayn(5); writeinstruction(0x0e); delayn(5); writeinstruction(0x06); delayn(5); writeinstruction(0x01); delayn(5);
} /********************** 写数据 **********************/ writedate(unsigned char d) {
while(busytest()^0); RS=1; RW=0; E=0; P0=d; _nop_(); _nop_(); _nop_(); _nop_(); E=1; _nop_(); _nop_(); _nop_(); _nop_(); E=0;
} /*********************** 视觉地址向实际地址转换 ************************/ zh(unsigned char x) { writeinstruction(x|0x80); } /********************** 主函数 ***********************/ main() {
unsigned char code a[]={"hello I am 1602"}, b[]={"can i help you"},c[]={"Mr PanSJ"}; unsigned char i; csh(); while(1) { writeinstruction(0x01); zh(0x00); for(i=0;a!='\0';i++) {
writedate(a); delaym(1); } delaym(15); writeinstruction(0x01); zh(0x00) ; for(i=0;b!='\0';i++) {
writedate(b); delaym(1); } zh(0x40); for(i=0;c!='\0';i++) {
writedate(c); delaym(1); } delaym(20);
} }
|