Discussion in "PIC Microcontroller Discussion" started by    kingrosekhan123    Apr 10, 2013.
Wed Apr 10 2013, 09:55 am
#1
A.A...!
kindly check this code and tell what is actually doing ...please...

CCP1CON=Ox02; //Compare mode, toggle upon match
T3CON=Ox42; //Timer3 for Compare, 1:1 prescaler
TRISCbits.TRISC2=0; //CCP1 pin an output
TRISCbits.TRISC0=1; //T3CLK pin an input
CCPR1L=10; //load CCPR1L
CCPR1H=0; //load CCPR1H
while(1)
{
TMR3H=O;
TMR3L=O;
PIR1bits.CCP1IF=0; //clear CCP1IF flag
T3CONbits.TMR30N=1; //turn on Timer3
while(PIR1bits.CCP1IF==0) ;//wait for CCP1IF
//CCP toggles CCP pin upon match
T3CONbits.TMR30N=0; //stop Timer3
}
Wed Apr 10 2013, 02:37 pm
#2
what is meant by compare capture....
how we use...any example or tutorial for understanding.
kindly share it..
Wed Apr 10 2013, 03:00 pm
#3
CCP1CON = 0x02 means you are using compare mode.
T3CON = 0x42 means you are using external clock for timer. thats the reason PC.0 is made input for clock

CCPR1 register is used for compare and is loaded with a value. when timer value matches this capture value CCP1IF flag is set and pin is toggled. However the CCP1IF trigger function is not selected anywhere in this code so I am not sure whether it will toggle the pin or not.

Code is really simple.. Just open datasheet along with code to understand what is going. Post again if you have anymore questions.
Wed Apr 10 2013, 11:49 pm
#4
CCPR1L=10; //load CCPR1L
CCPR1H=0; //load CCPR1H


how we load this value in it...???

because its 16 bit..
Mon Apr 15 2013, 04:41 pm
#5
CCPR1L = CCPR1 low register (lower byte)
CCPR1H = CCPR1 High register (higher byte)

so loading 0x00 in high and 10 (0xA) in low means you are loading 0x000A in compare reigster.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

MildredWoumb
Wed May 15 2024, 04:07 am
NaKrutkADamb
Wed May 15 2024, 12:03 am
MichaelGot
Tue May 14 2024, 04:08 pm
FrankTrelm
Tue May 14 2024, 10:39 am
BillyTum
Tue May 14 2024, 09:08 am
Loganbag
Tue May 14 2024, 04:05 am
MichaelMog
Tue May 14 2024, 03:58 am
ThomasGaxaW
Mon May 13 2024, 05:33 pm