Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Edge trigger help

Status
Not open for further replies.

Mosaic

Well-Known Member
Hi guys,
I have a timer clock byte running and I'd like to execute a function every time bit 4 changes state.
Not while it's a 1 or 0 but when it changes.

Can anyone share a tip as to how to proceed with this in asm?

thx
!!
 
Code:
;
;  tmrbyte  ____---____-----___   new sample
;  oldbyte  _____---____-----__   state latch
;  changes  ____-__-___-____-__   changes, hi or lo
;
        movf    tmrbyte,W       ; sample it
        xorwf   oldbyte,W       ; changes, hi or lo
        xorwf   oldbyte,F       ; update state latch (oldbyte = tmrbyte)
        movwf   changes         ; b4 = '1' = a b4 state change
This one uses one less variable (use 'skpz' or 'skpnz' plus 'goto' instruction after the 'andlw' instruction);

Code:
;
;  tmrbyte  ____---____-----___   new sample
;  oldbyte  _____---____-----__   state latch
;  changes  ____-__-___-____-__   changes, hi or lo
;
        movf    tmrbyte,W       ; sample it
        xorwf   oldbyte,W       ; changes, hi or lo
        xorwf   oldbyte,F       ; update state latch (oldbyte = tmrbyte)
        andlw   b'00010000'     ; Z=0 (change) or Z=1 (no change)
 
Last edited:
Thx a heap Mike!!!!

I am just now beginning to appreciate the bitwise capabilities of Xor. I kinda only thought of it as a useful toggle.

Byte A Xor Byte B = Changes/differences Byte (diff. bits set)

Changes BYTE xor BYTE A = BYTE B
Changes BYTE xor BYTE B = BYTE A

Some bit masking and you're set for bitwise ops. Fit it in looping code and u can get changes between iterations. I was using some complicated branching code to do the same thing, about dbl the size of your example.

Hopefully soon I'll be able to read/conceive code and 'see' the actual machine bits 'alter'. Kinda matrix-ish.
Right now, I still have to grab a pencil and work it out just to be sure.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top