Hi I'm back...My first attempt for 1 flow sensor is I tried to count the pulse similar to a switch button....but still not really sure if I'm doing it right. If its fine how do I get flow rate?...kindly check the code I'm using.
Code:
INCLUDE "MODEDEFS.BAS" ' Include Shiftin/out modes
INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
;-- Define LCD connections -- (change these to match your hardware) ------------
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 5
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 4
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
PAUSE 100
TRISA = %00000000 ; set PORTA to output pins
PortA = %00000000 ; set to PORTA low
TRISB = %10000000 ; set PORTB to B7 input pin rest output pins
PortB = %00000000 ; set to PORTB low
TRISC = %10000000 ; set PORTD to output pins
PORTC = %00000000
TRISD = %10000000 ; set PORTD to output pins
PORTD = %00000000 ; set to PORTD low
LCDOUT $FE,1 ; Initialize the LCD
pause 200 ; pause 2 milisec
OPTION_REG = $7f 'enable pull offs
'--variables init
flag1 var bit
flag1 = 0
c var byte
c = 0
cnt1 var word
cnt1 = 0
StatLed var PORTA.0
StatLed = 0
But0 var PortB.7
But0 = 0
'--LCD line
ln1 con $80
ln2 con $C0
CS con 1
SerialInput var byte[50]
Serialdata var byte
; setup serial port line for transmition
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 1
DEFINE HSER_BAUD 9600
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
RCIF VAR PIR1.5 ' Receive interrupt flag (1=full , 0=empty)
TXIF VAR PIR1.4 ' Transmit interrupt flag (1=empty, 0=full)
'------------------------------------------------------Transmition-------------
; create the transmition interrupt
'((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _ToggleLED1, PBP, yes
INT_Handler RX_INT, _Getbytes, PBP, no
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
;
T1CON = $31 ; Prescaler = 8, TMR1ON
@ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts
@ INT_ENABLE RX_INT
'((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))
;------------------------------------------------------------------------
Hserout ["Flow Sensor Test",13]
pause 1000
Main:
PortB.7 = 0
LCDOUT $FE,ln1,"Flow Sensor Test"
LCDOUT $FE,ln2 ,"Cnt: ",dec3 cnt1
Pause 25
IF But0 = 0 then
cnt1 = cnt1+1
While But0 = 0:Wend
If flag1 = 0 then
HSEROUT ["Counter:",Dec3 cnt1,13]
flag1 = 1
else
flag1 = 0
Endif
else
endif
Goto main
'(((((((((((((((((((((((((This is a preparation for PC interface))))))))))))))))
Getbytes:
While RCIF = 1 ' clear the buffer
c = c + 1
Hserin [Serialdata]
select case Serialdata ' What to do with that data???
case "A" ' User selection
HSEROUT ["Option A",13] ' take it out
case "B"
HSEROUT ["Option B",13] ' take it out
case "C"
HSEROUT ["Option C",13] ' take it out
case "*"
'HSEROUT ["This is it! > ",13] ' take it out
SerialInput[c] =" "
case else
SerialInput[c] = Serialdata
End select
Wend
@ INT_RETURN
'*******************************************************************************
ToggleLED1:
'Toggle statLed
@ INT_RETURN
I also attached some pics about my hardware setup..
Appreciate any input and time...
Regards,
tacbanon
Bookmarks