View previous topic :: View next topic |
Author |
Message |
ritchie
Joined: 13 Sep 2003 Posts: 87
|
Need Help with this Code on PIC18F1320 |
Posted: Wed Mar 03, 2004 8:56 pm |
|
|
Hello,
I need your help regarding the code below. My problem is that when I click the run program of the ICD the first time & second time my LED blinks but when I stop the program and run again using the ICD the LED will not blink again.
I need your help if I configured correctly the PIC chip.
The code list:
Code: |
#include <18F1320.h> // MCU specific library
#fuses INTRC_IO,NOLVP,NOWDT,NOPROTECT
#use delay (clock=8000000) // 8MHz clock
#define LED PIN_A2
#byte OSCCON = 0x0FD3
void led_func()
{
output_high(LED);
delay_ms(1000);
output_low(LED);
delay_ms(1000);
}
main()
{
//OSCCON = 0b11111001;
setup_oscillator(OSC_8MHZ);
setup_adc_ports(NO_ANALOGS);
while(TRUE)
{
led_func();
}
} |
Need your help.
Thanx |
|
|
SteveS
Joined: 27 Oct 2003 Posts: 126
|
|
Posted: Thu Mar 04, 2004 9:04 am |
|
|
I'm using the 182320 and it seems to be working ok with the ICD-2.
I noticed you initially had:
OSCCON = 0b11111001
although commented out, I don't think it's the correct value. I use 0x72 to jump to 8Mhz.
setup_oscillator(OSC_8MHZ); generates 0x70. I'm thinking that the system clock select bits (0&1) should be 1x (binary). You may want to check that.
Check the listing to see the code seems right.
One odd thing I've noticed is that I think my timers sometimes keep running even whan I pasuse the program thru the ICD. There may be some oddities with the ICD and internal oscillators.
Oh, and I usually put a short delay after boosting the oscillator to let it settle. I think it's good practice in general to delay a bit after startup to be sure the power supply has really settled.
- SteveS |
|
|
ritchie
Joined: 13 Sep 2003 Posts: 87
|
|
Posted: Thu Mar 04, 2004 9:03 pm |
|
|
SteveS wrote: | I'm using the 182320 and it seems to be working ok with the ICD-2.
I noticed you initially had:
OSCCON = 0b11111001
although commented out, I don't think it's the correct value. I use 0x72 to jump to 8Mhz.
setup_oscillator(OSC_8MHZ); generates 0x70. I'm thinking that the system clock select bits (0&1) should be 1x (binary). You may want to check that.
Check the listing to see the code seems right.
One odd thing I've noticed is that I think my timers sometimes keep running even whan I pasuse the program thru the ICD. There may be some oddities with the ICD and internal oscillators.
Oh, and I usually put a short delay after boosting the oscillator to let it settle. I think it's good practice in general to delay a bit after startup to be sure the power supply has really settled.
- SteveS |
Thank you. Its now working using the internal oscillator block at 8MHz... I just added a delay before setup_oscillator(0x72) is invoke. |
|
|
|