|
|
View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Aug 05, 2009 2:08 pm |
|
|
Quote: | the ST7920 need an enable pulse width of 140nS
void lcd_instruction (unsigned char x)
{
lcd_check_busy();
output_low(rs); //data not commnad.
output_low(rw); //write not read.
output_b(x); //data to bus.
output_high(e); //enable.
delay_us(450);
output_low(e); //disable.
} |
Then why do you use 450 us for the 'e' pulse width ?
It's much longer than the required width:
Code: | 450 us
------- = 3214.3 times greater than the required pulse width.
140 ns |
Change the delay to delay_us(1). That should be long enough.
Quote: | void main ()
{
int i;
while(1)
{
lcd_init();
for(i=0;i<8;i++)
{
lcd_display(TAB[i]);
delay();
}
delay_ms(1000); //pause de 1 seconde permettant de voir l'affichage
lcd_clear();
}
} |
You should not call lcd_init() in a loop. You should call it one time,
at the start of main().
Also, look at the flow chart on page 11 of this LCD data sheet.
(This LCD uses the ST7920).
http://www.lcdchina.com/UpFile/200812137385421.pdf
It shows a 15 ms minimum delay is required after power-up, before
any commands are sent to the LCD. You don't have that delay in
your main(). You need to add it.
Your LCD data sheet does not have a flow chart for the initialization.
This Crystalfontz data sheet shows a power-up delay of 40ms is required.
Also, it has a different initialization flow chart:
http://www.crystalfontz.com/products/12864j/datasheets/1537/CFAG12864JTMITT_Preliminary_2.pdf
Read the LCD data sheet. In the same flowchart, it shows the Busy
flag cannot be used until a certain point in the initialization process.
You are using the Busy bit too soon, in your code. The data sheet
shows that fixed delays (using delay_ms() function) must be used
for the first few commands, instead of polling the Busy bit. |
|
|
mortaurat
Joined: 23 Jul 2009 Posts: 14
|
|
Posted: Wed Aug 05, 2009 3:41 pm |
|
|
I've found why it doesn't work !!!
My pic 16f876 doesn't support 20MHz crystal (contrary to mentioned in datasheet)...
a simply program like this one doesn't work:
Code: | void main()
{
int i=0;
while(1)
{
output_b(i);
delay_ms(1000);
i=i+1;
}
} |
Really thank you for your help, i will try a 20MHz crystal when I will receive my 16f877A ;)
thanks again. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Aug 05, 2009 4:29 pm |
|
|
Were you using a -04 or -10 PIC (4 MHz or 10 MHz) ? |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Wed Aug 05, 2009 8:53 pm |
|
|
mortaurat wrote: | I found delay in the datasheet.
In page 11, 200nS for one instruction looks good for the lcd display.
unlike to the hd44780, the ST7920 need an enable pulse width of 140nS, so it shall be ok...
|
You should. We're just emphasizing that you look and double check.
It's surprising how RTFM creeps into our lives and kicks our butt-skis.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
mortaurat
Joined: 23 Jul 2009 Posts: 14
|
|
Posted: Thu Aug 06, 2009 1:08 am |
|
|
PCM programmer wrote: | Were you using a -04 or -10 PIC (4 MHz or 10 MHz) ? |
-04
So I think the driver may work with a 20MHz crystal, it will be useful if someone else bought the QL_200 development board and need a driver for this display ;).
I will add other function in order to allow to trace circle, line and other things, I will post it when it will be finished.
Thanks. |
|
|
leevise
Joined: 05 Aug 2010 Posts: 89
|
|
Posted: Thu Dec 30, 2010 10:08 am |
|
|
Using 20Mhz crystal, my demo is successful, only add
"#fuses HS,NOWDT,PUT,NOPROTECT". I test this define, if you delete this instruction, the LCD doesn't work, but you add it in your C program, the LCD is ok. The C code follow as:
Code: |
#include <18f452.h>
#fuses HS,NOWDT,PUT,NOPROTECT
#use delay (clock = 20000000)
#define e PIN_C6 // E 使能端H选通
#define rs PIN_C2 //指令数据选择端
#define psb PIN_C1 //串并口模式选择:H并行L串口
#define rst PIN_C5 //RESET ,
#define rw PIN_C4 //并行的读写信号
void lcd_init(); //LCD init
void lcd_clear(); //clear lcd display and cursor back to home
void lcd_display(unsigned char); //affichage lcd
void lcd_instruction(unsigned char); //send instruction to lcd
void lcd_data(unsigned char); //send data to lcd
void delay(); //delay func, decide the speed of init.
void lcd_check_busy(); //check if the lcd display is busy
const unsigned char TAB[]={'A','B','C','D','E','F','g','h','i','j','k','L','M' };
void main ()
{
int i ;
while(1)
{
lcd_init();
for(i=0;i<8;i++)
{
lcd_display(TAB[i]);
delay();
}
delay_ms(1000); //pause de 1 seconde permettant de voir l'affichage
lcd_clear();
}
}
//initialisation du LCD
void lcd_init()
{
output_low(rst); //reset LCD
delay();
output_high(rst); //LCD normal work.
output_high(psb); //8 bit as parrallel.
lcd_instruction(0x30); //basic operation instruction
lcd_instruction(0x01); //off display
lcd_instruction(0x06); //set the cursor's moving direction.
lcd_instruction(0x0c); //on display,off cursor,off blink
}
void lcd_clear ()
{
lcd_instruction(0x01); //clear display and cursor back to home
lcd_instruction(0x34); //extend.
lcd_instruction(0x30); //basic operation instruction
}
void lcd_display(unsigned char data)
{
lcd_data(data);
}
void lcd_instruction (unsigned char x)
{
lcd_check_busy();
output_low(rs); //data not commnad.
output_low(rw); //write not read.
output_d(x); //data to bus.
output_high(e); //enable.
delay_us(450);
output_low(e); //disable.
}
void lcd_data (unsigned char x)
{
lcd_check_busy();
output_high(rs); //data not commnad.
output_low(rw); //write not read.
output_d(x); //data to bus.
output_high(e); //enable.
delay_us(450);
output_low(e); //disable.
}
//delay
void delay()
{
int i=0;
while(i<250)
{
i=i+1;
}
}
//check lcd busy.
void lcd_check_busy()
{
int busy;
busy=1; //set busy signal
output_low(rs); //command not data.
output_high(rw); //read not write.
while(busy)
{
output_high(e); //enable.
if(!input(PIN_B7)) busy=0; //
output_low(e); //DISABLE.
}
output_low(e); //DISABLE.
}
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|