View previous topic :: View next topic |
Author |
Message |
Turd HG Ruler

Joined: 18 Aug 2007 Posts: 274 Location: Saskatchewan, Canada
|
Posted: Mon Nov 10, 2008 1:03 pm Post subject: easypport.bi |
|
|
Heres a .bi I made to make it easier to use the parallel port in FreeBASIC
easypport.bi
Code: | #define pins out 888,
function pin0() as integer
if inp(889) and 8 then
return 1
else
return 0
end if
end function
function pin1() as integer
if inp(889) and 16 then
return 1
else
return 0
end if
end function
function pin2() as integer
if inp(889) and 32 then
return 1
else
return 0
end if
end function
function pin3() as integer
if inp(889) and 64 then
return 1
else
return 0
end if
end function
function pin4() as integer
if inp(889) and 128 then
return 0
else
return 1
end if
end function
sub high(pin as integer)
dim as integer i
if pin < 8 then
i = bitset(0, pin)
if not inp(888) and i then
out 888, inp(888) + i
end if
elseif pin = 8 or pin = 9 or pin = 11 then
pin = pin - 8
i = bitset(0, pin)
if inp(890) and i then
out 890, inp(890) - i
end if
elseif pin = 10 then
pin = pin - 8
i = bitset(0, pin)
if not inp(890) and i then
out 890, inp(890) + i
end if
end if
end sub
sub low(pin as integer)
dim as integer i
if pin < 8 then
i = bitset(0, pin)
if inp(888) and i then
out 888, inp(888) - i
end if
elseif pin = 8 or pin = 9 or pin = 11 then
pin = pin - 8
i = bitset(0, pin)
if not inp(890) and i then
out 890, inp(890) + i
end if
elseif pin = 10 then
pin = pin - 8
i = bitset(0, pin)
if inp(890) and i then
out 890, inp(890) - i
end if
end if
end sub
sub toggle(pin as integer)
dim as integer i
if pin < 8 then
i = bitset(0, pin)
if inp(888) and i then
out 888, inp(888) - i
elseif not inp(888) and i then
out 888, inp(888) + i
end if
elseif pin > 7 and pin < 12 then
pin = pin - 8
i = bitset(0, pin)
if inp(890) and i then
out 890, inp(890) - i
elseif not inp(890) and i then
out 890, inp(890) + i
end if
end if
end sub
sub pulsout(pin as integer, tm as integer)
toggle pin
sleep tm, 1
toggle pin
sleep tm, 1
end sub
sub lcdchr(s as string)
dim as integer i
for i = 1 to len(s)
high 9
pins asc(mid(s, i, 1))
pulsout 8, 1
next i
end sub
sub lcdins(d as integer)
low 9
pins d
pulsout 8, 1
end sub
sub lcdinit()
pins 0
out 890, 11
sleep 300
pins 56
pulsout 8, 1
sleep 50
pulsout 8, 1
pulsout 8, 1
pins 128
pulsout 8, 1
pins 14
pulsout 8, 1
end sub
|
Commands are:
Code: | #include "easypport.bi"
'pins ouputs 0 - 7 (data port)
'eg
pins 255 'make the eight pins go high
'pin0 inputs 0, 1, 2, 3, 4 (status port)
'eg
if pin2 = 1 then print "pin2 is high"
'high 0 make an output pin high. outputs 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
'eg
high 5 'makes pin 5 high
'low 0 make an output pin low. outputs 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
'eg
low 8
'toggle 0 toggles an output pin. makes a pin high if it's low and makes it low if it's high
'eg
toggle 2
'pulsout 0, 0 pulses an output pin. if the pin is low it will be brought high and then low for a difined time
'eg
pulsout 5, 1 'pulse output 5 for 1ms
'lcdinit initialises a 1x16 or 2x16 character lcd
'eg
lcdinit
'lcdins send an instruction to an lcd
'eg
lcdins 1 'send the "clear display" instruction to the lcd
'lcdchr send characters to an lcd
'eg
lcdchr "Hello"
|
Heres a test program for a 1x16 or 2x16 character LCD.
Code: | #include "easypport.bi"
'outputs 0 - 7 on parallel port go to pin 7 - 14 on the lcd through 330 ohm resistors
'output 8 on the parallel port goes to pin 6 on the lcd through 330 ohm resistors
'output 9 on the parallel port goes to pin 5 on the lcd through 330 ohm resistors
'pin 5 on the lcd is grounded
lcdinit 'initialise the lcd
lcdins 1 'send the "clear display" instruction to the lcd
do while inkey$ = ""
lcdins 128 'move cursor to the start of the first line
lcdchr time 'send some characters to the lcd
sleep 1000
loop
pins 0 'make outputs on the data port low
out 890, 11 'make outputs on the control port low
'1 Clear display and move to the start of the first line
'2 Move the cursor and display ‘window’ to the start of the first line
'4 Set ‘right to left printing’ mode
'5 Set ‘scroll printing to the left’ mode
'6 Set ‘left to right printing’ mode
'7 Set ‘scroll printing to the right’ mode
'10 Turn visual LCD screen off
'12 Hide cursor
'13 Make cursor flash
'14 Turn visual LCD screen (and cursor) on
'16 Move cursor left one position
'20 Move cursor right one position
'24 Scroll display ‘window’ left one position
'28 Scroll display ‘window’ right one position
'128 Move cursor to the start of the first line
'192 Move cursor to the start of the second line |
 |
|
Back to top |
|
 |
|
 |
Alan Site Admin

Joined: 29 Jan 2006 Posts: 1399 Location: Winnipeg, MB
|
Posted: Mon Nov 10, 2008 6:56 pm Post subject: |
|
|
Nice writeup. Is this the language that you used?
http://www.freebasic.net/
Looks like port manipulation is implemented quite nicely in that language. Are you going to make a CPU usage monitor using this display? |
|
Back to top |
|
 |
Turd HG Ruler

Joined: 18 Aug 2007 Posts: 274 Location: Saskatchewan, Canada
|
Posted: Mon Nov 10, 2008 7:23 pm Post subject: |
|
|
Yep, FreeBASIC is great, there's a compiler for Windows, Linux and even DOS.
Quote: | Are you going to make a CPU usage monitor using this display? | I'm going to try do some cool stuff
eric
Last edited by Turd on Fri Nov 14, 2008 6:10 am; edited 1 time in total |
|
Back to top |
|
 |
Turd HG Ruler

Joined: 18 Aug 2007 Posts: 274 Location: Saskatchewan, Canada
|
Posted: Fri Nov 14, 2008 6:07 am Post subject: |
|
|
I got the temperature and time working in Ubuntu Linux:
Code: | #include "easypport.bi"
dim as string temp
lcdinit
lcdins 1
do while inkey$ = ""
lcdins 128
Open Pipe "cat /proc/acpi/thermal_zone/THRM/temperature" For Input As #1
Line Input #1, temp
lcdchr right(temp, 4)
close #1
lcdins 192
lcdchr time
sleep 1000
loop
pins 0
out 890, 11 |
btw. I get a lot of help from the people at the FreeBASIC forum.
eric |
|
Back to top |
|
 |
Alan Site Admin

Joined: 29 Jan 2006 Posts: 1399 Location: Winnipeg, MB
|
Posted: Fri Nov 14, 2008 7:13 pm Post subject: |
|
|
Looks good. Where is the temperature coming from? |
|
Back to top |
|
 |
Turd HG Ruler

Joined: 18 Aug 2007 Posts: 274 Location: Saskatchewan, Canada
|
Posted: Fri Nov 14, 2008 7:35 pm Post subject: |
|
|
"cat /proc/acpi/thermal_zone/THRM/temperature" in Ubuntu. I think the sensor is in the possessor.
eric |
|
Back to top |
|
 |
Turd HG Ruler

Joined: 18 Aug 2007 Posts: 274 Location: Saskatchewan, Canada
|
Posted: Fri Nov 28, 2008 7:26 pm Post subject: |
|
|
GadgetGangster is selling a kit and theres a pdf how-to there too
eric |
|
Back to top |
|
 |
Turd HG Ruler

Joined: 18 Aug 2007 Posts: 274 Location: Saskatchewan, Canada
|
Posted: Tue Mar 10, 2009 3:17 pm Post subject: |
|
|
I'm working on a gui program for that parallel port/LCD circuit
Not everything works though.
eric |
|
Back to top |
|
 |
Turd HG Ruler

Joined: 18 Aug 2007 Posts: 274 Location: Saskatchewan, Canada
|
Posted: Sat Mar 28, 2009 12:48 pm Post subject: |
|
|
Heres the Linux version.
I don't know how to get the temperature in Windows yet. If anyone knows how let me know. _________________ eric |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|