|
用stc15f2k60s2寫了個1602驅(qū)動,然后程序不做任何更改直接源文件下載進(jìn)去,顯示的內(nèi)容都不一樣是怎么回事?,有時候下載下去又直接正常
51hei圖片_20200725172710.jpg (68.34 KB, 下載次數(shù): 34)
下載附件
2020-7-25 17:27 上傳
51hei圖片_20200725172719.jpg (72.7 KB, 下載次數(shù): 35)
下載附件
2020-7-25 17:27 上傳
這是怎么回事?
- void main()
- {
- Init_CPP();
- Init_1602();
- Write_string(1,1,"test ok");
- while(1)
- {
- sprintf(display,"time:%02d",dd);
- Write_string(0,0,display);
- }
- }
復(fù)制代碼- bit CheckBusy()
- {
-
- P=0xff;
- E=0;
- RS=0;
- RW=1;
- E=1;
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- dd=P0;
-
- E=0;
- return(bit)(dd&0x80);
- }
- void Write_dat(unsigned char dat)
- {
- while(CheckBusy());
- DelayMs(); //這是個5ms的延時,如果不加這個顯示就是亂碼
- DelayMs();
- E=0;
- RS=1;
- RW=0;
- _nop_();
- _nop_();
- E=1;
- P0=dat;
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- E=0;
- }
- void Write_com(unsigned char com)
- {
- while(CheckBusy());
- DelayMs();
- DelayMs();
- E=0;
- RS=0;
- RW=0;
- _nop_();
- _nop_();
- E=1;
- P0=com;
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- _nop_();
- E=0;
- }
- void Write_string(unsigned char x,unsigned char y,unsigned char*s)
- {
- if(y==0)
- Write_com(0x80+x);
- else
- Write_com(0xc0+x);
- while(*s)
- {
- Write_dat(*s);
- s++;
- }
- }
復(fù)制代碼
|
|