- 阅读权限
- 150
- UID
- 7
- 帖子
- 140
- 精华
- 0
- 注册时间
- 2013-2-26
- 在线时间
- 20 小时
- UID
- 7
- 帖子
- 140
- 精华
- 0
- 注册时间
- 2013-2-26
- 在线时间
- 20 小时
|
'******************************************'
'* 通用风机控制器12版BASCOM-AVR程序 *'
'******************************************'
'* 文件名称:fjcx12-1.bas *'
'* 处 理 器:ATmega-16L *'
'* 原 理 图:TYFJKZ12.SCH *'
'* 日 期:2006年10月4日 *'
'* 版 本:V12.01 *'
'* 作 者:铜河 *'
'******************************************'
$regfile = "m16def.dat" '设定工作CPU型号
$crystal = 2000000 '设定使用内部2M振荡器
Config Portc = Output '设置C口为输出
Config Portb = Output '设置B口为输出
Ddra = &B00100000 '设置A口的第5位为输出,其余为输入
Porta = &B00011111 '将键盘输入接口上拉
Ddrd = &B10110000 '设置D口的第7/5/4位为输出,其余为输入
Portd = &B01001111 '将键盘输入接口上拉
Dim A1 As Byte , A2 As Byte , A3 As Byte , A4 As Byte , A5 As Word , A6 As Word , A7 As Word '工作数据定义
Dim C(16) As Byte '数组定义
Dim E As Byte , S0 As Byte , S1 As Byte , S2 As Byte , S3 As Byte , D As Byte , F As Byte
Dim K1 As Byte , K2 As Byte , K3 As Byte , K4 As Byte , K5 As Byte , K As Byte , Js As Byte
Dim Taozhen_bz As Bit , Sansuo_bz As Bit
Config Timer0 = Timer , Prescale = 32 '定时器0设定为预分频256
Config Timer2 = Timer , Async = Off , Prescale = 1024
Config Watchdog = 2048
On Ovf2 Tim2_isr
On Ovf0 Tim0_isr '定时器0中断入口地址
Enable Timer0 '允许定时器0中断
Enable Timer2
Start Timer0 '开启定时器0
Start Timer2
Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Down , Prescale = 1
Enable Interrupts '允许全局中断
Key1 Alias Pind.3 '定义按键别称
Key2 Alias Pind.2
Key3 Alias Pind.0
Key4 Alias Pina.3
Key5 Alias Pina.1
Led1 Alias Portc.3
Led2 Alias Portc.2
Djkz Alias Portd.7
Zscl Alias Pind.6
Spk Alias Porta.5
A2 = 0
Restore Daima
For D = 1 To 16
Read C(d)
Next D
Readeeprom A1 , 1
Readeeprom A2 , 2
Readeeprom A3 , 3
Readeeprom A4 , 4
Readeeprom A5 , 5
S0 = C(a1)
S1 = C(a2)
S2 = C(a3)
S3 = C(a4)
Gosub Pwm_js
Pwm1a = A7 '先将上次关机前的数据送PWM
Waitms 2000
Set Djkz '延时500MS开风机电源
Start Watchdog
E = 0
F = 0
Reset Taozhen_bz
Reset Led1
Set Led2
Js = 0
D = 2 '1
Begin:
Do
If Taozhen_bz = 0 Then '如果调整标志为0
Bitwait Key1 , Reset '等待设定键按下
Waitms 20 '延时消抖
Bitwait Key1 , Reset '再次判别
Gosub Spk_ds
Set Taozhen_bz '调整标志置1
Set Led1 '调整灯亮,工作灯灭
Reset Led2
Bitwait Key1 , Set '等待按键释放
Waitms 20
Bitwait Key1 , Set '确定按键释放
Else
Gosub Rd_key
If K <> 0 Then
K3 = K
Waitms 20
Gosub Rd_key
If K = K3 Then
Gosub Spk_ds
Select Case K
Case 1 'S3键处理
If A2 = 1 Then
D = 2
Else
D = D + 1
If D >= 4 Then D = 4
End If
Case 4 'S2键处理
If A2 = 1 Then
D = 2
Else
If D >= 4 Then D = 4
D = D - 1
If D = 1 Then D = 2
End If
Case 8 'S1键处理
Reset Taozhen_bz '清除调整标志,返回工作状态
Reset Led1 '关闭设定灯,开工作灯
Set Led2
Gosub Pwm_js
Pwm1a = A7
Writeeeprom A1 , 1 '数据存入EEPROM
Writeeeprom A2 , 2
Writeeeprom A3 , 3
Writeeeprom A4 , 4
Writeeeprom A5 , 5
Case 32 'S5键处理,数字加1
Select Case D
Case 1
Incr A1
If A1 >= 11 Then A1 = 1
Case 2
' Incr A2
If A2 = 1 Then
A2 = 10
A3 = 2
A4 = 5
Else
A2 = 1
A3 = 10
A4 = 10
End If
Case 3
Incr A3
If A3 >= 10 Then
A3 = 2
A4 = 5
End If
Case 4
Incr A4
If A3 = 2 Then
If A4 >= 10 Then A4 = 5
Else
If A4 >= 11 Then A4 = 1
End If
End Select
Case 128 'S4键处理,数字减1
Select Case D
Case 1
If A1 >= 11 Then A1 = 9
A1 = A1 - 1
If A1 = 0 Then A1 = 10
Case 2
If A2 = 1 Then
A2 = 10
A3 = 2
A4 = 5
Else
A2 = 1
A3 = 10
A4 = 10
End If
Case 3
If A3 >= 11 Then A3 = 9
A3 = A3 - 1
If A3 = 1 Then A3 = 9
If A3 = 2 Then A4 = 5
Case 4
If A4 >= 11 Then A4 = 9
A4 = A4 - 1
If A3 = 2 Then
If A4 <= 4 Then A4 = 9
Else
If A4 = 0 Then A4 = 10
End If
End Select
End Select
S0 = C(a1)
S1 = C(a2)
S2 = C(a3)
S3 = C(a4)
' Gosub Pwm_js
While K = K3 '等待按键释放
Gosub Rd_key
Wend
' Pwm1a = A7
End If
End If
End If
Loop
Spk_ds: '喇叭发短声
Set Spk
Waitms 100
Reset Spk
Return
Pwm_js:
If A2 = 1 Then '计算PWM值
A7 = &HFF
Else
A5 = A4
If A5 = 10 Then A5 = 0
A5 = A5 * 17
A5 = A5 \ 10
A6 = A3
If A6 = 10 Then A6 = 0
A6 = A6 * 17
A6 = A6 \ 10
Shift A6 , Left , 4
A7 = A6 Or A5
End If
Return
Rd_key: '读键子程序
K1 = Pind Or &B11110000 '读入D口数据
K1 = Not K1
K2 = Pina Or &B11110000
K2 = Not K2
Shift K2 , Left , 4
K = K1 Or K2
Return
Tim0_isr: 'LED数码管扫描显示
Load Timer0 , 125 '定时器初值
Reset Portc.4
Reset Portc.5
Reset Portc.6
Reset Portc.7
Select Case E
Case 0
Portb = S0 ': Set Portc.4
Case 1
Portb = S1
If Taozhen_bz = 1 Then
Set Portc.5
Else
If A2 = 10 Then
Reset Portc.5
Else
Set Portc.5
End If
End If
Case 2
Portb = S2 : Set Portc.6
Case 3
Portb = S3 : Set Portc.7
End Select
E = E + 1
If E = 4 Then E = 0
Incr F
If F = 125 Then
F = 0
Led1 = Not Led1
End If
' End If
Reset Watchdog
Return
Tim2_isr: '闪烁控制
Load Timer2 , 100
If Js >= 5 Then
Js = 0
If Taozhen_bz = 1 Then
Sansuo_bz = Not Sansuo_bz '如果调整标志为1,闪烁标志取反
If Sansuo_bz = 1 Then
Select Case D
Case 1
S0 = &HFF
Case 2
S1 = &HFF
Case 3
S2 = &HFF
Case 4
S3 = &HFF
End Select
Else
Select Case D
Case 1
S0 = C(a1)
Case 2
S1 = C(a2)
Case 3
S2 = C(a3)
Case 4
S3 = C(a4)
End Select
End If
Else
Reset Sansuo_bz '否则闪烁标志清0
End If
Else
Incr Js
End If
Return
Daima:
Data &HF9 , &HA4 , &HB0 , &H99 , &H92 , &H82 , &HF8 , &H80
Data &H90 , &HC0 , &H88 , &H83 , &HC6 , &HA1 , &H86 , &H8E |
|