SB BBC @ GBR Oldie hints/tips #028-031 Hints and tips from the archives of Wakefield BBC Micro User Group... 28. User port experimenting (1) ~~~~~~~~~~~~~~~~~~~~~~~~~~~ The User Port is controlled by a very versatile little chip called a 6522 VIA, (Versatile Interface Adapter), which also looks after the Centronics printer port. You have 20 connector pins available, consisting of 8 connected to 0 Volts, 2 connected to +5 Volts, 2 handshake lines, (CB1 and CB2), and the 8 Input/Output lines PB0 to PB7. These lines default as inputs fairly similar to the 74L series low-power TTL gates. If you check them with a multimeter, you will find that they float high to about +3 Volts, just like a TTL input. The status of these 8 lines is read into location &FE60, so if you interrogate it with PRINT ?&FE60, you will get 255 Decimal, which is FF in Hex and 11111111 in Binary. If you were to short-circuit PB0 to 0 Volts, then you would get 254 Decimal, or 11111110 Binary. Similarly, if you short PB1 instead, you get 253 or 11111101, and if you short the lot together, you get 0, or 00000000 in Binary. It will be obvious by now that it is convenient to 'look' at &FE60 in Binary, as it gives a direct representation of what is happening on the pins. If you wish to test the status of one particular pin, ie one binary bit, then use the logical AND to 'mask' out the other bits, and then divide it by itself to turn it into a 1 or 0. Thus, to test PB1, use PRINT (?&FE60 AND 2)DIV2. More generally, to test pin PBn%, where n% is 0 to 7, use p%=2^n%:PRINT (?&FE60 AND p%)DIV p%. If you stick a minus sign in front of the expression (?&FE60 etc...), then it will return the value TRUE for logic high, and FALSE for 0. Always use integer variables to avoid silly rounding errors, and to increase speed. This short program displays the status of the pins in Decimal, Hex and Binary, enabling you to watch what happens when you pull various inputs low. You can also drive them up to +5 Volts like any TTL gate, and they source only 0.8 mA when low, so you can drive them from +5 Volt CMOS logic if you want. If you do have an accident, a new 6522 VIA isn't too expensive! 10 MODE 7:VDU23,1,0;0;0;0;:REM * Cursor off * 20 PRINT TAB(5,8)"Decimal"TAB(16,8)"Hex"TAB(25,8)"Binary" 30 REPEAT port%=?&FE60:REM * Read Port * 40 PRINT TAB(7,10);port%" "TAB(16,10);~port%" "TAB(24,10); 50 FOR pb%=7 TO 0 STEP-1 60 power%=2^pb%:REM * Read each bit * 70 PRINT;(port% AND power%)DIV power%; 80 NEXT:UNTIL FALSE 29. User port experimenting (2) ~~~~~~~~~~~~~~~~~~~~~~~~~~~ The previous program examines the User Port inputs via location &FE60. However, by writing to &FE62 you can nominate pins as outputs instead, and they will default to logic LO, which you can check with the previous program, and confirm with a multimeter. This program asks you which bits are to be outputs, so enter 0237 or 134 or whichever bits you want, in any order. If you just press without entering anything, all pins will be reset as inputs. Strangely, so it might seem, you alter the output states by writing to &FE60; the pins set as inputs will ignore this, so no need to worry on that score. In other words, ?&FE60=255 would set all outputs to logic HI without affecting the inputs, and so if you PRINT ?&FE60 afterwards, you will see the effect. Try combining the two programs, and add a few bits of your own to make a more complete experimenting program. 10 PRINT ?&FE62:INPUT"Which ones for output? " output$ 20 FOR pb%=0 TO 7:power%=2^pb% 30 IF INSTR(output$,STR$(pb%))>0 THEN ?&FE62=?&FE62 OR power% ELSE ?&FE62=?&FE62 AND (255-power%) 40 NEXT:PRINT ?&FE62 30. Program verify ~~~~~~~~~~~~~~ To see if a BASIC program has been successfully SAVEd to tape, without losing the current program from memory, type *LOAD "" 8000 , (note the empty quotes). This works well for programs of not more than 16k in length, as it is simply trying to 'write' into the BASIC ROM, which it cannot do. However, all the normal error-checking of the tape data takes place, accompanied by the usual "Searching" and "Loading" messages. If you have sideways RAM, then you should operate the write-protect switch to avoid garbage being written into the RAM. 31. Tape reset ~~~~~~~~~~ If you have a DFS fitted, then pressing will cause a "warm" reset to the cassette filing system. This is quicker than pressing followed by typing *T. . The cursor will step a few spaces to the right, but this is harmless; press if it bothers you. 73 Rick G4BLT @ GB7WRG