Problem posting code
acting strange under IE but not Chrome?!?!
Something in this code segment freaking out the forum editor under IE8
Something in this code segment freaking out the forum editor under IE8
' IS24C16A_Demo.bs2
' {$STAMP BS2}
' {$PBASIC 2.5}
' This program demonstrates the basics of reading and writing data to the
' IS24C16A smart card.
' -----[ I/O Definitions ]-------------------------------------------------
IO PIN 3 ' Serial Data IO
CD PIN 2 ' Card Detect
CLK PIN 1 ' Serial Data Clock
' -----[ Constants ]-------------------------------------------------------
Ack CON 0 ' Acknowledge - Successful data transfer
NAck CON 1 ' Acknowledge - Unsuccessful data transfer
' -----[ Variables ]-------------------------------------------------------
index VAR Word ' Variable space for FOR..NEXT loop
command VAR Byte ' Read/Write designation
wData VAR Byte ' Write data
rData VAR Byte ' Read data
choice VAR Nib ' User selection
I2CAck VAR Bit ' Acknowledge bit
temp VAR Byte ' Variable space
address VAR Word ' Current address loaction
EpromSize CON 2
start VAR Word
leng VAR Word '# bytes to dump
incr VAR Nib
'myList VAR Byte(10)
idx VAR Word
' -----[ Initialization ]--------------------------------------------------
' Declares PSC and waits for a smart card to be inserted
leng =256
Program_Start:
DEBUG CLS
DO WHILE (CD = 0) ' Check for smart card,
DEBUG HOME, "No card inserted!" ' loop until card detected
LOOP
' -----[ Program Code ]----------------------------------------------------
Main:
DO
DEBUG CR, "Select:", CR, ' Selection screen
" 1)Dump data from card", CR,
" 2)Load data to card", CR,
"Selection: ", CLREOL
DEBUGIN DEC choice ' Get selection from user
SELECT choice ' Branch to subroutines
CASE 1: GOSUB Dump_Data ' based on user input
CASE 2: GOSUB Load_Data
CASE ELSE: DEBUG CLS, "Invalid selection."
ENDSELECT
LOOP
END
Dump_Data:
DEBUG CR,CR, "Enter address to dump, 0 to ", DEC (1024 * EpromSize) - leng + 15, ": "
DEBUGIN DEC5 start
start = (start/16)*16
address = start
' address = 256*(page-1) ' Set the counter to the first address of the page
GOSUB Device_Addressing ' Call device addressing
' DEBUG CR, DEC5 address, CR
FOR index = 0 TO 255
IF(index//16 = 0) THEN ' Display 'y-axis' of memory map
DEBUG CR, DEC5 address, " "
incr = 0
ENDIF
GOSUB Read_Current_Data ' Read current address data
DEBUG CRSRX, (incr * 3) + 7, HEX2 temp
SELECT temp
CASE < 32
DEBUG CRSRX, (incr * 2) + 60, "."
CASE > 128
DEBUG CRSRX, (incr * 2) + 60, "."
CASE 32 TO 127
DEBUG CRSRX, (incr * 2) + 60, temp
ENDSELECT
incr = incr + 1
address = address + 1
NEXT
RETURN
' -----[ Subroutine - Write_Data ]-----------------------------------------
' Writes data to specified address location
Write_Data:
DEBUG CR, "Enter address to dump, 0 to ", DEC (1024 * EpromSize) - leng + 15, ": "
DEBUGIN DEC5 address
DEBUG CR, "Input data to write [Hex]: " ' Prompt user for data &
DEBUGIN HEX wData ' store in variable wData
GOSUB Write_Address ' Write data to address location
temp = wData
RETURN
' -----[ Subroutine - Device_Addressing ]----------------------------------
' Begins data transmission & sends address of requested Slave devices
Device_Addressing:
GOSUB DeviceStart ' Call start condition
temp = 100000 ' Device Address 10AAA(W)
command = address.HIGHBYTE << 1
command = command & 001110 ' Device Address 10AAA(R) and ROM Address
temp = temp | command ' Add the ROM address into the Command
GOSUB SendOut
IF (I2CAck=NAck) THEN Device_Addressing ' No acknowledge, send again
Send_Address: ' Read current address
temp = address
GOSUB SendOut
IF (I2CAck=NAck) THEN Send_Address ' No acknowledge, send again
RETURN
' -----[ Subroutine - Read_Current_Data ]----------------------------------------
' During 'read' selection, allows user to browse through each 16-byte page of data
Read_Current_Data:
GOSUB DeviceStart ' Call start condition
temp = 100001 ' Device Address 10AAA(R)
command = address.HIGHBYTE << 1
command = command & 001110 ' Device Address 10AAA(R) with ROM Address
temp = temp | command ' Add the ROM address into the Command
GOSUB SendOut ' Send out the Device Address information
IF(I2CAck=NAck)THEN Read_Current_Data ' Wait for the acknowledge, if get no acknowledge, Start again
GOSUB Receive_NAck ' begin to receive the data from the Slaver, No acknowledge
GOSUB DeviceStop
rData = Temp
RETURN
' -----[ Subroutine - Read_Current_Data ]----------------------------------------
' During 'read' selection, allows user to browse through each 16-byte page of data
Write_Address:
GOSUB Device_Addressing
Send_Data: ' Send the data
Temp = WData
GOSUB SendOut
IF (I2CAck=NAck) THEN Send_data
GOSUB DeviceStop ' after send out a byte, stop and release the bus
RETURN
' -----[ Subroutine - DeviceStart ]----------------------------------------
DeviceStart: ' I2C start bit sequence
INPUT IO
INPUT CLK
LOW IO
Clock_hold:
DO : LOOP UNTIL(CLK=1)
RETURN
' -----[ Subroutine - DeviceStop ]-----------------------------------------
DeviceStop: ' I2C stop bit sequence
LOW IO
INPUT CLK
INPUT IO
RETURN
' -----[ Subroutine - SendOut ]--------------------------------------------
SendOut: ' Send out a byte and get acknowledge
SHIFTOUT IO, CLK, MSBFIRST, [Temp\8]
SHIFTIN IO, CLK, MSBPRE, [I2CAck\1]
RETURN
'------------------Receive a Byte---------
Receive_NAck: ' While recieving byte in random mode, the device require no Acknowledge
I2CAck = NAck
Receive:
SHIFTIN IO, CLK, MSBPRE, [Temp\8] 'Get a byte of data and send out a acknowledge
SHIFTOUT IO, CLK, MSBFIRST, [I2CAck\1]
RETURN
Load_Data:
' DEBUG DEC ? name,CR
' DEBUG DEC ? addr,CR
' DEBUG DEC ? city,CR
' DEBUG DEC ? phone,CR
address = 0
FOR incr = 1 TO 4 ' Print blocks one by one
LOOKUP (incr - 1),
[name, addr, city, phone], idx
DO
READ idx, wData ' Get next character
idx = idx + 1 ' Point to next location
GOSUB Write_Address
address = address + 1
IF (wData = 0) THEN EXIT ' If 0, we're done with block
LOOP
NEXT
RETURN

Comments
Thanks, but the issue seems to involve previewing and advanced editing mode. Sometimes I get a popup message saying the message is too short and somtimes I can't place the cursor inside the message to change the text. Really peculiar behavior!
The first time I saw your firs post, it did not have Code tags. Later I saw I did.
I think it's Solar Flares.
That was part of the weird behavior. I was looking at it in preview mode and the code window looked fine but when I saved it, it was all run together and had HTML tags embedded. Now when I try to edit it, the only way I can do it is buy clicking the A/A button to switch the editor in "Source" mode rather than "WYSIWYG" mode...
' IS24C16A_Demo.bs2 ' {$STAMP BS2} ' {$PBASIC 2.5} ' This program demonstrates the basics of reading and writing data to the ' IS24C16A smart card. ' -----[ I/O Definitions ]------------------------------------------------- IO PIN 3 ' Serial Data IO CD PIN 2 ' Card Detect CLK PIN 1 ' Serial Data Clock ' -----[ Constants ]------------------------------------------------------- Ack CON 0 ' Acknowledge - Successful data transfer NAck CON 1 ' Acknowledge - Unsuccessful data transfer ' -----[ Variables ]------------------------------------------------------- index VAR Word ' Variable space for FOR..NEXT loop command VAR Byte ' Read/Write designation wData VAR Byte ' Write data rData VAR Byte ' Read data choice VAR Nib ' User selection I2CAck VAR Bit ' Acknowledge bit temp VAR Byte ' Variable space address VAR Word ' Current address loaction EpromSize CON 2 start VAR Word leng VAR Word '# bytes to dump incr VAR Nib 'myList VAR Byte(10) idx VAR Word ' -----[ Initialization ]-------------------------------------------------- ' Declares PSC and waits for a smart card to be inserted leng =256 Program_Start: DEBUG CLS DO WHILE (CD = 0) ' Check for smart card, DEBUG HOME, "No card inserted!" ' loop until card detected LOOP ' -----[ Program Code ]---------------------------------------------------- Main: DO DEBUG CR, "Select:", CR, ' Selection screen " 1)Dump data from card", CR, " 2)Load data to card", CR, "Selection: ", CLREOL DEBUGIN DEC choice ' Get selection from user SELECT choice ' Branch to subroutines CASE 1: GOSUB Dump_Data ' based on user input CASE 2: GOSUB Load_Data CASE ELSE: DEBUG CLS, "Invalid selection." ENDSELECT LOOP END Dump_Data: DEBUG CR,CR, "Enter address to dump, 0 to ", DEC (1024 * EpromSize) - leng + 15, ": " DEBUGIN DEC5 start start = (start/16)*16 address = start ' address = 256*(page-1) ' Set the counter to the first address of the page GOSUB Device_Addressing ' Call device addressing ' DEBUG CR, DEC5 address, CR FOR index = 0 TO 255 IF(index//16 = 0) THEN ' Display 'y-axis' of memory map DEBUG CR, DEC5 address, " " incr = 0 ENDIF GOSUB Read_Current_Data ' Read current address data DEBUG CRSRX, (incr * 3) + 7, HEX2 temp SELECT temp CASE < 32 DEBUG CRSRX, (incr * 2) + 60, "." CASE > 128 DEBUG CRSRX, (incr * 2) + 60, "." CASE 32 TO 127 DEBUG CRSRX, (incr * 2) + 60, temp ENDSELECT incr = incr + 1 address = address + 1 NEXT RETURN ' -----[ Subroutine - Write_Data ]----------------------------------------- ' Writes data to specified address location Write_Data: DEBUG CR, "Enter address to dump, 0 to ", DEC (1024 * EpromSize) - leng + 15, ": " DEBUGIN DEC5 address DEBUG CR, "Input data to write [Hex]: " ' Prompt user for data & DEBUGIN HEX wData ' store in variable wData GOSUB Write_Address ' Write data to address location temp = wData RETURN ' -----[ Subroutine - Device_Addressing ]---------------------------------- ' Begins data transmission & sends address of requested Slave devices Device_Addressing: GOSUB DeviceStart ' Call start condition temp = %10100000 ' Device Address %1010AAA(W) command = address.HIGHBYTE << 1 command = command & %00001110 ' Device Address %1010AAA(R) and ROM Address temp = temp | command ' Add the ROM address into the Command GOSUB SendOut IF (I2CAck=NAck) THEN Device_Addressing ' No acknowledge, send again Send_Address: ' Read current address temp = address GOSUB SendOut IF (I2CAck=NAck) THEN Send_Address ' No acknowledge, send again RETURN ' -----[ Subroutine - Read_Current_Data ]---------------------------------------- ' During 'read' selection, allows user to browse through each 16-byte page of data Read_Current_Data: GOSUB DeviceStart ' Call start condition temp = %10100001 ' Device Address %1010AAA(R) command = address.HIGHBYTE << 1 command = command & %00001110 ' Device Address %1010AAA(R) with ROM Address temp = temp | command ' Add the ROM address into the Command GOSUB SendOut ' Send out the Device Address information IF(I2CAck=NAck)THEN Read_Current_Data ' Wait for the acknowledge, if get no acknowledge, Start again GOSUB Receive_NAck ' begin to receive the data from the Slaver, No acknowledge GOSUB DeviceStop rData = Temp RETURN ' -----[ Subroutine - Read_Current_Data ]---------------------------------------- ' During 'read' selection, allows user to browse through each 16-byte page of data Write_Address: GOSUB Device_Addressing Send_Data: ' Send the data Temp = WData GOSUB SendOut IF (I2CAck=NAck) THEN Send_data GOSUB DeviceStop ' after send out a byte, stop and release the bus RETURN ' -----[ Subroutine - DeviceStart ]---------------------------------------- DeviceStart: ' I2C start bit sequence INPUT IO INPUT CLK LOW IO Clock_hold: DO : LOOP UNTIL(CLK=1) RETURN ' -----[ Subroutine - DeviceStop ]----------------------------------------- DeviceStop: ' I2C stop bit sequence LOW IO INPUT CLK INPUT IO RETURN ' -----[ Subroutine - SendOut ]-------------------------------------------- SendOut: ' Send out a byte and get acknowledge SHIFTOUT IO, CLK, MSBFIRST, [Temp\8] SHIFTIN IO, CLK, MSBPRE, [I2CAck\1] RETURN '------------------Receive a Byte--------- Receive_NAck: ' While recieving byte in random mode, the device require no Acknowledge I2CAck = NAck Receive: SHIFTIN IO, CLK, MSBPRE, [Temp\8] 'Get a byte of data and send out a acknowledge SHIFTOUT IO, CLK, MSBFIRST, [I2CAck\1] RETURN Load_Data: ' DEBUG DEC ? name,CR ' DEBUG DEC ? addr,CR ' DEBUG DEC ? city,CR ' DEBUG DEC ? phone,CR address = 0 FOR incr = 1 TO 4 ' Print blocks one by one LOOKUP (incr - 1), [name, addr, city, phone], idx DO READ idx, wData ' Get next character idx = idx + 1 ' Point to next location GOSUB Write_Address address = address + 1 IF (wData = 0) THEN EXIT ' If 0, we're done with block LOOP NEXT RETURN