البرنامج :
كود:
Device = 16F877A
Xtal = 20
LCD_DTPin PORTB.4
LCD_RSPin PORTB.2
LCD_ENPin PORTB.3
Adin_Res 10 ; Set the resolution to 10
Adin_Tad FRC ; Choose the RC osc for ADC samples
Adin_Stime 50 ; Allow 50us for charge time
Input PORTA.0 ;TRISA =%1 , pin A.0 as input
ADCON1 = %00001110 ;pin A.0 as analog and others as Digital, left justified
Dim ADC_result As Word ;create variable " ADC_result" to store data
Dim Min_Temp As Byte
Dim Max_Temp As Byte
Dim x As Byte ; repeat count variable
Dim g As 223 ;g = constant 223 this is the degrees in ASCII
Dim cool_relay As PORTD.2 ;Names for pins
Dim heat_relay As PORTD.3
Dim led As PORTD.4
Dim enter As PORTD.5 ; E button
Dim increase As PORTD.6 ; increase button
Dim decrease As PORTD.7 ; decrease button
EWrite 0,[20,24] ;Initial content of EEprom
starting: ;3 flashes of the LED which indicates work
For x =1 To 3
High led
DelayMS 200
Low led
DelayMS 200
Next
Min_Temp = ERead 0 ;EEprom reads 0 and saves it to Min_Temp
Max_Temp = ERead 1 ;EEprom reads 1 and saves it to Max_Temp
sensing:
ADC_result = ADIn 0 ; read channel 0 (A0) And store in ADC_result
Print Cls ;LCD clean
Print At 1,1,"Tmin Tactual Tmax" ; send text at line 1 , box 1
ADC_result = ADC_result /128 ; the ADC_result divide by 128 => AD 9-bit
Print At 2,7, Dec ADC_result,g,"C" ;Display el decimal de ADC_result
Print At 2,1, Dec Min_Temp,g,"C" ; Display the decimal Min_Temp
Print At 2,13, Dec Max_Temp,g,"C" ; Display the decimal Max_Temp
For x = 1 To 50 ;repeated 50 times
If enter =0 Then record1a ; E button pressed
DelayMS 10
Next
If ADC_result < Min_Temp Then heat ;if data is <Min_Temp going to heat
If ADC_result > Max_Temp Then cool
Low heat_relay : Low cool_relay ;off the 2 relays
GoTo sensing ;continue to sensing
heat:
High heat_relay : Low cool_relay
GoTo sensing
cool:
High cool_relay : Low heat_relay
GoTo sensing
record1a:
GoSub debounce
record1:
Print Cls
Print At 1,1, "Temp.Program "
Print At 2,1,"Low= ",Dec Min_Temp ,g,"C"
DelayMS 100
If decrease=0 Then subtract1
If increase=0 Then add1
If enter=0 Then recordA
GoTo record1
subtract1:
GoSub debounce ;key debounce program
If Min_Temp < 1 Then record1
Min_Temp= Min_Temp -1
GoTo record1
add1:
GoSub debounce
If Min_Temp > 40 Then record1
Min_Temp= Min_Temp + 1
GoTo record1
recordA:
GoSub debounce
EWrite 0,[Min_Temp] ;EEPROM write to address 0 "Min_Temp" value
record2:
Print Cls
Print At 1,1, "Temp.Program "
Print At 2,1,"High= ",Dec Max_Temp ,g,"C"
DelayMS 100
If decrease=0 Then subtract2
If increase=0 Then add2
If enter=0 Then recordB
GoTo record2
subtract2:
GoSub debounce
If Max_Temp < 5 Then record2
Max_Temp= Max_Temp -1
GoTo record2
add2:
GoSub debounce
If Max_Temp > 50 Then record2
Max_Temp= Max_Temp + 1
GoTo record2
recordB:
GoSub debounce
EWrite 1,[Max_Temp] ;write to address 1 of the EEPROM "Max_Temp" value
GoTo starting
debounce: ;key debounce program
High led
DelayMS 150
Low led
debounce2:
If decrease=0 Then debounce2
If increase=0 Then debounce2
If enter=0 Then debounce2
DelayMS 100
Return
End