View previous topic :: View next topic |
Author |
Message |
target_locked
Joined: 24 Apr 2014 Posts: 2
|
Posted: Thu Apr 24, 2014 2:09 pm Post subject: ATMEGA16 with LCD16x2 (4 bit) |
|
|
Hi there,
I am new to Bascom and I got an issue with LCD 16x2 (4 bit). My CPU is ATMega16.
I have another sample program written in C and it works well all times with this LCD. I call this LCD_Demo.hex
Now with my Bascom program (I call it LCD_Shift). It only run correctly after I run above LCD_Demo.hex. If I turn off the power and ON again, my LCD_Shift will not run correctly, strange chars appear.
I just leave power on, load LCD_Demo.hex, it will run well, then load my LCD_Shift.hex, it work well also.
I guess the issue related to the temporary memory that when I switch off the power it will loose the data.
I would like to know what is wrong in my Bascom LCD_Shift program? Do I miss any step to make the LCD run stably?
Thanks,
Here is my Bascom code:
Code: |
' LCD_Shift: Shift 2 rows left then right
$regfile = "m16def.dat"
$crystal = 12000000
Config Porta = Output
Config Lcd = 16 * 2
Config Lcdbus = 4
Config Lcdmode = Port
Config Lcdpin = Pin , Rs = Porta.0 , E = Porta.2 , Db4 = Porta.4 , Db5 = Porta.5 , Db6 = Porta.6 , Db7 = Porta.7
Dim Pos As Byte
Do
Cls
Upperline
Lcd "012345678901john"
Lowerline
Lcd "0123456789012ike"
For Pos = 0 To 16 Step 1
Waitms 300
Shiftlcd Left
Next Pos
For Pos = 0 To 32 Step 1
Waitms 200
Shiftlcd Right
Next Pos
Loop
End
|
And here is C Code Vision that work well all times:
Code: |
//LCD DEMO
// the LCD is connected to PORTA outputs
// see the file lcd.h in the ..\inc directory
#asm
.equ __lcd_port=0x1b ;PORTA
#endasm
// include the LCD driver routines
#include <lcd.h>
#include <mega16.h>
void main(void)
{
// initialize the LCD for
// 2 lines & 16 columns
lcd_init(16);
// go on the second LCD line
lcd_gotoxy(1,0);
// display the message
lcd_putsf("ROW 1");
lcd_gotoxy(0,1);
lcd_putsf("ROW 2");
// stop here
while (1);
}
|
Here is the LCD circuit:
(BASCOM-AVR version : 2.0.7.3 , Latest : 2.0.7.7 ) |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Thu Apr 24, 2014 2:16 pm Post subject: |
|
|
you should remark these lines :
'Config Lcdbus = 4
'Config Lcdmode = Port
then you should make the WR pin low first. Or connect it to ground.
config ......
porta.1=0 'WR pin low
INITLCD 'now init lcd when wr pin is low
just read the help about lcd _________________ Mark |
|
Back to top |
|
|
target_locked
Joined: 24 Apr 2014 Posts: 2
|
Posted: Fri Apr 25, 2014 11:36 am Post subject: |
|
|
Thanks Albertsm,
The solution work perfectly.
The key point is pulling the WR pin Low and command InitLCD.
Code: | $regfile = "m16def.dat"
$crystal = 12000000
Config Porta.1 = Output
Config Lcd = 16 * 2
Config Lcdbus = 4
Config Lcdmode = Port
Config Lcdpin = Pin , Rs = Porta.0 , E = Porta.2 , Db4 = Porta.4 , Db5 = Porta.5 , Db6 = Porta.6 , Db7 = Porta.7
Porta.1 = 0 'WR pin low
Initlcd 'now init lcd when wr pin is low
Dim Pos As Byte
Do
Cls
Upperline
Lcd "012345678901john"
Lowerline
Lcd "0123456789012ike"
For Pos = 0 To 16 Step 1
Waitms 300
Shiftlcd Left
Next Pos
For Pos = 0 To 32 Step 1
Waitms 200
Shiftlcd Right
Next Pos
Loop
End |
|
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Sat Apr 26, 2014 9:34 pm Post subject: |
|
|
yes and new version of bascom also support WR pin with BUSY check. for those having enough pins. _________________ Mark |
|
Back to top |
|
|
|
|
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 You cannot attach files in this forum You cannot download files in this forum
|
|