YIM bunchhat
Member level 2
- Joined
- Oct 19, 2010
- Messages
- 46
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,288
- Activity points
- 1,580
program Accelrometer
SYMBOL CS = PORTC.0
DIM DAX,DAY,DAZ AS SHORT
DIM VX,VY,VZ AS STRING[4]
''''''''''''''''''Read data from sensor''''''''''''''''''''''''''''
SUB FUNCTION SPI_RD(DIM ADD AS BYTE) AS BYTE
RESULT = 0
ADD = ADD << 1
ADD = %00000000 OR ADD
CS = 0
SPI1_write(ADD)
RESULT = SPI1_read(0x00)
CS = 1
END SUB
''''''''''''''''''''''''Write register to sensor''''''''''''''''''''''''''''''''''''
SUB PROCEDURE SPI_WR(DIM ADD AS BYTE,DIM THEDA AS BYTE)
ADD = ADD << 1
ADD = %10000000 OR ADD
CS = 0
SPI1_write(ADD)
SPI1_write(THEDA)
CS = 1
END SUB
main:
DAX =0
DAY = 0
DAZ = 0
Delay_ms(3000)
UART1_Init(9600)
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_HIGH_2_LOW)
SPI_WR($0D,$9D)
SPI_WR($16,$05)
SPI_WR($10,40)
SPI_WR($12,90)
SPI_WR($14,0)
START:
DAX = SPI_RD($06)
DAY = SPI_RD($07)
DAZ = SPI_RD($08)
ShortToStr(DAX,VX)
ShortToStr(DAY,VY)
ShortToStr(DAZ,VZ)
''''''''''''''''''Send data to COM''''''''''''''''
UART1_Write_Text(VX)
UART1_Write_Text(VY)
UART1_Write_Text(VZ)
Delay_ms(500)
GOTO START
end.
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?