# [SOLVED]An easy problem with 18F4520

Status
Not open for further replies.

#### miyop

##### Newbie level 6
I'm new at PIC programming and I have a project with 18F4520. My code language is C and I use CCs C as a compiler. I wrote a code to blink a led for beginning but I couldn't achieve it. The code is very easy but I couldn't understand where the error is. The code I wrote is this:

#include<18f4520.h>
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#use delay (clock = 4000000)

#use fast_io(b)

void main(void)
{

int a=0;
set_tris_b(0x00);

while(TRUE){

if(a>9) break;
output_high(pin_b0);
delay_ms(300);
output_low(pin_b0);
delay_ms(300);
a++;

}

}

Can anyone help me with this easy code? I don't know if I am wrong with the fuses or configuration settings.

#### hemnath

Try this code ..led's connected to PORT B. It will glow for every 1 sec interval
HTML:
#include <18f4520.h>
#FUSES NOWDT
#FUSES XT

#use delay(clock=4000000)

void main()
{
set_tris_b(0x00);
while(1)
{
output_b(0xFF);
delay_ms(1000);
output_b(0x00);
delay_ms(1000);
}
}
Best wishes

- - - Updated - - -

Try this code ..led's connected to PORT B. It will glow for every 1 sec interval
HTML:
#include <18f4520.h>
#FUSES NOWDT
#FUSES XT

#use delay(clock=4000000)

void main()
{
set_tris_b(0x00);
while(1)
{
output_b(0xFF);
delay_ms(1000);
output_b(0x00);
delay_ms(1000);
}
}
Best wishes

#### miyop

##### Newbie level 6
Try this code ..led's connected to PORT B. It will glow for every 1 sec interval
HTML:
#include <18f4520.h>
#FUSES NOWDT
#FUSES XT

#use delay(clock=4000000)

void main()
{
set_tris_b(0x00);
while(1)
{
output_b(0xFF);
delay_ms(1000);
output_b(0x00);
delay_ms(1000);
}

}
Best wishes :)
This is my circuit:

Thank you so much. This is my first thread in a forum and the first reply I received.
But the code did not work. Is my circuit wrong or is the connection of oscillator incoorect?

Last edited:

#### hemnath

check the value of the crystal. I think you have not mentioned the crystal value in the proteus.
If still it doesn't works..

try it ...
use #fuses INTRC_IO instead of #fuses XT. Remove the crystal. This fuse uses internal oscillator so you need not to connect external crystal. compile and load the hex file.

#### miyop

##### Newbie level 6
check the value of the crystal. I think you have not mentioned the crystal value in the proteus.
If still it doesn't works..

try it ...
use #fuses INTRC_IO instead of #fuses XT. Remove the crystal. This fuse uses internal oscillator so you need not to connect external crystal. compile and load the hex file.

I tried all you said but nothing changed. It gives everytime the same warning seen below:

That warning flows continuously and endlessly. What can cause this warning?

Note: I'm sorry for these easy questions but as I said I started this work not more than 2-3 days ago. And thank you again for your interest.

- - - Updated - - -

I think my CCs compiler may not be supporting 18Fxxx chips. Can it be? If it is, then can you suggest me a compiler to compile the code above.

#### hemnath

Power to MCLR connection makes problem. Right now i dont have proteus to simulate. But i think, Change that power supply and use another power source which is named "POWER". You can find it. Read Proteus ISIS user manual.

- - - Updated - - -

check it ..+10V is the power in this case.

miyop

### miyop

points: 2

#### miyop

##### Newbie level 6
Thanks for your help "hemnath". I think my compiler does not support 18f family. I will try another one.

- - - Updated - - -

It was because of the compiler. I used a different version and it worked.

Status
Not open for further replies.