'**************************************************************************** 'GT69DEMO.BAS Using a Toshiba T6963C graphic LCD controller 'Version 1.0 'Written in Bascom-AVR ver 1.11.6.2 '============================================================================ ' '================== NOT FOR COMMERICIAL USE ================================= ' ' Author: Ranjit Diol, COMPSys Date: September, 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. ' ' For Commercial Licensing please contact ' rsdiol@compsys1.com for more information ' '=============================================================================== $regfile = "8535def.dat" 'AT90S8535 mcu 'Setup ports and aliases Ddrb = &B11111111 'Output Portb = &B11111111 Ddrd = &B11111111 Portd = &B11111111 '************************ ' LCD Module constants * '************************ ' ' '============IMPORTANT NOTE============== 'Following are for a 240x64 pixel display 'ADJUST THESE TO MATCH YOUR LCD PANEL. 'Check your LCD data sheet for details Const Gl_horiz = 240 'Horizontal resolution Const Gl_vert = 64 'Vertical resolution Const Gl_row = 32 'Calculation for rows Const Gl_col = 64 'Calculation for columns '======================================== ' 'T6963C Controller 'Register set commands: Const Cursor_ptr_set = &H21 'Cursor Pointer Set Const Offset_reg_set = &H22 'Offset Register Set Const Addr_ptr_set = &H24 'Address Pointer Set 'Control Word Set commands: Const Text_home_set = &H40 'Text Home Address Set Const Text_area_set = &H41 'Text Area Set Const Graph_home_set = &H42 'Graphics Home address Set Const Graph_area_set = &H43 'Graphics Area Set 'Mode Set commands (OR with CG rom commands): Const Or_mode = &H80 'OR mode Const Xor_mode = &H81 'XOR mode Const And_mode = &H83 'AND mode Const Text_attr_mode = &H84 'Text Attribute mode Const Int_cg_mode = &H80 'Internal CG ROM mode Const Ext_cg_mode = &H88 'External CG ROM mode 'Display Mode commands (OR together required bits): Const Display_off = &H90 'display off Const Blink_on = &H91 Const Cursor_on = &H92 Const Text_on = &H94 Const Graphic_on = &H98 Const Text_and_graph_on = &H9C 'Cursor Pattern Select Const Cursor_1line = &HA0 Const Cursor_2line = &HA1 Const Cursor_3line = &HA2 Const Cursor_4line = &HA3 Const Cursor_5line = &HA4 Const Cursor_6line = &HA5 Const Cursor_7line = &HA6 Const Cursor_8line = &HA7 'Data Auto Read/Write Const Data_auto_wr = &HB0 Const Data_auto_rd = &HB1 Const Auto_data_reset = &HB2 'Data Read/Write Const Data_wr_inc = &HC0 'Data write and increment addr Const Data_rd_inc = &HC1 'Data read and increment addr Const Data_wr_dec = &HC2 'Data write and decrement addr Const Data_rd_dec = &HC3 'Data read and decrement addr Const Data_wr = &HC4 'Data write - no addr change Const Data_rd = &HC5 'Data read - no addr change '************************ ' STATUS bits * '************************ Const Sta0 = 0 'command excution status Const Sta1 = 1 'data read/write status Const Sta2 = 2 'auto data read status Const Sta3 = 3 'auto data write status Const Sta5 = 5 '=troller status Const Sta6 = 6 'peek/copy error flag Const Sta7 = 7 'blink? or blank? status 'Variables used for LCD x,y limits Const Ascii_offset = &H20 'ASCII offset for conversion Const Gl_pause = 2 'Small delay Const Gl_xmax = Gl_horiz - 1 'Maximum Horiz resolution Const Gl_xmin = 0 Const Gl_ymax = Gl_vert - 1 'Maximum vertical resolution Const Gl_ymin = 0 Const Gl_lines = Gl_vert / 8 'Lines = vertical resolution divided by 8 'IMPORTANT: 'Change according to your LCD 'Below are the vertical line numbers 0-7 and horiz tab locations 0-29 'for a 240x64 bit LCD display (8 lines x 30 characters) 'Lines (rows) are incremented by 8 Const Line0 = 0 Const Line1 = 8 Const Line2 = 16 Const Line3 = 24 Const Line4 = 32 Const Line5 = 40 Const Line6 = 48 Const Line7 = 56 'Tabs are columns incremented by 8 for 8x8 character space Const Tab0 = 0 Const Tab1 = 8 Const Tab2 = 16 Const Tab3 = 24 Const Tab4 = 32 Const Tab5 = 40 Const Tab6 = 48 Const Tab7 = 56 Const Tab8 = 64 Const Tab9 = 72 Const Tab10 = 80 Const Tab11 = 88 Const Tab12 = 96 Const Tab13 = 104 Const Tab14 = 112 Const Tab15 = 120 Const Tab16 = 128 Const Tab17 = 136 Const Tab18 = 144 Const Tab19 = 152 Const Tab20 = 160 Const Tab21 = 168 Const Tab22 = 176 Const Tab23 = 184 Const Tab24 = 192 Const Tab25 = 200 Const Tab26 = 208 Const Tab27 = 216 Const Tab28 = 224 Const Tab29 = 232 'Variables used ' *** MODIFY AS REQUIRED FOR OTHER PINS AND PORTS ***** ' Gl_tris Alias Ddrd 'Data bus direction Gl_dat Alias Portd 'LCD 8 bit data bus Gl_wr Alias Portb.0 'Write control bit Gl_rd Alias Portb.1 'Read control bit Gl_ce Alias Portb.5 'Chip enable control bit Gl_cd Alias Portb.4 'Command and Data toggle bit Gl_rst Alias Portb.3 'Reset control bit Gl_fsz Alias Portb.2 'Font select control bit Gl_bsy Alias Pind.7 'In case there is a need, not really used Gl_sta0 Alias Pind.0 'Status Bit 0 Gl_sta1 Alias Pind.1 'Status Bit 1 Gl_sta2 Alias Pind.2 'Status Bit 2 Gl_sta3 Alias Pind.3 'Status Bit 3 Gl_inp Alias Pind 'LCD data input 'General use variables used Dim Gl_msb As Byte 'Data 1 variable Dim Gl_lsb As Byte 'Data 2 variable Dim Gl_cmd As Byte 'Command variable Dim Gl_tmp As Byte 'Temp var Dim Gl_x As Word '16 bit var for address loop Dim Gl_y As Word '16 bit var for address loop Dim Gl_i As Byte 'General var Dim Gl_j As Byte 'General var Dim Graph_home As Word 'LCD graphic start addr Dim Graph_area As Word 'LCD graphic bytes per line Dim Text_home As Word 'LCD text start addr Dim Text_area As Word 'LCD text chars per line Dim Gl_addr As Word 'LCD memory Address Dim Gl_byte As Byte 'Graphic byte Dim Gl_char As Byte 'Text byte Dim Ptr_flag As Byte 'Addr ptr flag Dim Gl_oldaddr As Word 'Var to keep track of address Dim Gl_fs As Byte 'LCD font size Dim W_tmp1 As Word 'Temp word var Dim W_tmp2 As Word 'Temp word var Dim B_tmp1 As Byte 'Temp byte var Dim B_tmp2 As Byte 'Temp byte var Dim Stat_mask As Byte 'Status mask byte 'NOTE:Following are string variables, change according to your needs Dim G_chr As String * 1 'Char var Dim G_str As String * 32 'Text string var 'Initialize variables 'Set Font size to 8x8 Gl_fsz = 0 'Set pin for 8x8 Font size Gl_fs = 0 '0=8x8 character space, 1=6x8 Gl_tmp = 0 Gl_i = 0 Ptr_flag = Data_wr 'FS offsets Dim Font_size As Byte 'Var for font size Dim Font_byte As Byte 'Var for font byte 'Initialize variables Gl_tmp = 0 Gl_i = 0 Ptr_flag = Data_wr 'Initial settings of port and bits Gl_dat = 0 'Clear PORTD Gl_wr = 1 'Write high Gl_rd = 1 'Read high Gl_ce = 1 'Chip enable high (active low) Gl_cd = 1 'Command high Gl_fsz = 0 'Set Font size (1=6x8 and 0=8x8 font) Gl_rst = 1 'RESET always high (low will reset the LCD controller) Waitms 500 'Let things stabilize 'Initialize LCD VRAM area variables '===========IMPORTANT================== 'Adjust according to you LCD data sheet Gl_fs = 0 '8x8 character size this makes computing for graphics much easier than using the 6x8 font size Graph_home = &H1000 'Graphics area in VRAM Text_home = &H0000 'Text area in VRAM If Gl_fs = 0 Then Font_size = 8 '8x8 character space Font_byte = 7 'Var used for calculations Graph_area = &H0020 '32 bytes per line (30 if horiz=240 bits) Text_area = &H0020 '32 8x8 chars per line (30 if horiz = 240 bits) Else Font_size = 6 '6x8 character space Font_byte = 5 'Var used for calcultions Graph_area = &H0028 '40 bytes per line Text_area = &H0028 '40 6x8 chars per line End If Gl_rst = 0 ' Reset after power-on Waitms 100 Gl_rst = 1 '================ M A I N =================== Main: 'Initialize and display opening text messages Gosub Gl_init 'To Display text: Assign G_str the text, set x,y location and use gosub Put_str Gl_x = Tab5 Gl_y = Line1 G_str = "Toshiba T6963C LCD" Gosub Put_str Gl_x = Tab5 Gl_y = Line2 G_str = "With an Atmel 8535" Gosub Put_str Wait 1 Gl_y = Line3 Gl_x = Tab12 G_str = "by" Gosub Put_str Gl_x = Tab4 Gl_y = Line4 G_str = "Ranjit Diol-COMPSys" Gosub Put_str 'Draw a horizontal line Gl_byte = 255 'Place byte &H11111111 (straight line 8 bits wide) Gl_y = Line5 For Gl_x = 0 To Gl_horiz Step 8 Gosub Put_byte Next Gl_x Gl_x = Tab1 Gl_y = Line6 G_str = "www.compsys1.com/workbench" Gosub Put_str Wait 8 Gosub Grf_clr 'Demonstration of dispalying a 64x64 bitmap image Restore Imgdat For Gl_y = 0 To 63 For Gl_x = 0 To 63 Step 8 'Step each byte Read Gl_byte Gosub Put_byte Next Gl_x Next Gl_y Ptr_flag = Data_wr_inc 'Increment cursor Gl_x = Tab9 'Starting x,y lcoation on LCD Gl_y = Line3 G_str = "Display a Bitmap!" Gosub Put_str Wait 10 Goto Main End '========== E N D O F M A I N ============= 'DATA SECTION 'Data to display a 64x64 bitmap Imgdat: Data &H00 , &H00 , &H00 , &H00 , &H04 , &H80 , &H00 , &H00 , &H00 , &H00 , &H00 , &H08 , &HC0 , &H60 , &H00 , &H00 Data &H00 , &H00 , &H00 , &H20 , &H5E , &HB0 , &H00 , &H00 , &H00 , &H00 , &H04 , &H34 , &H00 , &HEC , &H00 , &H00 Data &H00 , &H00 , &H00 , &HC4 , &H09 , &HBE , &H00 , &H00 , &H00 , &H00 , &H0C , &H01 , &HFF , &HFF , &H00 , &H00 Data &H00 , &H00 , &H1C , &H00 , &H7E , &HBF , &H80 , &H00 , &H00 , &H00 , &H28 , &H01 , &HE1 , &H97 , &H80 , &H00 Data &H00 , &H00 , &H7D , &H1E , &H84 , &HDF , &HC0 , &H00 , &H00 , &H01 , &H7E , &HFF , &H11 , &HEF , &HC0 , &H00 Data &H00 , &H01 , &HCA , &H7E , &H8F , &HEF , &HE0 , &H00 , &H00 , &H03 , &H29 , &H70 , &H38 , &HFF , &HF8 , &H00 Data &H00 , &H06 , &H10 , &H04 , &H40 , &H7D , &H08 , &H00 , &H00 , &H03 , &H83 , &HD0 , &H02 , &H78 , &H7C , &H00 Data &H00 , &H07 , &H21 , &H00 , &H9C , &HF7 , &H04 , &H00 , &H00 , &H07 , &H91 , &H00 , &H30 , &HF9 , &HBE , &H00 Data &H00 , &H07 , &H65 , &HBE , &HF8 , &HED , &HC6 , &H00 , &H00 , &H07 , &HB3 , &HFB , &HE8 , &HEF , &HFE , &H00 Data &H00 , &H07 , &HF8 , &HFF , &HF7 , &HE3 , &H0E , &H00 , &H00 , &H0F , &HF5 , &HE7 , &HE8 , &H01 , &HFE , &H00 Data &H00 , &H0F , &H72 , &H80 , &H00 , &H00 , &HFF , &H00 , &H00 , &H0F , &HF0 , &H80 , &H00 , &H00 , &H3E , &H00 Data &H00 , &H0F , &H60 , &H80 , &H00 , &H00 , &H7E , &H00 , &H00 , &H0E , &HE0 , &H00 , &H00 , &H00 , &H06 , &H00 Data &H00 , &H0E , &H20 , &H00 , &H00 , &H00 , &H16 , &H00 , &H00 , &H1C , &H00 , &H00 , &H00 , &H00 , &H0E , &H00 Data &H00 , &H1C , &H00 , &H00 , &H00 , &H00 , &H1E , &H00 , &H00 , &H1C , &H00 , &H00 , &H00 , &H00 , &H1E , &H00 Data &H00 , &H3C , &H00 , &H00 , &H00 , &H00 , &H1A , &H00 , &H00 , &H2C , &H00 , &H00 , &H00 , &H00 , &H06 , &H00 Data &H01 , &HAC , &H00 , &H00 , &H00 , &H00 , &H2E , &H00 , &H01 , &HCC , &H06 , &H70 , &H00 , &H00 , &H36 , &H00 Data &H02 , &HB8 , &H00 , &HF8 , &H00 , &H00 , &H1E , &H00 , &H01 , &H0C , &H01 , &H80 , &H00 , &HFE , &H0E , &H00 Data &H01 , &H2C , &H0F , &HFC , &H01 , &HF6 , &H1E , &H00 , &H00 , &H8C , &H1F , &H92 , &H03 , &H60 , &H0F , &H40 Data &H01 , &HB8 , &H03 , &HCA , &H07 , &HFC , &H1C , &H00 , &H00 , &H2C , &H01 , &HB8 , &H09 , &HAE , &H09 , &HC0 Data &H00 , &HEC , &H04 , &H00 , &H0B , &HC4 , &H16 , &H00 , &H00 , &H6C , &H00 , &H00 , &H10 , &H78 , &H14 , &H00 Data &H00 , &H4C , &H00 , &H00 , &H10 , &H80 , &H1E , &H40 , &H00 , &H1C , &H00 , &H00 , &H00 , &H70 , &H19 , &H80 Data &H00 , &H04 , &H00 , &H00 , &H00 , &H00 , &H1A , &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H0F , &H00 Data &H00 , &H18 , &H00 , &H00 , &H00 , &H00 , &H3A , &H00 , &H00 , &H00 , &H00 , &H00 , &H20 , &H00 , &H22 , &H00 Data &H00 , &H00 , &H00 , &H0C , &H28 , &H00 , &H04 , &H00 , &H00 , &H04 , &H00 , &H43 , &HD0 , &H00 , &H48 , &H00 Data &H00 , &H00 , &H03 , &H80 , &H00 , &H00 , &H58 , &H00 , &H00 , &H02 , &H00 , &H00 , &H01 , &H00 , &H40 , &H00 Data &H00 , &H02 , &H01 , &HC0 , &H00 , &H80 , &H80 , &H00 , &H00 , &H00 , &H00 , &H7E , &H12 , &H80 , &H80 , &H00 Data &H00 , &H01 , &H00 , &H38 , &H5E , &H01 , &H00 , &H00 , &H00 , &H00 , &H80 , &H40 , &H30 , &H01 , &H00 , &H00 Data &H00 , &H00 , &HC0 , &H2F , &HE0 , &H02 , &H00 , &H00 , &H00 , &H00 , &H60 , &H10 , &H10 , &H04 , &H00 , &H00 Data &H00 , &H00 , &H10 , &H08 , &H20 , &H08 , &H00 , &H00 , &H00 , &H00 , &H08 , &H07 , &HC0 , &H10 , &H00 , &H00 Data &H00 , &H00 , &H04 , &H00 , &H00 , &H40 , &H00 , &H00 , &H00 , &H00 , &H02 , &H00 , &H01 , &H00 , &H00 , &H00 Data &H00 , &H00 , &H00 , &H80 , &H06 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H40 , &H08 , &H00 , &H00 , &H00 Data &H00 , &H00 , &H00 , &H30 , &H30 , &H00 , &H00 , &H00 , &H00 , &H00 , &H00 , &H03 , &H80 , &H00 , &H00 , &H00 'End of image data '********** SUBROUTINES ************* '****Subroutines used in this program **** 'Send commands and data 'These are required routines Send_2: Gosub Busy_chk Gl_dat = Gl_lsb Gl_cd = 0 Gl_rd = 1 Gl_ce = 0 Gl_wr = 0 Gl_wr = 1 Gl_ce = 1 Send_1: Gosub Busy_chk Gl_dat = Gl_msb Gl_cd = 0 Gl_rd = 1 Gl_ce = 0 Gl_wr = 0 Gl_wr = 1 Gl_ce = 1 Send_cmd: Gosub Busy_chk Gl_dat = Gl_cmd Gl_rd = 1 Gl_ce = 0 Gl_wr = 0 Gl_wr = 1 Gl_ce = 1 Return Busy_chk: Gl_ce = 1 Gl_tris = &B00000000 Gl_cd = 1 Gl_wr = 1 Gl_ce = 0 Gl_rd = 0 Stat_mask = Gl_inp And 3 If Stat_mask <> 3 Then Goto Busy_chk Gl_rd = 1 Gl_ce = 1 Gl_tris = &B11111111 Return 'End of commands/data routines 'Set address given x,y coordinates Gl_gaddr: W_tmp1 = Gl_y * Gl_row W_tmp2 = Gl_x / Font_size Gl_addr = W_tmp1 + W_tmp2 Gl_addr = Gl_addr + Graph_home Gl_oldaddr = Gl_addr Gl_msb = High(gl_addr) Gl_lsb = Low(gl_addr) Gl_cmd = Addr_ptr_set Gosub Send_2 Return 'Initialize and clear display Gl_init: 'Initialization 'See data sheets for more info for the commands and parameters ' Set Graphic Home Addr Gl_msb = High(graph_home) Gl_lsb = Low(graph_home) Gl_cmd = Graph_home_set Gosub Send_2 ' Set Graphic Area Gl_msb = High(graph_area) Gl_lsb = Low(graph_area) Gl_cmd = Graph_area_set Gosub Send_2 ' Set Text Home Addr Gl_msb = High(text_home) Gl_lsb = Low(text_home) Gl_cmd = Text_home_set Gosub Send_2 ' Set Text Area Gl_msb = High(text_area) Gl_lsb = Low(text_area) Gl_cmd = Text_area_set Gosub Send_2 ' Set OR mode Gl_cmd = Or_mode Gosub Send_cmd Grf_clr: ' Set Addr Ptr Gl_msb = $00 Gl_lsb = $00 Gl_cmd = Addr_ptr_set Gosub Send_2 ' Set Graphic mode on Gl_cmd = Graphic_on Gosub Send_cmd For Gl_i = 1 To Gl_horiz ' Clear Graphic Screen For Gl_j = 1 To Gl_vert Gl_msb = $00 'Clear byte Gl_cmd = Data_wr_inc 'Command Gosub Send_1 'Send glcd_msb followed by glcd_cmd Next Next 'Do it 240x64 times Return 'End of Init routine Txt_home: ' Set Text Home Addr Gl_msb = High(text_home) Gl_lsb = Low(text_home) Gl_cmd = Text_home_set Gosub Send_2 Return Gl_txt_pos: W_tmp1 = Gl_y / 8 W_tmp1 = W_tmp1 * Gl_row W_tmp1 = W_tmp1 + Text_home Gl_addr = W_tmp1 W_tmp1 = Gl_x / Font_size Gl_addr = Gl_addr + W_tmp1 Gl_msb = High(gl_addr) Gl_lsb = Low(gl_addr) Gl_cmd = Addr_ptr_set Gosub Send_2 Return 'Sets graphic mode on Grf_on: Gosub Send_2 Gl_cmd = Graphic_on Gosub Send_cmd Return 'Sets text mode on Txt_on: Gosub Txt_home Gl_cmd = Text_on Gosub Send_cmd Return 'Sets text and graphics mode on Grf_txt_on: Gosub Txt_home Gl_cmd = Text_and_graph_on Gosub Send_cmd Return 'Places a byte at x,y Put_byte: 'Assumes gl_x,gl_y and gl_byte and ptr_flag Gosub Txt_home Gosub Txt_on 'Graphic and Text mode Gosub Gl_gaddr 'Set address Gl_msb = Gl_byte Gl_cmd = Ptr_flag Gosub Send_1 Gosub Grf_txt_on Return 'STRING Routines 'Places a string of characters on the LCD, it uses the Put_it subroutine Put_str: B_tmp1 = Len(g_str) For B_tmp2 = 1 To B_tmp1 G_chr = Mid(g_str , B_tmp2 , 1) Gl_char = Asc(g_chr) - &H20 Gosub Put_it Gl_x = Gl_x + 8 Next B_tmp2 Return Put_it: Gosub Gl_txt_pos 'Set text addr given gl_x,gl_y Gl_msb = Gl_char Gl_cmd = Ptr_flag Gosub Send_1 Gosub Grf_txt_on Return 'End of String routines '=================== 'END OF SUBROUTINES '===================