An almost useless program

picaxester

Senior Member
Heres a useless little program that I made to make it a bit easier to use the PICAXE chips in Linux :)
Video



It's written in FreeBASIC
Code:
dim as integer i, x, y, buttons
dim shared chip as string
dim as string s, usb, fname
dim text(15) as string

declare sub black

screenres 387,300

draw string (18,21), "08"
draw "BM10,11 D26 R1 D1 R1 D1 R26 U1 R1 U1 R1 U26 L1 U1 L1 U1 L26 D1 L1 D1 L1"
draw string (58,21), "08M"
draw "BM50,11 D26 R1 D1 R1 D1 R34 U1 R1 U1 R1 U26 L1 U1 L1 U1 L34 D1 L1 D1 L1"
draw string (106,21), "14M"
draw "BM98,11 D26 R1 D1 R1 D1 R34 U1 R1 U1 R1 U26 L1 U1 L1 U1 L34 D1 L1 D1 L1"
draw string (154,21), "18"
draw "BM146,11 D26 R1 D1 R1 D1 R26 U1 R1 U1 R1 U26 L1 U1 L1 U1 L26 D1 L1 D1 L1"
draw string (194,21), "18A"
draw "BM186,11 D26 R1 D1 R1 D1 R34 U1 R1 U1 R1 U26 L1 U1 L1 U1 L34 D1 L1 D1 L1"
draw string (242,21), "18X"
draw "BM234,11 D26 R1 D1 R1 D1 R34 U1 R1 U1 R1 U26 L1 U1 L1 U1 L34 D1 L1 D1 L1"
draw string (290,21), "18X1"
draw "BM282,11 D26 R1 D1 R1 D1 R42 U1 R1 U1 R1 U26 L1 U1 L1 U1 L42 D1 L1 D1 L1"
draw string (346,21), "20M"
draw "BM338,11 D26 R1 D1 R1 D1 R34 U1 R1 U1 R1 U26 L1 U1 L1 U1 L34 D1 L1 D1 L1"
draw string (18,62), "28"
draw "BM10,52 D26 R1 D1 R1 D1 R26 U1 R1 U1 R1 U26 L1 U1 L1 U1 L26 D1 L1 D1 L1"
draw string (58,62), "28A"
draw "BM50,52 D26 R1 D1 R1 D1 R34 U1 R1 U1 R1 U26 L1 U1 L1 U1 L34 D1 L1 D1 L1"
draw string (106,62), "28X"
draw "BM98,52 D26 R1 D1 R1 D1 R34 U1 R1 U1 R1 U26 L1 U1 L1 U1 L34 D1 L1 D1 L1"
draw string (154,62), "28X1"
draw "BM146,52 D26 R1 D1 R1 D1 R42 U1 R1 U1 R1 U26 L1 U1 L1 U1 L42 D1 L1 D1 L1"
draw string (210,62), "28X1_0"
draw "BM202,52 D26 R1 D1 R1 D1 R58 U1 R1 U1 R1 U26 L1 U1 L1 U1 L58 D1 L1 D1 L1"
draw string (282,62), "28X_1"
draw "BM274,52 D26 R1 D1 R1 D1 R50 U1 R1 U1 R1 U26 L1 U1 L1 U1 L50 D1 L1 D1 L1"
draw string (346,62), "USB"
draw "BM338,52 D26 R1 D1 R1 D1 R34 U1 R1 U1 R1 U26 L1 U1 L1 U1 L34 D1 L1 D1 L1"
draw string (338,104), "EXIT"
draw "BM330,94 D26 R1 D1 R1 D1 R42 U1 R1 U1 R1 U26 L1 U1 L1 U1 L42 D1 L1 D1 L1"
draw string (258,104), "COMPILE"
draw "BM250,94 D26 R1 D1 R1 D1 R66 U1 R1 U1 R1 U26 L1 U1 L1 U1 L66 D1 L1 D1 L1"
'draw string (18,104), "PROGRAM NAME AND OUTPUT"
draw "BM10,94 D26 R1 D1 R1 D1 R226 U1 R1 U1 R1 U26 L1 U1 L1 U1 L226 D1 L1 D1 L1"

chip = "./picaxe08"
usb = " -c/dev/ttyS0 "

do while inkey$ = ""

	do while buttons < 1
		getmouse (x, y, , buttons)
		s = inkey$
		if s = chr(255) & "k" then end
		if s = chr(27) then end
		sleep 10
	loop
	
	'08
	if x > 10 and x < 40 and y > 11 and y < 41 then
		black
		draw "BM12,13 P8, 15"
		chip = "./picaxe08"
		
	'08M
	elseif x > 50 and x < 88 and y > 11 and y < 41 then
		black
		draw "BM52,13 P8, 15"
		chip = "./picaxe08m"
		
	'14M
	elseif x > 98 and x < 136 and y > 11 and y < 41 then
		black
		draw "BM100,13 P8, 15"
		chip = "./picaxe14m"
		
	'18
	elseif x > 146 and x < 176 and y > 11 and y < 41 then
		black
		draw "BM148,13 P8, 15"
		chip = "./picaxe18"
		
	'18A
	elseif x > 186 and x < 224 and y > 11 and y < 41 then
		black
		draw "BM188,13 P8, 15"
		chip = "./picaxe18a"
		
	'18X
	elseif x > 234 and x < 272 and y > 11 and y < 41 then
		black
		draw "BM236,13 P8, 15"
		chip = "./picaxe18x"
		
	'18X1
	elseif x > 282 and x < 328 and y > 11 and y < 41 then
		black
		draw "BM284,13 P8, 15"
		chip = "./picaxe18x_1"
		
	'20M
	elseif x > 338 and x < 376 and y > 11 and y < 41 then
		black
		draw "BM340,13 P8, 15"
		chip = "./picaxe20m"
		
	'28
	elseif x > 10 and x < 40 and y > 52 and y < 82 then
		black
		draw "BM12,54 P8, 15"
		chip = "./picaxe28"
		
	'28A
	elseif x > 50 and x < 88 and y > 52 and y < 82 then
		black
		draw "BM52,54 P8, 15"
		chip = "./picaxe28a"
		
	'28X
	elseif x > 98 and x < 136 and y > 52 and y < 82 then
		black
		draw "BM100,54 P8, 15"
		chip = "./picaxe28x"
		
	'28X1
	elseif x > 146 and x < 192 and y > 52 and y < 82 then
		black
		draw "BM148,54 P8, 15"
		chip = "./picaxe28x1"
		
	'28X1_0
	elseif x > 202 and x < 264 and y > 52 and y < 82 then
		black
		draw "BM204,54 P8, 15"
		chip = "./picaxe28x1_0"
		
	'28X_1
	elseif x > 274 and x < 328 and y > 52 and y < 82 then
		black
		draw "BM276,54 P8, 15"
		chip = "./picaxe28x_1"
		
	'USB
	elseif x > 338 and x < 376 and y > 52 and y < 82 then
		if usb = " -c/dev/ttyS0 " then
			draw "BM340,54 P8, 15"
			usb = " "
		elseif usb = " " then
			draw "BM340,54 P0, 15"
			usb = " -c/dev/ttyS0 "
		end if
		
	'EXIT
	elseif x > 330 and x < 376 and y > 94 and y < 124 then
		end
		
	'COMPILE
	elseif x > 250 and x < 320 and y > 94 and y < 124 then
		locate 17, 1
		for i = 1 to 15
			print "                                               "
		next i
		locate 1, 20
		print "Wait..."
		open pipe "cd ~; cd Documents/PICAXE; sudo " & chip & usb & fname for input as #1
		for i = 1 to 15
			line input #1, text(i)
		next i
		
		locate 17, 1
		for i = 1 to 15
			if text(i) > "" then
				print text(i)
			end if
		next i
		
		close #1
		
		locate 1, 20
		print "       "
		
	'FILE NAME
	elseif x > 10 and x < 208 and y > 94 and y < 124 then
		locate 14, 3
		print "                            "
		locate 14, 3
		input "", fname
		
	
	end if
	

    getmouse (x, y, , buttons)
    do while x > 1 and buttons > 0
    	getmouse (x, y, , buttons)
    	sleep 10
    loop
loop

Sub black()
	chip = ""
	draw "BM12,13 P0, 15"
	draw "BM52,13 P0, 15"
	draw "BM100,13 P0, 15"
	draw "BM148,13 P0, 15"
	draw "BM188,13 P0, 15"
	draw "BM236,13 P0, 15"
	draw "BM284,13 P0, 15"
	draw "BM340,13 P0, 15"
	draw "BM12,54 P0, 15"
	draw "BM52,54 P0, 15"
	draw "BM100,54 P0, 15"
	draw "BM148,54 P0, 15"
	draw "BM204,54 P0, 15"
	draw "BM276,54 P0, 15"
End Sub
 
Last edited:

picaxester

Senior Member
Heres the program if anyone wants to try it :)
You can run it from any directory but the .bas file and the compilers have to be in: Documents/PICAXE
 

picaxester

Senior Member
I think I first started with QBasic then got into PICAXE then FreeBASIC.
It's pretty close to the same thing.

I made a .bi library file for FreeBASIC to make using the parallel port like a PICAXE.
So for I've made functions for:
pins
pinsc
pin0 - pin4
high 0 - high 11
low 0 - low 11
toggle 0 - toggle 11
pulsout 0 - pulsout 11
And some functions for 8 bit parallel LCDs:
lcdinit
lcdchr "string"
lcdins instruction

Code:
#define pins out 888,

sub pinsc(pin as integer)
	select case pin
		case 0
			out 890, &b1011		'1011
		case 1
			out 890, &b1010		'1011
		case 2
			out 890, &b1001		'1011
		case 3
			out 890, &b1000		'1011
		case 4
			out 890, &b1111		'1011
		case 5
			out 890, &b1110		'1011
		case 6
			out 890, &b1101		'1011
		case 7
			out 890, &b1100		'1011
		case 8
			out 890, &b0011		'1011
		case 9
			out 890, &b0010		'1011
		case 10
			out 890, &b0001		'1011
		case 11
			out 890, &b0000		'1011
		case 12
			out 890, &b0111		'1011
		case 13
			out 890, &b0110		'1011
		case 14
			out 890, &b0101		'1011
		case 15
			out 890, &b0100		'1011
	end select
end sub

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
 

jc173

Member
I've downloaded FreeBASIC and it's confusing......
Opened the programme and it just gives me a DOS prompt...:confused:
 
Top