mike_s
01-02-2006, 09:16 AM
Hi,
I'm just a poor electrician struggling with the programming side of the stamp.
I have been attempting first to get an LCD running which worked finally for me but only in 8 bit mode.
The end purpose will be to replace my microwaves mechanical timer with a digital control. While you can pick up something like this for as little as
80 dollars Australian because I work in the appliance field this interests me as a starting point.
Having mastered the operation of the Hitachi style 2x16 display The next phase is the countdown timer.
I have achieved that I believe after much head banging but was wondering if my code is ok or if there is a better way to tackle it.
Keep·in mind that the time will be set by keypad when completed. I have the keypad just about ready(But for plugs on the end of the wires)
For testing purposes the countdown time is entered by the program.
If this code is ok will I be able to successfully add another block of code for the keypad to enter the time?
I·was going to add a time of day clock but changed my mind because I wouldn't know how to integrate a 555 timer with the stamp or if this would even work.
' ================================================== =======================
' File...... Countdown timer.BS2
' Purpose... Countdown timer for Parallel LCD Display
' Author.... Mike Seiler
' E-mail.... ms767210@bigpond.net.au (mailto:ms767210@bigpond.net.au)
' {$PBASIC 2.5}
' {$STAMP BS2}
' -----[ I/O Definitions ]-------------------------------------------------
··· E CON 6 ' Enable Pin For LCD
··· RW CON 5 ' R/W Pin For LCD
··· RS CON 4 ' LCD Register Select· 0 = Instruction, 1 = Text
' -----[ Variables ]-------------------------------------------------------
··· char VAR Byte········ ' Character To Send To LCD
··· index VAR Nib
··· tens_minutes VAR Nib
··· minutes VAR Nib
··· tens_seconds VAR Nib
··· seconds VAR Nib
··· tens_minutes = 0····· 'Preset time
··· minutes = 1·········· 'within program
··· tens_seconds = 0····· 'temporary till keypad
··· seconds = 0·········· 'and code is added
' -----[ Constants ]-------------------------------------------------------
··· Clr_Display CON %00000001···· ' Clear the display
··· Rtrn_Home CON %00000010······ 'Return Home without clearing display
··· EntryMode_Set CON %00000100·· 'Still don't understand this function?
··· Display_Off CON %00001000···· ' Turn display off
··· Display_On CON %00001100····· ' Turn display on
··· Modeset CON %00111000········ ' Set 8 bit mode 2 lines and 5x7 characters
' Initialise I/O ----------------------------------------------------------
··· DIRB = %1110················· 'set pins 4,5 and 6 as outputs
··· OUTB = %0000················· 'clear them
··· DIRH = %11111111············· 'set pins 8-15 as outputs(unfortunately I had no success in running it in 4 bit mode
··· OUTH = %00000000············· 'but will have to complete this task yet to free up needed pins
main:
··· PAUSE 200············ 'delay till power reaches desired level ON powerup
··· char = Modeset······· 'I think there is enough info about on this sequence
··· GOSUB lcdcmd
··· char = Display_Off
··· GOSUB LCDcmd
··· char = Display_On
··· GOSUB LCDcmd
··· char = Clr_Display
··· GOSUB LCDcmd
··· char = EntryMode_Set
··· GOSUB LCDcmd
··· GOSUB Update_display
··· tens_seconds = 6
Countdown:
· FOR seconds = 9 TO 0···· 'Main loop consists of many conditionals essential to maintaining proper time display
· IF seconds = 9 THEN tens_seconds = tens_seconds - 1
· IF seconds = 9 AND tens_seconds = 15 THEN minutes = minutes - 1
· IF seconds = 9 AND tens_seconds = 5 THEN minutes = minutes - 1
· IF seconds = 9 AND tens_seconds = 5 AND minutes = 9 AND tens_minutes <>0 THEN tens_minutes = tens_minutes - 1
· IF seconds = 9 AND tens_seconds = 15 AND minutes = 15 AND tens_minutes <> 0 THEN tens_minutes = tens_minutes - 1
· IF tens_seconds = 15 THEN tens_seconds = 5
· IF minutes = 15 THEN minutes = 9
· PAUSE 990
· GOSUB Update_display
· IF tens_minutes = 0 AND minutes = 0 AND tens_seconds = 0 AND seconds = 0 THEN finished
· NEXT
· IF seconds = 15 THEN Countdown
LCDcmd:
··· OUTH = char············ 'Send an instruction to LCD
··· LOW RS
··· PULSOUT E, 1
··· RETURN
LCDwr:
··· OUTH = char············ 'Send data to LCD
··· HIGH RS
··· PULSOUT E, 1
··· RETURN
Update_display:
·· char = Rtrn_Home························· 'Return Home and rewrite
·· GOSUB LCDcmd
·· char = tens_minutes + 48················· 'value 48 is added to display correct numeric character as part of time remaining display
·· GOSUB LCDwr
·· char = minutes + 48······················ 'character
·· GOSUB LCDwr
·· char = 58································ ': character of the time remaining display
·· GOSUB LCDwr
·· char = tens_seconds + 48················· 'etc..
·· GOSUB LCDwr
·· char = seconds + 48
·· GOSUB LCDwr
·· RETURN
·· Finished:
DEBUG "DONE!"
·
I'm just a poor electrician struggling with the programming side of the stamp.
I have been attempting first to get an LCD running which worked finally for me but only in 8 bit mode.
The end purpose will be to replace my microwaves mechanical timer with a digital control. While you can pick up something like this for as little as
80 dollars Australian because I work in the appliance field this interests me as a starting point.
Having mastered the operation of the Hitachi style 2x16 display The next phase is the countdown timer.
I have achieved that I believe after much head banging but was wondering if my code is ok or if there is a better way to tackle it.
Keep·in mind that the time will be set by keypad when completed. I have the keypad just about ready(But for plugs on the end of the wires)
For testing purposes the countdown time is entered by the program.
If this code is ok will I be able to successfully add another block of code for the keypad to enter the time?
I·was going to add a time of day clock but changed my mind because I wouldn't know how to integrate a 555 timer with the stamp or if this would even work.
' ================================================== =======================
' File...... Countdown timer.BS2
' Purpose... Countdown timer for Parallel LCD Display
' Author.... Mike Seiler
' E-mail.... ms767210@bigpond.net.au (mailto:ms767210@bigpond.net.au)
' {$PBASIC 2.5}
' {$STAMP BS2}
' -----[ I/O Definitions ]-------------------------------------------------
··· E CON 6 ' Enable Pin For LCD
··· RW CON 5 ' R/W Pin For LCD
··· RS CON 4 ' LCD Register Select· 0 = Instruction, 1 = Text
' -----[ Variables ]-------------------------------------------------------
··· char VAR Byte········ ' Character To Send To LCD
··· index VAR Nib
··· tens_minutes VAR Nib
··· minutes VAR Nib
··· tens_seconds VAR Nib
··· seconds VAR Nib
··· tens_minutes = 0····· 'Preset time
··· minutes = 1·········· 'within program
··· tens_seconds = 0····· 'temporary till keypad
··· seconds = 0·········· 'and code is added
' -----[ Constants ]-------------------------------------------------------
··· Clr_Display CON %00000001···· ' Clear the display
··· Rtrn_Home CON %00000010······ 'Return Home without clearing display
··· EntryMode_Set CON %00000100·· 'Still don't understand this function?
··· Display_Off CON %00001000···· ' Turn display off
··· Display_On CON %00001100····· ' Turn display on
··· Modeset CON %00111000········ ' Set 8 bit mode 2 lines and 5x7 characters
' Initialise I/O ----------------------------------------------------------
··· DIRB = %1110················· 'set pins 4,5 and 6 as outputs
··· OUTB = %0000················· 'clear them
··· DIRH = %11111111············· 'set pins 8-15 as outputs(unfortunately I had no success in running it in 4 bit mode
··· OUTH = %00000000············· 'but will have to complete this task yet to free up needed pins
main:
··· PAUSE 200············ 'delay till power reaches desired level ON powerup
··· char = Modeset······· 'I think there is enough info about on this sequence
··· GOSUB lcdcmd
··· char = Display_Off
··· GOSUB LCDcmd
··· char = Display_On
··· GOSUB LCDcmd
··· char = Clr_Display
··· GOSUB LCDcmd
··· char = EntryMode_Set
··· GOSUB LCDcmd
··· GOSUB Update_display
··· tens_seconds = 6
Countdown:
· FOR seconds = 9 TO 0···· 'Main loop consists of many conditionals essential to maintaining proper time display
· IF seconds = 9 THEN tens_seconds = tens_seconds - 1
· IF seconds = 9 AND tens_seconds = 15 THEN minutes = minutes - 1
· IF seconds = 9 AND tens_seconds = 5 THEN minutes = minutes - 1
· IF seconds = 9 AND tens_seconds = 5 AND minutes = 9 AND tens_minutes <>0 THEN tens_minutes = tens_minutes - 1
· IF seconds = 9 AND tens_seconds = 15 AND minutes = 15 AND tens_minutes <> 0 THEN tens_minutes = tens_minutes - 1
· IF tens_seconds = 15 THEN tens_seconds = 5
· IF minutes = 15 THEN minutes = 9
· PAUSE 990
· GOSUB Update_display
· IF tens_minutes = 0 AND minutes = 0 AND tens_seconds = 0 AND seconds = 0 THEN finished
· NEXT
· IF seconds = 15 THEN Countdown
LCDcmd:
··· OUTH = char············ 'Send an instruction to LCD
··· LOW RS
··· PULSOUT E, 1
··· RETURN
LCDwr:
··· OUTH = char············ 'Send data to LCD
··· HIGH RS
··· PULSOUT E, 1
··· RETURN
Update_display:
·· char = Rtrn_Home························· 'Return Home and rewrite
·· GOSUB LCDcmd
·· char = tens_minutes + 48················· 'value 48 is added to display correct numeric character as part of time remaining display
·· GOSUB LCDwr
·· char = minutes + 48······················ 'character
·· GOSUB LCDwr
·· char = 58································ ': character of the time remaining display
·· GOSUB LCDwr
·· char = tens_seconds + 48················· 'etc..
·· GOSUB LCDwr
·· char = seconds + 48
·· GOSUB LCDwr
·· RETURN
·· Finished:
DEBUG "DONE!"
·