Help with PIC18F45505 and GLCD

Discussion in 'Embedded Systems and Microcontrollers' started by menotu3169, Jul 13, 2014.

  1. menotu3169

    Thread Starter New Member

    Mar 8, 2007
    3
    0
    Hello, I am trying to connect my mcu to a 128*64 graphical LCD and I am having some trouble. I was hoping someone might be able to help.


    I am using a PIC18F4550 microcontroller and a CM12864-2 LCD(from futurlec).
    My code is posted below. The LCD seems to power on fine, and I am able to adjust the contrast, but I can't get anything to display.

    After spending some time searching, I found 2 pages ((Here and Here) both of which seem to say that there is something weird about this particular LCD, but neither page really discusses what is weird about them. The second page has some code for another mcu, but I'm not able to follow the code.

    I've double and triple checked my wiring, and I'm confident that it is okay.
    Can anyone help?
    Does anyone know anything about these LCDs? Are there any problems with my code?

    Any help would be greatly appreciated.
    Thanks
    M



    Code ( (Unknown Language)):
    1. #include <p18f4550.h>
    2. #include <delays.h>
    3.  
    4. #define CS1 PORTBbits.RB0
    5. #define CS2 PORTBbits.RB1
    6. #define RS  PORTBbits.RB2
    7. #define EN  PORTBbits.RB3
    8.  
    9. #define RW  PORTBbits.RB6
    10. #define RST PORTBbits.RB4
    11. //RB5 not used
    12. #define LCD_Data    PORTD
    13. #define Data_out()    TRISD=0x00;
    14. #define Data_in()    TRISD=0xff;
    15.  
    16. #pragma config PBADEN = OFF
    17. #pragma config WDT = OFF //disable watchdog timer
    18. #pragma config MCLRE = ON//; MCLEAR Pin on
    19. #pragma config DEBUG = ON//; Enable Debug Mode
    20. #pragma config LVP = OFF//; Low-Voltage programming disabled (necessary for debugging)
    21. #pragma config FOSC = INTOSCIO_EC//;Internal oscillator, port function on RA6
    22.  
    23. void pulse(void);
    24. void put(unsigned char data);
    25. unsigned char get(void);
    26. void GotoCol(unsigned char X_addr);
    27. void GotoRow (unsigned char Y_addr);
    28. void GotoXY(unsigned char X_addr, unsigned char Y_addr);
    29. void LCD_on(void);
    30. void LCD_off(void);
    31. void LCD_start_line();
    32. void get_status();
    33.  
    34.  
    35. void main(void){
    36.     unsigned char data;
    37.     unsigned char x,y;
    38.  //OSCCON=0xf0;
    39.  TRISB=0x00;
    40.  PORTB=0x00;
    41.  TRISD=0x00;
    42.  PORTD=0x00;
    43.  Delay100TCYx(1);
    44.  RST=1;
    45.  LCD_on();
    46.  
    47.  for (y=0;y<=7;y++){
    48.      GotoXY(x,y);
    49.      for (x=1;x<0X80;x+=3){
    50.          put(0xc3);
    51.          put(0xff);
    52.          put(0xc3);
    53.      }
    54.  }
    55.  
    56.  while(1);
    57.  
    58.  
    59. }
    60.  
    61.  
    62. void get_status(){
    63.     unsigned char data;
    64.     Data_in();
    65.     RS=0;
    66.     RW=1;
    67.     data=LCD_Data;
    68.     pulse();
    69.     Delay1TCY();
    70.     Data_out();
    71. }
    72.  
    73. void LCD_on(void){
    74.     RS=0;
    75.     RW=0;
    76.     //data=0x3f;
    77.     LCD_Data=0x3f;  //data;
    78.     pulse();
    79. }
    80.  
    81. void LCD_off(void){
    82.     RS=0;
    83.     RW=0;
    84.     //data=0x3e;
    85.     LCD_Data=0x3e;  //data;
    86.     pulse();
    87. }
    88.  
    89. void GotoXY(unsigned char X_addr, unsigned char Y_addr){
    90.     GotoCol(X_addr);
    91.     GotoRow(Y_addr);
    92. }
    93.  
    94. void GotoCol(unsigned char X_addr){
    95.     unsigned char data;
    96.     if (X_addr >= 64){
    97.         CS1=0;
    98.         CS2=1; //CS are active low
    99.         X_addr = X_addr - 64;
    100.     }
    101.     else if (X_addr < 64){
    102.         CS1=1;
    103.         CS2=0;
    104.     }
    105.  
    106.     RS=0;
    107.     RW=0;
    108.     data=0x40|X_addr;
    109.     LCD_Data=data;
    110.     pulse();
    111.     CS1=0;
    112.     CS2=0;  
    113. }
    114.  
    115. void GotoRow (unsigned char Y_addr){
    116.     unsigned char data;
    117.     RS=0;
    118.     RW=0;
    119.     data=0xb8|Y_addr;
    120.     LCD_Data=data;
    121.     pulse();
    122. }
    123.  
    124. void put(unsigned char data){
    125.     RS=1;
    126.     RW=0;
    127.     LCD_Data=data;
    128.     pulse();
    129. }
    130.  
    131.  
    132. void pulse(void){
    133.     Delay10TCYx(2);
    134.     EN=1;
    135.     Delay100TCYx(1);
    136.     EN=0;
    137.     Delay100TCYx(1);
    138.     EN=1;
    139. }
    140.  
     
Loading...