Sei sulla pagina 1di 3

' ' ' ' ' ' ' ' ' ' ' ' ' ' '

Program 3-WIRE.BAS ************************************************************* * For use with EXPERIMENTING WITH THE PICBASIC PRO COMPILER * * * * This source code may be freely used within your own * * programs. However, if it is used for profitable reasons, * * please give credit where credit is due. * * And make a reference to myself or Rosetta Technologies * * * * Les. Johnson * ************************************************************* Read a voltage from any of the inputs from a MAX186 A/D converter and display the result on a serial LCD set for Inverted 9600 baud This program uses a 3 wire interface with the MAX186

' The Demonstration circuit has a 10K pot from Vdd to Gnd with the centre Wiper going to CH0. ' MAX186 pin connections: ' ' ' ' ' DOUT - DIN (connected together by a 1k resistor (PORTB.2) SSTRB (Conversion status flag, Optional Connection) CS (Active-low select, PORTB.1) SCLK (Serial clock line, PORTB.0) *********************************************************************** Include "Modedefs.Bas" ' ** Setup Crystal Frequency in mhz ** Define OSC ' ** Setup Debug Defines ** Define Define Define Define Define rs sent ' ** Declare the variables ** Max_Val Cntrl 6 Max_Ch Var Max_Temp Var d by the MAX186 subroutine V Var Mv Var Sclk put Cs Var PortB.1 e ' ** DTA, used to be DIN and DOUT ** Dta Var PortB.2 ut and output SSTRB Var PortB.4 ' MAX186 chip select lin ' MAX186 serial data inp ' MAX186 conversion stat Var Byte Byte Byte Word PortB.0 ' Analog input channel ' Temporary variable use ' Volts variable ' Millivolts variable ' MAX186 serial clock in Var Var Word Byte ' 12 bit ADC result ' Control byte for MAX18 DEBUG_REG DEBUG_BIT DEBUG_BAUD DEBUG_MODE DEBUG_PACING PortA 0 9600 1 500 ' ' ' ' ' Debug PortA *** Debug pin Bit-0 *** *** Debug Baud Rate *** Set Serial Mode Inverted Delay 'in Us' between characte 4 ' Set Xtal Frequency

us flag,(OPTIONAL) ' ** Define LCD Constants ** I Clr Line1 line 1 Line2 line 2 Line3 line 3 Line4 line 4 Cgram LCD Shift_L Shift_R Con Con 24 28 ' Shift display left ' Shift display right Con 64 ' Point to Cgram within Con 212 ' Point to beginning of Con 148 ' Point to beginning of Con 192 ' Point to beginning of Con Con Con 254 1 128 ' Control Byte ' Clear the display ' Point to beginning of

' ** The Main program starts here ** Pause 500 lize Debug I,Clr:Pause 30 Main: Max_Ch=0 the MAX186 Gosub Max186_In V= Max_Val/1000 dividing by 1000 Mv= Max_Val //1000 s by dividing by 1000 Debug I,Line1,"Max_Val= ",#Max_Val," " Debug I,Line2,#V,".",dec3 Mv," Volts" ivolts Goto Main ' Point to Channel 0 of ' Go and do a sample ' Split off the volts by ' Split off the millivot ' Display the Volts.Mill ' Do it forever of the 7 inputs of the "MAX_CH". ' Clear the LCD ' Wait for Pic to Initia

' This subroutine returns the value of the voltage on any MAX186. ' Before calling, Tha channel to read from is loaded into ' "MAX_VAL" returns with the voltage Max186_In: Max_Val=0 Max_Temp=Max_Ch ' _Ch" Lookup Max_Ch,[0,64,16,80,32,96,48,112],Max_Ch Cntrl=%10001110 | Max_Ch ' ts Low Cs ' ' ** DOUT has changed to DTA ** Shiftout Dta,Sclk,Msbfirst,[Cntrl\8] ' byte ' ** DIN has also changed to DTA ** Shiftin Dta,Sclk,Msbpost,[Max_Val\12] ' x_Val" High Cs ' Max_Ch=Max_Temp ' Max_Ch" Return '

Save the Value of "Max "OR" in the Channel bi Activate the MAX186 Clock out the Control Clock 12 bits into "Ma Deactivate the MAX186 Restore the value of " Exit the subroutine

Potrebbero piacerti anche