' ========================================================================= ' ' File....... SW20-EX24-74HC165-1.BS2 ' Purpose.... Expanded inputs with 74HC165 ' Author..... (C) 2000 - 2005, Parallax, Inc. ' E-mail..... support@parallax.com ' Started.... ' Updated.... 01 SEP 2005 ' ' {$STAMP BS2} ' {$PBASIC 2.5} ' ' ========================================================================= ' -----[ Program Description ]--------------------------------------------- ' ' This program demonstrates a simple method of turning three BASIC Stamp ' I/O pins into eight digital inputs with a 74HC165 shift register. ' -----[ I/O Definitions ]------------------------------------------------- Clock PIN 0 ' shift clock (74HC165.2) SerData PIN 1 ' serial data (74HC165.7) Load PIN 2 ' input load (74HC165.1) ' -----[ Constants ]------------------------------------------------------- DelayTime CON 100 ' -----[ Variables ]------------------------------------------------------- switches VAR Byte ' switch data ' -----[ Initialization ]-------------------------------------------------- Reset: HIGH Load ' make output and high DEBUG CLS, "Switches 76543210", CR, "-------- --------", CR, "Status ........" ' -----[ Program Code ]---------------------------------------------------- Main: DO GOSUB Get_165 ' get switch inputs DEBUG CRSRXY, 10, 2, BIN8 switches ' display current status PAUSE DelayTime ' pad the loop a bit LOOP ' -----[ Subroutines ]----------------------------------------------------- Get_165: PULSOUT Load, 5 ' load switch inputs SHIFTIN SerData, Clock, MSBPRE, [switches] ' shift them in RETURN