![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
Hello, i have coded a bit of code. It should read the portb inputs and hold the porta 2 low for 100ms if the b port was high, or high for 100ms if the portb was low. And it should continue and check every potb pin. Put for some reason it just switches on porta 2 if portb 4 is low. It doesn't continue to other ports. Any help is mostly welcome! Code: Send bcf portA, LedSend movf Bit_temp, w xorlw d'8' btfsc status, z clrf Bit_temp btfss portB, Bit_temp goto SendBit call del100 incf Bit_temp, f goto Send SendBit bsf portA, LedSend call del100 incf Bit_temp, f return | |
| |
| | #2 |
|
Just a few things here. 1) the btfss f,d (from the any pic data sheet) stores f as a seven bit adderss and b as a three bit constant. Not knowing what uC you are using you should get a warning about truncation when you compile it. 2) You are using a goto SendBit and then a return from that. Need to use a call or you are going to get stack overflow and the program will not work correctly. try that sould fix it. kingpin094 | |
| |
| | #3 |
|
I'm using a pic16f628. I fixed the call/goto issue. But I don't cuite understand your first point. Do you mean that I can't use Code: incf Bit_temp, f This is the warning i get: 74 : Argument out of range. Least significant bits used. As I understand this it shouldn't have any difference as long as the value doesn't exced 7. And it "doesn't" because it's reseting it to zero before it can read it with an 8 stored. | |
| |
| | #4 | |
| Quote:
Code: btfss portB, Bit_temp | ||
| |
| | #5 |
|
Yes Bit_temp is a variable. So it is not possible to use a loop to read all the pins? I have to read all the pinns independently. So much for my attempt to do a bit of a 'better' code Ok thanks for the help. Much appreciated! Ofcourse if it is possible to do this in a loop, i'd be glad to know how. Here's the whole code, if intrested. | |
| |
| | #6 | |
| Quote:
However, checking each pin with a BTFSS would only take 16 lines, and execute considerably faster (if that was a concern?) - plus it gives the added advantage of easily allowing seperate routines for each pin. | ||
| |
|
| Tags |
| code, pic |
| Thread Tools | |
| Display Modes | |
| |