'Timer Test V1.0 Camerart 12.02.14
'Uses 12f683, internal 4mHz clock
'Define SIMULATION_WAITMS_VALUE = 1 'SIMULATION ONLY
Define CONF_WORD = %11001111000100 '0x33c4
Dim an0 As Word 'setting an0 as WORD length makes ADC count =1023 max
Dim an1 As Word 'if set as BYTE length makes ADC count =255 max
Dim t As Word 't = Ticks counter, incremented on INTERRUPT
Dim firstpulse As Byte 'Check Byte or word
Dim secondpulse As Byte
Symbol rled = GP2 'LED's
Symbol gled = GP5
OSCCON = %01100000 'Internal 4MHz osc
CMCON0 = %00000111 '7 'Comparators off
WPU = 0 'Internal pull-ups = off
OPTION_REG = %10000000 'Pull ups, TMR0, Prescaler
INTCON = %10000000 'Timer interrupt bits
ANSEL = %01000011 '0x03 '0-3 Selecting pins Analogue Digital 6 Fosc/4
ADCON0 = %00000101 'A/D 0x85?
'[in theory ALL these should start up as '0' at power ON
'but its wise to ensure that they are!]
PIE1 = 0 'peripheral intr disable
INTCON.INTE = 0
INTCON.T0IF = 0
PIE1.TMR1IE = 0 'Disable Timer 1 Overflow Interrupt
PIR1.TMR1IF = 0 'Clear Timer 1 Overflow Interrupt Flag
'set I/O pin direction
'(TRISIO = %XX001011) [ list pins in same order as binary bits]
TRISIO.5 = 0 'PIN 5 as gled
TRISIO.4 = 0 'PIN 4 unused
TRISIO.3 = 1 'PIN 5 as Button input (IN ONLY)
TRISIO.2 = 0 'PIN 5 as rled
TRISIO.1 = 1 'PIN 6 as analog1
TRISIO.0 = 1 'PIN 7 as analog0
'START UP FLASH Red then Gn LED
rled = 1
WaitMs 1000
rled = 0
WaitMs 1000
gled = 1
WaitMs 1000
gled = 0
WaitMs 1000
'preload tmr1 0.5sec count
TMR1L = %11011100 'L + H = decimal 65536-62500=3036] = 8uSec*62500 = 0.5Sec==Count up from 3036 decimal To 65536
TMR1H = %00001011 '='Then roll over To 0000 Count And generate an Interrupt every 0.5sec
T1CON = %00110001 'prescale 8:1, internal clock, start tmr1
PIE1.TMR1IE = 1 'all start up done so Enable Timer 1 Interrupt
loop:
Adcin 0, an0 'read ADC0 Sets first pulse
Adcin 1, an1 'read ADC1 Sets second pulse
If an0 >= 100 Then 'if ADC0 counter => 100 then......
rled = 1 'ON IN SIMULATOR = OFF
firstpulse = an0
WaitMs an0 'this pulse duration is an0 millisec long
firstpulse = 0
Else
rled = 0 'OFF IN SIMULATOR = ON
Endif
If an1 >= 100 Then
gled = 1 'ON IN SIMULATOR = OFF
secondpulse = an1
WaitMs an1
secondpulse = 0
Else
gled = 0 'OFF IN SIMULATOR = ON
Endif
Goto loop
End
On Interrupt
Save System
'on this test the ISR is only a dummy call
PIR1.TMR1IF = 0 'must clear tmr1 intr
'must reload tmr1 0.5sec count
TMR1L = %11011100 'L + H = decimal 65536-62500=3036] = 8uSec*62500 = 0.5Sec==Count up from 3036 decimal To 65536
TMR1H = %00001011 '='Then roll over To 0000 Count And generate an Interrupt every 0.5sec
Resume