1602的簡單顯示程序,為什么我把程序里所有的NOP都去掉了,程序還是能夠正常運行,1602還正常顯示呢?
按道理他的時序不是被破壞了,應該不能正常顯示才對啊,高手指點指點。
#include<reg52.h> //包含單片機寄存器的頭文件
#include<intrins.h> //包含_nop_()函數(shù)定義的頭文件
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引腳
/**********************
延時函數(shù)
**********************/
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;
}
/********************
讀指令/數(shù)據(jù)地址
********************/
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);
}
/**********************
寫數(shù)據(jù)
**********************/
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;
}
/***********************
視覺地址向?qū)嶋H地址轉(zhuǎn)換
************************/
zh(unsigned char x)
{
writeinstruction(x|0x80);
}
/**********************
主函數(shù)
***********************/
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);
}
}
歡迎光臨 (http://www.torrancerestoration.com/bbs/) | Powered by Discuz! X3.1 |