I would like learn registers of PIC18 (using 18f4550 for training), but I have problem with configuration of PIC's, I can't understand how configure some of registers.
For example, I have written program with using interrupt on PORTB.RB1, when I press a button it changes state of PORTD, but it does not work, PORTD on proteus doesn't change state.
I use MikroC and Proteus 8.1.
Code: Select all
short int temp;
bit indicator;
void interrupt()
{
if (INTCON.RBIF == 1)
{
indicator = 1; // increment counter or variable
temp = LATB; // read PORTB
INTCON.RBIF = 0; // clear flag RBIF
}
}
void main()
{
temp = 0;
indicator = 0;
// OSCCON: OSCILLATOR CONTROL REGISTER pg.35
OSCCON = 0b01110010;
// RCON: RESET CONTROL REGISTER (pg.48) and (pg.112)
RCON.IPEN = 1; // Interrupt Priority Enable bit, 1 = Enable priority levels on interrupts
RCON.SBOREN = 0; // 0 = ne robutu reset pru znujenni pitania MK
// INTCON: INTERRUPT CONTROL REGISTER (pg.103)
INTCON = 0b10001000;
// INTCON2: INTERRUPT CONTROL REGISTER 2 (pg.104)
INTCON2 = 0b01110001;
// INTCON3: INTERRUPT CONTROL REGISTER 3 (pg.105)
INTCON3 = 0b00000000;
// ADCON0: A/D CONTROL REGISTER 0 (pg.267)
ADCON0 = 0b00000000;
// ADCON1: A/D CONTROL REGISTER 1 (pg.268)
ADCON1 = 0b00001111;
// REGISTER 22-1: CMCON: COMPARATOR CONTROL REGISTER (pg.277)
CMCON=0b00000111;
TRISB.RB1 = 1; // PORTB pin 7 input
TRISD = 0;
PORTB = 0;
PORTD = 0;
PORTE.RDPU = 1;
if(indicator == 1)
{
PORTD = ~PORTD;
indicator = 0;
}
}
I sorry about my English.