Revision: 1253 Author: bvwelch Date: Thu Aug 27 10:25:02 2009 Log: JALLIB-compatible version of STERM Master
http://code.google.com/p/jallib/source/detail?r=1253 Added: /trunk/include/external/lcd/lcd_sterm_master.jal ======================================= --- /dev/null +++ /trunk/include/external/lcd/lcd_sterm_master.jal Thu Aug 27 10:25:02 2009 @@ -0,0 +1,195 @@ +-- Title: STERM Master library for JALLIB +-- Author: Javier MartÃnez & Eur Van Andel Copyright (C) 2003-2009 All rights reserved +-- Adapted-by: William Welch +-- Compiler: 2.4 +-- Released under the ZLIB license (http://www.opensource.org/licenses/zlib-license.html) +-- +-- This file is part of jallib (http://jallib.googlecode.com) +-- +-- Description: Master Serial Terminal routines +-- : ** For Eur's Contest ** +-- + +-- Frame structure +-- +-- +---+---------+------+ +-- | S | command | data | +-- +---+---------+------+ +-- +-- S = Sync bit, active low. +-- command = ( 4 bits ) +-- M->S 0x00 Output STerm flags. +-- 0x01 Output data is 'LCD instruction'. +-- 0x02 Output data is 'LCD data'. +-- 0x03 Output data is serial data to PC. +-- 0x04 Reserved (not used yet). +-- 0x05 Reserved (not used yet). +-- 0x06 Reserved (not used yet). +-- 0x07 Reserved (not used yet). + +-- S->M 0x08 Input STerm flags. +-- 0x09 Input data is keyboard. +-- 0x0A Input data is serial data from PC. +-- 0x0B Input data is serial buffer status. +-- 0x0C Reserved (not used yet). +-- 0x0D Reserved (not used yet). +-- 0x0E Reserved (not used yet). +-- 0x0F Reserved (not used yet). +-- data = ( 8 bits ) +-- +-- +-- STerm Flags +-- Write with command 0x00, read with command 0x08. +-- +-- 7 6 5 4 3 2 1 0 +-- +---+---+---+---+---+---+---+---+ +-- | | | | | | | | R | +-- +---+---+---+---+---+---+---+---+ +-- +-- R = Reset STerm (Active High). +-- + +function __term_byte( byte in command1 , byte in data1 ) return byte is + var byte commandtemp + var bit available = low + -- Trunc command to low nibble + commandtemp = command1 -- Bug corrected, this is necesary. + command1 = commandtemp << 4 + while ! available loop + -- Sync Bit. ( low = active ) + lcd_sterm_pin = high + delay_10us ( 1 ) + lcd_sterm_pin = low + delay_10us ( 9 ) + lcd_sterm_pin_dir = input + available = lcd_sterm_pin -- slave forces low when busy. + available = lcd_sterm_pin -- if available or not present => high + lcd_sterm_pin = low + lcd_sterm_pin_dir = output + lcd_sterm_pin = low + if available then + delay_10us ( 25 ) -- normal pulse + else + delay_1ms ( 1 ) -- extended pulse + end if + end loop + -- Command Nibble. + for 4 loop + -- Not Sync Bit. ( high = not active ) + lcd_sterm_pin = high + delay_10us ( 8 ) + -- Get 'command' through carry + asm rlf command1,f + -- Output bit information. MSB first + if status_c then + -- Make a B1 + delay_10us ( 5 ) + lcd_sterm_pin = low + -- Active? interrupts during pulse output + delay_10us ( 13 ) + else + -- Make a B0 + lcd_sterm_pin = low + -- Active? interrupts during pulse output + delay_10us ( 18 ) + end if + end loop + -- Data byte. + for 8 loop + -- Disable interrupts during pulse output + -- Not Sync Bit. ( high = not active ) + lcd_sterm_pin = high + delay_10us ( 8 ) + -- Check for input/output data. + if commandtemp >= 0x08 then + -- Prepare for input + lcd_sterm_pin_dir = input + -- Sample the bit information + delay_10us ( 5 ) + status_c = lcd_sterm_pin + -- Get 'data' through carry + asm rlf data1,f + -- Active? interrupts during pulse output + delay_10us ( 13 ) + -- restore pin + lcd_sterm_pin = low + lcd_sterm_pin_dir = output + lcd_sterm_pin = low + else + -- Get 'data' through carry + asm rlf data1,f + -- Output bit information. MSB first + if status_c then + -- Make a B1 + delay_10us ( 5 ) + lcd_sterm_pin = low + delay_10us ( 13 ) + else + -- Make a B0 + lcd_sterm_pin = low + delay_10us ( 8 ) + end if + end if + end loop + return data1 +end function + +-- Send 'hd447804 data' command to Terminal: +procedure _lcd_write_data( byte in data3 ) is + var byte dummy + -- send command + dummy = __term_byte ( 0x02 , data3 ) +end procedure + +-- Send 'hd447804 instruction' command to Terminal: +procedure _lcd_write_command( byte in instr ) is + var byte dummy + -- send command + dummy = __term_byte ( 0x01 , instr ) +end procedure + +include lcd_hd44780_common + +-- Send reset to Terminal: +-- Clear the LCD and makes a sw reset of the PIC. +procedure lcd_init() is + var byte dummy + lcd_sterm_pin = low + lcd_sterm_pin_dir = output + lcd_sterm_pin = low + -- send command + dummy = __term_byte ( 0x00 , 0x00 ) -- On reset, STerm_flag<0> is 0. + -- wait 10ms to reset the LCD + delay_1ms ( 1 ) +end procedure + +-- Send 'input buffer' command to Terminal: +function lcd_buflag() return byte is + var byte vartemp = 0x00 + return __term_byte ( 0x0B , vartemp ) +end function + +-- Send 'input keyboard' command to Terminal: +function lcd_key'get() return byte is + var byte vartemp = 0x00 + return __term_byte ( 0x09 , vartemp ) +end function + +-- two functions borrowed from keyboard.jal for compatibility + +-- getkey - return the key pressed (until it is released) +function getkey() return byte is + var byte vartemp = 0x00 + return __term_byte ( 0x09 , vartemp ) +end function + +var byte lastkey = 0xff + +-- getkey_once - return the value of a key pressed only once +function getkey_once() return byte is + var byte key = getkey() + if (key == lastkey) then return 0x10 end if + lastkey = key + return key +end function + --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jallib" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/jallib?hl=en -~----------~----~----~----~------~----~------~--~---
