|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
PIC bsf instruction
After spending the last 3 hours trying to figure out what's going on, I think I need to verify my conclusion because it seems strange to me.
If I set the output of more than one pin, they like to turn on and off. I've narrowed down the problem to the way I'm setting my outputs. I'm using a single port and setting individual pins using bsf and bcf. However, it seems that bsf will set ONLY that one bit; all others will be cleared. This doesn't sound right to me. I scoped the outputs and it seems like that is exactly what it's doing. The first pin I set only stays high for one instruction cycle. When the next pin turn on, the first one turns off. Then, they swap when the first pin gets set high again. I've attached my code and the scope capture. Ch1 is pin C0 and Ch2 is pin C2. |
|
#2
|
|||||
|
|||||
|
Re: PIC bsf instruction
I'm far from an expert on the PIC, but looking over the data sheet and instruction set, it seems that bsf and bcf should be working like you'd think. I don't know how MPASM handles things, but perhaps you don't have the right bank selected or something. Also, and this is a complete guess, but there might be some issue with stale data or a delayed write back or something with those happening back to back, so perhaps tossing some NOPs in front, in between, and behind all your loop instructions there and see if that fixes things.
|
|
#3
|
|||
|
|||
|
Re: PIC bsf instruction
I figured it out.
By default, pins that can be used as analog channels are set to analog. If you want to use them as digital, you have to set them using the ANSEL and ANSELH registers. This needs to be done in addition to setting them as outputs or inputs. |
|
#4
|
||||
|
||||
|
Re: PIC bsf instruction
right,
too bad I only saw your post now, I assume you have the PICKIT2, right? ^^ give me a call anytime if you have any questions. (I'm online on my MSN most of the time). |
|
#5
|
||||
|
||||
|
Re: PIC bsf instruction
One other note: bsf and bcf are read-modify-write instructions. The pins of the port are read, the pin you specify in the instruction is modified, and then all the pins are written out. If a pin is allowed to drive it to what you set (a legal high or low), its fine. If the pin was driving a load which kept it from going to a high enough voltage to be a high level, it would be written back to a low.
The Pic18 series parts have output latch registeres, so this is not a probem with them. For the 10, 12, and 16 series parts, you need to be aware of it. Brian |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Vex transmitter Instruction Manual Needed (FOUND IT!) | boyntonstu | VEX | 0 | 04-08-2007 08:00 |