bragas
Newbie level 5
hello.At firstly I'm sorry for my terrible english.I design a circuit for car body control unit(BSI).I will control windsheld wipers(with rain sensor),car ceiling lamp,headlights,central locking etc. automatically with PIC16F877A.But ı have some problems about lightening system.I can use timer0 or timer2.For example,when you open the car's door,ceiling lamp will ON continuous.then you close the door,lamp will OFF 12 seconds later. I wrote asm code for 12 seconds.It works.NO problem.but I want that:After central locking is ON ,ceiling lamp will ON during 5 seconds.then It will OFF.And headlights will ON 20 seconds.How can I design algoritm and write asm code for this scenario.
I opened the door =>> ceiling lamp:ON
I closed the door =>> ceiling lamp:in normally will OFF 12 seconds later.But After 4 seconds from I closed door,I locked car.the ceiling lamp will OFF 5 seconds later.In totally,lamp will be OFF ,after 9 seconds.Also headlights will ON during 20 seconds.then it will OFF.
my asm code for 12 seconds: (ı must add 5 seconds and 20 seconds for central locking).
I opened the door =>> ceiling lamp:ON
I closed the door =>> ceiling lamp:in normally will OFF 12 seconds later.But After 4 seconds from I closed door,I locked car.the ceiling lamp will OFF 5 seconds later.In totally,lamp will be OFF ,after 9 seconds.Also headlights will ON during 20 seconds.then it will OFF.
my asm code for 12 seconds: (ı must add 5 seconds and 20 seconds for central locking).
Code:
LIST P=16F877A
INCLUDE "P16F877A.INC"
__CONFIG H'3F31'
COUNT_60mS EQU h'20'
ORG h'000'
GOTO START
ORG h'004'
GOTO INTERRUPT
START
CLRF PORTB
BANKSEL TRISB
CLRF TRISB ;B0 is ceiling lamp,B1 is head lights
MOVLW b'11111111'
MOVWF TRISD ;D0 is door and D1 is central locking
MOVLW b'11010111' ; T0CS=0, PSA=0, PRSC=1/256
MOVWF OPTION_REG ;
BANKSEL PORTB ; BANK0
BSF INTCON,7
;CEILING LAMP CONTROL
START1
BTFSS PORTD,0
CALL TIMER
BTFSS PORTD,0
GOTO START1
BCF INTCON,5
BSF PORTB,0
BCF INTCON,5
GOTO START1
TIMER
BSF INTCON,5
RETURN
; after 12 seconds , ceiling lamp will turn off
INTERRUPT
BCF INTCON,2
MOVLW D'10'
MOVWF TMR0
INCF COUNT_60mS,F
MOVLW D'200' ; 60mS*200=12000mS=12 seconds
SUBWF COUNT_60mS,W
BTFSS STATUS,Z
GOTO INT_J1
CLRF COUNT_60mS
CLRF PORTB
INT_J1
RETFIE
END