| |
'********************************************************************
'********************************************************************
'Description: DS-GPM controlled by an OOPicII microcontroller connected
to a
'DS-LCDD2 Serial/IIC LCD. This application demonstrates reading of internal
registers
'and displaying results on an LCD screen.
'Created: 10/11/02 Revision: 1.0
'Version: B.1.0 Written By: Total Robots (Jamie Finnan)
'Adapted from: Designer Systems Original Code
'
'TR-020
'
'********************************************************************
'********************************************************************
Dim GPM As New oi2c
Dim LCD As New oLCDSE 'LCD object
Dim RTS As New oDio1
Dim Hours As New oByte 'Hours storage register
Dim Minutes As New oByte 'Minutes storage register
Dim Seconds As New oByte 'Seconds storage register
Dim Day As New oByte 'Day storage register
Dim Month As New oByte 'Month storage register
Dim Year As New oWord 'Year storage register
Dim Heading As New oWord 'Heading storage register (1 degree accuracy)
Dim Speed As New oWord 'Speed storage register (1 kmh accuracy)
Dim Latitude As New oWord 'Latitude storage register (1 degree accuracy)
Dim Longitude As New oWord 'Longitude storage register (1 degree accuracy)
Dim Count As New oByte
'********************************************************************
Sub Main()
oopic.delay = 400 'Wait 4 seconds for GPM to initialise
Const GPMAdr = &h68 'GPM A0 & A1 jumpers ON (Range &h68-&h6B)
LCD.IOLine = 12 'LCD is on IOLine 12 (Pin 12)
LCD.Clear 'Clear LCD screen
LCD.String=" GPM & DS-LCDD2 " 'Write to LCD screen.
LCD.Value=254 'Send command value to LCD.
LCD.Value=192 'Set second line value on LCD.
LCD.String="Example Application." 'Write to LCD screen.
oopic.delay = 200 '2 second delay.
LCD.Clear 'Clear the screen.
RTS.IOline = 24
RTS.Direction = cvOutput 'Ensure RTS line is high (ready for communication)
RTS = cvOff
Call SetUpGPM 'Setup GPM ready for information retrieval
do
'********************************************************************
' Stores time, date, heading and speed in registers defined above
'********************************************************************
count = 0
call StoreGPTD 'Store time and date
call StoreGPHS 'Store heading and speed
call StoreGPLL 'Store longitude and latitude
'********************************************************************
' Send time, date, heading & speed to LCD as displayable output
'********************************************************************
While count<3 'Loop constuct to show second count
GPM.Location = 0 'Point to R0
LCD.String = "Time = "+chr$(GPM+48)+chr$(GPM+48)+":
"+chr$(GPM+48)+chr$(GPM+48)+":"+chr$(GPM+48)+chr$(GPM+48)
LCD.Value = 254 'Command value
LCD.Value = 192 'Move to second line
LCD.String = "Date = "+chr$(GPM+48)+chr$(GPM+48)+"/"+chr$(GPM+48)+chr$(GPM+48)+"/
"+chr$(GPM+48)+chr$(GPM+48)+chr$(GPM+48)+chr$(GPM+48)
OOPic.Delay = 70 Small delay
count = count+1 'Increment file by 1 until count = 3
LCD.Clear 'Clear LCD
Wend 'End while statement
LCD.Clear 'Clear LCD
GPM.Location = 46 'Point to R46
LCD.String = "Heading = "+chr$(GPM+48)+chr$(GPM+48)+chr$(GPM+48)+".
"+chr$(GPM+48)+"deg"
LCD.Value = 254
LCD.Value = 192
LCD.String = "Speed = "+chr$(GPM+48)+chr$(GPM+48)+chr$(GPM+48)+".
"+chr$(GPM+48)+"kmh"
oopic.delay = 300 'Wait 3 seconds
LCD.Clear
GPM.Location = 14 'Point to R46
LCD.String = "Latitude = "+chr$(GPM+48)+chr$(GPM+48)+chr$(GPM+48)+".
"+chr$(GPM+48)+"deg"'+chr$(&h0d)+chr$(&h0a)
LCD.Value = 254
LCD.Value = 192
LCD.String = "Longitude= "+chr$(GPM+48)+chr$(GPM+48)+chr$(GPM+48)+"
."+chr$(GPM+48)+"deg"'+chr$(&h0d)+chr$(&h0a)+chr$(&h0a)
OOPic.delay = 300
LCD.Clear
loop
End Sub
'********************************************************************
' Subroutine to setup I2C communication to DS-GPM
'********************************************************************
Sub SetUpGPM()
'********************************************************************
'Set the DS-GPM I2C address shifted right by 1 bit
'********************************************************************
GPM.Node = GPMAdr 'Setup I2C address for GPM
'********************************************************************
'Setup I2C addressing to GPM
'********************************************************************
GPM.Width = cv8bit 'Control Info is 1-byte
GPM.Mode = cv10bit 'I2C mode is 10-Bit Addressing
GPM.NoInc = cvFalse 'Increment on every read/write
End Sub
'********************************************************************
' Subroutine to store time and date as values
'********************************************************************
Sub StoreGPTD()
GPM.Location = 0 'Start at R0
Hours = (GPM*10)+GPM 'Store hours
Minutes = (GPM*10)+GPM 'Store minutes
Seconds = (GPM*10)+GPM 'Store seconds
Day = (GPM*10)+GPM 'Store day
Month = (GPM*10)+GPM 'Store month
Year = (GPM*1000)+(GPM*100)+(GPM*10)+GPM 'Store year
End Sub
'********************************************************************
' Subroutine to store heading and speed as values
'********************************************************************
Sub StoreGPHS()
GPM.Location = 46 'Start at R46
Heading = (GPM*100)+(GPM*10)+GPM 'Store heading in degrees
Speed = (GPM*100)+(GPM*10)+GPM 'Store speed in kmh
End Sub
'********************************************************************
'Subroutine to store latitude and longitude as values
'********************************************************************
Sub StoreGPLL()
GPM.Location = 14
Latitude = (GPM*100)+(GPM*10)+GPM 'Store latitude in degrees
Longitude = (GPM*100)+(GPM*10)+GPM 'Store longitude in degrees
End Sub
'********************************************************************
'********************************************************************
|