'File: glsdemo.bas 'Program to test the SED1330 Controller based graphic LCD 'Can be also used with the GLIPIC2 Windows application 'Written in PICBasicPro Ver 2.32 'Revision 1.0 'Display to be used: 256x128 Graphic LCD '================================================================== ' ***** THIS CODE IS NOT FOR COMMERCIAL USE ***** '================================================================== ' ' Author: Ranjit Diol, COMPSys Date: July, 2001 ' (c) Copyright COMPSys, 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. ' ' It can be distributed freely in its entirety, portions may be used in ' non-commercial applications as long as the author is given credit for those ' portions used. ' ' Contact: rsdiol@compsys1.com for more information ' '********************************************************************************** ' ' PLEASE NOTE: This is an abreviated version of a larger application, hence, ' You may find numerous defined variables that are never used ' '********************************************************************************** ' '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 '*** PIC PINS REQUIRED *** ' 'PLEASE NOTE: '================================================================== 'Following is the GLiPIC pcb configuration 'Change the assignments as needed if you do not use the GLiPIC pcb '================================================================== 'Set pins for output TRISB.1 = 0 'LCD Reset TRISB.2 = 0 'LCD RD TRISD = 0 'LCD 8 bit data bus TRISC.0 = 0 'LCD A0 data/command TRISC.1 = 0 'LCD WR TRISC.2 = 0 'LCD CS 'Variable assignments gl_dat var PORTD gl_a0 var PORTC.0 gl_rd var PORTB.2 gl_wr var PORTC.1 gl_cs var PORTC.2 gl_rst var PORTB.1 gl_tris var TRISD gl_cs = 0 'Chip select active 'Serial I/O definitions and variables out_pin var PORTC.6 'Serial OUT pin in_pin var PORTC.7 'Serial IN pin ser_baud con 32 '19200 Baud in_dat var BYTE 'In coming byte data in_ser var BYTE[15] 'In coming data buffer in_lsb var BYTE 'In coming lsb of word in_msb var BYTE 'In coming msb of word gl_chr var BYTE 'Character byte eep_addr var WORD 'External eeprom address hex_nibble var BYTE 'Var used for incoming data 'Terminal variables in_array var BYTE[32] 'In coming array in_ctl var BYTE[8] 'In coming control array buff_count var BYTE 'General counter gl_delay var BYTE 'Delay variable gl_idx var BYTE 'General use gl_idy var BYTE 'General use 'EEprom scl VAR PORTC.3 'I2C SCL for ext eeprom sda VAR PORTC.4 'I2C SDA for ext eeprom ctl CON $A0 'EEprom control code 'Constants used SYS_SET con $40 SYS_SLEEP con $53 SYS_CGRAM_ADDR con $5C SYS_SCROLL con $44 SYS_SCROLL_HDOT con $5a SYS_SCROLL_RATE con $5a SYS_CUR_FORM con $5d SYS_CUR_ADDR con $46 SYS_CUR_READ con $47 SYS_CUR_DIR_RT con $4c SYS_CUR_DIR_LT con $4d SYS_CUR_DIR_UP con $4e SYS_CUR_DIR_DN con $4f SYS_OVER_LAY con $5b SYS_MWRITE con $42 SYS_MREAD con $43 LCD_DISP_ON con $59 LCD_DISP_OFF con $58 LCD_INVERSE con $ff LCD_NORMAL con $00 LCD_CR con $20 '32 Chars/bytes per line LCD_W con $100 '256 pixels wide LCD_H con $80 '128 pixels high LCD_Lh con $08 'Height of line (8x8 characters) LCD_L1 con $00 'Line 1 LCD_L2 con $20 'Line 2 LCD_L3 con $40 'Line 3 LCD_L4 con $60 'Line 4 LCD_L5 con $80 'Line 5 LCD_L6 con $A0 'Line 6 LCD_L7 con $C0 'Line 7 LCD_L8 con $E0 'Line 8 LCD_L9 con $100 'Line 9 LCD_L10 con $120 'Line 10 LCD_L11 con $140 'Line 11 LCD_L12 con $160 'Line 12 LCD_L13 con $180 'Line 13 LCD_L14 con $1A0 'Line 14 LCD_L15 con $1C0 'Line 15 LCD_L16 con $1E0 'Line 16 LCD_GRH con $1000 'Graphic home position 'Variables used gl_cmd var BYTE gl_cur var BYTE gl_byte var BYTE gl_i var BYTE gl_j var BYTE gl_k var BYTE gl_x var WORD gl_y var WORD gl_addr var WORD gl_w var WORD gl_read var BYTE gl_old var BYTE pix_x var WORD pix_y var WORD gl_addrlo var WORD gl_addrhi var WORD gl_nib var BYTE gl_rst = 0 pause 1 gl_rst = 1 'Make sure reset is high pause 100 goto main 'Jump over subroutines ' '===== SUBROUTINES ============ ' send_dat: gl_a0 = 0 gl_dat = gl_byte goto gl_strobe send_cmd: gl_a0 = 1 gl_dat = gl_cmd gl_strobe: gl_wr = 0 @ nop gl_wr = 1 gl_a0 = 0 return 'Clear Graphic Screen gl_grfclr: gl_cmd = SYS_CUR_ADDR 'CSRW command gosub send_cmd gl_byte = $00 gosub send_dat gl_byte = $10 gosub send_dat gl_cmd = SYS_CUR_DIR_RT 'Cur movement right gosub send_cmd gl_cmd = SYS_MWRITE gosub send_cmd gl_byte = LCD_NORMAL for gl_i = 1 to 128 for gl_j = 1 to 32 gosub send_dat next gl_j next gl_i gl_cmd = SYS_CUR_ADDR 'CSRW command gosub send_cmd gl_byte = $00 gosub send_dat gl_byte = $10 gosub send_dat gl_cmd = SYS_CUR_DIR_RT 'Cur movement right gosub send_cmd return gl_grfhome: gl_cmd = SYS_CUR_ADDR 'CSRW command gosub send_cmd gl_byte = $00 gosub send_dat gl_byte = $10 gosub send_dat gl_cmd = SYS_CUR_DIR_RT 'Cur movement right gosub send_cmd return 'Clear Text screen gl_txtclr: gl_cmd = SYS_CUR_ADDR 'CSRW command gosub send_cmd gl_byte = $00 gosub send_dat gl_byte = $00 gosub send_dat gl_cmd = SYS_CUR_DIR_RT 'Cur movement right gosub send_cmd gl_cmd = SYS_MWRITE gosub send_cmd for gl_i = 1 to 16 for gl_j = 1 to 32 gl_byte = $20 'ASCII Space gosub send_dat next gl_j next gl_i gl_cmd = SYS_CUR_ADDR 'CSRW command gosub send_cmd gl_byte = $00 gosub send_dat gl_byte = $00 gl_cmd = SYS_CUR_DIR_RT 'Cur movement right gosub send_cmd return gl_init: 'Setup LCD gl_cmd = SYS_SET gosub send_cmd for gl_i = 0 to 7 'P1 P2 P3 P4 P5 P6 P7 P8 lookup gl_i,[$30,$87,$07,$1f,$52,$7f,$20,$0],gl_byte gosub send_dat next gl_i 'scroll gl_cmd = SYS_SCROLL gosub send_cmd for gl_i = 0 to 5 lookup gl_i,[$0,$0,$7f,$00,$10,$7f],gl_byte gosub send_dat next gl_i 'Hdot gl_cmd = SYS_SCROLL_RATE gosub send_cmd gl_byte =$0 gosub send_dat 'Overlay gl_cmd = SYS_OVER_LAY gosub send_cmd gl_byte = %00000001 gosub send_dat 'DISP OFF gl_cmd =LCD_DISP_OFF gosub send_cmd gl_byte = %00010110 gosub send_dat 'Clear Graphic screen gosub gl_grfclr 'Clear Text screen gosub gl_txtclr 'CSRW set cursor home gl_cmd = SYS_CUR_ADDR gosub send_cmd gl_byte = $0 gosub send_dat gl_byte = $0 gosub send_dat gl_cmd = SYS_CUR_DIR_RT gosub send_cmd gl_byte = SYS_MWRITE gosub send_dat gl_byte = $0 gosub send_dat 'CSR FORM gl_cmd =SYS_CUR_FORM gosub send_cmd gl_byte = $04 gosub send_dat gl_byte = $86 gosub send_dat 'DISP ON gl_cmd = LCD_DISP_ON gosub send_cmd gl_byte = %00010100 'cursor off gosub send_dat 'CSR DIR gl_cmd = SYS_CUR_DIR_RT gosub send_cmd return 'Find hex nibble gl_find: Lookdown in_array[gl_i],["0123456789abcdef"],hex_nibble return 'Routine to set the address 'assumes address is in gl_addr and cursor movment in gl_cur gl_setaddr: 'CSRW set cursor home gl_cmd = SYS_CUR_ADDR 'Address command gosub send_cmd gl_byte = gl_addr.BYTE0 'Vram text memory starts at $0000 and graphics at $1000 gosub send_dat gl_byte = gl_addr.BYTE1 gosub send_dat gl_cmd = gl_cur 'Set cursor movement to left,right,up or down gosub send_cmd return 'End of subroutines '============================================ ' BEGIN MAIN PROGRAM '============================================ main: 'Begin Program gosub gl_init 'Initialize 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 '============================ ' 'Left vert Line gl_addr = LCD_GRH + 0 'Graphic home position $1000 gl_cur = SYS_CUR_DIR_DN 'Cur movement to right gosub gl_setaddr 'MWRITE gl_cmd =SYS_MWRITE gosub send_cmd gl_byte = %10000000 'Bit 7 set for gl_i = 0 to 127 gosub send_dat next gl_i 'Right vert Line gl_addr = LCD_GRH + 31 'Graphic home position $1000 gl_cur = SYS_CUR_DIR_DN 'Cur movement to right gosub gl_setaddr 'MWRITE gl_cmd =SYS_MWRITE gosub send_cmd gl_byte = %00000001 'Bit 0 set for gl_i = 0 to 127 gosub send_dat next gl_i 'Top Line gl_addr = LCD_GRH + 0 'Graphic home position $1000 gl_cur = SYS_CUR_DIR_RT 'Cur movement to right gosub gl_setaddr 'MWRITE gl_cmd =SYS_MWRITE gosub send_cmd gl_byte = %11111111 'All bits set for gl_i = 0 to 31 gosub send_dat next gl_i 'Bottom Line gl_addr = LCD_GRH + $0FE0 'Set bottom right addr gl_cur = SYS_CUR_DIR_RT 'Cur movement to left gosub gl_setaddr 'MWRITE gl_cmd =SYS_MWRITE gosub send_cmd gl_byte = %11111111 'All bits set for gl_i = 0 to 31 gosub send_dat next gl_i 'Terminal Subroutine term: 'Assumes Home Position 'Setup variables gl_j=0 gl_i=0 gl_k=0 buff_count = 32 gl_delay = 10 gl_addr = 0 gl_x = 0 gl_y = 0 gl_idx = 120 gl_idy = 0 'MAIN LOOP Get the initial parameters get_param: serin2 in_pin,ser_baud,[wait ("*"),STR in_ctl\9] for gl_i = 0 to 8 Lookdown in_ctl[gl_i],["0123456789abcdef"],hex_nibble in_ctl[gl_i]=hex_nibble next gl_delay = (in_ctl[7]<<4) | in_ctl[8] buff_count = (in_ctl[1]<<4) | in_ctl[2] gl_addr.byte1 = (in_ctl[3] <<4) | in_ctl[4] gl_addr.byte0 = (in_ctl[5] <<4) | in_ctl[6] 'buff_count = (buff_count - 1) eep_addr = gl_addr gl_j=in_ctl[0] if gl_j = 0 then lcd_set 'Display directly on LCD if gl_j = 1 then eep_loop 'Load ext eeprom if gl_j = 4 then lcd_fill 'Display images loop if gl_j = 5 then eep_disp 'For Horiz bytes goto get_param lcd_fill: gl_idx = 232 gl_idy = 0 gl_x = 0 gl_y = 0 goto lcd_loop eep_disp: gosub gl_txtclr gl_idx = buff_count - 1 'Use for x limit gl_idy = gl_delay - 1 'Use for y limit gl_x = 0 gl_y = 0 gosub gl_grfhome gl_cmd = SYS_MWRITE gosub send_cmd for gl_x = 0 to gl_idx '31 bytes across for gl_y = 0 to gl_idy '127 vert lines I2CREAD sda,scl,ctl,eep_addr,[gl_byte] gosub send_dat eep_addr = eep_addr + 1 next gl_y next gl_x serout2 out_pin,ser_baud,["Displayed",10,13] goto get_param eep_loop: serin2 in_pin,ser_baud,5000,eep_done,[wait ("]"),STR in_array\buff_count] 'Wait for ] and the load in_array for gl_i = 0 to (buff_count-1) 'Get char and place in array Lookdown in_array[gl_i],["0123456789abcdef"],hex_nibble in_array[gl_i]=hex_nibble next for gl_i = 0 to (buff_count-1) step 2 gl_byte = (in_array[gl_i]<<4) | (in_array[gl_i+1]) 'Form a hex number MSB-LSB I2CWRITE sda,scl,ctl,eep_addr,[gl_byte] pause 10 eep_addr=eep_addr+1 next goto eep_loop lcd_set: gosub gl_txtclr 'gosub gl_grfclr gl_idx = 248 gl_idy = 0 gl_x = 0 gl_y = 0 gosub gl_grfhome gl_cmd = SYS_MWRITE gosub send_cmd lcd_loop: serin2 in_pin,ser_baud,2000,get_param,[wait ("]"),STR in_array\buff_count] 'Wait for ] and the load in_array for gl_i = 0 to (buff_count - 1) gosub gl_find 'Get char and place in array in_array[gl_i]=hex_nibble next for gl_i = 0 to (buff_count - 1) step 2 gl_byte = (in_array[gl_i]<<4) | (in_array[gl_i+1]) 'Form a hex number MSB-LSB gosub send_dat next goto lcd_loop eep_done: serout2 out_pin,ser_baud,["last byte at:",DEC eep_addr,10,13] goto get_param end '==================== ' END OF PROGARM '====================