Learning Registers PIC18

General discussion on mikroC.
Post Reply
Author
Message
Miho
Posts: 17
Joined: 17 Jul 2014 11:29

Learning Registers PIC18

#1 Post by Miho » 16 Aug 2014 09:03

Hello every one.
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;
     }
}
And other question, what C compiler is better and easy with configuration of PIC.
I sorry about my English.

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Learning Registers PIC18

#2 Post by filip » 26 Aug 2014 12:48

Hi,

I believe I have answered you here :
http://www.mikroe.com/forum/viewtopic.php?f=13&t=61180

Regards,
Filip.

Post Reply

Return to “mikroC General”