Jump to content

BBC

Members
  • Content Count

    1
  • Joined

  • Last visited

Community Reputation

0 Neutral

About BBC

  • Rank
    Newbrie
  1. I am having trouble using the debugger buttons to generate an interrupt-on-change for the 16F1933. The following code is similar to that posted by Daz on 2 Dec. 2010. The code is intended to simply light a led connected to porta when portb.0 button is pushed. The button block does not activate the interrupt-on-change for the portb input(s). Any help would be greatly appreciated. #include <system.h> #include <stdlib.h> // Target PIC16F1933 configuration word #pragma DATA _CONFIG1, _FOSC_XT & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF #pragma DATA _CONFIG2, _WRT_OFF & _VCAPEN_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_19 & _DEBUG_ON & _LVP_OFF // Set PIC clock frequency #pragma CLOCK_FREQ 4000000 #define button1 portb.0 #define led1 porta.0 unsigned char flag1; // ***************** Interrupt Service Routine ********************* // // Called from portb change of state // // ****************************************************************** void interrupt(void) { //Handle external interrupt if( intcon & (1<<IOCIF) ) { if(button1){flag1 = 1;} clear_bit( intcon, IOCIF ); } } //****************** init_processor() *************************** // // Set up PIC16F1933 internal registers // // Parameters: // Entry: none // Exit: none // // ************************************************************** void init_processor() { // Configure port A ansela = 00000000b; // porta all digital trisa = 00000000b; // porta all outputs // Configure port B anselb = 00000000b; // portb all digital trisb = 11111111b; // portb all inputs // positive edge detect enabled for portb inputs set_bit(iocbp, IOCBP0); set_bit(iocbp, IOCBP1); set_bit(iocbp, IOCBP2); set_bit(iocbp, IOCBP3); set_bit(iocbp, IOCBP4); set_bit(iocbp, IOCBP5); set_bit(iocbp, IOCBP6); set_bit(iocbp, IOCBP7); // negative edge int-on-change disabled clear_bit(iocbn, IOCBN0); clear_bit(iocbn, IOCBN1); clear_bit(iocbn, IOCBN2); clear_bit(iocbn, IOCBN3); clear_bit(iocbn, IOCBN4); clear_bit(iocbn, IOCBN5); clear_bit(iocbn, IOCBN6); clear_bit(iocbn, IOCBN7); trisc = 00000000b; // portc all outputs } void main() { init_processor(); porta = 0; portb = 0; intcon = (1<<GIE | 1<<IOCIE); // enable interrupts //Endless loop while( 1 ) { if(flag1) { led1 = !led1; //on/off flag1 = !flag1; //reset } }//while }//main
×
×
  • Create New...