Ich entwickle eine Grundschaltung für ein Ballerspiel. Wenn ein Bereich des Ziels erreicht ist, muss der Mikrocontroller den aktuellen Wert zum erreichten Wert addieren.
Mein Problem ist, dass ich keine Interrupts auf Proteus zum Laufen bringen kann. (RB0 externer Interrupt)
Ich verwende den Hi-Tech-C-Compiler (kostenlose Version)
Was mache ich falsch?
/* 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];
}
Projekt (Proteus 8.5) und Compiler herunterladen: https://1drv.ms/f/s!AipcmZDTZPIPlOknaPJ06hKTQbzLiA
Beim Einschalten wird RB0 in den analogen Modus versetzt und alle digitalen Eingänge auf dem Pin werden deaktiviert. Um digitale E/A auf RB0-5 zu aktivieren, müssen Sie die entsprechenden Bits in löschen ANSELH
.
ANSELH = 0;
macht PORTB-Eingänge digital.
Da Sie RA0-6 als digitale Eingänge verwenden, sollten Sie auch löschen ANSEL
.
dannyf
dannyf
Italo Almeida
Ian Bland
Italo Almeida
Ian Bland