'TSLOFL-3 10/08/00 working on polarity- initially looks OK 'TSLOFL-2 08/30/00 incomplete- LEDs are working. Motors on both yards 'are working. 'TSLOFL-1 08/23/00 yard track LEDs are selectable ' 'A BS2 STAMP project to interpret control panel commands from the 'OFL staging yard and drive the switch machines, set polarity and 'provide data to the central computer. ' by Wayne Roderick tetonsl@ida.net 'set pin directions- and define terminations input 0 'PIC-10 unassigned, future computer interface input 1 ' -11 unassigned input 2 ' -12 unassigned input 3 ' -13 unassigned input 4 ' -14 unassigned input 5 ' -15 unassigned input 6 ' -16 unassigned input 7 ' -17 unassigned input 8 ' -18 unassigned High 9 ' -19 Send serial data out 74164-1,2 Serin High 10 ' -20 Clear-not used " -9 clear High 11 ' -21 Register clock -8 Low 12 ' -22 Clock 74165-2 ClockG High 13 ' -23 Shift/Load " -1 Shift/Load Low 14 ' -24 Clock Inhibit " -15 Clock inhibit input 15 ' -25 Bring serial data in " -9 Serin 'variables OFLup var nib 'upper track selection OFLdn var nib 'lower track selection PB1 var byte 'first bank of push buttons PB2 var byte 'second bank of push buttons PB3 var byte 'third bank of push buttons DatPinOut con 9 'data pin to 74164 ClkOut con 11 'shift clock to 74164 Cntr var byte 'counter for demo DatOut1 var byte 'data Out DatOut2 var byte 'data Out DatOut3 var byte 'data Out DatOut4 var byte 'data Out DatPinIn con 15 'data pin from 74165 ClkIn con 12 'shift clock to 74165 ShftLoad con 13 'shift/load to 74165 DatIn1 var byte 'data in DatIn2 var byte 'data in DatIn3 var byte 'data in DatIn4 var byte 'data in i var byte 'general purpose counter j var byte ' " " " TrkUp var byte 'selected yard track TrkDn var byte 'selected yard track OFLsw12 var bit 'switch position (former S6) SW11 var bit 'switch position PolOut var nib 'polarity lights & relays LED18 var bit 'block 18/19 polarity error LED19 var bit 'block 19/11 polarity error Pol18 var bit 'block 18 polarity Pol19 var bit 'block 19 polarity Mtrs var byte 'switch motor status 'Start program 'Clear (Low) sets all outputs of the 74164 Low- not a good thing 'for the TSL standards! forget it. port is available for other use 'Define the hardware connections 'Lower yard 'Trk-1, bitval=001, DatIn1/DatOut1 ' Push/LEDs 'Trk-8, bitval=128, DatIn1/DatOut1 'Upper yard 'Trk-1, bitval=001, DatIn2/DatOut2 ' Push/LEDs 'Trk-5, bitval=016, DatIn2/DatOut2 'more 'OFLsw12, Rvrs bitval=032, DatIn2/DatOut2 ' Push/LEDs 'OFLsw12, Nrml bitval=064, DatIn2/DatOut2 'not used, bitval=128, DatIn2/DatOut2 'Blk18/19 Polarity, bitval=001, DatIn3/DatOut3 'Blk19/11 Polarity, bitval=002, DatIn3/DatOut3 'old intrfc 'SW11 position, bitval=004, DatIn3 'polar rlys 'Blk18 relay, bitval=004, DatOut3 'Blk19 relay, bitval=008, DatOut3 'Switch Motors, Upper entry, bitval 001, DatOut3 ' " Upper Next" " 002, DatOut3 ' " Upper Last " 004, DatOut3 ' " Lower Entry " 008, DatOut3 ' " Lower Next" " 016, DatOut4 ' " Lower Last " 032, DatOut4 ' " Lower OFLsw12 " 064, DatOut4 'Initial conditions- ' pause 2000 'let railroad power stabilize Mtrs = %10110111 'route agrees with LEDs PolOut = %00001000 'polar lites, relays & sw motors TrkUp = %01010000 'upper trk #5[16] Grn LED TrkDn = %00001000 'lower trk #4[8] Grn LED SW11 = %1 'this is assumption, initially we don't know GOTO OutPutIt ScanKeypad: PULSOUT ShftLoad,10 SHIFTIN DatPinIn,ClkIn,MSBPre,[DatIn1,DatIn2,DatIn3] DatIn1=(DatIn1 ^ %11111111) 'flip the logic to Positive, active=1 IF DatIn1 <> 0 Then TrkSlctDn DatIn2=(DatIn2 ^ %11111111) IF (DatIn2 & %00011111) <> 0 THEN TrkSlctUp IF (DatIn2 & %01100000) <> 0 THEN OFLsw12Set DatIn3=(DatIn3 ^ %11111111) 'polarity buttons & Sw11 position IF (DatIn3 & %00000011) <> 0 THEN PolSet IF (DatIn3 & %00000100) <> (SW11*4) THEN PolSW11 GOTO ScanKeyPad TrkSlctDn: 'Lower yard, Light LED & run switch motors IF TrkDn=DatIn1 THEN ScanKeyPad 'already there TrkDn=DatIn1 'one of eight i=0 j=%00000001 loop2: if TrkDn=j THEN MotorsDn 'test each bit i=i+1 'next track j=j*2 'next bit GOTO Loop2 MotorsDn: Mtrs = (Mtrs & %11000111) 'zero lower level motors-save others LOOKUP i,[%000,%100,%010,%110,%001,%101,%011,%111],j ' debug bin ? DatIn2,bin ? TrkUp,bin ? Mtrs Mtrs = Mtrs | (j*8) 'OR in the new setting ' debug bin? i,bin ?j,bin ? Mtrs,"&&&&&" GOTO OutPutIt TrkSlctUp: 'Upper yard, lite LED & run switch motors IF TrkUp=DatIn2 THEN ScanKeyPad 'already there TrkUp = (DatIn2 & %00011111) 'LED drive, save it i=0 j=%00000001 'get the motor lineup loop1: If TrkUp=j THEN MotorsUp 'test each bit i=i+1 'next track j=j*2 'next bit GOTO LOOP1 MotorsUp: 'Upper Yard and OFLsw12 Mtrs = (Mtrs & %01111000) 'zero upper level motors- save others LOOKUP i,[%110,%010,%101,%001,%111],j ' debug bin ? DatIn2,bin ? TrkUp,bin ? Mtrs Mtrs = Mtrs | j 'OR in the new setting ' debug bin? i,bin ?j,bin ? Mtrs,"&&&&&" GOTO OutPutIt OFLsw12set: 'OFLsw12 lites IF TrkUp=DatIn2 THEN ScanKeyPad 'already there i = (DatIn2 & %01100000) '32 or 64,lite up one or the other OFLsw12=(i >> 6)^1 '1 or 0, 1=reverse TrkUp=(TrkUp & %00011111) 'strip the old OFLsw12 Lites TrkUp = (i | TrkUp) 'OR in the new one OFLsw12Mtr: Mtrs = (Mtrs & %00111111) 'zero OFLsw12 motor- save others ' debug "OFL1 ",bin?Mtrs,bin?OFLsw12 ' j = (OFLsw12 ^ %1) 'XOR to invert it j = OFLsw12 j = (j <<6) 'move to bit 64 Mtrs = Mtrs | j 'OR the sw motor with others ' debug "OFL2 ",bin?Mtrs,bin?j ' debug "OFLsw12 ", bin ? j, ? OFLsw12, bin ? Mtrs,bin?Pol19 POL19=(OFLsw12^%1) 'match the polarity ' POL19=OFLsw12 GOTO PolarLites PolSw11: 'old style mainline switch machine i = (DatIn3 & %00000100) 'bit value 4 = switch 11 posituion ' debug bin ? DatIn3, bin ? i, bin ? SW11 Sw11=i/4 'save the new position POL18=(SW11^%1) 'match block 18 polarity ' debug "PS0 ", bin ? Pol18, bin ? SW11, CR GOTO PolarLites PolSet: ' debug cls, "Entering PolSet ",CR PolSet1: 'manual override polarity setting i = (DatIn3 & %0001) 'trap PB1 selection if i=0 THEN PolSet2 'not pressed Pol19 = (Pol18^%1) 'match polarity PolSet2: i = (DatIn3 & %0010) 'trap PB2 selection if i=0 THEN PolarLites 'not pressed Pol19 = (OFLsw12 ^ %1) 'match polarity PolarLites: LED18=(POL18 ^ POL19) 'On if they conflict LED18=(LED18 ^ %1) LED19=(OFLsw12 ^ POL19) 'On if they conflict LED19=(LED19 ^%1) ' debug "polarlite ",?LED18,?Pol18,?LED19,?Pol19,CR PolDone: PolOut= LED18 | ((LED19 << 1) | (Pol18 << 2) | (Pol19 << 3)) ' debug "PS4 ",bin ? PolOut,CR GOTO OutputIt OutPutIt: DatOut1 = (TrkDn ^ %11111111) 'flip logic back to negative DatOut2 = (TrkUp ^ %11111111) 'combine & flip logic j=(Mtrs << 4) 'pick off four motors DatOut3 = ((PolOut | j) ^ %11111111)'OR with polarity lites & relays j=(Mtrs >> 4) 'the remaining four motors DatOut4 = ((Mtrs >> 4) ^ %11111111) ' debug bin? TrkDn,bin? DatOut1,bin? TrkUp,bin ? OFLsw12,bin? DatOut2 ' debug bin ? DatOut4 ' debug bin ? Mtrs SHIFTOUT DatPinOut,ClkOut,msbfirst,[DatOut4,DatOut3,DatOut2,DatOut1] GOTO ScanKeypad