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 / Please modify given code for pic16f877a

Please modify given code for pic16f877a

|

Microcontroller › PIC › Please modify given code for pic16f877a

  • This topic has 1 reply, 2 voices, and was last updated 8 years, 1 month ago by Ashutosh Bhatt.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • April 27, 2017 at 3:22 am #4648
    Vinod kumar Warudkar
    Participant

    I am Begener , so please help me given code is for PIC16f877a, its working as motion sensor, including 8 ir sensors,

    & 14 indicator, I want to keep there only 8 indicator,

    what i want that is whenever 1 sensor blocked then 1 indicator should be glow on , if 2 nd & four sensors are blocked then 2nd & 4th indicator should be glow on others sholud be off.

    code is

    #include<16F877A.h>
    #include<string.h>
    #use delay(clock4000000)

    #byte portb  =  6
    #byte leds1  =  7
    #byte leds2  =  8

    void main()
    {
    set_tris_b(0xff);            //set port b as input port
    set_tris_c(0x00);            //set port c as output port
    set_tris_d(0x00);            //set port d as output port
    set_tris_e(0x00);            //set port e as output port
    portb=0Xff;            //make all port b pins are high
    leds1-0X00;            //switch off all leds
    leds2=0X00;inputs(pin_c7)
    output_high(pin_E0);        //set pin_E0 high
    while(true)
    {
    while(input(pin_E0))
    {
    if(input(pin_B0))        //if 1st sensor blocked
    {
    leds1=0x7f;    //switch on 7 leds
    leds2=0x00;    //switch off remaining leds
    }
    if(input(pin_B1))        //if 2nd sensor blocked
    {
    leds1=0xfE;    //switch on 7 leds
    leds2=0x00;    //switch off remaining leds
    }
    if(input(pin_B2))        //if 3rd sensor blocked
    {
    leds1=0xfc;    //switch on 7 leds
    leds2=0x01;    //switch off remaining leds
    }
    if(input(pin_B3))        //if 4th sensor blocked
    {
    leds1=0xf8;    //switch on 7 leds
    leds2=0x03;    //switch off remaining leds
    }
    if(input(pin_B4))        //if 5th sensor blocked
    {
    leds1=0xf08;    //switch on 7 leds
    leds2=0x07;    //switch off remaining leds
    }
    if(input(pin_B5))        //if 6th sensor blocked
    {
    leds1=0xE0;    //switch on 7 leds
    leds2=0x0f;    //switch off remaining leds
    }
    if(input(pin_B6))        //if 7th sensor blocked
    {
    leds1=0xC0;    //switch on 7 leds
    leds2=0x1f;    //switch off remaining leds
    }
    if(input(pin_B7))        //if 8th sensor blocked
    {
    leds1=0x80;    //switch on 7 leds
    leds2=0x3f;    //switch off remaining leds
    }
    if(portb=0x00)
    {
    leds1=0x00;    //switch off leds
    leds2=0x00;
    }
    }
    while(!input(pin_E0))
    {
    if(input(pin_B0))        //if 1st sensor blocked
    {
    leds1=0xff;    //switch on all leds
    leds2=0xff;
    delay_ms(1);    //delay for 1msec
    leds1=0x7f;    //switch on 7 leds and switch off remaining leds
    leds2=0x00;
    delay_ms(10);    //delay for 10msec
    }

    if(input(pin_B1))        //if 2nd sensor blocked
    {
    leds1=0xff;    //switch on all leds
    leds2=0xff;
    delay_ms(1);    //delay for 1msec
    leds1=0xfE;    //switch on 7 leds and switch off remaining leds
    leds2=0x00;
    delay_ms(10);    //delay for 10msec
    }

    if(input(pin_B2))        //if 3rd sensor blocked
    {
    leds1=0xff;    //switch on all leds
    leds2=0xff;
    delay_ms(1);    //delay for 1msec
    leds1=0xfC;    //switch on 7 leds and switch off remaining leds
    leds2=0x01;
    delay_ms(10);    //delay for 10msec
    }
    if(input(pin_B3))        //if 4th sensor blocked
    {
    leds1=0xff;    //switch on all leds
    leds2=0xff;
    delay_ms(1);    //delay for 1msec
    leds1=0xf8;    //switch on 7 leds and switch off remaining leds
    leds2=0x03;
    delay_ms(10);    //delay for 10msec
    }
    if(input(pin_B4))        //if 5th sensor blocked
    {
    leds1=0xff;    //switch on all leds
    leds2=0xff;
    delay_ms(1);    //delay for 1msec
    leds1=0xf0;    //switch on 7 leds and switch off remaining leds
    leds2=0x07;
    delay_ms(10);    //delay for 10msec
    }
    if(input(pin_B5))        //if 6th sensor blocked
    {
    leds1=0xff;    //switch on all leds
    leds2=0xff;
    delay_ms(1);    //delay for 1msec
    leds1=0xE0;    //switch on 7 leds and switch off remaining leds
    leds2=0x0f;
    delay_ms(10);    //delay for 10msec
    }
    if(input(pin_B6))        //if 7th sensor blocked
    {
    leds1=0xff;    //switch on all leds
    leds2=0xff;
    delay_ms(1);    //delay for 1msec
    leds1=0xC0;    //switch on 7 leds and switch off remaining leds
    leds2=0x1f;
    delay_ms(10);    //delay for 10msec
    }
    if(input(pin_B7))        //if 8th sensor blocked
    {
    leds1=0xff;    //switch on all leds
    leds2=0xff;
    delay_ms(1);    //delay for 1msec
    leds1=0x80;    //switch on 7 leds and switch off remaining leds
    leds2=0x3f;
    delay_ms(10);    //delay for 10msec
    }
    if(portb==0x00)
    {
    leds1=0xff;    //switch on all leds
    leds2=0xff;
    delay_ms(1);    //delay for 1msec
    leds1=0x00;
    leds2=0x00;    //switch of all leds
    delay_ms(10);    //delay for 10msec
    }
    }
    }
    }

    May 2, 2017 at 11:46 am #14587
    Ashutosh Bhatt
    Participant

    why to write such a lengthy code?

    just get the input from sensor from 1 port

    and give same output to indicators on another port

    thats it……………..

  • 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

  • using a RTC in SF basic June 21, 2025
  • Can I make two inputs from one?? June 21, 2025
  • Help with finding unique wire lug(s) June 21, 2025
  • Simple LED Analog Clock Idea June 21, 2025
  • Kawai KDP 80 Electronic Piano Dead June 21, 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