'Flowsensor interface
'*******************************************************************************
$PROG &HFF,&HE2,&HDF,&HFF' generated. Take care that the chip supports all fuse bytes.
$regfile = "ATtiny84.dat"
$crystal = 8000000
$hwstack = 48
$swstack = 32
$framesize = 32
'Variabelen dimensioneren ******************************************************
const False = 0
const True = 1
const Timer0Reload = 7 '1 msec.
dim Drukknop as byte
dim DrukknopBediend as byte
dim DrukknopTeller as byte
dim DrukknopTeller2 as byte
dim MWheater as word
dim MWsensor as word
dim StuurWaarde as word
dim OutputWaarde as word
dim VerschilWaarde as word
'Processor pennen toewijzen ****************************************************
config PINA.0 = input 'pin 13, ADC0
config PINA.1 = input 'Pin 12, ADC1, Flowsignaal
config PINA.2 = input 'Pin 11, ADC2
config PINA.3 = input 'Pin 10, ADC3
config PINA.4 = output 'Pin 9, TxD
config PINA.5 = output 'Pin 8, OC1B, PWM
config PINA.6 = output 'Pin 7, OC0A, PWM
config PINA.7 = input 'Pin 6, ADC7
config PINB.0 = input 'Pin 2, PCint8, Drukknop
config PINB.1 = output 'Pin 3, Test LED
config PINB.2 = output 'Pin 5
config PINB.3 = output 'Pin 4, TxD
set pina.4
set Pinb.0 'Pull-up weerstand activeren
set pINB.1 'LED uitzetten
set pinb.3
'PWM configuratie **************************************************************
config timer1 = Pwm, Pwm = 10, Compare_A_Pwm = Clear_Up, Compare_B_Pwm = Clear_Up, Prescale = 1
'ADC configuratie **************************************************************
config ADC = single, Prescaler = Auto, Reference = Avcc
start Adc
'Debounce timer ****************************************************************
config timer0 = timer, Prescale = 1024
load timer0, Timer0Reload
on timer0 Timer0isr
enable timer0
start timer0
enable interrupts
'Software serieele poort aanmaken **********************************************
open "ComA.4:19200,8,N,1" for output as #1
'Main loop *********************************************************************
do
MWheater = getadc(1)
MWsensor = getadc(2)
Verschilwaarde = MWheater - MWsensor
if MWsensor > MWheater then
StuurWaarde = StuurWaarde - 1
if StuurWaarde < 10 then StuurWaarde = 10
end if
if MWsensor < MWheater then
StuurWaarde = Stuurwaarde + 1
if StuurWaarde > 1000 then StuurWaarde = 1000
end if
PWM1A = StuurWaarde
OutputWaarde = StuurWaarde - 350
if MWheater < 10 then OutputWaarde = 1
if MWheater > 1000 then OutputWaarde = 1
if MWsensor < 10 then OutputWaarde = 1
if MWsensor > 1000 then OutputWaarde = 1
Pwm1b = OutputWaarde
print #1, MWheater;
print #1, " ";
print #1, MWsensor;
print #1, " ";
print #1, OutputWaarde;
print #1, " ";
print #1, VerschilWaarde
if DrukknopBediend = True then
reset portb.1
DrukknopBediend = False
end if
loop
close #1
end
'Digitale ingang debouncen *****************************************************
Timer0isr:
load timer0, Timer0Reload
if Drukknop = 0 and DrukknopBediend = False then
DrukknopTeller = DrukknopTeller + 1
if DrukknopTeller >= 255 then
DrukknopTeller = 255
end if
else
DrukknopTeller = 0
end if
if DrukknopTeller >= 150 then
DrukknopBediend = True
' hier aktie uitvoeren na indrukken knop
end if
if pinb.1 = 0 then
DrukknopTeller2 = DrukknopTeller2 + 1
if DrukknopTeller2 > 5 then
set PORTB.1
end if
end if
return
|