I have attached my draft library for the k107. I still have to put in
the descriptive text but the library does compile but is, as of today,
untested.
I am sending it now so that TPTB (The Powers That Be) can make
suggestions as to what has to be changed to conform to your standards.
Please be critical! I want to learn! I won't mind a kick in the butt if
I deserve it.
Thanks
Wayne
-- -----------------------------------------------------------------------------
-- Title: LCD library for the k107 Serial Backpack
-- Author: Wayne Topa, Copyright (c) 2008..2009, all rights reserved.
-- Adapted-by:
-- Compiler: >=2.4k
--
-- This file is part of jallib (http://jallib.googlecode.com)
-- Released under the ZLIB license (http://www.opensource.org/licenses/zlib-license.html)
--
-- Sources:
--
-- Description:
-- Serial interface for K107 (and similar) serial LCD backpack for
-- 2x16 to 4x20 HD44780 compatible alphanumeric LCD displays.
-- .
-- Expects: - 1 pin from Pic to K107
-- .
-- Directions for use of this library in application programs
-- (in this sequence):
-- define in calling program or here ???
const byte K107_CHARS = 20
var byte i
-- var byte cmd[]
procedure k107_init(byte in geo) is
var byte cmd[]
case geo of
216: block const byte cmd[] = "?G216" end block
220: block const byte cmd[] = "?G220" end block
224: block const byte cmd[] = "?G224" end block
240: block const byte cmd[] = "?G240" end block
416: block const byte cmd[] = "?G416" end block
420: block const byte cmd[] = "?G420" end block
end case
for 5 using i loop
serial_sw_write(cmd[i])
end loop
-- delay required when writing to K107 EEPROM
delay_100ms(2)
end procedure
-- Tab size can be 1-8
procedure k107_tabsize(byte in tab) is
serial_sw_write("?")
serial_sw_write("s")
serial_sw_write(tab)
delay_100ms(2)
end procedure
procedure k107_cursor_style(byte in c_style) is
serial_sw_write("?")
serial_sw_write("c")
serial_sw_write(c_style)
delay_100ms(2)
end procedure
-- Back Light settings 00 to FF hex. Use 80 or less normally
procedure k107_backlight(byte in bl) is
serial_sw_write("?")
serial_sw_write("s")
serial_sw_write(bl)
end procedure
-- goto line
procedure k107_goto_line(byte in ln) is
serial_sw_write("?")
serial_sw_write("y")
serial_sw_write(ln)
end procedure
-- goto column
procedure k107_goto_column(byte in cl) is
serial_sw_write("?")
serial_sw_write("x")
serial_sw_write(cl)
end procedure
-- home cursor
procedure k107_home() is
serial_sw_write("?")
serial_sw_write("a")
end procedure
-- CLRF, cursor at start of line, line cleared
procedure k107_clrf() is
serial_sw_write("?")
serial_sw_write("n")
end procedure
-- tab, advances display one tab postiion
procedure k107_tab() is
serial_sw_write("?")
serial_sw_write("t")
end procedure
-- carrage return, cursor to start of current line
procedure k107_CR() is
serial_sw_write("?")
serial_sw_write("m")
end procedure
-- clear current line, cursor to start of current line
procedure k107_clr_line_home() is
serial_sw_write("?")
serial_sw_write("l")
end procedure
-- clear screen and leave cursor at home position
procedure k107_clear() is
serial_sw_write("?")
serial_sw_write("f")
end procedure
-- Non-destructive backspace
procedure k107_cur_back_1_no_del() is
serial_sw_write("?")
serial_sw_write("h")
end procedure
-- destructive backspace
procedure k107_cur_back_1_del() is
serial_sw_write("?")
serial_sw_write("b")
end procedure
-- forward cursor
procedure k107_cur_forward_1() is
serial_sw_write("?")
serial_sw_write("i")
end procedure
-- down cursor
procedure k107_cur_down_1() is
serial_sw_write("?")
serial_sw_write("j")
end procedure
-- up cursor
procedure k107_cur_up_1() is
serial_sw_write("?")
serial_sw_write("k")
end procedure
Yes, I remembered as soon as i read it, lcd_k107.jal it is
> """
> <device-family>_<device>.jal for external libraries [this is the case here,
> right ?]. device-family describes the device family (...), and is often the
> directory name where the lib is. device precisely sets the part.
>
> Ex: lcd_hd44780_4.jal, rtc_ds1302.jal, co2_t6603.jal
> """
I have renamed all procedures per your examples.
>
> JSG validator also says ("jallib validate k107.jal"):
>
> """
> File: k107.jal
> 2 errors found
> ERROR: Cannot find end of field content Description
> ERROR: 105: Found Capitals in token: 'k107_CR'
>
> 0 warnings found
> """
>
> Mmmh... OK, so "k107_CR" should be "k107_cr". This other error is trickier:
> it can't find "Description" field, while there's one ! Why ? Actually, it
> can find the end of the section, so the whole section is ignored. Adding a
^^ do you mean can't??
> "--" at the end fixes the problem:
>
> -- Directions for use of this library in application programs
> -- (in this sequence):
> -- <==== THIS ONE :)
Sorry I'm not understanding that-----
k107_CR has been changed to lcd_k107_cr
>
> About k107_init, it takes an argument for the geometry. I guess it describes
> the number of rows and columns. Ex: 416 is a 4 rows and 16 columns LCD,
> right ? I would have preferred specifying rows and cols separately, maybe
> more user-friendly. But that's a matter of taste !
>
As the k107 only accepts 6 different geometrys, I thing it is better
if this is changed to lcd_k107_init(byte geo) , The gom arg would be a
number between 1 & 6.
> Thinking again about your "case" impl., I wonder how defining both "var byte
> cmd[]" and "const byte cmd[]" behaves... More, if "geo" can be 416 or 420,
> then it must be a "word", not a "byte". And here I've found interesting
> things... Here's a program I've written including unittest:
Yes I forgot to change it when the if,elseif code would not compile.
All the unittest is interesting but I can't get that to run here.
>
I keep coming up with very strand errors when using the library.
ie:
const byte LCD_CHARS =20 (Which is also declared in serial_sw_write)
which I include before the lcd_k107
If I declare it in the sample program, I get errors in the lcd_k107.jal
LCD_CHARS not declared
If I declare it in the library
var byte init1[LCD_CHARS] = "?G216" -- Compiler says constant expected
But it seems to work ok in the sample 16f648a_lcd_hd44780_4_1.jal which
it that way.
var byte line1[LCD_CHARS] = "<= 2 x 16 LCD =>"
Maybe the compiler does not like the? (?????)
I tried to replace the case part of lcd_k107_init with the it/elseif
and I get elseif not declared. It's in the use guide so I must just be
screwing things up. I don't know how tho.
I plan to put the lib aside, for now, and concetrate on the sample
program. I will switch to assembly if necessary. I have 8-10 LCD's and
4 K107's so I have to get something working soon. I am not getting younger.
Thanks for the pointers Seb. I really appreciate the guidance.
Regards
Wayne
Because I did not find any samples of how to use print.jal or format.jal
with serial_sw_write. I don't really understand enough to figure that out.
I would like to know if they would work though.
--
You received this message because you are subscribed to the Google Groups "jallib" group.
To post to this group, send email to jal...@googlegroups.com.
To unsubscribe from this group, send email to jallib+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jallib?hl=en.
Iirc I did not send you the code yet (so it is long overdue...)
Procedure PwmIrLed() acts like the pin for software_serial. But it is
not just a pin, it enables and disables pwm on ccp2. And it s ets the
pwm-pin c1 low when pwm is turned off, so the leds are actually off
(and not continuous on).
Joep
PS I changed the serial_software timing. Can you verify if it works
okay now for your k017 library?
-- ir_sender.jal
-- PwmIrLed - pulse led @ 56kHz or put it off.
procedure PwmIrLed'put(bit in ii) is
if (ii) then
ccp2con = 0x0c ; pwm mode on
else
ccp2con = 0x00 ; pwm mode off
pin_c1 = low
end if
end procedure
-- ----------------------------------------------------------------------------
; setup serial_sw to pulse the IrLed
const bit serial_sw_invert = false
const serial_sw_baudrate = 1200
const serial_sw_stopbits = 0 -- don't send stop bits (actually, don't let the
-- serial routine *wait* for the stop bit)
var bit serial_sw_rx_pin
alias serial_sw_tx_pin is PwmIrLed
include serial_software
pin_c1_direction = output ; IrLed pin
; setup pwm for the IR led
T2CON = 4 ; timer 2 on, prescaler = 1, postscaler = 1
PR2 = 88 ; create 56 kHz pulse
ccpr2l = 44 ;
-- ----------------------------------------------------------------------------
Sorry but I have been busy trying to get a wireless networking and have
not had any time lately for my jal hobby,
>
Joep
I am confused. The code I 'thought' you were sending was to help get
rid of the INTCON_GIE errors I was getting on some of the 8 pin chips
ie the 12f509 IIRC.
Does the ir_sender procedure help with that???? If it does, I have been
away from jal for too long.
Sorry for the cc: but I don't think my mail is getting to the list when
I originate it, it seems to be OK, sometimes, if I reply only.
I never know if my mail is getting through because if no one replies, I
think nobody cares.
I an going to test the 4MHz clocks ASAP. I WILL let YOU know.
Happy New Year
Wayne
Joep
Sir, I am happy to inform you that the changes you made to the
serial_software timing were successful. I am now able to run the
16f628a_lcd_k107_sample at 4MHz.
Thanks again for your efforts.
Wayne