I rarely find a challenge I can't overcome by just thinking it out a bit, but I've got to say this attempt at using the PIC has just been endless confusion and frustration. I just don't know what I'm doing wrong and I can't find anything that I'd consider a really straight forward "beginner's" guide. I've been writing web and database software for years using some pretty high extreme SQL and PHP - and I'm getting the gist of some of this ASM stuff. I've been boarding out my own discrete circuits for quite a while also but trying to blend the bread board with software has just de-railed me.
I've got some 16F688's here - I picked them because they seemed like a good match on the site where I ordered the PBP compiler and the USB programmer.
I used their example program "blink" and just hooking it to a board with nothing but +3v, ground, and a 0.1uF noise cap off a regulated power supply - it pulls almost 200 mA of juice and burned up one 3v regulator. Something is wrong.
Here is the exact code I had in MicroCode Studio:
Code:
' Example program to blink an LED connected to PORTB.0 about
' once a second
loop:
High PORTC.5 ' Turn on LED connected to PORTB.0
Pause 500 ' Delay for .5 seconds
Low PORTC.5 ' Turn off LED connected to PORTB.0
Pause 500 ' Delay for .5 seconds
Goto loop ' Go back to loop and blink LED forever
End
I changed PORTB.0 to PORTC.5 because the F688 doesn't seem to have a PORTB.
I compiled it with no errors, then in meProg, I selected the right PIC from the drop down, and set the following options:
Oscillator: INTOSCIO
WDT: Enabled
P-up Timer: Disable
MCLR Pin: Reset
Brown out: Enabled
Int Ext Switch Over: Enabled
Fail-Safe Clock: Enabled
Code: Not Protect
Data EEPROM: Not Protect
It seemed to program just fine, no errors, the light went red then green just as expected.
I tried it with and without a pull-up on MCLR and same thing - it draws tons of juice and basically does nothing. I've got a few of the PIC's so I tried to flash several of them - each the same thing.
I'm also having a real hard time understanding how to select the oscillator source - the data sheet is very cryptic to me. It sounds as if INTOSCIO is the same description as INTOSC. It also seems I need to set this frequency in the registers, but I "DEFINE OSC 4" or "DEFINE OSC 8" in PBP - I don't know if that actually changes the clock speed or if I need to still manually edit the registers, and speaking of that - the data sheet seems to say it's got something to do with INTOSCIO, HFINTOSC and teh FOSC bits in the CONFIG register, but also talks about the SCS bit in the OSCCON reg, and the IRCF bits there. I've got scratch paper all over my desk with these crypic names and register values - I realize that's just how it is, but I really wish there was something written somewhere that just put it really straight and easy:
"Set the value of this register to this by typing {THIS} in your code, then set the value of this other register to this by typing...." sort of thing.
There seems to be a lot of tribal knowledge in this just to get started.
My application seems so simple - just counting timers and flipping pins in response to them. Really really simple logic stuff - this PIC is just here to replace a bunch of 555 timers I had feeding into eachother to simplify my board layout - I thought it had to be awful simple and the snips of code I'm seeing all over the forum seem so straight forward, but I'm having a real struggle here just getting out the door.
I've made various posts here on the forum all justs trying to get the basics - I've gotten a couple of responses and I thank you all so much for that, but I hope someone can break it down a little further, or point me to other references. I'm more than willing to do the leg work - i just can't find the references.
Bookmarks