Dear Sir the Project is ABout Motion sensor.
The Basic idea of the project is as follows:
-Person in front of sensor: sensor will give one pulse at interrupt
pin and when person moves away the sensor will give another pulse.
-When the person is in front of sensor the pulse is the odd number
pulse and that time one LED shud blink untill the person moves away i.e up to next interrupt comes and one valve(PINA,1) should b
ON for one sec.
-When same Person moves away- the pulse is treated as even pulse and
the LED shud b On till the another interrup comes and the Valve( PINA,1) shud b On for 10 sec.
Please help.
I really request you to Help me ASAP with the followigng code since i am really frustrated… Please check n make necessary corrections.
/*
-
ISR.asm
-
Created: 08-04-2015 20:45:54
-
Author: Purva
*/
/*
-
interrupt_test.asm
-
Created: 08-04-2015 08:25:42
-
Author: Purva
*/
.def odd_even=r16
.def pulse_count=r17
.def temp=r18
.def delay1=r19
.def delay2=r20
.def delay3=r21
.def ledcycle=r22
.def stack=r23
.equ led=5
.equ delaytimeone=20 ;enter delaytime X FOR ONE SEC
.equ delaytimeten=200 ;enter delaytime X FOR TEN SEC
.cseg
.org 000
rjmp main
.org 0001
rjmp isr
main:
;---------STACK INITIALICATION----------
ldi temp,low(RAMEND)
out SPL,temp
ldi temp,$ff ;portA as input port
out DDRA,temp
ldi temp,$ff ;portB as output port
out DDRB,temp
ldi temp,$00 ;portD as input port.
out DDRD,temp
;ldi temp,(1<<TOIE0)
;out TIMSK,temp
ldi temp,(1<<ISC01|1<<ISC00);rising edge triggers int.
out MCUCR,temp
ldi temp,(1<<INT0) ;ext int0 enabled
out GIMSK,temp
;CBI PINB,led ; OFF THE LED
;cbi pina,1
sei
loop_here:
rjmp loop_here
isr:
in stack,GIMSK ; read status flag
cli
;sbi pinb,5 ; For debugging
;---------motion detection---------------
;sbis portb,6
;rjmp pulse_check
inc pulse_count ;increament the pulse couter each time the pulse comes in.
rjmp odd_even_check ;check if the count is odd ir even.
odd_even_check:
;---------check if the pulse count is odd or even.-----
mov odd_even,pulse_count ; move pulse count to odd_even register
andi odd_even,1 ; anding the contents in odd_even with immediate 1
ldi temp,1
eor odd_even,temp. ; XOR odd_even with 1.
breq odd_person_movein ; branch if odd_even is equal to 0
rjmp even_person_moveout
;--------Person in front of ssensor----------------------
odd_person_movein:
sbi pina,1 ;start the valve
;cbi pinb,led
ldi temp,delaytimeone ;load temp with delay time for one sec.
rjmp flash
longDelay:
ser delay1 ;T1 used as delay 2nd count
ser delay2 ;T2 used as delay 3d count
;ldi delay1,1
;ldi delay2,2
delay_1:
dec delay2
brne delay_1
dec delay1
brne delay_1
dec temp ;temp must be preset as
brne delay_1 ; delay master count
ret
RESET:
sbi DDRD, led ;connect LED to PORTD pin
flash:
sbi Pinb, led ;LED on
ldi temp, delaytimeone ;X sec delay
;cbi pinb,6 ;for debugging
;sbis pinb,6 ;check for incoming pulse
;rjmp pulse_check
rcall longDelay
cbi Pinb, led ;LED off
inc ledcycle ;increament ledcycle count
ldi temp,1 ;load temp wid value one
cpse ledcycle,temp ;compare ledcycle to temp and off the valve if equal
rjmp normal
cbi pina,1 ;switch off the valve aft one sec.
normal:
ldi temp, delaytimeone ;X sec delay
;cbi pinb,6 ;for debugging
;sbis pinb,6 ;check for incoming pulse
;rjmp pulse_check
rcall longDelay
rjmp flash
out GIMSK,stack ; restore old status
reti
;------ Person moved out------------
even_person_moveout:
sbi pinb,led ;glow led always
cbi pina,1
ldi temp,delaytimeten ;load delay time for ten sec
sbi pina,1 ;start the valve
longDelay1:
;ser delay1 ;T1 used as delay 2nd count
;ser delay2 ;T2 used as delay 3d count
ldi delay1,1
ldi delay2,2
delay_11:
dec delay2
brne delay_11
dec delay1
brne delay_11
dec temp ;temp must be preset as
brne delay_11 ; delay master count
cbi pina,1
;rjmp pulse_check
out GIMSK,stack ; restore old status
Reti