EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / code not simulating

code not simulating

|

Microcontroller › PIC › code not simulating

  • This topic has 1 reply, 2 voices, and was last updated 8 years, 10 months ago by Hari Prasaath K.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • March 9, 2016 at 5:08 am #4359
    amarjeet yadav
    Participant

    guys, i have written a code a code for my project in MPLAB , the build is SUCCESSFUL , but the simulation is not working, the controller isnt reading the "if" condition. plz see if anyone can help me.  

    here is the code

     

    #include<p18f4520.h>
     
    #pragma config OSC=HS
    #pragma config PWRT=OFF
    #pragma config WDT=OFF
    #pragma config DEBUG=OFF, LVP=OFF 
     
    #define RF PORTBbits.RB0
    #define IR PORTBits.RB1
    #define light PORTBbits.RB2
    #define open PORTBbits.RB3
    #define close PORTBbits.RB4
     
    void msdelay(int time);
    void motor_forward();
    void motor_reverse();
    void motor_stop();
    void light_on();
    void light_off();
    void buzzer_on();
    void buzzer_off();
     
    void msdelay(int time)
    {
    int i,j;
    for(i=0;i<time;i++)
    for(j=0;j<135;j++);;
     
    }
     
    void motor_forward()
    {
    PORTCbits.RC0 = 1;
    PORTCbits.RC1 = 0;
    }
     
    void motor_reverse()
    {
    PORTCbits.RC0 = 0;
    PORTCbits.RC1 = 1;
    }
    void motor_stop()
    {
    PORTCbits.RC0 = 0;
    PORTCbits.RC1 = 0;
    }
    void light_on()
    {
    PORTCbits.RC3 = 1;
    }
    void light_off()
    {
    PORTCbits.RC3 = 0;
    }
    void buzzer_on()
    {
    PORTCbits.RC2 = 1;
    }
    void buzzer_off()
    {
    PORTCbits.RC2 = 0;
    }
     
    void main(void)
    {
    int flag = 0;
     
        TRISB = 0xFF;
    PORTB = 0xFF;
    TRISC = 0x00;
    PORTC = 0x00;
    ADCON1 = 0XFF;
     
    while(1)
    {
    if( PORTB == 0XFE ) // RF LINK
    { 
    if(flag == 0)
    {
    motor_forward();
    light_on();
    msdelay(1000);
    motor_stop();
    flag = 1;
    RF = 1;
    }
    else
    {
    motor_stop();
    }
    }
    else if(PORTB == 0XFD) // IR PAIR
    {
    buzzer_on();
    msdelay(100);
    buzzer_off();
    IR = 1;
    }
    else if(light == 0) // LIGHT SWITCH 
    { light_off();
    light = 1;
    }
    else if(open == 0) // OPENING SWITCH
    {
    motor_forward();
    msdelay(1000);
    motor_stop();
    open =1;
    }
    else if(close == 0) // CLOSING SWITCH
    {
    motor_reverse();
    msdelay(1000);
    motor_stop();
    close =1;
    }
    else
    {
    light_off();
    motor_stop();
    buzzer_off();
    }
    }
    }
     
    March 30, 2017 at 1:38 pm #14541
    Hari Prasaath K
    Participant

    Give a brief on your project about your idea. so any one can understand the flow and give you the solution.

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Do i need a buffer? February 7, 2026
  • FM Radio circuits February 7, 2026
  • wall transformer polarity February 7, 2026
  • To buy or DIY? February 7, 2026
  • engineering analysis of shmidth trigger without simulation February 6, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise