logo
 
首页-> 产品信息-> 8位单片机
 
入门指南
开发&工具
应用方案
客户支持
 
快速编程
一、IO口设置 二、AD设置 三、Timer定时设置 四、捕获设置
五、比较输出设置 六、PWM比较输出设置 七、时基设置 八、外部中断的设置
九、SPI的设置 十、UART的设置 十一、LVR的设置 十二、看门狗的设置
十三、STOP模式的设置 十四、HALT的设置    
警告:由于格式的原因,直接从网页上复制程序,粘贴到编译环境里面,编译时会出错。敬请直接下载word档,从word里面直接复制到编译环境里面即可。 ( word原文件下载)

PWM比较输出设置

1. 设置Timer112PWM输出(PB3),周期4ms,占空比25%,产生中断   

 lda   #$C0
  sta   P_TMR1_DutyPeriod ;set duty and period initial value first Set duty value
  lda   #$00
  sta   P_TMR1_PWMPeriod ;Set Period value
  lda   #$18
  sta   P_TMR1_PWMDuty   ;set duty value
 
  lda   P_TMR0_1_Ctrl1
  and   #$0F
  ora   #C_T1FCS_Div_8   
  sta   P_TMR0_1_Ctrl1   ;Set Timer1 clock source is Fsys/8
 
  lda   P_TMR0_1_Ctrl0
  and   #$0F
  ora   #C_T112B_PWM   
  sta   P_TMR0_1_Ctrl0   ;Set Timer1 is 12-bit PWM
 
  set   P_INT_Flag1, CB_INT_T1OIF
  set   P_INT_Ctrl1, CB_INT_T1OIE
 
  cli

2.设置Timer112PWM输出(PB3),周期4ms,占空比25%,不产生中断 

 lda   #$70
 sta   P_TMR1_DutyPeriod ;set duty and period initial value first Set duty value
 lda   #$00
 sta   P_TMR1_PWMPeriod ;Set Period value
 lda   #$FF
 sta   P_TMR1_PWMDuty   ;set duty value
 
 lda   P_TMR0_1_Ctrl1
 and   #$0F
 ora   #C_T1FCS_Div_8   
 sta   P_TMR0_1_Ctrl1   ;Set Timer1 clock source is Fsys/8
 
 lda   P_TMR0_1_Ctrl0
 and   #$0F
 ora   #C_T112B_PWM   
 sta   P_TMR0_1_Ctrl0   ;Set Timer1 is 12-bit PWM

3.设置Timer312PWM输出(PD2),周期4ms,占空比25%,产生中断 

 lda   #$C0
 sta   P_TMR3_DutyPeriod ;set duty and period initial value first Set duty value
 lda   #$00
 sta   P_TMR3_PWMPeriod ;Set Period value
 lda   #$18
 sta   P_TMR3_PWMDuty   ;set duty value
 
 lda   P_TMR2_3_Ctrl1
 and   #$0F
 ora   #C_T3FCS_Div_8   
 sta   P_TMR2_3_Ctrl1   ;Set Timer3 clock source is Fsys/8
 
 lda   P_TMR2_3_Ctrl0
 and   #$0F
 ora   #C_T312B_PWM   
 sta   P_TMR2_3_Ctrl0   ;Set Timer3 is 12-bit PWM
 
 set   P_INT_Flag1,CB_INT_T3OIF
 set   P_INT_Ctrl1,CB_INT_T3OIE
 
 cli

4.设置Timer312PWM输出(PD2),周期4ms,占空比25%,不产生中断 

 lda   #$C0
  sta   P_TMR3_DutyPeriod ;set duty and period initial value first Set duty value
  lda   #$00
  sta   P_TMR3_PWMPeriod ;Set Period value
  lda   #$18
  sta   P_TMR3_PWMDuty   ;set duty value
 
  lda   P_TMR2_3_Ctrl1
  and   #$0F
  ora   #C_T3FCS_Div_8   
  sta   P_TMR2_3_Ctrl1   ;Set Timer3 clock source is Fsys/8
 
  lda   P_TMR2_3_Ctrl0
  and   #$0F
  ora   #C_T312B_PWM   
  sta   P_TMR2_3_Ctrl0   ;Set Timer3 is 12-bit PWM
 
  set   P_INT_Flag1,CB_INT_T3OIF

版权所有:北京凌阳爱普科技有限公司 京ICP备05061966号 未经许可网站内容严禁复制、转载,任何人不得擅自使用
友情链接:凌阳爱普 嵌入式培训 安卓培训 凌阳大学计划 北京嵌入式培训 深圳嵌入式培训 成都嵌入式培训