Code:
'PIC 12F683 port/pin allocations
'-------------------------------
'GPIO.0/Pin 7 = I2C SCL clock
'GPIO.1/Pin 6 = I2C SDA data
'GPIO.2/Pin 5 = spare
'GPIO.3/Pin 4 = spare
'GPIO.4/Pin 3 = LED
'GPIO.5/Pin 2 = Serial TX
'-----------------------
' PIC Defines
' ===========
'Config bits set to INTERNAL OSC, Watch dog ON, Power up timer ON, Master Clear NOT used, BrownOut protection ON,
@ Device pic12f683, intrc_osc, wdt_on, pwrt_on, mclr_off, bod_on ;Config switches, different from PBP default
'@ __Config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF ;USING MPASM ONLY
Define Osc 4 '4Mhz clock used. Note - Set PIC config fuses on programmer to use Internal RC OSC
Include "modedefs.bas" ' Include serial modes
' Define some constants if needed
' Software Defines
Cal_table var word[11] '11 word array to store calibration data
Temp_Var var byte 'temp variable
Temp_Var2 var Word 'temp variable
i2c_Reg var Byte 'variable for target i2c register address
CPIN var GPIO.0 ' I2C clock pin
DPIN var GPIO.1 ' I2C data pin
SO Var GPIO.5 'Serial out pin
LED var GPIO.4 'Indicator LED, via 500ohm to +3.3V
'Alias's for calibration data in the sensor to match the Bosch paramater list names
AC1 var Cal_table[0] '
AC2 var Cal_table[1] 'BMP085 has 11 16bit values stored in EEPROM
AC3 var Cal_table[2] 'First byte is at $AA last at $BF
AC4 var Cal_table[3] 'Lowbyte is MSB, Highbyte is LSB
AC5 var Cal_table[4] 'some values are signed (not AC4, AC5, AC6)
AC6 var Cal_table[5]
B1 var Cal_table[6]
B2 var Cal_table[7]
MB var Cal_table[8]
MC var Cal_table[9]
MD var Cal_table[10]
' Initialise Processor - check for each PIC type either 12F629 or 12F675
' --------------------
VRCON.7 = %0 'Comparator voltage reference OFF
CMCON0 = %111 'Comparator inputs to OFF, all pins normal I/O
ANSEL = 0 'Turn off al AD's rem out for PIC12F629, use for PIC12F675
' Set initial state of GPIO port pins as Input or Output
TRISIO.0 = 0 'Input(0 = output, 1 = Input)
TRISIO.1 = 0 '
TRISIO.2 = 1 '
TRISIO.3 = 0 '
TRISIO.4 = 0 '
TRISIO.5 = 1 '
' PIC initialization code
Low LED 'LED on
pause 500
High LED 'LED off
Serout SO,N2400,[$FE,$01] ' Clear LCD & home LCD cursor.
pause 10 ' wait for LCD to catch up
Serout SO,N2400,[" FrSky Vario "] ' Serial print
Serout SO,N2400,[$FE,$C0] ' Shift cursor to line2
Serout SO,N2400,[" development jig "] ' Serial print
Pause 3000
i2c_Reg =$AA 'Start address of calibration data
I2CREAD DPIN,CPIN,$EF,I2C_REG,[STR Cal_table\11],read_error1 'Read 11 words out of sensor
Serout SO,N2400,[$FE,$01] ' Clear LCD & home LCD cursor.
Pause 10 ' wait for LCD to catch up
Main:
Serout SO,N2400,[$FE,$02] 'home LCD cursor.
i2c_Reg = $F4 '$F4 is the control register address
I2CWRITE DPIN,CPIN,$EE,I2C_REG,[$2E] ' Write $2E to set temperature conversion
Pause 10 ' Delay 10ms after each write
i2c_Reg = $F6 '$F6 is the result register MSB
I2CREAD DPIN,CPIN,$EF,I2C_REG,[Temp_Var2],read_error 'Read temperature MSB, LSB.
Serout SO,N2400,[#Temp_Var2," "] 'Send Word size number to LCD
'lets see whats in the cal data array for a checking math
Serout SO,N2400,[$FE,$C0] ' Shift cursor to line2
Serout SO,N2400,[#AC1," ",#AC2," ",#AC3]
Serout SO,N2400,[$FE,$94] ' Shift cursor to line3
Serout SO,N2400,[#AC4," ",#AC5," ",#AC6]
Serout SO,N2400,[$FE,$D4]
Serout SO,N2400,[#B1," ",#B2," ",#MB]
' ," ",#MC," ",#MD] '
pause 1000
Toggle LED
Goto main
Read_error:
Serout SO,N2400,[$FE,$01] ' Clear LCD & home LCD cursor.
Pause 10 ' wait for LCD to catch up
Serout SO,N2400,["i2c bus read error"] '
pause 250
Toggle LED
Goto main
Read_error1:
Serout SO,N2400,[$FE,$01] ' Clear LCD & home LCD cursor.
Pause 10
Serout SO,N2400,["i2c cal read error "] '
End
Bookmarks