 |
|
 |
' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------
'
' Reads a potentiometer with RCTIME and sends the value to a SEETRON
' (www.seetron.com) serial LCD.
' -------------------------------------------------------------------------
' Device Settings
' -------------------------------------------------------------------------
DEVICE SX28, OSCXT2, TURBO, STACKX, OPTIONX
FREQ 4_000_000
ID "SEROUT"
' -------------------------------------------------------------------------
' IO Pins
' -------------------------------------------------------------------------
PotPin VAR RA.0 ' I/O pin for RCTIME
Sout VAR RA.1 ' output to SEETRON 2x16
' -------------------------------------------------------------------------
' Constants
' -------------------------------------------------------------------------
Baud CON "N9600"
LcdI CON $FE ' instruction
LcdCls CON $01 ' clear the LCD
LcdHome CON $02 ' move cursor home
LcdCrsrL CON $10 ' move cursor left
LcdCrsrR CON $14 ' move cursor right
LcdDispL CON $18 ' shift chars left
LcdDispR CON $1C ' shift chars right
LcdDDRam CON $80 ' Display Data RAM control
LcdCGRam CON $40 ' Character Generator RAM
LcdLine1 CON $80 ' DDRAM address of line 1
LcdLine2 CON $C0 ' DDRAM address of line 2
' -------------------------------------------------------------------------
' Variables
' -------------------------------------------------------------------------
analog VAR Byte ' pot value
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:
DELAY 750 ' let LCD initialize
TX_BYTE LcdI ' clear screen, home cursor
TX_BYTE LcdCls
DELAY 1
PUT line1, "POT: " ' initialize LCD buffer
PUT line2, " "
Main:
HIGH PotPin ' charge capacitor
DELAY_US 250 ' for 250 usecs
RCTIME PotPin, 1, analog, 5 ' read pot (10 us units)
Show_Pot:
tmpB1 = analog / 100 ' get 100s value
tmpB2 = __REMAINDER ' save 10s and 1s
tmpB1 = tmpB1 + "0" ' convert 100s to ASCII
PUT line1(5), tmpB1 ' move to LCD buffer
tmpB1 = tmpB2 / 10 ' get 10s value
tmpB2 = __REMAINDER ' save 1s
tmpB1 = tmpB1 + "0" ' convert 10s to ASCII
PUT line1(6), tmpB1 ' move to LCD buffer
tmpB1 = tmpB2 + "0" ' convert 1s to ASCII
PUT line1(7), tmpB1 ' move to LCD buffer
UPDATE_L1 ' update LCD
DELAY 100 ' wait 100 ms
GOTO Main ' do it over
' -------------------------------------------------------------------------
' 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 LcdI ' cursor to line 1, col 0
TX_BYTE LcdLine1
DELAY 1
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 LcdI ' cursor to line 2, col 0
TX_BYTE LcdLine2
DELAY 1
FOR idx = 0 TO 15
TX_BYTE line2(idx) ' transfer buffer
NEXT
RETURN
' -------------------------------------------------------------------------
' Updates the LCD with both line buffers
UPDATE_LCD:
TX_BYTE LcdI
TX_BYTE LcdHome
DELAY 1
UPDATE_L1
UPDATE_L2
RETURN