📄 相位修正.bas
字号:
' 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -