EmbeddedRelated.com
Forums
Memfault Beyond the Launch

LPC and LCD problem

Started by zanakca January 16, 2009
Hello community !

I anything on the LCD.

here is the interfacing :

P0.4 -> D4
P0.5 -> D5
P0.6 -> D6
P0.7 -> D7

P4.15 -> E
P4.27 -> RS
P4.29 -> RW

Code:
#include "lpc2468_registers.h"
#include "lcd.h"

#define BUSY_MASK 0x00000080

#define TRUE 1
#define FALSE 0

void InitLeds(void);

void InitPLL(void);
void feed(void);

void IRQ_Routine (void) __attribute__ ((interrupt("IRQ")));
void FIQ_Routine (void) __attribute__ ((interrupt("FIQ")));
void SWI_Routine (void) __attribute__ ((interrupt("SWI")));
void UNDEF_Routine (void) __attribute__ ((interrupt("UNDEF")));
/* return TRUE if the button is pressed */
int But1Pressed(void)
{
if (FIO2PIN & (1<<13)) return FALSE;
else return TRUE;
}
int But2Pressed(void)
{
if (FIO2PIN & (1<<21)) return FALSE;
else return TRUE;
}

void Delay(void)
{
int j;
for (j = 0; j < 10000; j++ );
}
void lcd_string(char *senpoint)
{
while(*senpoint != '\0')
{
lcd_char(*senpoint);
senpoint++;
}
}

void lcd_line1(void)
{
lcd_cmd(0x80);
}

void lcd_line2(void)
{
lcd_cmd(0xc0);
}

void lcd_line3(void)
{
lcd_cmd(0x94);
}

void lcd_line4(void)
{
lcd_cmd(0xd4);
}

void lcd_cmd(unsigned char letter)
{
unsigned char temp;
temp=letter;
temp=temp>>4;
lcd_nybble(temp,0);
temp=letter;
temp=temp&0x0f;
lcd_nybble(temp,0);
}

void lcd_char(unsigned char letter)
{
unsigned char temp;
temp=letter;
temp=temp>>4;
lcd_nybble(temp,1);
temp=letter;
temp=temp&0x0f;
lcd_nybble(temp,1);
}

void lcd_nybble(unsigned char nyb,unsigned char rs)
{
int i,dat;
if(rs)
FIO4SET |= 1<<27; //set RS pin
else
FIO4CLR |= 1<<27; //clear RS pin
dat = nyb; //get the nybble in an int

FIO0CLR |= 1<<4; // D4
FIO0CLR |= 1<<5; // D5
FIO0CLR |= 1<<6; // D6
FIO0CLR |= 1<<7; // D7

FIO0SET |= dat<<4; //OR the bits in there
strobe_e(); //latch data to LCD
}

void lcd_init(void)
{
delay_ms(500); //settle time delay
lcd_nybble(0x03,0); //reset LCD
lcd_nybble(0x03,0);
lcd_nybble(0x03,0);
delay_ms(5);
strobe_e();
delay_us(160);
strobe_e();
delay_us(160);
lcd_nybble(0x02,0);
delay_us(160);
lcd_cmd(0x28); //set 4-bit mode and 2 lines
delay_us(160);
lcd_cmd(0x10); //cursor move & shift left
delay_us(160);
lcd_cmd(0x06); //entry mode = increment
delay_us(160);
lcd_cmd(0x0e); //display on - cursor blink on
delay_us(160);
lcd_cmd(0x01); //clear display
delay_ms(40);
}

void strobe_e(void)
{
FIO4SET |= 1<<15;
delay_us(1);
FIO4CLR |= 1<<15;
delay_us(160);
}

void delay_ms(int x)
{
int a,b;
for(a=0;a for(b=0;b<3500;b++);
}
}

void delay_us(int x)
{
int a,b;
for(a=0;a for(b=0;b<4;b++);
}
/* return TRUE if the RTC is OK */
int TestRTC(void)
{
int timeout = 1000000;
RTC_CCR = 0;
RTC_SEC = 0x00;
RTC_CCR = 1<<1; /* clear the counter */
RTC_CCR = 1<<0 | 1<<4; /* enable the clock using the external xtal */

while (timeout--);
timeout = RTC_CTC;

if ((1550 < timeout) & (timeout < 1600)) return TRUE;

return FALSE;
}

int main (void) {

int j; // loop counter (stack variable)
//InitPLL();

SCS |= 1<<0; /* enable fast IO on ports 0&1 */

InitLeds();

for (j = 0; j < 200000; j++);
lcd_init();
while(1){
lcd_line1();
lcd_string("LPC2148 LCD");
delay_ms(1000);
lcd_line2();
lcd_string("It works!");
lcd_line3();
lcd_string("Line 3 here.");
lcd_line4();
lcd_string("Here is line 4!");
delay_ms(1000);
}

}
#define PLL_MValue 11
#define PLL_NValue 0
#define CCLKDivValue 4
#define USBCLKDivValue 5

void InitPLL(void)
{

volatile unsigned long MValue;
volatile unsigned long NValue;

if ( PLLSTAT & (1 << 25) )
{
PLLCON = 1; /* Enable PLL, disconnected */
PLLFEED = 0xaa;
PLLFEED = 0x55;
}

PLLCON = 0; /* Disable PLL, disconnected */
PLLFEED = 0xaa;
PLLFEED = 0x55;

SCS |= 0x20; /* Enable main OSC */
while( !(SCS & 0x40) ); /* Wait until main OSC is usable */

CLKSRCSEL = 0x1; /* select main OSC, 12MHz, as the PLL clock
source */

PLLCFG = PLL_MValue | (PLL_NValue << 16);
PLLFEED = 0xaa;
PLLFEED = 0x55;

PLLCON = 1; /* Enable PLL, disconnected */
PLLFEED = 0xaa;
PLLFEED = 0x55;

CCLKCFG = CCLKDivValue; /* Set clock divider */

while ( ((PLLSTAT & (1 << 26)) == 0) ); /* Check lock bit status */

MValue = PLLSTAT & 0x00007FFF;
NValue = (PLLSTAT & 0x00FF0000) >> 16;
while ((MValue != PLL_MValue) && ( NValue != PLL_NValue) );

PLLCON = 3; /* enable and connect */
PLLFEED = 0xaa;
PLLFEED = 0x55;
while ( ((PLLSTAT & (1 << 25)) == 0) ); /* Check connect bit
status */
}
void InitLeds(void)
{

FIO4DIR |= 1<<17; /* STAT1&2 as out */
FIO4DIR |= 1<<16;

FIO0DIR |= 1<<4; // D4
FIO0DIR |= 1<<5; // D5
FIO0DIR |= 1<<6; // D6
FIO0DIR |= 1<<7; // D7

FIO4DIR |= 1<<15; // E
FIO4DIR |= 1<<27; // RS
FIO4DIR |= 1<<29; // RW
}
/* Stubs for various interrupts (may be replaced later) */
/* ---------------- */

void IRQ_Routine (void) {
while (1) ;
}

void FIQ_Routine (void) {
while (1) ;
}
void SWI_Routine (void) {
while (1) ;
}
void UNDEF_Routine (void) {
while (1) ;
}

PLEASE HELP !!! I'M REACHING PROJECT DEADLINES Razz

An Engineer's Guide to the LPC2100 Series

You're doing it wrong.
FIO0CLR |= 1<<4; // D4
FIO0CLR |= 1<<5; // D5
FIO0CLR |= 1<<6; // D6
FIO0CLR |= 1<<7; // D7

FIO0SET |= dat<<4; //OR the bits in there

You don't |=, you assign these directly. It may not fix other problems you
have, but this certainly isn't correct.

On Fri, Jan 16, 2009 at 5:01 PM, zanakca wrote:

> Hello community !
>
> I > anything on the LCD.
>
> here is the interfacing :
>
> P0.4 -> D4
> P0.5 -> D5
> P0.6 -> D6
> P0.7 -> D7
>
> P4.15 -> E
> P4.27 -> RS
> P4.29 -> RW
>
> Code:
>
> #include "lpc2468_registers.h"
> #include "lcd.h"
>
> #define BUSY_MASK 0x00000080
>
> #define TRUE 1
> #define FALSE 0
>
> void InitLeds(void);
>
> void InitPLL(void);
> void feed(void);
>
> void IRQ_Routine (void) __attribute__ ((interrupt("IRQ")));
> void FIQ_Routine (void) __attribute__ ((interrupt("FIQ")));
> void SWI_Routine (void) __attribute__ ((interrupt("SWI")));
> void UNDEF_Routine (void) __attribute__ ((interrupt("UNDEF")));
>
> /* return TRUE if the button is pressed */
> int But1Pressed(void)
> {
> if (FIO2PIN & (1<<13)) return FALSE;
> else return TRUE;
> }
> int But2Pressed(void)
> {
> if (FIO2PIN & (1<<21)) return FALSE;
> else return TRUE;
> }
>
> void Delay(void)
> {
> int j;
> for (j = 0; j < 10000; j++ );
> }
>
> void lcd_string(char *senpoint)
> {
> while(*senpoint != '\0')
> {
> lcd_char(*senpoint);
> senpoint++;
> }
> }
>
> void lcd_line1(void)
> {
> lcd_cmd(0x80);
> }
>
> void lcd_line2(void)
> {
> lcd_cmd(0xc0);
> }
>
> void lcd_line3(void)
> {
> lcd_cmd(0x94);
> }
>
> void lcd_line4(void)
> {
> lcd_cmd(0xd4);
> }
>
> void lcd_cmd(unsigned char letter)
> {
> unsigned char temp;
> temp=letter;
> temp=temp>>4;
> lcd_nybble(temp,0);
> temp=letter;
> temp=temp&0x0f;
> lcd_nybble(temp,0);
> }
>
> void lcd_char(unsigned char letter)
> {
> unsigned char temp;
> temp=letter;
> temp=temp>>4;
> lcd_nybble(temp,1);
> temp=letter;
> temp=temp&0x0f;
> lcd_nybble(temp,1);
> }
>
> void lcd_nybble(unsigned char nyb,unsigned char rs)
> {
> int i,dat;
> if(rs)
> FIO4SET |= 1<<27; //set RS pin
> else
> FIO4CLR |= 1<<27; //clear RS pin
> dat = nyb; //get the nybble in an int
>
> FIO0CLR |= 1<<4; // D4
> FIO0CLR |= 1<<5; // D5
> FIO0CLR |= 1<<6; // D6
> FIO0CLR |= 1<<7; // D7
>
> FIO0SET |= dat<<4; //OR the bits in there
> strobe_e(); //latch data to LCD
> }
>
> void lcd_init(void)
> {
> delay_ms(500); //settle time delay
> lcd_nybble(0x03,0); //reset LCD
> lcd_nybble(0x03,0);
> lcd_nybble(0x03,0);
> delay_ms(5);
> strobe_e();
> delay_us(160);
> strobe_e();
> delay_us(160);
> lcd_nybble(0x02,0);
> delay_us(160);
> lcd_cmd(0x28); //set 4-bit mode and 2 lines
> delay_us(160);
> lcd_cmd(0x10); //cursor move & shift left
> delay_us(160);
> lcd_cmd(0x06); //entry mode = increment
> delay_us(160);
> lcd_cmd(0x0e); //display on - cursor blink on
> delay_us(160);
> lcd_cmd(0x01); //clear display
> delay_ms(40);
> }
>
> void strobe_e(void)
> {
> FIO4SET |= 1<<15;
> delay_us(1);
> FIO4CLR |= 1<<15;
> delay_us(160);
> }
>
> void delay_ms(int x)
> {
> int a,b;
> for(a=0;a > for(b=0;b<3500;b++);
> }
> }
>
> void delay_us(int x)
> {
> int a,b;
> for(a=0;a > for(b=0;b<4;b++);
> }
>
> /* return TRUE if the RTC is OK */
> int TestRTC(void)
> {
> int timeout = 1000000;
> RTC_CCR = 0;
> RTC_SEC = 0x00;
> RTC_CCR = 1<<1; /* clear the counter */
> RTC_CCR = 1<<0 | 1<<4; /* enable the clock using the external xtal */
>
> while (timeout--);
> timeout = RTC_CTC;
>
> if ((1550 < timeout) & (timeout < 1600)) return TRUE;
>
> return FALSE;
> }
>
> int main (void) {
>
> int j; // loop counter (stack variable)
> //InitPLL();
>
> SCS |= 1<<0; /* enable fast IO on ports 0&1 */
>
> InitLeds();
> for (j = 0; j < 200000; j++);
> lcd_init();
> while(1){
> lcd_line1();
> lcd_string("LPC2148 LCD");
> delay_ms(1000);
> lcd_line2();
> lcd_string("It works!");
> lcd_line3();
> lcd_string("Line 3 here.");
> lcd_line4();
> lcd_string("Here is line 4!");
> delay_ms(1000);
> }
>
> }
>
> #define PLL_MValue 11
> #define PLL_NValue 0
> #define CCLKDivValue 4
> #define USBCLKDivValue 5
>
> void InitPLL(void)
> {
>
> volatile unsigned long MValue;
> volatile unsigned long NValue;
>
> if ( PLLSTAT & (1 << 25) )
> {
> PLLCON = 1; /* Enable PLL, disconnected */
> PLLFEED = 0xaa;
> PLLFEED = 0x55;
> }
>
> PLLCON = 0; /* Disable PLL, disconnected */
> PLLFEED = 0xaa;
> PLLFEED = 0x55;
>
> SCS |= 0x20; /* Enable main OSC */
> while( !(SCS & 0x40) ); /* Wait until main OSC is usable */
>
> CLKSRCSEL = 0x1; /* select main OSC, 12MHz, as the PLL clock
> source */
>
> PLLCFG = PLL_MValue | (PLL_NValue << 16);
> PLLFEED = 0xaa;
> PLLFEED = 0x55;
>
> PLLCON = 1; /* Enable PLL, disconnected */
> PLLFEED = 0xaa;
> PLLFEED = 0x55;
>
> CCLKCFG = CCLKDivValue; /* Set clock divider */
>
> while ( ((PLLSTAT & (1 << 26)) == 0) ); /* Check lock bit status */
>
> MValue = PLLSTAT & 0x00007FFF;
> NValue = (PLLSTAT & 0x00FF0000) >> 16;
> while ((MValue != PLL_MValue) && ( NValue != PLL_NValue) );
>
> PLLCON = 3; /* enable and connect */
> PLLFEED = 0xaa;
> PLLFEED = 0x55;
> while ( ((PLLSTAT & (1 << 25)) == 0) ); /* Check connect bit
> status */
> }
>
> void InitLeds(void)
> {
>
> FIO4DIR |= 1<<17; /* STAT1&2 as out */
> FIO4DIR |= 1<<16;
>
> FIO0DIR |= 1<<4; // D4
> FIO0DIR |= 1<<5; // D5
> FIO0DIR |= 1<<6; // D6
> FIO0DIR |= 1<<7; // D7
>
> FIO4DIR |= 1<<15; // E
> FIO4DIR |= 1<<27; // RS
> FIO4DIR |= 1<<29; // RW
> }
>
> /* Stubs for various interrupts (may be replaced later) */
> /* ---------------- */
>
> void IRQ_Routine (void) {
> while (1) ;
> }
>
> void FIQ_Routine (void) {
> while (1) ;
> }
>
> void SWI_Routine (void) {
> while (1) ;
> }
>
> void UNDEF_Routine (void) {
> while (1) ;
> }
>
> PLEASE HELP !!! I'M REACHING PROJECT DEADLINES Razz
>
>
>


Memfault Beyond the Launch