相位修正.bas

来自「1602的流水灯等程序 用BASCOM-AVR语言 ATmega16平台」· BAS 代码 · 共 69 行

BAS
69
字号
          ' 1602为什么不能显示,相位修正模式下为什么不中断


 $regfile = "m16def.dat"
   $crystal = 8000000
   '======================================
   '配置1602LCD
   Config Lcdpin = Pin , Db4 = Portb.0 , Db5 = Portb.1 , Db6 = Portb.2 , Db7 = Portb.3 , E = Portb.4 , Rs = Portb.5
Config Lcd = 16 * 2
    Cursor Off                                              '光标关闭
    Cls                                                     '清屏LCD
   '======================================
   '*************************************
   '定时器1为匹配输出
   Config Timer1 = Timer , Prescale = 8 , Compare A = Toggle , Clear Timer = 0
   'Compare1a = 65000
   '定义匹配输出为相位修正模式
   Reset Tccr1a.0
   Reset Tccr1a.1
   Set Tccr1b.4
   Reset Tccr1b.3
    Enable Interrupts
   Enable Compare1a
   On Compare1a Compare1a_irs

   '定义TOP
   Dim Pwm_t As Word                                        'PWM_T为脉冲周期
   Dim Pwm_p As Byte                                        'Pwm_p为脉冲占空比
   Dim B As Long
   Pwm_t = 2000                                             '周期为1000us
   Pwm_p = 50                                               '占空比为50%
  B = Pwm_t \ 2                                             '输入ICR1(TOP)值
   Capture1 = B
   Locate 1 , 1
   Lcd B
   Wait 7


   B = Pwm_t \ 200
   B = B * Pwm_p
  B = Capture1 - b
  Compare1a = B
    Locate 1 , 1
   Lcd B
   Wait 7
  Ddrd = &H30

   '************************************


  ' Enable Interrupts
 '  Enable Compare1a
 '  On Compare1a Compare1a_irs

    B = &H0

   Do

   Loop

   End


   Compare1a_irs:
     Locate 1 , 1
     B = B + 1
      Lcd B
      Waitms 10
      Return

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?