📄 demo9s08aw60_test.c
字号:
/******************************************************************************
*
* 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 */
/*
// ---------------------------------------------------------------------------
// Peripheral Initialization Routine
// ---------------------------------------------------------------------------
*/
void PeriphInit(void)
{
SOPT = 0x00; /* Disable COP */
PTCDD = 0x10; // set port c as inputs for push button switch input
PTCPE = 0xEF; // enable port c pullups for push button switch operation
PTFDD = 0xFF; // set port f as outputs for LED operation
PTFD = 0x00;
/* TPM1SC: TOF=0,TOIE=0,CPWMS=0,CLKSB=0,CLKSA=0,PS2=0,PS1=0,PS0=0 */
// TPM1SC = 0x00; /* Stop and reset counter */
// TPM1MOD = 0x00; /* Period value setting */
// (void)(TPM1SC == 0); /* Overflow int. flag clearing (first part) */
/* TPM1SC: TOF=0,TOIE=1,CPWMS=0,CLKSB=0,CLKSA=1,PS2=1,PS1=1,PS0=0 */
//TPM1SC = 0x4E; /* Int. flag clearing (2nd part) and timer control register setting */
/* ### */
}
/*
// ---------------------------------------------------------------------------
// Main
// ---------------------------------------------------------------------------
*/
void main(void) {
unsigned short tempcount;
unsigned short tempcount2;
PeriphInit(); /* Microcontroller initialization */
EnableInterrupts; /* enable interrupts */
// Begin LED/Switch test
for(;;) // If ms still has time left, delay another ms
{
if (PTCD_PTCD2==0x01)
b_ClearBit(0,PTFD);
else
b_SetBit(0,PTFD);
b_SetBit(7,PTFD);
tempcount = 125; // This loop is about 8 instructions
while(tempcount != 0) // 125 loops is 1000 instructions
{
tempcount2 = 125;
while(tempcount2 != 0) // 125 loops is 1000 instructions
tempcount2--;
tempcount--; // Run at 4MHz is 1ms
}/* End While */
b_ClearBit(7,PTFD);
tempcount = 125; // This loop is about 8 instructions
while(tempcount != 0) // 125 loops is 1000 instructions
{
tempcount2 = 125;
while(tempcount2 != 0) // 125 loops is 1000 instructions
tempcount2--;
tempcount--; // Run at 4MHz is 1ms
}/* End While */
} /* loop forever */
}/* end main(void) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -