PDA

View Full Version : Can't get a 16F88 to do anything.



ccowley
- 23rd August 2008, 06:29
Is there anyone out there willing to give me a code sample that will flash an LED using a 16F88 (code from start to finish including all fuse settings etc.).

I have worked with lots of PIC's, though mostly the 12F series lately. I started out programming microcontrollers in HEX, then graduated to assembly, and have been using PICBasic PRO for years (currently using v 2.47). I am very familair with them and usually don't have any problems, but this 16F88 is kicking my tail! I have the CMCON, ANSEL, TRIS settings, & OSCCON to what I'm pretty sure are the correct settings (though I have tried a few different settings), but still nothing.

I have looked over all the similar links and have tried everthing in them and I still can't get a blinking LED from this chip. I always start with a new chip by getting an LED blinking, but I just can't seem to get it. I have spent hours on this! It's got to be some little thing I am missing, but I haven't been able to see it. At this point I am just throwing any piece of code in there.

So, all I need is some known good code. I don't care which port you put it on or anything, just give me a blinking LED that usies the internal RC oscillator at 8MHz, no comparators turned on, no analog, just digital I/O all all the ports.

I have tried different chips (3) and different breadboards and different power supply's.

I am using Microcode Studio Plus as my editor, I then import the file the MPLab like I do with all my other chips. I have set the chip selection to correct one in both Mircode Studio Plus and MPLab. I have tried setting the fuses through the code (which is what I usually do) and manually, neither way has worked for me. My code doesn't spit out any errors (not that it means too much).

I am stuck! Any help would be greatly appreciated.

Carl

mackrackit
- 23rd August 2008, 07:02
Welcome,
Generally we like to have the problem code posted, then we can help you find the problem.
http://www.picbasic.co.uk/forum/showthread.php?t=1742

Post #20 in this thread has blinky code
http://www.picbasic.co.uk/forum/showthread.php?t=9167&highlight=16F88

Archangel
- 23rd August 2008, 08:38
Hi ccowley,
Welcome to The Forum, let's pretend, just for hoots, that you are a complete newbie, and we are the starving code hungry dogs,<b> I did say we are pretending didn't I ?</b> Throw us some bones of your startup code, maybe a little meat on those bones (a loop or 2 ), a little copy paste of what you have tried . . . and we'll see if you did something wrong, just so you don't have to edit the hex later ;)

ccowley
- 24th August 2008, 00:50
Hi again,

Thanks to both of you for your input! I really appreciate the response, but things still aren't working. I did read through the entire thread that was linked to (among others) and tried everything that was suggested. The code snippit below is the from that thread and is the one I have been working with today. I have spent another 4 hours playing with this thing and it just isn't going.

I have repeated the results with two different bread boards and two different power supplys and I have rotated through 4 diffent chips and get the same results. I have checked my power and ground connection also. I can't remember ever have this kind of trouble with a microcontroller (well, okay, there were a few hairy times back in wirewrap days in college with a certain 6502 chip).

So, here is the code that I am using:

OSCCON = %01101110 'set int osc to 4mhz
'OSCON = %01100000
ANSEL = 0 'ALL DIGITAL
CMCON = 7 'COMPARATORS OFF

TRISA = %00000000 'ALL OUTPUTS
TRISB = %00000000 'ALL OUTPUTS
PORTA = 0 'PORTA LOW

@ DEVICE MCLR_OFF, INTRC_OSC, WDT_ON, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_OFF
Pause 100 'SETTLE DOWN

START:
High PORTA.6 'ON LED
High PORTA.7
Pause 1000
Low PORTA.6 'OFF LED
Low PORTA.7
Pause 1000
GoTo START 'REPEAT FOREVER

end

I have also tried it with the edited INC file and unedited INC file as mentioned in the other thread, but it doesn't change anything.

One odd note is that RB5 is always a constant 5V on every chip that I have tried so far (up to 4 now). I checked it with a scope to see if it was a clock signal or something, but it is a solid 5v.

Thanks in advance!

Carl

mikendee
- 24th August 2008, 03:15
Hi Carl,
I usually use
OSCCON = %01101000 and it seems to work. Don't forget the Define OSC for speeds other than 4MHz.
Hope this helps.
Mike

ccowley
- 24th August 2008, 03:28
Hi Mike,

Thanks for taking a look at it. I tried the OSCCON value that you suggested and it still didn't work. I am beginning to wonder if it must be a compiler error, but I'm sure I'm not the only one using these that is still on PBP 2.47. I ordered upgrade to PBP 2.50 today just in case, but I'm not conviced that's the answer.

Thanks again,

Carl

mackrackit
- 24th August 2008, 04:47
If you are using MPLAB then try this config


@__config _CONFIG1, _INTRC_IO & _WDT_ON & _LVP_OFF & _CP_OFF &_MCLR_OFF

ccowley
- 24th August 2008, 07:49
Hi Dave,

I only use MPLab for programming the chip it isn't used for anything else. The current fuses show up perfectly in MPLab when I import my code into it. If I change them, they change in MPLab with next import. I have also turned off the 'set from code' on import and set them manually, but still no luck.

I suppose I could change MicroCode Studio's setup so that it used MPLabs assembler (I have used it that way before) instead of PBP's and then I could use the fuse settings that you listed. It might be worth a shot. I will check it on Monday.

Either I am missing something really simple or this thing just isn't compiling/programming correctly as far as I can tell. My PICStartPlus programmer has the most current software upgrade too. Monday I'm going to try it all with a different computer and my other PICStartPlus programmer. I also order one of MicroEngineering Labs new programmers along with the PBP upgrade, so I'll see if that makes any difference. My current version of PBP is supposed to work with the F88 though, so I am at a loss.

My current setup is working fine with the other PIC's I am programming and using in other projects, but I need some of the extras in the F88 for another project and I am just not getting anywhere with this bad boy.

Thanks for the suggestions,

Carl

Archangel
- 24th August 2008, 08:26
try this using MPASM assembler:


OSCCON = %01101110 'set int osc to 4mhz
OSCTUNE = 0 ' SET TO CENTER FREQ

ANSEL = 0 'ALL DIGITAL
ADCON0 = 0
ADCON1 = 0
CMCON = 7 'COMPARATORS OFF
DEFINE OSC 4

TRISA = %00000000 'ALL OUTPUTS
TRISB = %00000000 'ALL OUTPUTS
PORTA = 0 'PORTA LOW
@ __config _CONFIG1, _INTRC_IO & _WDT_ON & _LVP_OFF & _CP_OFF &_MCLR_OFF
;@ DEVICE MCLR_OFF, INTRC_OSC, WDT_OFF, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_OFF
Pause 100 'SETTLE DOWN

START:
High PORTA.6 'ON LED
High PORTA.7
Pause 1000
Low PORTA.6 'OFF LED
Low PORTA.7
Pause 1000
GoTo START 'REPEAT FOREVER

end

or this for PM assembler


OSCCON = %01101110 'set int osc to 4mhz
OSCTUNE = 0 ' SET TO CENTER FREQ

ANSEL = 0 'ALL DIGITAL
ADCON0 = 0
ADCON1 = 0
CMCON = 7 'COMPARATORS OFF
DEFINE OSC 4

TRISA = %00000000 'ALL OUTPUTS
TRISB = %00000000 'ALL OUTPUTS
PORTA = 0 'PORTA LOW
;@ __config _CONFIG1, _INTRC_IO & _WDT_ON & _LVP_OFF & _CP_OFF &_MCLR_OFF
@ DEVICE MCLR_OFF, INTRC_OSC, WDT_OFF, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_OFF
Pause 100 'SETTLE DOWN

START:
High PORTA.6 'ON LED
High PORTA.7
Pause 1000
Low PORTA.6 'OFF LED
Low PORTA.7
Pause 1000
GoTo START 'REPEAT FOREVER

end

A genuine 2 bit blinky

nomad
- 24th August 2008, 11:38
i had 3 16f88's that no matter what i did, they would not run with internal osc. pop a crystal and 2 caps and not another problem since.

ccowley
- 25th August 2008, 18:29
The code for MPASM compiled and assembled fine, but it still didn't work. Is this working for you with one of your chips or are you just thinking this should work? Just trying to determine if this is a code issue or chip or compiler version issue.

I'll have the new compiler software and programmer on Wednesday, so I'll give it all a try again then.

Thanks again for looking at this!

Carl

ccowley
- 25th August 2008, 18:43
i had 3 16f88's that no matter what i did, they would not run with internal osc. pop a crystal and 2 caps and not another problem since.

I hope this isn't a bad batch of 16F88's. I bought 50 of these, but it was back when they first came out, so maybe. If they don't work with the new compiler etc. then I will try them with a crystal, but that won't do me much good as the board they are going into has already been produced without a section for a crystal. You might be asking, "What kind of idiot gets a board produced without having fully tested the code in a microcontroller?". Well, the board is actually designed to use either a 12F683 (which it has been using for a couple years without any problems) or a 16F88. The 16F88 brings in some advanced circuitry and options to the circuit that we haven't used up until this time, but we would like to start including those options. So, I am stuck with needing to use the internal oscillator since that is what the board is designed to use.

Are you aware of a bad lot/date code of 16F88's?

Thanks for your input!

Carl

Bruce
- 25th August 2008, 19:05
Try this;


@ DEVICE MCLR_OFF, INTRC_OSC, WDT_ON, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_OFF

OSCCON = %01100000 'set int osc to 4mhz
ANSEL = 0 'ALL DIGITAL
CMCON = 7 'COMPARATORS OFF

TRISA = %00000000 'ALL OUTPUTS
TRISB = %00000000 'ALL OUTPUTS
PORTA = 0 'PORTA LOW

Pause 100 'SETTLE DOWN

START:
High PORTA.6 'ON LED
High PORTA.7
Pause 1000
Low PORTA.6 'OFF LED
Low PORTA.7
Pause 1000
GoTo START 'REPEAT FOREVER

end
Compile & program with your setup. If it doesn't work, try the attached .hex file. It's the
same thing as above. Make sure the config settings are the same as shown in the code
before programming the part.

The .hex file attached was compiled with 2.47, and verified working on an F88.

ccowley
- 25th August 2008, 22:37
Thanks everyone for your help with this!!!

Thanks for the HEX file Bruce! It worked great! Which led me back to my compiler as the possible cultprit for my woes. I felt like an idiot as I found MicroCode Studio was pointing to a PBP directory on an old back up drive with V2.45 on it, but even after switching it so that it pointed to my newer drive with V2.47 on it the compile still didn't work. So, I took it to another machine and compiled it there and once again, your code worked perfectly!

Comparing the two systems made me look a bit closer at my screen. I noticed that MicroCode Studio had an additional tool bar (which was the lowest of all the tool bars) and two sets of compile buttons. I had updated MicroCode Studio to make sure I had the latest version before starting this and didn't notice it had turned on the ICD menu bar with its ICD compile button which look very much like the standard compile buttons. So, being a creature of habit, I have been just pointing to the lowest compile button on my screen not realizing it was the ICD compile button. The regular compile button works great, the ICD button, not so great, at least how I'm using it. On my other computer (when I turn the ICD menu bar on) it actually says "ICD Compile" next to the button (since I keep that screen at a higher resolution), but on the computer I normally use it just shows the button. I knew it had to be something idiotic I was doing since I haven't had this kind of problem programming PICs before, but I just couldn't see it and wouldn't have seen it without the troubleshooting help that was provided here.

Finally I can (sheepishly) get back to getting some work done.

Thanks again to everyone who chimed in on this thread!

Carl

mackrackit
- 25th August 2008, 23:42
F9 for compile.
No button look alikes :D
Glad you got it going.