Jump to content
Sign in to follow this  
meder

Error in Inter.c sample

Recommended Posts

Its nice to have a working bug free sample app to get a Dev system up and running. ;)

The sample inter.c does not toggle the portb bit correctly.

If you run it the bit stays high. But, MPLAB 6.4 happily toggles the bit!

Heres the correct coding:

 

//This sample program for the PIC16F84 target shows how

//to use interrupts. If there is a LED connected to

//B7 it will blink.

 

#include <system.h>

 

char led = 1;

 

void interrupt( void )

{

   if( led == 1 )

   {

       portb |= 128;

       led = 0;

   }

   else

   {

       portb &= ~128;

       led = 1;

   }

 

   clear_bit( intcon, T0IF );  //clear TMR0 overflow flag

}

 

main()

{

   option_reg = 7;  //set prescaler to 1:256

   

   trisb = 0;

   portb = 0;

   enable_interrupt( GIE );

   enable_interrupt( T0IE );  //enable TMR0 overflow bit

 

 

   while( 1 ); //endless loop

 

}

 

/*

   EOF

*****************/

Share this post


Link to post
Share on other sites
Guest Pavel
Its nice to have a working bug free sample app to get a Dev system up and running. ;)

The sample inter.c does not toggle the portb bit correctly.

If you run it the bit stays high. But, MPLAB 6.4 happily toggles the bit!

Heres the correct coding:

...

The inter.c sample code is correct. Your change (portb &= ~128;) does the same as the original code(portb &= 127;). You must be doing something wrong. Please check again.

 

Regards,

Pavel

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.

Guest
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.

Loading...
Sign in to follow this  

×
×
  • Create New...