من با بسکام کار میکنم.متغیر هایی که در داخل تابع (....subوsub buzer_coldدربرنامه زیر)تعریف میکنم و از جنس single هستند هروقت می خوام تو حافظه ایپرام ذخیره کنم ،عبارت NAN به جای عدد در ال سی دی نمایش می ده.وقتی نمی خوام تو حافظه ایپرام ذخیره کنم مشکل نیست وعبارت مقدار عدد رو درست نمایش می ده .اما برای متغیر هایی از جنس byte & word چه در حافظه ایپرام ذخیره کنم و چه ذخیره نکنم مقدار صحیح اون نشون می ده(ton وtoff در برنامه زیر) .نمی دونم مشکل از کجاست .کسی اگه می دونه کمکم کنه.
برنامه هم بصورت کامل در زیر اوردم .
$regfile = "m16def.dat"
$crystal = 8000000
'******************************************** ***********************************
$hwstack = 128
$swstack = 128
$framesize = 128
'******************************************** ***********************************
Config Portb.7 = Output
Config Portb.6 = Output
Config Portb.5 = Output
Config Portb.4 = Output
Config Portb.0 = Input
Config Portb.1 = Input
Config Portb.2 = Input
Config Portb.3 = Input
Config 1wire = Portd.6
'******************************************** **********************************
Config Lcd = 16 * 2
Config Lcdpin = Pin , Rs = Pind.0 , E = Pind.1 , Db4 = Pind.2 , Db5 = Pind.3 , Db6 = Pind.4 , Db7 = Pind.5
'******************************************** **********************************
Dim A(9) As Byte
Dim X As Integer
Dim T As Single
Dim Buz_h As Single 'heat buzer
Dim Buz_c As Single ' cold buzer
Dim Ton As Byte 'time on
Dim Toff As Byte 'time off
Dim Ss As Byte '
Dim S As Byte 'second
Dim M As Byte 'min
'---------------------var eerom
Dim Buz_h_e As Eram Single
Dim Buz_c_e As Eram Single
Dim Ton_e As Eram Byte
Dim Toff_e As Eram Byte
'******************************************** ***********************************
Buz_h = Buz_h_e
Buz_c = Buz_c_e
Ton = Ton_e
Toff = Toff_e
'******************************************** ***********************************
Declare Sub H_temp
Declare Sub Buzer_heat
Declare Sub Buzer_cold
Declare Sub Time_on
'******************************************** *********************************
Enable Interrupts
Config Timer2 = Timer , Async = On , Prescale = 128
Enable Timer2
Enable Ovf2
On Timer2 Label
Start Timer2
'******************************************** **********************************
Config Single = Scientific , Digits = 1
Deflcdchar 0 , 6 , 9 , 9 , 6 , 32 , 32 , 32 , 32 ' replace [x] with number (0-7)
'--------------------------------------------------------------------
1wreset
1wwrite &HCC '204
1wwrite &H44 '68
Wait 1
'************************************main ********************************
Termometer:
Do
'--------------read temp
1wreset
1wwrite &HCC
1wwrite &H44
Waitms 100
1wreset
1wwrite &HCC '204
1wwrite &HBE '190
A(1) = 1wread(9)
Waitms 100
If A(9) = Crc8(a(1) , 8) Then
X = Makeint(a(1) , A(2))
T = X / 16
End If
'-----------------
If T => Buz_h Then Sound Portb.4 , 150 , 150
If T <= Buz_c Then Sound Portb.4 , 150 , 150
If M = 0 And S <= Ton Then : Set Portb.6 : Else : Reset Portb.6 : End If
If S = 0 And Portb.6 = 1 Then : Reset Portb.6 : End If
'-------------------
Cursor Off
Home : Lcd "Temp:" ; T ; Chr(0) ; "c" ; Spc(5)
Home L : Lcd "on:" ; Ton ; Spc(1) ; M ; ":" ; S ; Spc(1) ; "of:" ; Toff ; Spc(2)
'----------------------
Debounce Pinb.0 , 0 , L_temp
'--------------------------
Loop
End
'******************************************** ***********************************
Sub Buzer_heat
Do
If Pinb.2 = 0 Then Buz_h = Buz_h + .1
If Pinb.3 = 0 Then Buz_h = Buz_h -.1
Debounce Pinb.0 , 0 , Buzer_cold
Debounce Pinb.1 , 0 , Termometer
buz_h_e= buz_h
Waitms 100
Home : Cursor Off
Lcd "buzer heat:" ; Buz_h ; Spc(13)
Home L : Lcd Spc(16)
Loop
End Sub
'******************************************** ********************************
Sub Buzer_cold
Do
If Pinb.2 = 0 Then Buz_c = Buz_c + .1
If Pinb.3 = 0 Then Buz_c = Buz_c -.1
Debounce Pinb.0 , 0 , Time_on
Debounce Pinb.1 , 0 , Termometer
Buz_c_e = Buz_c
Waitms 100
Home : Cursor Off
Lcd "buzer cold:" ; Buz_c ; Spc(13)
Home L : Lcd Spc(16)
Loop
End Sub
'******************************************** ***********************************
Sub Time_on
Do
If Pinb.2 = 0 Then Incr Ton
If Pinb.3 = 0 Then Decr Ton
Debounce Pinb.0 , 0 , Time_off
Debounce Pinb.1 , 0 , Termometer
Ton_e = Ton
Waitms 100
Home : Cursor Off
Lcd "time on=" ; Ton ; "sec" ; Spc(5)
Home L : Lcd Spc(16)
Loop
End Sub
'******************************************** ***********************************
Sub Time_off
Do
If Pinb.2 = 0 Then Incr Toff
If Pinb.3 = 0 Then Decr Toff
Debounce Pinb.1 , 0 , Termometer
Debounce Pinb.0 , 0 , Termometer
Toff_e = Toff
Waitms 100
Home : Cursor Off : Lcd "time off=" ; Toff ; "min" ; Spc(10)
Home L : Lcd Spc(16)
Loop
End Sub
'******************************************** ***********************************
Label:
Incr Ss : If Ss => 1 Then : Decr S : Ss = 0 : End If
If S = 255 Then : Decr M : S = 59 : End If
If M = 255 Or M = 254 Then : M = Toff -1 : End If
Return
برنامه هم بصورت کامل در زیر اوردم .
$regfile = "m16def.dat"
$crystal = 8000000
'******************************************** ***********************************
$hwstack = 128
$swstack = 128
$framesize = 128
'******************************************** ***********************************
Config Portb.7 = Output
Config Portb.6 = Output
Config Portb.5 = Output
Config Portb.4 = Output
Config Portb.0 = Input
Config Portb.1 = Input
Config Portb.2 = Input
Config Portb.3 = Input
Config 1wire = Portd.6
'******************************************** **********************************
Config Lcd = 16 * 2
Config Lcdpin = Pin , Rs = Pind.0 , E = Pind.1 , Db4 = Pind.2 , Db5 = Pind.3 , Db6 = Pind.4 , Db7 = Pind.5
'******************************************** **********************************
Dim A(9) As Byte
Dim X As Integer
Dim T As Single
Dim Buz_h As Single 'heat buzer
Dim Buz_c As Single ' cold buzer
Dim Ton As Byte 'time on
Dim Toff As Byte 'time off
Dim Ss As Byte '
Dim S As Byte 'second
Dim M As Byte 'min
'---------------------var eerom
Dim Buz_h_e As Eram Single
Dim Buz_c_e As Eram Single
Dim Ton_e As Eram Byte
Dim Toff_e As Eram Byte
'******************************************** ***********************************
Buz_h = Buz_h_e
Buz_c = Buz_c_e
Ton = Ton_e
Toff = Toff_e
'******************************************** ***********************************
Declare Sub H_temp
Declare Sub Buzer_heat
Declare Sub Buzer_cold
Declare Sub Time_on
'******************************************** *********************************
Enable Interrupts
Config Timer2 = Timer , Async = On , Prescale = 128
Enable Timer2
Enable Ovf2
On Timer2 Label
Start Timer2
'******************************************** **********************************
Config Single = Scientific , Digits = 1
Deflcdchar 0 , 6 , 9 , 9 , 6 , 32 , 32 , 32 , 32 ' replace [x] with number (0-7)
'--------------------------------------------------------------------
1wreset
1wwrite &HCC '204
1wwrite &H44 '68
Wait 1
'************************************main ********************************
Termometer:
Do
'--------------read temp
1wreset
1wwrite &HCC
1wwrite &H44
Waitms 100
1wreset
1wwrite &HCC '204
1wwrite &HBE '190
A(1) = 1wread(9)
Waitms 100
If A(9) = Crc8(a(1) , 8) Then
X = Makeint(a(1) , A(2))
T = X / 16
End If
'-----------------
If T => Buz_h Then Sound Portb.4 , 150 , 150
If T <= Buz_c Then Sound Portb.4 , 150 , 150
If M = 0 And S <= Ton Then : Set Portb.6 : Else : Reset Portb.6 : End If
If S = 0 And Portb.6 = 1 Then : Reset Portb.6 : End If
'-------------------
Cursor Off
Home : Lcd "Temp:" ; T ; Chr(0) ; "c" ; Spc(5)
Home L : Lcd "on:" ; Ton ; Spc(1) ; M ; ":" ; S ; Spc(1) ; "of:" ; Toff ; Spc(2)
'----------------------
Debounce Pinb.0 , 0 , L_temp
'--------------------------
Loop
End
'******************************************** ***********************************
Sub Buzer_heat
Do
If Pinb.2 = 0 Then Buz_h = Buz_h + .1
If Pinb.3 = 0 Then Buz_h = Buz_h -.1
Debounce Pinb.0 , 0 , Buzer_cold
Debounce Pinb.1 , 0 , Termometer
buz_h_e= buz_h
Waitms 100
Home : Cursor Off
Lcd "buzer heat:" ; Buz_h ; Spc(13)
Home L : Lcd Spc(16)
Loop
End Sub
'******************************************** ********************************
Sub Buzer_cold
Do
If Pinb.2 = 0 Then Buz_c = Buz_c + .1
If Pinb.3 = 0 Then Buz_c = Buz_c -.1
Debounce Pinb.0 , 0 , Time_on
Debounce Pinb.1 , 0 , Termometer
Buz_c_e = Buz_c
Waitms 100
Home : Cursor Off
Lcd "buzer cold:" ; Buz_c ; Spc(13)
Home L : Lcd Spc(16)
Loop
End Sub
'******************************************** ***********************************
Sub Time_on
Do
If Pinb.2 = 0 Then Incr Ton
If Pinb.3 = 0 Then Decr Ton
Debounce Pinb.0 , 0 , Time_off
Debounce Pinb.1 , 0 , Termometer
Ton_e = Ton
Waitms 100
Home : Cursor Off
Lcd "time on=" ; Ton ; "sec" ; Spc(5)
Home L : Lcd Spc(16)
Loop
End Sub
'******************************************** ***********************************
Sub Time_off
Do
If Pinb.2 = 0 Then Incr Toff
If Pinb.3 = 0 Then Decr Toff
Debounce Pinb.1 , 0 , Termometer
Debounce Pinb.0 , 0 , Termometer
Toff_e = Toff
Waitms 100
Home : Cursor Off : Lcd "time off=" ; Toff ; "min" ; Spc(10)
Home L : Lcd Spc(16)
Loop
End Sub
'******************************************** ***********************************
Label:
Incr Ss : If Ss => 1 Then : Decr S : Ss = 0 : End If
If S = 255 Then : Decr M : S = 59 : End If
If M = 255 Or M = 254 Then : M = Toff -1 : End If
Return