COG 2x16 LCD_Init()

Discuss with MikroElektronika software developers about current library development.
Post Reply
Author
Message
ProggIsitec
Posts: 50
Joined: 08 Jul 2014 09:05

COG 2x16 LCD_Init()

#1 Post by ProggIsitec » 08 Jul 2014 12:34

I´m trying to use a COG 2x16 and it works with a PIC18F45K22, but not with a PIC32MX795F.

For both I´m using the same code, but different compilers (MikroE PIC compiler and MikroE PIC32 compiler).

This is the code:

Code: Select all

// LCD module connections
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;

sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections

char txt1[] = "mikroElektronika";
char txt2[] = "EasyPIC6";
char txt3[] = "Lcd4bit";
char txt4[] = "example";

char i;                              // Loop variable

void Move_Delay() {                  // Function used for text moving
  Delay_ms(500);                     // You can change the moving speed here
}

void main(){
  AD1PCFG = 0xFFFF;                                       // Configure AN pins as digital

  Lcd_Init();                        // Initialize LCD

  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  Lcd_Out(1,6,txt3);                 // Write text in first row

  Lcd_Out(2,6,txt4);                 // Write text in second row
  Delay_ms(2000);
  Lcd_Cmd(_LCD_CLEAR);               // Clear display

  Lcd_Out(1,1,txt1);                 // Write text in first row
  Lcd_Out(2,5,txt2);                 // Write text in second row

  Delay_ms(2000);

  // Moving text
  for(i=0; i<4; i++) {               // Move text to the right 4 times
    Lcd_Cmd(_LCD_SHIFT_RIGHT);
    Move_Delay();
  }

  while(1) {                         // Endless loop
    for(i=0; i<8; i++) {             // Move text to the left 7 times
      Lcd_Cmd(_LCD_SHIFT_LEFT);
      Move_Delay();
    }

    for(i=0; i<8; i++) {             // Move text to the right 7 times
      Lcd_Cmd(_LCD_SHIFT_RIGHT);
      Move_Delay();
    }
  }
}
I took a logic analyzer and looked at the output of the code. If you have a look at the attached screenshots, you will see that the RS-line is wrongly set to data register for the PIC32.

So what can I do?
Attachments
PIC32
PIC32
PIC32 LCD.png (65.88 KiB) Viewed 3194 times
PIC18
PIC18
PIC18 LCD.png (63.85 KiB) Viewed 3194 times

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: COG 2x16 LCD_Init()

#2 Post by filip » 14 Aug 2014 09:00

Hi,

Please, have you tried using LAT registers instead of the PORT register for the Lcd pin definitions ?

Regards,
Filip.

ProggIsitec
Posts: 50
Joined: 08 Jul 2014 09:05

Re: COG 2x16 LCD_Init()

#3 Post by ProggIsitec » 14 Aug 2014 09:01

Yeah, this was the problem. I don´t know why I could compile and write it into a PIC32, but I could.

As I´ve took the right example it worked :)

Post Reply

Return to “Library Development Discussion”