HerbertMunch
New Member
Hi im trying to control a 44870 lcd with a pic18f4550.
It seems everytime i try and do LCD i run into problems. Im running out of hair to pull out.
I have tried the microchip c18 XLCD library, and my own lcd code, but neither work.
I have included my code, and circuit diagram.
The code project is a slightly modified Microchip usb framework.
The code that im trying to get working resides inside LCD.c and PinDefs.h.
it would seem that Im failing to initialise the lcd properly.
Can anyone see any obvious mistakes im making?
Many thanks.
Chris
LCD.C code
PinDefs.h
It seems everytime i try and do LCD i run into problems. Im running out of hair to pull out.
I have tried the microchip c18 XLCD library, and my own lcd code, but neither work.
I have included my code, and circuit diagram.
The code project is a slightly modified Microchip usb framework.
The code that im trying to get working resides inside LCD.c and PinDefs.h.
it would seem that Im failing to initialise the lcd properly.
Can anyone see any obvious mistakes im making?
Many thanks.
Chris
LCD.C code
Code:
#include "LCD.h"
void Delay1mS(void);
void Delay15mS(void);
void Delay5mS(void);
void Delay200uS(void);
void PulseE(void);
void SendCommand1(byte);
void SendCharacter(char);
byte Swap(byte);
//Sends a byte command to the HD44780 display.
void SendCommand(byte command)
{
Delay15mS();
command = 0;
}
//Swaps nibbles of byte
byte Swap(byte command)
{
byte temp = command <<4;
temp |= command >>4;
return temp;
}
//Initialises the display
void OpenLCD(void)
{
//Make port outputs
LCDPORT = 0;
LCDTRIS = 0;
//Wait for display
Delay15mS();
//Send 0x03
SendCommand1(0x20);
SendCommand1(0x28);
SendCommand1(0x06);
SendCommand1(0x0c);
SendCommand1(0x01);
SendCharacter('a');
}
void SendCommand1(byte command)
{
LCDTRIS &= 0x0F;
LCDPORT &= 0x0F;
//Swap nibbles
LCDPORT |= command;
//LCDPORT |= command & 0xF0;
PulseE();
Delay15mS();
}
void SendCharacter(char character)
{
LCDPORT =0;
LCD_RS =1;
LCDPORT |= character & 0xF0;
PulseE();
LCDPORT |= Swap(character) & 0xF0;
PulseE();
Delay15mS();
}
void PulseE(void)
{
LCD_E = 1;
Delay200uS();
LCD_E = 0;
Delay1mS();
}
PinDefs.h
Code:
/*
Pin definitions and macros
Chris Dec 07
*/
#include <P18F4550.h>
//Power check pins
#define PIN_SELFPOWER PORTBbits.RB5
#define PIN_USBPOWER PORTDbits.RD3
//Switch pins
#define PIN_SWITCH1 PORTBbits.RB4
#define PIN_SWITCH2 PORTBbits.RB3
//LED pins
#define PIN_LED1 LATBbits.LATB2
#define PIN_LED2 LATBbits.LATB1
#define PIN_ONLED LATBbits.LATB0
//Piezo pins
#define PIN_PIEZO1 LATCbits.LATC0
#define PIN_PIEZO2 LATCbits.LATC1
//LM35
#define PIN_LM35 PORTEbits.RE1
//LCD pins - bit 3 is not used for LCD and should not be manipulated
#define PIN_BACKLIGHT LATCbits.LATC6
#define LCDPORT PORTD
#define LCDTRIS TRISD
#define LCD_RS PORTDbits.RD0
#define LCD_RW PORTDbits.RD1
#define LCD_E PORTDbits.RD2
//Macros
#define ScreenOn() PIN_BACKLIGHT = 1;
#define ScreenOff() PIN_BACKLIGHT = 0;
Attachments
Last edited: