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
  • 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

Reply
  • 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

Children
  • 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.

  • Hello.

    I now have tryed the code and it worked in C.

    You MUST PUT code like here with P1 and P2 in columen 1! becoz it is then a label.

    You chek the int32 for you .you

    __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
    }
    

    Zeusti/

    Always Your Freind
    (and Tamers)

  • Tamer.

    plz do not be offended . if other people like my anserws more than yo'rs.

    Zeusti,.

    Always your freind.

  • using port no p1 24-31 for data bits and p0.12 13 15 for rs rw and e bits respectively..i am trying to display the characters in the code but nothing comes up on the display and neither the inituialization commands are working kindly help

    #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 0x00008000
    //#define RW 0x00002000
    //#define RS 0x00001000
    
    /*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
            }
    }
     */
     void delay()__arm
    {
    
    __asm
    {
    MOV R3,R0
    loop:
    MOV R1,#11         ;R1 = 11
    loop1:
    SUB  R1,R1,#1      ;R1 = R1-1
    BNE   loop1           ;Branch if not now nullified
    NOP                ;A more delaying
    SUB   R0,R0,#1     ;R0 = R0-1
    BNE    loop          ;BRANCH if NOW NOT NULLIFIED
    BX     LR          ;GO TO WHERE YOU CAME FROM
    }
    }
    int main(void)
    {
            init_PLL();
            init_GPIO();
            lcd_init();
            while(1)
            {
                    lcd_data('A');
                    lcd_data('B');
                    lcd_data(96);
                    lcd_data(0x95);
    
            }
    }
    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)
    {
            PINSEL1=0xFF000000;
            PINSEL0=0x0000B000;
            IODIR1=0xFF000000;
            IODIR0=0x0000B000;
    }
    void lcd_init(void)
    {
    
            lcd_cmd(0x380000);
            lcd_cmd(0x0e0000);
            lcd_cmd(0x010000);
            lcd_cmd(0x800000);
            lcd_cmd(0x060000);
    }
    
    void lcd_data(unsigned char ldata)
    {
    
            IOSET0=ldata;
            IOSET1=0x00001000;//RS;
            IOCLR1=0x00002000;//RW;
            IOSET1=0x00008000;//E;
            IOCLR1=0x00008000;//E;
            delay();
     }
      void lcd_cmd(unsigned char lcmd)
      {
    
    
                    IOSET0=lcmd;
                    IOCLR1=0x00001000;//RS;
                    IOCLR1=0x00002000;//RW;
                    IOSET1=0x00008000;//E;
                    IOCLR1=0x00008000;//E;
                    delay();
      }
    /*
    void delay(/*any arguement if required)
    {
                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
    } */
    /*
      void delay(unsigned int value)
      {
    
             unsigned int i;
            for(i=0;i<value;i++);
            {
    
            }
      }
      */
    

  • Mr Approving Zeusti,

    Not sure about your comment style; but I like your code. Nice accuracy and really efficient.

  • vikas,
    why are you using 2 branch instructions when you can do the same with one? you're killing your prefetch cache...!

  • void delay()__arm
    {
    __asm
    {
    MOV R3,R0
    loop:
    SUB  R1,R1,#1      ;R1 = R1-1
    NOP                ;A more delaying
    SUB   R0,R0,#1     ;R0 = R0-1
    BNE    loop          ;BRANCH if NOW NOT NULLIFIED
    BX     LR          ;GO TO WHERE YOU CAME FROM
    }
    }
    

    will this be fine

  • <quote>
    you're killing your prefetch cache...!
    <end>

    no Mr Tameer.

    it is a delay with delays calculated. kiled prefetch cache is part of the delay!

    Plz do not be so upset .if you study YOU can learn.

    Zeusti.

    Always yo're freind.

  • <quote>
    you're killing your prefetch cache...!
    <end>

    no Mr Tameer.

    it is a delay with delays calculated. kiled prefetch cache is part of the delay!

    Plz do not be so upset .if you study YOU can learn.

    Zeusti.

    Always yo're freind.

    every nonsense post of yours makes this charade better. please, do proceed....

  • vikas,
    can you make up a convincing argument as to WHY you need to decrement both R0 and R1? only one of them will do! you also forgot to backup the value of the changed registers in the stack, and to pop the old value from the stack when done.

  • plz mr tameer.

    plz explain what you think is so bad with my code?

    it works.

    it does not need horible *15 macro !!!

    Zeusti.

    always yo're freind.

  • but mr tameer.

    yo're code still used R0 and R1 and did not pre serve?

    does ARM calling convections need you to store R0 and R1?

    Zeusti.

    Always yo're freind.

  • the 15 factor was established for
    * a LPC2478 running at 72 MHz
    * measuring with a scope and a processor pin how long the delay actually is. the 15 constant would need to be changed in case another processor speed is configured. that is the reason it is embedded in a macro - changing platform only required one localized change that affects all instances where it was used.

  • if you look at one of my previous posts, you would see that I indicated that mistake already. there is no need to decrement more than one register. the need to preserve/restore R0 and R1 stems from the fact that the caller might assume a different role/value for these registers, hence delaying your code without maintaining their old value might break your software one the call returns.

  • poor mr tameer.

    read the apcs.

    Zeusti.

    Always yo're freind.