| ??? 11/03/03 16:57 Read: times |
#57747 - RE: toggle function Responding to: ???'s previous message |
Hi,
I think you may find such examples anywhere. If you need to copy the state of one port to another then the simplest way is just connect them together (= By software it is done with two commands: SETB P3.7 ; set pin as input one CYCLE: MOV C,P3.7 ; image input MOV P1.1,C ; to output JMP CYCLEIf you need to toggle output on each button action then you must know something about signal debounce: SETB P3.7 ; set pin as input one CYCLE: JB P3.7,$ ; wait for button pushed MOV R0,#40 PUSHED: JB P3.7,CYCLE ; debounce DJNZ R1,$ ; negative DJNZ R0,PUSHED ; edge CPL P1.1 ; toggle output RELEASE: JNB P3.7,$ ; wait for button poped MOV R0,#40 POPED: JNB P3.7,RELEASE ; debounce DJNZ R1,$ ; positive DJNZ R0,POPED ; edge JMP CYCLEHere the DJNZ is used as debounce cycle. Please understand that it is not a good idea. Probably you should use timed intervals to not be depended on OSC frequence used. Good days! |



