CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC timer

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Noobie
Guest







PIC timer
PostPosted: Wed Mar 11, 2009 2:41 pm     Reply with quote

I'm new in PIC programming and i've some question about PIC16F876A. Here are my Question: How long is the maximum delay can the PIC uC do? If I'd like to activate a sensor after 3 days (72Hrs) I turn ON the PIC, what should I use for such long delay?

Any examples can be referred?

Can someone help me on this matter? I need to solve this doubt for my Final Year Project.

Thank you.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 11, 2009 3:13 pm     Reply with quote

If the only thing you want to do, after power-up of the PIC, is to wait
for 3 days, then you can just call delay_ms() in a loop.

This will give a one minute delay:
Code:
delay_ms(60000);

Then just create a for(;;) loop that calls it the required number of times.

A tip regarding the loop counter value:
Remember that in CCS, an 'int' is an unsigned 8-bit integer, and can take
values from 0 to 255. If you want a larger number, you need to use
declare it as 'int16' (0 to 65535) or 'int32'.
necati



Joined: 12 Sep 2003
Posts: 37
Location: istanbul

View user's profile Send private message

PostPosted: Wed Mar 11, 2009 3:21 pm     Reply with quote

Code:
#include <16f876a.h>
#fuses  XT, NOPROTECT,PUT, NOWDT,BROWNOUT
#use    delay(clock=4000000)
#BYTE   PORT_A=0X05
#BYTE   PORT_B=0X06
#BYTE   PORT_C=0X07
/***entegreterbiyecisi@yahoo.com***/
// LCD STUFF
#define LCD_RS      PIN_b6
#define LCD_EN      PIN_b5
#define LCD_D4      PIN_b4
#define LCD_D5      PIN_b3
#define LCD_D6      PIN_b2
#define LCD_D7      PIN_b1
#define FIRST_LINE  0x00
#define SECOND_LINE 0x40
#define CLEAR_DISP  0x01
#define CURS_ON     0x0e
#define CURS_OFF    0x0c
/***entegreterbiyecisi@yahoo.com***/
#use fast_io ( a )
#use fast_io ( b )
#use fast_io ( c )
/***entegreterbiyecisi@yahoo.com***///lcd
void LCD_Init        ( void );
void LCD_SetPosition ( unsigned int cX );
void LCD_PutChar     ( unsigned int cX );
void LCD_PutCmd      ( unsigned int cX );
void LCD_PulseEnable ( void );
void LCD_SetData     ( unsigned int cX );
/***entegreterbiyecisi@yahoo.com***/
int16 clock =400;
int8 hours=0,minutes=0,seconds=0;
int1 yz=0;
///////////////////////////////////////////

///////////////////////////////////////////
#int_TIMER1
void TIMER1() {
clock -=25 ;
///////////////////////////
if(clock <25 ) {seconds++;clock +=400;yz=1;    //sec   1 artır  400
if(seconds == 60) {minutes++;seconds = 0; //60    puls ta min  1 artır
if(minutes == 60) {hours++;minutes = 0;   //60    puls ta hour 1 artır
}}}}
/*************************entegreterbiyecisi@yahoo.com******************************/
void main(void){

      setup_adc_ports(no_analogs);
      SET_TRIS_A   (0b11111111);
      SET_TRIS_B   (0b10000001);
      SET_TRIS_C   (0b10000000);
      setup_timer_1(t1_internal|t1_div_by_1);
      enable_interrupts(int_timer1);
      enable_interrupts(global);     
      PORT_A=0;
      PORT_B=0;
      PORT_C=0;
      port_b_pullups(0b10000000);
      lcd_init();
      //LCD_PutCmd(CURS_ON);
      LCD_PutCmd(CLEAR_DISP);
      output_high (pin_c3);
      delay_ms (100);
///////////////////////////////////////////////
   while(true){
          if(yz==1){LCD_SetPosition (second_LINE+0);
                  printf(lcd_putchar,"\%02d:%02d:%02d",hours,minutes,seconds);
                  output_toggle(PIN_c2);
                  yz=0;}
                  if(hours==72){output_low (pin_c3);}
              }}
/***entegreterbiyecisi@yahoo.com***/ //lcd basla
void LCD_Init ( void ){
    LCD_SetData ( 0x00 );
    output_low ( LCD_RS );
    LCD_SetData ( 0x03 );
    LCD_PulseEnable();
    LCD_PulseEnable();
    LCD_PulseEnable();
    LCD_SetData ( 0x02 );
    LCD_PulseEnable();   
    LCD_PutCmd ( 0x2C );   
    LCD_PutCmd ( 0x0C );   
    LCD_PutCmd ( 0x01 );   
    LCD_PutCmd ( 0x06 );   
    }
/***entegreterbiyecisi@yahoo.com***/
void LCD_SetPosition ( unsigned int cX )
    {
    LCD_SetData ( swap ( cX ) | 0x08 );
    LCD_PulseEnable();
    LCD_SetData ( swap ( cX ) );
    LCD_PulseEnable();
    }
/***entegreterbiyecisi@yahoo.com***/
void LCD_PutChar ( unsigned int cX )
    {
    output_high ( LCD_RS );
    LCD_SetData ( swap ( cX ) );
    LCD_PulseEnable();
    LCD_SetData ( swap ( cX ) ); 
    LCD_PulseEnable();
    output_low ( LCD_RS );
    }
/***entegreterbiyecisi@yahoo.com***/
void LCD_PutCmd ( unsigned int cX )
    {
    LCD_SetData ( swap ( cX ) );   
    LCD_PulseEnable();
    LCD_SetData ( swap ( cX ) );     
    LCD_PulseEnable();
    }
/***entegreterbiyecisi@yahoo.com***/
void LCD_PulseEnable ( void )
    {
    output_high ( LCD_EN );
    delay_us ( 100 );
    output_low ( LCD_EN );
    delay_ms ( 5 );
    }
/***entegreterbiyecisi@yahoo.com***/
void LCD_SetData ( unsigned int cX )
    {
    output_bit ( LCD_D4, cX & 0x01 );
    output_bit ( LCD_D5, cX & 0x02 );
    output_bit ( LCD_D6, cX & 0x04 );
    output_bit ( LCD_D7, cX & 0x08 );
    }
/***entegreterbiyecisi@yahoo.com***/ //lcd son
Noobie
Guest







PostPosted: Thu Mar 12, 2009 10:02 am     Reply with quote

Thanks for PCM programmer, i manage to have few minutes waiting, now i'm running the board and test for hrs and days experiment. thank you for info~ ^^

Thanks to necati for providing the code, however, i do not need to display my counter... But i'll consider to do it for my enhancement if i have extra time.. ^^
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group