I have been trying this for a long time to display rpm on the LCD but it does not display the rpm.
I initialized rpm to a float variable and a normal text to a character.
The character message displays but not the rpm, is this because I have the rpm in float and I did not convert into string or a character or is there any other problem.
I will attach my code for your reference.
Code: Select all
char *text = "Cadence";
float *Rpm = 0;
unsigned int Rot_time = 0;
unsigned short Pulse_HSL; // holding falling edge time for start of timing sequence
unsigned int Pulse_HSH;
unsigned short Pulse_EL; // rising edge for end time sequence
unsigned int Pulse_EH;
//unsigned float Rot_PH = 0;
//unsigned float Rot_PL = 0;
void main()
{
//Soft_Uart_Init(PORTC,7,6,57600,0);
delay_ms(500);
PORTB = 0;
TRISB = 0;
TRISD = 0; //Set all PORTD for output
PORTD = 0;
TRISC = 0x02; //RC1 as input for CCP2
Lcd_Init(&PORTB);
Lcd_Cmd(Lcd_clear);
Lcd_Out(1 ,1 , text);
INTCON = 0; //Disable all Interrupts for initialization of other registers
T3CON = 0; //0000 0000 was $C0 Sets Timer1 as source clock for CCP1 and CCP2 leaves timer3 off
CCP2CON = 0x04; // set for every faling edge, 05 every rising edge capture
//CCP2CON = 0x06; //set for 4th rising edge, $07 Initially Set CCP2 for 16th Rising Edge Capture
T1CON = 0x01; //set for 8 bit time read, prescaler of 1 and turn timer 1 on
//T1CON = 0x81; // set for 16bit read, prescaler 1 and timer1on
TMR1L = 0x00; //zero timer registers
TMR1H = 0x00;
INTCON = 0xC0; //Enable Interrupts
while(1)
{
//delay_ms(100);
//Soft_Uart_write(Rpm);
if(PIR2.CCP2IF == 0 && CCP2CON == 0x04) // if flag is set and pulse is trigerred
Rot_time = (Pulse_EH<<8|Pulse_EL) - (Pulse_HSH<<8|Pulse_HSL);
Rpm = 240000000/Rot_time;//combining both hi and low byte of rotation period
Lcd_Out_cp(Rpm); // Print text on LCD
}
}
void interrupt()
{
//INTCON.GIE = 0; // clearing GIE to prevent any other interrupts while handling this one
if(PIR2.CCP2IF == 1)
{
switch(CCP2CON)
{
case 0x04: // start time of the sequence i.e. falling edge and gets start time
Pulse_HSL = CCPR2L; // capture pulse high start time
Pulse_HSH = CCPR2H; // get captured time high byte
CCP2CON = 0x05;
PIR2.CCP2IF = 0; // reset the flag
break;
case 0x05: // end time sequence so timing sequence complete, calculate time intervals
Pulse_EL = CCPR2L; // get time of the rising edge
Pulse_EH = CCPR2H;
//Rot_PL = Pulse_EL - Pulse_HSL; // rotation time = Pulse time HI + pulse time LOW
//if(STATUS == 0){ Pulse_EH = Pulse_EH - 1; }
//Rot_PH = Pulse_EH - Pulse_HSH;
CCP2CON = 0x04; // set start next timing sequence for falling edge.
PIR2.CCP2IF = 0;
break;
default: rpm = 0;
} // switch
} // if
} // interrupt
Kind Regards
Antony