View previous topic :: View next topic |
Author |
Message |
John22
Joined: 08 Feb 2014 Posts: 6
|
LCD ST7920 problem |
Posted: Sat Feb 08, 2014 8:02 am |
|
|
I am trying to use a graphic LCD module with controller ST7920 following the driver at http://www.ccsinfo.com/forum/viewtopic.php?t=49505
My problem is that i don't know how to connect it with the pic. The driver present:
Code: |
#define rs PIN_C0 //COMMAND/DATA SELECT
#define rw PIN_C1 //READ/WRITE SELECT
#define e PIN_C2 //ENABLE SIGNAL
#define rst PIN_C5 //RESET SIGNAL
|
What about the other pins of the lcd? I think, i need to define also at least the DB4,DB5,DB6,DB7 but where?
please i need your help. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Feb 08, 2014 11:53 am |
|
|
He says in the program exactly where
Quote: | data is sent using port B so change output_b() to other ports you
want to use. |
So put lcd data lines D0-D7 to port B pins B0-B7. |
|
|
John22
Joined: 08 Feb 2014 Posts: 6
|
LCD ST7920 problem |
Posted: Sun Feb 09, 2014 5:59 am |
|
|
I did it but the LCD, still is not working. Actually i can't see anything (even a small light) to say that the LCD is alive.
What is needed to change ?? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Feb 09, 2014 11:32 am |
|
|
1. Post all the connections you have made to the LCD. (Power, ground,
contrast, etc.)
2. Post a link to the data sheet for the LCD. |
|
|
John22
Joined: 08 Feb 2014 Posts: 6
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Feb 10, 2014 4:14 pm |
|
|
1. You need to carefully read all documentation. Look on page 7 of the
ST7920 data sheet. What does it say about the PSB signal ? What
voltage level should it be connected to, if you want to use a parallel
interface ? Your schematic shows a parallel interface connection to
the LCD, but PSB voltage is wrong.
Quote: | #define rs PIN_C0 //COMMAND/DATA SELECT
#define rw PIN_C1 //READ/WRITE SELECT
#define e PIN_C2 //ENABLE SIGNAL
#define rst PIN_C5 //RESET SIGNAL |
2. The pin assignments above do not match your schematic at all.
Your schematic uses pins on PortA for these signals.
3. You also have pin A2 assigned to both E and RST.
Those signals need to be on separate pins.
4. Your backlight voltages are reversed on the BLA and BLK pins.
"K" is the cathode of a diode in this case, and "A" is the anode.
The +3.3v voltage goes to the anode. The cathode goes to ground.
Many of these items should have been seen by you and fixed.
I can help, but you have to pay attention to detail. A large part
of success in electronics and programming is about watching the details. |
|
|
John22
Joined: 08 Feb 2014 Posts: 6
|
LCD ST7920 problem |
Posted: Tue Feb 11, 2014 11:57 am |
|
|
Hello PCM Programmer,
I changed the PSB to connect to vdd now.(page 7 and page 10 of the manual! )
"What voltage level should it be connected to, if you want to use a parallel
interface ?"
I don’t know this question? I use a 3.3V . Where can I find this ?
I replace the following commands:
Code: |
#define rs PIN_C0 //COMMAND/DATA SELECT
#define rw PIN_C1 //READ/WRITE SELECT
#define e PIN_C2 //ENABLE SIGNAL
#define rst PIN_C5 //RESET SIGNAL
|
With these commands:
Code: | #define rs PIN_A0 //COMMNAD/DATA SELECT
#define rw PIN_A1 //READ/WRITE SELECT
#define e PIN_A2 //ENABLE SIGNAL
#define rst PIN_A3 //RESET SIGNAL
|
(my pic don’t provide with C port !)
"The pin assignments above do not match your schematic at all.
Your schematic uses pins on PortA for these signals."
Yes because when I answer the question I removed the lcd and I was trying to connecting again (to check for any connectivity problem)
"You also have pin A2 assigned to both E and RST.
Those signals need to be on separate pins."
For the RST I use A3
"Your backlight voltages are reversed on the BLA and BLK pins.
"K" is the cathode of a diode in this case, and "A" is the anode.
The +3.3v voltage goes to the anode. The cathode goes to ground. "
I changed it. Now BLA -->VDD and BLK-->VSS
I want to fix this problem as soon as possible that’s why I do stupid errors.
My LCD is still not working. What else can I checked? (btw how to check if my LCD module is not faulty????) |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Feb 11, 2014 12:26 pm |
|
|
Post your lcd test program. This is the program you wrote that calls
the lcd functions in the st7920.h driver file.
Make sure to post:
1. The #include line for the PIC.
2. Any #device statements
3. #fuses
4. #use delay()
5. Any other #use statements
6. Any other #include statements
7. #define statements
8. Variable declarations
9. main() and the code inside main().
Do not post the "st7920.h" file from the Code Library. I can look at
it in the Code Library. |
|
|
John22
Joined: 08 Feb 2014 Posts: 6
|
LCD ST7920 problem |
Posted: Tue Feb 11, 2014 12:55 pm |
|
|
main
Code: |
#include <33fj128GP802.h>
// Device Specification
#FUSES NOPROTECT //General Segment Code not Protected
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES FRC //Internal RC at default frequency
#FUSES NOWDT //No Watch Dog Timer #use delay (clock=8000000) // Use built-in function: delay_ms() & delay_us()
#use delay(clock=7.37MHz) //default frequency for RC
#include "st7920.h"
#include "GRAPHICS.C"
//
//
//
//
void main(){
glcd_init_graph();
while(1){
glcd_fillscreen(ON);
glcd_update();
delay_ms(1000);
glcd_fillscreen(OFF);
glcd_update();
delay_ms(1000);
//glcd_plot_image(60,50,0,0,0);
glcd_update();
delay_ms(1000);
}
}
|
st7920.h
Code: |
#define rs PIN_A0 //COMMNAD/DATA SELECT
#define rw PIN_A1 //READ/WRITE SELECT
#define e PIN_A2 //ENABLE SIGNAL
#define rst PIN_A3 //RESET SIGNAL
#define ON 1
#define OFF 0
#define XVAL 16 // 16 X 16 or 256 for there is 8 word values for the upper and lower
#define YVAL 32
// PSB is tied to Vcc for this driver because this driver uses Parallel
// operation.
// data is sent using port B so change output_b() to other ports you
//want to use. Dont for get to change the Busy pin @ lcd_check_busy
#define GLCD_WIDTH 128
//////////////////////////////////////////////////////////////////////////////////
//The following are the functions included in this driver file
// glcd_readbyte();
// glcd_instruction( instruction );
// glcd_data( data ); - data can be an array of characters!
// glcd_check_busy();
// glcd_update(); -must be called always after writing a pixel or using functions
// from GRAPHICS.C .. Only applicaticable in Graphing mode
// glcd_fillscreen( ON or OFF);
// glcd_init_graph(); initialize for graphing mode
// glcd_init_basic(); initilize for accessing the stored Characters
// you can use glcd_data() for writing text
// glcd_pixel(x coordinate, y coordinate, ON or OFF);
// -WORKS WITH GRAPHIC.C from CCS Drivers
// glcd_plot_image(width,height,X coor, Y coor, inverse);
// -plots the image[] array. Declare it first before this driver.
// or modify this driver
//
//////////////////////////////////////////////////////////////////////////////////
typedef union
{
int16 word;
int8 nbyte[2];
} Dots;
typedef struct
{
int1 refresh;
Dots pix[YVAL][XVAL]; // Max dimensions for display (x,y) = (128,32)
} GD_RAM; // (0,0) corresponds to upper lefthand corner.
GD_RAM gdram;
unsigned int8 glcd_readByte (unsigned int1 address)
{
unsigned int8 data; // Stores the data read from the LCD
if(address==1){
output_high(rs);
}
if(address==0){
output_low(rs);
}
output_high(rw);//GLCD_RW = RW_READ; // Set for reading
output_high(e);//GLCD_E = 1; // Pulse the enable pin
delay_us(1);
data=input_b(); // Get the data from the display's output register
output_low(e);//GLCD_E = 0;
return (data);
}
void glcd_check_busy(){
int1 busy=1;
output_low(rs); // LOW RS and High RW will put the lcd to
output_high(rw); // read busy flag and address counter
while(busy){ // will cycle until busy flag is 0
output_high(e);
if(!input(PIN_B7)){
busy=0;
}
output_low(e);
}
}
void glcd_instruction(unsigned char x){
glcd_check_busy(); //must be satisfied before sending instruction
output_low(rs); // LOW RS and LOW RW will put the lcd to
output_low(rw); // Write instruction mode
output_b(x); // 8bit data to bus
output_high(e); // enable
delay_us(1);
output_low(e); // disable
}
void glcd_data(unsigned char x){
glcd_check_busy();
output_high(rs); // HIGH RS and LOW RW will put the lcd to
output_low(rw); // Write data register mode
output_b(x);
output_high(e);
delay_us(1);
output_low(e);
}
void glcd_fillScreen (unsigned int1 color)
{
int8 v, h;
int16 d;
d = (color == ON ? 0xFFFFL : 0x0000L);
for (v=0; v < YVAL; v++)
{
for (h=0; h < XVAL; h++)
{
gdram.pix[v][h].word = d;
}
}
gdram.refresh = TRUE;
}
void glcd_update ()
{
int8 v, h;
if (gdram.refresh)
{
for (v=0; v <YVAL; v++)
{
glcd_instruction( 0x80 | v); // Set Vertical Address.
glcd_instruction( 0x80 | 0); // Set Horizontal Address.
for (h=0; h <XVAL; h++)
{
glcd_data( gdram.pix[v][h].nbyte[1]); // Write High Byte.
glcd_data( gdram.pix[v][h].nbyte[0]); // Write Low Byte.
}
}
gdram.refresh = FALSE;
}
}
void glcd_init_graph(){
delay_ms(40);
output_low(rst); //reset LCD
delay_us(1);
output_high(rst); //LCD normal operation
glcd_instruction(0x30); //set 8 bit operation and basic instruction set
delay_us(144);
glcd_instruction(0x0C); //display on cursor off and char blink off
delay_us(100);
glcd_instruction(0x01); //display clear
delay_ms(10);
glcd_instruction(0x06); //entry mode set
delay_us(72);
glcd_instruction(0x34); // Select extended instruction set.
delay_ms (10);
glcd_instruction(0x36); // Graphic display ON.
delay_ms (10);
glcd_fillScreen (OFF);
glcd_update ();
}
void glcd_init_basic(){
delay_ms(40);
output_low(rst); //reset LCD
delay_us(1);
output_high(rst); //LCD normal operation
glcd_instruction(0x30); //set 8 bit operation and basic instruction set
delay_us(144);
glcd_instruction(0x0C); //display on cursor off and char blink off
delay_us(100);
glcd_instruction(0x01); //display clear
delay_ms(10);
glcd_instruction(0x06); //entry mode set
delay_us(72);
}
void glcd_pixel(int8 x, int8 y, int1 color)
{
int8 v, h, b;
if(y>31){x += 128; y-= 32;};
v = y;
h = x/16;
b = 15 - (x%16);
if (color == ON) bit_set (gdram.pix[v][h].word, b);
else bit_clear (gdram.pix[v][h].word, b);
gdram.refresh = TRUE;
}
void glcd_plot_image(int width,int height,int x,int y,int inverse)
{
unsigned int i=0, j=0, k=0;
unsigned int16 count=0;
//glcd_fillScreen(OFF); //Clears the screen (opt.)
for(j=0;j<height;j++)
{
for(;i<width;)
{
for(k=8;k>0;k--){
if(inverse)glcd_pixel(i+x,j+y,~bit_test(image[count],(k-1)));
else glcd_pixel(i+x,j+y,bit_test(image[count],(k-1)));
i++;
}
count++;
}
i=0;
}
}
|
Can you see any problem??
Also didn't connect anything at the the pins :NC,Vo,Vout .Is this right? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 12, 2014 2:27 pm |
|
|
Vo is normally the contrast voltage pin. You didn't post a data sheet for
the full LCD. You only gave one for the ST7920 controller. So I don't
know for sure what the correct circuit is for the Vo pin.
You could try this:
Code: |
Vo
|
|
Vout ---/\/\/\/\/\/\/--- Vss (ground)
10K trimpot
|
Get a 10K trimpot. Put Vout on one side and Vss on the other side.
Then connect the center (wiper) pin to Vo. Try adjusting it for 0.4v
and if that doesn't give good contrast, then adjust it up to 3.0v slowly.
See if that works. |
|
|
|