I have a code from this page
[url]http://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&p=60815#60815[/url]
I would like to ask about the program description below
[code:1:02b82ae2bb]'===============================================================================
' Project: L3G4200D 3tripple axes gyro Test #1
' Created: 2011-12-23
' Edited: 2011-12-30
' By: Glen Aidukas [bahbots.com]
' Description:
' This is test software for initializing, reading and displaying data from
' the L3G4200D triple axes gyro via I2C on an ATMega1284P
' Note: ANSI (vt100) escape sequences are used to format output.
' Make sure to use ANSI or vt100 terminal type for proper formating.
' Breakout board is from: http://www.dsscircuits.com/l3g4200d-3-axis-gyro.html
' Datasheet: http://www.dsscircuits.com/images/datasheets/L3G4200D.pdf
'-------------------------------------------------------------------------------
'=====[ Compiler Directives ]===================================================
$crystal = 18432000
$regfile = "m1284pdef.dat"
$baud = 38400
$hwstack = 64
$swstack = 64
$framesize = 64
'-------------------------------------------------------------------------------
'=====[ Global Vars & Constants ]===============================================
dim tick as dword ' used for 100Hz tick count
dim tickn as dword ' used for next timer tick event
dim n as integer ' temp var for visual positioning
dim X as integer
dim Xl as byte at X + 0 overlay
dim Xh as byte at X + 1 overlay
dim Y as integer
dim Yl as byte at Y + 0 overlay
dim Yh as byte at Y + 1 overlay
dim Z as integer
dim Zl as byte at Z + 0 overlay
dim Zh as byte at Z + 1 overlay
dim Temp as byte
dim Status as byte
dim Test_gyro as Byte
'' list of L3G4200D register positions
Const WHO_AM_I = &H0F
Const L3G4200D_R = &HD3
Const L3G4200D_W = &HD2
Const CTRL_REG1 = &H20
Const CTRL_REG2 = &H21
Const CTRL_REG3 = &H22
Const CTRL_REG4 = &H23
Const CTRL_REG5 = &H24
'-------------------------------------------------------------------------------
'=====[ Setup Timer0 for Tick isr ]=============================================
Config Timer2= Timer, Prescale= 1024, Compare A= Disconnect, Clear Timer= 1
' crystal / Prescale / CountWanted = reload value
' 18432000 / 1024 / 100Hz = 180 (trigger every 100th sec (10ms))
OCR2A = 180 - 1
On OC2A TickCounter_isr
Enable OC2A
'-------------------------------------------------------------------------------
'=====[ I2C BUS INIT ]==========================================================
'configure the scl and sda pins
$LIB "I2C_TWI.LBX" ' uncomment for hardware I2C
'Config Scl = Portc.0 ' uncomment for software I2C
'onfig Sda = Portc.1 ' uncomment for software I2C
Config Twi = 400000
I2cinit
'-------------------------------------------------------------------------------
'=====[ Misc Initilization ]====================================================
Config Serialout = Buffered, Size = 254
print "{027}[2J{027}[1;1H"; "Starting..."
Enable Interrupts
print
print "InitGyro: ";
gosub InitGyro
'-------------------------------------------------------------------------------
'=====[ Start of main loop ]====================================================
do
if tick >= tickn then
Gosub Read_Gyro
print "{027}[5;1H"; "Count : "; tick; "{027}[K"
print "{027}[K"
print "Status: "; bin(status); "{027}[K"
print "Temp : "; temp; "{027}[K"
print "{027}[K"
print "{027}[10;1H";
print "Gyro-X: "; x; "{027}[K"
print "Gyro-Y: "; y; "{027}[K"
print "Gyro-Z: "; Z; "{027}[K"
'' print visual position of values
print "{027}[10;20H["; : print "{027}[10;60H]";
print "{027}[11;20H["; : print "{027}[11;60H]";
print "{027}[12;20H["; : print "{027}[12;60H]";
n= x/256 : n=n+ 40 : print "{027}[10;"; n; "H|";
n= y/256 : n=n+ 40 : print "{027}[11;"; n; "H|";
n= z/256 : n=n+ 40 : print "{027}[12;"; n; "H|";
print "{027}[13;1H"; "{027}[J";
tickn= tickn + 20
endif
CONFIG POWERMODE = idle
Loop
End
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'=====[ Tick timer ISR ]========================================================
TickCounter_isr:
incr tick
return
'-------------------------------------------------------------------------------
'=====[ Initilize Gyro]=========================================================
InitGyro:
I2cstart
I2cwbyte L3G4200D_W
I2cwbyte WHO_AM_I
I2cstart
I2cwbyte L3G4200D_R
I2crbyte Test_gyro , Nack
I2cstop
Print "&B"; bin(Test_gyro); " [&h"; Hex(Test_Gyro); "]";
' if test_gyro = 11010011 (D3) then connection is ok
I2cstart
I2cwbyte L3G4200D_W
I2cwbyte CTRL_REG1
I2cwbyte &B00000_1111 'Enable x, y, z and turn off power down
I2cstop
I2cstart
I2cwbyte L3G4200D_W
I2cwbyte CTRL_REG2
I2cwbyte &B0010_1001 'adjust/use the HPF
I2cstop
I2cstart
I2cwbyte L3G4200D_W
I2cwbyte CTRL_REG3
I2cwbyte &B0000_1000
I2cstop
I2cstart
I2cwbyte L3G4200D_W
I2cwbyte CTRL_REG4
' I2cwbyte &B0000_0000 'scale 250
' I2cwbyte &B0001_0000 'scale 500
I2cwbyte &B1011_0000 'scale 2000
I2cstop
I2cstart
I2cwbyte L3G4200D_W
I2cwbyte CTRL_REG5
I2cwbyte &B0000_0000 'high-pass filtering of outputs
I2cstop
return
'-------------------------------------------------------------------------------
'=====[ Read Gyro Data ]========================================================
Read_Gyro:
I2cstart
I2cwbyte L3G4200D_W
I2cwbyte &B1010_0110 ' (OUT_TEMP AND &B10000000)
I2cstart
I2cwbyte L3G4200D_R
I2crbyte Temp, Ack
I2crbyte Status, Ack
I2crbyte Xl, Ack
I2crbyte Xh, Ack
I2crbyte Yl, Ack
I2crbyte Yh, Ack
I2crbyte Zl, Ack
I2crbyte Zh, Nack
I2cstop
Return
'-------------------------------------------------------------------------------[/code:1:02b82ae2bb]
How to get the number 256 and 40 from this line
[code:1:02b82ae2bb] n= x/256 : n=n+ 40 : print "{027}[10;"; n; "H|";
n= y/256 : n=n+ 40 : print "{027}[11;"; n; "H|";
n= z/256 : n=n+ 40 : print "{027}[12;"; n; "H|"; [/code:1:02b82ae2bb]
Thanks Before [/url]
[b:02b82ae2bb][color=red:02b82ae2bb](BASCOM-AVR version : 2.0.7.6 )[/b:02b82ae2bb][/color:02b82ae2bb]
↧