Cooking Timer
Mikrobasic Pro Code
program sevenSEGCOOKTMR
dim i as byte
dim j as byte
dim v as byte
dim por1 as byte
dim por2 as byte
dim counter , counter12 as byte
dim a as integer
' This function returns masks
' for common cathode 7-seg display
sub function mask(dim num as longword) as byte
select case num
case 0 result = 0xc0
case 1 result = 0xf9
case 2 result = 0xa4
case 3 result = 0xb0
case 4 result = 0x99
case 5 result = 0x92
case 6 result = 0x82
case 7 result = 0xf8
case 8 result = 0x80
case 9 result = 0x90
end select
end sub
sub procedure interrupt
if v = 0 then
PORTB = por1 ' Prepare mask for digit
PORTa = 1 ' Turn on 1st, turn off 2nd 7seg
v = 1
else
PORTB = por2 ' Prepare mask for digit
PORTa = 2 ' Turn on 2nd, turn off 1st 7seg
v = 0
end if
TMR0 = 0
INTCON = $20
end sub
sub procedure counterstart
i=0
while i+ counter >0
for counter12 = counter to 0 step-1
' Prepare ones digit
j = counter12 mod 10
por1 = mask(j)
' Prepare tens digit
j = (counter12 div 10) mod 10
por2 = mask(j)
for a=0 to 1000 step 1 'MIA EXTRA METAVLITI GIA NA DIARESOUME TA 56MS KAI NA TA KANOUME 56000
if counter12=0 then break 'ME TO BREAK SPAME TIN LOOPA
end if
delay_ms(56)
next a
if counter12<1 then 'ALARM
Sound_Init(PORTA, 3)
Sound_Init(PORTA, 3)
Sound_Play(6300, 100)
Sound_Play(4300, 100)
Sound_Play(2300, 1000)
Sound_Play(6300, 100)
Sound_Play(4300, 100)
Sound_Play(2300, 1000)
Sound_Play(6300, 100)
Sound_Play(4300, 100)
Sound_Play(2300, 1000)
Sound_Play(6300, 100)
Sound_Play(4300, 100)
Sound_Play(2300, 1000)
Sound_Play(6300, 100)
Sound_Play(4300, 100)
Sound_Play(2300, 100)
Sound_Play(6300, 100)
Sound_Play(4300, 100)
Sound_Play(2300, 1000)
end if
counter=0 'GIA NA STAMATAEI STO 0 MOLIS TELEIWNEI I ANTRISTROFI
next counter12
wend
end sub
main:
cmcon=0 'disable comparators
vrcon=0
OPTION_REG = $80
por2 = $3F
j = 0
TMR0 = 0
INTCON = $A0
TRISA.0=0
TRISA.1=0
TRISA.2=0
TRISA.3=0
TRISA.4=1
TRISA.5=1
TRISA.6=0
TRISB = 0
PORTB = 0
PORTA=0
counter=0
i=0
while TRUE
'Prepare ones digit
j = counter mod 10
por1 = mask(j)
' Prepare tens digit
j = (counter div 10) mod 10
por2 = mask(j)
if Button(PORTa, 5, 50, 0) then
Sound_Init(PORTA, 3)
Sound_Play(11500, 30)
inc(counter)
end if
if Button(PORTA,4,50,0) then
Sound_Init(PORTA, 3)
Sound_Play(7869, 400)
counterstart
end if
wend
end.