;Author : Leprechaun
;Date: September 23rd 2009
;PROGRAM FUNCTION:light control for smart home
list P=16F877a
include "P16F877a.inc"
__config 0x3D18
;***Declarations***
CBLOCK 20h
NumH
NumL
ENDC
;***
ORG 0x000
GOTO Init
ORG 0x004
Init
CLRF PORTA ; Initialize PORTA by
BSF STATUS, RP0 ; Select Bank 1
MOVLW 0x06 ; Configure all pins
MOVWF ADCON1 ; as digital inputs
MOVLW 0xCF ; Value used to initialize data direction
MOVWF TRISA ; Set RA<3:0> as inputs RA<5:4> as outputs TRISA<7:6>are always read as '0'.
MOVLW b'10000101' ;
MOVWF ADCON1 ;
BCF STATUS,RP0 ;
MOVLW b'10000001' ;
MOVWF ADCON0 ;
;Program Start:
Main
; Read_ADC
BSF ADCON0, GO_DONE ;initiate conversion
BTFSC ADCON0, GO_DONE
GOTO $-1 ;wait for ADC to finish
MOVF ADRESH,W
MOVWF NumH
BSF STATUS,RP0
MOVF ADRESL,W
MOVWF NumL ;return result in NumL and NumH
BCF STATUS,RP0
BTFSS NumH,1
GOTO led_on
BCF PORTA,4 ; turn 0ff the LED
GOTO Main
led_on
BSF PORTA,4 ;turn on the LED
GOTO Main
END