fl fswrite lcdserlnk.f decimal { LCD Serial Link Routines to setup a serial process in a cog to permit writing to a serial enabled LCD. You initialize the serial cog with 'startLCD' and display text with 'strlnk' (still to be completed - a thoroughly annotated demo). All display routines start with a 'maklnk' and conclude with 'brklnk', which, effectively, turns console mirroring on then off. v 1.0 - 3 Oct 2011 Brian Riley, Underhill Center, VT, USA v 1.1 - 4 Oct 2011 added formatted print for dec, hex, bin } { create console link to LCD using cog 4 maklnk ( -- ) } : maklnk 4 cogid swap iolink ; { break console link to LCD brklnk ( -- ) - the 10 ms delay at beginning MUST be there to give the iolink routines time to flush its buffer } : brklnk 10 delms cogid iounlink ; { display string ( cstr -- ) - based upon string write word from CasKaz's parallel LCD routines } : strlnk maklnk C@++ dup if bounds do i C@ emit loop else 2drop then brklnk cr ; { clear/home screen of LCDpa clrlcd ( -- ) - "?f" is the string for a Peter Anderson serial LCD chip, edit this to your flavor } : clrlcd c" ?f" strlnk ; { initiate serial process in cog 4 startLCD ( -- ) - by using the same pin spec for tx and rx, pin 7, you get a simple loopback and mirroring of main console whenever iolink is active } : startLCD 7 7 19200 4 startserialcog 10 delms clrlcd ; { Formatted display words for dec, hex, and bin - routines taken directly from LCD Parallel code the only changes needed were to change each 'LCD_charout' call to an 'emit' and add the 'maklnk' and 'brklnk' calls } hex \ display decimal number to covert hex (n -- ) n:hex-value variable tmp wvariable result { decimal ( n1 n2 -- ) n1 - number to be displayed n2 - number of digit positions - if you give it 123456 and specify 4 digits it will print 3456 - the minus sign in neg numbers counts as one of the digit positions } : declnk maklnk 0 result W! 3b9aca00 tmp L! swap dup 80000000 and if \ check neg, "-" invert 1+ 2d emit swap 1- else swap then dup a swap - 0 do tmp L@ a u/ tmp L! loop \ shrink loop to n2 0 do dup tmp L@ >= if tmp L@ u/mod 30 + else 30 then emit tmp L@ a u/ tmp L! loop drop brklnk cr ; \ display hex number (n1 n2 -- ) n1:hex-value n2:digits(1 to 8) : hexlnk maklnk dup rot2 8 swap - 2 lshift lshift swap 0 do dup f0000000 and 1c rshift dup a < if 30 + else 37 + then emit 4 lshift loop drop brklnk cr ; \ display binary number (n1 n2 -- ) n1:hex-value n2:digits(1 to 10) : binlnk maklnk dup rot2 20 swap - lshift swap 0 do dup 80000000 and if 31 else 30 then emit 1 lshift loop drop brklnk cr ; ...