' ========================================================================= ' ' File...... LTC1298_BPI216.SXB ' Purpose... ' Author.... Jon Williams _ Modified by MikeS ' E-mail.... ' Started... ' Updated... 10 Aug 2007 ' ' ========================================================================= ' ------------------------------------------------------------------------- ' Program Description ' ------------------------------------------------------------------------- 'This program reads the temp. from an LM34 analog temp. sensor and feed it into 'an LTC1298 ADC. The output is displayed on a BPI-216 LCD ' ------------------------------------------------------------------------- ' Device Settings ' ------------------------------------------------------------------------- DEVICE SX28, OSCXT2, TURBO, STACKX, OPTIONX FREQ 8_000_000 ' ------------------------------------------------------------------------- ' IO Pins ' ------------------------------------------------------------------------- LCD VAR RA.2 ' serial out to BPI-216 LCD CS VAR RB.0 '1298.1 Clock VAR RB.1 '1298.7 Dio VAR RB.2 '1298.5&6 ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- 'Seetron BPI-216 LCD LcdBaud CON "N2400" ' baud for serial LCD 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 ' ------------------------------------------------------------------------- adcLo VAR Byte adcHi VAR Byte temp1 VAR Byte ' subroutine work vars temp2 VAR Byte temp3 VAR Byte temp4 VAR Byte tmpB1 VAR Byte ' subroutine work vars tmpB2 VAR Byte tmpB3 VAR Byte tmpW1 VAR Word ' ========================================================================= PROGRAM Start ' ========================================================================= ' ------------------------------------------------------------------------- ' Subroutine Declarations ' ------------------------------------------------------------------------- WAIT_MS SUB 1, 2 TX_BYTE SUB 1 TX_HEX2 SUB 1 RD_1298 SUB 1 LCD_OUT SUB 1, 2 ' ------------------------------------------------------------------------- 'Program code ' ------------------------------------------------------------------------- Start: PLP_A = %0000 PLP_B = %00000111 PLP_C = %00000000 HIGH CS ' deselect adc LOW Clock ' init clock for 0-1-0 Wait_MS 100 ' let LCD initialize LCD_OUT LcdI ' Transmit control instruction Wait_MS 5 LCD_OUT LcdCls Wait_MS 1000 Show_Banner: LCD_OUT LcdI Wait_MS 5 LCD_OUT LcdLine1 LCD_OUT "hello" LCD_OUT LcdI Wait_MS 5 LCD_OUT LcdLine2 LCD_OUT "world" pause 1000 Main: DO LCD_OUT LcdI ' clear LCD Wait_MS 5 LCD_OUT LcdCls Wait_MS 5 LCD_OUT "LTC1298" LCD_OUT LcdI Wait_MS 5 LCD_OUT LcdLine2 LCD_OUT "Ch0: " RD_1298 0 ' read channel 0 TX_HEX2 adcHi ' display (hex) TX_HEX2 adcLo WAIT_MS 250, 2 LOOP END ' ------------------------------------------------------------------------- ' Subroutine Code ' ------------------------------------------------------------------------- ' Use: WAIT_MS milliseconds {, multiplier} ' -- multiplier is optional WAIT_MS: temp1 = __PARAM1 ' get milliseconds IF __PARAMCNT = 1 THEN ' if no multiplier temp2 = 1 ' set to 1 ELSE ' else temp2 = __PARAM2 ' get multiplier ENDIF IF temp1 > 0 THEN ' no delay if either 0 IF temp2 > 0 THEN PAUSE temp1 * temp2 ' do the delay ENDIF ENDIF RETURN ' ------------------------------------------------------------------------- '---------------------------------------------------------------- ' Use: TX_BYTE aByte ' -- transmits one byte to LCD TX_BYTE: temp1 = __PARAM1 ' copy outgoing byte SEROUT LCD, LCDBaud, temp1 RETURN ' ------------------------------------------------------------------------- ' Use: TX_HEX2 aByte ' -- sends "aByte" to host in HEX2 format (text) TX_HEX2: temp2 = __PARAM1 ' copy byte FOR temp3 = 1 TO 2 ' send two nibbles temp4 = temp2 & $F0 ' get a nibble SWAP temp4 IF temp4 < $A THEN temp4 = temp4 + "0" ' convert to "0".."9" ELSE temp4 = temp4 + 55 ' convert to "A".."F" ENDIF TX_BYTE temp4 ' send to host temp2 = temp2 << 4 ' position next nibble NEXT RETURN ' ------------------------------------------------------------------------- ' Use: RD_1298 channel ' -- puts ADC value for "channel" (0 or 1) in adcHi\adcLo RD_1298: temp1 = %1011 ' set for single-ended mode temp1.2 = __PARAM1.0 ' select channel CS = 0 SHIFTOUT Dio, Clock, LSBFIRST, temp1\4 ' send configuration SHIFTIN Dio, Clock, MSBPOST, adcHi\4 ' get high nib of adc SHIFTIN Dio, Clock, MSBPOST, adcLo\8 ' get low nib of adc CS = 1 RETURN ' ------------------------------------------------------------------------- ' Use: LCD_OUT [ aByte | string | label ] ' -- "aByte" is single-byte constant or variable ' -- "string" is an embedded literal string ' -- "label" is DATA statement label for stored z-String LCD_OUT: tmpB1 = __PARAM1 ' byte or string offset IF __PARAMCNT = 2 THEN ' string specified? tmpB2 = __PARAM2 ' yes, save base DO READ tmpB2 + tmpB1, tmpB3 ' read a character IF tmpB3 = 0 THEN EXIT ' if 0, string complete SEROUT Lcd, LcdBaud, tmpB3 ' send the byte INC tmpB1 ' point to next character tmpB2 = tmpB2 + Z ' update base on overflow LOOP ELSE SEROUT Lcd, LcdBaud, tmpB1 ' send the byte ENDIF RETURN ' -------------------------------------------------------------------------