Bascom and lcd

The LCD and Keypad Shield gives you a handy 16-character by 2-line display, 5 buttons and a controllable backlight.
Post Reply
ascii
Posts: 4
Joined: Sat Feb 01, 2014 1:12 pm

Bascom and lcd

Post by ascii » Mon Feb 03, 2014 12:09 am

Hi all, just been playing around with the LCD shield and Bascom as C makes me want to hurt small fluffy animals.

anyway here's some basic "Basic" code to display some adc values and button presses.

using the usbdroid board

Code: Select all



$regfile = "m328pdef.dat"
$crystal = 16000000
Config Timer2 = Pwm , Prescale = 1 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Up
Config Adc = Single , Prescaler = Auto
Config Lcd = 16x2
Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7 , E = Portb.2 , Rs = Portb.0
'----------------------------------------------------------------------------------------------------------------
Dim C As Byte
Dim Backlight As Byte
Dim Kpad As Word
Dim Moist_raw As Word
Dim Moist_ave As Word
Dim A As Byte
'---------------------------------------------------------------------------------------------------------------
Start Adc
Cls
Backlight = 50
C = 0
Cursor Off
'----------------------------------------------------------------------------------------------------------------

Main:
Do

If Backlight > 100 Then Backlight = 100
If Backlight < 5 Then Backlight = 5
Pwm2b = Backlight

Kpad = Getadc(0 , 64 )
Moist_raw = Getadc(1 , 64)

'--------------average adc moisture value----------------------------
Incr C
Moist_ave = Moist_ave + Moist_raw

  If C = 10 Then
  Moist_ave = Moist_ave / 10
  Locate 1 , 1 : Lcd "m=" ; Moist_ave ; "  "
  Moist_ave = 0
  C = 0
Else
End If
'--------------------------------------------------------------------


Locate 1 , 10 : Lcd "b=" ; Backlight ; "  "
Locate 2 , 10 : Lcd "s=" ; Kpad ; "   "
Locate 2 , 1 : Lcd "m=" ; Moist_raw

       If Kpad < 50 Then : Kpad = 0                         'right button
  Elseif Kpad < 170 Then : Kpad = 1                         'up button
  Elseif Kpad < 350 Then : Kpad = 2                         'down button
  Elseif Kpad < 550 Then : Kpad = 3                         'left button
  Elseif Kpad < 750 Then : Kpad = 4                         'select button
  Elseif Kpad > 1000 Then : Kpad = 5                        'no button
  End If

 Home Lower
 On Kpad Gosub Bright , Bup , Bdown , Bleft , Bselect , Bnobutton
 Waitms 250
 Loop


 End

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Bright:
Lcd "right "
Return

Bup:
Lcd "up    "
Backlight = Backlight + 5
Return

Bdown:
Lcd "down  "
Backlight = Backlight - 5
Return

Bleft:
Lcd "left  "
Return

Bselect:
Lcd "select"
Return

Bnobutton:

Return

andrew
Freetronics Staff
Freetronics Staff
Posts: 978
Joined: Sun Jul 14, 2013 7:06 am
Location: Melbourne, Australia
Contact:

Re: Bascom and lcd

Post by andrew » Mon Feb 03, 2014 2:38 am

Thanks for that, always interesting to see other ways of doing things.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests