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

int_ext problem

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



Joined: 24 May 2007
Posts: 97

View user's profile Send private message

int_ext problem
PostPosted: Mon Jul 16, 2007 6:22 pm     Reply with quote

Hello,

I am trying to write a program where on a push of the button the 16F88 toggles a variable. Also for a longer push of the same button it will (should) enter the menu subroutine to give me different options to change, however the interrupt doesn't seem to work... - Yes I know it is my fault. So that's why I am asking you the more experienced one...

So the pic is 16F88, tne PIN_B4 is connected to a push button, the other end of the push button is connected to the ground...

Here is the relevant portion of the code I wrote:

Code:


#Define M_button       Pin_B4
#Define On        1
#Define Off       0
...
...
...

int Tracking;

Void ShortBeep();
Void LongBeep();
Void Menu();

#int_EXT
Void Ext_isr() {
      Delay_ms(250);
      If (Input(M_Button)){
               If (Tracking == Off) {
                     Tracking = On;
                     Shortbeep();
                     Delay_ms(150);
                     Longbeep();
               }
               Else {
                     Tracking = Off;
                     LongBeep();
                     Delay_ms(150);
                     ShortBeep();
               }
      }
      Else {
               Delay_ms(1750);
               If (!Input(M_Button)) {
                  Delay_ms(500);
                  If (Input(M_Button)){
                     Longbeep();
                     Menu();
                  }
               }
            }
}

...
...
...

Void
   set_tris_a(0b00000001);
   set_tris_b(0b11010000);
   setup_adc_ports(sAN0|VSS_VDD);
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   port_b_pullups(True);
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_EXT);

...
...
...



The PIC boots however nothing happens when I push the button - short or long push...

Can you please help me?

Thanks, Ox.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 16, 2007 8:14 pm     Reply with quote

Quote:
So the pic is 16F88, tne PIN_B4 is connected to a push button.
However the interrupt doesn't seem to work.

RB4 uses INT_RB interrupts. RB0 uses INT_EXT interrupts.

Remember that with INT_RB interrupts, you need to read Port B inside
the ISR to clear the "mis-match condition". Also, it will interrupt on
either edge. You can't specify the edge with INT_RB.
oxxyfx



Joined: 24 May 2007
Posts: 97

View user's profile Send private message

PostPosted: Mon Jul 16, 2007 9:17 pm     Reply with quote

Thank you. I remembered the INT_RB after I posted my original post and changed the code to that, but it still did not work. After I read your post I did a search on the forum and based on that modified the code to the following:

Code:

...
...
#int_RB
Void RB_isr() {
int8 tempb;

      tempb = input_b();
      If (bit_test(tempb.4) == 0){
          Delay_ms(500);
          tempb = input_b();
           If (bit_test(tempb.4) == 1){
               If (Tracking == Off) {
                     Tracking = On;
                     Shortbeep();
                     Delay_ms(150);
                     Longbeep();
               }
               Else {
                     Tracking = Off;
                     LongBeep();
                     Delay_ms(150);
                     ShortBeep();
               }
           }
           Else {
               Delay_ms(1750);
               tempb = input_b();               
               If (bit_test(tempb.4) == 0) {
                  Delay_ms(500);
                  tempb = input_b();   
                  If (bit_test(tempb.4) == 1){
                     Longbeep();
                     Menu();
                  }
               }
           }
      }
}
...
...
...
void main()
{
   set_tris_a(0b00000001);
   set_tris_b(0b11010000);
   setup_adc_ports(sAN0|VSS_VDD);
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   port_b_pullups(True);
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_RB);
   ext_int_edge(H_to_L);
...
...
...
}


It looks like it never beyond the first if statement because I can never hear the beeps - no matter how long I keep the button pressed.

Thanks,
Ox.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 16, 2007 10:09 pm     Reply with quote

You need to look at the .LST file to see what the compiler is doing.
Look at the code generated for the setup_spi(FALSE) statement.
What is it doing to pin RB4 ? How will this affect your program ?
Quote:

.................... setup_spi(FALSE);
0010: BCF STATUS.RP0
0011: BCF SSPCON.SSPEN
0012: BSF STATUS.RP0
0013: BCF TRISB.2
0014: BSF TRISB.1
0015: BCF TRISB.4
0016: MOVLW 00
0017: BCF STATUS.RP0
0018: MOVWF SSPCON
0019: BSF STATUS.RP0
001A: MOVWF SSPSTAT
....................

The SPI module is disabled upon power-on reset. You don't need
to use that function. Or more accurately, the Wizard doesn't need
to put in that line and it causes harm by doing so.
oxxyfx



Joined: 24 May 2007
Posts: 97

View user's profile Send private message

PostPosted: Mon Jul 16, 2007 11:10 pm     Reply with quote

Thank you, my lst file looks like this:

Code:

.................... void main()
.................... {
*
0992:  CLRF   04
0993:  BCF    03.7
0994:  MOVLW  1F
0995:  ANDWF  03,F
0996:  MOVLW  62
0997:  BSF    03.5
0998:  MOVWF  0F
0999:  MOVLW  0C
099A:  MOVWF  19
099B:  MOVLW  A6
099C:  MOVWF  18
099D:  MOVLW  90
099E:  BCF    03.5
099F:  MOVWF  18
09A0:  BSF    03.5
09A1:  BCF    1F.4
09A2:  BCF    1F.5
09A3:  MOVF   1B,W
09A4:  ANDLW  80
09A5:  MOVWF  1B
09A6:  MOVLW  07
09A7:  MOVWF  1C
....................    set_tris_a(0b00000001);
*
09AA:  MOVLW  01
09AB:  BSF    03.5
09AC:  MOVWF  05
....................    set_tris_b(0b11010000);
09AD:  MOVLW  D0
09AE:  MOVWF  06
....................    setup_adc_ports(sAN0|VSS_VDD);
09AF:  BCF    1F.4
09B0:  BCF    1F.5
09B1:  MOVF   1B,W
09B2:  ANDLW  80
09B3:  IORLW  01
09B4:  MOVWF  1B
....................    setup_adc(ADC_CLOCK_INTERNAL);
09B5:  BCF    1F.6
09B6:  BCF    03.5
09B7:  BSF    1F.6
09B8:  BSF    1F.7
09B9:  BSF    03.5
09BA:  BCF    1F.7
09BB:  BCF    03.5
09BC:  BSF    1F.0
....................    setup_spi(FALSE);
09BD:  BCF    14.5
09BE:  MOVLW  00
09BF:  MOVWF  14
09C0:  BSF    03.5
09C1:  MOVWF  14
....................    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
09C2:  MOVF   01,W
09C3:  ANDLW  C7
09C4:  IORLW  08
09C5:  MOVWF  01
....................    setup_timer_1(T1_DISABLED);
09C6:  BCF    03.5
09C7:  CLRF   10
....................    setup_timer_2(T2_DISABLED,0,1);
09C8:  MOVLW  00
09C9:  MOVWF  78
09CA:  MOVWF  12
09CB:  MOVLW  00
09CC:  BSF    03.5
09CD:  MOVWF  12
....................    setup_comparator(NC_NC_NC_NC);
09CE:  MOVLW  07
09CF:  MOVWF  1C
09D0:  MOVF   05,W
09D1:  MOVLW  03
09D2:  MOVWF  77
09D3:  DECFSZ 77,F
09D4:  GOTO   1D3
09D5:  MOVF   1C,W
09D6:  BCF    03.5
09D7:  BCF    0D.6
....................    setup_vref(FALSE);
09D8:  BSF    03.5
09D9:  CLRF   1D
....................    port_b_pullups(True);
09DA:  BCF    01.7
....................    enable_interrupts(GLOBAL);
09DB:  MOVLW  C0
09DC:  BCF    03.5
09DD:  IORWF  0B,F
....................    enable_interrupts(INT_RB); 
09DE:  BSF    03.6
09DF:  BSF    0B.3
....................    ext_int_edge(H_to_L);
09E0:  BSF    03.5
09E1:  BCF    03.6
09E2:  BCF    01.6



I tried disabling it, and it doesn't seem to make any difference....

Code:

.................... void main()
.................... {
*
0992:  CLRF   04
0993:  BCF    03.7
0994:  MOVLW  1F
0995:  ANDWF  03,F
0996:  MOVLW  62
0997:  BSF    03.5
0998:  MOVWF  0F
0999:  MOVLW  0C
099A:  MOVWF  19
099B:  MOVLW  A6
099C:  MOVWF  18
099D:  MOVLW  90
099E:  BCF    03.5
099F:  MOVWF  18
09A0:  BSF    03.5
09A1:  BCF    1F.4
09A2:  BCF    1F.5
09A3:  MOVF   1B,W
09A4:  ANDLW  80
09A5:  MOVWF  1B
09A6:  MOVLW  07
09A7:  MOVWF  1C
....................    set_tris_a(0b00000001);
*
09AA:  MOVLW  01
09AB:  BSF    03.5
09AC:  MOVWF  05
....................    set_tris_b(0b11010000);
09AD:  MOVLW  D0
09AE:  MOVWF  06
....................    setup_adc_ports(sAN0|VSS_VDD);
09AF:  BCF    1F.4
09B0:  BCF    1F.5
09B1:  MOVF   1B,W
09B2:  ANDLW  80
09B3:  IORLW  01
09B4:  MOVWF  1B
....................    setup_adc(ADC_CLOCK_INTERNAL);
09B5:  BCF    1F.6
09B6:  BCF    03.5
09B7:  BSF    1F.6
09B8:  BSF    1F.7
09B9:  BSF    03.5
09BA:  BCF    1F.7
09BB:  BCF    03.5
09BC:  BSF    1F.0
.................... //   setup_spi(FALSE);
....................    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
09BD:  BSF    03.5
09BE:  MOVF   01,W
09BF:  ANDLW  C7
09C0:  IORLW  08
09C1:  MOVWF  01
....................    setup_timer_1(T1_DISABLED);
09C2:  BCF    03.5
09C3:  CLRF   10
....................    setup_timer_2(T2_DISABLED,0,1);
09C4:  MOVLW  00
09C5:  MOVWF  78
09C6:  MOVWF  12
09C7:  MOVLW  00
09C8:  BSF    03.5
09C9:  MOVWF  12
....................    setup_comparator(NC_NC_NC_NC);
09CA:  MOVLW  07
09CB:  MOVWF  1C
09CC:  MOVF   05,W
09CD:  MOVLW  03
09CE:  MOVWF  77
09CF:  DECFSZ 77,F
09D0:  GOTO   1CF
09D1:  MOVF   1C,W
09D2:  BCF    03.5
09D3:  BCF    0D.6
....................    setup_vref(FALSE);
09D4:  BSF    03.5
09D5:  CLRF   1D
....................    port_b_pullups(True);
09D6:  BCF    01.7
....................    enable_interrupts(GLOBAL);
09D7:  MOVLW  C0
09D8:  BCF    03.5
09D9:  IORWF  0B,F
....................    enable_interrupts(INT_RB); 
09DA:  BSF    03.6
09DB:  BSF    0B.3
....................    ext_int_edge(H_to_L);
09DC:  BSF    03.5
09DD:  BCF    03.6
09DE:  BCF    01.6


Should I try to change the pin? maybe use RB6 or 7 instead of RB4? I have an RS232 TX on RB5...

Thankx, Ox.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 16, 2007 11:19 pm     Reply with quote

Post your compiler version.
oxxyfx



Joined: 24 May 2007
Posts: 97

View user's profile Send private message

PostPosted: Tue Jul 17, 2007 6:32 am     Reply with quote

It is 4.023.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 17, 2007 11:42 am     Reply with quote

You're using fast i/o mode. That's why those lines didn't appear in your
.LST file.

I think you need to prove that you can get #int_rb to work.
See the test program shown below. I compiled it with PCM vs. 4.023
and ran it on a PicDem2-Plus board. It worked. Every time I press
or release a push-button (on RB4), I get the LED on RB0 to blink.
That's what it should do. You get an interrupt on both edges. The
200 ms delay acts as a debounce delay in this test.
Try this program "as is". Don't add fast i/o or TRIS statements to it.

Code:

#include <16F88.h>
#fuses INTRC_IO, NOWDT, PUT, BROWNOUT, NOLVP
#use delay(clock=4000000)

#int_rb
void int_rb_isr()
{
int8 c;

output_high(PIN_B0);
delay_ms(200);
output_low(PIN_B0);

c = input_b();
}

//=================================
void main()
{
port_b_pullups(TRUE);
enable_interrupts(GLOBAL);
enable_interrupts(INT_RB);

while(1);
}
oxxyfx



Joined: 24 May 2007
Posts: 97

View user's profile Send private message

PostPosted: Tue Jul 17, 2007 11:50 am     Reply with quote

Thank you. I will try this perhaps tonight and I will let you know by tomorrow how it goes.

thanks, Ox.
oxxyfx



Joined: 24 May 2007
Posts: 97

View user's profile Send private message

PostPosted: Tue Jul 17, 2007 8:12 pm     Reply with quote

Ok,

I've got the LED flashing with your code. Now what should be my next step? Try disabling the Fast_IO on port B and the set_tris_B statements?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 17, 2007 8:43 pm     Reply with quote

Quote:

#use fast_io(A)
#use fast_io(B)


set_tris_a(0b00000001);

set_tris_b(0b11010000);
setup_adc_ports(sAN0|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
setup_spi(FALSE);

Remove the statements shown in bold. If you use CCS pin i/o functions
the compiler will automatically handle the TRIS. Most of the stuff that
the Wizard puts in to disable the peripheral modules isn't needed,
because these modules are disabled upon power-on reset anyway.
oxxyfx



Joined: 24 May 2007
Posts: 97

View user's profile Send private message

PostPosted: Tue Jul 17, 2007 8:55 pm     Reply with quote

Thank you. I've got it working. After I remove the fast_io's and the Tris, I had to go back to my original code version with the Input(M_button) statements, because the tempb = Input_B()'s didn't work. Now I have it now up and running.

Thank you for your patience and help.

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