?? avr單片機_計算器程序.txt
字號:
'項目:4*4鍵盤1602液晶顯示的計算器
'結果:在proteus仿真運行成功
'時間:2007年8月22日 修正bug
'開發軟件:bascom-avr 11.8.5
'作者:あ邂逅記憶あ
'宜昌AVR單片機 http://ycavr.cn
$regfile = "m16def.dat"
$crystal = 8000000
Config Lcdpin = Pin , Db4 = Porta.4 , Db5 = Porta.5 , Db6 = Porta.6 , Db7 = Porta.7 , E = Porta.3 , Rs = Porta.2
Config Lcd = 16 * 2
Config Kbd = Portc
Cursor Off
Cls
Dim Key As Byte
Dim Oldkey As Byte
Dim Keyvalue As Byte '鍵盤值校正
Dim A As Long '第一個運算數據
Dim B As Long '第二個運算數據
Dim Operator As Byte : Operator = 0 '運算符標識 1為加2為減3為乘4為除
Dim Resault As Single '運算結果,單精度數。
Dim Error As Bit : Error = 0 '出錯標志位
Declare Sub Correct() '鍵盤值校正子程序
Declare Sub Account()
Declare Sub Keynum()
Do
Do
Oldkey = Getkbd()
Waitms 20
Do
Key = Getkbd()
Waitms 20
Loop Until Key <> 16
Loop Until Key <> Oldkey '取鍵盤值,直到鍵松開為止,防止按住不松,連續出現多個。
Correct '鍵盤值校正
Select Case Key '據校正后的鍵盤值作出相應動作
Case Is < 3
Keynum
Case 3
If B <> 0 Then Account
Operator = 4 '除運算
Case Is < 7
Keynum
Case 7
If B <> 0 Then Account
Operator = 3 '乘運算
Case Is < 11
Keynum
Case 11
If B <> 0 Then Account
Operator = 2 '減運算
Case 12
Cls
Key = 0
A = 0
B = 0
Operator = 0
Resault = 0
Case 13
Keynum
Case 14
Account
Operator = 0
Resault = 0
Case 15
If B <> 0 Then Account
Operator = 1 '加運算
End Select
Loop
End
Sub Correct()
Select Case Key
Case 0
Keyvalue = 7
Case 1
Keyvalue = 8
Case 2
Keyvalue = 9
Case 8
Keyvalue = 1
Case 9
Keyvalue = 2
Case 10
Keyvalue = 3
Case 13
Keyvalue = 0
Case Else
Keyvalue = Key
End Select
End Sub
Sub Account()
Select Case Operator
Case 1
Resault = A + B
Case 2
Resault = A - B
Case 3
Resault = A * B
Case 4
If B = 0 Then '除數為零,顯示錯誤!
Cls
Lcd "B=0"
Locate 2 , 4
Lcd "Error !"
Set Error '置出錯標志位
Else
Resault = A / B
End If
End Select
If Error = 0 Then
Cls
Lcd Resault
A = Resault
B = 0
Else
Wait 1
Cls
A = 0
B = 0
Operator = 0
Resault = 0
Reset Error '清出錯標志位
End If
End Sub
Sub Keynum()
Cls
If Operator = 0 Then
A = A * 10
A = A + Keyvalue
Lcd A
Else
B = B * 10
B = B + Keyvalue
Lcd B
End If
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -