pwm(灯亮度).c
来自「此程序为Freescale程序」· C语言 代码 · 共 53 行
C
53 行
/***************************************************************************
功能:PWM
作者:唐小进
时间:08.2.11
现象:改变PWMDTY4,灯的亮度会改变
***************************************************************************/
#include <hidef.h> /* common defines and macros */
#include <mc9s12dg128.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"
void delay(int m){
int i,j;
for(i=0;i<500;i++)
for(j=0;j<m;j++){
}
}
void Pwm4_init(void){
PWME_PWME4=0; /*关断PWM*/
PWMCLK_PCLK4=1; /*时钟源位SA*/
PWMPRCLK_PCKA=1; /*A/128*/
PWMSCLA=0XFF; /*A为256*/
PWMPOL_PPOL4=1; /*开始为高电平,相等时为低电平*/
PWMCAE_CAE4=0; /*左对齐*/
PWMPER4=0XFF; /*周期*/
PWMDTY4=0; /*占空比为0*/
PWME_PWME4=1; /*开启PWM*/
}
/*void Shutdown_init(void){
DDRP_DDRP7=0;
PTP_PTP7=0;
PWMSDN=0x03;
} */
void main (void){
//int i;
DDRA=0XFF;
PORTA=0X00;
Pwm4_init();
while(1){
/*for(i=40;i>=0;i--){
if(PTP_PTP4==0)
PORTA=0X77;
else
PORTA=0X00;
delay(800);
}*/
PWMDTY4=20;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?