The following are the source programs:
1#include <reg52.h>2#include <intrins.h>3 4 /**5 * P2 on the D1 ~ D76 */7Sbit RS = P3 ^0;//Data H Command L8Sbit RW = P3 ^1;//Read H write L9Sbit E = P3 ^2;//High-level H enableTen #defineDATA P2 One A /** - * Measured time by Logic Analyzer - * Single instruction is 5us the * NOP 0.4ms - * After the experiment found that only a single instruction execution time 5us Hugh Eye can - * E = 1 need to wait a short period of time, in the manual does not explain- - */ + - voidDelayms (Charms); + Charis_busy (); A voidWrite_cmd (unsignedCharcmd); at voidWrite_data (unsignedChardat); - voidPOS (unsignedCharPOS); - - voidMain () - { - //Initialize reset lcd1602 inWrite_cmd (0x38);//Set display mode script 00111000 = 0x38 -Delayms (1); toWrite_cmd (0x0c);//On display does not show the cursor does not blink +Delayms (1); -Write_cmd (0x06);//The cursor sets the character after the pointer plus a theDelayms (1); *Write_cmd (0x01);//cursor Clear 0 pointer clear 0 $Delayms (1);Panax Notoginseng -POS (0); theWrite_data ('1'); +Write_data ('2'); AWrite_data ('3'); theWrite_data ('4'); +Write_data ('5'); -Write_data ('6'); $Write_data ('7'); $Write_data ('8'); -Write_data ('9'); -Write_data ('0'); the -POS (0x40);Wuyi theWrite_data ('1'); -Write_data ('2'); WuWrite_data ('3'); -Write_data ('4'); AboutWrite_data ('5'); $ - while(1); - } - A voidPOS (unsignedCharPOS) + { the //set pointer position 0x80 | position -Write_cmd (pos|0x80); $ } the the voidWrite_data (unsignedChardat) the { the while(Is_busy ()); -RS =1; inRW =0; theE =0; the //_nop_ (); AboutDATA =dat; the _nop_ (); theE =1;//transfer when e high-low changes theE =0; + } - the voidWrite_cmd (unsignedCharcmd)Bayi { the while(Is_busy ()); theRS =0; -RW =0; -E =0; the //_nop_ (); theDATA =cmd; the _nop_ (); theE =1;//transfer when e high-low changes -E =0; the } the the Charis_busy ()94 { the intA=0; the Charresult; theRS =0;//the command was sent.98RW =1;//Read About //_nop_ (); -E =1;//to enable101 _nop_ ();102result = (1<<7& DATA);//7bit 1 Busy 0 not busy103E =0;//Cancel to enable104 returnresult; the }106 107 voidDelayms (CharMs//@12.000mhz108 {109 while(ms--) the {111UnsignedCharI, J; thei =2;113j =239; the Do the { the while(--j);117} while(--i);118 }119}
The simulation shows that one character is missing, not knowing what the reason is. Wait for the real machine to come, in the experiment.
Proteus 8 drawing schematic simulation 1602 LCD display characters