📄 lcd+led.bas
字号:
$regfile = "m16def.dat" ' 定义目标单片机是ATmega16
$crystal = 8000000 ' 定义单片机时钟周期是8000000Hz
$baud = 9600
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
Dim S As String * 16
Enable Interrupts
Config Timer1 = Timer , Prescale = 8
Enable Timer1
On Timer1 Key_isr
Config Pind.2 = Input
Config Pind.3 = Input
Portd.2 = 1
Portd.3 = 1
Porta = &HFF
Ddra = &HFF
Dim A As Byte , G As Byte , T As Integer
A = 0
G = 1
Dim Key1 As Bit , Key2 As Bit
Cls
S = "Ready? go!"
Waitms 10
Lcd S
Do
Porta = &HFF
Waitms 50
Porta = Not Porta
Waitms 50
Loop Until Pind.2 = 0
Cls
S = "*speedis:fastest"
Waitms 10
Lcd S
Locate 2 , 1
S = "*style is:"
Waitms 10
Lcd S
Start Timer1
Star:
Do
If A <= 4 Then
On A Gosub Huayang0 , Huayang1 , Huayang2 , Huayang3 , Huayang4
Else
A = 0
Goto Star
End If
Loop
End
Key_isr:
Key1 = Pind.2
Key2 = Pind.3
If Key1 = 0 Then
Incr A
End If
If Key2 = 0 Then
G = G + 1
Select Case G
Case 2 : S = "faster "
Case 3 : S = "normal "
Case 4 : S = "slower "
Case 5 : S = "slowest"
Case Else : S = "fastest"
End Select
Locate 1 , 10
Waitms 5
Lcd S
End If
If G <= 5 Then
T = G * 20
Else
G = 1
End If
Return
Huayang0:
S = "one "
Delay
Locate 2 , 11
Lcd S
Porta = &HFE
Waitms T
Porta = &HFD
Waitms T
Porta = &HFB
Waitms T
Porta = &HF7
Waitms T
Porta = &HEF
Waitms T
Porta = &HDF
Waitms T
Porta = &HBF
Waitms T
Porta = &H7F
Waitms T
Return
Huayang1:
S = "two "
Delay
Locate 2 , 11
Lcd S
Porta = &B00111111
Waitms T
Porta = &B11001111
Waitms T
Porta = &B11110011
Waitms T
Porta = &B11111100
Waitms T
Return
Huayang2:
S = "three"
Delay
Locate 2 , 11
Lcd S
Porta = &B00011111
Waitms T
Porta = &B11000111
Waitms T
Porta = &B11111000
Waitms T
Return
Huayang3:
S = "four "
Delay
Locate 2 , 11
Lcd S
Porta = &B01111110
Waitms T
Porta = &B10111101
Waitms T
Porta = &B11011011
Waitms T
Porta = &B11100111
Waitms T
Porta = &B11011011
Waitms T
Porta = &B10111101
Waitms T
Return
Huayang4:
S = "five "
Delay
Locate 2 , 11
Lcd S
Porta = &B10101010
Waitms T
Porta = Not Porta
Waitms T
Return
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -