Download here - Adam Morse

Transcript
Sensor.asm
;
; Sensors.asm - definitions functions used to configure and/or read the sensors
;
LIST
P=PIC18F46K22
; list directive to define processor
#INCLUDE <P18F46K22.INC>
; processor specific variable definitions
#INCLUDE "AutonomousTrailer.inc" ; Definitions for our project
;
; Define entry points that will be accessible from outside this file
;
global SensorInit, SensorRead
;
; Start of the code section
;
Code
;
; Function:
;
; Purpose:
;
; Parameters:
;
; Returns:
;
; Notes:
;
SensorInit:
SensorInit
To initialize the sensor configuration
None
Nothing of any value
None
;
; Configure portA for input and set first bit for analog input
;
clrf
PORTA,A
clrf
ANSELA,A
bsf
ANSELA,ANSA2
bsf
TRISA,RA2
;
; Configure ADCON2:
;
;
b7='1'
- Right justified output
;
b6='0'
- unimplemented
;
b5-3='100' - 8 TAD
;
b2-0='020' - Conversion clock= FOSC/32
;
movlw B'10100010'
movwf ADCON2,A
;
; Configure ADCON1:
;
;
b7='0'
- use CCP5 trigger
;
b6-4='000' - unimplemented
;
b3-2='00'
- use internal AVdd for A/D Vref+
;
b1-0='00'
- use internal Avss for A/D Vref;
movlw B'00000000'
movwf ADCON1,A ;Configure ADCON1, Internal ref
;
; Configure ADCON0:
;
;
b7='0'
- unimplemented
;
b6-2='00010' - use AN2 for analog input
;
b1='0'
- No conversion in progress yet
;
b0='1'
- ADC is enabled
;
movlw B'00001001'