Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] An easy problem with 18F4520

Status
Not open for further replies.

miyop

Newbie level 6
Joined
Nov 14, 2012
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,336
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.
 

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 :)
 

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:

Circuit2.png

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:

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.
 

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:

Warning.png

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.
 

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 - - -

exmple.jpgcheck it ..+10V is the power in this case.
 
  • Like
Reactions: miyop

    miyop

    Points: 2
    Helpful Answer Positive Rating
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.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top