At the moment i'm haveing trouble getting it to display anything at all i found demo code with the pickit2 cd and according to it's instructions I wired the display up for 4-bit mode but it simply won't light up the code compiles fine too. also the R/W pin the code doesn't do anything with it so since it's write when low I'm useing a pull down resistor even though it's not in the schematic.
#include <pic.h>
/* cLCD.c - Write a String to a 4 Bit Hitachi 44780 LCD I/F
This Program Initializes Hitachi 44780 Based LCD in 4 Bit Mode
and then writes a simple string to it. The simulator was used
to time delay values.
LCD Write Information can be found at http://www.myke.com
RC3:RC0 - LCD I/O D7:D4 (Pins 14:11)
RC4 - LCD E Clocking Pin
RC5 - LCD R/S Pin
myke predko
04.11.08
*/
__CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT \
& UNPROTECT & BORDIS & IESODIS & FCMDIS);
int i, j, k, n; // Use Global Variables for Debug
// 1234567890123456
const char TopMessage[] = " PIC MCU ";
const char BotMessage[] = " Evil Genius ";
#define E RC4 // Define the LCD Control Pins
#define RS RC5
const int Twentyms = 1250; // Declare a Constant for 20 ms Delay
const int Fivems = 300;
const int TwoHundredus = 10;
LCDWrite(int LCDData, int RSValue)
{
PORTC = (LCDData >> 4) & 0x0F; // Get High 4 Bits for Output
RS = RSValue;
E = 1; E = 0; // Toggle the High 4 Bits Out
PORTC = LCDData & 0x0F; // Get Low 4 Bits for Output
RS = RSValue;
E = 1; E = 0; // Toggle the Low 4 Bits Out
if ((0 == (LCDData & 0xFC)) && (0 == RSValue))
n = Fivems; // Set Delay Interval
else
n = TwoHundredus;
for (k = 0; k < n; k++); // Delay for Character
} // End LCDWrite
main()
{
PORTC = 0; // Start with Everything Low
//CMCON0 = 7; // Turn off Comparators
ANSEL = 0; // Turn off ADC
TRISC = 0; // All of PORTC are Outputs
// Initialize LCD according to the Web Page
j = Twentyms;
for (i = 0; i < j; i++); // Wait for LCD to Power Up
PORTC = 3; // Start Initialization Process
E = 1; E = 0; // Send Reset Command
j = Fivems;
for (i = 0; i < j; i++);
E = 1; E = 0; // Repeat Reset Command
j = TwoHundredus;
for (i = 0; i < j; i++);
E = 1; E = 0; // Repeat Reset Command Third Time
j = TwoHundredus;
for (i = 0; i < j; i++);
PORTC = 2; // Initialize LCD 4 Bit Mode
E = 1; E = 0;
j = TwoHundredus;
for (i = 0; i < j; i++);
LCDWrite(0b00101000, 0); // LCD is 4 Bit I/F, 2 Line
LCDWrite(0b00000001, 0); // Clear LCD
LCDWrite(0b00000110, 0); // Move Cursor After Each Character
LCDWrite(0b00001110, 0); // Turn On LCD and Enable Cursor
for (i = 0; TopMessage[i] != 0; i++)
LCDWrite(TopMessage[i], 1);
LCDWrite(0b11000000, 0); // Move Cursor to the Second Line
for (i = 0; BotMessage[i] != 0; i++)
LCDWrite(BotMessage[i], 1);
while(1 == 1); // Finished
} // End cLCD
(http://i134.photobucket.com/albums/q118/shawn6901/PIC_LCD2.jpg)
Been busy lately only just got a chance to try it. What happened is the First row of digits lit up solid bars and the second row didn't light up. I removed the MCU and re-powered the circuit and same result indicating the LCD was acting alone when it lit up the first line with solid bars which means a software issue. Does anyone know of any good LCD driver code that I could use that's compatible with a Hitachi 44780 LCD controller.
*edit* I'm now useing different code and getting better results now a blinking cursor still can't get any text.
LCD.c
/*
* LCD interface example
* Uses routines from delay.c
* This code will interface to a standard LCD controller
* like the Hitachi HD44780. It uses it in 4 bit mode, with
* the hardware connected as follows (the standard 14 pin
* LCD connector is used):
*
* PORTC bits 0-3 are connected to the LCD data bits 4-7 (high nibble)
* PORTA bit 3 is connected to the LCD RS input (register select)
* PORTA bit 1 is connected to the LCD EN bit (enable)
*
* To use these routines, set up the port I/O (TRISA, TRISD) then
* call lcd_init(), then other routines as required.
*
*/
#ifndef _XTAL_FREQ
// Unless specified elsewhere, 4MHz system frequency is assumed
#define _XTAL_FREQ 20000000
#endif
#include <htc.h>
#include "c:\Projects\LCD_test1\lcd.h"
#define LCD_RS RB4
#define LCD_RW RB6
#define LCD_EN RB5
#define LCD_DATA PORTC
#define LCD_STROBE() ((LCD_EN = 1),(LCD_EN=0))
/* write a byte to the LCD in 4 bit mode */
void
lcd_write(unsigned char c)
{
__delay_us(40);
LCD_DATA = ( ( c >> 4 ) & 0x0F );
LCD_STROBE();
LCD_DATA = ( c & 0x0F );
LCD_STROBE();
}
/*
* Clear and home the LCD
*/
void
lcd_clear(void)
{
LCD_RS = 0;
lcd_write(0x1);
__delay_ms(2);
}
/* write a string of chars to the LCD */
void
lcd_puts(const char * s)
{
LCD_RS = 1; // write characters
while(*s)
lcd_write(*s++);
}
/* write one character to the LCD */
void
lcd_putch(char c)
{
LCD_RS = 1; // write characters
lcd_write( c );
}
/*
* Go to the specified position
*/
void
lcd_goto(unsigned char pos)
{
LCD_RS = 0;
lcd_write(0x80+pos); // origional
//lcd_write(0x20+pos); //temp
}
/* initialise the LCD - put into 4 bit mode */
void
lcd_init()
{
char init_value;
ADCON1 = 0x06; // Disable analog pins on PORTA
init_value = 0x3;
TRISB=0;
TRISC=0;
LCD_RS = 0;
LCD_EN = 0;
LCD_RW = 0;
__delay_ms(15); // wait 15mSec after power applied,
LCD_DATA = init_value;
LCD_STROBE();
__delay_ms(5);
LCD_STROBE();
__delay_us(200);
LCD_STROBE();
__delay_us(200);
LCD_DATA = 2; // Four bit mode
LCD_STROBE();
lcd_write(0x28); // Set interface length
lcd_write(0xF); // Display On, Cursor On, Cursor Blink
lcd_clear(); // Clear screen
lcd_write(0x6); // Set entry Mode
}
LCD.h
/*
* LCD interface header file
* See lcd.c for more info
*/
/* write a byte to the LCD in 4 bit mode */
extern void lcd_write(unsigned char);
/* Clear and home the LCD */
extern void lcd_clear(void);
/* write a string of characters to the LCD */
extern void lcd_puts(const char * s);
/* Go to the specified position */
extern void lcd_goto(unsigned char pos);
/* intialize the LCD - call before anything else */
extern void lcd_init(void);
extern void lcd_putch(char);
/* Set the cursor position */
#define lcd_cursor(x) lcd_write(((x)&0x7F)|0x80)
main.c
void
main(void)
{
lcd_init();
lcd_goto(0); // select first line
lcd_puts("123456789");
lcd_goto(0x40); // Select second line
lcd_puts("Oh Hai There");
for(;;);
}
also inorder to get the blinking cursor i need to comment out the following lines otherwise I just get all solid blocks on the first line and nothing on the second.
lcd_goto(0x40); // Select second line
lcd_puts("Oh Hai There");