'###########################################################################
' Data Aquisition System Master Card
'###########################################################################
$crystal = 14746000
$baud = 115200
$baud1 = 115200
Open "COM1:" For Binary As #1
Open "COM2:" For Binary As #2
Config Pind.0 = Output
Portd.0 = 1
Config Portd.1 = Output
Config Scl = Porte.6 ' IIC Serial Clock Line
Config Sda = Porte.7 ' IIC Serial Data line
Config Porta = Output
Config Portc = Input
Config Portg.0 = Output
Config Portg.1 = Output
Config Portg.2 = Output
Portg.0 = 1
Portg.1 = 1
Portg.2 = 1
Config Timer0 = Timer , Prescale = 64
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' IIC BUS Variables
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Dim Waddress As Byte , Raddress As Byte , M_add As Word , Count As Integer
Dim Flg As Bit , Rxbyte As Byte
Dim Ch0vlt As String * 6 , Ch1vlt As String * 6 , Ch2vlt As String * 6 , Ch3vlt As String * 6
Dim Ch4vlt As String * 6 , Ch5vlt As String * 6 , Ch6vlt As String * 6 , Ch7vlt As String * 6
Dim Ch8vlt As String * 6 , Ch9vlt As String * 6 , Ch10vlt As String * 6 , Ch11vlt As String * 6
Dim Ch12vlt As String * 6 , Ch13vlt As String * 6 , Ch14vlt As String * 6 , Ch15vlt As String * 6
Dim Chno As Byte , Cab As Byte , Smplno As Byte , Termin As Byte , Crdcnt As Byte
Declare Sub Aquire()
Declare Sub Getdata()
Declare Sub Smplbus()
Enable Interrupts
On Timer0 Tmr0isr
Crdcnt = Pinf And &H0F
Waitms 5
Termin = 0
Count = 0
Call Aquire
Do
If Count >= 10000 Then
Stop Timer0
Call Getdata
If Termin = 1 Then
Termin = 0
Count = 0
Call Aquire
End If
End If
Loop
Print #1 , "This is it"
End
Sub Aquire()
Enable Timer0
Load Timer0 , 73
Start Timer0
End Sub
Sub Getdata()
Local Pdd As Word
Local Pdat As Byte
Local Chadd As String * 2
Local Devid As Byte
Cab = 0
Do
Portd.1 = 1
Chadd = Lookupstr(cab , Scrdadd)
Portg.0 = 1
Portg.1 = 0
Ddrc = &H00
Portc = &HFF
Porta = Hexval(chadd)
If Pinc = Hexval(chadd) Then
For Smplno = 1 To 48
For Chno = 0 To 15
Call Smplbus
Next
Print #1 , Ch0vlt ; "," ; Ch1vlt ; "," ; Ch2vlt ; "," ; Ch3vlt ; "," ; Ch4vlt ; "," ; Ch5vlt ; "," ; Ch6vlt ; "," ; Ch7vlt ; ",";
Print #1 , Ch8vlt ; "," ; Ch9vlt ; "," ; Ch10vlt ; "," ; Ch11vlt ; "," ; Ch12vlt ; "," ; Ch13vlt ; "," ; Ch14vlt ; "," ; Ch15vlt
Print #2 , Ch0vlt ; "," ; Ch1vlt ; "," ; Ch2vlt ; "," ; Ch3vlt ; "," ; Ch4vlt ; "," ; Ch5vlt ; "," ; Ch6vlt ; "," ; Ch7vlt ; ",";
Print #2 , Ch8vlt ; "," ; Ch9vlt ; "," ; Ch10vlt ; "," ; Ch11vlt ; "," ; Ch12vlt ; "," ; Ch13vlt ; "," ; Ch14vlt ; "," ; Ch15vlt
Next
End If
Wait 1
Print #1 , "Card:" ; Cab ; " scan complete"
Cab = Cab + 1
Loop Until Cab = Crdcnt
Termin = 1
'Print #1 , "This is the end of Scan of 8 cards"
Portd.1 = 0
Waitms 25
End Sub
Sub Smplbus()
Local Volt As Single
Local Pdata As Word
Local Pdd As Word
Local Pl As Byte
Local Ph As Byte
Portg.0 = 0
Portg.1 = 0
Portg.2 = 1
Waitus 25
Pl = Pinc
Waitus 25
Portg.1 = 1
Waitus 25
Ph = Pinc
Waitus 25
Portg.2 = 0
Portg.1 = 1
Portg.0 = 1
Ddrc = &H00
Portc = &H00
Pdata = Makeint(pl , Ph)
Pdd = Pdata And 2048
If Pdd = 2048 Then
Pdata = Pdata - 1
Pdata = Pdata Xor &H0FFF
Volt = Pdata * 0.00244140625
Volt = Volt * -1
Else
Volt = Pdata * 0.00244140625
End If
Select Case Chno
Case Is = 0:
Ch0vlt = Fusing(Volt, "#.###")
Case Is = 1:
Ch1vlt = Fusing(volt , "#.###")
Case Is = 2:
Ch2vlt = Fusing(volt , "#.###")
Case Is = 3:
Ch3vlt = Fusing(volt , "#.###")
Case Is = 4:
Ch4vlt = Fusing(volt , "#.###")
Case Is = 5:
Ch5vlt = Fusing(volt , "#.###")
Case Is = 6:
Ch6vlt = Fusing(volt , "#.###")
Case Is = 7:
Ch7vlt = Fusing(volt , "#.###")
Case Is = 8:
Ch8vlt = Fusing(volt , "#.###")
Case Is = 9:
Ch9vlt = Fusing(volt , "#.###")
Case Is = 10:
Ch10vlt = Fusing(volt , "#.###")
Case Is = 11:
Ch11vlt = Fusing(volt , "#.###")
Case Is = 12:
Ch12vlt = Fusing(volt , "#.###")
Case Is = 13:
Ch13vlt = Fusing(volt , "#.###")
Case Is = 14:
Ch14vlt = Fusing(volt , "#.###")
Case Is = 15:
Ch15vlt = Fusing(volt , "#.###")
End Select
End Sub
Tmr0isr:
If Pind.0 = 0 Then
Set Portd.0
Else
Incr Count
Reset Portd.0
End If
Load Timer0 , 73
Return
Srl0isr:
Rxbyte = Udr
Return
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
' Data Tables
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Scrdadd:
Data "81" , "82" , "83" , "84" , "85" , "86" , "87" , "88"
Close #1
Close #2
|