;May2008 Atomsoft
;Polling Accelerometer X and Y axis, using PORTA.7 and PORTA.6
;Timer1 holds the count equal to the time A.7 or A.6 are high
;The count is then transferred to XaxisH/L and YaxisH/L
;No LCD display on this version, so delays in the program.
list p=18F1320
include <p18F1320.inc>
CONFIG OSC = INTIO2, WDT = OFF, LVP = OFF, DEBUG = ON
XaxisH EQU 0x14
XaxisL EQU 0x15
YaxisH EQU 0x16
YaxisL EQU 0x17
org 0x00
goto Init ;go to start of main code
ORG 0x0008 ;High priority interrupt vector
retfie
ORG 0x0018 ;low priority interrupts
retfie
Init:
movlw 0x72 ; 8MHz clock select
movwf OSCCON
clrf TRISB ;PORTB all outs
[B] bsf TRISA, 6
bsf TRISA, 7[/B]
movlw 0x10 ;prescaler 1:2, 8MHz xtal, so 1uSec clock
movwf T1CON ;stop TMR1
Main:
Call Read_X
Call Read_Y
nop
;LCD subr goes here
goto Main
Read_X: ;if PORTA.7 already High, then wait for low
btfsc PORTA,7
return
WaitA7_Hi: ;wait for PORTA.7 to go high
btfss PORTA,7
goto WaitA7_Hi
bsf T1CON,TMR1ON ;start TMR1
WaitA7_Lo:
btfsc PORTA,7
goto WaitA7_Lo
bcf T1CON,TMR1ON ;stop TMR1
;
movf TMR1H,W ;read TMR1 and save count
movwf XaxisH
movf TMR1L,W
movwf XaxisL
clrf TMR1H
clrf TMR1L
return
Read_Y: ;if PORTA.6 already High, then wait for low
btfsc PORTA,6
return
WaitA6_Hi: ;wait for PORTA.6 to go high
btfss PORTA,6
goto WaitA6_Hi
bsf T1CON,TMR1ON
WaitA6_Lo:
btfsc PORTA,6
goto WaitA6_Lo
bcf T1CON,TMR1ON
;
movf TMR1H,W
movwf YaxisH
movf TMR1L,W
movwf YaxisL
clrf TMR1H
clrf TMR1L
return
End