سلام.من یه پروژه بستم که میخام هر 500ms یک سری داده رو توی sd ذخیره کنم.
همه چیز درست کار میکنه اما قسمتی که تایمر داره 500ms حساب میکنه که وارد زیر برنامه ذخیره کردن بشه مشکل داره.برنامه رو هم هرچی بررسی میکنم مشکلی نداره!!
کسی میتونه به کد من یه نگاه کنه و ببینه مشکل کجاست؟
همه چیز درست کار میکنه اما قسمتی که تایمر داره 500ms حساب میکنه که وارد زیر برنامه ذخیره کردن بشه مشکل داره.برنامه رو هم هرچی بررسی میکنم مشکلی نداره!!
کسی میتونه به کد من یه نگاه کنه و ببینه مشکل کجاست؟
کد:
[FONT=Yekan]$regfile = "m32def.dat"[/FONT]$crystal = 16000000
$baud = 4800
$swstack = 32
$hwstack = 64
$framesize = 64
'***************************config*****************
$include "CONFIG_AVR-DOS.Bas"
$include "Config_MMCSD_HC.bas"
Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.1 , Db6 = Portc.0 , _
Db7 = Portd.7 , E = Portc.3 , Rs = Portc.4
Config Lcd = 16 * 2
Config Portb.0 = Output
Enable Interrupts
Enable Adc
Start Adc
Config Int1 = Rising
Enable Int1
Config Timer0 = Timer , Prescale = 64
Enable Timer0
Start Timer0
Enable Ovf0
On Ovf0 T_count
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Declare Sub Record
'*************************var********************
Dim C As Word
Dim B As Single
Dim M As String * 10
Dim V As Single
Dim P0 As Single , P1 As Single
Dim P As String * 10
Dim Eror As Byte
Dim S As String * 60 , Fl As String * 12 , Ff As Byte
Dim H As Byte
Dim Count As Word
Dim Flok As Byte
Dim Rev As Word
Dim Rpm1 As Word
Dim Rpm2 As Word
Dim Pulse As Word
'****************************main*****************
Main:
Timer0 = 55
Count = 0
Rpm1 = 0
Rpm2 = 0
'******************
Spiinit
Cls
If Driveinit() <> 0 Then
Lcd "Error Init "
Flok = 0
Else
Lcd "Init Ok "
End If
Waitms 500
Cls
Home
If Initfilesystem(1) <> 0 Then
Lcd "System Error "
Flok = 0
Else
Lcd "SD ok "
Flok = 1
End If
Waitms 500
Firr:
Cls
Home
If Initfilesystem(1) <> 0 Then
Lcd "system error "
Flok = 0
Else
Lcd "SD ok "
Flok = 1
End If
Waitms 500
'************************
Do
'Start Timer0
H = Timer0
C = Getadc(0)
B = C / 204.6
M = Fusing(b , "#.##")
V = Val(m)
If 0.0197 <= V And V <= 0.29228 Then
P0 = V + 0.1042
P1 = P0 / 0.2478
Elseif V > 0.197 And 0.38978 <= V And V <= 2.8866 Then
P0 = V + 2.3003
P1 = P0 / 1.5824
Elseif V > 2.8866 And 2.4707 <= V And V <= 4.07765 Then
P0 = V + 2.8858
P1 = P0 / 1.7855
Elseif V > 4.07765 And 4.2966 <= V And V <= 4.87326 Then
P0 = V - 1.0014
P1 = P0 / 0.8238
Elseif V > 4.87326 And 4.87314 <= V And V <= 5 Then
P0 = V - 4.2405
P1 = P0 / 0.1318
End If
P = Fusing(p1 , "#.##")
On Int1 Velocity
Cursor Off
Cls
Lcd "Speed:" ; Rpm2 ; "rpm"
Locate 2 , 1
Lcd "P:" ; P ; "cm"
Pulse = 0
Waitms 1000
Rev = Pulse / 100
Rpm1 = Rev * 60
Rpm2 = Rpm1 / 9.1
If Count = 625 Then Set Portb.0
'Toggle Portb.0
' Fl = "REC1.xlsx"
' Open Fl For Append As #1
'Print #1 , "Position= " ; P ; " Speed= " ; Rpm2
' Close #1
' Set Portb.0
' Waitms 500
' Reset Portb.0
' Waitms 500
'T_count = 0
'Timer1 = 0
Loop
End 'end program
'****************************intrrupt****************
Velocity:
Incr Pulse
Return
'**********************sub ovf1***************
T_count:
Timer0 = 55
Incr Count
'Toggle Portb.0
Return
'**********************Record*****************
Record:
Fl = "REC1.txt"
Open Fl For Append As #1
Print #1 , " Position= " ; P ; " Speed= " ; Rpm2
Close #1
Set Portb.0
Waitms 500
Reset Portb.0
Waitms 500
Count = 0
Timer0 = 55
[FONT=Yekan]Return[/FONT]




(بهتر از این کلمه به ذهنم نرسید)
دیدگاه