'* PIC16F684 * Kinox KXTF9 Example *'
'Title: Kinox KXTF9 Example
'Description: This program uses PIC16F684 to communicate with the Kinox KXTF9.
'from AN-023: Getting Started with the KXTF9
'Author: languer (2012)
'General Configuration
Define CONF_WORD = 0x33c4
Define CLOCK_FREQUENCY = 8
'Define SIMULATION_WAITMS_VALUE = 1
OSCCON = 0x71 'set for internal 8MHZ oscillator
'Variable Declarations
Symbol io_sda = RA0 'I2C SDA
Symbol io_scl = RA1 'I2C SCL
Symbol io_rs232 = RA2 'rs232 debug output
Const kxtf9_address = 0x0f
Const ctrl_reg1 = 0x1b
Const tilt_timer = 0x28
Const wuf_timer = 0x29
Const b2s_timer = 0x2a
Const xout_h = 0x07
Const yout_h = 0x09
Const zout_h = 0x0b
Dim _true As Bit
Dim _false As Bit
_true = True
_false = False
'Main Program
main:
Dim data_x As Byte
Dim data_y As Byte
Dim data_z As Byte
AllDigital
TRISA = %11111111
TRISC = %11111111
'power-up delay (110ms minimum)
WaitMs 200
Serout io_rs232, 9600, "Example to poll KXTF9", CrLf
'set accelerometer to read back acceleration data
I2CWrite io_sda, io_scl, kxtf9_address, ctrl_reg1, 0x98
While _true
WaitMs 1000
I2CRead io_sda, io_scl, kxtf9_address, xout_h, data_x
I2CRead io_sda, io_scl, kxtf9_address, yout_h, data_y
I2CRead io_sda, io_scl, kxtf9_address, zout_h, data_z
Serout io_rs232, 9600, "X, Y, Z = ", #data_x, ", ", #data_y, ", ", #data_z, CrLf
Wend
End