/****************************************************************************** * * Copyright (C) 2006 Freescale Semiconductor, Inc. * All Rights Reserved * * Filename: DEMO9S08AW60_TEST.c * Author: Daniel Kruczek * Revision: 3.0 * * Description: Flashes LED_BAR7 and LED_BAR0 turns on and off according to * the state of SW1. * * Notes: Also serves as an example for the 9S08AW60 demo board. * Created using CodeWarrior 5.0 for HC(S)08. ******************************************************************************/ // =================================================================== // Macro Functions definitions // =================================================================== // The setting in project preference must be checked // char should be unsigned 8 bit
typedef unsigned char muint8; typedef unsigned short muint16; typedef unsigned long muint32;
typedef char mint8; typedef short mint16; typedef long mint32;
// To Clear or Set single bits in a byte variable. #define b_SetBit(bit_ID, varID) (varID |= (muint8)(1<<bit_ID)) #define b_ClearBit(bit_ID, varID) (varID &= ~(muint8)(1<<bit_ID)) #define b_XorBit(bit_ID, varID) (varID ^= (muint8)(1<<bit_ID))
// To Clear or Set single bits in a word(16-bit) variable. #define w_SetBit(bit_ID, varID) (varID |= (muint16)(1<<bit_ID)) #define w_ClearBit(bit_ID, varID) (varID &= ~(muint16)(1<<bit_ID)) #define w_XorBit(bit_ID, varID) (varID ^= (muint16)(1<<bit_ID))
#include <hidef.h> /* EnableInterrupts macro */ #include "derivative.h" /* include peripheral declarations */
muint8 flag; /* // --------------------------------------------------------------------------- // Peripheral Initialization Routine // --------------------------------------------------------------------------- */ void PeriphInit(void) { SOPT = 0x00; /* Disable COP */ PTCDD = 0x10; PTCPE = 0xEF; PTFDD = 0xFF; PTFD = 0x00; flag=1; }
/***** Init_TPM init code *****/ void TPM_init(void) {
//TPM1SC = 0x00; TPM1SC = 0x00; //TPM2SC TPM1MOD = 0x5FFF; TPM1C2V = 0x0FF; (void)(TPM1C2SC == 0);
TPM1C2SC = 0x68; TPM1C3V = 0x0FFF; (void)(TPM1C3SC == 0); //TPM1C2SC = 0x28; TPM1C3SC = 0x28; (void)(TPM1SC == 0); TPM1SC = 0x0F; } void main(void) { PeriphInit(); /* Microcontroller initialization */ TPM_init(); EnableInterrupts; /* enable interrupts */ // Begin LED/Switch test for(;;) { if (PTCD_PTCD2==0x01) b_ClearBit(2,PTFD); else b_SetBit(2,PTFD); b_ClearBit(7,PTFD); b_ClearBit(6,PTFD); b_ClearBit(5,PTFD);
} /* loop forever */ }/* end main(void) */
interrupt void PWMCH2_ISR(void) { TPM1C2SC_CH2IE=0X00; TPM1C2SC&=0xEF;
flag++;
if(flag<=1) { b_SetBit(7,PTFD); } else { flag=0; b_ClearBit(7,PTFD); }
TPM1C2SC_CH2IE=0X01; }
|