Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help with Capture mode in PIC CCP

Status
Not open for further replies.

hemnath

Advanced Member level 3
Joined
Jun 24, 2012
Messages
702
Helped
61
Reputation
120
Reaction score
57
Trophy points
1,308
Location
Chennai
Activity points
6,588
Sorry for posting this post again. I did get any solution from my recent post. So i think re-posting the post again will get some results. Please help in configuring the registers with PIC CCP module in Capture mode.

HTML:
#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);

CCP1IE	=	0;
CCP1IF	=	0;
lcd_cmd(0x01);
lcd_cmd(0x80);
printf(lcd_data,"%lu secs",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);
}
 

Everytime values are changing.
I'm giving 2Khz to PIN C2. It shows some values on LCD. Say about 7525 secs. When i change the frequency from 2Khz to 5Khz, there is no change in the LCD.
Please check that i have configured the registers correctly. I have doubt in that.

Thanks in advance :)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top