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
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
Rich (BB code):
#include <p18f4550.h>
#include <delays.h>
#define CS1 PORTBbits.RB0
#define CS2 PORTBbits.RB1
#define RS PORTBbits.RB2
#define EN PORTBbits.RB3
#define RW PORTBbits.RB6
#define RST PORTBbits.RB4
//RB5 not used
#define LCD_Data PORTD
#define Data_out() TRISD=0x00;
#define Data_in() TRISD=0xff;
#pragma config PBADEN = OFF
#pragma config WDT = OFF //disable watchdog timer
#pragma config MCLRE = ON//; MCLEAR Pin on
#pragma config DEBUG = ON//; Enable Debug Mode
#pragma config LVP = OFF//; Low-Voltage programming disabled (necessary for debugging)
#pragma config FOSC = INTOSCIO_EC//;Internal oscillator, port function on RA6
void pulse(void);
void put(unsigned char data);
unsigned char get(void);
void GotoCol(unsigned char X_addr);
void GotoRow (unsigned char Y_addr);
void GotoXY(unsigned char X_addr, unsigned char Y_addr);
void LCD_on(void);
void LCD_off(void);
void LCD_start_line();
void get_status();
void main(void){
unsigned char data;
unsigned char x,y;
//OSCCON=0xf0;
TRISB=0x00;
PORTB=0x00;
TRISD=0x00;
PORTD=0x00;
Delay100TCYx(1);
RST=1;
LCD_on();
for (y=0;y<=7;y++){
GotoXY(x,y);
for (x=1;x<0X80;x+=3){
put(0xc3);
put(0xff);
put(0xc3);
}
}
while(1);
}
void get_status(){
unsigned char data;
Data_in();
RS=0;
RW=1;
data=LCD_Data;
pulse();
Delay1TCY();
Data_out();
}
void LCD_on(void){
RS=0;
RW=0;
//data=0x3f;
LCD_Data=0x3f; //data;
pulse();
}
void LCD_off(void){
RS=0;
RW=0;
//data=0x3e;
LCD_Data=0x3e; //data;
pulse();
}
void GotoXY(unsigned char X_addr, unsigned char Y_addr){
GotoCol(X_addr);
GotoRow(Y_addr);
}
void GotoCol(unsigned char X_addr){
unsigned char data;
if (X_addr >= 64){
CS1=0;
CS2=1; //CS are active low
X_addr = X_addr - 64;
}
else if (X_addr < 64){
CS1=1;
CS2=0;
}
RS=0;
RW=0;
data=0x40|X_addr;
LCD_Data=data;
pulse();
CS1=0;
CS2=0;
}
void GotoRow (unsigned char Y_addr){
unsigned char data;
RS=0;
RW=0;
data=0xb8|Y_addr;
LCD_Data=data;
pulse();
}
void put(unsigned char data){
RS=1;
RW=0;
LCD_Data=data;
pulse();
}
void pulse(void){
Delay10TCYx(2);
EN=1;
Delay100TCYx(1);
EN=0;
Delay100TCYx(1);
EN=1;
}