سلام
برنامه زیر مربوط به دماسنج کتاب اقای کاهه هستش ولی من مدار رو بستم دما رو 222 درکه نشون میداد!!
به نظرتون اشکالش از کجاست؟
$regfile = "m32def.dat"
'We use internal osc 4000000 for atmega32
$crystal = 4000000
Config Lcdpin = Pin , Db4 = Portc.1 , Db5 = Portc.2 , Db6 = Portc.3 , Db7 = _
Portc.4 , E = Portd.2 , Rs = Portd.3
Config Lcd = 16 * 2
Config Adc = Single , Prescaler = Auto
Start Adc
Config Timer0 = Timer , Prescale = 1024
Enable Interrupts
Enable Timer0
On Timer0 Temp_sample
Start Timer0
Dim Sample As Word
Dim Temp As Word
Dim Temp_final As Integer
Dim Sum As Integer
Deflcdchar 0 , 24 , 24 , 32 , 32 , 32 , 32 , 32 , 32 '' sign -> (')
Cursor Off
Cls
Do
Loop
end 'end program
Temp_sample:
Incr Sample 'incr sampling counter
Temp = Getadc(0) 'read adc(0) every 65ms
Sum = Sum + Temp 'sum the sample data
If Sample = 15 Then '20 samples
Sample = 0 'reset sample counter
Stop Timer0 'stop timer to calculation
Sum = Sum / 15 'mean calculation
Sum = Sum - 558 'decrementing offset
Temp_final = Sum / 2 'every 10mv is almost 2 step of adc (adc step=5/1023=4.88mv)
Select Case Temp_final
Case Is =< 10 : 'compare temperature
Home L
Lcd " Low "
Case 11 To 34 : 'compare temperature
Home L
Lcd " Normal "
Case Is >= 35 : 'compare temperature
Home L
Lcd " High "
End Select
Home
Lcd Temp_final ; Chr(0) ; "C " 'show temperature
Start Timer0
Sum = 0
End If
Return