Example code for Newhaven OLED display NHD-0216KZW/ 0220DZW/ 0420DZW - (8-bit)
#include <reg52.h> //--------------------------------------------------------- sbit R_S = P3^0; sbit R_W = P3^7; sbit E = P3^4; char const text1[] = {"Newhaven Display"}; char const text2[] = {"Character LCD "}; void Delayms(int n){ int i; int j; for (i=0;i<n;i++) for (j=0;j<1000;j++) {;} } void command(char i){ P1 = i; R_S =0; R_W =0; E = 1; //Delayms(5); E = 0; } void write(char i){ P1 = i; R_S =1; R_W =0; E = 1; //Delayms(5); E = 0; } void init(){ E = 0; //Delayms(5); command(0x30); //Delayms(100); command(0x30); //Delayms(10); command(0x30); //Delayms(10); command(0x38); command(0x10); command(0x0c); command(0x06); } void disp_pic(){ int i; command(0x02); for (i=0;i<16;i++){ write(text1[i]); } command(0xC0); for (i=0;i<16;i++){ write(text2[i]); } } void main(void) { P1=0; P3=0; init(); command(0x01); //Delayms(50); while(1){ disp_pic(); //Delayms(1000); } }