' {$STAMP BS2} ' {$PBASIC 2.5} '.......................................................................... 'SETUP WIRED SRINT 8 to VELLEMAN 'PIN 2 (confirmed) on Sprint8 TO PIN 15 on the STAMP 'PIN 5 on Sprint8 to GND on the STAMP 'PIN 1 on the STAMP to PIN 3 on VELLEMAN 'GND on the STAMP to PIN 5 on VELLEMAN 'if the programme receives a finish signal on or after 2 minutes it will reset to the beginning of the programme '.......................................................................... serData VAR Byte(8) 'only 8 bytes required from STAMP vell VAR Byte(10) '10 byte array required by VELLEMAN x VAR Byte ' parameter - can be up to 255 so byte required n VAR Byte 'is checksum Z VAR Nib 'module address '...................................................................................................... 'REMOVE DECIMAL POINT from address 3 left over from previous programme n= 256-(13+3+80+0) vell(0)= 13 vell(1)= 3 'addresses 3 vell(2)= 80 'P = 80 Byte command vell(3)= 0 'clear all segments vell(4)= n 'checksum vell(5) =13 vell(6)= 8 vell(7)= 83 'S strobe command vell(8)= 1 vell(9)= 151 SEROUT 1,16780,[STR vell\10] 'using Pin 1 on BS 2400\8\N\1 Main: '................................................................................................... 'CLEAR MODULES DEBUG "clearing the 4 modules",CR FOR Z = 1 TO 4 n= 256-(13+z+66+0) vell(0)= 13 vell(1)= z 'addresses 1 to 4 vell(2)= 66 'B = 66 Byte command vell(3)= 0 'clear all segments vell(4)= n 'checksum vell(5) =13 vell(6)= 8 vell(7)= 83 'S strobe command vell(8)= 1 vell(9)= 151 SEROUT 1,16780,[STR vell\10] 'using Pin 1 on BS 2400\8\N\1 NEXT '.............................................................................................. 'ADD DECIMAL POINT DEBUG "adding the decimal point to module 2",CR n= 256-(13+2+80+255) vell(0)= 13 vell(1)= 2 'addresses 2 vell(2)= 80 'P = 80 Byte command vell(3)= 255 'clear all segments vell(4)= n 'checksum vell(5) =13 vell(6)= 8 vell(7)= 83 'S strobe command vell(8)= 1 vell(9)= 151 SEROUT 1,16780,[STR vell\10] 'using Pin 1 on BS 2400\8\N\1 '................................................................................................... 'acquire first bytes ignoring event data DEBUG "waiting for data",CR 'Main: SERIN 15,16468,[WAIT(48,48,48,48,48,48),serData] 'skip the first six zeros when New Event SERIN 15,16468,[STR serData\8] '9600\8\N\1 inverted Pin 15 on the Stamp baudmode is the same for BS2 and BS2pe '................................................................................................................... 'next 4 lines optional FOR x = 0 TO 7 DEBUG? x DEBUG? serData(x) NEXT '.................................................................................................... 'FIRST MODULE byte 5 LOOKDOWN serData(4),[ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ],x LOOKUP x,[237,12,230,174,15,171,203,44,239,47],x n= 256-(13+1+66+x) 'checksum vell(0)= 13 vell(1)= 1 'address 1 vell(2)= 66 'B = 66 Byte command vell(3)= x 'segments vell(4)= n 'checksum vell(5) =13 vell(6)= 8 vell(7)= 83 'S strobe command vell(8)= 1 vell(9)= 151 SEROUT 1,16780,[STR vell\10] 'using Pin 1 on BS 2400\8\N\1 'SECOND MODULE byte 6 LOOKDOWN serData(5),[ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ],x LOOKUP x,[253,28,230,190,31,187,219,60,255,63],x n= 256-(13+2+66+x) 'checksum vell(0)= 13 vell(1)= 2 'address 2 vell(2)= 66 'B = 66 Byte command vell(3)= x 'segments vell(4)= n 'checksum vell(5) =13 vell(6)= 8 vell(7)= 83 'S strobe command vell(8)= 1 vell(9)= 151 SEROUT 1,16780,[STR vell\10] 'using Pin 1 on BS 'THIRD MODULE byte 7 LOOKDOWN serData(6),[ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ],x LOOKUP x,[237,12,230,174,15,171,203,44,239,47],x n= 256-(13+3+66+x) 'checksum vell(0)= 13 vell(1)= 3 'address 3 vell(2)= 66 'B = 66 Byte command vell(3)= x 'segments vell(4)= n 'checksum vell(5) =13 vell(6)= 8 vell(7)= 83 'S strobe command vell(8)= 1 vell(9)= 151 SEROUT 1,16780,[STR vell\10] 'using Pin 1 on BS 'FOURTH MODULE byte 8 LOOKDOWN serData(7),[ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ],x LOOKUP x,[237,12,230,174,15,171,203,44,239,47],x n= 256-(13+4+66+x) 'checksum vell(0)= 13 vell(1)= 4 'address 4 vell(2)= 66 'B = 66 Byte command vell(3)= x 'segments vell(4)= n 'checksum vell(5) =13 vell(6)= 8 vell(7)= 83 'S strobe command vell(8)= 1 vell(9)= 151 SEROUT 1,16780,[STR vell\10] 'using Pin 1 on BS '.......................................................................................................... 'SECOND TIME AROUND SECOND_TIME_AROUND: 'look for new data from Sprint8 SERIN 15,16468,[STR serData\8] '9600\8\N\1 inverted baudmode is the same for BS2 and BS2pe '............................................................................................................. 'allowing 99.99 on Velleman module address 1 if time > 60s IF serData(4)=49 AND serData(5)=48 THEN serData(5)=54 '6 IF serData(4)=49 AND serData(5)=49 THEN serData(5)=55 '7 IF serData(4)=49 AND serData(5)=50 THEN serData(5)=56 '8 IF serData(4)=49 AND serData(5)=51 THEN serData(5)=57 '9 '............................................................................................................. 'FIRST MODULE LOOKDOWN serData(5),[ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ],x LOOKUP x,[237,12,230,174,15,171,203,44,239,47],x n= 256-(13+1+66+x) 'checksum vell(0)= 13 vell(1)= 1 'address 1 vell(2)= 66 'B = 66 Byte command vell(3)= x 'segments vell(4)= n 'checksum vell(5) =13 vell(6)= 8 vell(7)= 83 'S strobe command vell(8)= 1 vell(9)= 151 SEROUT 1,16780,[STR vell\10] 'using Pin 1 on BS 'SECOND MODULE LOOKDOWN serData(6),[ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ],x LOOKUP x,[253,28,246,190,31,187,219,60,255,63],x n= 256-(13+2+66+x) 'checksum vell(0)= 13 vell(1)= 2 'address 2 vell(2)= 66 'B = 66 Byte command vell(3)= x 'segments vell(4)= n 'checksum vell(5) =13 vell(6)= 8 vell(7)= 83 'S strobe command vell(8)= 1 vell(9)= 151 SEROUT 1,16780,[STR vell\10] 'using Pin 1 on BS 'THIRD MODULE LOOKDOWN serData(7),[ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ],x LOOKUP x,[237,12,230,174,15,171,203,44,239,47],x n= 256-(13+3+66+x) 'checksum vell(0)= 13 vell(1)= 3 'address 3 vell(2)= 66 'B = 66 Byte command vell(3)= x 'segments vell(4)= n 'checksum vell(5) =13 vell(6)= 8 vell(7)= 83 'S strobe command vell(8)= 1 vell(9)= 151 SEROUT 1,16780,[STR vell\10] 'using Pin 1 on BS 'FOURTH MODULE LOOKDOWN serData(8),[ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ],x LOOKUP x,[237,12,230,174,15,171,203,44,239,47],x n= 256-(13+4+66+x) 'checksum vell(0)= 13 vell(1)= 4 'address 4 vell(2)= 66 'B = 66 Byte command vell(3)= x 'segments vell(4)= n 'checksum vell(5) =13 vell(6)= 8 vell(7)= 83 'S strobe command vell(8)= 1 vell(9)= 151 SEROUT 1,16780,[STR vell\10] 'using Pin 1 on BS '.................................................................................................... 'this allows the programme to go to the beginning (New Event) or go to the interim programme 'prevents 00.00 appearing for first finisher with a new event 'the Stamp must receive a finish signal at 1m40s or longer IF serData(4)=> 49 AND serData(5) = 52 THEN GOTO Main ELSE GOTO SECOND_TIME_AROUND 'time greater than or equal to 1m40s