Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1147532
  • 博文数量: 139
  • 博客积分: 2510
  • 博客等级: 少校
  • 技术积分: 1712
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-13 23:10
个人简介

每天进步一点点。

文章分类

全部博文(139)

文章存档

2015年(3)

2014年(11)

2013年(25)

2011年(1)

2009年(3)

2008年(29)

2007年(45)

2006年(22)

分类: C/C++

2008-10-29 10:13:18

1.main.c

#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */

#include "PWM.h"

word prd = 0xFFFF;
word dty = 0x8000;
 
void MCU_init(void) /* Device initialization function declaration */
{
  PWM_Init();
}

void main(void) {

  /* Uncomment this function call after using Device Initialization
     to use the generated code */

  MCU_init();

  EnableInterrupts; /* enable interrupts */

  /* include your code here */



  for(;;)
  {
    PWM_SetPeriod(prd);
    PWM_SetDuty(dty);
    
    __RESET_WATCHDOG(); /* feeds the dog */
  } /* loop forever */
  /* please make sure that you never leave this function */
}


2.pwm.c


#include <MC9S08AW60.h>

void PWM_Init(void)
{
  /* ### Init_TPM init code */
  TPM1MOD = 0x00;
  TPM1C2V = 0x8000;
  /* TPM1C2SC: CH2F=0,CH2IE=0,MS2B=1,MS2A=0,ELS2B=0,ELS2A=1 */
  TPM1C2SC = 0x24;

  /* TPM1SC: TOF=0,TOIE=0,CPWMS=0,CLKSB=0,CLKSA=1,PS2=0,PS1=1,PS0=1 */
  TPM1SC = 0x0B;
}

void PWM_SetDuty(word duty)
{
   TPM1C2V = duty;
}

void PWM_SetPeriod(word period)
{
   TPM1MOD = period;
}

阅读(2834) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~