Code:
'****************************************************************
'* Name : *
'* Author : *
'* Notice : *
'* : *
'* Date : 2/17/2006 *
'* Version : 1.0 *
'* Notes : Uses Darryl Taylor interrupt routines *
'* : *
'****************************************************************
DEFINE LOADER_USED 1 'Only required if bootloader used to program PIC
define OSC 4
INCLUDE "modedefs.bas"
INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
' ** Setup the ADCIN Defines **
Define ADC_BITS 10 ' Set resolution of conversion
Define ADC_CLOCK 2 ' Set clock source (x/FOSC or FRC)
Define ADC_SAMPLEUS 50 ' Set sampling time (in uS)
' OPTION_REG.7 = 0
'ADCON1 = 7 ' PORTA digital
PORTA = %00000000 'Set all pins to 0
TRISA = %00111111 'Set PORTA RA0-RA5 to input
PORTB = %00000000 'Set all pins to 0 (off)
TRISB = %01110000 'Set PORTB inputs/output
PORTC = %00000000 'Set all outputs to 0 (off)
TRISC = %00000000 'Set PORTC to all output
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
' Alias pins
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
LED1 VAR PORTB.0 'LED1 simulating "alarm"
LED2 VAR PORTB.1 'LED2 simulating main heater on
LED3 VAR PORTB.2 'LED3 simulating Q/T heater on
thelcd var PORTB.3
button1 VAR PORTB.4
button2 VAR PORTB.5
button3 VAR PORTB.6
buzzer var PORTB.7 'sonalert alarm
heartbeat var PORTC.5
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
' Define Variables
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
display var byte
temp1 VAR byte
temp2 VAR byte
setpoint1 var byte
setpoint2 var byte
main_lowtmp var byte
main_hightmp var byte
qt_lowtmp var byte
qt_hightmp var byte
sample1 VAR byte
sample2 VAR byte
AD_Raw Var Word ' 16-bit result of A/D conversion
AD_Result Var Word ' Quantasized ADC result
Bit_Cnt Var Byte ' General purpose loop
Chr Var Byte ' Degrees sign build variable
Quanta Con 1250
Alarm var byte
looplength var byte
trouble var byte
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
' ** Define LCD Constants **
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
I Con 254 ' Control Byte
Clr Con 1 ' Clear the display
Line1 Con 128 ' Point to beginning of line 1
Line2 Con 194 ' Point to beginning of line 2
Line3 Con 148 ' Point to beginning of line 3
Line4 Con 212 ' Point to beginning of line 4
Baud con 84
Cgram Con 64 ' Point to Cgram in the LCD
'((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
' Clear LCD and pause to start
'((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
Pause 5000
Serout2 thelcd,Baud,[I,clr]
Pause 1000
Serout2 thelcd,Baud,[I,clr]
Pause 1000
Serout2 thelcd,Baud,[I,clr,I,128," START"]
Pause 1500
temp1 = 0
temp2 = 0
display = 0
setpoint1 = 79
setpoint2 = 79
main_lowtmp = setpoint1 - 2
main_hightmp = setpoint1 + 2
qt_lowtmp = setpoint2 - 2
qt_hightmp = setpoint2 + 2
looplength = 16
trouble = 0
'((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
' build the degree symbol
'((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
For Bit_Cnt =0 to 7 '
Lookup Bit_Cnt,[%00000110,%00001001,%00001001,%00000110,0,0,0,0],Chr
Serout2 thelcd,84,[$fe,96+Bit_Cnt,Chr,1]' Output the bit patterns to the LCD's CGRAM
Next
'((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
' set-up A/D channels
'((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
ADCON1= %10001110 ' Configure for AN0 and AN1 as analog input
' With right justified result
'((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
' Interrupt handler
'((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _ToggleLED1, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
T1CON = $31 ; Prescaler = 8, TMR1ON
@ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts
'((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
' Main program loop - updates the LCD and siteplayer with the time
'and status of temperatures and pumps
'((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
mainloop:
GoSub showonlcd
'GoSub read_switches
goto mainloop
'---[INT - interrupt handler]---------------------------------------------------
ToggleLED1:
TOGGLE heartbeat
display = display + 1
@ INT_RETURN
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'read Temp sensors for high/low temp alarm and display on LCD
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
showonlcd:
select case display
Case 1
display = display + 1
gosub read_maintemp
INTCON.7 = 0
Serout2 thelcd,Baud, [I,clr]
Serout2 thelcd,Baud, [I,130,"MAIN TANK TEMP"]
Serout2 thelcd,Baud, [I,196,#(AD_Result/100),".",#(AD_Result//100),4," ","C"]
AD_Result = 0
INTCON.7 = 1
low buzzer
case 6
display = display + 1
gosub read_qttemp
INTCON.7 = 0
Serout2 thelcd,Baud, [I,clr]
Serout2 thelcd,Baud, [I,130,"Q/T TANK TEMP"]
Serout2 thelcd,Baud, [I,196,#(AD_Result/100),".",#(AD_Result//100),4," ","C"]
AD_Result = 0
INTCON.7 = 1
'display = 0
Case 11
display = display + 1
select case trouble
CASE 0
'display = display + 1
INTCON.7 = 0
Serout2 thelcd,Baud, [I,clr]
Serout2 thelcd,Baud, [I,128," SYSTEM"]
Serout2 thelcd,Baud, [I,196,"NORMAL"]
INTCON.7 = 1
end select
end select
if display = looplength then display = 0
RETURN
goto mainloop
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'read CT sensors for pump motors
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
read_switches:
RETURN
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'misc alarms and things
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
sonalert:
high buzzer
goto mainloop
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'misc alarms and things ...LM335 temp sensors
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
read_maintemp:
ADCIN 0,AD_Raw ' Place the conversion of channel0 into AD_RAW
AD_Result=((AD_Raw*10)-5594) */ Quanta 'Quantasize the result
return ' go back to where it came from
read_qttemp:
ADCIN 1,AD_Raw ' Place the conversion of channel1 into AD_RAW
AD_Result=((AD_Raw*10)-5594) */ Quanta 'Quantasize the result
return ' go back to where it came from
goto mainloop
Serout2 thelcd,Baud, [I,clr]
Serout2 thelcd,Baud, [I,128,"PROGRAM STOPPED"]
end
Bookmarks