moon_light_2010 WROTE:thanks ABSF for your respond. Actually, what I want to do is to know how to handle this glcd. So, my first step is to write something to it and I want to do that in parallel mode. You just said something about the serial mode, do you mean by that that I can use this glcd in text mode only in serial mode !? I can't write some normal ASCII characters to this glcd in parallel mode?!
I tried the page you posted, yet I actually couldn't grasp all of that. It was merely focusing on serial mode.
In summary I just want to know the simplest correct sequence of steps that would initialize the glcd and display something in it.
Was pulling RST and PSB up and grounding R/W right ? ( you know I didn't connect them to my MCU).
I would be thankful if you could check the code I typed and feed me back if it has some faults.
You can use it in parallel mode too, 4-bit or 8-bit mode.
By the way, according to the code, what's the "Wait(255)" mean there? Wait there for 255ms? 255microseconds?
The ST7920 cannot accept instructions and data too fast. Slow down the time taken for the microcontroller to send the data.
Here is a sample code in mbed using a 4-bit parallel mode. You may need to modify the "wait" inside to a desired delay function. Please notice that the waits in mbed takes in fraction of a second:
- CODE: SELECT_ALL_CODE
#include "mbed.h"
DigitalOut myled(LED1);
DigitalOut RS(p9);
DigitalOut E(p10);
DigitalOut DB4(p11);
DigitalOut DB5(p12);
DigitalOut DB6(p13);
DigitalOut DB7(p14);
void ST7920_Init();
void ST7920_Command(unsigned char);
void ST7920_Data(unsigned char);
void ST7920_Print(unsigned char, unsigned char, char*);
int main() {
ST7920_Init();
ST7920_Print(0,1, "Hello World!");
while(1) {
}
}
void ST7920_Command(unsigned char data)
{
RS = 0;
wait(0.001);
// Move higher nibble first
DB4 = (data & (1 << 4)) >> 4;
DB5 = (data & (1 << 5)) >> 5;
DB6 = (data & (1 << 6)) >> 6;
DB7 = (data & (1 << 7)) >> 7;
E = 1;
wait(0.00001);
E = 0;
// Then move the lower nibble
DB4 = (data & (1 << 0)) >> 0;
DB5 = (data & (1 << 1)) >> 1;
DB6 = (data & (1 << 2)) >> 2;
DB7 = (data & (1 << 3)) >> 3;
E = 1;
wait(0.00001);
E = 0;
}
void ST7920_Init()
{
wait(0.5);
ST7920_Command(0x20); // 0b0010x0xx
wait(0.001);
ST7920_Command(0x20); // 0b0010x0xx
wait(0.001);
ST7920_Command(0x0F); // 0b00001DCB
wait(0.001);
ST7920_Command(0x01); // 0b00000001
wait(0.01);
ST7920_Command(0x06); // 0b000001(1/D)S
ST7920_Command(0x02);
}
void ST7920_Data(unsigned char data)
{
RS = 1;
wait(0.001);
// Move higher nibble first
DB4 = (data & (1 << 4)) >> 4;
DB5 = (data & (1 << 5)) >> 5;
DB6 = (data & (1 << 6)) >> 6;
DB7 = (data & (1 << 7)) >> 7;
E = 1;
wait(0.00001); // at least 25ns and above here
E = 0;
// Then move the lower nibble
DB4 = (data & (1 << 0)) >> 0;
DB5 = (data & (1 << 1)) >> 1;
DB6 = (data & (1 << 2)) >> 2;
DB7 = (data & (1 << 3)) >> 3;
E = 1;
wait(0.00001);
E = 0;
}
void ST7920_Print(unsigned char x, unsigned char y, char* string)
{
switch(y)
{
case 1:
x += 0x80;
break;
case 2:
x += 0x90;
break;
case 3:
x += 0x88;
break;
case 4:
x += 0x98;
break;
default:
x = 0x80;
break;
}
ST7920_Command(x);
while(*string)
ST7920_Data(*string++);
}
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool