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

比较输出设置

1.设置Timer08位比较输出(PB2)10Khz、产生中断   

 lda   #156      
  sta   P_TMR0_Preload   ;set Timer0 counter initial value
 
  lda   P_TMR0_1_Ctrl1
  and #$F0
  ora   #C_T0FCS_Div_8   
  sta   P_TMR0_1_Ctrl1   ;Set Timer0 clock source is Fsys/8
 
  lda   P_TMR0_1_Ctrl0
  and #$F0
  ora   #C_T08B_COMP   
  sta   P_TMR0_1_Ctrl0   ;Set Timer0 is 8-bit compare output
 
  set   P_INT_Flag1,CB_INT_T0OIF
              ;clear compare INT flag
  set   P_INT_Ctrl1,CB_INT_T0OIE
              ;compare INT enable
  cli

2.设置Timer08位比较输出(PB2):10Khz、不产生中断

 lda   #156      
  sta   P_TMR0_Preload   ;set Timer0 counter initial value
 
  lda   P_TMR0_1_Ctrl1
  and #$F0
  ora   #C_T0FCS_Div_8   
  sta   P_TMR0_1_Ctrl1   ;Set Timer0 clock source is Fsys/8
 
  lda   P_TMR0_1_Ctrl0
  and #$F0
  ora   #C_T08B_COMP   
sta   P_TMR0_1_Ctrl0   ;Set Timer0 is 8-bit compare output

3.设置Timer18位比较输出(PB3):10Khz、产生中断  

 lda   #156       ;
  sta   P_TMR1_Preload   ; Set Timer1 low byte counter initial 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_T18B_COMP
  sta   P_TMR0_1_Ctrl0   ; Set Timer1 is 8-bit compare output
 
  set   P_INT_Flag1,CB_INT_T1OIF
              ;clear compare INT flag
  set   P_INT_Ctrl1,CB_INT_T1OIE
              ;compare INT enable
  cli

4.设置Timer18位比较输出(PB3):10Khz、不产生中断    

 lda   #156       ;
  sta   P_TMR1_Preload   ; Set Timer1 low byte counter initial value
 
  lda   P_TMR0_1_Ctrl1
  and   #$0F
  ora   #C_T1FCS_Div_8
  sta   P_TMR0_1_Ctrl1   ; Set Timer1 clock source is Fsys/128
 
  lda   P_TMR0_1_Ctrl0
  and   #$0F
  ora   #C_T18B_COMP
  sta   P_TMR0_1_Ctrl0   ; Set Timer1 is 8-bit compare output

5.设置Timer116位比较输出(PB3)100hz、产生中断

 lda   #$D8       ;
  sta   P_TMR1_PreloadHi   ; Set Timer1 high byte counter initial value
  lda   #$F0       ;
  sta   P_TMR1_Preload   ; Set Timer1 low byte counter initial 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_T116B_COMP
  sta   P_TMR0_1_Ctrl0   ; Set Timer1 is 16-bit compare output
 
  set   P_INT_Flag1,CB_INT_T1OIF
              ;clear compare INT flag
  set   P_INT_Ctrl1,CB_INT_T1OIE
              ;compare INT enable
  cli

6.设置Timer116位比较输出(PB3):10Khz、不产生中断 

 lda   #$D8       ;
  sta   P_TMR1_PreloadHi   ; Set Timer1 high byte counter initial value
  lda   #$F0       ;
  sta   P_TMR1_Preload   ; Set Timer1 low byte counter initial 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_T116B_COMP
  sta   P_TMR0_1_Ctrl0   ; Set Timer1 is 16-bit compare output
 
  set   P_INT_Flag1,CB_INT_T1OIF
              ;clear compare INT flag

7.设置Timer28位比较输出(PD3):10Khz、产生中断   

 lda   #156      
  sta   P_TMR2_Preload   ;set Timer2 counter initial value
 
  lda   P_TMR2_3_Ctrl1
  and #$F0
  ora   #C_T2FCS_Div_8   
  sta   P_TMR2_3_Ctrl1   ;Set Timer2 clock source is Fsys/8
 
  lda   P_TMR2_3_Ctrl0
  and #$F0
  ora   #C_T28B_COMP   
  sta   P_TMR2_3_Ctrl0   ;Set Timer2 is 8-bit compare output
 
  set   P_INT_Flag1,CB_INT_T2OIF
              ;clear compare INT flag
  set   P_INT_Ctrl1,CB_INT_T2OIE
              ;compare INT enable
  cli

 

8.设置Timer28位比较输出(PD2):10Khz、不产生中断  

 lda   #156      
  sta   P_TMR2_Preload   ;set Timer2 counter initial value
 
  lda   P_TMR2_3_Ctrl1
  and #$F0
  ora   #C_T2FCS_Div_8   
  sta   P_TMR2_3_Ctrl1   ;Set Timer2 clock source is Fsys/8
 
  lda   P_TMR2_3_Ctrl0
  and #$F0
  ora   #C_T28B_COMP   
  sta   P_TMR2_3_Ctrl0   ;Set Timer2 is 8-bit compare output
 
  set   P_INT_Flag1,CB_INT_T2OIF
              ;clear compare INT flag

9.设置Timer3的8位比较输出(PD2):10Kz、产生中断    

 lda   #156       ;
  sta   P_TMR3_Preload   ; Set Timer3 low byte counter initial 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_T38B_COMP
  sta   P_TMR2_3_Ctrl0   ; Set Timer3 is 8-bit compare output
 
  set   P_INT_Flag1,CB_INT_T3OIF
              ;clear compare INT flag
  set   P_INT_Ctrl1,CB_INT_T3OIE
              ;compare INT enable
  cli

10.设置Timer3的8位比较输出(PD2):10Khz、不产生中断  

 lda   #156       ;
  sta   P_TMR3_Preload   ; Set Timer3 low byte counter initial 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_T38B_COMP
  sta   P_TMR2_3_Ctrl0   ; Set Timer3 is 8-bit compare output
 
  set   P_INT_Flag1,CB_INT_T3OIF
             ;clear compare INT flag

11.设置Timer3的16位比较输出(PD2):100hz、产生中断 

 lda   #$D8       ;
  sta   P_TMR3_PreloadHi   ; Set Timer3 high byte counter initial value
  lda   #$F0       ;
  sta   P_TMR3_Preload   ; Set Timer3 low byte counter initial 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_T316B_COMP
  sta   P_TMR2_3_Ctrl0   ; Set Timer3 is 16-bit compare output
 
  set   P_INT_Flag1,CB_INT_T3OIF
              ;clear compare INT flag
  set   P_INT_Ctrl1,CB_INT_T3OIE
              ;compare INT enable
  cli

12.设置Timer316位比较输出(PD2):100hz、不产生中断 

 lda   #$D8       ;
  sta   P_TMR3_PreloadHi   ; Set Timer3 high byte counter initial value
  lda   #$F0       ;
  sta   P_TMR3_Preload   ; Set Timer3 low byte counter initial 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_T316B_COMP
  sta   P_TMR2_3_Ctrl0   ; Set Timer3 is 16-bit compare output
 
  set   P_INT_Flag1,CB_INT_T3OIF
              ;clear compare INT flag

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