📄 pwm(灯亮度).c
字号:
/***************************************************************************
功能: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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -