I'm trying to display frequency in LCD. But its not working. Please help.
I'm giving input from function generator to pin C2.
I'm giving input from function generator to pin C2.
Rich (BB code):
#include "18f2520.h" #include "f2420_regs.h" #fuses INTRC #use delay(clock=4000000) #define RS PIN_A2 #define EN PIN_A1 void lcd_init(); void lcd_cmd(unsigned char); void lcd_data(unsigned char); unsigned int16 value; unsigned int8 high_byte, low_byte; void main() { lcd_init(); TRIS_C2 = 1; // PIN C2 configured as input for capture mode TRISB = 0; CCP1CON = 0b00000101; // Capture mode, every rising edge CCPR1H = 0; CCPR1L = 0; T1CON = 0b11001000; // 16-Bit, 1:1 Prescale value while(1) { TMR1H = 0; TMR1L = 0; CCP1IF = 0; // Interrupt flag is cleared while(CCP1IF == 0); // waits till Interrupt flag gets cleared TMR1ON = 1; // Timer1 ON CCP1IF = 0; // Interrupt flag is cleared while(CCP1IF == 0); // waits till Interrupt flag gets cleared TMR1ON = 0; // Timer1 OFF low_byte = CCPR1L; high_byte = CCPR1H; value = ((high_byte * 256) + low_byte)*60; CCP1IE = 0; CCP1IF = 0; lcd_cmd(0x01); lcd_cmd(0x80); printf(lcd_data,"%lu HZ",value); delay_ms(1000); } } void lcd_init() { lcd_cmd(0x30); // Configure the LCD in 8-bit mode, 1 line and 5x7 font //lcd_cmd(0x28); lcd_cmd(0x0c); // display on and cursor off lcd_cmd(0x01); // clear display screen lcd_cmd(0x06); // increment cursor lcd_cmd(0x80); // set cursor to 1st line } void lcd_cmd(unsigned char c) { output_b(c); output_low(RS); output_high(EN); delay_ms(15); output_low(EN); } void lcd_data(unsigned char z) { output_b(z); output_high(RS); output_high(EN); delay_ms(15); output_low(EN); }