' ------------------------------------------------------------------------- ' Program Description ' ------------------------------------------------------------------------- ' 04/01/2007 v1.0 Tested working code ' ' Demonstrates sending data to serial iLCD at 2400bps ' ------------------------------------------------------------------------- ' Device Settings ' ------------------------------------------------------------------------- DEVICE SX28, oscxt2, TURBO, STACKX, OPTIONX FREQ 4_000_000 ID "SEROUT" ' ------------------------------------------------------------------------- ' IO Pins ' ------------------------------------------------------------------------- Sout VAR RC.6 ' pin used to output to iLCD 2x16, change this pin to your pin ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- Baud CON "N2400" ESC CON $1B ' instruction ESC LcdCls CON "1" ' clear the LCD using character 1 LcdLine1 CON $80 ' DDRAM address of line 1 LcdLine2 CON $C0 ' DDRAM address of line 2 ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- char VAR Byte ' character to send idx VAR Byte ' loop counter line1 VAR Byte(16) ' line 1 buffer line2 VAR Byte(16) ' line 2 buffer tmpB1 VAR Byte ' subroutine work vars tmpB2 VAR Byte tmpW1 VAR Word ' ========================================================================= PROGRAM Start ' ========================================================================= ' ------------------------------------------------------------------------- ' Subroutine DECLARATIONS ' ------------------------------------------------------------------------- TX_BYTE SUB 1, 2 ' transmit a byte DELAY_US SUB 1, 2 ' delay in microseconds DELAY SUB 1, 2 ' delay in milliseconds UPDATE_L1 SUB 0 ' update line 1 of LCD UPDATE_L2 SUB 0 ' update line 2 of LCD UPDATE_LCD SUB 0 ' update both lines ' ------------------------------------------------------------------------- ' Program Code ' ------------------------------------------------------------------------- Start: OUTPUT Sout ' set pin to output DELAY 900 ' wait for LCD to wake up TX_BYTE ESC ' clear screen, home cursor TX_BYTE LcdCls DELAY 50 ' delay a bit after clear screen PUT line1, " HELLO THERE " ' initialize LCD buffers PUT line2, " FROM SXB " UPDATE_LCD ' draw to the screen Main: GOTO Main ' loop forever ' ------------------------------------------------------------------------- ' Subroutines Code ' ------------------------------------------------------------------------- ' Use: TX_BYTE theByte {, repeats } ' -- first parameter is byte to transmit ' -- second (optional) parameter is number of times to send TX_BYTE: tmpB1 = __PARAM1 ' char to send IF __PARAMCNT = 1 THEN ' if no repeats specified tmpB2 = 1 ' - set to 1 ELSE tmpB2 = __PARAM2 ' - save repeats ENDIF DO WHILE tmpB2 > 0 SEROUT Sout, Baud, tmpB1 ' send the character DEC tmpB2 LOOP RETURN ' ------------------------------------------------------------------------- ' Use: DELAY_US us ' -- 'us' is delay in microseconds, 1 - 65535 DELAY_US: IF __PARAMCNT = 1 THEN tmpW1 = __PARAM1 ' save byte value ELSE tmpW1 = __WPARAM12 ' save word value ENDIF PAUSEUS tmpW1 RETURN ' ------------------------------------------------------------------------- ' Use: DELAY ms ' -- 'ms' is delay in milliseconds, 1 - 65535 DELAY: IF __PARAMCNT = 1 THEN tmpW1 = __PARAM1 ' save byte value ELSE tmpW1 = __WPARAM12 ' save word value ENDIF PAUSE tmpW1 RETURN ' ------------------------------------------------------------------------- ' Transfers line 1 buffer to LCD ' -- makes no change in LCD screen position UPDATE_L1: TX_BYTE ESC TX_BYTE "P" TX_BYTE LcdLine1 FOR idx = 0 TO 15 TX_BYTE line1(idx) ' transfer buffer NEXT RETURN ' ------------------------------------------------------------------------- ' Transfers line 2 buffer to LCD ' -- makes no change in LCD screen position UPDATE_L2: TX_BYTE ESC TX_BYTE "P" TX_BYTE LcdLine2 FOR idx = 0 TO 15 TX_BYTE line2(idx) ' transfer buffer NEXT RETURN ' ------------------------------------------------------------------------- ' Updates the LCD with both line buffers UPDATE_LCD: UPDATE_L1 UPDATE_L2 RETURN