This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

IR photodiode pulse detector..please tell me that any mistake from this code...?

sbit IR_Tx at RA3_bit;
sbit start at RB0_bit;
unsigned short pulserate, pulsecount;

sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;

void delay_debounce(){ Delay_ms(300);
}

void delay_refresh(){ Delay_ms(5);
}

void countpulse(){ IR_Tx = 1; delay_debounce(); delay_debounce(); TMR0=0; //0 to 1 transition Delay_ms(15000); // Delay 1 Sec IR_Tx = 0; pulsecount = TMR0; pulserate = pulsecount*4;
}

char message1[] = "Frequency= Hz";
char *freq = "000";

void Display_Freq() {
freq[0] = (pulserate/100)%10+ 48; // Extract hundreds digit
freq[1] = (pulserate/10)%10 + 48; // Extract tens digit
freq[2] = pulserate%10 + 48; // Extract ones digit

Lcd_Out(1, 11, freq);
}

void main() {
CMCON = 0x07; // Disable Comparators
TRISA = 0b00110000; // RA4/T0CKI input, RA5 is I/P(clear) only
TRISB = 0b00000001; // RB0 input(start),rest output,direction
PORTB = 0; //all outputs
OPTION_REG = 0b00101000; // Prescaler (1:1), TOCS =1 counter mode
pulserate=0;
Display_Freq();

Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // CLEAR display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off Lcd_Out(1,1,message1); // Write message1 in 1st row

do { if(!start){ delay_debounce(); countpulse(); Delay_ms(1000); // Delay 1 Sec Display_Freq();//TMR0@countpulse@pulsecount@pulserate,value
} } while(1); // Infinite loop
}

0