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:
This compiles without any problems and produces the following assembly code:
- 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!
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:
Everything seems to work fine when I try to program the 16F88:;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
So I'm wondering: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
- 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: