Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

my first 16F88 has me stumped

Status
Not open for further replies.

Hank Fletcher

New Member
I'm trying to figure what's wrong with my first attempt to program a PIC. It's probably something simple, but with this being my first time I think I'm getting overwhelmed by the factors!

Anyway, I'm trying to program a 16F88 to flash two LEDs at intervals of 1s. The program is derived from a demo program included with Great Cow BASIC. Here's the program in GCB:

#chip 16F88, 8
#config OSC = INTRC_IO

'Set the pin directions
dir PORTB.0 out
dir PORTB.1 out

'Main routine
Start:

'Turn one LED on, the other off
SET PORTB.0 ON
SET PORTB.1 OFF
wait 1 sec

'Now toggle the LEDs
SET PORTB.0 OFF
SET PORTB.1 ON
wait 1 sec

'Jump back to the start of the program
goto Start

This compiles without any problems and produces the following assembly code:
;Program compiled by Great Cow BASIC (0.9 10/2/2007)
;Need help? See the GCBASIC forums at https://sourceforge.net/forum/?group_id=169286,
;check the documentation or email hconsidine@bigpond.com.

;********************************************************************************

;Set up the assembler options (Chip type, clock source, other bits and pieces)
LIST p=16F88, r=DEC
#include <P16F88.inc>
__CONFIG _CONFIG1, _INTRC_IO & _WDT_OFF & _LVP_OFF & _MCLR_OFF

;********************************************************************************

;Set aside memory locations for variables
DELAYTEMP equ 32
DELAYTEMP2 equ 33
DELAYTEMP4 equ 34
SysTemp1 equ 35
SysTemp2 equ 36
SysWaitTempMS equ 37
SysWaitTempS equ 38

;********************************************************************************

;Jump to initialisation code when PIC is reset
ORG 0
call INITSYS
goto SystemInitialise

;********************************************************************************

;Interrupt vector
ORG 4
retfie

;********************************************************************************

;Various initialisation routines, automatically called by GCBASIC
SystemInitialise

;********************************************************************************

;Start of the main program
banksel TRISB
bcf TRISB,0
bcf TRISB,1
START
banksel PORTB
bsf PORTB,0
bcf PORTB,1
movlw 1
movwf SysWaitTempS
call Delay_S
bcf PORTB,0
bsf PORTB,1
movlw 1
movwf SysWaitTempS
call Delay_S
goto START
BASPROGRAMEND
sleep
goto $

;********************************************************************************
;Subroutines included in program
;********************************************************************************

DELAY_MS
DMS_START
movlw 10
movwf DELAYTEMP2
DMS_OUTER
movlw 66
movwf DELAYTEMP
DMS_INNER
decfsz DELAYTEMP, F
goto DMS_INNER
decfsz DELAYTEMP2, F
goto DMS_OUTER
decfsz SysWaitTempMS, F
goto DMS_START
return

;********************************************************************************

Delay_S
DS_START
movlw 10
movwf DELAYTEMP4
DS_OUTER
movlw 100
movwf SysWaitTempMS
call Delay_MS
decfsz DELAYTEMP4, F
goto DS_OUTER
decfsz SysWaitTempS, F
goto DS_START
return

;********************************************************************************

INITSYS
movlw 112
movwf SysTemp1
banksel OSCCON
movf OSCCON,W
banksel SysTemp1
iorwf SysTemp1,W
banksel OSCCON
movwf OSCCON
banksel PORTA
clrf PORTA
clrf PORTB
movlw 7
banksel CMCON
movwf CMCON
banksel ADCON0
bcf ADCON0,ADON
banksel ADCON1
bcf ADCON1,ADFM
clrf ANSEL
banksel STATUS
return

;********************************************************************************

END
Everything seems to work fine when I try to program the 16F88:
Auto-connect not enabled - Not connecting (Try enabling auto-connect on the ICD2 settings pages.)
Connecting to MPLAB ICD 2
...Connected
Setting Vdd source to MPLAB ICD 2
Target Device PIC16F88 found, revision = Rev 0x8
...Reading ICD Product ID
Running ICD Self Test
...Passed
MPLAB ICD 2 Ready
Setting Vdd source to target
Programming Target...
...Validating configuration fields
Verifying...
...Verify Succeeded
Programming Configuration Bits
.. Config Memory
Verifying configuration memory...
...Verify Succeeded
...Programming succeeded
02-Aug-2007, 23:38:24

MPLAB ICD 2 Ready
So I'm wondering:
- I have to hit "release from reset" then I can remove the PIC from the programmer, right?
- I'm not programming the PIC in circuit, just in the ZIF, so should the ICD2 be set to power the target (I'm wondering because the ICD2 I'm using is just getting its power from the USB)?
- Is there perhaps a problem with the circuit I'm using the 16F88 in?

Sorry, but I haven't gotten around to schematic software yet. But it's a simple circuit:
- two LEDs to ground and pins 6 and 7 (RB0 and RB1) of the PIC, 470Ohm resistors between each LED and its PIC pin. Testing reveals the LEDs work fine between ground and the PIC pins (no problems there)
- ground to pin 5 (Vss) of the PIC, 5V to pin 14 (Vdd).

Thanks! Again, I'm sure it's something simple but I can't get my head around it!
 
Last edited:
My laptop is lousy at powering any sort of circuit thru a programmer. Will work on Pic demo boards tho, where the USB provides V+ and the Vpp is seperated off from that.
 
I might not have made that clear. I'm just programming the PIC (out of circuit), and I was wondering what the settings for that ought to be. Confusing the issue is that my ICD2 doesn't have an input for power other than the USB. So the part that's puzzling me is that there's no circuit that needs to be powered, just the PIC in the ZIF, so does that need 5V from the ICD2 or should the ICD2 be set for the PIC to be self-powered?

As curious and relevant that might be, I'm not 100% that it's my only problem.
 
If you are programming your pic with your ICD2 and then transferring it to your circuit then it should work fine.

I'm assuming you either,
Compile your basic code in MPLAB,
or, you assembly the asm file in MPLAB,
or, you import the HEX file into MPLAB.

If you view the disassembly listing (in MPLAB) before programming it should be similar to the asm file.

Mike.
 
You should also check that under menu "Configure->configuration bits" that the box at the top is checked - configuration bits set in code.

Mike.
 
Don't think its a MPLAB thing. Great Cow Basic compiles the basic into a downloadable hex file for the programmer. If the program compiles, an assembly file is also produced for debugging. The chip looks to be programmed and ready to go, but personaly have not used the ICD2.

Maybe the "in circuit" 16f88 wiring needs to be checked over for continuity & voltage. Is the 16f88 in a breadboard? Tried a different location? How is it powered? Is the power decoupled?
 
Nickleflippr, the ICD2 only works with MPLAB. If you don't either compile, assemble or import then the code just isn't there and it will program a blank chip.

Mike.
 
Pommie, sorry if my wires are crossed there, like I said , have not used the
ICD2. When using a Microchip PicKit 2 programmer, it happily imports and downloads the compiled hex file from GCBasic, without the assistance of MPLAB.
 
Hank,

You are not programming your code into the PIC. The following is from an PIC16F88 with the ICD2 as a programmer. I added the bold to the interesting lines.
MPLAB ICD 2 Ready
Programming Target...
...Validating configuration fields
...Erasing Part
...Programming EEPROM Memory
...Programming Program Memory (0x0 - 0xCB7)
Verifying...
...Program Memory
...EEPROM
...Verify Succeeded
Programming Configuration Bits
.. Config Memory
Verifying configuration memory...
...Verify Succeeded
...Programming succeeded
03-Aug-2007, 02:26:59

MPLAB ICD 2 Ready
With the ICD2 set to debugger you should see.
MPLAB ICD 2 Ready
Programming Target...
...Validating configuration fields
...Erasing Part
...Programming EEPROM Memory
...Programming Program Memory (0x0 - 0xCB7)
...Loading DebugExecutive
...Programming DebugExecutive
...Programming Debug Vector
Verifying...
...Program Memory
...EEPROM
...Debug Executive
...Debug Vector
...Verify Succeeded
Programming Configuration Bits
.. Config Memory
Verifying configuration memory...
...Verify Succeeded
Connecting to debug executive
...Programming succeeded
03-Aug-2007, 02:29:42

MPLAB ICD 2 Ready
Running Target
Your output follows.

MPLAB ICD 2 Ready
Setting Vdd source to target
Programming Target...
...Validating configuration fields
Verifying...
...Verify Succeeded
Programming Configuration Bits
.. Config Memory
Verifying configuration memory...
...Verify Succeeded
...Programming succeeded
02-Aug-2007, 23:38:24
MPLAB ICD 2 Ready

All you have done is program the configuration bits.

My guess is that you are compiling the Great Cow code with the Great Cow IDE then attempting to program it with MPLAB. If so inside MPLAB you have to import the hex file first. FILE>IMPORT. You need to import the HEX file each time you start the ICD2 IDE.

Also I do not see where the ICD2 in erasing the part. Maybe because you did not have anything to program it figures it does not need to. After you have inported you hex I would expect to see that too.

Does Great Cow have instructions on using their compiler with MPLAB so that you can compile program and debug from within the MPLAB IDE? That would be the way to go.



HTH
 
Thanks for the help so far, guys. I hadn't realized I would need to import the .hex file. I've tried that, but now I get this:
ICDWarn0033: MPLAB ICD 2 does not support programming this device if both the internal oscillator and internal MCLR are selected. You may continue programming, but you are encouraged to cancel, reconfigure your device, and try again.
I gather that's just an unforeseen complication on my part, in terms of that I can't use the internal oscillator and internal MCLR at the same time on a 16F88? If I set MCLR to on, I think I need a pull-up resistor on the MCLR pin - what value should the resistor be?

FYI the power for my circuit is 5V regulated (and plenty amps). Yes, it's in a breadboard.
 
I just tried that out, setting MCLR on, and it programmed just fine (although for some reason I had to quit out of MPLAB and reload to get it to work?). I put the MCLR pin through a 10K resistor to the 5V in my circuit, and the LEDs are blinking perfectly! I guess the only downside to this is that I'm now one I/O pin shorter than I thought I'd be. There's an argument there for people claiming you can gain two output pins by using an internal oscillator, if by using the int osc you have to give up the internal MCLR (on the 16F88, anyway).

Like I said, the circuit's working fine, but I'm curious - what's the best way to deal with stray capacitance with a PIC on a breadboard circuit (besides keeping wires or leads as short as possible)?
 
Last edited:
If you are that close on pin count use a 28 pin PIC.
I'll keep playing with the 16F88 for now and try to apply it to my project (the recorder robot) - I think it will be good enough for the first attempt (for which I'm seriously considering limiting the number of "fingers," and accordingly the need for as much I/O pins).

But I really think I ought to keep a lookout for a larger pin-count PIC. I know I've seen some popular 28 and 40 pin PICs recommended on this forum, but I can't remember what or where. What can you suggest?
 
Since you probably need drivers for outputs anyway (relays, etc.), you might consider using one or more cascadable 8 bit serial-to-parallel sinking driver ICs with a 3 pin interface (Micrel MIC5821/MIC5841 or Allegro A6821/A6841). The MIC5841 and A6841 devices even have built in suppression diodes on the outputs for when you're driving relays.
 
justDIY said:
the 16F767 (28 pin) is a fun chip for playing with leds and rgb color mixing. It has three hardware PWM modules, so you can do 30 bit color mixing in hardware, without wasting any cpu cycles or much code space.

I didn't know that. Wow, I see it in the Data Sheet. I think I need to add one of those series to my next sample order.

Thank you Sir!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top