225Views7Replies

Author Options:

How can I make my mikroc compiler codes (the ones involving inputs and interrupt) work on proteus or the hardware ? Answered

When try simulating my mikroc code on proteus and also when i programmed the hardware (PIC 18F14K22) with PICKIT3 i get the same result.
My program works as instructed when I do not involve inputs. For example

void main() {
TRISA = 0xFF; //PORT A as inputs
TRISB = 0x00; //set PORT B pins as output

while(1){

       PORTB= 0x00;
       Delay_ms(1000);
       PORTB = 0b11000000;     //PORT B HIGH
       Delay_ms(1000);
       PORTB = 0b11100000;
       Delay_ms(1000);
       PORTB = 0b11110000;
       Delay_ms(1000);
       PORTB = 0b00111111;   //PORT B LOW after 1sec
       Delay_ms(1000);
       PORTB = 0b00011111;
       Delay_ms(1000);
       PORTB = 0b00001111;
       Delay_ms(1000);



     }
}
This program works when i test it on the simulator or my 18F14K22.

But once i require a logic high to an input port for the mcu to carry out the operation, nothing happens. For example

void main() {
TRISA = 0xFF; //PORT A as inputs
TRISB = 0x00; //set PORT B pins as output

while(1){
       if(PORTA.f0==1){
       PORTB= 0x00;
       Delay_ms(1000);
       PORTB = 0b11000000;     //PORT B HIGH
       Delay_ms(1000);
       PORTB = 0b11100000;
       Delay_ms(1000);
       PORTB = 0b11110000;
       Delay_ms(1000);
       PORTB = 0b00111111;   //PORT B LOW after 1sec
       Delay_ms(1000);
       PORTB = 0b00011111;
       Delay_ms(1000);
       PORTB = 0b00001111;
       Delay_ms(1000);
       }


     }
}
 There is no response from the microcontroller when write this code on the MCU via  micrchip's PICKIT3 or on proteus.
Pls am i missing something in order for this to. Thank you.

Discussions

0
None
steveastrouk

3 years ago

How are you asserting the pins high and low ?

0
None
ikechukwu.dimobisteveastrouk

Answer 3 years ago

This is the simulation picture on peroteus. Please where could the problem be from. The code?, do i need to add something to the code?

Capture.JPG
0
None
steveastroukikechukwu.dimobi

Answer 3 years ago

Check the pin is actually being pulled low

Also, try the button function library in MikroC

if (Button(&PORTA, 0,1,1)) // If the button connected to RA0 is pressed

0
None
ikechukwu.dimobisteveastrouk

Answer 3 years ago

Thank you Steveastrouk. The problem has been solved. I simply set ANSEL = 0 and the program is working as required.