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_RB is not working with 18f45k22(solved)

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 24, 2011 3:11 pm     Reply with quote

I modified the program and now it works. The LED flashes when the
program starts. Then when you push a button on pin B4, the LED will
flash again. The main problem is that in vs. 4.119, the IOCB register
address is incorrect.
Code:

#include <18F45k22.h>   
#fuses INTRC_IO,NOWDT,NOPROTECT,BROWNOUT,PUT,MCLR, BORV27,NOPBADEN
#use delay(clock=4000000)

#define LED_RT    PIN_B0
#define X_SPUR_A  PIN_B4


void setup_IOCB(int8 mask)
{
#byte IOCB = 0xF62   // Register address for 18F45K22

IOCB = mask;
}

//----------------------------
void flash_led(void) 
{
int8 j=0;

for(j=0; j<10;j++)       
   {
    output_toggle(LED_RT);
    delay_ms(100);
   }


}

//------------------------------
#int_rb
void IRQ_XY(void)
{
int temp;

flash_led(); 

temp = input(PIN_B4); // To clear mismatch condition
}
 

//============================================
void main()
{
int temp;

output_low(LED_RT);  // LED is initially Off

port_b_pullups(0x10);   // Enable pull-up on pin B4 only
   
temp = input(PIN_B4);   // Read Pin B4 to clear mismatch condition
clear_interrupt(INT_RB); 
enable_interrupts(INT_RB4); // Enable int-on-change for pin B4 only
setup_IOCB(0x10);    // *** Fixes bug with ASM code for line above
enable_interrupts(GLOBAL);
   
flash_led();

while(1);
}
mdemuth



Joined: 16 Apr 2007
Posts: 71
Location: Stuttgart, Germany

View user's profile Send private message Visit poster's website

PostPosted: Mon Mar 28, 2011 3:26 am     Reply with quote

This looks much better => solved!
Thanks! Very Happy
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