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 support@ccsinfo.com

problem with Port _b_ inpeetrup

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



Joined: 23 Jun 2006
Posts: 12

View user's profile Send private message

problem with Port _b_ inpeetrup
PostPosted: Sat Oct 21, 2006 5:37 am     Reply with quote

hello
i have to take input from encoders for that i decided to use RB4 pin(interrup on chnage) on pic16f877. i used the example code EX_PBUTT.c with little modifications.
on change i on/off led attached to RD0 pin.To have interrupt on change i used to ground pin RB4 & RB5.
The code is working well in proteus simulation but when i use it on actual hardware it is not responding well.
Instead when i ground pin RB3 it toggles LED. I m not getting wht the problem is .
I have also read the forums regarding port B interrupt on chnage but i m getting no info.
Please help me out.
Also i am not understanding why #if LOWTOHIGH & #elif HIGHTOLOW
are used in program.
Code:

#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)

#define LOWTOHIGH TRUE
#define HIGHTOLOW FALSE

short int dbutton4, dbutton5, dbutton6, dbutton7;

#int_rb
void detect_rb_change() {
   int current;
   static int last=0;

   set_tris_b(0xF0);
   current=input_b();

   #if LOWTOHIGH
   if ((!bit_test(last,4))&&(bit_test(current,4))) {dbutton4=1;}
   if ((!bit_test(last,5))&&(bit_test(current,5))) {dbutton5=1;}
   if ((!bit_test(last,6))&&(bit_test(current,6))) {dbutton6=1;}
   if ((!bit_test(last,7))&&(bit_test(current,7))) {dbutton7=1;}
   #elif HIGHTOLOW
   if ((!bit_test(current,4))&&(bit_test(last,4))) {dbutton4=1;}
   if ((!bit_test(current,5))&&(bit_test(last,5))) {dbutton5=1;}
   if ((!bit_test(current,6))&&(bit_test(last,6))) {dbutton6=1;}
   if ((!bit_test(current,7))&&(bit_test(last,7))) {dbutton7=1;}
   #endif

   last=current;
}

void clear_delta() {
   dbutton4=0;
   dbutton5=0;
   dbutton6=0;
   dbutton7=0;
}

void main() {
   clear_delta();

   port_b_pullups(TRUE);
   enable_interrupts(INT_RB);
   enable_interrupts(GLOBAL);

   output_low(PIN_D0);
   while (TRUE) {
      if(dbutton4) {
        output_high(PIN_D0);
        dbutton4=FALSE;
      }
      if(dbutton5) {
        output_low(PIN_D0);
        dbutton5=FALSE;
      }
   }
}
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Sat Oct 21, 2006 6:30 am     Reply with quote

Quote:
Also i am not understanding why #if LOWTOHIGH & #elif HIGHTOLOW


I believe these are used to set whether you want to detect a switch change from low-to-high or high-to-low... If you are grounding a pullup with a switch then you would use HIGHTOLOW. To do that you would comment out the appropriate #define line.

Code:
//#define LOWTOHIGH TRUE


Good luck,

John
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