Has anyone encountered similar situation with LCD.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Has anyone encountered similar situation with LCD.

497 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by black_ghost on Thu Oct 13 23:29:12 MST 2011
first of i think i have a bad lcd. when i power it on it doesnt display the solid square boxes. And when i tried to adjust the 10k tripot the lcd remains solid green. Before i seen flashes of solid squares and could adjust the contrast. I dont think my code is wrong cause i used a logic analyzer to to determine my pin output and could see when the signals were low and high. I have tried compiling my code but no success. As anyone encountered similar situation if so pls what do i do and below is my code to verify also.


#define NVIC_ST_CTRL_R          (*((volatile unsigned long *)0xE000E010))

#define NVIC_ST_RELOAD_R        (*((volatile unsigned long *)0xE000E014))

#define NVIC_ST_CURRENT_R       (*((volatile unsigned long *)0xE000E018))

#define NVIC_ST_CTRL_COUNT      0x00010000  // Count flag

#define NVIC_ST_CTRL_CLK_SRC    0x00000004  // Clock Source

#define NVIC_ST_CTRL_INTEN      0x00000002  // Interrupt enable

#define NVIC_ST_CTRL_ENABLE     0x00000001  // Counter mode

#define NVIC_ST_RELOAD_M        0x00FFFFFF  // Counter load value



void lcd_init(); //initialization of LCD.
void lcd_initwrite(uint8_t value);  //writes into 2 nibbles
void command(uint8_t value);  //command functions
void lcd_line1();
void lcd_string(char *a);
void print (char cmd);   //counter for 1ms SysTicks
// read current tick counter
//  SysTick_Handler - just increment SysTick counter
void SysTick_init(void);
void SysTick_Wait(unsigned long delay);
void SysTick_Wait10ms(unsigned long delay);

//initialization of LCD
void lcd_init()
{

    SysTick_Wait10ms(20); // sets delay off 20ms before powering up.
    lcd_initwrite(0x30);  // initialize commands for LCD
    SysTick_Wait10ms(10); //delays for more than 5ms.
    lcd_initwrite(0x30); 
    SysTick_Wait(10000); //delays for about 140micro seconds
    lcd_initwrite(0x30);
    SysTick_Wait(10000);
    lcd_initwrite(0x20); //initialization command for a 4 bit
    SysTick_Wait(10000);
    command(0x28);
    SysTick_Wait(120000);//set to 4 bit and 2 lines
    command(0x01);
    SysTick_Wait(120000);//clears the display
    command(0x06);
    SysTick_Wait(12000);//Entry mode for the LCD
    command(0x0E);  //Turn on the display
    SysTick_Wait(12000);
}
//sends the initialization commands
void lcd_initwrite(uint8_t value)
{
    LPC_GPIO0->FIOCLR |= (1<<9); // clears the RS signal
    LPC_GPIO0->FIOCLR |= (1<<8); // clears the RW signal

    //upper nibble and stores it in the data line d4-d7
    uint8_t bit[4];
    bit[0]=(value & 0x10)>>4;
    bit[1]=(value & 0x20)>>5;
    bit[2]=(value & 0x40)>>6;
    bit[3]=(value & 0x80)>>7;
    bit[0] ? (LPC_GPIO0->FIOSET = (1<<6)) : (LPC_GPIO0->FIOCLR = (1<<6));
    bit[1] ? (LPC_GPIO0->FIOSET = (1<<0)) : (LPC_GPIO0->FIOCLR = (1<<0));
    bit[2] ? (LPC_GPIO0->FIOSET = (1<<1)) : (LPC_GPIO0->FIOCLR = (1<<1));
    bit[3] ? (LPC_GPIO0->FIOSET = (1<<18)) :(LPC_GPIO0->FIOCLR = (1<<18));
    LPC_GPIO0->FIOSET |= (1<<7); //sets the enable pin
    SysTick_Wait(10000);                 //lms second delay
    LPC_GPIO0->FIOCLR |= (1<<7); //clears the enable pin
}

void command(uint8_t value)
{
    uint8_t bit[4];

    LPC_GPIO0->FIOCLR |= (1<<9); //RW is low
    LPC_GPIO0->FIOCLR |= (1<<8); //RS is set low
    //upper nibble and sending the data to the ports
    bit[0] = (value & 0x10) >> 4;
    bit[1] = (value & 0x20) >> 5;
    bit[2] = (value & 0x40) >> 6;
    bit[3] = (value & 0x80) >> 7;
    bit[0] ? (LPC_GPIO0->FIOSET = (1<<6))  : (LPC_GPIO0->FIOCLR = (1<<6));
    bit[1] ? (LPC_GPIO0->FIOSET = (1<<0))  : (LPC_GPIO0->FIOCLR = (1<<0));
    bit[2] ? (LPC_GPIO0->FIOSET = (1<<1))  : (LPC_GPIO0->FIOCLR = (1<<1));
    bit[3] ? (LPC_GPIO0->FIOSET = (1<<18)) : (LPC_GPIO0->FIOCLR = (1<<18));
    LPC_GPIO0->FIOSET |= (1<<7);
    SysTick_Wait(10000);
    LPC_GPIO0->FIOCLR |= (1<<7);

  //lower nibble and stores the value in the data port
    bit[0]=(value & 0x01)>>0;
    bit[1]=(value & 0x02)>>1;
    bit[2]=(value & 0x04)>>2;
    bit[3]=(value & 0x08)>>3;
    bit[0] ? (LPC_GPIO0->FIOSET = (1<<6)) : (LPC_GPIO0->FIOCLR = (1<<6));
    bit[1] ? (LPC_GPIO0->FIOSET = (1<<0)) : (LPC_GPIO0->FIOCLR = (1<<0));
    bit[2] ? (LPC_GPIO0->FIOSET = (1<<1)) : (LPC_GPIO0->FIOCLR = (1<<1));
    bit[3] ? (LPC_GPIO0->FIOSET = (1<<18)): (LPC_GPIO0->FIOCLR = (1<<18));
    LPC_GPIO0->FIOSET |= (1<<7);
    SysTick_Wait(10000);
    LPC_GPIO0->FIOCLR |= (1<<7);
    SysTick_Wait(10000);
}

//instruction command for setting up line 1.
void lcd_line1()
{
    command(0x80);
}
//displays characters on LCD
void print(char cmd)
{
        SysTick_Wait(4000);
        uint8_t bit[4]; //array of 4bits
        LPC_GPIO0->FIOCLR |= (1<<8); //RW is 0
        LPC_GPIO0->FIOSET |= (1<<9); //sets RS = 1;

        //upper nibble
        bit[0] = (cmd & 0x10) >> 4; //
        bit[1] = (cmd & 0x20) >> 5;
        bit[2] = (cmd & 0x40) >> 6;
        bit[3] = (cmd & 0x80) >> 7;
        bit[0] ? (LPC_GPIO0->FIOSET = (1<<6)) : (LPC_GPIO0->FIOCLR =  (1<<6));
        bit[1] ? (LPC_GPIO0->FIOSET = (1<<0)) : (LPC_GPIO0->FIOCLR =  (1<<0));
        bit[2] ? (LPC_GPIO0->FIOSET = (1<<1)) : (LPC_GPIO0->FIOCLR =  (1<<1));
        bit[3] ? (LPC_GPIO0->FIOSET = (1<<18)): (LPC_GPIO0->FIOCLR =  (1<<18));
        LPC_GPIO0->FIOSET |= (1<<7); //sets Enable pin
        SysTick_Wait(10000);
        LPC_GPIO0->FIOCLR |= (1<<7); //clear enable pin
        SysTick_Wait(10000);


        //lower nibble
        bit[0]=(cmd & 0x01)>>0;
        bit[1]=(cmd & 0x02)>>1;
        bit[2]=(cmd & 0x04)>>2;
        bit[3]=(cmd & 0x08)>>3;
        bit[0] ? (LPC_GPIO0->FIOSET = (1<<6))  : (LPC_GPIO0->FIOCLR = (1<<6));
        bit[1] ? (LPC_GPIO0->FIOSET = (1<<0))  : (LPC_GPIO0->FIOCLR = (1<<0));
        bit[2] ? (LPC_GPIO0->FIOSET = (1<<1))  : (LPC_GPIO0->FIOCLR = (1<<1));
        bit[3] ? (LPC_GPIO0->FIOSET = (1<<18)) : (LPC_GPIO0->FIOCLR = (1<<18));
        LPC_GPIO0->FIOSET |= (1<<7); //sets enable to high
        SysTick_Wait(10000);
        LPC_GPIO0->FIOCLR |= (1<<7); //sets enable pin to low
        SysTick_Wait(10000);
}
void lcd_string(char *a)
{

while (*a != '\0')
  {
    print(*a);
    a++;
  }
}


    void SysTick_Init(void)
{

      NVIC_ST_CTRL_R = 0;                   // disable SysTick during setup

      NVIC_ST_RELOAD_R = NVIC_ST_RELOAD_M;  // maximum reload value

      NVIC_ST_CURRENT_R = 0;
      // enable SysTick with core clock

        NVIC_ST_CTRL_R = NVIC_ST_CTRL_ENABLE+NVIC_ST_CTRL_CLK_SRC;

  }

    // Time delay using busy wait.


    void SysTick_Wait(unsigned long delay)
    {

      volatile unsigned long elapsedTime;

      unsigned long startTime = NVIC_ST_CURRENT_R;

      do{

        elapsedTime = (startTime-NVIC_ST_CURRENT_R)&0x00FFFFFF;

      }

      while(elapsedTime <= delay);

    }

    // Time delay using busy wait.

    // 10000us equals 10ms

    void SysTick_Wait10ms(unsigned long delay)
    {

      unsigned long i;

      for(i=0; i<delay; i++){

        SysTick_Wait(60000);  // wait 10ms (assumes 6 MHz clock)

      }

    }


int main(void)
{
    //selecting my data line pins on port 1
    LPC_PINCON->PINSEL0 = 0x00000000;
    LPC_GPIO0->FIODIR = 0x000403C3;      //selecting to outputs on port 0.
    LPC_GPIO0->FIOCLR = 0x000403C3;    //clears the port 0.

    SysTick_Init();
    lcd_init();
    while(1)
    {
        lcd_line1();
        lcd_string("Hello.");
        SysTick_Wait(10000);

    }

    return 0 ;
}
0 Kudos
9 Replies

435 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by black_ghost on Sat Oct 15 17:08:48 MST 2011

Quote: Luis Digital
LPC1768 = 100 MHz
LPC1769 = 120 MHz

The memory size is the same. Important to note that changing the processor in use, does not change the speed (you have to modify the initialization files manually).



i am using the systick operation as a time delay for my lcd but i am trying how to implement i think i have the right approach but don't know how to implement using interrupts do u have an idea or a better approach below is my code
#define NVIC_ST_CTRL_R          (*((volatile unsigned long *)0xE000E010))

#define NVIC_ST_RELOAD_R        (*((volatile unsigned long *)0xE000E014))

#define NVIC_ST_CURRENT_R       (*((volatile unsigned long *)0xE000E018))

#define NVIC_ST_CTRL_COUNT      0x00010000  // Count flag

#define NVIC_ST_CTRL_CLK_SRC    0x00000004  // Clock Source

#define NVIC_ST_CTRL_INTEN      0x00000002  // Interrupt enable

#define NVIC_ST_CTRL_ENABLE     0x00000001  // Counter mode

#define NVIC_ST_RELOAD_M        0x00FFFFFF  // Counter load value
void SysTick_init(void);
void SysTick_Wait(unsigned long delay);
void SysTick_Wait10ms(unsigned long delay);
void SysTick_Init(void)
{

      NVIC_ST_CTRL_R = 0;                   // disable SysTick during setup

      NVIC_ST_RELOAD_R = NVIC_ST_RELOAD_M;  // maximum reload value

      NVIC_ST_CURRENT_R = 0;
      // enable SysTick with core clock

        NVIC_ST_CTRL_R = NVIC_ST_CTRL_ENABLE+NVIC_ST_CTRL_CLK_SRC;

  }

    // Time delay using busy wait.


    void SysTick_Wait(unsigned long delay)
    {

      volatile unsigned long elapsedTime;

      unsigned long startTime = NVIC_ST_CURRENT_R;

      do{

        elapsedTime = (startTime-NVIC_ST_CURRENT_R)&0x00FFFFFF;

      }

      while(elapsedTime <= delay);

    }

    // Time delay using busy wait.

    // 10000us equals 10ms

    void SysTick_Wait10ms(unsigned long delay)
    {

      unsigned long i;

      for(i=0; i<delay; i++){

        SysTick_Wait(1000000);  // wait 10ms (assumes 100MHz clock)

      }

    }
0 Kudos

435 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Luis Digital on Sat Oct 15 06:45:30 MST 2011
LPC1768 = 100 MHz
LPC1769 = 120 MHz

The memory size is the same. Important to note that changing the processor in use, does not change the speed (you have to modify the initialization files manually).
0 Kudos

435 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by OXO on Sat Oct 15 01:08:10 MST 2011

Quote: black_ghost
I looked and couldnt find any example. the only example i came across was based on LPC1768 and not LPC1769. i imported the project and couldnt compile it on LPC1769. I am trying to use systick as a time delay to drive a 16x2 lcd using a 4bit interface. If you have an idea that would really help thanks.



Other than memory sizes, 1768 and 1769 are the same. You really need to get to grips with the tools.
0 Kudos

435 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by black_ghost on Fri Oct 14 16:23:51 MST 2011

Quote: whitecoe
Sorry, I just have to ask - have you actually looked at any of the code provided along with LPCXpresso IDE????

There are several that make use of the sys tick timer that would show you exactly how to set this up, and to use it to create a delay loop.


I looked and couldnt find any example. the only example i came across was based on LPC1768 and not LPC1769. i imported the project and couldnt compile it on LPC1769. I am trying to use systick as a time delay to drive a 16x2 lcd using a 4bit interface. If you have an idea that would really help thanks.
0 Kudos

435 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by whitecoe on Fri Oct 14 11:06:15 MST 2011
Sorry, I just have to ask - have you actually looked at any of the code provided along with LPCXpresso IDE????

There are several that make use of the sys tick timer that would show you exactly how to set this up, and to use it to create a delay loop.
0 Kudos

435 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by black_ghost on Fri Oct 14 09:45:49 MST 2011

Quote: gbm
Look at this:
elapsedTime = (startTime-NVIC_ST_CURRENT_R)&0x00FFFFFF

and change the order of args in subtraction.
BTW. It-s not a good technique for delays but should work ok until you relize what interrupts are. ;)



Ok so i changed the order of the args but i think my 16x2 lcd is bad cause i cant see the solid squares and using the tripot it still doesnt adjust the contrast. I read sys_tick operation from the user manual but you could explain me to how i could use the interrupts in this situation or go about using the interrupt as i dont have a clear understanding to implement it. I am a newbie by the way. Thanks.
0 Kudos

435 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Fri Oct 14 08:59:52 MST 2011
Look at this:
elapsedTime = (startTime-NVIC_ST_CURRENT_R)&0x00FFFFFF

and change the order of args in subtraction.
BTW. It-s not a good technique for delays but should work ok until you relize what interrupts are. ;)
0 Kudos

435 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by black_ghost on Fri Oct 14 01:43:20 MST 2011
oh that was error by me typing lol. the sad face was about the lcd not successfully working
0 Kudos

434 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by StephenHawkings on Fri Oct 14 01:24:47 MST 2011
Probably you need to look at this line of code:

bit[3] ? (LPC_GPIO0->FIOSET = (1<<18)) :(LPC_GPIO0->FIOCLR = (1<<18));

Best regards
SH
0 Kudos