Autor Tema: Problemas con interrupcion por cambio en puerto b...16f84a - programacion en c  (Leído 2533 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado maverick84

  • PIC10
  • *
  • Mensajes: 1
Soy nuevo en el foro y recien me estoy introduciendo a esto de los pic

Tengo el siguiente programa (intpb.c) y cuando quiero simularlo me tira error "Internal exception: access violation in module <unknow>" el proteus..La idea del programa es que por el puerto a0-a3 y b3 pueda preder y apagar led (salidas). por b1yb2 me conecto al rs232 y por rb4-br7 monitoreo sensores.....cuando unos de estos se activa salta la interrupcion del puerto b.

Sinceramente no entiendo que me esta faltando para configurar la interrupcion del puerto b, cuando activo esta no puedo simular,....agradesco si alguien me puede colaborar. he buscado en internet muchos ejemplos y no varia de lo que tengo....tengo poca experiencia en esto, alomejor estoy pasando por alto algo..

Agradesco quien me pueda ayudar...
---------------------------------------------------------------------------------------------------------------------------

// intpb.c

#include <16F84a.H>

unsigned int command;
#use delay(clock=4000000)


//#use fixed_io(A_OUTPUTS=PIN_A0,PIN_A1,PIN_A2,PIN_A3,PIN_A4)
//#use fixed_io(B_OUTPUTS=PIN_B3,PIN_B2)


#use rs232(baud=9600 ,xmit=PIN_B2,rcv=PIN_B1)

#use fast_io(B)


//#define alarm PIN_B0


unsigned int cmd,on;


#INT_RB
RB_isr()
{

printf("\n\rAlarma Activada RB4-RB7\n\r");

cmd=swap(INPUT_B() & 0x30); // carga en la variable cmd el valor del puerto


}



void send_ok(){
putc(7);
printf("\n\rComando %c Ok\n\r",command);
}
void print_help(){
fputs("Menu Telecontrol (? : Ayuda) ");
fputs("1:LED 1On/2:LED 1Off - 3:LED 2On/4:LED 2Off");
fputs("5:LED 3On/6:LED 3Off - 7:LED 4On/8:LED 4Off - 9:LED 5On/0:LED 5Off ");
fputs("A:Sensor1/B:Sensor2/C:Sensor3/D:Sensor4");
}

void service1(){
output_high(PIN_A0);//led 1
//send_ok();
}
void service2(){
output_low(PIN_A0);
//send_ok();
}
void service3(){
output_high(PIN_A1);//led 2
//send_ok();
}
void service4(){
output_low(PIN_A1);
//send_ok();
}
void service5(){
output_high(PIN_A2);;//led 3
//send_ok();
}
void service6(){
output_low(PIN_A2);
//send_ok();
}
void service7(){
output_high(PIN_A3);//led 4
//send_ok();
}
void service8(){
output_low(PIN_A3);
//send_ok();
}
void service9(){
output_high(PIN_B3);
//send_ok();
}
void service0(){
output_low(PIN_B3);
//send_ok();
}
void serviceA(){
printf("\n\rSensor 1 = %c\n\r",input(PIN_B4)+0x30);//sw1
//send_ok();
}
void serviceB(){
printf("\n\rSensor 2 = %c\n\r",input(PIN_B5)+0x30);//sw2
//send_ok();
}
void serviceC(){
printf("\n\rSensor 3 = %c\n\r",input(PIN_B6)+0x30);//sw3
//send_ok();
}
void serviceD(){
printf("\n\rSensor 4 = %c\n\r",input(PIN_B7)+0x30);//sw4
//send_ok();
}

main() {

setup_counters(RTCC_INTERNAL,RTCC_DIV_2);

//set_tris_b(0b11100100); //11110000 RB0-RB3 salidas, RB4-RB7 entradas. 1=entrada, 0=salida
// set_tris_b(0x0F);

//disable_interrupts(INT_RB);
// port_b_pullups(TRUE);
enable_interrupts(INT_RB); //Si habilito esta interrupcion salta el programa..no corre
enable_interrupts(GLOBAL);


//set_tris_b(0b11111000);// 0000111 entrada =0, salidas =1






while(1){
command = getc();
switch(command){
case '?': print_help();
break;
case '1': service1();
break;
case '2': service2();
break;
case '3': service3();
break;
case '4': service4();
break;
case '5': service5();
break;
case '6': service6();
break;
case '7': service7();
break;
case '8': service8();
break;
case '9': service9();
break;
case '0': service0();
break;
case 'A': serviceA();
break;
case 'B': serviceB();
break;
case 'C': serviceC();
break;
case 'D': serviceD();
break;
}
}
}