//-------------------------------------------------------------------------*
// 文件名: PWM.h                                                           *
// 说  明: 定时器和定时器通道设置头文件                                    *
//-------------------------------------------------------------------------*

#ifndef PWM_H
#define PWM_H
  //1 头文件
  #include "Type.h"           //类型别名定义
  #include "MC9S08AW60.h"  //映像寄存器地址头文件

  //2 函数声明
  //-----------------------------------------------------------------------*
  //函数名: PWM(PWM波输出函数)                                             *
  //功能: 根据所需的PWM波的周期和占空比,并设置相关寄存器,输出PWM波         * 
  //参数:                                                                  *
  //    (1)TMPNo:定时器号(1-2)                                             *
  //    (2)CHNo:通道号(定时器1通道号0-5,定时器2通道号0-1)                  *
  //    (3)Period:PWM波周期(0-65535)                                       *
  //    (4)Duty:PWM波占空比(0-100)                                         *
  //返回:无                                                                *
  //-----------------------------------------------------------------------*
  void PWM(uint8 TMPNo,uint8 CHNo,uint16 Period, uint8 Duty);
  
  //3 寄存器有关的宏定义
  //标志位掩码的定义
  //定时器状态和控制寄存器各个位的掩码
  #define AW60_TPM_CSTR_TOF             (0x80)   //定时器溢出标志位掩码
  #define AW60_TPM_CSTR_TOIE            (0x40)   //定时器溢出中断使能位掩码
  #define AW60_TPM_CSTR_CPWMS           (0x20)   //PWM选择位掩码
  #define AW60_TPM_CSTR_CLKSB           (0x10)   //时钟源选择位B掩码
  #define AW60_TPM_CSTR_CLKSA           (0x08)   //时钟源选择位A掩码
  #define AW60_TPM_CSTR_PS2             (0x04)   //预分频位2掩码
  #define AW60_TPM_CSTR_PS1             (0x02)   //预分频位1掩码
  #define AW60_TPM_CSTR_PS0             (0x01)   //预分频位0掩码
  //定时器通道状态和控制寄存器各个位的掩码
  #define AW60_TPM_CHSCSTR_CHF          (0x80)   //标志位
  #define AW60_TPM_CHSCSTR_CHIE         (0x40)   //中断使能位
  #define AW60_TPM_CHSCSTR_MSB          (0x20)   //模式选择位B
  #define AW60_TPM_CHSCSTR_MSA          (0x10)   //模式选择位A
  #define AW60_TPM_CHSCSTR_ELSB         (0x08)   //沿跳变/输出电平选择位B
  #define AW60_TPM_CHSCSTR_ELSA         (0x04)   //沿跳变/输出电平选择位A
  //AW60的定时器模块相关寄存器的定义
  //x=1表示定时器1模块 x=2表示定时器2模块
  //定时器状态和控制寄存器
  #define AW60_TMP_CSTR(x)      (*(vuint8 *)(0x00000020+(x-1)*64))
  //定时器计数寄存器(高)
  #define AW60_TMP_CNTH(x)  (*(vuint8 *)(0x00000021+(x-1)*64))
  //定时器计数寄存器(低)
  #define AW60_TMP_CNTL(x)  (*(vuint8 *)(0x00000022+(x-1)*64))    
  //定时器预置寄存器(高)
  #define AW60_TMP_MODH(x)   (*(vuint8 *)(0x00000023+(x-1)*64))
  //定时器预置寄存器(低)
  #define AW60_TMP_MODL(x)   (*(vuint8 *)(0x00000024+(x-1)*64))
  //定时器1通道状态和控制寄存器
  #define AW60_TMP1_CHSCSTR(x)  (*(vuint8 *)(0x00000025+(x)*3))
  //定时器1通道数值寄存器(高)
  #define AW60_TMP1_CHVH(x)  (*(vuint8 *)(0x00000026+(x)*3))
  //定时器1通道数值寄存器(低)
  #define AW60_TMP1_CHVL(x)  (*(vuint8 *)(0x00000027+(x)*3))
  //定时器2通道状态和控制寄存器
  #define AW60_TMP2_CHSCSTR(x)  (*(vuint8 *)(0x00000065+(x)*3))
  //定时器2通道数值寄存器(高)
  #define AW60_TMP2_CHVH(x)  (*(vuint8 *)(0x00000066+(x)*3))
  //定时器2通道数值寄存器(低)
  #define AW60_TMP2_CHVL(x)  (*(vuint8 *)(0x00000067+(x)*3))    
    
#endif    