'**************************************************************************** 'GLT6963C.BAS Graphic application for use with a Toshiba T6963C (or compatible) 'graphic LCD controller connected to a Microchip(TM) PIC 16F877 microcontroller 'Version 1.0 'Written in MELabs PicBasicPro(TM) Ver 2.32 'GLUTIL.EXE Ver 1.1 is an Windows based interface that is used with GLSDEMO.BAS '============================================================================ 'This program uses the GLTLIB.BAS Graphic Library 'The Graphic Library contains and initializes all the variables used. ' '================== NOT FOR COMMERICIAL USE ================================= ' ' Author: Ranjit Diol, COMPSys Date: April, 2001 ' (c) Copyright COMPSys, April 2001 ' ' DISCLAIMER: This file is being released as non-commericial ' software. It is being provided "AS IS", neither the author, ' nor COMPSys shall be held liable for any damages caused ' by its use. ' ' This product is issued as a single license and can not ' be distributed to others without the explicit consent of ' COMPSys. ' ' SINGLE USER LICENSE: This application may be used in its entirety or ' in parts within some other non-commercial application(s) as long ' as the those applications are used solely by the licensee. ' ' ' Contact: rsdiol@compsys1.com for more information '=============================================================================== 'clear all variables clear DEFINE ONINT_USED 1 'Required if using ISP DEFINE OSC 20 'OSC speed, you may have to tweak the 'strobe' 'routine's e_pause constant for other speeds ADCON1 = 7 'Make all pins digital, you may adjust as needed SPBRG=0 '************ NOTE *********** RCSTA=0 'This is required if you are using TXSTA=2 'Shane Tolmie's bootloader (PICLoader) '***************************** 'Temp variables used tmp_x var BYTE tmp_y var BYTE tmp_x = 0 tmp_y = 0 m_edata var BYTE 'Data byte to be written m_edata = 0 'Internal eeprom m_addr var BYTE m_addr = $00 m_i var BYTE 'Index Counter include "gltlib.bas" 'The graphic subroutines '============================ ' **** Start Program ****** '============================ main: 'testing -- display some bytes 'test Graphic LCD glcdinit: gosub gl_init 'Initialize and clear display gosub grf_on 'Graphics on '*** READ FROM EXTERNAL EEPROM and then display eep_addr = 0 for gl_y = 0 to 63 for gl_x = 0 to 239 step 8 I2CREAD sda,scl,ctl,eep_addr,[gl_byte] 'serout2 out_pin,ser_baud,[HEX gl_byte] gosub put_byte eep_addr = eep_addr + 1 next gl_x next gl_y glcd_ce = 1 pause 2000 'wait a sec or two 'Now clear the display gosub grf_clr gosub grf_txt_on '*****New added July 8 'testing -- display designs glc_cx = 119 'Circle Center x glc_cy = 31 'Circle Center y for glc_r = 10 to 30 step 10 'Radius gosub gl_circ next glc_r glc_cx = 45 'Square Center x glc_cy = 31 'Square Center y for glc_r = 10 to 30 step 10 'Radius gosub gl_square next glc_r glc_cx = 194 'Square45 Center x glc_cy = 31 'Square45 Center y for glc_r = 10 to 30 step 10 'Radius gosub gl_square45 next glc_r pause 2000 'wait a sec 'Now clear the display gosub grf_clr gosub grf_txt_on gl_x = 8 'Horiz pos gl_y = 8 'Vert pos for gl_i = 0 to 26 lookup gl_i,["Sharp 240x64 using a T6963C"],g_char gosub put_char gl_x = gl_x + 8 next gl_i pause 2000 'wait a sec goto temp1 gl_x = 48 'Horiz pos gl_y = 24 'Vert pos for gl_i = 0 to 20 lookup gl_i,["Software 24 June 2001"],g_char gosub put_char gl_x = gl_x + 8 next gl_i gl_y = 34 for gl_x = 48 to 216 gl_y = 33 gosub gl_setdot gl_y = 35 gosub gl_setdot next gl_x pause 2000 'let's look at a while 'Reinitialize lcd gosub gl_init gosub grf_txt_on '****** NEW Test chart axis ********** 'Set addr ptr s_tick = 4 'Tick mark spacing s_ystart = 10 'Start pos s_yend = 50 'End pos s_xstart = 10 s_xend = 120 gosub gl_xaxis 'draw xaxis gosub gl_yaxis 'draw yaxis 'Next add some labels 'Vertical first gl_x = 0 'First pos on line gl_y = 16 '3rd line down line down for gl_i = 0 to 3 lookup gl_i,["TEMP"],g_char gosub put_char gl_y = gl_y + 8 next gl_i 'Now Horiz at bottom gl_x = 32 'Start a bit to the right gl_y = 56 'Bottom line down for gl_i = 0 to 5 lookup gl_i,["HOURLY"],g_char gosub put_char gl_x = gl_x + 8 next gl_i gl_y = s_yend - 1 'Now set a bunch of dots for gl_x = s_xstart to s_xend RANDOM gl_inc1 if gl_inc1.BYTE0 > 127 then gl_y = gl_y - 1 else gl_y = gl_y + 1 endif if gl_y > s_yend then gl_y = s_yend-1 if gl_y < s_ystart then gl_y = s_ystart + 1 gosub gl_setdot next gl_x 'Place labels gl_x = 130 gl_y = 8 for gl_i = 0 to 5 lookup gl_i,["Count:"],g_char gosub put_char gl_x = gl_x + 8 next gl_i gl_x = 32 gl_y = 0 for gl_i = 0 to 6 lookup gl_i,["DIGIVAC"],g_char gosub put_char gl_x = gl_x + 8 next gl_i gl_x = 130 gl_y = 16 for gl_i = 0 to 5 lookup gl_i,[" Temp:"],g_char gosub put_char gl_x = gl_x + 8 next gl_i gl_x = 130 gl_y = 24 for gl_i = 0 to 5 lookup gl_i,[" Torr:"],g_char gosub put_char gl_x = gl_x + 8 next gl_i gl_x = 130 gl_y = 32 for gl_i = 0 to 5 lookup gl_i,["TimeM:"],g_char gosub put_char gl_x = gl_x + 8 next gl_i gl_x = 130 gl_y = 40 for gl_i = 0 to 5 lookup gl_i,["TimeS:"],g_char gosub put_char gl_x = gl_x + 8 next gl_i gl_tmp = 0 'var used for misc calcs g_count = 0 '********************************************** 'NEW ***** '** Need to develop a subroutine to convert a number to ASCII *** ' so that each digit is sent as an ascii char gl_x = 180 'X pos of 5 digit number gl_y = 8 'Line 2 g_count = g_count + 1 if g_count >65534 then g_count = 0 'No overflow allowed g_num = g_count gosub put_4dig 'Display digits subroutine '************************ '**NEW*** gl_x =180 gl_y = 16 g_char = g_num DIG 2 gosub put_it gl_x = gl_x + 8 g_char = g_num DIG 1 gosub put_it gl_x = gl_x + 8 g_char = g_num DIG 0 gosub put_it gl_x = gl_x + 8 g_char = "." gosub put_char gl_x = gl_x + 8 g_char = g_num DIG 0 gosub put_it gl_x = gl_x + 8 g_char = "C" gosub put_char gl_x =180 gl_y = 24 'g_num = torr gosub put_1dig gl_x =180 gl_y = 32 'g_num = minn gosub put_1dig gl_x =180 gl_y = 40 'g_num = sec gosub put_2dig temp1: ' goto temp1 'End of logo screen '====================================== '******************* '* BEGIN MAIN LOOP * '******************* 'Main loop get_char: serout2 out_pin,ser_baud,["Ready:",10,13] serin2 in_pin,ser_baud,[wait ("]"),in_dat] 'Wait for ] and the load in_dat if (in_dat="c") OR (in_dat = "C") then do_circ 'Branch to circle sub ]c]40201e if (in_dat="s") OR (in_dat = "S") then do_square 'Branch to square sub if (in_dat="q") OR (in_dat = "Q") then do_sqr45 'Branch to square45 sub if (in_dat="t") OR (in_dat = "T") then do_star4 'Branch to star4 sub if (in_dat="l") OR (in_dat = "L") then do_line 'Branch to line sub if (in_dat="r") OR (in_dat = "R") then do_rect 'Branch to rect sub if (in_dat="b") OR (in_dat = "B") then do_bar 'Branch to bar sub if (in_dat="k") OR (in_dat = "K") then do_clear 'Branch to clear sub if (in_dat="d") OR (in_dat = "D") then do_setdot 'Branch to setdot sub if (in_dat="e") OR (in_dat = "E") then do_resetdot 'Branch to resetdot sub if (in_dat="p") OR (in_dat = "P") then do_putchar 'Branch to putchar sub if (in_dat="u") OR (in_dat = "U") then do_putbyte 'Branch to putbyte sub if (in_dat="x") OR (in_dat = "X") then do_xaxis 'Branch to x-axis sub if (in_dat="y") OR (in_dat = "Y") then do_yaxis 'Branch to y-axis sub if (in_dat="f") OR (in_dat = "F") then do_fill 'Branch to do_fill sub if (in_dat="h") OR (in_dat = "H") then do_hstring 'Branch to do_hstring sub if (in_dat="v") OR (in_dat = "V") then do_vstring 'Branch to do_vstring sub if (in_dat="m") OR (in_dat = "M") then do_lcd_w 'Branch to do_lcd_w sub if (in_dat="n") OR (in_dat = "N") then do_lcd_r 'Branch to do_lcd_r sub if (in_dat="o") OR (in_dat = "O") then do_eep_w 'Branch to do_eep_w sub if (in_dat="a") OR (in_dat = "A") then do_eep_r 'Branch to do_eep_r sub if (in_dat="g") OR (in_dat = "G") then do_ieep_r 'Branch to do_ieep_r sub if (in_dat="w") OR (in_dat = "W") then do_ieep_w 'Branch to do_ieep_w sub goto get_char ' End of Terminal Loop 'Start of Routine Branches '========================= 'CIRCLE do_circ: gosub get_three 'Get 3 values gosub c_assign 'Assign the values gosub gl_circ 'Draw the circle 'Return back to main loop goto get_char 'Get next command 'SQUARE do_square: gosub get_three 'Get 3 values gosub c_assign 'Assign the values gosub gl_square 'Draw the square goto get_char 'Get next command 'SQUARE45 do_sqr45: gosub get_three 'Get 3 values gosub c_assign 'Assign the values gosub gl_square45 'Draw the diamond goto get_char 'Get next command 'STAR4 do_star4: gosub get_three 'Get 3 values gosub c_assign 'Assign the values gosub gl_star4 'Draw the 4 point star goto get_char 'Get next command 'BAR do_bar: gosub get_four gosub get_tick gosub gl_bar goto get_char 'RECTANGLE do_rect: gosub get_four gosub get_tick gosub gl_rect goto get_char 'LINE do_line: gosub get_four 'Get 4 values and assign them gosub gl_line 'Draw the line goto get_char 'X AXIS do_xaxis: gosub get_three s_xstart = b_inp1 s_xend = b_inp2 s_ystart = b_inp3 gosub get_tick 'Get the tick mark value gosub gl_xaxis 'Draw x-axis goto get_char 'Y AXIS do_yaxis: gosub get_three s_ystart = b_inp1 s_yend = b_inp2 s_xstart = b_inp3 gosub get_tick 'Get the tick mark value gosub gl_yaxis 'Draw y-axis goto get_char 'CLEAR LCD do_clear: gosub grf_clr goto get_char 'RESET/SET DOT 'Set /Reset Dot routine do_resetdot: 'Set flag and drop down to setdot sub rs_flag = 1 do_setdot: gosub get_two 'Get values and assign them gosub xy_assign gosub gl_setdot 'Set the dot (pixel) rs_flag = 0 goto get_char 'PLACE CHARACTER do_putchar: gosub get_two gosub xy_assign gosub get_tick 'Wait for ] and get gl_chr then load gl_char g_char = gl_chr gosub put_char goto get_char 'PLACE BYTE do_putbyte: gosub get_three gosub xy_assign gl_byte = b_inp3 'Byte to be placed gosub put_byte 'Place it goto get_char do_fill: gosub get_tick 'Get the value for design gl_x1 = 0 gl_x2 = 239 gl_y1 = 0 gl_y2 = 63 gosub gl_bar goto get_char 'Place a horizontal string using int eeprom character do_hstring: gosub get_two gosub xy_assign gosub gl_txt_pos tmp_x = gl_xpos gosub get_tick 'Wait for ] and the load gl_chr while gl_chr <> "@" if gl_chr =";" then g_char = " " gosub put_char goto skip_space endif g_char = gl_chr gosub put_char skip_space: gl_x = gl_x +8 if gl_x > 239 then gl_xpos = tmp_x endif gosub gl_txt_pos gosub get_tick wend goto get_char 'Place a vertical string using int eeprom character do_vstring: gosub get_two gosub xy_assign tmp_x = gl_x tmp_y = gl_y gosub gl_txt_pos gosub get_tick 'Wait for ] and the load gl_chr while gl_chr <> "@" if gl_chr =";" then g_char = " " gosub put_char goto skip_vspace endif g_char = gl_chr gosub put_char skip_vspace: gl_x = tmp_x gl_y = gl_y + 8 if gl_y > 63 then gl_y = tmp_y endif gosub gl_txt_pos gosub get_tick wend goto get_char 'Write int eeprom do_ieep_w: gl_flag = 2 goto eep_rw 'Read int eeprom do_ieep_r: gl_flag = 3 goto eep_rw: 'Write ext eeprom do_eep_w: gl_flag = 0 goto eep_rw 'Read ext eeprom do_eep_r: gl_flag = 1 eep_rw: gosub get_four 'Get 4 hex values ee_addr1.BYTE1 = gl_x1 'Convert them to words ee_addr1.BYTE0 = gl_x2 ee_addr2.BYTE1 = gl_y1 ee_addr2.BYTE0 = gl_y2 'serout2 out_pin,ser_baud,[hex4 ee_addr1,hex4 ee_addr2] 'for debugging for ee_addr = ee_addr1 to ee_addr2 'External Eeprom if gl_flag = 0 then gosub get_one 'Get byte from I/O I2CWRITE sda,scl,ctl,ee_addr,[b_inp1] 'and send to ext eeprom pause 10 endif if gl_flag = 1 then I2CREAD sda,scl,ctl,ee_addr,[gl_chr] 'or Read chr from ext eeprom gosub send_one endif 'Internal Eeprom if gl_flag = 2 then gosub get_one 'Get byte from I/O WRITE ee_addr.BYTE0,b_inp1 'and send to int eeprom 'pause 10 endif if gl_flag = 3 then READ ee_addr.BYTE0,gl_chr 'or Read chr from int eeprom gosub send_one 'and send it out I/O endif next ee_addr gl_flag = 0 goto get_char 'Read LCD data from the LCD at location x,y and send to I/O do_lcd_r: gosub get_four 'Get gl_x1,gl_x2, gl_y1 and gl_y2 for gl_y = gl_y1 to gl_y2 for gl_x = gl_x1 to gl_x2 gosub read_lcd 'This returns gl_chr gosub send_one 'and send it out I/O next gl_x next gl_y goto get_char do_lcd_w: gosub get_four 'Get gl_x1,gl_x2, gl_y1 and gl_y2 for gl_y = gl_y1 to gl_y2 for gl_x = gl_x1 to gl_x2 gosub get_one 'Returns in b_inp1 gl_byte = b_inp1 gosub put_byte 'Place it next gl_x next gl_y end '****************** '* END OF PROGRAM * '******************