سلام
من یه برنامه کوچک تو بیسکام نوشتم که هر x میلی ثانیه یکبار فاصله زمانی بین دو لبه بالارونده از یک سیگنال رو توسط تایمر میخونه.
اما نمیدانم که چرا وقتی این x میلی ثانیه رو کمتر یا بیشتر میکنم ، زمان خوانده شده توسط تایمر هم متفاوت میشه .
میتوانید بگید مشکل این کد چیه؟نوع میکرو مگا 8 است.
من یه برنامه کوچک تو بیسکام نوشتم که هر x میلی ثانیه یکبار فاصله زمانی بین دو لبه بالارونده از یک سیگنال رو توسط تایمر میخونه.
اما نمیدانم که چرا وقتی این x میلی ثانیه رو کمتر یا بیشتر میکنم ، زمان خوانده شده توسط تایمر هم متفاوت میشه .
میتوانید بگید مشکل این کد چیه؟نوع میکرو مگا 8 است.
$crystal = 16000000
' - - - - - - - - - -[Subrootins Declarations] - - - - - - - - - -
Declare Sub Show_frequency()
' - - - - - - - - - -[configuration of lcd pins] - - - - - - - - - -
Config Lcd = 20 * 4
Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5 , E = Portc.1 , Rs = Portc.0
' - - - - - - - - - -[configurations] - - - - - - - - - -
Config Timer1 = Timer , Prescale = 1024
Config Int0 = Rising
' - - - - - - - - - -
Enable Interrupts
Enable Timer1
'----------
On Int0 Count1
'----------
Cursor Off
'- - - - - - - - - - - -[port direction]- - - - - - - - - - - - -
Ddrd = &H00
Portd = &HFF
Config Portb.0 = Output
Config Portb.1 = Output
Config Portb.2 = Output
'- - - - - - - - - - - - - - - - - - - - - -- - - - - - - - - - -
' - - - - - - - - - - - - - - - - -[definition of variables]--------------
Dim B As Byte , Counts As Long
Dim I As Byte , Gross_frequency As Long , E As String * 4
Dim Temp As Long , Temp1 As Long , J As Byte
Dim L1 As Integer , L2 As Integer
' - - - - - - - - - - - - - - - - -
B = 0
Counts = 0
I = 0
Disable Int0
Disable Timer0
Waitms 500
Cls
Do
If I = 0 Then Enable Int0
این قسمت مشکل ایجاد میکنهwaitms 500
while i=0
wend
Disable Timer1
Call Show_frequency()
Locate 1 , 1 : Lcd Gross_frequency ; " "
Locate 2 , 1 : Lcd Counts ; " "
I = 0
Loop
Count1:
Select Case B
Case 0
Enable Timer1
Start Timer1
Incr B
Set Portb.0
Reset Portb.0
Case 1
Disable Int0
Stop Timer1
Counts = Timer1
Timer1 = 0
Set Portb.1
Reset Portb.1
B = 0
I = 1
End Select
' Waitms 100
Return
Sub Show_frequency()
'( Select Case Counts
Case 120 To 160
Gross_frequency = 720000 / Counts
Case Is > 160
Gross_frequency = 780000 / Counts
End Select
'
Gross_frequency = 1560000 / Counts
' Incr Temp
End Sub Show_frequency()
Return
' - - - - - - - - - -[Subrootins Declarations] - - - - - - - - - -
Declare Sub Show_frequency()
' - - - - - - - - - -[configuration of lcd pins] - - - - - - - - - -
Config Lcd = 20 * 4
Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5 , E = Portc.1 , Rs = Portc.0
' - - - - - - - - - -[configurations] - - - - - - - - - -
Config Timer1 = Timer , Prescale = 1024
Config Int0 = Rising
' - - - - - - - - - -
Enable Interrupts
Enable Timer1
'----------
On Int0 Count1
'----------
Cursor Off
'- - - - - - - - - - - -[port direction]- - - - - - - - - - - - -
Ddrd = &H00
Portd = &HFF
Config Portb.0 = Output
Config Portb.1 = Output
Config Portb.2 = Output
'- - - - - - - - - - - - - - - - - - - - - -- - - - - - - - - - -
' - - - - - - - - - - - - - - - - -[definition of variables]--------------
Dim B As Byte , Counts As Long
Dim I As Byte , Gross_frequency As Long , E As String * 4
Dim Temp As Long , Temp1 As Long , J As Byte
Dim L1 As Integer , L2 As Integer
' - - - - - - - - - - - - - - - - -
B = 0
Counts = 0
I = 0
Disable Int0
Disable Timer0
Waitms 500
Cls
Do
If I = 0 Then Enable Int0
این قسمت مشکل ایجاد میکنهwaitms 500
while i=0
wend
Disable Timer1
Call Show_frequency()
Locate 1 , 1 : Lcd Gross_frequency ; " "
Locate 2 , 1 : Lcd Counts ; " "
I = 0
Loop
Count1:
Select Case B
Case 0
Enable Timer1
Start Timer1
Incr B
Set Portb.0
Reset Portb.0
Case 1
Disable Int0
Stop Timer1
Counts = Timer1
Timer1 = 0
Set Portb.1
Reset Portb.1
B = 0
I = 1
End Select
' Waitms 100
Return
Sub Show_frequency()
'( Select Case Counts
Case 120 To 160
Gross_frequency = 720000 / Counts
Case Is > 160
Gross_frequency = 780000 / Counts
End Select
'

Gross_frequency = 1560000 / Counts
' Incr Temp
End Sub Show_frequency()
Return
دیدگاه