View previous topic :: View next topic |
Author |
Message |
Elysion
Joined: 03 Aug 2010 Posts: 26
|
A question about 18f14k50 |
Posted: Sat Dec 04, 2010 1:28 am |
|
|
My compiler version is 4.108 and I want to write an easy blinking led program for testing. But I couldn't set its internal oscillator to 8MHZ.
My code:
Code: |
#include <18F14K50.h>
#device adc=8
#include <PIC18F14K50_registers.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //Also I have tried #FUSES XT and INTRC
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOMCLR //Master Clear pin enabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOCPB //No Boot Block code protection
#FUSES NOWRTB //Boot block not write protected
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES HFOFST
#FUSES NOWRT0
#FUSES NOWRT1
#FUSES USBDIV2
#FUSES BBSIZ2K //2K words Boot Block size
#FUSES CPUDIV4 //System Clock by 4
#FUSES PCLKEN
#use delay(int=8000000) //Also I have tried #use delay(clock=8000000)
#define LED PIN_A5
void main()
{
OSCCON=01100111;
setup_adc_ports(NO_ANALOGS|VSS_VDD);
//Example blinking LED program
while(true){
output_low(LED);
delay_ms(1000);
output_high(LED);
delay_ms(1000);
}
}
|
How can I blink a led with 18f14k50? |
|
![](templates/subSilver/images/spacer.gif) |
wireless
Joined: 02 Nov 2003 Posts: 16 Location: London England
|
|
Posted: Sat Dec 04, 2010 3:30 am |
|
|
Hi
I have not looked at your code in detail but you have set the OSCCON register to a huge decimal value.
OSCCON=01100111;
I think you intended it to be binary so you should have added a 'b' at the end of the number or expressed it a 0x67.
OSCCON=01100111b;
Regards
Terry _________________ "An engineer is someone, who can do for 5 bob, what any dam fool can do for 10. " - Hon C S Royce Joint Founder of Rolls Royce. |
|
![](templates/subSilver/images/spacer.gif) |
Elysion
Joined: 03 Aug 2010 Posts: 26
|
|
Posted: Sat Dec 04, 2010 5:47 am |
|
|
I changed my code as you said but the same problem is continuing.
OSCCON=0b01100111; |
|
![](templates/subSilver/images/spacer.gif) |
Elysion
Joined: 03 Aug 2010 Posts: 26
|
|
Posted: Sat Dec 04, 2010 7:08 am |
|
|
And I can use it with external oscillator but I haven't used with internal oscillator, yet. |
|
![](templates/subSilver/images/spacer.gif) |
Elysion
Joined: 03 Aug 2010 Posts: 26
|
|
Posted: Sat Dec 04, 2010 9:31 am |
|
|
Also I found a problem at 18f14k50's library. When I looked at its ASM list, I saw this line:
This register (FB4) is unimplemented register which is only read. How can I avoid this problem? And also my oscillator problem is continuing. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Dec 04, 2010 10:46 pm |
|
|
Try the following simple program:
Code: |
#include <18F14K50.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOLVP,NOPLLEN,CPUDIV1
#use delay(clock=4000000)
//======================================
void main(void)
{
while(1)
{
output_high(PIN_A5); // Blink an LED on Pin A5
delay_ms(500);
output_low(PIN_A5);
delay_ms(500);
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
Elysion
Joined: 03 Aug 2010 Posts: 26
|
|
Posted: Mon Dec 06, 2010 12:33 am |
|
|
Is there any difference between "#use delay(clock=4000000)" and "#use delay(int=4000000)"?
Thanks. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19365
|
|
Posted: Mon Dec 06, 2010 5:29 am |
|
|
Yes.
The first is the 'old' form. It _just_ says what frequency the chip is being clocked at.
On more modern compilers, the delay function will accept other parameters, making it partially replace the fuse functions. The second form you give, says 'use the internal oscillator at 4MHz', so automatically sets the INT_RC fuse if it is not already selected.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Elysion
Joined: 03 Aug 2010 Posts: 26
|
|
Posted: Mon Jan 24, 2011 3:45 am |
|
|
I couldn't work 18f14k50 with internal oscillator. I tried various compiler version (4.108, 4.110, 4.114). But I couldn't work with its internal oscillator. Is there anyone to try PIC18f14k50 with real hardware? |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 24, 2011 12:45 pm |
|
|
I tested the program that I posted above on a 18F14K50 with vs. 4.114
and it worked. I tested it on a Microchip "Low pin count" 20-pin
development board and programmed it with a Pickit2. The Pickit2
provides +3.3v power to the 18F14K50. I jumpered pin A5 to the "DS1"
LED and it blinks at the correct rate.
If it doesn't work for you, then you likely have a hardware problem. |
|
![](templates/subSilver/images/spacer.gif) |
vinniewryan
Joined: 29 Jul 2009 Posts: 154 Location: at work
|
|
Posted: Mon Jan 24, 2011 3:39 pm |
|
|
I had an issue programming the 18F13K50 and a simple firmware update on my ICD fixed it right up. It might be worth consideration. _________________ Vinnie Ryan |
|
![](templates/subSilver/images/spacer.gif) |
|