Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Init problems with a 4x20 LCD (KS0066) and a PIC16f877a

Status
Not open for further replies.

Gukken

Newbie level 1
Joined
Mar 24, 2012
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,297
Hi! First post. I've been having some trouble initializing my 4x20 LCD Winstar WH2004A display with my PIC16f877a.
The problem is that it will only initialize the first line (shows as row 1&3 on the display). Exactly as the startup sequence is for this display.

The display datasheet is @ **broken link removed** <- Direct link to the WH2004A datasheet PDF
The datasheet offers some clues: 1/16 duty cycle

Connection details.
RS = RA0
R/W = GND (0)
E = RA1
DB4=RB0 , DB5=RB1 , DB6=RB2 , DB7=RB3
If you ignore the 7segment displays and the button - the power source looks likes this **broken link removed**

I couldn't find a datasheet for the KS0066 driver (for the LCD) but there's a driver KS0066U datasheet http://www.datsi.fi.upm.es/docencia/Micro_C/lcd/ks0066u.pdf

Anyway... Here's my code
Code:
#include <htc.h>
#include <pic16f877a.h>
#include <pic.h>

__CONFIG(FOSC_XT & WDTE_OFF & BOREN_OFF & LVP_OFF & CPD_OFF &
DEBUG_OFF & CP_OFF);

#define _XTAL_FREQ 4000000 //4MHz
#define RS   RA0
#define EN   RA1


void startupint() {
PORTD = 0x00;
PORTB = 0x00;
ADCON1 = 0x06;  //Analog comparators off
CMCON = 0x07;
PORTA = 0x00;
PORTE = 0x00;
PORTC = 0x00;
TRISA = 0x00; //PORTA all output
TRISB = 0x00; //PORTB all output
TRISC = 0x00; //PORTC all output
TRISD = 0x00; //PORTD all output
TRISE = 0x00; //PORTE all output
}

void strobe_EN() {
EN = 1;
EN = 0;
}

void lcdinit() {
__delay_ms(1000);      // Wait for LCD to settle
RS=0;
EN=0;      
PORTB = 0x02;         // START FUNCTION SET
strobe_EN();         
//__delay_us(10);
strobe_EN();
PORTB = 0x0C;         // 2-Line mode, Display on
strobe_EN();         // END FUNCTION SET

__delay_us(80);         // WAIT FOR MORE THAN 39uS

PORTB = 0x00;         // START ON/OFF Control
strobe_EN();
PORTB = 0x0c;         // Display on
strobe_EN();
__delay_us(80);         // END ON/OFF Control

PORTB = 0x00;         // START DISPLAY CLEAR
strobe_EN();
PORTB = 0x01;
strobe_EN();
__delay_ms(4);         // END DISPLAY CLEAR

PORTB = 0x00;         // START ENTRY MODE SET
strobe_EN();
PORTB = 0x06;         // Increment mode, entire shift off
strobe_EN();
__delay_us(80);         // END ENTRY MODE SET

}

void main() {

startupint();
lcdinit();
//lcdclear();
//writelcd(0x30);
while(1) {
NOP();
}


}

I keep on wondering if there's any problems with my delays?? I use HITECH compiler (PRO) and MPLAB IDE v8.30. Just started from ASM to C but I've been searching for alot of sample codes online and they all seem to be compatible.
But it won't start up the second line (or row 2&4).

EDIT: Oh, forgot to mention that I'm using a 10kOhm pot for contrast.
 
Last edited:

hi try to take a look to my thread,it maybe helful for you even you don't use assembly language.
 

A 20x4 LCD to be addressed differently than the 16x4.
A good site:
**broken link removed**
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top