SparkFun Forums 

Where electronics enthusiasts find answers.

Your source for all things Atmel.
By madamaxo
#2184
Hi !

I have acquired a AVR-MT-128 from OLIMEX and the Codevision code works fine.

Even though I like C I would like to use BASCOM AVR as well but so far had no success with the LCD. Other tests such as the Relay and buzzer have worked fine.

The following is a translation of the C code com Olimex example that I ported to BASCOM. The LCD pin assignment have been made correctly but nothing shows up on the LCD.

' ###########################################
' Start here
' ###########################################
Const Disp_on = &B00001100
Const Disp_off = &B00001000
Const Clr_disp = &B00000001
Const Cur_home = &B00000010
Const Dd_ram_addr = &B10000000

Declare Sub _e
Declare Sub Lcdinit
Declare Sub Buzzer
Declare Sub Lcdsendchar(byref Sendc As String)
Declare Sub Lcdsendcmd(sendcmd As Byte)


Dim Lcddata As Byte


Sub _e
Portc.2 = 1
Waitms 1
Portc.2 = 0
End Sub


Sub Lcdinit
Portc.0 = 0
Waitms 110
Portc = &B00110000
_e
Waitms 10
Portc = &B00110000
_e
Waitms 10
Portc = &B00110000
_e
Waitms 10
Portc = &B00100000
_e
End Sub


Sub Buzzer

Do
Porte.4 = 0
Porte.5 = 1
Waitms 1
Porte.5 = 0
Porte.4 = 1
Loop Until Porta.3 = 0

End Sub

Sub Lcdsendchar(byref Sendc As String * 1)

Waitms 2

Lcddata = Val(sendc) And &B11110000

Portc = Portc And &B00001111
Portc = Portc Or Lcddata

Portc.0 = 1

_e

Lcddata = Val(sendc) And &B00001111

Portc = Portc And &B11110000
Portc = Portc Or Lcddata

Portc.0 = 1

_e


End Sub


Sub Lcdsendcmd(sendcmd As Byte)

Waitms 2

Lcddata = Val(sendcmd) And &B11110000

Portc = Portc And &B00001111
Portc = Portc Or Lcddata

Portc.0 = 0

_e

Lcddata = Val(sendcmd) And &B00001111

Portc = Portc And &B11110000
Portc = Portc Or Lcddata

Portc.0 = 0

_e

End Sub


Dim Cmd As Byte
Dim I As Byte
Dim Temp As String * 1
Dim Lcd_message As String * 32


Cmd = Disp_on

Call Lcdsendcmd(cmd)
Waitms 10

Cmd = Clr_disp
Call Lcdsendcmd(cmd)

Waitms 10

Cmd = Dd_ram_addr
Call Lcdsendcmd(cmd)

Lcd_message = "TESTE 123"

I = Len(lcd_message)


Do
Temp = Mid(Lcd_message,i,1)
Call Lcdsendchar(temp )
I = I - 1
Loop Until I = 0

Cmd = Dd_ram_addr

Call Lcdsendcmd(cmd)


End
' ###########################################
' End here
' ###########################################


Notice that I have not used in the internal Bascom LCD routines, they wont work at all.

Did anyone had the experience of using BASCOM Avr with this Olimex board ?

Thanks,

Max
By AVRMan
#2414
Hey Max, I had some troubles to find out this one (I'm TOTALLY new to AVR) but here it is:

You have to include the following lines at the start of the program, preferably after the REGFILE$ and other $ directives :

$lib "lcd4busy.lib"
Const _lcdport = Portc
Const _lcdddr = Ddrc
Const _lcdin = Pinc
Const _lcd_e = 2
Const _lcd_rw = 1
Const _lcd_rs = 0

Then all you have to do is use the LCD command to send the text to the LCD.

:wink:
By askjerry
#33726
I do not have the file lcd4busy.lib

Where is it?
By rmillqvist
#33771
Max,
I you have the full version of Bascom it will be in the Bascom-avr\lib directory, if you have the demo version there will be a compiled library called lcd4busy.LBX that does the same thing.
TTFN
Robert
By kimmi
#34129
hi

A small fix on the lcd and you dont need this setup

un-soilder the RW pin from LCD & AVR
add a 3 pin jumper
join 1&2 for orginal mode
or 2&3 for Bascom FIX
(if you only use bascom then just connect LCD RW to GND)
see images below

now you can use lcd like this in Bascom :
Code: Select all
'SparkFunElectronics Atmega128
'Development Board.
'PROJECT: Test setup

$regfile = "m128def.dat"

'Real Sparkfun
$crystal = 16000000

Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E = Portc.2 , Rs = Portc.0

'Config Buzzer
Config Pine.4 = Output : Config Pine.5 = Output

'Config 5 buttons for input...
Config Pina.0 = Input                                       'B1 UP
Config Pina.1 = Input                                       'B2 LEFT
Config Pina.2 = Input                                       'B3 ENTER
Config Pina.3 = Input                                       'B4 RIGHT
Config Pina.4 = Input                                       'B5 DOWN


Declare Sub Beep
Dim Jbee As Integer

Enable Interrupts

Cursor Off Noblink
Cls
Lcd "OLIMEX MT-128 "
Locate 2 , 1
Lcd "TEST Ver 1.00"
Wait 1                                                      'wait a moment
Beep

Wait 1                                                      'wait a moment
Beep

 Cls
 Locate 1 , 1
 Lcd "PRESS A KEY"

Do

 If Pina.0 = 0 Then
  Lcd "KEY UP"
  Beep
  Bitwait Porta.0 , Set
  Cls
  End If
 If Pina.1 = 0 Then
    Lcd "KEY LEFT"
    Beep
    Bitwait Porta.1 , Set
    Cls
 End If
 If Pina.2 = 0 Then
    Lcd "KEY ENTER"
    Beep
    Bitwait Porta.2 , Set
    Cls
 End If
 If Pina.3 = 0 Then
    Lcd "KEY RIGHT"
    Beep
    Bitwait Porta.3 , Set
    Cls
 End If

 If Pina.4 = 0 Then
    Lcd "KEY DOWN"
    Beep
    Bitwait Porta.4 , Set
    Cls
 End If
Loop
End

Sub Beep()
 For Jbee = 1 To 100
  Porte.6 = 0
  Porte.7 = 1
  Waitus 125
  Porte.6 = 0
  Porte.7 = 1
  Waitus 125
 Next Jbee
End Sub



'Hope this helps you
Image
By almaro
#142294
Its even easyer then making a hardware change, add "wr = portc.1" to the config lcd code and it works without modifications.:-)