源程序,fastavr还是快,就是资料太少,不好学啊!
'//////////////////////////////////////////////////////////////
$Device= m16 ' used device
$Stack = 125 ' stack depth
$Clock = 8 ' adjust for used crystal
$Timer1=Timer, Prescale=8
$Lcd =PORTD.4 , RS = PORTD.2 , EN = PORTD.3, 16, 2
$Key Rows=PORTB&h07
$Def TestPin0=PORTA.0
$Def TestPin1=PORTA.1
$Source= On
Declare Interrupt Ovf1()
Dim Testch(18) As Word
Dim akey As Byte ,achg As Byte,i As Byte,j As Byte,tempw As Word,temp As Byte
Dim tempy As Word
Testch(0)=500:Testch(1)=800:Testch(2)=500:Testch(3)=1000:Testch(4)=500:Testch(5)=1000
Testch(6)=500:Testch(7)=1000:Testch(8)=500:Testch(9)=1000:Testch(10)=500:Testch(11)=1000
Testch(12)=500:Testch(13)=1000:Testch(14)=500:Testch(15)=1000:Testch(16)=500
Testch(17)=7500
i=0:akey=0:achg=0
Set DDRA.0
Set DDRA.1
TestPin0=1:TestPin1=0
Start Timer1
Enable Ovf1
Enable Interrupts
InitLcd( )
Do
Cls '
WaitMs 5 '
Cursor Off
Locate 1, 1 ' '
Lcd "12345678" '
Locate 2 , 1
Lcd Testch(achg+achg+1)
Cursor On:Cursor blink
Locate 1,achg+1
'//////////////////////////////////////////
akey=Key():temp=achg+achg+1
If akey=1 Then
Incr achg
If achg=8 Then
achg=0
End If
End If
'/////////////////////////////////////////
If akey=2 Then
Testch(temp)=Testch(temp)+9
If Testch(temp)>1500 Then
Testch(temp)=1500
End If
End If
'/////////////////////////////////////////
If akey=4 Then
Testch(temp)=Testch(temp)-9
If Testch(temp)<500 Then
Testch(temp)=500
End If
End If
tempw=20000-500*9
For j=0 To 7
temp=j+j+1
tempw=tempw-Testch(temp)
Next
testch(17)=tempw
WaitMs 100
Loop
End
'//////////////////////////////////////////////////////////////
Interrupt Ovf1(), Save 4
Toggle Testpin0:Toggle TestPin1
tempy=65520-testch(i)
TCNT1H= Shift(Right,8,tempy)
TCNT1L=tempy
Incr i
If i=18 Then
i=0
End If
End Interrupt |