Jump to content
Sign in to follow this  

Using TMR0 with PIC16F628 @4Mhz still too fast

Recommended Posts

Hi all,

I have been playing around with Timers and would like to create a routine that creates a slow blink but uses at little of the processor as possible.  The code below works however I would like to know if it would be better using Timer 1 or 2 perhaps the brownout timer????


My code was copied from the samples which does NOT have  a delay and the LED blinks for the naked eye about every 65ms:

C2C Tmr0 Sample



// This program is testing the timer feature within C
// by blinking a LED connected to B1 
#pragma CLOCK_FREQ 4000000
#include <system.h>
//Configuration Bits
list p=16F628
__config _HS_OSC & _WDT_OFF & _PWRTE_OFF & _CP_OFF & _BODEN_ON;

unsigned int TMR0Overflows;

void interrupt( void )
   if (++TMR0Overflows == 10)     // This should slow things down
 PORTB ^= 00000010b; 	 // complement PORTB:1
 TMR0Overflows = 0;
   TMR0=0; 	 // initialize timer for new overflow or more accurate timing
 clear_bit( INTCON, T0IF );  //clear TMR0 overflow flag


disable_interrupt( GIE );

   set_bit( STATUS, RP0 );
   OPTION_REG = 7;    //set prescaler to 1:256
   set_tris_b( 0 );
   clear_bit( STATUS, RP0 );	// switch to bank 0
   output_port_b( 0 ); 	 // 

   enable_interrupt( T0IE );	//enable Timer (TMR0) overflow bit in INTCON register

enable_interrupt( GIE );	// enable main int flag in INTCON register
   TMR0Overflows = 0;

   while( 1 );



Thank You very much



Share this post

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...