In SX Microcontrollers, SX/B Compiler and SX-Key Tool, robotworkshop wrote: You can try the code below to see if it makes any difference. It was compiled under the older SX/B. I am not near any of my SX boards at the moment so I haven't tried loading it into any chips yet.... ' ========================================================================= ' ' File...... TESTCOM.SXB ' Purpose... Serial Port test on SX48 OEM Module (tweaked for Bill) ' Author.... ' E-mail.... ' Website... ' Created... 11 MAR 2009 ' Updated... ' ' Version... 1.0 ' ' ========================================================================= ' ------------------------------------------------------------------------- ' Program Description ' ------------------------------------------------------------------------- ' ' Program to wait for a byte from a VB app running on a PC via an eb501 module ' It requires an external 20mhz resonator. ' ------------------------------------------------------------------------- ' Device Settings ' ------------------------------------------------------------------------- DEVICE SX48, OSCXT2 ' May also try OSCHS1 FREQ 20_000_000 ID "TESTCOM" ' ------------------------------------------------------------------------- ' IO Pins ' ------------------------------------------------------------------------- Sout VAR RA.3 ' Serial output (s Sin VAR RA.2 ' Serial input SIO VAR TRIS_A ' I/O direction of Port A RX VAR RB.0 ' RX from VB app on PC Left VAR RB.2 ' Left LED Right VAR RB.3 ' Right LED BIO VAR TRIS_B ' I/O direction of Port B CIO VAR TRIS_C ' I/O direction of Port C DIO VAR TRIS_D ' I/O direction of Port D EIO VAR TRIS_E ' I/O direction of Port E LEDs VAR RC ' Port C ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- True CON 1 False CON 0 Baud CON "T9600" ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- sData VAR Byte ' Serial data in from host oldRecData VAR Byte RecData VAR Byte tmpB1 VAR Byte ' subroutine work vars tmpB2 VAR Byte tmpW1 VAR Word ' ------------------------------------------------------------------------- PROGRAM Start ' ------------------------------------------------------------------------- ' ------------------------------------------------------------------------- ' Function and Subroutine Declarations ' ------------------------------------------------------------------------- TX_Byte SUB 1 ' TX to Serial I/O DELAY SUB 1, 2 ' delay in milliseconds ' ------------------------------------------------------------------------- ' Program Code ' ------------------------------------------------------------------------- ' Setup IO ports: Direction, etc. Start: SIO = %00000111 ' Set RA.3 as out and RA.2 as in for Serial port BIO = %11110011 ' Setup port B as inputs (except for RB2 and RB3) CIO = %00000000 ' Setup port C as outputs for LED's DIO = %11111111 ' Setup port D as inputs EIO = %11111111 ' Setup port E as inputs RecData = 0 ' Set outputs to known state HIGH Left ' Or use LOW HIGH Right ' Or use LOW Main: IF RecData = 65 THEN HIGH Left LOW Right ENDIF IF RecData = 66 THEN LOW Left HIGH Right ENDIF IF RecData = 90 THEN LOW Left LOW Right ENDIF oldRecData = RecData ' at this point "oldRecData" equals "RecData" TightLoop: SERIN RX, Baud, RecData ' get new data from eb501, if available if oldRecData = RecData then TightLoop ' if old data (oldRecData) is the same as the new data (RecData), stay in the "TightLoop" 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: TX_Byte char ' -- 'Transmits 'char' over serial connection TX_Byte: tmpB1 = __PARAM1 ' get the passed byte value SEROUT Sout, Baud, tmpB1 ' Send the byte RETURN ' ========================================================================= ' User Data ' ========================================================================= ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=334931#m334953 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2009 (http://www.dotNetBB.com)