I need antitangent function in my project, so I write a simple test code for using atn function in BASCOM,
[code:1:473188546a]
$regfile = "m32def.dat" ' specify the used micro
$crystal = 8000000 ' used crystal frequency
$baud = 9600 ' use baud rate
Config Scl = Porta.4
Config Sda = Porta.5
Config I2cdelay = 10
Const L3g4write = &HD2
Const L3g4read = &HD3
Const Adxl345write = &HA6
Const Adxl345read = &HA7
Dim Jby As Byte
Dim Iby As Byte
Dim Lby As Byte , Mby As Byte , Xby As Byte , Yby As Byte , Zby As Byte
Dim Buff(6) As Byte
Dim Acc(3) As Integer
Dim An(6) As Integer
Dim Accel_x As Integer
Dim Accel_y As Integer
Dim Accel_z As Integer
Dim Sensor_sign(9) As Integer
Dim An_offset(6) As Integer
Dim Buf As Single
Dim Buf2 As Single
I2cinit
I2cstart
I2cwbyte Adxl345write
I2cwbyte &H2D
I2cwbyte &B00001000
I2cstop
Waitms 100
Dim S As Single , X As Single
Do
Print "Loop Start"
For Iby = 1 To 6
I2cstart
I2cwbyte Adxl345write
Jby = &H31 + Iby
I2cwbyte Jby
I2cstart
I2cwbyte Adxl345read
I2crbyte Xby
I2crbyte Yby , Nack
Buff(iby) = Yby
I2cstop
Next Iby
Accel_x = Makeint(buff(1) , Buff(2))
Accel_y = Makeint(buff(3) , Buff(4))
Accel_z = Makeint(buff(5) , Buff(6))
Buf = Accel_y / Accel_z
Print "Step 1"
Buf2 = Atn(buf)
Print "Step 2"
Waitms 50
Loop
End
[/code:1:473188546a]
It works well, but when I add atn function like this code into my project(more code, more function), a strange thing happened:
"step 1" has been printed normal, but there is no "Step 2" shown, the log is like below:
"Loop start"
"Step 1"
"Loop start"
"Step 1"
"Loop start"
"Step 1"
"Loop start"
"Step 1"
.....
It is strange, after atn function called, it looks like the loop has been stopped and goto next loop.
It is so confused, stack problem? anybody can give me some suggestion?
↧