moad
Newbie level 5
- Joined
- Jan 30, 2015
- Messages
- 9
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 113
for the past 2 week iv just started my first ever project to make a c program on the software called mikroc where i would get pulses in from the flow meter and calculate the flow rate of how much litres flows every hour which then outputs to the lcd, however, after using a timer of 100ms and an interrupt that occurs that does the calculations and displays on the screen. i get lots of 0's on lcd and when the water flows through the meter...i get a change of 1 . thats all. please guys i would very much appreciate it if i get help on this. also how do i read the input signal becuase i may have done it wrong. the input signal is connected to RB7 as i have chaned the interrupt pin.
pic16f877a datasheet: **broken link removed** water flow meter datasheet: **broken link removed**
this is the code:
pic16f877a datasheet: **broken link removed** water flow meter datasheet: **broken link removed**
this is the code:
Code:
//Prescaler 1:4; TMR1 Preload = 15536; Actual Interrupt Time : 100 ms
volatile unsigned int val;
char num [20];
int calc;
void InitTimer1(){
T1CON = 0x21;
TMR1IF_bit = 0;
TMR1H = 0x3C;
TMR1L = 0xB0;
TMR1IE_bit = 1;
INTCON = 0xC8;
}
void Interrupt(){
if ((TMR1IF_bit) && (RBIF_bit)){
TMR1IF_bit = 0;
RBIF_bit = 0;
TMR1H = 0x3C;
TMR1L = 0xB0;
val= PORTB.F7; //read the input signal and assign it to val
Calc = (val * 60 / 7.5); //calculations for the flow rate per hour
longinttostrwithzeros(calc,num); //displaying on screen
Lcd_Out(1, 3, num );
}
}
void main() {
Lcd_Init();
TRISB=0b10000000; //initiallizing rb7 as the interrupt
PORTB=0;
InitTimer1(); //100ms timer
}
Last edited by a moderator: