CFAG12864B Black Screen

az7834

New member
I am using a CFAG12864B-WGH-V and have it connected to my PIC18f6720 board with no problems. When I supply the PIC with power, the lcd turns on and has every pixel turned on giving me a black screen. Currently I'm trying to turn the screen off (command 00111110, 0x3E), but I cannot get my code to work. What am I doing wrong?

Code:
#include <protoalone.h>
#define CS1 PIN_C4
#define CS2 PIN_C5
#define RST PIN_C2
#define RW PIN_C3
#define DI PIN_C0
#define E PIN_C1
#define D_ADDRESS 0xf83
#byte lcd=D_ADDRESS

main() {
   int8 screenon=0x3E; 
   output_low(RW);
   output_low(CS1);
   output_low(CS2);
   output_low(E);
   lcd=screenon;           
   output_high(E);
}
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 
Last edited:
Maybe you have the contrast set too high (too much negative voltage on pin 3), or pin 3 is wired wrong. Do you have a pot from +5v to -10v (pin 18), with the wiper to pin 3?
 

az7834

New member
cosmicvoid said:
Maybe you have the contrast set too high (too much negative voltage on pin 3), or pin 3 is wired wrong. Do you have a pot from +5v to -10v (pin 18), with the wiper to pin 3?
You were right, I did have the contrast screwed up. It's fixed now, but I still can't communicate with or output to the LCD. In the following code I'm just changing the screen from on to off, and then doing a status read of the bits. I should be getting an output of 00100000, but instead I'm getting 00000000 as if the screen off command was never sent. Here is the code:
Code:
#include <protoalone.h>
#define CS1 PIN_C4
#define CS2 PIN_C5
#define RST PIN_C2
#define RW PIN_C3
#define DI PIN_C0
#define E PIN_C1
#define D_ADDRESS 0xF83
#byte lcd=D_ADDRESS
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, parity=n, bits=8, stream=PORT1)

main() {
   int x;
   byte screenoff;
   output_low(CS1);
   output_low(RW);
   output_low(DI);
   screenoff=0x3E;
   output_low(E);
   lcd=screenoff;
   output_high(E); 
   output_high(RW);
   for(x=0; x<8; x++) {
      if(bit_test(lcd,x))
         fputc('1',PORT1);
      else
         fputc('0',PORT1);
}
 
Last edited:
I don't see anything in your code to change the data bus (the cpu port) from output to input when you check status. You do have a bidirectional port for the bus, right?
 
I don't know if "set_tris_d()" is the answer.

It looks like you may have a problem with your usage of the E strobe. The "action" for write occurs on the falling edge of E, and in your code you do not drop E after the command, so effectively the command has not occured.

Do it like this:

command byte on output pins
raise E
nop (delay if necessary for timing 450 nS)
lower E

change bus to input
raise E
test port for status (loop)
lower E

change bus to output
etc, etc.

There are lots of samples of PIC code in these forums, and CF Tech has posted links to lots more.
 
Top