// Lesson #23 - Demonstrate Timer 1 and CCP Capture

// August 18th, 2012.


// Related to timing

unsigned long t1; // 16 bit number, 0 - 65,535


// Related to string printing

unsigned short int stringLength;

unsigned short int i;

char periodData[] = "original value in here!";


void writeString(char periodData[])

{

// Get string length

stringLength = strlen(periodData);

for(i = 0; i<stringLength; i++)

{

Soft_UART_Write(periodData[i]);

}

Soft_UART_Write(0x0D);

Soft_UART_Write(0x0A);

}


void configStuff()

{

// Configure timer1 and int registers

T1CON = 0b00110001; // Enable timer1, Fosc/4 input

// Configure capture

CCP1CON = 0x05; // Capture every rising-edge

// Configure interrupt

INTCON = 0b11000000; // Enable global/periph ints

// Configure peripheral interrupt

PIE1 = 0b00100000; // Enable CCP interrupt

TRISIO.B2 = 1;

}


void interrupt(void)

{

// Respond to CCP interrupt

INTCON = 0;

PIR1.B5 = 0;

t1 = TMR1H;

t1 = t1 << 8;

t1 = t1 | TMR1L;

LongToStr(t1, periodData);

writeString(periodData);

INTCON = 0b11000000;

}


void main() {

Soft_UART_Init(&GPIO, 1, 0, 4800, 0);

configStuff();

while(1)

{

}

}