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 / Pic 16F877A MickroC

Pic 16F877A MickroC

|

Microcontroller › PIC › Pic 16F877A MickroC

  • This topic has 1 reply, 2 voices, and was last updated 8 years, 7 months ago by Hari Prasaath K.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • April 27, 2016 at 5:54 pm #4438
    Muhammad Muaaz Khan
    Participant

     I want to do that when i press switch PORTD.F3 it will go out while(2) loop and do the function which i declared in PORTD.F3

    void main()

    {
      TRISD.F0 = 1; //Configure 1st bit of PORTD as input
     TRISD.F1 = 1; //Configure 1st bit of PORTD as input
     TRISD.F2 = 1; //Configure 1st bit of PORTD as input
     TRISD.F3 = 1; //Configure 1st bit of PORTD as input
     TRISB.F0 = 0; //Makes PORTB0 or RB0 Output Pin
       TRISB.F1 = 0; //Makes PORTB1 or RB0 Output Pin
        TRISB.F2 = 0; //Makes PORTB0 or RB0 Output Pin
       TRISB.F3 = 0; //Makes PORTB1 or RB0 Output Pin
        TRISB.F4 = 0; //Makes PORTB0 or RB0 Output Pin
       TRISB.F5 = 0; //Makes PORTB1 or RB0 Output Pin
        TRISB.F6 = 0; //Makes PORTB0 or RB0 Output Pin
       TRISB.F7 = 0; //Makes PORTB1 or RB0 Output Pin
     
        while(1) //Infinite Loop
       {
        if(PORTD.F1 == 0)   //If the switch is pressed
        {
        PORTB.F0 = 1; //LED ON
        PORTB.F1 = 0; //LED OFF
        PORTB.F2 = 0; //LED OFF
        PORTB.F3 = 1; //LED OFF
        PORTB.F4 = 1; //LED ON
        PORTB.F5 = 0; //LED OFF
        PORTB.F6 = 0; //LED OFF
        PORTB.F7 = 1; //LED ON
        Delay_ms(2000); //1 Second Delay
        PORTB.F0 = 0; //LED OFF
        PORTB.F3 = 0; //LED OFF
        PORTB.F4 = 0; //LED OFF
        PORTB.F5 = 0; //LED OFF
        PORTB.F6 = 0; //LED OFF
        PORTB.F7 = 0; //LED OFF
        }
        if(PORTD.F0 == 0)   //If the switch is pressed
        {
        PORTB.F1 = 1; //LED ON
        PORTB.F0 = 0; //LED OFF
        PORTB.F2 = 1; //LED ON
        PORTB.F3 = 0; //LED OFF
        PORTB.F4 = 0; //LED OFF
        PORTB.F5 = 1; //LED ON
        PORTB.F6 = 1; //LED ON
        PORTB.F7 = 0; //LED OFF
        Delay_ms(2000); //1 Second Delay
        PORTB.F1 = 0; //LED OFF
        PORTB.F2 = 0; //LED OFF
        PORTB.F3 = 0; //LED OFF
        PORTB.F4 = 0; //LED OFF
        PORTB.F5 = 0; //LED OFF
        PORTB.F6 = 0; //LED OFF
        PORTB.F7 = 0; //LED OFF
     
        }
        if(PORTD.F3 == 0)   //If the switch is pressed
        {
        PORTB.F0 = 0; //LED OFF
        PORTB.F1 = 0; //LED OFF
        PORTB.F2 = 0; //LED OFF
        PORTB.F3 = 0; //LED OFF
        PORTB.F4 = 0; //LED OFF
        PORTB.F5 = 0; //LED OFF
        PORTB.F6 = 0; //LED OFF
        PORTB.F7 = 0; //LED OFF
        Delay_ms(5000); //1 Second Delay
        }
        if(PORTD.F2 == 0)   //If the switch is pressed
        if((PORTD.F3 == 0))break;   //If the switch is pressed
        {
        while(1) //Infinite Loop
      {
        PORTB.F0 = 0; //LED OFF
        PORTB.F1 = 1; //LED ON
        PORTB.F2 = 0; //LED OFF
        PORTB.F3 = 0; //LED OFF
        PORTB.F4 = 0; //LED OFF
        PORTB.F5 = 0; //LED OFF
        PORTB.F6 = 0; //LED OFF
        PORTB.F7 = 0; //LED ON
        Delay_ms(500); //1 Second Delay
        PORTB.F3 = 1; //LED ON
        PORTB.F0 = 0; //LED OFF
        PORTB.F1 = 1; //LED ON
        PORTB.F2 = 0; //LED OFF
        PORTB.F4 = 0; //LED OFF
        PORTB.F5 = 0; //LED OFF
        PORTB.F6 = 0; //LED OFF
        PORTB.F7 = 0; //LED OFF
        Delay_ms(1000); //1 Second Delay
        PORTB.F0 = 1; //LED ON
        PORTB.F1 = 0; //LED OFF
        PORTB.F2 = 1; //LED ON
        PORTB.F3 = 0; //LED OFF
        PORTB.F4 = 0; //LED OFF
        PORTB.F5 = 0; //LED OFF
        PORTB.F6 = 0; //LED OFF
        PORTB.F7 = 0; //LED OFF
        Delay_ms(100); //1 Second Delay   Both legs are off
        PORTB.F0 = 0; //LED OFF
        PORTB.F1 = 0; //LED OFF
        PORTB.F2 = 0; //LED OFF
        PORTB.F3 = 0; //LED OFF
        PORTB.F4 = 0; //LED OFF
        PORTB.F5 = 0; //LED OFF
        PORTB.F6 = 0; //LED OFF
        PORTB.F7 = 0; //LED OFf
        Delay_ms(500); //1 Second Delay   second leg Left leg
        PORTB.F0 = 0; //LED OFF
        PORTB.F1 = 0; //LED OFF
        PORTB.F2 = 0; //LED OFF
        PORTB.F3 = 0; //LED OFF
        PORTB.F4 = 0; //LED OFF
        PORTB.F5 = 1; //LED ON
        PORTB.F6 = 0; //LED OFF
        PORTB.F7 = 0; //LED OFF
        Delay_ms(500); //1 Second Delay
        PORTB.F0 = 0; //LED OFF
        PORTB.F1 = 0; //LED OFF
        PORTB.F2 = 0; //LED OFF
        PORTB.F3 = 0; //LED OFF
        PORTB.F4 = 0; //LED OFF
        PORTB.F5 = 1; //LED ON
        PORTB.F6 = 0; //LED OFF
        PORTB.F7 = 1; //LED ON
        Delay_ms(1000); //1 Second Delay
        PORTB.F0 = 0; //LED OFF
        PORTB.F1 = 0; //LED OFF
        PORTB.F2 = 0; //LED OFF
        PORTB.F3 = 0; //LED OFF
        PORTB.F4 = 1; //LED ON
        PORTB.F5 = 0; //LED OFF
        PORTB.F6 = 1; //LED ON
        PORTB.F7 = 0; //LED OFF
        Delay_ms(100); //1 Second Delay   Both legs are off
        PORTB.F0 = 0; //LED OFF
        PORTB.F1 = 0; //LED OFF
        PORTB.F2 = 0; //LED OFF
        PORTB.F3 = 0; //LED OFF
        PORTB.F4 = 0; //LED OFF
        PORTB.F5 = 0; //LED OFF
        PORTB.F6 = 0; //LED OFF
        PORTB.F7 = 0; //LED OFf
        Delay_ms(1000); //1 Second Delay
        }
        }
        }
       }
    March 30, 2017 at 12:36 pm #14537
    Hari Prasaath K
    Participant

    What is the problem you are facing and in which part.

  • 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

  • Need a fresh eye on my first PCB November 14, 2025
  • restarting this Christmas project November 14, 2025
  • desoldering November 13, 2025
  • Unknown, to me, electric motor fitting November 13, 2025
  • Can a small solar panel safely trickle-charge old NiMH AA batteries? November 13, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 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