|
|
View previous topic :: View next topic |
Author |
Message |
KALKAN
Joined: 17 Apr 2005 Posts: 2
|
Set tris doesn't work |
Posted: Mon Jul 04, 2005 7:42 am |
|
|
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: 1907
|
|
Posted: Mon Jul 04, 2005 8:04 am |
|
|
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
|
|
Posted: Mon Jul 04, 2005 8:08 am |
|
|
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: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. |
|
|
|
|
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
|