AN2616 Freescale Semiconductor / Motorola, AN2616 Datasheet - Page 28

no-image

AN2616

Manufacturer Part Number
AN2616
Description
Getting Started with HCS08 and CodeWarrior Using C
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
AN2616
Use PWM to flash
LED
28
Adding the following code to the program will configure the PWM and will flash
LED5 (or buzzer on evaluation board), using LED3 and LED4 to indicate the
duty cycle selected by switch SW4, when changed by the operation of switch
SW3.
#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)
void main(void) {
}
Getting Started with HCS08 and CodeWarrior Using C
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;
for(;;) {
} /* loop forever */
Freescale Semiconductor, Inc.
__RESET_WATCHDOG(); /* kicks the dog */
LED2 = SW2;
if(SW3==DOWN){
}
For More Information On This Product,
/*Switch pressed*/
if(SW4==DOWN){/**/
}else{
}
TPM1C0V = DUTY25;/**/
TPM1C0V = DUTY75;/**/
LED3 = ON;/**/
LED4 = OFF;/**/
LED3 = OFF;/**/
LED4 = ON;/**/
Go to: www.freescale.com
//initialize as input (Data Direction Register)
/*MS0B=1, MS0A=0; << Edge align PWM*/
MOTOROLA

Related parts for AN2616