|
|
View previous topic :: View next topic |
Author |
Message |
Noobie Guest
|
PIC timer |
Posted: Wed Mar 11, 2009 2:41 pm |
|
|
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
|
|
Posted: Wed Mar 11, 2009 3:13 pm |
|
|
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:
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
|
|
Posted: Wed Mar 11, 2009 3:21 pm |
|
|
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
|
|
Posted: Thu Mar 12, 2009 10:02 am |
|
|
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.. ^^ |
|
|
|
|
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
|