Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Dim i As Byte
Dim rtim As Word 'number of cycles
Dim mtim As Word 'max time allowed (in cycles)
Dim react(10) As Word 'array to hold reaction times
'new variables from the forum example
Dim ms As Word
Dim seconds As Word
i = 0
main: 'i will have to restart the pic to reset - fine for now
If PORTB.0 = 1 Then
Goto ledon 'simplified version of final app - using 1 led and 1 button
Endif 'just want this timing issue sorted please.
If PORTB.1 = 1 Then
Goto getnewframes
Endif
Goto main
ledon:
PORTA.1 = 1 'led on
getkey:
If PORTB.2 = 1 Then 'reaction button
PORTA.1 = 0 'turn out the light...
rtim = ms
react(i) = ms 'save reaction into array
i = i + 1
'WaitMs(3000) 'wait 3sec before led on
Goto ledon 'start led on again and get another timing
Endif
If PIR1.TMR2IF = 1 Then
PIR1.TMR2IF = 0
ms = ms + 1
If ms = 1000 Then
ms = 0
seconds = seconds + 1
Endif
Endif
If ms > 2 Then 'no key pressed yet so we goto next
PORTA.1 = 0 'turn out the light
'WaitMs(3000)
Goto ledon
i = i + 1
Endif
Goto getkey
getnewframes:
'serial data from pc - code not needed
'when done we start ledon
TRISB = 0x00 'set all PORTB pins as outputs
Config PORTB = Input
INTCON.T0IE = 1 'enable Timer0 interrupts
INTCON.GIE = True 'enable all un-masked interrupts
OPTION_REG.T0CS = False 'set Timer0 clock source to internal instruction cycle clock
Dim i As Byte
Dim rtim As Word 'number of cycles
Dim react(10) As Word 'array to hold reaction times
Dim ms As Word
Dim seconds As Word
i = 0
main: 'i will have to restart the pic to reset - fine for now
If PORTB.0 = 1 Then
Goto ledon 'simplified version of final app - using 1 led and 1 button
Endif 'just want this timing issue sorted please.
If PORTB.1 = 1 Then
Goto getnewframes
Endif
Goto main
ledon:
PORTA.1 = 1 'led on
getkey:
If PORTB.2 = 1 Then 'reaction button
PORTA.1 = 0 'turn out the light...
rtim = ms
react(i) = ms 'save reaction into array
i = i + 1
'WaitMs(3000) 'wait 3sec before led on
Goto ledon 'start led on again and get another timing
Endif
If ms > 2 Then 'no key pressed yet so we goto next
PORTA.1 = 0
ms = 0 'turn out the light
'WaitMs(3000)
i = i + 1
Goto ledon
Endif
Goto getkey
getnewframes: 'serial data from pc - code not needed
End
On Interrupt 'interrupt routine
ms = ms + 1 'decrement the value on PORTB
INTCON.T0IF = 0 'enable new TMR0 interrupts
Resume
thanks for checking the code - however would the value in ms = mseconds? based on 4mhz?
Hi
- but the adc will follow soon coz i want to build a temp sensor (which has been done to death - but i want my own and in basic ! LOL).
thanks for the link.
just noticed something in the sim, can i "use" the timer/interupt pin? or should it be left open? Using the Pic 16f874A.
thanks - but in general is it ok to use the timer pins?
and
INTCON.T0IE = 1 'enable Timer0 interrupts
Then
INTCON.T0IE = 2 'enable Timer1 interrupts ?? if pic has more than one?
as i understand it... the timer function will fire "automatically". If i use the timer pin as an input and it is triggered would that not also cause the timer function to fire aswell ?? sorry for the "simple" question, but i would rather ask.
could you pls show a sml piece of code for somthing like: on interrupt 1 , on interrupt 2 ?
repeat after me : "Google is your friend...", heheh
I guess my input to oshonsoft would be to help us "lazy" programmers by providing an intellisense feature so that we can check what other attributes there are to functions and SFR's.