Serial Repeating
I'm trying to just parrot out the serial information (in at TTL and out at CMOS) and detecting and managing 4 buttons.· When I connected the GPS device to the serial out directly, it properly is showing at 4800 in hyperterminal.· I see the NEMA codes
But when going through this code, I'm getting gibberish.
Suggestions?
Thanks ahead of time.
Lance
' =========================================================================
'
'·· File...... LANCEGPS.SXB
'·· Author.... Lance Rasmussen
'·· E-mail.... lance@lance.ws
'·· Started...
'·· Updated... 10 APR 2008
'
' =========================================================================
'
' Program Description
'
'
' Device Settings
'
DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ 4_000_000
ID "KEYPAD"
'
' IO Pins
'
'RC7Unused PIN RC.7 OUTPUT·
'RC6Unused PIN RC.6 OUTPUT·
'RC5Unused PIN RC.5 OUTPUT·
'RC4Unused PIN RC.4 OUTPUT·
RC7Unused· ·PIN ·RC.7 ·OUTPUT
NShutter ·PIN ·RC.6 ·OUTPUT PULLUP
RC5Unused· ·PIN ·RC.5 ·OUTPUT
NMeter ··PIN ·RC.4 ·OUTPUT PULLUP
KeyD· ··PIN ·RC.2 ·INPUT ·SCHMITT ·PULLUP······ ' Remote receiver D
KeyC· ··PIN ·RC.1 ·INPUT ·SCHMITT ·PULLUP······ ' Remote receiver C
KeyB· ··PIN ·RC.3 ·INPUT ·SCHMITT ·PULLUP······ ' Remote receiver B
KeyA· ··PIN ·RC.0 ·INPUT ·SCHMITT ·PULLUP······ ' Remote receiver A
RB7Unused ·PIN ·RB.7 ·OUTPUT ·PULLUP
RB6Unused ·PIN ·RB.6 ·OUTPUT ·PULLUP
RB5Unused ·PIN ·RB.5 ·OUTPUT ·PULLUP
RB4Unused ·PIN ·RB.4 ·OUTPUT ·PULLUP
RB3Unused ·PIN ·RB.3 ·OUTPUT ·PULLUP
RB2Unused ·PIN ·RB.2 ·OUTPUT ·PULLUP
'RB1Unused ·PIN ·RB.1 ·OUTPUT ·PULLUP
'RB0Unused ·PIN ·RB.0 ·OUTPUT ·PULLUP
TX··PIN·RB.1·OUTPUT· ··' Serial out at 4800
RX··PIN·RB.0·INPUT·········· ·' from GPS
RAUnused PIN RA OUTPUT
'
' Constants
'
Yes············ CON···· 0······················ ' active low input
No············· CON···· 1
Pressed······ ·CON···· 1
GpsBaud··CON·"T4800"··' to/from GPS module
'
' Variables
'
tmpW1·········· VAR···· Word
tmpB0··VAR·Byte···' subroutine vars
temp1··VAR·Byte···' subroutine vars
temp2··VAR·Byte···' subroutine vars
temp3··VAR·Byte···' subroutine vars
char··VAR·Byte···' vars
' ======================================================================
· PROGRAM Start
' ======================================================================
'
' Subroutine Declarations
'
·DELAY·········· SUB···· 1, 2··················· ' delay in milliseconds
·GPSRX·· SUB· ···' get byte from GPS
·GPSTX·· SUB· 1···' send byte from GPS
'
' Program Code
'
Start:
RA = 0
RB = %00000011
RC = %00000000
NMeter = No
NShutter = No
Main:
· GPSRX·····'
·
· IF KeyA = Pressed then
··· DO
····· GPSRX·····'
··· LOOP UNTIL KeyA <> Pressed
··· NMeter = Yes
····· GPSRX·····'
··· PAUSE 200
····· GPSRX·····'
··· NShutter = Yes
··· PAUSE 300
··· NShutter = No
··· NMeter = No
· ENDIF
· IF KeyB = Pressed then
··· DO
····· GPSRX·····'
··· LOOP UNTIL KeyB <> Pressed
··· PAUSE 10000
··· NMeter = Yes
····· GPSRX·····'
··· PAUSE 200
····· GPSRX·····'
··· NShutter = Yes
··· PAUSE 300
··· NShutter = No
··· NMeter = No
· ENDIF
· IF KeyC = Pressed then
··· DO
····· GPSRX·····'
··· LOOP UNTIL KeyC <> Pressed
··· NMeter = Yes
····· GPSRX·····'
··· PAUSE 200
····· GPSRX·····'
··· NShutter = Yes
··· PAUSE 4000
··· NShutter = No
··· NMeter = No
· ENDIF
· IF KeyD = Pressed then
··· DO
····· GPSRX·····'
··· LOOP UNTIL KeyD <> Pressed
··· PAUSE 3000
····· GPSRX·····'
··· NMeter = Yes
··· PAUSE 200
····· GPSRX·····'
··· NShutter = Yes
··· PAUSE 200
··· NShutter = No
··· NMeter = No
· ENDIF
·
· GOTO Main
'
' Subroutine Code
'
'
' Use: DELAY ms
' -- 'ms' is delay in milliseconds, 1 - 65535
DELAY:
· IF __PARAMCNT = 1 THEN
··· tmpW1 = __PARAM1··························· ' save byte value
· ELSE
··· tmpW1 = __WPARAM12························· ' save word value
· ENDIF
· PAUSE tmpW1
· RETURN
' Use: theByte = GPSRX
GPSRX:
· SERIN RX, GpsBaud, temp1···' get byte from 406a
· SEROUT TX, GpsBaud, temp1···' repeat·byte out to serial output
RETURN
GPSTX:
'· SEROUT TX, GpsBaud, __PARAM1···'·Send byte·to serial output
RETURN
' ======================================================================
' User Data
' ======================================================================
·
But when going through this code, I'm getting gibberish.
Suggestions?
Thanks ahead of time.
Lance
' =========================================================================
'
'·· File...... LANCEGPS.SXB
'·· Author.... Lance Rasmussen
'·· E-mail.... lance@lance.ws
'·· Started...
'·· Updated... 10 APR 2008
'
' =========================================================================
'
' Program Description
'
'
' Device Settings
'
DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ 4_000_000
ID "KEYPAD"
'
' IO Pins
'
'RC7Unused PIN RC.7 OUTPUT·
'RC6Unused PIN RC.6 OUTPUT·
'RC5Unused PIN RC.5 OUTPUT·
'RC4Unused PIN RC.4 OUTPUT·
RC7Unused· ·PIN ·RC.7 ·OUTPUT
NShutter ·PIN ·RC.6 ·OUTPUT PULLUP
RC5Unused· ·PIN ·RC.5 ·OUTPUT
NMeter ··PIN ·RC.4 ·OUTPUT PULLUP
KeyD· ··PIN ·RC.2 ·INPUT ·SCHMITT ·PULLUP······ ' Remote receiver D
KeyC· ··PIN ·RC.1 ·INPUT ·SCHMITT ·PULLUP······ ' Remote receiver C
KeyB· ··PIN ·RC.3 ·INPUT ·SCHMITT ·PULLUP······ ' Remote receiver B
KeyA· ··PIN ·RC.0 ·INPUT ·SCHMITT ·PULLUP······ ' Remote receiver A
RB7Unused ·PIN ·RB.7 ·OUTPUT ·PULLUP
RB6Unused ·PIN ·RB.6 ·OUTPUT ·PULLUP
RB5Unused ·PIN ·RB.5 ·OUTPUT ·PULLUP
RB4Unused ·PIN ·RB.4 ·OUTPUT ·PULLUP
RB3Unused ·PIN ·RB.3 ·OUTPUT ·PULLUP
RB2Unused ·PIN ·RB.2 ·OUTPUT ·PULLUP
'RB1Unused ·PIN ·RB.1 ·OUTPUT ·PULLUP
'RB0Unused ·PIN ·RB.0 ·OUTPUT ·PULLUP
TX··PIN·RB.1·OUTPUT· ··' Serial out at 4800
RX··PIN·RB.0·INPUT·········· ·' from GPS
RAUnused PIN RA OUTPUT
'
' Constants
'
Yes············ CON···· 0······················ ' active low input
No············· CON···· 1
Pressed······ ·CON···· 1
GpsBaud··CON·"T4800"··' to/from GPS module
'
' Variables
'
tmpW1·········· VAR···· Word
tmpB0··VAR·Byte···' subroutine vars
temp1··VAR·Byte···' subroutine vars
temp2··VAR·Byte···' subroutine vars
temp3··VAR·Byte···' subroutine vars
char··VAR·Byte···' vars
' ======================================================================
· PROGRAM Start
' ======================================================================
'
' Subroutine Declarations
'
·DELAY·········· SUB···· 1, 2··················· ' delay in milliseconds
·GPSRX·· SUB· ···' get byte from GPS
·GPSTX·· SUB· 1···' send byte from GPS
'
' Program Code
'
Start:
RA = 0
RB = %00000011
RC = %00000000
NMeter = No
NShutter = No
Main:
· GPSRX·····'
·
· IF KeyA = Pressed then
··· DO
····· GPSRX·····'
··· LOOP UNTIL KeyA <> Pressed
··· NMeter = Yes
····· GPSRX·····'
··· PAUSE 200
····· GPSRX·····'
··· NShutter = Yes
··· PAUSE 300
··· NShutter = No
··· NMeter = No
· ENDIF
· IF KeyB = Pressed then
··· DO
····· GPSRX·····'
··· LOOP UNTIL KeyB <> Pressed
··· PAUSE 10000
··· NMeter = Yes
····· GPSRX·····'
··· PAUSE 200
····· GPSRX·····'
··· NShutter = Yes
··· PAUSE 300
··· NShutter = No
··· NMeter = No
· ENDIF
· IF KeyC = Pressed then
··· DO
····· GPSRX·····'
··· LOOP UNTIL KeyC <> Pressed
··· NMeter = Yes
····· GPSRX·····'
··· PAUSE 200
····· GPSRX·····'
··· NShutter = Yes
··· PAUSE 4000
··· NShutter = No
··· NMeter = No
· ENDIF
· IF KeyD = Pressed then
··· DO
····· GPSRX·····'
··· LOOP UNTIL KeyD <> Pressed
··· PAUSE 3000
····· GPSRX·····'
··· NMeter = Yes
··· PAUSE 200
····· GPSRX·····'
··· NShutter = Yes
··· PAUSE 200
··· NShutter = No
··· NMeter = No
· ENDIF
·
· GOTO Main
'
' Subroutine Code
'
'
' Use: DELAY ms
' -- 'ms' is delay in milliseconds, 1 - 65535
DELAY:
· IF __PARAMCNT = 1 THEN
··· tmpW1 = __PARAM1··························· ' save byte value
· ELSE
··· tmpW1 = __WPARAM12························· ' save word value
· ENDIF
· PAUSE tmpW1
· RETURN
' Use: theByte = GPSRX
GPSRX:
· SERIN RX, GpsBaud, temp1···' get byte from 406a
· SEROUT TX, GpsBaud, temp1···' repeat·byte out to serial output
RETURN
GPSTX:
'· SEROUT TX, GpsBaud, __PARAM1···'·Send byte·to serial output
RETURN
' ======================================================================
' User Data
' ======================================================================
·
Comments
You cannot use the internal oscillator to do serial communications. It is not accurate enough.
Also you are going to miss incoming data while you are sending data.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Did you know that 111,111,111 multiplied by 111,111,111 equals 12345678987654321 ?
www.iElectronicDesigns.com
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Shawn Lowe
Maybe I should have waited to do that......
When I hook the GPS output to the serial out, I do get correct data (4800 8n1) but it doesn't seem to work going out of my program.