Amiga.org
Amiga computer related discussion => General chat about Amiga topics => Topic started by: haywirepc on January 21, 2012, 09:27:53 PM
-
Can someone tell me, can you turn off or on the printer port lines in amiga basic,
or some other programming language easily?
I have an idea for a simple home automation project, I just need to be able to turn the lines of the printer port low or high.
I know how to do this on a pc, but I never tried it on an amiga.
Any help or doc files would be greatly appreciated.
Thanks,
Steven
-
Yes, but I don't know how. Basic can make system calls so you should be able to do it. I have a book on PC automation with basic programs but its PC based.
I'll pull it out and have a look but I guess it wont translate to Amiga Basic.
-
Okay. No INP() or OUT() commands in Amiga Basic but I think this might help:
http://code.activestate.com/recipes/577750-for-amiga-heads-only-par-as-a-volume-in-read-mode-/
Arex or Python is the way to go. Be much faster than ABasic in any case. i guess.
-
Can someone tell me, can you turn off or on the printer port lines in amiga basic,
or some other programming language easily?
I have an idea for a simple home automation project, I just need to be able to turn the lines of the printer port low or high.
I know how to do this on a pc, but I never tried it on an amiga.
Any help or doc files would be greatly appreciated.
Thanks,
Steven
Might check here http://aminet.net/package/misc/misc/3DHome
There were some cool packages out there to control x-10 stuff, like EZHOME, if you can find it. maybe these have some insight on how they did it. article here thats interesting:
http://www.hometoys.com/htinews/aug98/reviews/hines/AmigaHA.html
this gives a arexx port i think: http://aminet.net/package/driver/other/ARexX-10
which leads to this: http://marrickltd.com:8090/_files/Manuals/MAN105_120.PDF
Mech
-
There's an 8-bit data direction register (DDR) that controlls the direction of the 8 data lines plus an 8-bit register that you read/write input/output states.
There's also three "control" lines which can also be set in direction and read the input state or change the output state.
All of these 8+3 lines can be individually set as inputs or outputs as you want them.
Example in C:
// Amiga register addresses
#define PARALLEL_DDR 0xBFE301 // System address of parallel port data direction register
#define PARALLEL_DATA 0xBFE101 // System address of paralled port data register
#define PAR_CTRL_DDR 0xBFD200 // System address of parallel port control line data direction register
#define PAR_CTRL_DATA 0xBFD000 // System address of parallel port control line data register
// Amiga register values
#define PARALLEL_DATA_OUTPUT 0xFF // Set parallel data direction to output
#define PARALLEL_DATA_INPUT 0x00 // Set parallel data direction to input
#define PARALLEL_CTRL_OUTPUT 0x07 // Set sel, pout, busy as outputs
/**********************************************************
write_data_latch
Writes single byte of data to programmer data latch
Arguments: unsigned char data_to_write
Return: none
Working:
**********************************************************/
void write_data_latch(unsigned char data_to_write)
{
// Write data to port
*parallel_ddr = PARALLEL_DATA_OUTPUT;
*parallel_data = data_to_write;
// Toggle data latch LE
*par_ctrl_data = *par_ctrl_data & (~DATA_LATCH_ON);
*par_ctrl_data = *par_ctrl_data | LATCH_IDLE;
}
Reading input lines is as simple as reading from system address 0xBFE101
Lines that are set as inputs will have a state of 1 or 0 depending on the 5V or 0V input state. If some lines are set as outputs, their current output state will be read in reads to 0xBFE101
That will work just like that, but to be "system friendly", you should declare to have the hardware resource open, then close it when the program exits.
e.g.
// Allocate the parallel port
if (MiscBase=OpenResource(MISCNAME))
{
pport_bits_owner = AllocMiscResource(MR_PARALLELBITS,"Your program name");
pport_port_owner = AllocMiscResource(MR_PARALLELPORT,"Your program name");
// If parallel port was successfully allocated
if ((pport_bits_owner==NULL) && (pport_port_owner==NULL))
{
// Here's where your program does its thing....
}
// Else the parallel port is busy
else
{
printf(" Can't allocate parallel port resources!\n");
printf(" The port may be in use by another application.\n\n");
}
// Clean up resources - do this when your program exits
if (pport_bits_owner==0){FreeMiscResource(MR_PARALLELBITS);}
if (pport_port_owner==0){FreeMiscResource(MR_PARALLELPORT);}
}
Should be easy enough do to in BASIC as well. Been a few years, but I guess it'd be something like:
REM set data lines as outputs
poke(hBFE301, hFF)
REM set output line states to 10101010
poke(hBFE101, hAA)
I can't remember how you state hex numbers in BASIC.
Look on Aminet as well, Barry Walker wrote some demo stuff that shows how to do the same sort of thing in ARexx.
-
Keep in mind that since there's no resource tracking, the parallel port is likely to stay allocated if you break the program.
-
Thanks for everyone's help...
Today, I found out how to use the joystick ports as digital inputs and can read them in amiga basic fine. This means an amiga can make quite an effective burglar alarm...
On the printer port...
I am sure what I need to do can be done, it will require some research. Essentially, I want to hook leds to the the 8 lines and be able to turn them on or off in basic or some other language. I can use some photocells and relays and other electronics to turn on and off whatever I want. I thought this might be a cool use for an a500 I have sitting around not doing much. I had some old hardware projects like this saved from magazines in a binder somewhere, wish I could find that binder now!
Steven
-
@Haywirepc
Slightly off topic, but have you looked at the Arduino? That might be a more fun way to get started :)
-
@haywirepc
It would be probably easier to use the serial port for your Projekt.
You can use the Standard System APIs and with a serial Relay card like this:
http://www.velleman.eu/products/view/?id=351282
You can switch whatever you like, without destroying your Amiga.
-
http://www.velleman.eu/products/view/?id=351282
Did you mean this? Do you think I can control that via the amiga's serial ports by sending serial strings through basic? I saw something like that before where you'd send 8 characters through the serial port (one for each relay). like 00000000 - all off 11111111 - all on. 00000001 - all off but 8 and so on...
Bloodline, yes I just recently saw those arduino boards. I'm very behind on microcontrollers, last one I played with alot was a basic stamp 2. That arduino is like having 3 or 4 basic stamp 2's in one, its really slick. I'm a bit intimidated by the programming language it uses, but I think it may be worth learning for all the options that tiny board has...
Thanks for everyone's suggestions. How do you control leds, lights, relays, whatever using an aimga? Any suggestions welcome!
Steven