Attaching an LCD Display ************************ A LCD display can be connected with two methods. · By wiring the LCD-pins to the processor port pins. This is the pin mode. The advantage is that you can choose the pins and that they don't have to be on the same port. This can make your PCB design simple. The disadvantage is that more code is needed. · By attaching the LCD-data pins to the data bus. This is convenient when you have an external RAM chip and will add only a little extra code. The LCD-display can be connected in PIN mode as follows: LCD DISPLAY PORT PIN DB7 PORTB.7 14 DB6 PORTB.6 13 DB5 PORTB.5 12 DB4 PORTB.4 11 E PORTB.3 6 RS PORTB.2 4 RW Ground 5 Vss Ground 1 Vdd +5 Volt 2 Vo 0-5 Volt 3 This leaves PORTB.1 and PORTB.0 and PORTD for other purposes. You can change these pin settings from the Options LCD menu. BASCOM supports many statements to control the LCD-display. For those who want to have more control of the example below shows how to use the internal BASCOM routines. $ASM Ldi _temp1, 5 'load register R24 with value Rcall _Lcd_control 'it is a control value to control the display Ldi _temp1,65 'load register with new value (letter A) Rcall _Write_lcd 'write it to the LCD-display ******************************************************************************* * Directives * ******************************************************************************* $LCD **** Action Instruct the compiler to generate code for 8-bit LCD displays attached to the data bus. Syntax $LCD = [&H]address Remarks Address The address where must be written to, to enable the LCD display and the RS line of the LCD display. The db0-db7 lines of the LCD must be connected to the data lines D0-D7. (or is 4 bit mode, connect only D4-D7) The RS line of the LCD can be configured with the LCDRS statement. On systems with external RAM, it makes more sense to attach the LCD to the data bus. With an address decoder, you can select the LCD display. Do not confuse $LCD with the LCD statement. See also $LCDRS , CONFIG LCD ******************************************************************************* $LCDPUTCTRL *********** Action Specifies that LCD control output must be redirected. Syntax $LCDPUTCTRL = label Remarks Label The name of the assembler routine that must be called when a control byte is printed with the LCD statement. The character must be placed in register R24. With the redirection of the LCD statement, you can use your own routines. See also $LCDPUTDATA ******************************************************************************* $LCDPUTDATA *********** Action Specifies that LCD data output must be redirected. Syntax $LCDPUTDATA = label Remarks Label The name of the assembler routine that must be called when a character is printed with the LCD statement. The character must be placed in R24. With the redirection of the LCD statement, you can use your own routines. See also $LCDPUTCTRL ******************************************************************************* $LCDRS ****** Action Instruct the compiler to generate code for 8-bit LCD displays attached to the data bus. Syntax $LCDRS = [&H]address Remarks Address The address where must be written to, to enable the LCD display. The db0-db7 lines of the LCD must be connected to the data lines D0-D7. (or is 4 bit mode, connect only D4-D7) On systems with external RAM, it makes more sense to attach the LCD to the data bus. With an address decoder, you can select the LCD display. See also $LCD , CONFIG LCDBUS ******************************************************************************* $LCDVFO ******* Action Instruct the compiler to generate very short Enable pulse for VFO displays. Syntax $LCDVFO Remarks VFO based displays need a very short Enable pulse. Normal LCD displays need a longer pulse. To support VFO displays this compiler directive has been added. The display need to be instruction compatible with normal HD44780 based text displays. Noritake is the biggest manufacturer of VFO displays. The $LCDVFO directive is intended to be used in combination with the LCD routines. ******************************************************************************* $SERIALINPUT2LCD **************** Action This compiler directive will redirect all serial input to the LCD display instead of echo-ing to the serial port. Syntax $SERIALINPUT2LCD Remarks You can also write your own custom input or output driver with the $SERIALINPUT and $SERIALOUTPUT statements, but the $SERIALINPUT2LCD is handy when you use a LCD display. By adding only this directive, you can view all output form routines such as PRINT, PRINTBIN, on the LCD display. See also $SERIALINPUT , $SERIALOUTPUT , $SERIALINPUT1 , $SERIALOUTPUT1 ******************************************************************************* * Instructions * ******************************************************************************* CLS *** Action Clear the LCD display and set the cursor to home. Syntax CLS Remarks Clearing the LCD display does not clear the CG-RAM in which the custom characters are stored. See also $LCD , $LCDRS , LCD , SHIFTLCD , SHIFTCURSOR , SHIFTLCD , INITLCD ******************************************************************************* CONFIG LCD ********** Action Configure the LCD display and override the compiler setting. Syntax CONFIG LCD = LCDtype , CHIPSET=KS077 | Dogm163v5 | DOG163V3 | DOG162V5 | DOG162V3 [,CONTRAST=value] Remarks LCDtype The type of LCD display used. This can be : 40 * 4,16 * 1, 16 * 2, 16 * 4, 16 * 4, 20 * 2 or 20 * 4 or 16 * 1a or 20*4A. Default 16 * 2 is assumed. CHIPSET KS077 Most text based LCD displays use the same chip from Hitachi. But some use the KS077 which is highly compatible but needs an additional function register to be set. This parameter will cause that this register is set when you initialize the display. CHIPSET DOGM The DOGM chip set uses a special function register that need to be set. The 16 x 2 LCD displays need DOG162V3 for 3V operation or DOG162V5 for 5V operation. The 16 x 3 LCD displays need DOG163V3 for 3V operation or Dogm163v5 for 5V operation CONTRAST The optional contrast parameter is only supported for the EADOG displays. By default a value from the manufacture is used. But you might want to override this value with a custom setting. When you have a 16 * 2 display, you don't have to use this statement. The 16 * 1a is special. It is used for 2 * 8 displays that have the address of line 2, starting at location &H8. The 20*4A is also special. It uses the addresses &H00, &H20, &H40 and &H60 for the 4 lines. It will also set a special function register. The CONFIG LCD can only be used once. You can not dynamic(at run time) change the pins. When you want to initialize the LCD during run time, you can use the INITLCD statement. See Also CONFIG LCDPIN , CONFIG LCDBUS ******************************************************************************* CONFIG LCDBUS ************* Action Configures the LCD data bus and overrides the compiler setting. Syntax CONFIG LCDBUS = constant Remarks Constant 4 for 4-bit operation, 8 for 8-bit mode (default) Use this statement together with the $LCD = address statement. When you use the LCD display in the bus mode the default is to connect all the data lines. With the 4-bit mode, you only have to connect data lines d7-d4. See also CONFIG LCD ******************************************************************************* CONFIG LCDMODE ************** Action Configures the LCD operation mode and overrides the compiler setting. Syntax CONFIG LCDMODE = type Remarks Type PORT Will drive the LCD in 4-bit port mode and is the default. In PORT mode you can choose different PIN's from different PORT's to connect to the upper 4 data lines of the LCD display. The RS and E can also be connected to a user selectable pin. This is very flexible since you can use pins that are not used by your design and makes the board layout simple. On the other hand, more software is necessary to drive the pins. BUS will drive the LCD in bus mode and in this mode is meant when you have external RAM and so have an address and data bus on your system. The RS and E line of the LCD display can be connected to an address decoder. Simply writing to an external memory location select the LCD and the data is sent to the LCD display. This means the data-lines of the LCD display are fixed to the data-bus lines. Use $LCD = address and $LCDRS = address, to specify the addresses that will enable the E and RS lines. See also CONFIG LCD , $LCD , $LCDRS ******************************************************************************* CONFIG LCDPIN ************* Action Override the LCD-PIN select options. Syntax CONFIG LCDPIN = PIN , DB4= PN,DB5=PN, DB6=PN, DB7=PN, E=PN, RS=PN CONFIG LCDPIN = PIN , PORT=PORTx, E=PN, RS=PN Remarks PN The name of the PORT pin such as PORTB.2 for example. PORTX When you want to use the LCD in 8 bit data, pin mode, you must specify the PORT to use. You can override the PIN selection from the Compiler Settings with this statement, so a second configuration lets you not choose more pins for a second LCD display. The config command is preferred over the menu settings since the code makes clear which pins are used. The CONFIG statement overrides the Options setting. See also CONFIG LCD ******************************************************************************* CURSOR ****** Action Set the LCD Cursor State. Syntax CURSOR ON / OFF BLINK / NOBLINK Remarks You can use both the ON or OFF and BLINK or NOBLINK parameters. At power up the cursor state is ON and NOBLINK. See also DISPLAY , LCD , SHIFTLCD , SHIFTCURSOR ******************************************************************************* DEFLCDCHAR ********** Action Define a custom LCD character. Syntax DEFLCDCHAR char,r1,r2,r3,r4,r5,r6,r7,r8 Remarks char Constant representing the character (0-7). r1-r8 The row values for the character. You can use the LCD designer to build the characters. It is important that a CLS follows the DEFLCDCHAR statement(s). So make sure you use the DEFLCDCHAR before your CLS statement. Special characters can be printed with the Chr() function. LCD Text displays have a 64 byte memory that can be used to show your own custom characters. Each character uses 8 bytes as the character is an array from 8x8 pixels. You can create a maximum of 8 characters this way. Or better said : you can show a maximum of 8 custom characters at the same time. You can redefine characters in your program but with the previous mentioned restriction. A custom character can be used to show characters that are not available in the LCD font table. For example a Û. You can also use custom characters to create a bar graph or a music note. See also Tools LCD designer ******************************************************************************* DISPLAY ******* Action Turn LCD display on or off. Syntax DISPLAY ON / OFF Remarks The display is turned on at power up. See also LCD ******************************************************************************* FOURTHLINE ********** Action Set LCD cursor to the start of the fourth line. Syntax FOURTHLINE Remarks Only valid for LCD displays with 4 lines. See also HOME , UPPERLINE , LOWERLINE , THIRDLINE, LOCATE ******************************************************************************* HOME **** Action Place the cursor at the specified line at location 1. Syntax HOME UPPER | LOWER | THIRD | FOURTH Remarks If only HOME is used than the cursor will be set to the upper line. You may also specify the first letter of the line like: HOME U See also CLS , LOCATE ******************************************************************************* INITLCD ******* Action Initializes the LCD display. Syntax INITLCD Remarks The LCD display is initialized automatic at start up when LCD statements are used by your code. If fore some reason you would like to initialize it again you can use the INITLCD statement. For example in environments with static electricity, the display can give strange output. You can initialize the display then once in a while. When the display is initialized, the display content is cleared also. The LCD routines depend on the fact that the WR pin of the LCD is connected to ground. But when you connect it to as port pin, you can use INITLCD after you have set the WR pin to logic 0. See also LCD ******************************************************************************* LCD *** Action Send constant or variable to LCD display. Syntax LCD x Remarks X Variable or constant to display. More variables can be displayed separated by the ; -sign LCD a ; b1 ; "constant" The LCD statement behaves just like the PRINT statement. So SPC() can be used too. The only difference with PRINT is that no CR+LF is added when you send data to the LCD. See also $LCD , $LCDRS , CONFIG LCD , SPC , CLS , INITLCD , SHIFTLCD , SHIFTCURSOR , CURSOR ******************************************************************************* LCD4.LIB ******** The built in LCD driver for the PIN mode is written to support a worst case scenario where you use random pins of the microprocessor to drive the LCD pins. This makes it easy to design your PCB but it needs more code. When you want to have less code you need fixed pins for the LCD display. With the statement $LIB "LCD4.LBX" you specify that the LCD4.LIB will be used. The following connections are used in the asm code: Rs = PortB.0 RW = PortB.1 we dont use the R/W option of the LCD in this version so connect to ground E = PortB.2 E2 = PortB.3 optional for lcd with 2 chips Db4 = PortB.4 the data bits must be in a nibble to save code Db5 = PortB.5 Db6 = PortB.6 Db7 = PortB.7 You can change the lines from the lcd4.lib file to use another port. Just change the address used : .EQU LCDDDR=$17 ; change to another address for DDRD ($11) .EQU LCDPORT=$18 ; change to another address for PORTD ($12) See the demo lcdcustom4bit.bas in the SAMPLES dir. Note that you still must select the display that you use with the CONFIG LCD statement. See also the lcd42.lib for driving displays with 2 E lines. Note that LBX is a compiled LIB file. In order to change the routines you need the commercial edition with the source code(lib files). After a change you should compile the library with the library manager. ******************************************************************************* LCD4BUSY ******** BASCOM supports LCD displays in a way that you can choose all pins random. This is great for making a simple PCB but has the disadvantage of more code usage. BASCOM also does not use the WR-pin so that you can use this pin for other purposes. The LCD4BUSY.LIB can be used when timing is critical. The default LCD library uses delays to wait until the LCD is ready. The lcd4busy.lib is using an additional pin (WR) to read the status flag of the LCD. The db4-db7 pins of the LCD must be connected to the higher nibble of the port. The other pins can be defined. '----------------------------------------------------------------------- ' (c) 2004 MCS Electronics ' lcd4busy.bas shows how to use LCD with busy check '----------------------------------------------------------------------- 'code tested on a 8515 $regfile="8515def.dat" 'stk200 has 4 MHz $crystal= 4000000 'define the custom library 'uses 184 hex bytes total $lib"lcd4busy.lib" 'define the used constants 'I used portA for testing Const _lcdport =Porta Const _lcdddr =Ddra Const _lcdin =Pina Const _lcd_e = 1 Const _lcd_rw = 2 Const _lcd_rs = 3 'this is like always, define the kind of LCD ConfigLcd= 16 * 2 'and here some simple lcd code Cls ******************************************************************************* LCD4E2 ****** The built in LCD driver for the PIN mode is written to support a worst case scenario where you use random pins of the microprocessor to drive the LCD pins. This makes it easy to design your PCB but it needs more code. When you want to have less code you need fixed pins for the LCD display. With the statement $LIB "LCD4E2.LBX" you specify that the LCD4.LIB will be used. The following connections are used in the asm code: Rs = PortB.0 RW = PortB.1 we don’t use the R/W option of the LCD in this version so connect to ground E = PortB.2 E2 = PortB.3 the second E pin of the LCD Db4 = PortB.4 the data bits must be in a nibble to save code Db5 = PortB.5 Db6 = PortB.6 Db7 = PortB.7 You can change the lines from the lcd4e2.lib file to use another port. Just change the address used : .EQU LCDDDR=$17 ; change to another address for DDRD ($11) .EQU LCDPORT=$18 ; change to another address for PORTD ($12) See the demo lcdcustom4bit2e.bas in the SAMPLES dir. Note that you still must select the display that you use with the CONFIG LCD statement. See also the lcd4.lib for driving a display with 1 E line. A display with 2 E lines actually is a display with 2 control chips. They must both be controlled. This library allows you to select the active E line from your code. In your basic code you must first select the E line before you use a LCD statement. The initialization of the display will handle both chips. Note that LBX is a compiled LIB file. In order to change the routines you need the commercial edition with the source code(lib files). After a change you should compile the library with the library manager. ******************************************************************************* LCDCONTRAST *********** Action Set the contrast of a TEXT LCD. Syntax LCDCONTRAST x Remarks X A variable or constant in the range from 0-3. Some LCD text displays support changing the contrast. Noritake displays have this option for example. ******************************************************************************* LOCATE ****** Action Moves the LCD cursor to the specified position. Syntax LOCATE y , x Remarks X Constant or variable with the position. (1-64*) Y Constant or variable with the line (1 - 4*) * Depending on the used display See also CONFIG LCD , LCD , HOME , CLS ******************************************************************************* LOWERLINE ********* Action Reset the LCD cursor to the lower line. Syntax LOWERLINE See also UPPERLINE , THIRDLINE , FOURTHLINE , HOME ******************************************************************************* SHIFTCURSOR *********** Action Shift the cursor of the LCD display left or right by one position. Syntax SHIFTCURSOR LEFT | RIGHT See also SHIFTLCD ******************************************************************************* SHIFTLCD ******** Action Shift the LCD display left or right by one position. Syntax SHIFTLCD LEFT / RIGHT See also SHIFTCURSOR , SHIFTCURSOR , INITLCD , CURSOR ******************************************************************************* THIRDLINE ********* Action Reset LCD cursor to the third line. Syntax THIRDLINE See also UPPERLINE , LOWERLINE , FOURTHLINE ******************************************************************************* UPPERLINE ********* Action Reset LCD cursor to the upper line. Syntax UPPERLINE Remarks Optional you can also use the LOCATE statement. See also LOWERLINE , THIRDLINE , FOURTHLINE , LCD, CLS , LOCATE *******************************************************************************