ME Labs, Inc. 719-520-5323 |
ME Labs, Inc. | 1-719-520-5323 | Example Program - LTCX.pbpPICBASIC PRO program to read LTC1298 ADC.' Name : LTCX.pbp ' Compiler : PICBASIC PRO Compiler 2.6 ' Assembler : PM or MPASM ' Target PIC : 40-pin 16F877A, 18F452 or similar ' Hardware : LAB-X1 Experimenter Board ' Oscillator : 4MHz external crystal ' Keywords : SHIFTIN, SHIFTOUT, LCDOUT ' Description : PICBASIC PRO program to read LTC1298 ADC. ' ' Define LOADER_USED to allow use of the boot loader. ' This will not affect normal program operation. Define LOADER_USED 1 ' Define LCD pins Define LCD_DREG PORTD Define LCD_DBIT 4 Define LCD_RSREG PORTE Define LCD_RSBIT 0 Define LCD_EREG PORTE Define LCD_EBIT 1 Include "modedefs.bas" ' Alias pins CS Var PORTC.5 ' Chip select CK Var PORTC.3 ' Clock DI Var PORTA.2 ' Data in D0 Var PORTC.1 ' Data out ' Allocate variables addr Var Byte ' Channel address / mode x Var Word y Var Word z Var Word result Var Word High CS ' Chip select inactive ADCON1 = 7 ' Set PORTA, PORTE to digital Low PORTE.2 ' LCD R/W line low (W) Pause 100 ' Wait for LCD to start Goto mainloop ' Skip subroutines ' Subroutine to read a/d convertor getad: CS = 0 ' Chip select active ' Send address / mode - Start bit, 3 bit addr, null bit] Shiftout DI, CK, MSBFIRST, [1\1, addr\3, 0\1] Shiftin D0, CK, MSBPRE, [result\12] ' Get 12-bit result CS = 1 ' Chip select inactive Return ' Subroutine to get x value (channel 0) getx: addr = $05 ' Single ended, channel 0, MSBF high Gosub getad x = result Return ' Subroutine to get y value (channel 1) gety: addr = $07 ' Single ended, channel 1, MSBF high Gosub getad y = result Return ' Subroutine to get z value (differential) getz: addr = $01 ' Differential (ch0 = +, ch1 = -), MSBF high Gosub getad z = result Return mainloop: Gosub getx ' Get x value Gosub gety ' Get y value Gosub getz ' Get z value Lcdout $fe, 1, "x=", #x, " y=", #y, " z=", #z ' Send values to LCD Pause 100 ' Do it about 10 times a second Goto mainloop ' Do it forever End Download the program file. |
Copyright 2022 ME Labs, Inc. PO Box 8250 Asheville NC 28814 (719) 520-5323 (719) 520-1867 fax email: support@melabs.com |
|