lebohangmaphothoane
Member
HI everyone. I am to build a light control system. first of all i want to program using assembly language. the tools that iam going to use are a light sensor(0..10 LUX Description D0141i), LEDs, PIC16F877A. the system should work like this, during day light or when it is light/bright, the LEDs must be off and when it is dark or during the night, the LEDs must be on. The light sensor should help to determine when it is dark or light. PIC16F877A must take the output from the light sensor and then it should turn the LEDs on or off depending on the input that comes from the light sensors. Can any one help me with the code, written in assembly language.
hear is what i tried but i could not finish it
;PROGRAM FUNCTION:light control for smart home
list P=16F877a
include "C:\Program Files\Microchip\MPASM Suite\p16f5x.inc"
__config _CP_OFF & _WDT_OFF & _RC_OSC
;Declarations:
porta equ 05
portb equ 06
;Subroutines:
Init
movlw b'10000001';
movwf ADCON0 ;
BANKSEL ADCON1
movlw b'10000101'
movwf ADCON1
BANKSEL ADCON0
; Initializing porta
BCF STATUS, RP0 ;
BCF STATUS, RP1 ; Bank0
CLRF PORTA ; Initialize PORTA by
; clearing output
; data latches
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'.
return
;Program Start:
Start
call Init ;sets the values of ADCON0 and ADCON1
;initialize porta
Main
; Read_ADC
bsf ADCON0, GO_DONE ;initiate conversion
btfsc ADCON0, GO_DONE
goto $-1 ;wait for ADC to finish
movf ADRESH,W
andlw 0x03
movwf NumH
BANKSEL ADRESL
movf ADRESL,W
BANKSEL ADRESH
movwf NumL ;return result in NumL and NumH
return
hear is what i tried but i could not finish it
;PROGRAM FUNCTION:light control for smart home
list P=16F877a
include "C:\Program Files\Microchip\MPASM Suite\p16f5x.inc"
__config _CP_OFF & _WDT_OFF & _RC_OSC
;Declarations:
porta equ 05
portb equ 06
;Subroutines:
Init
movlw b'10000001';
movwf ADCON0 ;
BANKSEL ADCON1
movlw b'10000101'
movwf ADCON1
BANKSEL ADCON0
; Initializing porta
BCF STATUS, RP0 ;
BCF STATUS, RP1 ; Bank0
CLRF PORTA ; Initialize PORTA by
; clearing output
; data latches
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'.
return
;Program Start:
Start
call Init ;sets the values of ADCON0 and ADCON1
;initialize porta
Main
; Read_ADC
bsf ADCON0, GO_DONE ;initiate conversion
btfsc ADCON0, GO_DONE
goto $-1 ;wait for ADC to finish
movf ADRESH,W
andlw 0x03
movwf NumH
BANKSEL ADRESL
movf ADRESL,W
BANKSEL ADRESH
movwf NumL ;return result in NumL and NumH
return