"); //-->
这个简单的例子用来演示飞思卡尔的MC9S08AC16的PWM模块的用法,用的开发板是我做的NSS08Kit-R1型开发板,由于所有S08单片机的PWM模块都是高度相似的,因此,这个例子对于其他型号的S08单片机也应该适用
/******************************
@ Nicrosystem Freescale S08 DevKit(NSS08Kit-R1)
@ author:bluehacker<nicrosystem@gmail.com>
@ date:2009-04-06
********************************/
/*****************************
@说明:
本程序用来测试 MC9S08AC16的 PWM功能,使用TPM2的channel0和channel1,
首先输出edge aligned pwm,输出大约10秒后再改为输出 center pwm
如此循环
****************/
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include "delay.h"
#define BUS_CLK 4000000L
//以查询方式发送一个字节
void uart2_send_byte_poll(unsigned char c) {
/*SCI2C2_TIE =0;
SCI2C2_TCIE=0;
SCI2C2_RIE=0;
SCI2C2_ILIE=0;*/
SCI2D=c;
while(SCI2S1_TC==0);
}
//以查询方式发送一个字符串
void uart2_send_string_poll(unsigned char *str) {
while(*str!='\0'){
uart2_send_byte_poll(*str++);
}
}
//设置系统时钟模式,为FEE,8MHZ的系统主频,BUS CLK为4MHZ
void init_system_clock()
{
ICGC1=0xf8;
ICGC2=0x89;
while(ICGS1_LOCK==0);
}
//初始化sci2
//设置sci2为8bit,一个停止位,无校验模式
//设置sci2发送,接收使能,中断全部禁止
//设置波特率为9600
void init_sci2()
{
unsigned int BaudRate;
BaudRate="BUS"_CLK/9600/16;
SCI2BDH=(unsigned char)(BaudRate>>8);
SCI2BDL=(unsigned char)(BaudRate&0x00ff);
SCI2C1=0x04;
SCI2C2=0x0c;
SCI2C3=0x00;
}
//设置tpm2 channel0,channel1为edge-aligned pwm
//low-true pulse,1khz frequency
void init_tpm2_pwm()
{
TPM2MODH=0x0f;
TPM2MODL=0xa0;
TPM2C0SC=0x24;
TPM2C1SC=0x24;
TPM2C0VH=0x02;
TPM2C0VL=0xff;
TPM2C1VH=0x05;
TPM2C1VL=0xff;
TPM2SC=0x08;
}
void main(void) {
EnableInterrupts; /* enable interrupts */
/* include your code here */
SOPT_COPE=0;//disable cop watchdog
init_system_clock();
init_sci2();
uart2_send_string_poll((unsigned char*)("start.....\n"));
uart2_send_string_poll((unsigned char*)("output edge-aligned pwm....\n"));
init_tpm2_pwm();
for(;;) {
//__RESET_WATCHDOG(); /* feeds the dog */
delay_1s(10);
//set center-aligned pwm output,high true pulse
uart2_send_string_poll((unsigned char*)("output center-aligned pwm....\n"));
TPM2SC=0x00;
delay_1s(1);
TPM2C0SC=0x08;
TPM2C1SC=0x08;
TPM2SC=0x08;
TPM2SC_CPWMS=1;
delay_1s(10);
//set edge-aligned pwm output,low-true pulse
uart2_send_string_poll((unsigned char*)("output edge-aligned pwm....\n"));
TPM2SC=0x00;
delay_1s(1);
TPM2C0SC=0x24;
TPM2C1SC=0x24;
TPM2SC=0x08;
} /* loop forever */
/* please make sure that you never leave main */
}
专栏文章内容及配图由作者撰写发布,仅供工程师学习之用,如有侵权或者其他违规问题,请联系本站处理。 联系我们
相关推荐
2025年真的是人工智能代理之年吗?
人工智能代理何时能准备好实现自主业务运营?
PSD8xxF的在系统编程技术
BOE(京东方)全球首个OLED显示通透度团体标准正式发布 以科学标尺定义“柔性好屏”新高度
BTH-801F/BTH-801J红外遥控发射、接收模块应用电路图
BA5104/5204红外遥控发射、接收集成应用电路图
PLC控制系统抗干扰分析
BL20106红外线接收前置放大集成应用电路图
招聘硬件工程师
招聘软件工程师
有哪位大侠知道哪里可以当tornado2.2得嘛?
2010英特尔杯大学生电子设计竞赛(8)
轻量化智能眼镜:AI与微型显示引领可穿戴设备新潮流
PORTMON
PFS-4091高敏度红外接收器件内部电路图
2025年全球智能手机出货量增长2%,苹果创历史新高,2026年或迎挑战
HF-15/HJ-15高灵敏度、远距离红外遥控发射、接收组件应用电路图
英特尔在数据中心领域仍在挣扎,但情况可能会有所改善
招聘应用工程师
热力学计算大幅减少了AI-图像能耗
博通新款双频 Wi-Fi 8芯片BCM6714与BCM6719
2010英特尔杯大学生电子设计竞赛(7)
PMP方案比较
2010英特尔杯大学生电子设计竞赛(5)
CPU爆火,但服务器领域还有更大机会
2010英特尔杯大学生电子设计竞赛(6)
2010英特尔杯大学生电子设计竞赛(9)
物理AI蓄势待发,存储准备好了吗?
招聘硬件工程师
PLC抗干扰的软件措施