PC0接复位、PC1接时钟、PC2输出数据、PC3接D/C、PC5测试电压
$regfile = "m88def.dat"
$crystal = 1000000
'-------------------------------------------------------------------------------
Dc Alias Portc.3
Ddrc = &B111011111 : Portc = 0
'-------------------------------------------------------------------------------
Config Adc = Single , Prescaler = Auto , Reference = Internal
Config Spi = Soft , Din = Portc.6 , Dout = Portc.2 , Ss = None , Clock = Portc.1
Spiinit
'-------------------------------------------------------------------------------
Dim A As Byte , I As Word , X As Byte , Y As Byte , C As Byte
Dim Ac As Long , Zf As String * 4 , Gs As Byte , Zf1 As String * 1
'-------------------------------------------------------------------------------
Portc.0 = 0 : Waitms 10 : Portc.0 = 1 : Waitms 10
Do
'初始化3310LCD
Dc = 0
Restore Begin
Gosub Out_data : Gosub Out_data : Gosub Out_data : Gosub Out_data
'清屏,光标回位
Dc = 1
For I = 1 To 4032
A = 0 : Spiout A , 1
Next
Dc = 0
X = 128 : Gosub Out_x
Y = 64 : Gosub Out_y
'显示"电压"
Dc = 1
X = 128 : Y = 64
Restore Aa
For I = 1 To 32
Gosub Out_data : Gosub Out_data
Dc = 0
X = X + 1 : Gosub Out_x
Y = 64 : Gosub Out_y
Dc = 1
Next
'检测电压
Ac = Getadc(5)
Ac = Ac * 1100
Ac = Ac / 1023
'把电压数值转变为字符
Zf = Str(ac)
'求字符的个数
Gs = Len(zf)
'显示电压值的字符
For I = 1 To Gs
Zf1 = Mid(zf , I , 1)
Select Case Zf1
Case "0" : Restore A0
Case "1" : Restore A1
Case "2" : Restore A2
Case "3" : Restore A3
Case "4" : Restore A4
Case "5" : Restore A5
Case "6" : Restore A6
Case "7" : Restore A7
Case "8" : Restore A8
Case "9" : Restore A9
End Select
For C = 1 To 8
Gosub Out_data : Gosub Out_data
Dc = 0
X = X + 1 : Gosub Out_x
Gosub Out_y
Dc = 1
Next
Next
'显示单位"mV"
Dc = 1
Restore Ab
For I = 1 To 16
Gosub Out_data : Gosub Out_data
Dc = 0
X = X + 1 : Gosub Out_x
Gosub Out_y
Dc = 1
Next
Waitms 3000
Loop
End
'-------------------------------------------------------------------------------
Out_x:
Spiout X , 1
Return
'-------------------------------------------------------------------------------
Out_y:
Spiout Y , 1
Return
'-------------------------------------------------------------------------------
Out_data:
Read A : Spiout A , 1
Return
'*******************************************************************************
'----------------------------------初始化数据-----------------------------------
Begin:
Data &B00100001 , &B10010000 , &B00100010 , &B00001100
'-------------------------------------电压 -------------------------------------
Aa:
Data 0 , 0 , 0 , 0 , 248 , 15 , 72 , 4 , 72 , 4 , 72 , 4 , 72 , 4 , 255 , 63
Data 72 , 68 , 72 , 68 , 72 , 68 , 72 , 68 , 248 , 79 , 0 , 64 , 0 , 112 , 0 , 0
Data 0 , 32 , 0 , 24 , 254 , 39 , 2 , 32 , 66 , 32 , 66 , 32 , 66 , 32 , 66 , 32
Data 250 , 63 , 66 , 32 , 66 , 33 , 66 , 46 , 98 , 36 , 66 , 32 , 2 , 32 , 0 , 0
'--------------------------------------mV --------------------------------------
Ab:
Data 128 , 32 , 128 , 63 , 128 , 32 , 128 , 0 , 128 , 63 , 128 , 32 , 128 , 0 , 0 , 63
Data 8 , 0 , 120 , 0 , 136 , 7 , 0 , 56 , 0 , 14 , 200 , 1 , 56 , 0 , 8 , 0
'---------------------------------------0---------------------------------------
A0:
Data 0 , 0 , 224 , 15 , 16 , 16 , 8 , 32 , 8 , 32 , 16 , 16 , 224 , 15 , 0 , 0
'---------------------------------------1---------------------------------------
A1:
Data 0 , 0 , 16 , 32 , 16 , 32 , 248 , 63 , 0 , 32 , 0 , 32 , 0 , 0 , 0 , 0
'---------------------------------------2---------------------------------------
A2:
Data 0 , 0 , 112 , 48 , 8 , 40 , 8 , 36 , 8 , 34 , 136 , 33 , 112 , 48 , 0 , 0
'---------------------------------------3---------------------------------------
A3:
Data 0 , 0 , 48 , 24 , 8 , 32 , 136 , 32 , 136 , 32 , 72 , 17 , 48 , 14 , 0 , 0
'---------------------------------------4---------------------------------------
A4:
Data 0 , 0 , 0 , 7 , 192 , 4 , 32 , 36 , 16 , 36 , 248 , 63 , 0 , 36 , 0 , 0
'---------------------------------------5---------------------------------------
A5:
Data 0 , 0 , 248 , 25 , 8 , 33 , 136 , 32 , 136 , 32 , 8 , 17 , 8 , 14 , 0 , 0
'---------------------------------------6---------------------------------------
A6:
Data 0 , 0 , 224 , 15 , 16 , 17 , 136 , 32 , 136 , 32 , 24 , 17 , 0 , 14 , 0 , 0
'---------------------------------------7---------------------------------------
A7:
Data 0 , 0 , 56 , 0 , 8 , 0 , 8 , 63 , 200 , 0 , 56 , 0 , 8 , 0 , 0 , 0
'---------------------------------------8---------------------------------------
A8:
Data 0 , 0 , 112 , 28 , 136 , 34 , 8 , 33 , 8 , 33 , 136 , 34 , 112 , 28 , 0 , 0
'---------------------------------------9---------------------------------------
A9:
Data 0 , 0 , 224 , 0 , 16 , 49 , 8 , 34 , 8 , 34 , 16 , 17 , 224 , 15 , 0 , 0
|