Currently doing for my final year project and want to test my lcd qy1602a with simple program. I had construct the circuit and coding like in this thread: https://www.electro-tech-online.com/threads/pic-18f4550-2x8-lcd-character-display-assistance.122251/
It cant work in proteus and my hardware. I using pickit2 as my programmer. isnt any setting that i miss out?
I had change abit in the coding as i want to use external oscillator.
[/CODE]
View attachment 62167
It cant work in proteus and my hardware. I using pickit2 as my programmer. isnt any setting that i miss out?
I had change abit in the coding as i want to use external oscillator.
Code:
[CODE]//turns watch dog timer off, turn low voltage programming off
#pragma config WDT=OFF, LVP=OFF, DEBUG=ON, MCLRE = OFF
#pragma config OSC=HS
#include <p18f4520.h>
#include <delays.h>
#define _XTAL_FREQ 10000000
//LCD (PortD)
#define E LATDbits.LATD6
#define R_W LATDbits.LATD5
#define RS LATDbits.LATD4
#define LCDdata LATD
void command(unsigned char);
void write(unsigned char);
void Nybble(unsigned char);
void init(void);
void PutMessage(rom char *);
void main()
{
while(!OSCCONbits.IOFS); //wait for osc stable
ADCON1 = 0x0F; //make RA0 digital
//data direction registers all 0's mean that all pins are set to output
//all 1's means that all of the pins are set to operate as inputs
TRISA = 0x00;
TRISB = 0x00;
TRISD = 0x00;
init();
PutMessage("Hello World!");
command(0xc0);
PutMessage("WELCOME");
while(1);
}
//Write a string to the LCD
void PutMessage(rom char *Message)
{
rom char *Pos = Message;
while(*Pos!=0)
write(*Pos++);
}
/**********************************************************/
//4-bit methods for LCD
/**********************************************************/
void command(unsigned char i)
{
RS =0;
R_W =0; //R/W=LOW : Write
Nybble(i>>4); //Send upper 4 bits
Nybble(i); //Send lower 4 bits
Delay1KTCYx(2); //must wait at least 2mS (2*1000*4/1e6 = 8ms used)
}
void write(unsigned char i)
{
RS =1;
R_W =0; //R/W=LOW : Write
Nybble(i>>4); //Send upper 4 bits
Nybble(i); //Send lower 4 bits
Delay1KTCYx(2); //must wait 2mS
}
/**********************************************************/
void Nybble(unsigned char dat)
{
dat &= 0x0f; //clear top bits of dat
LCDdata &= 0xf0; //clear bottom bits of port (interested only in DB7-DB4)
LCDdata |= dat; //or the two and store at port
E = 1;
Delay1TCY(); //enable pulse width >= 300ns (used 4uS)
E = 0; //Clock enable: falling edge
}
/**********************************************************/
void init(void)
{
LCDdata=0x00;
Delay1KTCYx(15); //Wait >15 msec after power is applied (used 20mS)
Nybble(0x3); //command 0x30 = Wake up
Delay1KTCYx(5); //must wait 160us, busy flag not available (used 160uS)
Nybble(0x3); //command 0x30 = Wake up #2
Delay1KTCYx(5); //must wait 160us, busy flag not available (used 160uS)
command(0x20); //Function set: 4-bit/2-line
command(0x2c); //Function set: 4-bit/2-line
command(0x10); //Set cursor
command(0x01); //Clear Display (Added)
command(0x06); //Entry Mode set
command(0x0c);
}
/**********************************************************/
//End methods for LCD
/**********************************************************/
View attachment 62167
Last edited: