hi,
i am using PIC18F4550, with crystal of 8 MHz.
i am not able to understand how use configuration bits for this and how to calculate delay value, delay function if i want to make led blink for one second
i am using MPLAB IDE and C18 Compiler.
please help.
Without looking I expect the fuse setting is for the crystal is HS. You can get the C18 setting from the MPLAB help menu. For what they mean read the processor data sheet.
#pragma config OSC=HS, WDT=OFF, LVP=OFF, DEBUG=ON
You are using an 8 MHz crystal. The process runs at 1/4 the crystat so you are at 2 MHz.
The period is 1/freq or 1/2,000,000 or 0.0000005 seconds. Each instruction takes 0.0000005 seconds. An instruction time is also know as a Tcy.
In the header file C:\MCC18\h\delays.h you will find various functions for delaying based on the number of Tcy's required. Be sure to #include <delays.h>
You can use the stopwatch in MPLAB's simulator to verify your delay times.
The 18F4550 has a PLL that needs to be supplied with a 4MHz signal. So with an 8MHz crystal you need to set the PLL divide value to 2. This will give you a 96MHz signal out of the PLL and so you need to divide this by (at least) 2 to get 48MHz.
Using
Thanks 3v0 and Mike.
I appreciate your help.
I tried to write program in C18, just to check different delays.
But it gives error - something wrong with "int i and int j".
the code is as below :
#pragma config FOSC = INTOSCIO_EC //Internal oscillator, port function on RA6, EC used by USB
//#pragma config WDT = OFF, FOSC = HSPLL_HS, LVP = OFF , DEBUG = ON, CPUDIV = OSC1_PLL2, PLLDIV = 2
#pragma config WDT = OFF //Disable watchdog timer
void main()
{
ADCON1 = 0x0F; // Configure all ports with analog function as digital
CMCON = 7; // Disable comparators
The problem is with where you declared i and j. Change the code to put the variable definitions first in the code block. Ahead of any executable statements.
Code:
...
void main()
{
int i;
int j;
ADCON1 = 0x0F; // Configure all ports with analog function as digital
CMCON = 7; // Disable comparators
TRISB = 0;
PORTB = 0;
...