Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 13:44 29 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : uMite timer with keypad and LCD display

Author Message
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 10:19pm 28 Apr 2014
Copy link to clipboard 
Print this post

This thread follows on from another thread Umite keypad and interrupts to document the finalised version of MicroMite code to run a UV exposure box timer. The timer uses a 4x4 keypad for input and 20x4 LCD display.

Greg

'UVTimer - Author: Greg Yaxley with contributions
'from David Mortimer.
'Program to enter, display & control exposure time for
'a UV lamp box using a 4x4 keypad & 4x20 LCD display.
'MicroMite Basic V Beta 15-28 pin.
'----------------------------------------------
LCD INIT 2,3,4,5, 23,24
lcd clear
Keypad KeyCode, Key_Int, 15,16,17,18,6,7,9,10
led = 14 'pin no. for lamps-ON led
buzz = 21 'pin no. for buzzer
timeset = 0 'time is not set
setpin buzz,DOUT

display_menu:
settick 0,0
lcd cmd 12 'make cursor invisible (turn off)
if timeset = 0 then Mins$ = "00": secs$ = "00"
lcd 1,1, " Time set = "+ mins$ +":"+ secs$
lcd 2,c20, ""
LCD 3,1, "Reset time - Press A"
LCD 4,1, "Lamps ON - Press B"
do
if keycode = 20 goto set_time
if keycode = 21 goto lamps_ON
if keycode = 23 goto display_menu
loop

set_time:
settick 0,0
mins$= "": secs$= "" 'null default time strings
timeset = 0
lcd 2,c20,""
lcd 3,1, " Enter set time "
lcd 4,1, " MENU - Press D "
lcd 1,13, "" 'set cursor at 'mins' position
lcd cmd 15 'turn cursor on

for count = 1 to 2 'get the two minutes digits
get_keycode
if keycode = 23 then goto display_menu
if keycode > 9 then goto set_time
mins$ = mins$ + keycode$ 'build mins$
lcd 1,13, mins$ 'display current mins$ string
next
lcd cmd 20 'move cursor past ":"

for count = 1 to 2 'get the two seconds digits
get_keycode
if keycode = 23 then goto display_menu
if keycode >9 then goto set_time
if keycode >5 and count =1 then
beep (2,100,100) 'out-of-bounds secs entry
goto set_time
endif
secs$ = secs$ + keycode$ 'build secs$
lcd 1,16, secs$ 'display current secs$ string
next
timeset = 1
lcd cmd 12 'make cursor invisible (turn off)
'----------end of set_time:------------------

lamps_ON: 'if time is set, turns lamps ON, counts down,
if timeset = 0 then beep (2,50,50)
if timeset = 1 then '& then turns OFF. Exits if requested.
LCD 3,1, "Reset time - Press A"
LCD 4,1, "Lamps ON - Press B"
if keycode = 20 then goto set_time
if keycode = 21 then
setpin led,DOUT 'make lamp/relay pin digital out
setpin buzz,DOUT 'make buzzer pin digital out
lcd 2,1, "Countdown = "+ mins$ +":"+ secs$
lcd 3,1, " - LAMPS ON - "
lcd 4,1, "Lamps OFF - Press C "
beep (3,200,200) 'buzz "lamps-ON" - 3 short beeps
mins = val(mins$): secs = val(secs$)
totsecsrem = (mins*60)+secs 'total secs for countdown
pin(led) = 1 'turn ON lamp LED & relay
settick 1000,countdown 'interrupt each second for countdown
do while totsecsrem > 0
if keycode > 21 then exit do 'exit if C or D pressed
loop
'-------lamps_OFF------
settick 0,0 'stop countdown interrupt
beep (1,800,0) '1 long beep = "lamps OFF"
pin(led) = 0 'turn OFF lamp LED & relay
setpin led,0
'setpin buzz,0
endif
endif
goto display_menu

sub countdown
totsecsrem = totsecsrem - 1 'decrement 1 sec each interrupt
remmins = totsecsrem/60 'convert to mins & mins fraction
dispmins = fix(remmins) 'extract the mins
dispsecs = cint((remmins-dispmins)*60) 'convert fraction to secs
lcd 2,13, str$(dispmins,2,0,"0") +":"+ str$(dispsecs,2,0,"0")
end sub

Key_Int: 'key press detected
keycode$ = str$(keycode)
ireturn

sub get_keycode
keycode$ = "99"
do
loop until keycode$ <> "99"
end sub

sub beep (beeps,ontime,offtime)
for i=1 to beeps
pin(buzz)=1: pause ontime
pin(buzz)=0
if i < beeps then pause offtime
next
end sub


 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 09:09pm 29 Apr 2014
Copy link to clipboard 
Print this post

Hi Greg,

Looks like a nice handy programme.

Hook up a RTC and it can be used as a timed "switch on" as well as a duration timer.
David M.
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 12:50am 30 Apr 2014
Copy link to clipboard 
Print this post

Yes that's a pretty straight forward addition for projects that need it. I've got three pins left over on the 28 pinner so I think I'll have go at controlling the LCD display brightness - first job for Mick's MuP board

Greg
 
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 01:50am 30 Apr 2014
Copy link to clipboard 
Print this post

Hi Paceman,

Nice program! This is a keeper for sure as it tackles several different IO aspects and how to handle them. Very well done!
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 03:50am 30 Apr 2014
Copy link to clipboard 
Print this post

Thanks Jim, I thought it was a good demo exercise too - plus being something I needed. I wouldn't have tried to do the flashing cursor if Geoff hadn't provided the "LCD CMD" command for us, but that made it straight forward and it works well. The mods that Geoff successively made to formatting the "STR$" function made that part work well too.

If I can get PWM control working for the LCD backlight (via the "*" and "#" keys) I'll update the code here. That'll make it an even better demo and I'll pretty much have run out of pins - just two left so I don't feel greedy .

Greg
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 07:36am 30 Apr 2014
Copy link to clipboard 
Print this post

You can still add a temperature sensor. :)

Looks like a nice project and i have a need for something similar soon.

Thanks for sharing!
Microblocks. Build with logic.
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 03:43pm 30 Apr 2014
Copy link to clipboard 
Print this post

Good point TZ - now if I could just figure out why that might be useful....
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 07:22pm 30 Apr 2014
Copy link to clipboard 
Print this post

Closed box, UV light.
When in use temperature will rise.
You can monitor that and control a fan.

The goal: No more two pins left. :)


Microblocks. Build with logic.
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 01:14am 01 May 2014
Copy link to clipboard 
Print this post

I like your drift - but someone's bound to mention there's a 44 pin version available
 
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 05:52am 01 May 2014
Copy link to clipboard 
Print this post

Hi Paceman,

I'm not sure if you keep up with this forum often, but there is also a 44 pin version of the micromite you could use if you run out of pins on the 28.

( I couldn't resist)

Again, great code!!!
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 09:42pm 02 May 2014
Copy link to clipboard 
Print this post

OK fellas, I couldn't resist either. Below is the latest version with the PWM brightness control for the LCD module added - it's very simple hardware-wise to implement and below is my arrangement.

1. Connect your 5v supply to the LED backlight's anode which is on pin 15 of the 'standard' HD44780 compatible LCD module's 16 pin connector.
2. Connect the backlight cathode (pin 16 of the LCD module's 16 pin connector) to the collector of a BC337 or similar NPN transistor.
3. Connect the BC337 emitter to Gnd via a 100 ohm resistor (or a pot) to adjust the max current through the LED's - mine's pulling about 10mA max. but could handle considerably more I think.
4. Connect the base of the BC337 to pin 26 of the MicroMite (PWM Ch 2A) via a 1K resistor - this draws about 1mA.

That's it - can some kind soul do a schematic for it please .

The * and # keys control the PWM duty cycle and thus the brightness. I've used a default of 80% for the dutycycle and 10% for steps. You get your max brightness obviously at 100% (it'll tell you) but if that isn't enough then you'll need to reduce the value of the resistor to Gnd.

Greg

'UVTimer - Author: Greg Yaxley with contributions
'from David Mortimer. 2nd May 2014

'Program to enter, display & control exposure time for
'a UV lamp box using a 4x4 keypad & 4x20 LCD display.
'MicroMite Basic V4.5_28 pin.
'----------------------------------------------
OPTION AUTORUN ON 'run on power-up
dutycycle = 80 'default dutycycle for PWM (brightness)
pwm 2,50,dutycycle 'LCD backlight PWM control: 2A 50Hz 80%
LCD INIT 2,3,4,5, 23,24 'backlight on Ch. 2A (pin 26)
LCD clear
Keypad KeyCode, Key_Int, 15,16,17,18,6,7,9,10
led = 14 'pin no. for lamps-ON led
buzz = 21 'pin no. for buzzer
timeset = 0 'flag: exposure time is not set
pin(led)=0: pin(buzz)=0 'ensure led, lamps and buzzer start OFF
setpin led,DOUT
setpin buzz,DOUT

display_menu:
keycode = 99 'reset keypad
settick 0,0 'turn OFF timer interrupt
lcd cmd 12 'make cursor invisible (turn off)
if timeset = 0 then Mins$ = "00": secs$ = "00" 'default time
lcd 1,1, " Time set = "+ mins$ +":"+ secs$
lcd 2,1, " Brightness * or # "
'lcd 2,c20, "" 'clear LCD line 2
LCD 3,1, "Reset time - Press A"
LCD 4,1, "Lamps ON - Press B"
do
if keycode = 20 goto set_time 'key A
if keycode = 21 goto lamps_ON 'key B
if keycode = 23 goto display_menu 'key D
if keycode = 10 or keycode = 11 then brightness 'keys * and #
loop

set_time:
settick 0,0
mins$= "": secs$= "" 'null default time strings
timeset = 0 're-zero time-set flag
lcd 2,c20,""
lcd 3,1, " Enter set time "
lcd 4,1, " MENU - Press D "
lcd 1,13, "" 'set cursor at 'mins' position
lcd cmd 15 'turn cursor on

for count = 1 to 2 'get the two minutes digits
get_keycode
if keycode = 23 then goto display_menu
if keycode > 9 then goto set_time
mins$ = mins$ + keycode$ 'build mins$
lcd 1,13, mins$ 'display current mins$ string
next
lcd cmd 20 'move cursor past ":"

for count = 1 to 2 'get the two seconds digits
get_keycode
if keycode = 23 then goto display_menu
if keycode > 9 then goto set_time
if keycode > 5 and count = 1 then
beep (2,100,100) 'out-of-bounds secs entry
goto set_time
endif
secs$ = secs$ + keycode$ 'build secs$
lcd 1,16, secs$ 'display current secs$ string
next
timeset = 1 'flag: time correctly set
lcd cmd 12 'make cursor invisible (turn off)
'----------end of set_time:------------------

lamps_ON: 'If time is set, turns lamps ON, counts down
if timeset = 0 then beep (2,50,50) '& then turns OFF.
if timeset = 1 then 'Exits if requested.
LCD 3,1, "Reset time - Press A" 'keycode 20
LCD 4,1, "Lamps ON - Press B" 'keycode 21
if keycode = 20 then goto set_time
if keycode = 21 then 'legitimite request for "lamps ON"
setpin led,DOUT 'make lamp/relay pin digital out
setpin buzz,DOUT 'make buzzer pin digital out
lcd 2,1, "Countdown = " +mins$ +":" +secs$ +" "
lcd 3,1, " - LAMPS ON - "
lcd 4,1, "Lamps OFF - Press C "
beep (3,200,200) 'buzz "lamps-ON" - 3 short beeps
mins = val(mins$): secs = val(secs$)
totsecsrem = (mins*60)+secs 'total secs for countdown
pin(led) = 1 'turn ON lamp LED & relay
settick 1000,countdown 'interrupt each second for countdown
do while totsecsrem > 0
if keycode > 21 then exit do 'exit if C or D pressed
loop
'-------lamps_OFF------
settick 0,0 'stop countdown interrupt
beep (1,800,0) 'one long beep = "lamps OFF"
pin(led) = 0 'turn OFF lamp LED & relay
endif
endif
goto display_menu

Key_Int: 'key press detected
keycode$ = str$(keycode)
ireturn

sub get_keycode
keycode$ = "99"
do
loop until keycode$ <> "99"
end sub

sub countdown
totsecsrem = totsecsrem - 1 'decrement 1 sec each interrupt
remmins = totsecsrem/60 'convert to mins & mins fraction
dispmins = fix(remmins) 'extract the mins
dispsecs = cint((remmins-dispmins)*60) 'convert fraction to secs
lcd 2,13, str$(dispmins,2,0,"0") +":"+ str$(dispsecs,2,0,"0")
end sub 'display 2 digits for mins & secs, & any leading zeros

sub beep (beeps,ontime,offtime)
for i=1 to beeps
pin(buzz)=1: pause ontime
pin(buzz)=0
if i < beeps then pause offtime
next
End sub

sub brightness
lcd 2,c20,""
if keycode = 11 then dutycycle = dutycycle + 10
if keycode = 10 then dutycycle = dutycycle - 10
if dutycycle < 0 then dutycycle = 0
if dutycycle > 100 then
dutycycle = 100
lcd 2,1, " MAXIMUM BRIGHTNESS "
endif
pwm 2,50,dutycycle
keycode = 99
end sub
'------------------Finish---------------------
Edited by paceman 2014-05-04
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024