# 18F4620 Question

Status
Not open for further replies.

#### cwickham

##### New Member
hey everyone, i just got my pickit2.

Im just trying to get an led flashing to test it out, but i cant seem to make it work.

Code:
#if defined(__PCH__)
#include <18F4620.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,PBADEN = OFF,LVP = OFF, NOBROWNOUT
#use delay(clock=8000000)
#endif

#define ALL_OUT 0x00

void main(void)
{
setup_oscillator( OSC_8MHZ );
delay_ms(1500);
SET_TRIS_A(ALL_OUT);

while(1)
{
OUTPUT_HIGH(PIN_A0);
delay_ms(1000);
OUTPUT_LOW(PIN_A0);
delay_ms(1000);
}
}
for wiring i put both vdd pins to 5v, and both vss to ground, and from RA0 i have a resistor and LED.

It programs properly, but my LED does not flash?

Is my internal clock set up properly?

thanks
craig

Last edited:

#### 3v0

##### Coop Build Coordinator
Forum Supporter
You can use the # icon to place [CODE][/CODE] tags around you code and it will preserve the formating. A lot of new people are not using it, please do.

Like this.
Code:
//-------------------------------------------------------------
#if defined(__PCH__)
#include <18F4620.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,PBADEN = OFF,LVP = OFF, NOBROWNOUT
#use delay(clock=8000000)
#endif

#define ALL_OUT 0x00

void main(void)
{
setup_oscillator( OSC_8MHZ );
delay_ms(1500);
SET_TRIS_A(ALL_OUT);

while(1)
{
OUTPUT_HIGH(PIN_A0);
delay_ms(1000);
OUTPUT_LOW(PIN_A0);
delay_ms(1000);
}
}

//-------------------------------------------------------------
You have a PICkit2. You can use it as an in circuit debugger and figure out if the code is executing. Step, breakpoints, all that debugger stuff

I see you are using the CCS compiler. Their IDE may not be able to use the PICkit2 to debug. If so ditch it and use MPLAB. You can still use the CCS compiler but you may have to run a small program that integrates the compiler with MPLAB.

You will find progaming is much easier with ICD'ing.

I do not have the CCS manual in front of me but the OSC stuff looks about right.

Get you self up and runing in the debugger. Go from there. Make sure the LED is not in backwards 3v0

#### kchriste

##### New Member
Forum Supporter
You need to configure PORTA for digital inputs by writing 0x0F to ADCON1. You also need to turn off the analog comparators by writing 0x07 to CMCON.

Last edited:

#### 3v0

##### Coop Build Coordinator
Forum Supporter
EDIT: I agree give it a try. I forgot about the comparators.

The processor data sheet often has a bit of asm for setting up each port that will quickly tell you these sort of settings.

#### cwickham

##### New Member
thanks, i got set those values, and everything seemed to work in debug mode, but when i moved it to another board to test, it stopped working, well worked half the time. it was all because i forgot to tie MCLR high. Wat a newb i am.

thanks again for the help
craig

Status
Not open for further replies.