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

Set tris doesn't work

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



Joined: 17 Apr 2005
Posts: 2

View user's profile Send private message MSN Messenger

Set tris doesn't work
PostPosted: Mon Jul 04, 2005 7:42 am     Reply with quote

I made down counter with LED display. I want to use RB0 to INT. I read set_tris_b(0b0000001). But I cant use INT. What can I do?
Code:

#include <16F628.h>
#use delay ( clock = 6000000 )
#fuses HS,NOWDT,NOPROTECT,NOLVP,nomclr

BYTE CONST LED_MAP[10] = {0x7e,0x0c,0xb6,0x9e,0xcc,0xda,0xfa,0x0e,0xfe,0xde};

char saya,sayac=9,say=9, say1=9,say2=9;

#INT_EXT
void ext_isr(void)
 {
 static short button=TRUE;

if(button ){say--;}


}

void display_segs(char c)
{

output_b(LED_MAP[c]);


}

void display(char bir, char iki,char uc, ) {
   display_segs(bir);
      output_high(PIN_a0);
      delay_ms(5);
      output_low(PIN_a0);
   display_segs(iki);
      output_high(PIN_a1);
      delay_ms(5);
      output_low(PIN_a1);
   display_segs(uc);
      output_high(PIN_a2);
      delay_ms(5);
      output_low(PIN_a2);


}

void gos(void)
{
     if(say==-1)
   {
      say1--;
      say=9;
   }
   if(say1==-1)
   {
      say2--;

      say1=9;
   }
   if(say2==-1)
   {

      say2=9;
   }

   if(input(pin_a5))
      {
      say=0, say1=0,say2=0;
      }


}





void main(void)
{

  ext_int_edge(H_TO_L);
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);
  set_tris_B(0x01);
   
   while(TRUE)
   {
  display(say, say1, say2);


   gos();


}

}
newguy



Joined: 24 Jun 2004
Posts: 1909

View user's profile Send private message

PostPosted: Mon Jul 04, 2005 8:04 am     Reply with quote

Do you have an external pullup on B0? If not, use:

Code:
enable_pullups(TRUE);
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Jul 04, 2005 8:08 am     Reply with quote

Code:
char saya,sayac=9,say=9, say1=9,say2=9;
From the CCS manual chapter 'Data Definitions':
Quote:
All types, except float, by default are unsigned; however, maybe preceded by unsigned or signed
Change your line to
Code:
signed int8 saya,sayac=9,say=9, say1=9,say2=9;


Also be make sure to add a switch debouncing meassure or the following line is due to fail:
Code:
     if(say==-1)
Your switch will trigger the interrupt multiple times, so the variable 'say' will be decremented multiple times and become smaller than -1.
Search this forum for debounce software. As another option you can create a hardware debounce from the Schmitt-trigger function of the Int-ext input and adding an external R/C combination with a time constant of minimal 10ms.
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