![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
How can I compare a value from an ADC-reading to a set value? f.ex. the ADC has a range of 8 bit (0-255) and when the vaue is above a set value, f.ex. 200, one pin goes high, and when the value goes below 200 the pin goes low. How can this be done in assembler, or what is the comands to comapre values. ie. higher than >, lower than <? thanks. | |
| |
| | #2 | |
| Quote:
| ||
| |
| | #3 |
|
Jupp, its the 16LF877A chip, but how can I use the SUB and XOR commands to check if the value is higher than/lower than? I cant figure it out :? . thanks
| |
| |
| | #4 |
|
Theory and code examples can be found on PICList.com... Here's one (of many); http://www.piclist.com/techref/microchip/compcon.htm Regards, Mike - K8LH | |
| |
| | #5 | |
| Quote:
But basically you do the subtraction and check the flags in the status register. If you subtract 5 from 5, the answer is (obviously) zero, so the zero flag will be set. If you subtract 6 from 5 the function overflows, and the carry will be affected (I can't remember which way off hand). If you subtract 5 from 6, the answer is 1, and neither flag will be affected. So by checking both C and Z, you can determine =, <>, <, >, <=, >=. The PICList explains it all. | ||
| |
| | #6 |
|
The piclist webpage is down? cant get in, loads for ever.
| |
| |
| | #7 |
|
It's coming up fine on my FireFox browswer... Let me check IE... It's coming up ok in Internet Explorer too... Not sure why you're not getting in... Sorry... Regards, Mike - K8LH | |
| |
| | #8 |
|
Works fine here with IE6 as well, the actual page is http://www.piclist.com/techref/microchip/compcon.htm but here's some examples off of it. Code: ;if RAMx <= K ;Tony Nixon movf RAMx,w addlw 255 - K ; eg if RAMx > 5 ... addlw d'250' skpnc goto Endif ;if K <= RAMx ;Tony Nixon movf RAMx,w addlw 255 - K + 1 ; eg if RAMx < 5 ... addlw d'251' skpc goto Endif ;if RAMx < K ; Tony Nixon movf RAMx,w addlw 255 - K + 1 ; eg if RAMx >= 5 ... addlw d'251' skpnc goto Endif ;if K < RAMx ; Tony Nixon movf RAMx,w addlw 255 - K ; eg if RAMx <= 5 ... addlw d'250' skpc goto Endif ;if RAMx <= RAMy ; Scott Dattalo movf RAMx,w subwf RAMy,w skpc goto Endif ;if RAMy < RAMx ; Scott Dattalo movf RAMx,w subwf RAMy,w skpnc goto Endif | |
| |
|
| Tags |
| compare, values |
| Thread Tools | |
| Display Modes | |
| |