Microcontroller › PIC › Please modify given code for pic16f877a
- This topic has 1 reply, 2 voices, and was last updated 7 years, 5 months ago by Ashutosh Bhatt.
-
AuthorPosts
-
April 27, 2017 at 3:22 am #4648Vinod kumar WarudkarParticipant
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 = 8void 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 #14587Ashutosh BhattParticipantwhy 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……………..
-
AuthorPosts
- You must be logged in to reply to this topic.