Deja News Toolbar BuyDirect BuyDirect message/thread Message 44 of 191 for search * return to search results help User port Author: Alan - VE3NNM Date: 1999/02/20 Forum: comp.sys.cbm sponsored by: eBay more headers author posting history post reply prev next _________________________________________________________________ !From: "Martin Gunnarsson" !Newsgroups: comp.sys.cbm !Subject: User port !X-Newsreader: Microsoft Outlook Express 4.72.3110.5 !Message-ID: <1Zmz2.857$94.1487@nntpserver.swip.net> !NNTP-Posting-Host: 130.244.169.51 !X-Complaints-To: news-abuse@swip.net !X-Trace: nntpserver.swip.net 919468989 130.244.169.51 (Sat, 20 Feb 1999 01:03:09 MET DST) !Organization: A Customer of Tele2 !X-Sender: s-217240@dialup169-1-51.swipnet.se !Date: Sat, 20 Feb 1999 01:04:20 +0100 > Hey again > As you might recall I posted some messages here some time ago about > the user port on the C64. > I really appreciate the help I got building my relay-card. > Now I just realised I've run into a new problem. > As default all the 8 pins (pb0-pb7) is set as inputs. That way > there's 5V between every pin and the ground. It would be pretty bad > if all the relays (one for each pin) would be open before the > program loads. Actually it could cause pretty much troble. Although you are correct that the User Port's pins float at around +5 volts when they are configured as inputs and not connected to anything, I doubt if they would have sufficient current capacity to drive a circuit. There are no pull-up resistors connected to the PB0 - PB7 pins, that +5 volts is simply a residual voltage coming from the 6526 chip those pins are connected to. I haven't made any measurements, but I suspect that as soon as you attempted to load the pins with anything other than a high-impedance voltage comparator, or perhaps certain very high-impedance MOS families, that +5 volts would quickly sag or even dissapear completely (when they're configured as INPUTS only, of course). But that's not so great either, since it could leave your connected equipment in some un-defined logic state. But I certainly support your concerns. When I constructed several interfaces for electronics, Amateur Radio and remote-control use, I also was aware of that undefined state when the pins are set for input, and I would consider it poor design practice not to take it into account. I was off-hooking phone lines and activating transmitters and such, and the last thing I wanted was to have something "lock on" due to a computer reset from a power bump or whatever. I chose to use active-low outputs from the User Port in order to activate the connected peripheral. That is, the connected equipment only "turns on" when the user port pin is commanded to go low by the software. This prevents false tripping when the computer is first powered up, since you have to set the Data-Direction Register AND command the User Port's pins to go low before anything will happen at your connected equipment. There is one other advantage to using active-low outputs. The 6526 MOS chip's pins are capable of only 0.2 mA in high state, but can handle 3.2 mA when low. If you're driving CMOS chips or one or two TTL gates this isn't such a problem, but if your driving NPN transistors you'll find yourself a little short on current. I suggest you have the User Port drive a buffer chip such as the 74LS04 inverter, and place 10K pull-up resistors on the '04's INPUT pins in order to give the chip a defined logic state when the User Port's pins are floating. The 6526 can easily pull the combined current of the '04's input pins and pull-up resistors to ground. Another advantage of using a buffer chip is, if anything screws up on your interface board, it'll be the cheap 74LS04 chip that takes the hit, and not your precious 6526. > So now I was wondering if there's some kind of "flag pin" or some > other way I can find out if a pin is set to input or output. > Otherwise I'll just have to use a manual switch and turn on the > realy card after the program is loaded. In order to set all pins (PB0 through PB7) to outputs, simply poke the value 255 into the DDR (Data Direction Register) at location 56579: POKE 56579,255 If you ever need to determine the status of the DDR, simply PEEK(56579) to extract the numeric value. But once set, it won't change unless you tell it to (or the computer crashes!). You might wish to select certain pins for outputs, and others for inputs - this can be done by assigning each pin the following values: PB0=1 PB1=2 PB2=4 PB3=8 PB4=16 PB5=32 PB6=64 PB7=128 These numbers represent the value needed to turn each pin to an output. You add up the values of the pins you want to set to output, and POKE that value into the DDR at location 56579. examples: PB6 only (64) as output POKE 56579,64 PB1, PB4 and PB6 (2 + 16 + 64) as outputs POKE 56579,82 Default - all pins as inputs POKE 56579,0 Determining exactly which pins are set to input or output by PEEKing the DDR can involve some math - unless it's easy, like 0 or 255. :) You'll need to read up on the use of CBM BASIC's "AND" command, and learn how to use it with a numeric value to manipulate the result of a PEEK operation. I'm a little foggy on the methood (it's been a while), but I think you just AND the result of the PEEK operation with the numeric value of the pin. Example: REM CHECK DDR STATUS OF PB6 DD=PEEK(56579) IF DD AND 64 THEN <...> : REM EXECUTE IF PB6 IS OUTPUT The IF/THEN would be executed if PB6 (64) was an output, if it's false the program would go to the next line. To check to see if they're all set as outputs: REM CHECK STATUS OF DDR DD=PEEK(56579) IF DD=255 THEN <...> : REM EXECUTE IF PB0 THROUGH PB7 ARE OUTPUTS If I'm wrong on this, I'm sure there will be several people ready to correct me... ;) > Well, I'm greatful for any help I can get on this one. > Regards > Martin Gunnarsson -- +++++++++++++++++++++++++++++++++++++++++ From the keyboard of Alan - VE3NNM email: ve3nnm AT excite DOT com ------------------------------------------------------------------- Posted using NetTamer | The TRUTH about Micro$oft http://www.nettmamer.net/tamer.html | http://www.vcnet.com/bms/ ------------------------------------------------------------------- _________________________________________________________________ view for bookmarking text only mail this message to a friend post reply << prev · next >> subscribe to comp.sys.cbm SPONSORED LINKS Yellow Pages · Bid on Bargains · Express by Infoseek · Shopping · Free Stuff AutoConnect · Trade with Datek · Auctions & Classifieds · GET IT NOW @ NECX Home · Communities · My Deja News · Power Search · Post About Deja News · Ad Info · Our Advertisers ____________________________________________________ Copyright © 1995-99 Deja News, Inc. All rights reserved. Conditions of use · Site privacy statement reviewed by TRUSTe