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.

2 PIC questions

Status
Not open for further replies.
Hi All

Just a few minor PIC problems.

1. I have this code:

test1
btfss PORTA,0
goto test2
goto next1

test2
btfss PORTA,1
goto test3
goto next2

test3
btfss PORTA,2
goto test4
goto next3

test4
btfss PORTA,3
goto test1
goto next4

It's used as a scanningcode for 4 micro-switches. How can I store the values in variables so I can use them later on?

2. Can it be done in another way, so the scanning proces is faster?

__________________________________
Who can live without electronics - not me!
 
Your version works but you can try this shorter version:

Code:
test    btfsc PORTA,0   ; skip if portA,0 low
        goto next1        ; is high, go to handling routine
        btfsc PORTA,1
        goto next2
        btfsc PORTA,2
        goto next3
        btfsc PORTA,3
        goto next4
        goto test          ;loop until switch closure

Electronics4you said:
It's used as a scanningcode for 4 micro-switches. How can I store the values in variables so I can use them later on?

You set a flag in each of the above next# entry.

Electronics4you said:
2. Can it be done in another way, so the scanning proces is faster?

Four tests, total 8 instructions. Difficult to make it faster. On a PIC with a 20MHz crystal, the loop would take just 2uS to go around once. A switch closure is more like several mS and that's several thousand times slower than you can check them.

Why would you want the checking to be faster?
 
No debouncing

If we are talking switches, some debouncing should be considered, I think.

**broken link removed**
 
Just write the main program so it only runs the switch checking code 5 times per second or so, that works very good for debouncing...
 
How can I get the bit-tests stored, so i can generate a function, when a combinations of 4 bits occur?

___________________________________
Life's good - isn't it?
 
in each routine of next#, u set the appropriate bit of a register, call it STATUS_SWITCH
i.e: next# bsf STATUS_SWITCH, #
...

at the end of your scanning, you subtract the value in STATUS_SWITCH by your desired set of combinations.
chill :)
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top