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

Timer定时设置

1.设置Timer0的8位定时1ms,产生溢出中断(Fsys=8MHz)

  lda  #6
  sta  P_TMR0_Preload ;Set low byte initial value latter
  lda  P_TMR0_1_Ctrl1
  and  #$F0
  ora  #C_T0FCS_Div_32
  sta  P_TMR0_1_Ctrl1 ;Set Timer0 clock source is Fsys/32,Fsys(8MHz)/32/250= 1KHz(1ms)
  lda  P_TMR0_1_Ctrl0
  and  #$F0
  ora  #C_T08B_Timer
  sta  P_TMR0_1_Ctrl0 ;Set Timer0 is 8-bit timer
   
  set  P_INT_Flag1,CB_INT_T0OIF
     ;clear INT request flag
  set  P_INT_Ctrl1,CB_INT_T0OIE
     ;enable Timer0 overflow INT
  cli  ;enable INT

2. 设置Timer0的8位定时1ms,不产生溢出中断(Fsys=8MHz)

  lda  #6
  sta  P_TMR0_Preload ;Set low byte initial value latter
  lda  P_TMR0_1_Ctrl1
  and  #$F0
  ora  #C_T0FCS_Div_32
  sta  P_TMR0_1_Ctrl1 ;Set Timer0 clock source is Fsys/32,Fsys(8MHz)/32/250= 1KHz(1ms)
  lda  P_TMR0_1_Ctrl0
  and  #$F0
  ora  #C_T08B_Timer
  sta  P_TMR0_1_Ctrl0 ;Set Timer0 is 8-bit timer
   
  set  P_INT_Flag1,CB_INT_T0OIF
     ;clear INT request flag
  Loop:
  nop
  tst  P_INT_Flag1,CB_INT_T0OIF
  beq  Loop
  set  P_INT_Flag1,CB_INT_T0OIF

3. 设置Timer1的8位定时1ms,产生溢出中断(Fsys=8MHz)

  lda  #6
  sta  P_TMR1_Preload ;Set low byte initial value latter lda P_TMR0_1_Ctrl1
  and  #$0F
  ora  #C_T1FCS_Div_32
  sta  P_TMR0_1_Ctrl1 ;Set Timer1 clock source is Fsys/32,Fsys(8MHz)/32/250= 1KHz(1ms)
   
  lda  P_TMR0_1_Ctrl0
  and  #$0F
  ora  #C_T18B_Timer
  sta  P_TMR0_1_Ctrl0 ;Set Timer1 is 8-bit timer
   
  set  P_INT_Flag1,CB_INT_T1OIF
     ;clear INT request flag
  set  P_INT_Ctrl1,CB_INT_T1OIE
     ;enable Timer1 overflow INT
  cli  ;enable INT

4. 设置Timer1的8位定时1ms,不产生溢出中断(Fsys=8MHz)

  lda  #6
  sta  P_TMR1_Preload ;Set low byte initial value latter lda P_TMR0_1_Ctrl1
  and  #$0F
  ora  #C_T1FCS_Div_32
  sta  P_TMR0_1_Ctrl1 ;Set Timer1 clock source is Fsys/32,Fsys(8MHz)/32/250= 1KHz(1ms)
   
  lda  P_TMR0_1_Ctrl0
  and  #$F0
  ora  #C_T18B_Timer
  sta  P_TMR0_1_Ctrl0 ;Set Timer1 is 8-bit timer
  set  P_INT_Flag1,CB_INT_T1OIF
     ;clear INT request flag
  Loop:
  nop
  tst  P_INT_Flag1,CB_INT_T1OIF
  beq  Loop
  set  P_INT_Flag1,CB_INT_T1OIF

5. 设置Timer1的16位定时10ms,产生溢出中断(Fsys=8MHz)

  lda  #253
  sta  P_TMR1_PreloadHi ; Set high byte initial value first
  lda  #143
  sta  P_TMR1_Preload ;Set low byte initial value latter lda P_TMR0_1_Ctrl1
  and  #$0F
  ora  #C_T1FCS_Div_128 ; Set Timer1 clock source is Fsys/128
  sta  P_TMR0_1_Ctrl1
   
  lda  P_TMR0_1_Ctrl0
  and  #$0F
  ora  #C_T116B_Timer
  sta  P_TMR0_1_Ctrl0 ;Set Timer1 is 16-bit timer
   
  set  P_INT_Flag1,CB_INT_T1OIF
  set  P_INT_Ctrl1, CB_INT_T1OIE
     ;enable Timer1 overflow
  cli

6. 设置Timer1的16位定时10ms,不产生溢出中断(Fsys=8MHz)

  lda  #253
  sta  P_TMR1_PreloadHi ; Set high byte initial value first
  lda  #143
  sta  P_TMR1_Preload ;Set low byte initial value latter lda P_TMR0_1_Ctrl1
  and  #$0F
  ora  #C_T1FCS_Div_128 ; Set Timer1 clock source is Fsys/128
  sta  P_TMR0_1_Ctrl1
   
  lda  P_TMR0_1_Ctrl0
  and  #$0F
  ora  #C_T116B_Timer
  sta  P_TMR0_1_Ctrl0 ;Set Timer1 is 16-bit timer
   
  set  P_INT_Flag1,CB_INT_T1OIF

7. 设置Timer2的8位定时1ms,产生溢出中断(Fsys=8MHz)

  lda  #6
  sta  P_TMR2_Preload ;Set low byte initial value latter lda P_TMR2_3_Ctrl1
  and  #$F0
  ora  #C_T2FCS_Div_32
  sta  P_TMR2_3_Ctrl1 ;Set Timer2 clock source is Fsys/32,Fsys(8MHz)/32/250= 1KHz(1ms)
   
  lda  P_TMR2_3_Ctrl0
  and  #$F0
  ora  #C_T28B_Timer
  sta  P_TMR2_3_Ctrl0 ;Set Timer2 is 8-bit timer
   
  set  P_INT_Flag1,CB_INT_T2OIF
     ;clear INT request flag
  set  P_INT_Ctrl1,CB_INT_T2OIE
     ;enable Timer2 overflow INT
  cli  ;enable INT


8. 设置Timer2的8位定时1ms,不产生溢出中断(Fsys=8MHz)

  lda  #6
  sta  P_TMR2_Preload ;Set low byte initial value latter lda P_TMR2_3_Ctrl1
  and  #$F0
  ora  #C_T2FCS_Div_32
  sta  P_TMR2_3_Ctrl1 ;Set Timer2 clock source is Fsys/32,Fsys(8MHz)/32/250= 1KHz(1ms)
   
  lda  P_TMR2_3_Ctrl0
  and  #$F0
  ora  #C_T28B_Timer
  sta  P_TMR2_3_Ctrl0 ;Set Timer2 is 8-bit timer
 
  set  P_INT_Flag1,CB_INT_T2OIF
     ;clear INT request flag

9. 设置Timer3的8位定时1ms,产生溢出中断(Fsys=8MHz)

  lda  #6
  sta  P_TMR3_Preload ;Set low byte initial value latter lda P_TMR2_3_Ctrl1
  and  #$0F
  ora  #C_T3FCS_Div_32
  sta  P_TMR2_3_Ctrl1 ;Set Timer3 clock source is Fsys/32,Fsys(8MHz)/32/250= 1KHz(1ms)
   
  lda  P_TMR2_3_Ctrl0
  and  #$0F
  ora  #C_T38B_Timer
  sta  P_TMR2_3_Ctrl0 ;Set Timer3 is 8-bit timer
   
  set  P_INT_Flag1,CB_INT_T3OIF
     ;clear INT request flag
  set  P_INT_Ctrl1,CB_INT_T3OIE
     ;enable Timer3 overflow INT
  cli  ;enable INT

10. 设置Timer3的8位定时1ms,不产生溢出中断(Fsys=8MHz)

  lda  #6
  sta  P_TMR3_Preload ;Set low byte initial value latter lda P_TMR2_3_Ctrl1
  and  #$0F
  ora  #C_T3FCS_Div_32
  sta  P_TMR2_3_Ctrl1 ;Set Timer3 clock source is Fsys/32,Fsys(8MHz)/32/250= 1KHz(1ms)
   
  lda  P_TMR2_3_Ctrl0
  and  #$0F
  ora  #C_T38B_Timer
  sta  P_TMR2_3_Ctrl0 ;Set Timer3 is 8-bit timer
   
  set  P_INT_Flag1,CB_INT_T3OIF
     ;clear INT request flag

11. 设置Timer3的16位定时1ms,产生溢出中断(Fsys=8MHz)

  lda  #253
  sta  P_TMR3_PreloadHi ; Set high byte initial value first
  lda  #143
  sta  P_TMR3_Preload ;Set low byte initial value latter lda P_TMR2_3_Ctrl1
  and  #$0F
  ora  #C_T3FCS_Div_128 ; Set Timer3 clock source is Fsys/128
  sta  P_TMR2_3_Ctrl1
   
  lda  P_TMR2_3_Ctrl0
  and  #$0F
  ora  # C_T316B_Timer
  sta  P_TMR2_3_Ctrl0 ;Set Timer3 is 16-bit timer
   
  set  P_INT_Flag1,CB_INT_T3OIF
  set  P_INT_Ctrl1,CB_INT_T3OIE
     ;enable Timer3 overflow
  cli

12. 设置Timer3的16位定时1ms,不产生溢出中断(Fsys=8MHz)

  lda  #253
  sta  P_TMR3_PreloadHi ; Set high byte initial value first
  lda  #143
  sta  P_TMR3_Preload ;Set low byte initial value latter lda P_TMR2_3_Ctrl1
  and  #$0F
  ora  #C_T3FCS_Div_128 ; Set Timer3 clock source is Fsys/128
  sta  P_TMR2_3_Ctrl1
   
  lda  P_TMR2_3_Ctrl0
  and  #$0F
  ora  #C_T316B_Timer
  sta  P_TMR2_3_Ctrl0 ;Set Timer3 is 16-bit timer
   
  set  P_INT_Flag1,CB_INT_T3OIF

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