AN2616 Freescale Semiconductor / Motorola, AN2616 Datasheet - Page 32

no-image

AN2616

Manufacturer Part Number
AN2616
Description
Getting Started with HCS08 and CodeWarrior Using C
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
AN2616
32
Code to configure the clock in C would be:
The “while” loop ensures that the external clock has been selected
(ICGS1_ERCS) and that the FLL has locked to the desired frequency
(ICGS1_LOCK).
The final program is:
#include <hidef.h> /* for EnableInterrupts macro */
#include <MC9S08GB60.h> /* include peripheral declarations */
#include "M68DEMO908GB60.h"
#define PRESCALAR 7
#define MODULUS 32768
#define DUTY75 (MODULUS-(MODULUS/4))
#define DUTY25 (MODULUS/4)
interrupt Vkeyboard void intSW1(){
}
void main(void) {
Getting Started with HCS08 and CodeWarrior Using C
/*configure Internal Clock Generator [ICG]*/
/*MFD[]={4,6,8,10,12,14,16,18}*/
ICGC2_MFD = 7;
ICGC2_RFD = 0;
ICGC1 = 0b00111000;
while((ICGS1_LOCK==0)||(ICGS1_ERCS==0)){
}
ICGC2_LOCRE = 1; /*enable reset if clock fails*/
EnableInterrupts; /* enable interrupts */
/* include your code here */
PTADD = 0;
PTAPE = 0xf0; //Pullups on upper 4 bits
/*initialize bits 0-3 of Port F as outputs (connected to led's)*/
PTFDD = 0x0f;
LED1 = OFF;
LED2 = OFF;
LED3 = OFF;
LED4 = OFF;
LED5 = OFF;
/*Initialize timer TPM1 channel, assumes not touched since reset!*/
TPM1SC_CLKSA = 1;/*Select BUS clock*/
TPM1SC_CLKSB = 0;
TPM1SC_PS = PRESCALAR;/*clock source divided by prescalar*/
TPM1MOD = MODULUS;/*set Counter modulus*/
/*configure PWM mode and pulse*/
TPM1C0SC_MS0B = 1;
TPM1C0SC_ELS0A = 1; /*Select low as true*/
TPM1C0V = DUTY25;/*select final divider (duty cycle)*/
LED4 = ON;
KBIPE_KBIPE4 = 1;
KBISC_KBIE = 1;
Freescale Semiconductor, Inc.
/*Ensure COP doesn't reset device whilst waiting for clock lock*/
__RESET_WATCHDOG(); /* kicks the dog */
LED1 = SW4;
KBISC_KBACK = 1;/*acknowledge interrupt*/
For More Information On This Product,
Go to: www.freescale.com
//initialize as input (Data Direction Register)
/*MS0B=1, MS0A=0; << Edge align PWM*/
/*32KHz crystal, demo board.
*/
/* RFD[]={1,2,4,8,16,32,64,128}*/
/*32KHz crystal, demo board.
*/
For 4MHz crystal (eval board):
For 4MHz crystal (eval board):
ICGC2_MFD = 3
ICGC1 = 0b01111000;
MOTOROLA

Related parts for AN2616