I have another question. Since i've got my glcd up and running with you're help i have been working on PIC-GPS communications.
And with this i can't seem to get the usart bit working.
I have the following code:
Code: Select all
Device = 18F4550
Clock = 8
Config
PLLDIV = 2,
CPUDIV = OSC1_PLL2,
USBDIV = 2,
FOSC = INTOSCIO_EC,
VREGEN = ON
//====user settings to override default module options ====
#option GLCD_MODEL = S1D13700 //Controller mounted on display
#option GLCD_MODE = 8080 //hardware default M6800 Indirect CNF<3:2>
#option GLCD_DATA = PORTD // Data port - only 8 bit port
#option GLCD_RES = PORTB.5 // reset pin
#option GLCD_RD = PORTB.4 // RD pin - 8080 mode
#option GLCD_WR = PORTB.3 // WR pin - 8080 mode
#option GLCD_A0 = PORTB.2 // A0 pin
#option GLCD_CS = PORTB.0 // chip select
#option GLCD_TCR = $2C // TC/R setting to fix flicker problem on display override system instruction ($48)
#option GLCD_ASPECT_RATIO = 100 // aspect ratio, smaller number will squeeze y For GLCD circles And Boxes
#option GLCD_INIT_DELAY = 100 // initialisation delay (ms)
Dim
msg(12) As Byte
Include "Usart.bas"
Include "Convert.bas"
Include "glcd.bas"
Include "arial.bas"
Public Function SendMessage(ByRef message() As Byte, length As Byte) As Boolean
Dim
checksum As Byte,
i As Byte,
acked As Byte,
receive As Byte,
receive1 As Byte,
receive2 As Byte,
receive3 As Byte,
receive4 As Byte,
receive5 As Byte
High(PORTA.0)
checksum = $00
//Header
USART.WriteByte($A0)
USART.WriteByte($A1)
//Payload length
USART.WriteByte($00)
USART.WriteByte(length)
High(PORTA.1)
//payload
i = 0
While i < length
USART.WriteByte(message(i))
checksum = checksum Xor message(i)
Wend
High(PORTA.2)
//checksum
USART.WriteByte(checksum)
//End message
USART.WriteByte($0D)
USART.WriteByte($0A)
acked = 0
receive = 0
receive1 = 0
receive2 = 0
receive3 = 0
receive4 = 0
receive5 = 0
High(PORTA.3)
While acked=0
If DataAvailableTimeout(20) Then
receive5 = receive4
receive4 = receive3
receive3 = receive2
receive2 = receive1
receive1 = receive
receive = USART.ReadByte()
High(PORTA.4)
EndIf
If receive4 = $A1 Then
High(PORTA.5)
If USART.ReadByte() = $83 Then
acked = 1
GLCD.WriteAt(0,14,"NACK")
DelayMS(2000)
ElseIf USART.ReadByte() = $84 Then
acked = 1
GLCD.WriteAt(0,14,"NACK")
DelayMS(2000)
EndIf
EndIf
Wend
Low(PORTA.0)
Low(PORTA.1)
Low(PORTA.2)
Low(PORTA.3)
Low(PORTA.4)
Low(PORTA.5)
End Function
/// Start Main program
//OSCTUNE.6 = 0 // Turn off/on PLL
OSCCON = %01110110
Pen.Color = 1
Brush.Color =1
Pen.Mode = 0 // pen modes, pmCopy = 0, pmMerge = 1, pmXOR = 2,
Brush.Style = 0 //1=bsClear 0=bsSolid
SetFont(Arial)
//Set baudrate
msg(0) = $05
msg(1) = $00
msg(2) = $03
msg(3) = $00
GLCD.WriteAt(0,0,"Baudrate")
SendMessage(msg(), 4)
USART.SetBaudrate(br38400)
Cls(1)
I suspect i'm doing something wrong with addressing the uart on my pic or gps. I know for sure i have connected the gps correctly, because i had it running using MikroC.
Can someone shed some light on this?