Blinking an LED with PIC18F46K80

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
washburn96
Posts: 3
Joined: 05 Dec 2022 05:13

Blinking an LED with PIC18F46K80

#1 Post by washburn96 » 05 Dec 2022 05:27

I'm currently having some trouble trying to blink an LED, connected to pin RC0, on a PIC18F46K80. I'm currently trying to migrate from CCS to mikroC PRO and, since CCS always hides what's actually going on underneath your code, I might have developed some bad habits and now I have no idea on why this doesn't work. These are my goals:

- Use the internal RC oscillator to provide Fosc = 64MHz
- Turn on pin RC0 on PORTC
- Wait 500ms
- Turn off pin RC0
- Wait another 500ms.

This is my code:

Code: Select all

void main() {

     PORTC = 0x00;
     LATC = 0x00;
     TRISC.RC0 = 0;
     
     
     while(1){
              LATC.B0 = 1;
              Delay_ms(500);
              LATC.B0 = 0;
              Delay_ms(500);
     }

}
My configuration bits are the following:

MCU Clock Frequency: 64MHz
VREG Sleep: Disabled
LF-INTOSC Low Power: High Power
SOSC Power Selection and Mode: High Power
Extended Instruction Set: Enabled
Oscillator: Internal RC Oscillator
PLL x4: Enabled
FSCM: Disabled
IESO: Disabled
PUT: Enabled
BOR: Enabled in Hardware, SBOREN disabled
BOR Voltage: 1.8V
BOR Power Level: ZPBORMV instead of BORMV is selected
WDT: WDT disabled in hardware; SWDTEN bit disabled
WDT Postscaler: 1:1048576
ECAN Mux: TX and RX on RB2 and RB3
MSSP Address Masking: 7 bit
MCLR: Enabled
Stack Overflow Reset: Disabled
Boot Block Size: 2K
Background Debug: Disabled

Circuit schematic: https://prnt.sc/oE1e9MuxkXpZ

VU_NAS
Posts: 10
Joined: 20 Mar 2013 21:17

Re: Blinking an LED with PIC18F46K80

#2 Post by VU_NAS » 05 Dec 2022 17:19

I don't think this mcu can run at 64MHz via its internal PLL oscillator.

paulfjujo
Posts: 1557
Joined: 24 Jun 2007 19:27
Location: 01800 St Maurice de Gourdans France
Contact:

Re: Blinking an LED with PIC18F46K80

#3 Post by paulfjujo » 05 Dec 2022 17:50

Hello,


config bits !

Internal Oscillator !
• INTIO2 Internal Oscillator with I/O on RA6 and RA7
and
For the INTIOx modes (HF-INTOSC):
• Only the PLLEN can enable the PLL (PLLCFG is ignored).
bit PLLEN in OSCTUNE register

washburn96
Posts: 3
Joined: 05 Dec 2022 05:13

Re: Blinking an LED with PIC18F46K80

#4 Post by washburn96 » 05 Dec 2022 18:27

VU_NAS wrote:
05 Dec 2022 17:19
I don't think this mcu can run at 64MHz via its internal PLL oscillator.
Yes, it can. It has an internal RC oscillator with 16Mhz output, that can be multiplexed to a 4x PLL. I had it running like that with my code compiled in CCS PIC compiler

washburn96
Posts: 3
Joined: 05 Dec 2022 05:13

Re: Blinking an LED with PIC18F46K80

#5 Post by washburn96 » 05 Dec 2022 18:28

paulfjujo wrote:
05 Dec 2022 17:50
Hello,

did you disable Analog PORTC input ?
Most of new MCU , have inputs in Analog mode at reset or power ON ...

:idea: show us your code ..!
and config bits !
There are no analog functions multiplexed to PORTC in this MCU. If my LED was connected to a pin in PORTA, it would be another story.

paulfjujo
Posts: 1557
Joined: 24 Jun 2007 19:27
Location: 01800 St Maurice de Gourdans France
Contact:

Re: Blinking an LED with PIC18F46K80

#6 Post by paulfjujo » 07 Dec 2022 16:26

hello,


Except off Oscillator problem, i didn't see somewhat wrong ,
or interference with Secondary Oscillator SOSCO or SCLKI forced RC0 as input ?
SOSC Power Selection and Mode: High Power <- i don't know what does this exactly ..
capacitor on VCAP ?

i don't have your type of MCU to do this test
but i compiled the project ..
maybe you can upload this *.hex into your PIC and see if different behavior ...
TEST_18F46K80.zip
(48.1 KiB) Downloaded 47 times

hexreader
Posts: 1786
Joined: 27 Jun 2010 12:07
Location: England

Re: Blinking an LED with PIC18F46K80

#7 Post by hexreader » 11 Dec 2022 18:34

I do own a PIC18F46K80

The attached project works for me...

EDIT: - oops, mistakenly read LED on RB0 instead of RC0. Luckily example toggles both pins
Attachments
Pintest.zip
(53.12 KiB) Downloaded 43 times
Start every day with a smile...... (get it over with) :)

Post Reply

Return to “mikroC PRO for PIC General”