;************************************************************* ;* Macro library to support internal clock setup ;************************************************************** ;* FileName: 18FIntClock.asm ;* Processor: PIC18xxxx ;* Revison : 1-A ;* Copyright AFG-2009 ;************************************************************** ; Macros' List ; ;- m18SetIntClock IntFosc [31/125/250/500/1/2/4/8/16/32] ;- m18PLLOn ;- m18PLLOff ;- m18CheckIntOscStable ;- m18CheckOSTEnd NOLIST ;*********************************************** ; m18SetIntClck MACRO IntFosc [31/125/250/500/1/2/4/8/16/32] ; Set Internal Clock @ IntFosc - 16 and 32 MHz use PLL ; Request : INTIO1 or INTIO2 mode in CONFIG ; Note : PIC18F in INTIO1 or INTIO2 mode, start at 1MHz m18SetIntClock MACRO IntFosc #if IntFosc == d'31' ; slowest speed : intosc 31 kHz bcf OSCTUNE, PLLEN bcf OSCCON, IRCF0 bcf OSCCON, IRCF1 bcf OSCCON, IRCF2 #else #if IntFosc == d'125' ; slow speed : intosc 125 kHz bcf OSCTUNE, PLLEN bsf OSCCON, IRCF0 bcf OSCCON, IRCF1 bcf OSCCON, IRCF2 #else #if IntFosc == d'250' ; slow speed : intosc 250 kHz bcf OSCTUNE, PLLEN bcf OSCCON, IRCF0 bsf OSCCON, IRCF1 bcf OSCCON, IRCF2 #else #if IntFosc == d'500' ; slow speed : intosc 500 kHz bcf OSCTUNE, PLLEN bsf OSCCON, IRCF0 bsf OSCCON, IRCF1 bcf OSCCON, IRCF2 #else bsf OSCCON, IRCF2 #if IntFosc == d'1' ; reset default speed : intosc 1 MHz bcf OSCTUNE, PLLEN bcf OSCCON, IRCF0 bcf OSCCON, IRCF1 #else #if IntFosc == d'2' ; more speed : intosc 2 MHz bcf OSCTUNE, PLLEN bsf OSCCON, IRCF0 bcf OSCCON, IRCF1 #else #if IntFosc == d'4' ; more speed : intosc 4 MHz bcf OSCTUNE, PLLEN bcf OSCCON, IRCF0 bsf OSCCON, IRCF1 #else #if IntFosc == d'8' ; more speed : intosc 8 MHz bcf OSCTUNE, PLLEN bsf OSCCON, IRCF0 bsf OSCCON, IRCF1 #else #if IntFosc == d'16' ; more speed : enable PLL & 4 MHz bsf OSCCON, IRCF0 bcf OSCCON, IRCF1 bsf OSCTUNE, PLLEN #else #if IntFosc == d'32' ; fastest speed : enable PLL & 8 MHz bsf OSCCON, IRCF0 bsf OSCCON, IRCF1 bsf OSCTUNE, PLLEN #else error "Internal Clock Selection Wrong" #endif #endif #endif #endif #endif #endif #endif #endif #endif #endif ENDM ;*********************************************** ; m18CheckIntOscStable ; Check for internal oscillator stable ; if not, wait for stability m18IntOscStable MACRO btfss OSCCON, IOFS bra $-2 ENDM ;*********************************************** ; m18CheckOSTEnd ; Check for main oscillator stable ; if not wait for stability m18CheckOSTEnd MACRO btfss OSCCON, OSTS bra $-2 ENDM ;*********************************************** ; m18PLLOn ; Enable PLL m18PLLOn MACRO ; more speed : enable PLL bsf OSCTUNE, PLLEN ENDM ;*********************************************** ; m18PLLOff ; Disable PLL m18PLLOff MACRO ; more speed : enable PLL bcf OSCTUNE, PLLEN ENDM LIST