Device = 18F26K22
Declare Xtal 16
Config_Start
FOSC = INTIO67 'INTIO7 'INTIO67 'HSHP ' HS oscillator (high power > 16 MHz)
PLLCFG = On ' Oscillator multiplied by 4
PRICLKEN = On ' Primary clock enabled
FCMEN = OFF ' Fail-Safe Clock Monitor disabled
IESO = OFF ' Internal/External Oscillator Switchover mode disabled
PWRTEN = OFF 'On ' Power up timer enabled
BOREN = SBORDIS 'OFF ' Brown-out Reset enabled in hardware only (SBOREN is disabled)
BORV = 190 ' Brown Out Reset Voltage set to 1.90 V nominal
WDTEN = Off ' Watch dog timer is always disabled. SWDTEN has no effect.
WDTPS = 128 ' Watchdog Timer Postscale 1:128
CCP2MX = PORTC1 ' CCP2 input/output is multiplexed with RC1
PBADEN = Off ' PORTB<5:0> pins are configured as digital I/O on Reset
CCP3MX = PORTC6 ' P3A/CCP3 input/output is multiplexed with RC6
HFOFST = On ' HFINTOSC output and ready status are not delayed by the oscillator stable status
T3CMX = PORTC0 ' Timer3 Clock Input (T3CKI) is on RC0
P2BMX = PORTB5 ' ECCP2 B (P2B) is on RB5 (EXTMCLR = Enable MCLR/Disable RE Input)
MCLRE = INTMCLR ' MCLR pin enabled, RE3 input pin disabled (INTMCLR = Disable MCLR/Enabled RE Input)
STVREN = Off ' Stack full/underflow will not cause Reset
LVP = Off ' Single-Supply ICSP disabled
XINST = Off ' Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
Debug = Off ' Disabled
Cp0 = Off ' Block 0 (000800-001FFFh) not code-protected
CP1 = Off ' Block 1 (002000-003FFFh) not code-protected
CP2 = Off ' Block 2 (004000-005FFFh) not code-protected
CP3 = Off ' Block 3 (006000-007FFFh) not code-protected
CPB = Off ' Boot block (000000-0007FFh) not code-protected
CPD = Off ' Data EEPROM not code-protected
WRT0 = Off ' Block 0 (000800-001FFFh) not write-protected
WRT1 = Off ' Block 1 (002000-003FFFh) not write-protected
WRT2 = Off ' Block 2 (004000-005FFFh) not write-protected
WRT3 = Off ' Block 3 (006000-007FFFh) not write-protected
WRTC = Off ' Configuration registers (300000-3000FFh) not write-protected
WRTB = Off ' Boot Block (000000-0007FFh) not write-protected
WRTD = Off ' Data EEPROM not write-protected
EBTR0 = Off ' Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
EBTR1 = Off ' Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
EBTR2 = Off ' Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
EBTR3 = Off ' Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
EBTRB = Off ' Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
Config_End
OSCCON = %11110000
OSCCON2= %00000100
Declare SCL_Pin = PORTC.3 ' SCL connected to this pin for use with Busin and Busout
Declare SDA_Pin = PORTC.4 ' SDA connected to this pin for use with Busin and Busout
Declare Slow_Bus On ' Slows the bus speed when an oscillator higher than 4MHz
ANSELC = %00000000 ' Set portC Digital
TRISC = %00000001 ' Set PortC I/O
MMA7455_W_OFFSET(0,4,8) ' (X,Y,Z) 'Call Lib and Write Offset
Ini:
MMA7455_ReadDate() 'Call Lib read Data x,y,z
Print At 3,50,"X: ",Dec ACE_X
Print At 4,50,"Y: ",Dec ACE_Y
Print At 5,50,"Z: ",Dec ACE_Z
DelayMS 100
Goto Ini
END
$ifndef __MMA7455_INC_
$define __MMA7455_INC_
'
' MMA7455 variables
'
Dim ACE_X As Byte ' Read Value X
Dim ACE_Y As Byte ' Read Value Y
Dim ACE_Z As Byte ' Read Value Z
Dim OFF_X As Byte ' Value Offset X
Dim OFF_Y As Byte ' Value Offset Y
Dim OFF_Z As Byte ' Value Offset Z
'
' MMA7455 register addresses
'
$define C_REG_MM7 $16 ' 16 DIRECCION CONTROL REGISTRO
$define RE_ACELERO $3A ' 0011 1011 3A ALIAS DEL CODIGO PARA LEER
$define WR_ACELERO $3B ' 0011 1010 3B ALIAS DEL CODIGO PARA ESCRIBIR
$define LEO_X_REG $06 ' Read register X (8-Bit)
$define LEO_Y_REG $07 ' Read register Y (8-Bit)
$define LEO_Z_REG $08 ' Read register Z (8-Bit)
$ifndef False
$define False 0
$endif
$ifndef True
$define True 1
$endif
'----------------------------------------------------------------------------
GoTo _MMA7455_Main ' Jump over the routines
'----------------------------------------------------------------------------
$define MMA7455_W_OFFSET(hXX, hYY, hZZ) '
OFF_X = hXX '
OFF_Y = hYY '
OFF_Z = hZZ '
GoSub _MMA7455_W_OFFSET
_MMA7455_W_OFFSET:
HBStart ' Open I2C
HBusOut WR_ACELERO ,C_REG_MM7,[$65] ' Write MCTL Register $16, sending
HBusOut WR_ACELERO ,REG_XOFFL,[OFF_X] ' X LowByte Pag 14 DataSheet
HBusOut WR_ACELERO ,REG_YOFFL,[OFF_Y] ' Y LowByte
HBusOut WR_ACELERO ,REG_ZOFFL,[OFF_Z] ' Z LowByte
HBStop
Return
$define MMA7455_ReadDate() GoSub _MMA7455_ReadDate
_MMA7455_ReadDate:
' MMA7455_SendDate
HBStart
HBusIn RE_ACELERO ,LEO_X_REG,[ACE_X]
HBusIn RE_ACELERO ,LEO_Y_REG,[ACE_Y]
HBusIn RE_ACELERO ,LEO_Z_REG,[ACE_Z]
HBStop
DelayMS 100
Return
'----------------------------------------------------------------------------
_MMA7455_Main:
$endif ' _MMA7455_INC_
I do not understand, explain better.
THX.
I don´t understand you this part "I don't agree with the idea of not using a hardware I2C engine".
.This why I'm no longer using h/w I2C master.
The language is Proton Compiler (Crownhill).
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?