Nothing 'weird' at all, you didn't add code tags - browsers remove extraneous spaces and tabs, the code tags prevent that.That is so weird. I edited my post above because "the aystem" deleted all of the blank spaces.
browsers remove extraneous spaces and tabs
Browsers remove it - but obviously not when you're entering data, only when displaying it.No, the forum software removes spaces and tabs, else when I edited my post, I wouldn't have seen the original line with the spacers.
program KitchenTimer
device = 18F43K22
clock = 16
// int osc and IO pin libraries
include "intosc.bas"
#option DIGITALIO_INIT = true // automatically call setalldigital
include "setdigitalio.bas"
#option LCD_DATA = PORTD.4
#option LCD_RS = PORTD.2
#option LCD_EN = PORTD.3
include "LCD.bas"
include "convert.bas"
include "utils.bas"
include "ISRTimer.bas"
//SWITCHES
dim SelKey as PORTB.0
dim PlusKey as PORTB.1
dim MinusKey as PORTB.2
dim StartKey as PORTB.3 //start countdown
dim SWT_4 as PORTB.4
dim SWT_5 as PORTB.5
dim SWT_6 as PORTB.6
dim SWT_7 as PORTB.7
//LEDS
dim led0 as PORTC.0 //HOURS+
dim led1 as PORTC.1 //HOURS-
dim led2 as PORTC.2 //MINUTES+
dim led3 as PORTC.3 //MINUTES-
dim led4 as PORTC.4 //SECONDS+
dim led5 as PORTC.5 //SECONDS-
dim led6 as PORTC.6
dim led7 as PORTC.7
dim sel_focus as byte // used to set Plus/Minus key increment (H:M:S)
dim total_secs as word // user input (total H:M:S in secs)
dim timer_secs as word // timer counter
dim t_secs as word // interrupt-safe timer value used for display
// timer index number (one timer)
const Timer1 = 0
// display H:M:S on the LCD
sub DisplayTime(secs as word)
dim t_hours, t_mins, t_secs as byte
dim t_total as word
// convert total secs to individual H,M,S for display
t_total = secs // time to convert
t_hours = t_total / 3600 // number of hours
t_total = t_total - (t_hours * 3600) // subtract hours from total
t_mins = t_total / 60 // number of minutes
t_total = t_total - (t_mins * 60) // subtract minutes from the total
t_secs = t_total // what's left is seconds
// 123456789012345
LCD.WriteAt(1,1,"HRS MIN SEC")
LCD.WriteAt(2,1, DecToStr(t_hours), 3, " ") // print 3 chars, pad w/space
LCD.WriteAt(2,7, DecToStr(t_mins), 3, " ")
LCD.WriteAt(2,13, DecToStr(t_secs), 3, " ")
end sub
// timer event called by ISRTimer to keep track of elapsed time
event OnTimer1()
if (timer_secs > 0) then
timer_secs = timer_secs - 1
endif
end event
// key debounce delay
sub Debounce()
delayms(100)
end sub
// start of main program
main:
// set switch port to inputs and enable pullups
TRISB = $ff // set as inputs
WPUB = $ff // enable pullups on all PORTB pins
INTCON2.bits(7) = 0 // set bit RBPU = 0 turns on pullups
// set led port to outputs, all low
LATC = 0
TRISC = 0
// init variables
total_secs = 0
timer_secs = 0
// init LCD
LCD.Cls()
// activate the timer module for one timer...
Timer.Initialize(1)
// wait for START button
// the SEL button is used to select H:M:S for PLUS/MINUS buttons
// each press increments sel_focus
// sel_focus = 0 PLUS/MINUS Secs
// sel_focus = 1 PLUS/MINUS Mins
// sel_focus = 2 PLUS/MINUS Hrs
while (true)
DisplayTime(total_secs)
sel_focus = 0 // default to Secs
repeat
if (SelKey = 0) then // Sel button
sel_focus = sel_focus + 1
if (sel_focus > 2) then // wrap back to Secs
sel_focus = 0
endif
Debounce()
elseif (PlusKey = 0) then // Plus button
select (sel_focus)
case 0 // incr by secs
total_secs = total_secs + 1
case 1 // incr by mins (60 secs)
total_secs = total_secs + 60
case 2 // incr by hours (3600 secs)
total_secs = total_secs + 3600
end select
DisplayTime(total_secs)
Debounce()
elseif (MinusKey = 0) then // Minus button
select (sel_focus)
case 0 // decr by secs
if (total_secs > 0) then
total_secs = total_secs - 1
endif
case 1 // decr by mins (60 secs)
if (total_secs > 60) then
total_secs = total_secs - 60
endif
case 2 // decr by hours (3600 secs)
if (total_secs > 3600) then
total_secs = total_secs - 3600
endif
end select
DisplayTime(total_secs)
Debounce()
endif
until (StartKey = 0)
// Start timer running
// set timer total seconds counter from user input
timer_secs = total_secs
// initialise the timers - refreshes every 1000Hz (1ms)...
Timer.Items(Timer1).Interval = 1000 // call event every 1 sec
Timer.Items(Timer1).OnTimer = OnTimer1 // timer event handler
Timer.Items(Timer1).Enabled = true
// start processing all timers...
Timer.Start
// wait for timer total secs to count down
repeat
delayms(100) // wait a bit... no sense in hammering the lcd
repeat // get an interrupt-safe copy of the timer seconds
t_secs = timer_secs
until (t_secs = timer_secs)
DisplayTime(t_secs)
until (t_secs = 0)
Timer.Stop
end while
end program
tumbleweed , do you ever wish for more informed replies? That there was a scintilla of understanding or knowledge transfer? Something beyond CNTL-C and CNTL-V?Thanks will run suggestions and make adjustments as needed
// key debounce delay
sub Debounce()
delayms(50)
// wait for all keys to be released
while (PORTB <> $FF)
end while
delayms(50)
end sub
The LCD should display "0 0 0" when the timer finishes, after which it'll go back to the beginning of the 'while (true)' loop and display the last entered time again ( DisplayTime(total_secs) ). Add a 'delayms(1000)' after the timer.stop if you want to see the "0 0 0" better...and figure out what it is displaying when finished.
Timer.Stop
// timer is done... wait a bit
delayms(1000)
end while
program KitchenTimer
device = 18F43K22
clock = 16
// this option sets the longest time for the timer
// select either 'word' (18 hours) or 'longword' (99 hours)
#option MAX_TIME_TYPE = word
#if not(MAX_TIME_TYPE in (word, longword))
#error "MAX_TIME_TYPE option must be 'word' or 'longword'"
#endif
#if (MAX_TIME_TYPE = word)
type time_t = word
const MAX_SECS = 18 * 3600 // limit timer to 18 hours
#else
type time_t = longword
const MAX_SECS = 99 * 3600 // limit timer to 99 hours
#endif
// int osc and IO pin libraries
include "intosc.bas"
#option DIGITALIO_INIT = true // automatically call setalldigital
include "setdigitalio.bas"
#option LCD_DATA = PORTD.4
#option LCD_RS = PORTD.2
#option LCD_EN = PORTD.3
include "LCD.bas"
include "convert.bas"
include "utils.bas"
#option TIMER_AVAILABLE = 1 // we only use one timer
include "ISRTimer.bas"
//SWITCHES
dim AllKeys as PORTB
dim SelKey as PORTB.0
dim PlusKey as PORTB.1
dim MinusKey as PORTB.2
dim StartKey as PORTB.3 //start countdown
dim SWT_4 as PORTB.4
dim SWT_5 as PORTB.5
dim SWT_6 as PORTB.6
dim SWT_7 as PORTB.7
//LEDS
dim ALL_LEDS as PORTC
dim SEC_LED as PORTC.0 // sel_focus = 0 (secs)
dim MIN_LED as PORTC.1 // sel_focus = 1 (mins)
dim HOUR_LED as PORTC.1 // sel_focus = 2 (hours)
dim START_LED as PORTC.2 // waiting for START key
dim RUN_LED as PORTC.3 // timer running
dim led4 as PORTC.4
dim led5 as PORTC.5
dim led6 as PORTC.6
dim led7 as PORTC.7
dim sel_focus as byte // used to set Plus/Minus key increment (H:M:S)
dim total_secs as time_t // user input (total H:M:S in secs)
dim timer_secs as time_t // timer counter
dim t_secs as time_t // interrupt-safe timer value used for display
// timer index number (one timer)
const Timer1 = 0
// display H:M:S on the LCD
sub DisplayTime(secs as time_t)
dim t_hours, t_mins, t_secs as byte
dim t_total as time_t
// convert total secs to individual H,M,S for display
t_total = secs // time to convert
t_hours = t_total / 3600 // number of hours
t_total = t_total - (t_hours * 3600) // subtract hours from total
t_mins = t_total / 60 // number of minutes
t_total = t_total - (t_mins * 60) // subtract minutes from the total
t_secs = t_total // what's left is seconds
// 123456789012345
LCD.WriteAt(1,1,"HRS MIN SEC")
LCD.WriteAt(2,1, DecToStr(t_hours), 3, " ") // print 3 chars, pad w/space
LCD.WriteAt(2,7, DecToStr(t_mins), 3, " ")
LCD.WriteAt(2,13, DecToStr(t_secs), 3, " ")
end sub
// timer event called by ISRTimer to keep track of elapsed time
event OnTimer1()
if (timer_secs > 0) then
timer_secs = timer_secs - 1
endif
end event
// key debounce/ wait for all released
sub WaitForRelease()
delayms(50)
// wait for all keys to be released
while (AllKeys <> $FF)
end while
delayms(50)
end sub
// start of main program
main:
// set switch port to inputs and enable pullups
TRISB = $ff // set as inputs
WPUB = $ff // enable pullups on all PORTB pins
INTCON2.bits(7) = 0 // set bit RBPU = 0 turns on pullups
// set led port to outputs, all low
ALL_LEDS = 0
TRISC = 0
// init variables
total_secs = 0
timer_secs = 0
// init LCD
LCD.Cls()
// activate the timer module for one timer...
Timer.Initialize(1)
// wait for START button
// the SEL button is used to select H:M:S for PLUS/MINUS buttons
// each press increments sel_focus
// sel_focus = 0 PLUS/MINUS Secs
// sel_focus = 1 PLUS/MINUS Mins
// sel_focus = 2 PLUS/MINUS Hrs
while (true)
DisplayTime(total_secs)
sel_focus = 0 // default to Secs
ALL_LEDS = 0
SEC_LED = 1
START_LED = 1
repeat
if (SelKey = 0) then // Sel button
sel_focus = sel_focus + 1
if (sel_focus > 2) then // wrap back to Secs
sel_focus = 0
endif
select (sel_focus)
case 0:
SEC_LED = 1
MIN_LED = 0
HOUR_LED = 0
case 1:
SEC_LED = 0
MIN_LED = 1
HOUR_LED = 0
case 2:
SEC_LED = 0
MIN_LED = 0
HOUR_LED = 1
end select
WaitForRelease()
elseif (PlusKey = 0) then // Plus button
select (sel_focus)
case 0 // incr by secs
if (total_secs < (MAX_SECS-1)) then
total_secs = total_secs + 1
endif
case 1 // incr by mins (60 secs)
if (total_secs < (MAX_SECS-60)) then
total_secs = total_secs + 60
endif
case 2 // incr by hours (3600 secs)
if (total_secs < (MAX_SECS-3600)) then
total_secs = total_secs + 3600
endif
end select
DisplayTime(total_secs)
WaitForRelease()
elseif (MinusKey = 0) then // Minus button
select (sel_focus)
case 0 // decr by secs
if (total_secs > 0) then
total_secs = total_secs - 1
endif
case 1 // decr by mins (60 secs)
if (total_secs > 60) then
total_secs = total_secs - 60
endif
case 2 // incr by hours (3600 secs)
if (total_secs > 3600) then
total_secs = total_secs - 3600
endif
end select
DisplayTime(total_secs)
WaitForRelease()
endif
until (StartKey = 0)
// Start timer running
// set timer total seconds counter from user input
ALL_LEDS = 0
RUN_LED = 1
timer_secs = total_secs
// initialise the timers - refreshes every 1000Hz (1ms)...
Timer.Items(Timer1).Interval = 1000 // call event every 1 sec
Timer.Items(Timer1).OnTimer = OnTimer1 // timer event handler
Timer.Items(Timer1).Enabled = true
// start processing all timers...
Timer.Start
// wait for timer total secs to count down
repeat
delayms(100) // wait a bit... no sense in hammering the lcd
repeat // get an interrupt-safe copy of the timer seconds
t_secs = timer_secs
until (t_secs = timer_secs) // re-read until two successive reads are the same
DisplayTime(t_secs)
toggle(RUN_LED)
until (t_secs = 0)
// timer is done
Timer.Stop
RUN_LED = 0
// wait a bit before looping
delayms(1000)
end while
end program
After some research, my code in post#117 is missing lots of code after while true
BUT running the complete code in #117 it still outputs hexadecimal (not binary)
So the code in post#124 worked but the code in post#132 doesn't?just ran the code in post#132
won't accept any input.
program KitchenTimer
device = 18F43K22
clock = 16
// this option sets the longest time for the timer
// select either 'word' (18 hours) or 'longword' (99 hours)
#option MAX_TIME_TYPE = word
#if not(MAX_TIME_TYPE in (word, longword))
#error "MAX_TIME_TYPE option must be 'word' or 'longword'"
#endif
#if (MAX_TIME_TYPE = word)
type time_t = word
const MAX_SECS = 18 * 3600 // limit timer to 18 hours
#else
type time_t = longword
const MAX_SECS = 99 * 3600 // limit timer to 99 hours
#endif
// this option allows you to ignore the buttons on RB6 and RB7
#option IGNORE_RB6_RB7 = true
// int osc and IO pin libraries
include "intosc.bas"
#option DIGITALIO_INIT = true // automatically call setalldigital
include "setdigitalio.bas"
#option LCD_DATA = PORTD.4
#option LCD_RS = PORTD.2
#option LCD_EN = PORTD.3
include "LCD.bas"
include "convert.bas"
include "utils.bas"
#option TIMER_AVAILABLE = 1 // we only use one timer
include "ISRTimer.bas"
//SWITCHES
dim AllKeys as PORTB
dim SelKey as PORTB.0
dim PlusKey as PORTB.1
dim MinusKey as PORTB.2
dim StartKey as PORTB.3 //start countdown
dim SWT_4 as PORTB.4
dim SWT_5 as PORTB.5
dim SWT_6 as PORTB.6
dim SWT_7 as PORTB.7
//LEDS
dim ALL_LEDS as PORTC
dim SEC_LED as PORTC.0 // sel_focus = 0 (secs)
dim MIN_LED as PORTC.1 // sel_focus = 1 (mins)
dim HOUR_LED as PORTC.1 // sel_focus = 2 (hours)
dim START_LED as PORTC.2 // waiting for START key
dim RUN_LED as PORTC.3 // timer running
dim led4 as PORTC.4
dim led5 as PORTC.5
dim led6 as PORTC.6
dim led7 as PORTC.7
dim sel_focus as byte // used to set Plus/Minus key increment (H:M:S)
dim total_secs as time_t // user input (total H:M:S in secs)
dim timer_secs as time_t // timer counter
dim t_secs as time_t // interrupt-safe timer value used for display
// timer index number (one timer)
const Timer1 = 0
// display H:M:S on the LCD
sub DisplayTime(secs as time_t)
dim t_hours, t_mins, t_secs as byte
dim t_total as time_t
// convert total secs to individual H,M,S for display
t_total = secs // time to convert
t_hours = t_total / 3600 // number of hours
t_total = t_total - (t_hours * 3600) // subtract hours from total
t_mins = t_total / 60 // number of minutes
t_total = t_total - (t_mins * 60) // subtract minutes from the total
t_secs = t_total // what's left is seconds
// 123456789012345
LCD.WriteAt(1,1,"HRS MIN SEC")
LCD.WriteAt(2,1, DecToStr(t_hours), 3, " ") // print 3 chars, pad w/space
LCD.WriteAt(2,7, DecToStr(t_mins), 3, " ")
LCD.WriteAt(2,13, DecToStr(t_secs), 3, " ")
end sub
// timer event called by ISRTimer to keep track of elapsed time
event OnTimer1()
if (timer_secs > 0) then
timer_secs = timer_secs - 1
endif
end event
// key debounce/ wait for all released
sub WaitForRelease()
#if (IGNORE_RB6_RB7)
const KEY_MASK = %11000000
#else
const KEY_MASK = 0
#endif
delayms(50)
// wait for all keys to be released
while ((AllKeys or KEY_MASK) <> $FF)
end while
delayms(50)
end sub
// start of main program
main:
// set switch port to inputs and enable pullups
TRISB = $ff // set as inputs
WPUB = $ff // enable pullups on all PORTB pins
INTCON2.bits(7) = 0 // set bit RBPU = 0 turns on pullups
// set led port to outputs, all low
ALL_LEDS = 0
TRISC = 0
// init variables
total_secs = 0
timer_secs = 0
// init LCD
LCD.Cls()
// activate the timer module for one timer...
Timer.Initialize(1)
// wait for START button
// the SEL button is used to select H:M:S for PLUS/MINUS buttons
// each press increments sel_focus
// sel_focus = 0 PLUS/MINUS Secs
// sel_focus = 1 PLUS/MINUS Mins
// sel_focus = 2 PLUS/MINUS Hrs
while (true)
DisplayTime(total_secs)
sel_focus = 0 // default to Secs
ALL_LEDS = 0
SEC_LED = 1
START_LED = 1
repeat
if (SelKey = 0) then // Sel button
sel_focus = sel_focus + 1
if (sel_focus > 2) then // wrap back to Secs
sel_focus = 0
endif
select (sel_focus)
case 0:
SEC_LED = 1
MIN_LED = 0
HOUR_LED = 0
case 1:
SEC_LED = 0
MIN_LED = 1
HOUR_LED = 0
case 2:
SEC_LED = 0
MIN_LED = 0
HOUR_LED = 1
end select
WaitForRelease()
elseif (PlusKey = 0) then // Plus button
select (sel_focus)
case 0 // incr by secs
if (total_secs < (MAX_SECS-1)) then
total_secs = total_secs + 1
endif
case 1 // incr by mins (60 secs)
if (total_secs < (MAX_SECS-60)) then
total_secs = total_secs + 60
endif
case 2 // incr by hours (3600 secs)
if (total_secs < (MAX_SECS-3600)) then
total_secs = total_secs + 3600
endif
end select
DisplayTime(total_secs)
WaitForRelease()
elseif (MinusKey = 0) then // Minus button
select (sel_focus)
case 0 // decr by secs
if (total_secs > 0) then
total_secs = total_secs - 1
endif
case 1 // decr by mins (60 secs)
if (total_secs > 60) then
total_secs = total_secs - 60
endif
case 2 // decr by hours (3600 secs)
if (total_secs > 3600) then
total_secs = total_secs - 3600
endif
end select
DisplayTime(total_secs)
WaitForRelease()
endif
until (StartKey = 0)
// Start timer running
// set timer total seconds counter from user input
ALL_LEDS = 0
RUN_LED = 1
timer_secs = total_secs
// initialise the timers - refreshes every 1000Hz (1ms)...
Timer.Items(Timer1).Interval = 1000 // call event every 1 sec
Timer.Items(Timer1).OnTimer = OnTimer1 // timer event handler
Timer.Items(Timer1).Enabled = true
// start processing all timers...
Timer.Start
// wait for timer total secs to count down
repeat
delayms(100) // wait a bit... no sense in hammering the lcd
repeat // get an interrupt-safe copy of the timer seconds
t_secs = timer_secs
until (t_secs = timer_secs) // re-read until two successive reads are the same
DisplayTime(t_secs)
toggle(RUN_LED)
until (t_secs = 0)
// timer is done
Timer.Stop
RUN_LED = 0
// wait a bit before looping
delayms(1000)
end while
end program
disable_intr()
t_secs = timer_secs
enable_intr()
uint32_t getMs(void){
uint32_t retVal;
flagISR=0;
retVal=tickMs;
if(flagISR) //if Interrupt occurred
retVal=tickMs; //fetch milli seconds again
return(retVal);
}
uint32_t getMs(void){
uint32_t retVal;
retVal=tickMs;
if(retVal!=tickMs) //if Interrupt occurred
retVal=tickMs; //fetch milli seconds again
return(retVal);
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?