Well, several way to do it.
1)You could use a Timer interrupt which will read your dipswitch all the time, so in your main code you just need to read the DipSwitch variable.
2) Create a simple subroutine which will read the dipswitch when YOU decide
Now what's the better solution to read them... i will prefer to read the whole port where my dipswitch are attach to and only keep the interesting bits . Let's say i have 4 dipswitch connected to PORTB<3:0> i'll use
DipSwitch = PORTB & $0F
the & $0F is and bitwise AND with 0F hex. this mask <7:4> bit, and keep only <3:0>.. where my dipswitch are connected.
You could still use
DipSwitch.3=PORTB.3
DipSwitch.2=PORTB.2
DipSwitch.1=PORTB.1
DipSwitch.0=PORTB.0
Both do the same job.. i prefer the first one. Which is the faster.. i didn't measure it yet. I feel the first is faster...
HTH
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Bookmarks