PDA

View Full Version : 18F2550 Blinking LED With Pickit 2



kiewic
- 22nd April 2010, 19:42
Hi.

I'm trying to make a PIC 18F2550 blinks using pickit 2 and the internal oscillator. But it doesn't do it. Here is what I have tried.

1. I have the following code.



OSCCON = $70 'Int CLK 8MHz
OSCTUNE.6 = 1 'PLL 4x
ADCON1= %00001111 '$0F = disable A/D converter

TRISA = %00000000 'All pins are outputs
TRISB = %00000000
TRISC = %00000000

DEFINE OSC 32 '4x 8MHz

flip:
PORTC.0 = 1 'Turn on LED
PAUSE 500 'Delay for .5 seconds
PORTC.0 = 0 'Turn off LED
PAUSE 500
GOTO flip

END


2. This is my configuration on 18F2550.INC file.



LIST
LIST p = 18F2550, r = dec, w = -311, w = -230, f = inhx32
INCLUDE "P18F2550.INC" ; MPASM Header
__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
__CONFIG _CONFIG3H, _PBADEN_OFF_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L & 0DFh

__CONFIG _CONFIG1H, _FOSC_INTOSCIO_EC_1H
__CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_512_2H

NOLIST


3. I supposed the circuit is correct, because it runs with the following assambler code using MPLAB.



;_INTRC_OSC_NOCLKOUT

#include <p18F2550.inc>

cblock 0x20
Delay1 ; Define two file registers for the
Delay2 ; delay loop
endc

org 0
Start:
; bsf STATUS,RP0 ; select Register Page 1
bcf TRISC,0 ; make IO Pin B.0 an output
; bcf STATUS,RP0 ; back to Register Page 0
MainLoop:
bsf PORTC,0 ; turn on LED C0
OndelayLoop:
decfsz Delay1,f ; Waste time.
goto OndelayLoop ; The Inner loop takes 3 instructions per loop * 256 loopss = 768 instructions
decfsz Delay2,f ; The outer loop takes and additional 3 instructions per lap * 256 loops
goto OndelayLoop ; (768+3) * 256 = 197376 instructions / 1M instructions per second = 0.197 sec.
; call it a two-tenths of a second.

bcf PORTC,0 ; Turn off LED C0
OffDelayLoop:
decfsz Delay1,f ; same delay as above
goto OffDelayLoop
decfsz Delay2,f
goto OffDelayLoop
goto MainLoop ; Do it again...
end


Can you help me? Thanks.

mackrackit
- 23rd April 2010, 00:17
The configs


__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_INTOSCIO_EC_1H
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L & 0DFh


Top of code


OSCCON = %01110000
DEFINE OSC 8

just little changes...

kiewic
- 23rd April 2010, 03:53
Thanks mackrackit, but unfortunately it doesn't work. I made the changes you recommended, but the PIC continues not working :(

mackrackit
- 23rd April 2010, 04:03
How is the MCLR pin connected?

If it is not connected to anything then change the 3H line to


__CONFIG _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_OFF_3H

mackrackit
- 23rd April 2010, 04:30
I just tested this on a 4550 (I do not have a 2550) and it works as expected.


DEFINE OSC 8
@ __CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
@ __CONFIG _CONFIG1H, _FOSC_INTOSCIO_EC_1H
@ __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
@ __CONFIG _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_OFF_3H
@ __CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L & 0DFh
OSCCON = %01110000

TRISD = %00000000
TRISC = %00000000
flip:
HIGH PORTD.7
PORTD.6 = 1 'Turn on LED
PORTC.0 = 1
PAUSE 500 'Delay for .5 seconds
PORTD.6 = 0 'Turn off LED
PORTC.0 = 0
PAUSE 500
GOTO flip

kiewic
- 23rd April 2010, 04:40
The MCLR pin is connected directly to the first pin of the Pickit 2.

I tried changing that configuration, but nothing happened.

mackrackit
- 23rd April 2010, 05:43
Might be a stupid question but are you compiling for the correct chip?
Are you using MCS?

kiewic
- 23rd April 2010, 05:53
Yes, 18F2550 is selected on the combo box.

I'm using MicroCode Studio 3.0.0.5 and PICBASIC PRO 2.50B. When I compile, it uses the MPLAB assembler and it opens and closes a console window.