Compare Mode CCP1

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Compare Mode CCP1

mircea2012
Hy.
In this program i try to test compare mode using pic16f88.
I am not quite sure if it is OK but the code is working.
I set an output RB0 for 1 sec (led is ON), after that i reset that output RB0 (led is OFF) for 1 sec.
From my calculations : f = 4MHz / (4 * 8 * 65536) = 2Hz
T = 1 / 2Hz = 0,5 which means that the led is on twice per sec.
But in program i use variable counter to increase the delay, so led is on for 1 sec and off - 1 sec.


#include <system.h>

#pragma DATA _CONFIG1, _EXTRC_CLKOUT & _WDT_OFF & _LVP_OFF

unsigned int counter = 0;

void interrupt()
{    
     if((pir1 & 0x01) && (pir1 & 0x04))
     {                      
          clear_bit(pir1, 0);
          clear_bit(pir1, 2);
          counter++;
          if(counter == 2)
          {
                 ccp1con = 0b00001001;
          }
          else if(counter == 4)
          {
                 ccp1con = 0b00001000;
                 counter = 0;
          }
     }            
}

void main()
{
        trisb = 0xf0;
        portb = 0x00;
        tmr1h = 0;
        tmr1l = 0;
        ccpr1l = 0x60;
        ccpr1h = 0xea;
        cmcon = 0x07;
        t1con = 0b00110001;  // prescaler = 8
        intcon = 0b11000000;
        pie1 = 0b00000101;
        ccp1con = 0b00001000;
        while(1)
        {
       
        }
}
Reply | Threaded
Open this post in threaded view
|

Re:[PIC] Compare Mode CCP1

Bob Blick-4
added tag. -Bob

On Sat, Jun 22, 2013, at 11:42 AM, mircea2012 wrote:

> Hy.
> In this program i try to test compare mode using pic16f88.
> I am not quite sure if it is OK but the code is working.
> I set an output RB0 for 1 sec (led is ON), after that i reset that output
> RB0 (led is OFF) for 1 sec.
> >From my calculations : f = 4MHz / (4 * 8 * 65536) = 2Hz
> T = 1 / 2Hz = 0,5 which means that the led is on twice per sec.
> But in program i use variable counter to increase the delay, so led is on
> for 1 sec and off - 1 sec.
>
>
> #include <system.h>
>
> #pragma DATA _CONFIG1, _EXTRC_CLKOUT & _WDT_OFF & _LVP_OFF
>
> unsigned int counter = 0;
>
> void interrupt()
> {    
>      if((pir1 & 0x01) && (pir1 & 0x04))
>      {                      
>           clear_bit(pir1, 0);
>           clear_bit(pir1, 2);
>           counter++;
>           if(counter == 2)
>           {
> ccp1con = 0b00001001;
>  }
>  else if(counter == 4)
>  {
>         ccp1con = 0b00001000;
>         counter = 0;
>  }
>      }            
> }
>
> void main()
> {
> trisb = 0xf0;
> portb = 0x00;
> tmr1h = 0;
> tmr1l = 0;
> ccpr1l = 0x60;
> ccpr1h = 0xea;
> cmcon = 0x07;
> t1con = 0b00110001;  // prescaler = 8
> intcon = 0b11000000;
> pie1 = 0b00000101;
> ccp1con = 0b00001000;
> while(1)
> {
>
> }
> }
>

--
http://www.fastmail.fm - Access your email from home and the web

--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: [PIC] Compare Mode CCP1

Tamas Rudnai
Hi Mircea,

Could you please spell "Hi" correctly? :)

Thanks,
Tamas

Sent from my iPhone

On Jun 22, 2013, at 11:57 AM, Bob Blick <[hidden email]> wrote:

> added tag. -Bob
>
> On Sat, Jun 22, 2013, at 11:42 AM, mircea2012 wrote:
>> Hy.
>> In this program i try to test compare mode using pic16f88.
>> I am not quite sure if it is OK but the code is working.
>> I set an output RB0 for 1 sec (led is ON), after that i reset that output
>> RB0 (led is OFF) for 1 sec.
>>> From my calculations : f = 4MHz / (4 * 8 * 65536) = 2Hz
>> T = 1 / 2Hz = 0,5 which means that the led is on twice per sec.
>> But in program i use variable counter to increase the delay, so led is on
>> for 1 sec and off - 1 sec.
>>
>>
>> #include <system.h>
>>
>> #pragma DATA _CONFIG1, _EXTRC_CLKOUT & _WDT_OFF & _LVP_OFF
>>
>> unsigned int counter = 0;
>>
>> void interrupt()
>> {
>>     if((pir1 & 0x01) && (pir1 & 0x04))
>>     {
>>          clear_bit(pir1, 0);
>>          clear_bit(pir1, 2);
>>          counter++;
>>          if(counter == 2)
>>          {
>>         ccp1con = 0b00001001;
>>      }
>>      else if(counter == 4)
>>      {
>>             ccp1con = 0b00001000;
>>             counter = 0;
>>      }
>>     }
>> }
>>
>> void main()
>> {
>>    trisb = 0xf0;
>>    portb = 0x00;
>>    tmr1h = 0;
>>    tmr1l = 0;
>>    ccpr1l = 0x60;
>>    ccpr1h = 0xea;
>>    cmcon = 0x07;
>>    t1con = 0b00110001;  // prescaler = 8
>>    intcon = 0b11000000;
>>    pie1 = 0b00000101;
>>    ccp1con = 0b00001000;
>>    while(1)
>>    {
>>
>>    }
>> }
>
> --
> http://www.fastmail.fm - Access your email from home and the web
>
> --
> http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
> View/change your membership options at
> http://mailman.mit.edu/mailman/listinfo/piclist
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: [PIC] Compare Mode CCP1

Bob Blick-4
One thing at a time, Tamas. Topic tag trumps.
And who knows, "Hy" may be post-hello-kitty "Hai" and we are just too
old to appreciate a nice gesture that combines respect and familiarity.

Don't tell a youngster "get off my lawn" just for the hell of it  
>^..^<

Friendly regards,

Bob

On Sat, Jun 22, 2013, at 03:27 PM, Tamas Rudnai wrote:

> Hi Mircea,
>
> Could you please spell "Hi" correctly? :)
>
> Thanks,
> Tamas
>
> Sent from my iPhone
>
> On Jun 22, 2013, at 11:57 AM, Bob Blick <[hidden email]> wrote:
>
> > added tag. -Bob
> >
> > On Sat, Jun 22, 2013, at 11:42 AM, mircea2012 wrote:
> >> Hy.
> >> In this program i try to test compare mode using pic16f88.
> >> I am not quite sure if it is OK but the code is working.
> >> I set an output RB0 for 1 sec (led is ON), after that i reset that output
> >> RB0 (led is OFF) for 1 sec.
> >>> From my calculations : f = 4MHz / (4 * 8 * 65536) = 2Hz
> >> T = 1 / 2Hz = 0,5 which means that the led is on twice per sec.
> >> But in program i use variable counter to increase the delay, so led is on
> >> for 1 sec and off - 1 sec.
> >>
> >>
> >> #include <system.h>
> >>
> >> #pragma DATA _CONFIG1, _EXTRC_CLKOUT & _WDT_OFF & _LVP_OFF
> >>
> >> unsigned int counter = 0;
> >>
> >> void interrupt()
> >> {
> >>     if((pir1 & 0x01) && (pir1 & 0x04))
> >>     {
> >>          clear_bit(pir1, 0);
> >>          clear_bit(pir1, 2);
> >>          counter++;
> >>          if(counter == 2)
> >>          {
> >>         ccp1con = 0b00001001;
> >>      }
> >>      else if(counter == 4)
> >>      {
> >>             ccp1con = 0b00001000;
> >>             counter = 0;
> >>      }
> >>     }
> >> }
> >>
> >> void main()
> >> {
> >>    trisb = 0xf0;
> >>    portb = 0x00;
> >>    tmr1h = 0;
> >>    tmr1l = 0;
> >>    ccpr1l = 0x60;
> >>    ccpr1h = 0xea;
> >>    cmcon = 0x07;
> >>    t1con = 0b00110001;  // prescaler = 8
> >>    intcon = 0b11000000;
> >>    pie1 = 0b00000101;
> >>    ccp1con = 0b00001000;
> >>    while(1)
> >>    {
> >>
> >>    }
> >> }

--
http://www.fastmail.fm - The way an email service should be

--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist