' ========================================================================= ' ' {$STAMP BS2p} ' {$PBASIC 2.5} ' ' ========================================================================= ' -----[ NOTES: ]------------------------------------------------ ' Minimum reliable sample rate for I/O board inputs at 60HZ is 10 samples ' 0% error rate acheived at 10 samples with the following code: ' -----[ I/O Definitions ]------------------------------------------------- 'I/O Board A DataIOA PIN 7 ' DIN & DATA_RLY ClockA PIN 6 ' SCLK_IN & SCLK_RLY HC595A PIN 5 ' LAT_RLY Pin HC165A PIN 4 ' LOAD_IN Pin 'I/O Board B DataIOB PIN 3 ' DIN & DATA_RLY ClockB PIN 2 ' SCLK_IN & SCLK_RLY HC595B PIN 1 ' LAT_RLY Pin HC165B PIN 0 ' LOAD_IN Pin ' -----[ Variables ]------------------------------------------------------- index VAR Byte optosA VAR Byte 'Opto Status Byte A optosB VAR Byte 'Opto Status Byte B bitresultA VAR Word bitresultB VAR Word counter VAR Word subcounter VAR Nib Temperature CON 40 x VAR Word ' -----[ EEPROM Data ]----------------------------------------------------- ' -----[ Initialization ]-------------------------------------------------- MAINIO DEBUG CLS HIGH HC165A ' Make Output And HIGH HIGH HC165B ' -----[ Program Code ]---------------------------------------------------- Start: MAINIO index = 0 GOSUB Out_595A GOSUB Out_595B DEBUG CLS, "Board A & B Switches: 76543210", CRSRXY, 12, 5, "INPUTS A: 76543210", CRSRXY, 12, 10, "INPUTS B: 76543210" Main: DO index = 1 FOR counter = 0 TO 7 FOR x = 0 TO 20 bitresultA = 0 bitresultB = 0 GOSUB Out_595A ' Update 74HC595-A GOSUB Out_595B FOR subcounter = 0 TO 9 GOSUB In_165A bitresultA = bitresultA | optosA NEXT FOR subcounter = 0 TO 9 GOSUB In_165B bitresultB = bitresultB | optosB NEXT DEBUG CRSRXY, 22, 1, BIN8 index, CRSRXY, 22, 6, BIN8 bitresultA, CRSRXY, 22, 11, BIN8 bitresultB NEXT index = index << 1 NEXT LOOP ' -----[ Subroutines ]----------------------------------------------------- Out_595A: SHIFTOUT DataIOA, ClockA, MSBFIRST, [index] PULSOUT HC595A, 5 ' Latch Outputs RETURN In_165A: PULSOUT HC165A, 5 ' Load Inputs SHIFTIN DataIOA, ClockA, MSBPRE, [optosA] RETURN Out_595B: SHIFTOUT DataIOB, ClockB, MSBFIRST, [index] PULSOUT HC595B, 5 ' Latch Outputs RETURN In_165B: PULSOUT HC165B, 5 ' Load Inputs SHIFTIN DataIOB, ClockB, MSBPRE, [optosB] RETURN