C   32
init sysclk
Guest on 17th September 2023 09:44:58 PM


  1. #include <c8051f040.h>
  2.  
  3. void init_sysclk( ) {
  4.         char save = SFRPAGE;
  5.  
  6.         SFRPAGE = CONFIG_PAGE;
  7.        
  8.         OSCXCN = 0x77; // start up oscillator in crystal oscillator mode
  9.         while (!(OSCXCN & 0x80)); // wait for crystal startup
  10.        
  11.         // set the system clock source to the external source
  12.         CLKSEL = 0x01;
  13.  
  14.         SFRPAGE = save;
  15. }

Raw Paste

Login or Register to edit or fork this paste. It's free.