Hi,
I am trying to initialize my CFAH08 LCD but after power up and initialization I get the top row filled with black boxes and thats it. I have the contrast hooked up to a 10K pot and have adjusted that with no success. I have checked all my wiring with a multimeter and it all checks out. My guess is that there is something wrong with my code, but I have been over it a dozen times. I will check my wiring with an Oscope tomorrow, but if that is not the case then I am at a loss. My code is as follows:
lcd.h
lcd.c
driver.c
Any insight would be much appreciated.
- Nik
I am trying to initialize my CFAH08 LCD but after power up and initialization I get the top row filled with black boxes and thats it. I have the contrast hooked up to a 10K pot and have adjusted that with no success. I have checked all my wiring with a multimeter and it all checks out. My guess is that there is something wrong with my code, but I have been over it a dozen times. I will check my wiring with an Oscope tomorrow, but if that is not the case then I am at a loss. My code is as follows:
lcd.h
Code:
#ifndef LCD_H
#define LCD_H
#include <avr/io.h>
#include <inttypes.h>
#include "delay.h"
#define LCD_PORT PORTC
#define LCD_DDR DDRC
#define LCD_E 1
#define LCD_RS 2
#define LCD_RW 3
void lcd_init(void);
void lcd_port_init(void);
void lcd_cmd_write(uint8_t command);
void lcd_data_write(uint8_t command);
#endif
Code:
#include "lcd.h"
void lcd_init(void)
{
lcd_port_init();
delay_ms(50);
LCD_PORT &= ~((1 << LCD_RS) & (1 << LCD_RW));
// Ensure that the address is set
delay_us(50);
// Send 0x30 once
LCD_PORT = (LCD_PORT & 0x0F) | (0x0b00110000 & 0xF0);
delay_us(1);
LCD_PORT |= (1 << LCD_E);
delay_us(1);
LCD_PORT &= ~(1 << LCD_E);
delay_ms(5);
// Send 0x30 twice
LCD_PORT = (LCD_PORT & 0x0F) | (0x0b00110000 & 0xF0);
delay_us(1);
LCD_PORT |= (1 << LCD_E);
delay_us(1);
LCD_PORT &= ~(1 << LCD_E);
delay_ms(125);
// Send 0x30 three times
LCD_PORT = (LCD_PORT & 0x0F) | (0x0b00110000 & 0xF0);
delay_us(1);
LCD_PORT |= (1 << LCD_E);
delay_us(1);
LCD_PORT &= ~(1 << LCD_E);
delay_ms(5);
// Put the LCD in 4 bit mode
LCD_PORT = (LCD_PORT & 0x0F) | (0x0b00100000 & 0xF0);
delay_us(1);
LCD_PORT |= (1 << LCD_E);
delay_us(1);
LCD_PORT &= ~(1 << LCD_E);
delay_ms(5);
lcd_cmd_write(0b00101000);
lcd_cmd_write(0b00001000);
lcd_cmd_write(0b00000001);
lcd_cmd_write(0b00000110);
lcd_cmd_write(0x0F);
lcd_cmd_write(0x01);
delay_ms(500);
}
void lcd_port_init(void)
{
// Set the control pins to be output
LCD_DDR |= (1 << LCD_E) & (1 << LCD_RS) & (1 << LCD_RW);
// Set the data pins to be output
LCD_DDR |= (1 << 4) & (1 << 5) & (1 << 6) & (1 << 7);
}
void lcd_cmd_write(uint8_t command)
{
LCD_PORT &= ~((1 << LCD_RS) & (1 << LCD_RW));
// Ensure that the address is set
delay_us(1);
// Send the high nibble of the command
LCD_PORT = (LCD_PORT & 0x0F) | (command & 0xF0);
delay_us(1);
LCD_PORT |= (1 << LCD_E);
delay_us(1);
LCD_PORT &= ~(1 << LCD_E);
delay_us(1);
// Send the low nibble of the command
LCD_PORT = (LCD_PORT & 0x0F) | ((command << 4) & 0xF0);
delay_us(1);
LCD_PORT |= (1 << LCD_E);
delay_us(1);
LCD_PORT &= ~(1 << LCD_E);
delay_us(1);
}
void lcd_data_write(uint8_t command)
{
LCD_PORT |= (1 << LCD_RS);
LCD_PORT &= ~(1 << LCD_RW);
// Ensure that the address is set
delay_us(1);
// Send the high nibble of the command
LCD_PORT = (LCD_PORT & 0x0F) | (command & 0xF0);
delay_us(1);
LCD_PORT |= (1 << LCD_E);
delay_us(1);
LCD_PORT &= ~(1 << LCD_E);
delay_us(1);
// Send the low nibble of the command
LCD_PORT = (LCD_PORT & 0x0F) | ((command << 4) & 0xF0);
delay_us(1);
LCD_PORT |= (1 << LCD_E);
delay_us(1);
LCD_PORT &= ~(1 << LCD_E);
delay_us(1);
}
Code:
#include "lcd.h"
int main(void)
{
lcd_init();
lcd_data_write(0b01010111);
while(1 == 1);
}
- Nik
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.