Você está na página 1de 2

LIST P=16F872

include "P16F872.inc"

__CONFIG _XT_OSC & _WDT_OFF & _PWRTE_OFF & _CP_OFF & _BODEN_OFF
& _LVP_OFF

; PETAYI ELIAS T R094610K BSC and HAPANGA TINASHE R102542Q


HCT
status EQU 3

PORTA EQU 5

PORTB EQU 6

ADCON1 EQU 9f

ADCON0 EQU 1f

ADRESH EQU 1e

TRISA EQU 85

TRISB EQU 86

ORG 00h ; defining the start address of the program to start at


Address 00hex

GOTO init

; ***************main program***************************************************

init bsf status,5 ; Enter bank 1 to configure the essential registers

movlw 0xf

movwf TRISA ; configure PORTA as Input

movlw 0x00

movwf TRISB ; Configure PORTB as Output

bcf ADCON1,7 ; Left justification of the Digital value

movlw 0x0e

movwf ADCON1 ; Selecting RA0 as Analogue and the rest as Digital


Inputs in AD CON0

bcf status,5 ; Back to bank 0


bsf ADCON0,6 ; ADC Conversion Clock = FOSC/8

bcf ADCON0,5 ; Selecting the Analogue Channel RA0.

main clrf PORTB

clrf ADRESH ; clear any contents of the ADRESH

start clrf PORTB ; clear anything in PORTB

bsf ADCON0,2 ; start the conversion

poll btfsc ADCON0,2 ; check if the conversion is done

goto poll ; if not, keep on checking if the conversion is done

movf ADRESH,0 ; load the Converted Digital value into ADRESH

sublw 0xbf ; subtract converted digital value from reference


value BFhex

btfss status,0 ; check if the value has fluctuated above our


reference value

goto start ; if the value is still less than

bsf PORTB,0 ; Light the LED if the carry bit or the status register
is set

END

Você também pode gostar