Hi, I am trying to initialize a CFAH0802D using a PIC16F874a Hi tech C compiler in MP Lab, however I can only get the top row of boxes to light up. There seems to be an issue with my initialization routine. I attached my code, along with the schematic of my setup. I have added various delays in between commands to see if that will help, but it hasn't. If anyone has any suggestions, please let me know. Thanks.
my main is
And LCD.c, where initialization is
my main is
Code:
#include <pic.h>
#include "htc.h"
#include <stdio.h>
#include "LCD.h"
#include "delay.h"
#define _XTAL_FREQ 3580420
__CONFIG(FOSC_XT & WDTE_OFF& PWRTE_OFF & BOREN_OFF & LVP_OFF & WRT_OFF & DEBUG_ON & CPD_OFF & CP_OFF);
main()
{
lcd_clear();
lcd_init();
__delay_ms(500);
lcd_puts("test");
for(;;);
}
Code:
/*
* 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):
*
* PORTD 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 3580420
#endif
#include <htc.h>
#include "lcd.h"
#define LCD_RS RA3
#define LCD_RW RA2
#define LCD_EN RA1
#define LCD_DATA PORTD
#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);
}
/* initialise the LCD - put into 4 bit mode */
void
lcd_init()
{
char init_value;
ADCON1 = 0x06; // Disable analog pins on PORTA
init_value = 0x3;
TRISA=0;
TRISD=0;
LCD_RS = 0;
LCD_EN = 0;
LCD_RW = 0;
__delay_ms(500); // wait 15mSec after power applied, changed from 5ms
LCD_DATA = init_value;
LCD_STROBE();
__delay_ms(500); //changed from 5ms
LCD_STROBE();
__delay_us(500); //changed from 200
LCD_STROBE();
__delay_us(500); //changed from 200
LCD_DATA = 2; // Four bit mode
LCD_STROBE();
lcd_write(0x28); // Set interface length
__delay_ms(500); //changed from 5ms
lcd_write(0xF); // Display On, Cursor On, Cursor Blink
__delay_ms(500); //changed from 5ms
lcd_clear(); // Clear screen
__delay_ms(500); //changed from 5ms
lcd_write(0x6); // Set entry Mode
}
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
Attachments
-
866.3 KB Views: 905