For now, I can not make the preparation of Proton code. As you know 16F877 8-bit compiler to do arctangent operation to have an architecture that does not allow on Proton Basic. I will continue on the same plane with the code I made before. If you prepared for an 8-bit architecture, inc file you have, I'm glad you shared. However, when trying CCS C 8-bit architecture arctangent operations, Picbasic Pro account can be made in a very limited, and Proton Basic not to have never tried, very confusing.
Posted on: 22 March 2015, 09:10:22 - Automerged
HMC5883L Digital Compass with Pic 16f877A Picbasic Code
Related to the acceleration sensors, many questions unanswered in the forums and saw the unfinished work. Codes associated with acceleration sensors, I'll be posting the help of the codes used in the forums.
Some mathematical formulas taken from their pdf files of the acceleration sensor. Some numbers, because it does not allow the processor bits I wrote using the appropriate numbers. CCS C is very efficient in this regard. 8-bit inefficiency is able to absorb ("math.h"). Proton and Picbasic Pro may be errors. I'm glad you publish corrections.
We may in the future use of these codes to balance the robot and share code.
Good work everyone.
This codes works fine for me.
But I left as a side note to never trust the accuracy of the arctangent operation. I would be glad if you share that ensure the accuracy or improvement of.
Picbasic Code'****************************************************************
'* Name : HMC5883 PBP 16F877A.BAS *
'* Author : YUKSEL *
'* Notice : Copyright (c) 2015 YUKSEL *
'* : All Rights Reserved *
'* Date : 15.3.2015 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
adcon1 = 7 ' Turns Analogs off
'For 20 MHz config
#config
__config _HS_OSC & _LVP_OFF
#ENDCONFIG
DEFINE OSC 20
TRISA = %00000000
TRISB = %00000000
PORTC = %01000000
PORTD = %00000011
PORTE = %00000000
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 5
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 4
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
Symbol SDA = PORTD.0 'I2C data pin. Pullup connection is required.
Symbol SCL = PORTD.1 'I2C clock pin. Pullup connection is required.
Symbol W_DAT = $3C 'Used to perform a Write operation
Symbol R_DAT = $3D 'Used to perform a Read operation
Symbol CON_A = $00
Symbol CON_B = $01 'Send continuous MeVARurement mode.
Symbol MOD_R = $02 'Read/Write Register, Selects the operating mode. Default = Single meVARurement
Symbol X_MSB = $03 'Read Register, Output of X MSB 8-bit value.
Symbol X_LSB = $04 'Read Register, Output of X LSB 8-bit value.
Symbol Z_MSB = $05 'Read Register, Output of Z MSB 8-bit value.
Symbol Z_LSB = $06 'Read Register, Output of Z LSB 8-bit value.
Symbol Y_MSB = $07 'Read Register, Output of Y MSB 8-bit value.
Symbol Y_LSB = $08 'Read Register, Output of Y LSB 8-bit value.
READX VAR Word
READY VAR Word
READZ VAR Word
'X VAR BYTE
'Y VAR BYTE
'AZ VAR WORD
PAUSE 100 ' Give sensor needed power up time
I2CWRITE SDA,SCL,W_DAT,MOD_R,[$00] '00
PAUSE 70
I2CWRITE SDA,SCL,W_DAT,CON_A,[$10] '70
PAUSE 2
I2CWRITE SDA,SCL,W_DAt,CON_B,[$60] 'A0
PAUSE 100
READI2C:
I2CREAD SDA,SCL,R_DAT,X_MSB,[READX.HighByte] 'Read the data starting at x_msb 3
I2CREAD SDA,SCL,R_DAT,X_LSB,[READX.LowByte]
I2CREAD SDA,SCL,R_DAT,Z_MSB,[READZ.HighByte]
I2CREAD SDA,SCL,R_DAT,Z_LSB,[READZ.LowByte]
I2CREAD SDA,SCL,R_DAT,Y_MSB,[READY.HighByte]
I2CREAD SDA,SCL,R_DAT,Y_LSB,[READY.LowByte]
PAUSE 100
'X = READX>>2
'Y = READY>>2
'AZ = (-y ATN x)
LCDOUT $FE,1, "X=",SDec READX,$FE,2,$FE,$14,$FE,$14,$FE,$14,$FE,$14,$FE,$14,$FE,$14,$FE,$14,$FE,$14,"Y=",SDec READY," "
LCDOUT $FE,$C0,"Z=",sDec READZ," "',$FE,$C0+7,$FE,$C0+8,"AZ=",dec3 (AZ * 141)/100 ', " "
GoTo READI2C:
End