need help in ccp code.
Discussion in "PIC Microcontroller Discussion" started by kingrosekhan123 Apr 10, 2013.
Wed Apr 10 2013, 09:55 am
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
}
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
what is meant by compare capture....
how we use...any example or tutorial for understanding.
kindly share it..
how we use...any example or tutorial for understanding.
kindly share it..
Wed Apr 10 2013, 03:00 pm
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.
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
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
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.
CCPR1H = CCPR1 High register (higher byte)
so loading 0x00 in high and 10 (0xA) in low means you are loading 0x000A in compare reigster.
Powered by e107 Forum System