Estoy desarrollando un circuito básico para un juego de disparos. Cuando se alcanza algún área del objetivo, el microcontrolador debe agregar el valor actual al valor alcanzado.
Mi problema es que no puedo hacer que ninguna interrupción funcione en Proteus. (Interrupción externa RB0)
Estoy usando el compilador Hi-tech C (versión gratuita)
¿Qué estoy haciendo mal?
/* Main.c file generated by New Project wizard
*
* Created: qua jul 12 2017
* Processor: PIC16F883
* Compiler: HI-TECH C for PIC10/12/16
*/
#include <htc.h>
//digits (0-9)
const unsigned char disp[] = {0b00111111,0b00000110,0b01011011,0b01001111,0b01100110,0b01101101,0b01111101,0b00000111,0b01111111,0b01101111 };
//enable specific display using array index
const unsigned char ob[] = {0b00010000,0b00000010,0b00000100,0b00001000};
void set_display(int val, int display);
int value = 0;
int total = 0;
void interrupt rb0(void){
if(INTF){
value = RA0 + (RA1 * 2) + (RA2 * 3) + (RA3 * 4) + (RA4 * 5) + (RA6 * 6);
total += value;
INTF = 0;
}
}
void main(void)
{
// Set RB0 as input
// Set RB1 - RB7 as output
TRISB = 0b00000001;
PORTB = 0xff;
// Set RC as output (default 0)
TRISC=0X00;
PORTC=0X00;
TRISB0 = 1;
GIE = 1;
PEIE = 1;
INTEDG = 1;
INTE = 1;
//Set internal oscilator to 8MHz
IRCF2 = 1;
IRCF1 = 1;
IRCF0 = 1;
while (1){
int a = total/100;
int b = (total/10)%10;
int c = total%10;
set_display(value,0);
__delay_ms(25);
set_display(a,1);
__delay_ms(25);
set_display(b,2);
__delay_ms(25);
set_display(c,3);
__delay_ms(25);
}
}
void set_display(int val, int display){
PORTC = disp[val];
PORTB = ob[display];
}
Descargar proyecto (Proteus 8.5) y compilador: https://1drv.ms/f/s!AipcmZDTZPIPlOknaPJ06hKTQbzLiA
En el encendido, RB0 se establece en modo analógico y todas las entradas digitales en el pin están deshabilitadas. Para habilitar la E/S digital en RB0-5, debe borrar los bits apropiados en ANSELH
.
ANSELH = 0;
hará que las entradas de PORTB sean digitales.
Dado que está utilizando RA0-6 como entradas digitales, también debe borrar ANSEL
.
dannyf
dannyf
Italo Almeida
ian soso
Italo Almeida
ian soso