| ??? 07/21/06 21:12 Read: times |
#120817 - Problem with switches. |
The code is supposed to monitor port1 for changes and if the same happens, corresponding port0 pin is to be complemented. eg. Consider switches connected to port1 and leds to port0, initially all LEDs are switched on(inversion logic) p1.0 is pressed, p0.0 is switched off and if p1.0 is pressed again, p0.0 is switched on.
But i'm having problems with it, if button is pressed the LED flickers until it's released and the button has to be pressed for more than 5secons to change it's state. sometimes it doesn't even change the state.
FLAG equ 20h ;temporary storage of p1 values(switch array values)
org 0000h
ljmp sa_main
org 0030h
;------------------------------20ms delay----------------------------------
delay_20ms: push 00
push 01
mov r0,#36
delay_20ms_loop1: mov r1,#255
delay_20ms_loop2: djnz r1,delay_20ms_loop2
djnz r0,delay_20ms_loop1
pop 01
pop 00
ret
;------------------------------main code------------------------------------
sa_main: mov p0,#00h ;output port/devices
mov p1,#0ffh ;input port/switches
mov FLAG,#0ffh ;device status reset
mov sp,#64h
mov IE,#00h
sa_main1: mov p1,#0ffh
mov a,p1
cjne a,#0ffh,sa_main1 ;check if all keys are released initially
sa_loop: acall delay_20ms
mov a,p1
cjne a,#0ffh,debounce ;if key pressed, check debounce
sjmp sa_loop
debounce: acall delay_20ms
mov a,p1
cjne a,#0ffh,sa_check ;if key pressed, check switches
sjmp sa_loop
sa_check: jnb acc.0, flg0 ;check if p1.0 is grounded
jnb acc.1, flg1 ;check if p1.1 is grounded
jnb acc.2, flg2 ;check if p1.2 is grounded
jnb acc.3, flg3 ;check if p1.3 is grounded
jnb acc.4, flg4 ;check if p1.4 is grounded
jnb acc.5, flg5 ;check if p1.5 is grounded
jnb acc.6, flg6 ;check if p1.6 is grounded
jnb acc.7, flg7 ;check if p1.7 is grounded
flg0: cpl FLAG.0 ;if p1.0 is pulled low,compliment FLAG.0
sjmp sa_on
flg1: cpl FLAG.1 ;if p1.1 is pulled low,compliment FLAG.1
sjmp sa_on
flg2: cpl FLAG.2 ;if p1.2 is pulled low,compliment FLAG.2
sjmp sa_on
flg3: cpl FLAG.3 ;if p1.3 is pulled low,compliment FLAG.3
sjmp sa_on
flg4: cpl FLAG.4 ;if p1.4 is pulled low,compliment FLAG.4
sjmp sa_on
flg5: cpl FLAG.5 ;if p1.5 is pulled low,compliment FLAG.5
sjmp sa_on
flg6: cpl FLAG.6 ;if p1.6 is pulled low,compliment FLAG.6
sjmp sa_on
flg7: cpl FLAG.7
sa_on: mov p0,FLAG ;FLAG holds temporary status of p1, move the temporaryly stored status to p0
sjmp sa_loop
end
|
| Topic | Author | Date |
| Problem with switches. | 01/01/70 00:00 | |
| well, what is FLAG | 01/01/70 00:00 | |
| simple logic | 01/01/70 00:00 | |
| what is the difference | 01/01/70 00:00 | |
| It is application specific | 01/01/70 00:00 | |
| Good at checking if key IS pressed/ | 01/01/70 00:00 | |
| Schmidt triggers | 01/01/70 00:00 | |
you are very kind | 01/01/70 00:00 | |
| change detect needed | 01/01/70 00:00 |



