'**************************************************************************** 'GSEDUTIL.BAS Graphic application for use with a 256x128 SED1330 (or compatible) 'graphic LCD controller connected to a Microchip(TM) PIC 16F877 microcontroller 'Version 1.0 'Written in MELabs PicBasicPro(TM) Ver 2.32 'GLUTIL3.EXE Ver 1.3.1 is an Windows based interface that is used with GSEDUTIL.BAS '============================================================================ 'This program uses the GSEDLIB.BAS Graphic Library 'The Graphic Library contains and initializes all the variables used. ' '================== NOT FOR COMMERICIAL USE ================================= ' ' Author: Ranjit Diol, COMPSys Date: Feb, 2002 ' (c) Copyright COMPSys, Feb 2002 ' ' 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 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 "gsedlib.bas" 'The graphic subroutines '============================ ' **** Start Program ****** '============================ main: glcdinit: gosub gl_init 'Initialize and clear display gosub clr_all 'Now clear the display 'Display a message and draw a border around it 'First set text address and cursor direction '*** Message centered in LCD ****** gl_addr = LCD_L7 + 5 'Line 7 and 5 bytes to right gl_cur = SYS_CUR_DIR_RT gosub gl_setaddr 'MWRITE gl_cmd =SYS_MWRITE gosub send_cmd for gl_i = 0 to 21 lookup gl_i,["PIC Controlled SED1330"],gl_byte gosub send_dat next gl_i gl_addr = LCD_L8 + 3 'Line 8 and 3 bytes to right gl_cur = SYS_CUR_DIR_RT gosub gl_setaddr 'MWRITE gl_cmd =SYS_MWRITE gosub send_cmd for gl_i = 0 to 26 lookup gl_i,["Using PicBasicPro Ver. 2.32"],gl_byte gosub send_dat next gl_i gl_addr = LCD_L9 + 5 'Line 8 and 3 bytes to right gl_cur = SYS_CUR_DIR_RT gosub gl_setaddr 'MWRITE gl_cmd =SYS_MWRITE gosub send_cmd for gl_i = 0 to 20 lookup gl_i,["Ranjit Diol - COMPSys"],gl_byte gosub send_dat next gl_i gl_addr = LCD_L10 + 4 'Line 10 and 3 bytes to right gl_cur = SYS_CUR_DIR_RT gosub gl_setaddr 'MWRITE gl_cmd =SYS_MWRITE gosub send_cmd for gl_i = 0 to 22 lookup gl_i,["http://www.compsys1.com"],gl_byte gosub send_dat next gl_i 'Now draw a border around LCD '============================ ' gl_x1 = 0 'top left gl_y1 = 0 gl_x2 = 255 'bottom right gl_y2 = 127 s_tick = 1 'solid line gosub gl_rect gl_x1 = 4 'top left gl_y1 = 4 gl_x2 = 251 'bottom right gl_y2 = 123 gosub gl_rect pause 4000 gosub clr_all gl_addr = LCD_L1 + 5 'Line 10 and 3 bytes to right gl_cur = SYS_CUR_DIR_RT gosub gl_setaddr 'MWRITE gl_cmd =SYS_MWRITE gosub send_cmd for gl_i = 0 to 19 lookup gl_i,["DRAW GRAPHIC DESIGNS"],gl_byte gosub send_dat next gl_i glc_cx = 35 'Circle Center x glc_cy = 64 'Circle Center y for glc_r = 10 to 30 step 10 'Radius gosub gl_circ next glc_r glc_cx = 100 'Circle Center x glc_cy = 64 'Circle Center y for glc_r = 10 to 30 step 10 'Radius gosub gl_square next glc_r glc_cx = 160 'Circle Center x glc_cy = 64 'Circle Center y for glc_r = 10 to 30 step 10 'Radius gosub gl_square45 next glc_r glc_cx = 220 'Circle Center x glc_cy = 64 'Circle Center y for glc_r = 10 to 30 step 10 'Radius gosub gl_star4 next glc_r pause 4000 'wait a sec or two 'Now clear the display gosub clr_all gl_addr = LCD_L7 + 5 'Line 7 and 5 bytes to right gl_cur = SYS_CUR_DIR_RT gosub gl_setaddr gl_cmd =SYS_MWRITE gosub send_cmd for gl_i = 0 to 18 lookup gl_i,[" By COMPSys(c) 2002"],gl_byte gosub send_dat next gl_i pause 3000 'wait a while 'Reinitialize lcd gosub clr_all '****** NEW Test chart axis ********** 'Set addr ptr s_xstart = 16 s_tick = 4 'Tick mark spacing s_ystart = 32 'Start pos s_yend = 110 'End pos gosub gl_yaxis 'draw yaxis s_ystart = 110 s_xend = 120 gosub gl_xaxis 'draw xaxis 'Next add some labels gl_addr = LCD_L4 + 4 'Line 7 and 5 bytes to right gl_cur = SYS_CUR_DIR_RT gosub gl_setaddr gl_cmd =SYS_MWRITE gosub send_cmd for gl_i = 0 to 9 lookup gl_i,["SYSTEM LOG"],gl_byte gosub send_dat next gl_i 'Vertical gl_addr = LCD_L6 gl_cur = SYS_CUR_DIR_DN gosub gl_setaddr gl_cmd =SYS_MWRITE gosub send_cmd for gl_i = 0 to 7 lookup gl_i,["ACTIVITY"],gl_byte gosub send_dat next gl_i gl_addr = LCD_L5+1 gl_cur = SYS_CUR_DIR_DN gosub gl_setaddr gl_cmd =SYS_MWRITE gosub send_cmd for gl_i = 0 to 9 lookup gl_i,["9876543210"],gl_byte gosub send_dat next gl_i 'Now Horiz at bottom gl_addr = LCD_L16 + 3 'Line 7 and 5 bytes to right gl_cur = SYS_CUR_DIR_RT gosub gl_setaddr gl_cmd =SYS_MWRITE gosub send_cmd for gl_i = 0 to 5 lookup gl_i,["HOURLY"],gl_byte gosub send_dat next gl_i s_xstart = 16 s_xend = 120 s_ystart = 32 s_yend = 110 gl_y = s_yend '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 gl_addr = LCD_L8 + 16 'Line 7 and 5 bytes to right gl_cur = SYS_CUR_DIR_RT gosub gl_setaddr gl_cmd =SYS_MWRITE gosub send_cmd for gl_i = 0 to 12 lookup gl_i,["Terminal Mode"],gl_byte gosub send_dat next gl_i gl_addr = LCD_L9 + 16 'Line 7 and 5 bytes to right gl_cur = SYS_CUR_DIR_RT gosub gl_setaddr gl_cmd =SYS_MWRITE gosub send_cmd for gl_i = 0 to 12 lookup gl_i,["Waiting......"],gl_byte gosub send_dat next gl_i gl_addr = LCD_L11 + 16 'Line 7 and 5 bytes to right gl_cur = SYS_CUR_DIR_RT gosub gl_setaddr gl_cmd =SYS_MWRITE gosub send_cmd for gl_i = 0 to 13 lookup gl_i,["Use GLUTIL 1.3"],gl_byte gosub send_dat next gl_i 'End of intro 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 clr_all goto get_char 'RESET/SET DOT 'Set /Reset Dot routine do_resetdot: 'Set flag and drop down to setdot sub gl_rstflag = 1 do_setdot: gosub get_two 'Get values and assign them gosub xy_assign gosub gl_setdot 'Set the dot (pixel) gl_rstflag = 0 goto get_char 'PLACE CHARACTER do_putchar: gl_cur = SYS_CUR_DIR_RT 'Cursor direction right gosub get_two gosub xy_assign gosub get_tick 'Wait for ] and get gl_chr then load gl_char gosub put_char goto get_char 'PLACE BYTE do_putbyte: gosub get_three gosub xy_assign gl_chr = 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 = 255 gl_y1 = 0 gl_y2 = 127 gosub gl_bar goto get_char 'Place a horizontal string using int eeprom character do_hstring: gl_cur = SYS_CUR_DIR_RT gosub get_two gosub xy_assign tmp_x = gl_xpos gosub get_tick 'Wait for ] and the load gl_chr while gl_chr <> "@" if gl_chr =";" then gl_chr = " " 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 get_tick wend goto get_char 'Place a vertical string using int eeprom character do_vstring: gl_cur = SYS_CUR_DIR_LT gosub get_two gosub xy_assign tmp_x = gl_x tmp_y = gl_y gosub get_tick 'Wait for ] and the load gl_chr while gl_chr <> "@" if gl_chr =";" then gl_chr = " " gosub put_char goto skip_vspace endif gosub put_char skip_vspace: gl_x = tmp_x gl_y = gl_y + 8 if gl_y > 127 then gl_y = tmp_y endif 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 gl_addr = ($20*gl_y + gl_x/8) + LCD_GRH gosub gl_setaddr gosub read_lcd 'This returns gl_read gl_chr = gl_read 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 * '******************