1
Character LCDs / NHD-0216K1Z
« on: July 20, 2017, 09:05:58 AM »
I can display one letter, but debugging my program I'm sending more characters than aren't displayed. Using PIC16F886. I'm using code close to what I read on this forum. I've enclosed the code, doing something wrong.
The initialization is copied from code on the forum. Also I don't understand the newline command 0xC0 ?
The program will also be used later for AD converter. But right now I want to get the display to work. Plus it gives me some LCD display experience.
char const text1[] = {"Roger Lakin " };
void main(void) {
TRISC = 0x00; // this port is set for outputs
TRISB = 0xF8; // all are set to inputs except the lower three
TRISA3 = 0; //AN3 +VREF
TRISA5 = 1; // AN4 bit 5 set as input
TRISB0 = 0; // enable signal output
TRISB1 = 0; // read/write signal
TRISB2 = 0; // register select signal
//ADCON0 = 0x11; // 00 0100 0 1
//ADCON1 = 0x80; // ADFM = 1
//ADRESH = 0x00; // ADC 8 & 9 off
//ADRESL = 0x10; // ADC 4 turned on pin 7 RA5 ADC rest off
/******************************************/
x = 0;
// Init();
PORTC = 0x00;
while(1){
Init();
DisplayInfo();
delay(1000);
}
}
void DisplayInfo(){ //disp_pic
int i;
Home();
for (i=0;i<8;i++){
Write(text1);
y = 0; // debug breakpoint
}
}
void Write(unsigned char Dat){
PORTB = 0X00;
PORTC = Dat;
delay(10);
RSLO; // RB2=0
RWLO;//RB1=0; //write
EHI; // RB0
RSHI; //RB2 data
delay(10);
EHI; //RB0=1;//EHI; //RB0
delay(10);
ELO; //RB0
RSLO;
//PORTC = 0x01;
//WriteCtl();
y=0;
}
void Home(){
PORTC = 0x02;
WriteCtl();
delay(5);
}
void NextLine(){
PORTC = 0xC0;
WriteCtl();
}
// write controls
void WriteCtl(){
RSLO;
RWLO; //RB1
EHI; //RB0
delay(1);
ELO; //RB0
//RWHI; //RB1
//RSHI; //RB2
}
// AorD = 0 for address and 1 for data
void WriteAN(int AorD) { // wrtAdr = 0; wrtNum = 1;
PORTB = 0X00;
RWLO;//RB1=0; //write
ELO; // RB0
if (AorD == 0) {
RSLO; //RB2 address
} else {
RSHI; //RB2 data
}
delay(1);
EHI; //RB0=1;//EHI; //RB0
delay(1);
ELO; //RB0
//RB1=1;//RWHI; //RB1
//RB2=1;//RSHI; //RB2
}
void WriteInt(unsigned char charNum){
PORTC = charNum;
RB2 = 0;//RSLO; // RB2
RB1 = 0; // RWLO; // RB1
RB0 = 1; //EHI; // RB0
delay(10);
RB0 = 0; // ELO; // RB0
y=0; // breakpoint
}
void Init(){
ELO;
delay(50); //Wait >40 msec after power is applied
WriteInt(0x30); //command 0x30 = Wake up
delay(100); //must wait 5ms, busy flag not available
WriteInt(0x30); //command 0x30 = Wake up #2
delay(100); //must wait 160us, busy flag not available
WriteInt(0x30); //command 0x30 = Wake up #3
delay(100); //must wait 160us, busy flag not available
WriteInt(0x38); //Function set: 8-bit/1-line
WriteInt(0x14);//Set cursor to rightAC+1
WriteInt(0x0C); //Display ON; Cursor ON
WriteInt(0x02); //Entry mode set cursor right DDRAM + 1
}
The initialization is copied from code on the forum. Also I don't understand the newline command 0xC0 ?
The program will also be used later for AD converter. But right now I want to get the display to work. Plus it gives me some LCD display experience.
char const text1[] = {"Roger Lakin " };
void main(void) {
TRISC = 0x00; // this port is set for outputs
TRISB = 0xF8; // all are set to inputs except the lower three
TRISA3 = 0; //AN3 +VREF
TRISA5 = 1; // AN4 bit 5 set as input
TRISB0 = 0; // enable signal output
TRISB1 = 0; // read/write signal
TRISB2 = 0; // register select signal
//ADCON0 = 0x11; // 00 0100 0 1
//ADCON1 = 0x80; // ADFM = 1
//ADRESH = 0x00; // ADC 8 & 9 off
//ADRESL = 0x10; // ADC 4 turned on pin 7 RA5 ADC rest off
/******************************************/
x = 0;
// Init();
PORTC = 0x00;
while(1){
Init();
DisplayInfo();
delay(1000);
}
}
void DisplayInfo(){ //disp_pic
int i;
Home();
for (i=0;i<8;i++){
Write(text1);
y = 0; // debug breakpoint
}
}
void Write(unsigned char Dat){
PORTB = 0X00;
PORTC = Dat;
delay(10);
RSLO; // RB2=0
RWLO;//RB1=0; //write
EHI; // RB0
RSHI; //RB2 data
delay(10);
EHI; //RB0=1;//EHI; //RB0
delay(10);
ELO; //RB0
RSLO;
//PORTC = 0x01;
//WriteCtl();
y=0;
}
void Home(){
PORTC = 0x02;
WriteCtl();
delay(5);
}
void NextLine(){
PORTC = 0xC0;
WriteCtl();
}
// write controls
void WriteCtl(){
RSLO;
RWLO; //RB1
EHI; //RB0
delay(1);
ELO; //RB0
//RWHI; //RB1
//RSHI; //RB2
}
// AorD = 0 for address and 1 for data
void WriteAN(int AorD) { // wrtAdr = 0; wrtNum = 1;
PORTB = 0X00;
RWLO;//RB1=0; //write
ELO; // RB0
if (AorD == 0) {
RSLO; //RB2 address
} else {
RSHI; //RB2 data
}
delay(1);
EHI; //RB0=1;//EHI; //RB0
delay(1);
ELO; //RB0
//RB1=1;//RWHI; //RB1
//RB2=1;//RSHI; //RB2
}
void WriteInt(unsigned char charNum){
PORTC = charNum;
RB2 = 0;//RSLO; // RB2
RB1 = 0; // RWLO; // RB1
RB0 = 1; //EHI; // RB0
delay(10);
RB0 = 0; // ELO; // RB0
y=0; // breakpoint
}
void Init(){
ELO;
delay(50); //Wait >40 msec after power is applied
WriteInt(0x30); //command 0x30 = Wake up
delay(100); //must wait 5ms, busy flag not available
WriteInt(0x30); //command 0x30 = Wake up #2
delay(100); //must wait 160us, busy flag not available
WriteInt(0x30); //command 0x30 = Wake up #3
delay(100); //must wait 160us, busy flag not available
WriteInt(0x38); //Function set: 8-bit/1-line
WriteInt(0x14);//Set cursor to rightAC+1
WriteInt(0x0C); //Display ON; Cursor ON
WriteInt(0x02); //Entry mode set cursor right DDRAM + 1
}