I'm having trouble for creating a driver for a C-51505NFJ-SLW-AIN LCD display.
Here's my code:
#include<lpc17xx.h> #include "Board_LED.h"
/* Configure the data bus and Control bus as per the hardware connection */ #define LcdDataBusPort LPC_GPIO2->FIOPIN #define LcdControlBusPort LPC_GPIO0->FIOPIN
#define LcdDataBusDirnReg LPC_GPIO2->FIODIR #define LcdCtrlBusDirnReg LPC_GPIO0->FIODIR
#define LCD_RS 0 #define LCD_RW 1 #define LCD_EN 2
#define LCD_D4 0 #define LCD_D5 1 #define LCD_D6 2 #define LCD_D7 3
/* Masks for configuring the DataBus and Control Bus direction */ #define LCD_ctrlBusMask ((1<<LCD_RS)|(1<<LCD_RW)|(1<<LCD_EN)) #define LCD_dataBusMask ((1<<LCD_D4)|(1<<LCD_D5)|(1<<LCD_D6)|(1<<LCD_D7))
/* local function to generate some delay */ void delay_us(int cnt){
int i; for(i=0;i<cnt*20;i++); }
/* Function send the a nibble on the Data bus (LCD_D4 to LCD_D7) */ void sendNibble(char nibble){
LcdDataBusPort&=~(LCD_dataBusMask); // Clear previous data LcdDataBusPort|= (((nibble >>0x00) & 0x01) << LCD_D4); LcdDataBusPort|= (((nibble >>0x01) & 0x01) << LCD_D5); LcdDataBusPort|= (((nibble >>0x02) & 0x01) << LCD_D6); LcdDataBusPort|= (((nibble >>0x03) & 0x01) << LCD_D7); }
/* Function to send the command to LCD. As it is 4bit mode, a byte of data is sent in two 4-bit nibbles */ void Lcd_CmdWrite(char cmd){
sendNibble((cmd >> 0x04) & 0x0f); //Send higher nibble LcdControlBusPort &= ~(1<<LCD_RS); // Send LOW pulse on RS pin for selecting Command register LcdControlBusPort &= ~(1<<LCD_RW); // Send LOW pulse on RW pin for Write operation LcdControlBusPort |= (1<<LCD_EN); // Generate a High-to-low pulse on EN pin LED_On(0); delay_us(10000); LcdControlBusPort &= ~(1<<LCD_EN); LED_Off(0);
delay_us(10000);
sendNibble(cmd & 0x0f); //Send Lower nibble LcdControlBusPort &= ~(1<<LCD_RS); // Send LOW pulse on RS pin for selecting Command register LcdControlBusPort &= ~(1<<LCD_RW); // Send LOW pulse on RW pin for Write operation LcdControlBusPort |= (1<<LCD_EN); // Generate a High-to-low pulse on EN pin LED_On(0); delay_us(10000); LcdControlBusPort &= ~(1<<LCD_EN); LED_Off(0);
delay_us(10000); }
void Lcd_DataWrite(char dat){
sendNibble((dat >> 0x04) & 0x0f); //Send higher nibble LcdControlBusPort |= (1<<LCD_RS); // Send HIGH pulse on RS pin for selecting data register LcdControlBusPort &= ~(1<<LCD_RW); // Send LOW pulse on RW pin for Write operation LcdControlBusPort |= (1<<LCD_EN); // Generate a High-to-low pulse on EN pin delay_us(10000); LcdControlBusPort &= ~(1<<LCD_EN);
sendNibble(dat & 0x0f); //Send higher nibble LcdControlBusPort |= (1<<LCD_RS); // Send HIGH pulse on RS pin for selecting data register LcdControlBusPort &= ~(1<<LCD_RW); // Send LOW pulse on RW pin for Write operation LcdControlBusPort |= (1<<LCD_EN); // Generate a High-to-low pulse on EN pin delay_us(10000); LcdControlBusPort &= ~(1<<LCD_EN);
int main(){
char i,a[] = {"Hello, world!"}; LED_Initialize(); SystemInit(); //Clock and PLL configuration
LcdDataBusDirnReg = LCD_dataBusMask; // Configure all the LCD pins as output LcdCtrlBusDirnReg = LCD_ctrlBusMask;
LcdControlBusPort &= ~(1<<LCD_RS); LcdControlBusPort &= ~(1<<LCD_RW); LcdControlBusPort &= ~(1<<LCD_EN);
delay_us(1000);
Lcd_CmdWrite(0x02); // Initialize Lcd in 4-bit mode Lcd_CmdWrite(0x28); // enable 5x7 mode for chars Lcd_CmdWrite(0x0E); // Display OFF, Cursor ON Lcd_CmdWrite(0x01); // Clear Display Lcd_CmdWrite(0x80); // Move the cursor to beginning of first line
Lcd_DataWrite('H'); Lcd_DataWrite('e'); Lcd_DataWrite('l'); Lcd_DataWrite('l'); Lcd_DataWrite('o'); Lcd_DataWrite(' '); Lcd_DataWrite('w'); Lcd_DataWrite('o'); Lcd_DataWrite('r'); Lcd_DataWrite('l'); Lcd_DataWrite('d');
Lcd_CmdWrite(0xc0); for(i=0;a[i]!=0;i++){
Lcd_DataWrite(a[i]); } }
Does anyone know what am I doing wrong?
So what "trouble", exactly, are you having?
www.catb.org/.../smart-questions.html
What results are you seeing? What were you expecting? What testing/debugging/inspection have you done to determine what's going on?
Lots of code posted without the suggested code markup.
No description what problem you have.
No description what you have tried to overcome the problem.
Another thing - it's common to implement an output primitive that takes a string to avoid the need to multiple times write code to send out individual characters.
Sorry if I didn't especified my problem, but here it is. I'm trying to code a 20x2 lcd driver, I based my code on this tutorial exploreembedded.com/.../LPC1768:_Lcd_4bit, and I'm using this display: www.kyocera-display.com/.../C-51505NFJ-SLW-AIN_Eng.pdf. The hardware connections are all right. When I press the reset button of the board, the first line, blinks and nothing is shown. I thought it could be the delay speed, but I slowed it down. Now that's my problem, after the initialization process it should write "Hello world", but nothing happens.
Thanks
Again, what testing/debugging/inspection have you done to determine what's going on?
That tutorial describes what should happen on the signal lines between the LCD and your microcontroller - so have you checked what actually is happening ?