This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

lcd not working

hi
i am trying to interface an 16x2 lcd onto an arm7 board lpc2148. the pins i am using for the data is p0.16-p0.23
and for control signals ie rs rw e i am using p1.24 p1.25 p1.26 respectively.When i dump the following code nothing is getting changed in the display .can anybody help me out...i am attaching the code here ..kindly do the needful


#include<LPC214x.h>
void init_PLL(void);
void init_GPIO(void);
void lcd_data(unsigned char);
void lcd_cmd(unsigned char);
void lcd_init(void);
void delay(unsigned int);

#define E 0x04000000
#define RW 0x02000000
#define RS 0x01000000

int main(void)
{
        init_PLL();
        init_GPIO();
        lcd_init();
        while(1)
        {
                lcd_data('A');
                lcd_data('B');
                lcd_data(96);
                lcd_data('d');
                delay(0xffffff);
        }
}
void init_PLL(void)
{
        PLL0CFG=0x00000024; // TO GENERATE 60 MHZ CCLK
        PLL0CON=0x00000001;
        PLL0FEED=0x000000AA;//UPDATE THE PLL REGISTER
        PLL0FEED=0x00000055;
         while(!(PLL0STAT & 0x00000400)); // CHECK WHETHRT THE CCLK IS GENERATED EXAXT VALUE
        PLL0CON=0x00000003;  //  CONNECT PLL
        PLL0FEED=0x000000AA; //UPDATE THE PLL REGISTER
        PLL0FEED=0x00000055;
        VPBDIV=0x00000002;      //PCLK=1/2*CCLK
}
void init_GPIO( void)
{
        PINSEL0=0x00FF0000;
        PINSEL1=0x07000000;
        IODIR0=0x00FF0000;
        IODIR1=0x07000000;
}
void lcd_init(void)
{

        lcd_cmd(0x380000);
        delay(0xffffff);
        lcd_cmd(0x0e0000);
        delay(0xffffff);
        lcd_cmd(0x800000);
        delay(0xffffff);
        lcd_cmd(0x060000);
        delay(0xffffff);
}
unsigned int adjust_portbit(unsigned char c)
{
        unsigned char j;
        unsigned int result;
        result=c;
        for(j=0;j<16;j++)
        {
                result=result<<1;
        }
        return result;
}
void lcd_data(unsigned char ldata)
{
         unsigned int temp,z;
        temp=adjust_portbit(ldata);
    init_GPIO();
        z=~temp;
        IOCLR1=z;
        IOSET0=ldata;
        delay(0xffffff);
        IOCLR1=RW;
        IOSET1=RS;
        delay(0xffffff);
        IOSET1=E;
        delay(0xffffff);
        IOCLR1=E;
 }
  void lcd_cmd(unsigned char lcmd)
  {

        unsigned int temp,z;
                 temp=adjust_portbit(lcmd);
        init_GPIO();
        z=~temp;
                IOCLR1=z;
                IOSET0=lcmd;
                delay(0xffffff);
                IOCLR1=RW;
                IOCLR1=RS;
                IOSET1=E;
                delay(0xffffff);
                IOCLR1=E;

  }
  void delay(unsigned int value)
  {
         unsigned int i;
        for(i=0;i<value;i++);
        {

        }
  }

Parents
  • what a mess professor, this is a little better (I think):

    // time measurement in microseconds for an LPC2478 running at 72[MHz]. use for short delays only that depend
    // only on the speed of the processor.
    #define MICROSECONDS(x)                         (x*15)
    
    __asm void delay(int32u a_microseconds)
    {
    loop
             MOVS   R1, R0
             SUB    R0, R0, #1
             BNE    loop
    
             BX     LR
    }
    
    Usage:
    
    delay(MICROSECONDS(10) ) ;
    

Reply
  • what a mess professor, this is a little better (I think):

    // time measurement in microseconds for an LPC2478 running at 72[MHz]. use for short delays only that depend
    // only on the speed of the processor.
    #define MICROSECONDS(x)                         (x*15)
    
    __asm void delay(int32u a_microseconds)
    {
    loop
             MOVS   R1, R0
             SUB    R0, R0, #1
             BNE    loop
    
             BX     LR
    }
    
    Usage:
    
    delay(MICROSECONDS(10) ) ;
    

Children
  • what is missing if saving and restoring the values of R0 and R1 upon entry and exit.

  • Tapir

    Yo're work is quite acceptable but the macro ?

  • I'm proud you approve...take another look at the beginning of the code excerpt - the macro is there!

  • Timar

    yes i see the macro but why do u use? *15?

    my code is us as paramereter. and i donnot need the *15 :)

    Zeusti.

    Always your freind (and yors)

  • <qupote>
    I'll let you think about it.
    <end>

    must be becoz my code is designed better!

    Zeusti/

    Always the friend.

  • no. think again. you are a professor, after all.

  • <qiote>
    no. think again. you are a professor, after all.
    <end>

    i have already seen b4. you need macro bcoz you're code wants delay/15 . ok for beginer. if you have time to learn@ I can teach you.

    Zeusti/

    Always Your freind.

  • i have done a slight modification to the code that u have mentioned please kindly have a look at this code... i am getting these errors could u tell me why

    void delay()
    {
            __asm
            {
                    P1  MOV   R1,#11        ;R1 = 11
            P2  SUBS  R1,R1,#1          ;R1 = R1-1
            BNE   P2              ;Branch if not now nullified
            NOP                    ;A more delaying
    
            SUBS   R0,R0,#1       ;R0 = R0-1
            BNE    P1          ;BRANCH if NOW NOT NULLIFIED
    
            BX     LR           ;GO TO WHERE YOU CAME FROM
            }
    }
    

    the errors are
    LCD.C(19): error C197: inline-asm: Syntax error
    LCD.C(20): error C197: inline-asm: undefined identifier
    LCD.C(20): error C197: inline-asm: Syntax error
    LCD.C(24): error C197: inline-asm: undefined identifier
    LCD.C(24): error C197: inline-asm: Syntax error

  • __asm void delay(int32 usDelay)
    {
            P1    MOV   R1,#11        ;R1 = 11
            P2    SUBS  R1,R1,#1          ;R1 = R1-1
            BNE   P2              ;Branch if not now nullified
            NOP                    ;A more delaying
    
            SUBS   R0,R0,#1       ;R0 = R0-1
            BNE    P1          ;BRANCH if NOW NOT NULLIFIED
    
            BX     LR           ;GO TO WHERE YOU CAME FROM
    }
    

    Sorry but i canot try codeing atm.

    I think you SHOUJLD try it.

    Zeusti.

    Always yo're friend
    (and Timars!)

  • errors increased

    LCD20.C(28): error C25: syntax error near '__asm'
    LCD20.C(28): error C25: syntax error near 'usDelay'
    LCD20.C(29): warning C35: 'delay': uses old-style declarator
    LCD20.C(30): error C67: 'P1': undefined identifier
    LCD20.C(30): error C25: syntax error near 'MOV'
    LCD20.C(30): warning C34: 'R1': missing declaration specifiers
    LCD20.C(30): error C42: 'R1': not in formal parameter list
    LCD20.C(30): error C25: syntax error near '#'
    LCD20.C(30): error C142: illegal initialization
    LCD20.C(31): error C25: syntax error near 'P2'
    LCD20.C(31): warning C34: 'P2': missing declaration specifiers
    LCD20.C(31): error C42: 'P2': not in formal parameter list
    LCD20.C(31): warning C34: 'SUBS': missing declaration specifiers
    LCD20.C(31): error C42: 'SUBS': not in formal parameter list
    LCD20.C(31): warning C34: 'R1': missing declaration specifiers
    LCD20.C(31): error C42: 'R1': not in formal parameter list
    LCD20.C(31): warning C34: 'R1': missing declaration specifiers
    LCD20.C(31): error C42: 'R1': not in formal parameter list
    LCD20.C(31): error C25: syntax error near '#'
    LCD20.C(31): error C142: illegal initialization
    LCD20.C(31): error C67: 'R1': undefined identifier
    LCD20.C(32): error C53: redefinition of 'R1': different basic types
    LCD20.C(32): error C25: syntax error near 'BNE'
    LCD20.C(32): warning C34: 'BNE': missing declaration specifiers
    LCD20.C(32): error C42: 'BNE': not in formal parameter list
    LCD20.C(32): warning C34: 'P2': missing declaration specifiers
    LCD20.C(32): error C42: 'P2': not in formal parameter list
    LCD20.C(32): warning C34: 'Branch': missing declaration specifiers
    LCD20.C(32): error C42: 'Branch': not in formal parameter list
    LCD20.C(32): error C25: syntax error near 'if'
    LCD20.C(32): warning C34: 'not': missing declaration specifiers
    LCD20.C(32): error C42: 'not': not in formal parameter list
    LCD20.C(32): warning C34: 'now': missing declaration specifiers
    LCD20.C(32): error C42: 'now': not in formal parameter list
    LCD20.C(33): warning C34: 'nullified': missing declaration specifiers
    LCD20.C(33): error C42: 'nullified': not in formal parameter list
    LCD20.C(33): warning C34: 'NOP': missing declaration specifiers
    LCD20.C(33): error C42: 'NOP': not in formal parameter list
    LCD20.C(33): warning C34: 'A': missing declaration specifiers
    LCD20.C(33): error C42: 'A': not in formal parameter list
    LCD20.C(33): error C25: syntax error near 'more'
    LCD20.C(33): warning C34: 'more': missing declaration specifiers
    LCD20.C(33): error C42: 'more': not in formal parameter list
    LCD20.C(35): warning C34: 'delaying': missing declaration specifiers
    LCD20.C(35): error C42: 'delaying': not in formal parameter list
    LCD20.C(35): warning C34: 'SUBS': missing declaration specifiers
    LCD20.C(35): error C42: 'SUBS': not in formal parameter list
    LCD20.C(35): warning C34: 'R0': missing declaration specifiers
    LCD20.C(35): error C42: 'R0': not in formal parameter list
    LCD20.C(35): warning C34: 'R0': missing declaration specifiers
    LCD20.C(35): error C42: 'R0': not in formal parameter list
    LCD20.C(35): error C25: syntax error near '#'
    LCD20.C(35): error C142: illegal initialization
    LCD20.C(35): error C67: 'R0': undefined identifier
    LCD20.C(36): error C53: redefinition of 'R0': different basic types
    LCD20.C(36): error C25: syntax error near 'BNE'
    LCD20.C(36): error C7: compilation aborted

  • i have used this code ...but i am getting an error which is mentioned after the code

    void delay()__arm
    {
            __asm
            {
                    P1  MOV   R1,#11        ;R1 = 11
            P2  SUBS  R1,R1,#1          ;R1 = R1-1
            BNE   P2              ;Branch if not now nullified
            NOP                    ;A more delaying
    
            SUBS   R0,R0,#1       ;R0 = R0-1
            BNE    P1          ;BRANCH if NOW NOT NULLIFIED
    
            BX     LR           ;GO TO WHERE YOU CAME FROM
            }
    }
    

    error C197: inline-asm: Syntax error error C197: inline-asm: Syntax error

    the errors r shown at line starting with P2 an dthe other one BNE....kindly help

  • this is what you get when you use "professor" type code, I guess...simply put: if you plug my code into your program (not forgetting to adjust the "15" constant to your needs) you should be up and running in no time.