Changing register settings in Mikro C

Post your requests and ideas on the future development of mikroC PRO for PIC.
Post Reply
Author
Message
nthrower
Posts: 8
Joined: 27 Apr 2018 18:44

Changing register settings in Mikro C

#1 Post by nthrower » 27 Apr 2018 18:53

I am trying to use a 18F45K22, but want to use the internal clock @ 8Mhz.

I don't understand how to edit the registers using this software.

I need to edit

OSCCON
OSCCON2

Any ideas would be helpful.

I know Mikroe do preset configurations for this chip, but strangely enough not using the internal oscillator
(Perhaps they don't know either!)

Thanks
Nigel

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Changing register settings in Mikro C

#2 Post by filip » 30 Apr 2018 09:12

Hi,

To access the OSCCON registers, simply assign them a value in the the code, like this :

Code: Select all

void main() {
   OSCCON = 0xAA;
   OSCCON2 = 0x55;
}
Also be sure to set the internal clock configuration bits in the Edit Project Window.

Regards,
Filip.

nthrower
Posts: 8
Joined: 27 Apr 2018 18:44

Re: Changing register settings in Mikro C

#3 Post by nthrower » 30 Apr 2018 16:14

Hi,

Thanks, I will give it a try.

My only worry, is that this software runs @ run time, so if I set the registers to use the internal oscillator, it may not startup?

It concerns me that I can't set the registers when I download the code to the chip.

Thanks

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Changing register settings in Mikro C

#4 Post by filip » 03 May 2018 08:45

Hi,

It will run correctly as long as you do this at the beginning of your code.

Regards,
Filip.

nthrower
Posts: 8
Joined: 27 Apr 2018 18:44

Re: Changing register settings in Mikro C

#5 Post by nthrower » 17 May 2018 19:12

Thanks

Will give it a try

nthrower
Posts: 8
Joined: 27 Apr 2018 18:44

Re: Changing register settings in Mikro C

#6 Post by nthrower » 27 Jun 2018 12:00

Hi Filip,

All working now.

It took a while as I have never used this chip before.

The timings were wrong, so having spent some time going through the assembler output, I now know to set the clock in the compiler to the final clock speed of 64 MHz, as against the master clock @ 16 MHz.

Perhaps there should be a note somewhere on the Edit Project screen.

Onward and forward to learning about timers next.

Thanks

Nigel

Post Reply

Return to “mikroC PRO for PIC Wish List”