Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] How can we change the state of 3 adjescent

Status
Not open for further replies.

varunme

Advanced Member level 3
Joined
Aug 10, 2011
Messages
741
Helped
17
Reputation
36
Reaction score
17
Trophy points
1,318
Activity points
5,764
How to change the state of 3 adjescent bit according to input

How can we change the state of 3 adjescent bits of a port according to the input from another port

eg :1

input port : Portc= 10010000
Outputport: Portd= 11111100


eg :2

input port : Portc= 10001000
Outputport: Portd= 11101110

the three bits including that is high from the input also on
 

hai... tell us which are the 3 bits you want to change.. and brief the examples
 

The bits to be changed is unknown,
its according to the input from sensors
which ever bit is high, then three bits including the one that is high also goes high
 

Do you have any reference byte to compare which bit is changed? If no, then we need some more information from you about the project.

Thanks
 

Actually its not just on and off , its based on PWM, if a sensor is intercepted, the next three leds go 100%, otherwise its 50% based on below diagram
 

Attachments

  • plan for the road pathway 3.jpg
    plan for the road pathway 3.jpg
    24.3 KB · Views: 168

The adjescent two lights are shorted, so they lights up when one bit of pic is high.
I modified the project to just next pair of lights( so i have to change only one bit), so that it can easily be handled

inputstate = portc;
shift_res = 1>>inputstate;
adj_lit_result= shift_res & inputstate; // so that we can get two adjescent bits high


am building a code, essence of my task is

I want to accomplish, if the one sensor is intercepted by something the corresponding light to sensor and the adjescent light have to go 100% intensity, when the next sensor is intercepted, the corresponding light and its adjescent light has to go 100% and goes on according to the attached image, if a next sensor is not intercepted then that light should hold 100% until a certain time is reached to shut off it.

This is a modification of
https://www.edaboard.com/threads/235975/#post1012917
 

dear varun,

The reference byte which i have asked is where the sensors are going to be, i mean which are the bits the sensor is going to affect. As per the diagram which you have posted, i get some idea as follows.

consider your sensor is going to be in 0,3,6 bits of a byte (because as u said, the adjuscent 2 bits should get turned 100% intensity if the sensor interrupted). Then your reference byte will be 10010010 (0x92).

So as a simplest method you can read the port which is connected with sensor and compare with 9 combinations in switch case and define the constant values to output port. When all are zero, you can write by default 0x92 to the output port. So that the LED/lamp will glow with 100% intensity only on 3 pins

---------- Post added at 10:41 ---------- Previous post was at 10:40 ----------

if you think the 9 combinations are quite tedious then follow the below method

read the sensor

consider:
result = 10000000

compare = result * 0xF0;

now the compare holds 0x80;

use switch case for 3 combination 0x80, 0x10, 0x90

if case 0x80 then define a constant with the adjuscent bits high for

output port

similarly you can do for the other combinations too.

compare = result * 0x0F;

now the compare holds 0x02;

use switch case for 1 combination 0x02

if case 0x02 then define a constant with the adjuscent bits high for

output port

---------- Post added at 10:44 ---------- Previous post was at 10:41 ----------

the only problem here is you should know which are the bits are correspond to the sensor..

Is it helpful? otherwise i need time to bring you another method
 
  • Like
Reactions: varunme

    varunme

    Points: 2
    Helpful Answer Positive Rating
all together 8 sensors are there, so can use PORTB full (so from 0 to 7) and
8 Lights will be connected to PORTD (0 to 7) ,
I have to interface,

RTC,
USART,
LCD, also

so RTC based on I2C and UART based bluetooth module must be connected to respective pins of PORTC,
and remaining PORTA for LCD and PORTE for LDR


The idea is to accomplish one light pair( the topic name was 3 adjescent, but now i changed to 1 for simplicity and need only one) of light ahead to be at 100% to get a vehicle in road to get complete view at night.
 

Varun.. if you connect 8 sensors in a port, then i think the problem is much more simpler than i expect...

As you said adjacent 2 lights are shorted. then please ignore the one from port which always glows with 100% intensity. Now your sensor is connected in all port pins 11111111 and connect your output port with one of the adjacent light. i mean, consider you have 12 lights, 1 is always glow and the adjacent (2,3) of 1 is connected with port pin^0. similarly 4th is always glow and the adjacent (5,6) of 4 is connected with port pin^1. Now the sensor which is correspond to the 1st light is interrupted then you should increase the intensity of 2,3 lights.

In this manner, connect 2nd sensor should correspond to 4th light. Now whenever you read the sensor just copy the value of that port to the output port

---------- Post added at 11:52 ---------- Previous post was at 11:45 ----------

As i sense, you are trying to do unidirectional arrangement. it will be better if you do bidirectional
 
  • Like
Reactions: varunme

    varunme

    Points: 2
    Helpful Answer Positive Rating
I will work on this and reply u

---------- Post added at 23:24 ---------- Previous post was at 23:23 ----------

[/COLOR]As i sense, you are trying to do unidirectional arrangement. it will be better if you do bidirectional
yes , i am using 4 sensors on oneside and 4 sensors on otherside, so its bidirectional isnt it ?
the two lights are shorted just for using the remaining uC pins for interfacing others

---------- Post added at 23:35 ---------- Previous post was at 23:24 ----------

I would like to use all lights for varying the intensity, then only our concept of 50% energy efficiency can be attained
 
Last edited:

yes it is bidirectional. But are you implementing 8 sensors to control only 12 lights? so expensive but you can reduce them using LDR
 

ohh yes, if I direct the LDR sensor to anyy direction isnt it ?
but can I get digital signals from LDRs ?
 

or the ADC from the LDR to directly control all the lights isnt it ?

---------- Post added at 23:47 ---------- Previous post was at 23:44 ----------

so expensive but you can reduce them using LDR
you referred the LDR only for cost reduction isnt it ?, i misread as it using as a direction sensor
 

yes i referred the LDR for cost reduction. By the way, you get analog voltage from LDR not digital. And what sensor you are using for the movement detection?

For intensity reduction, give me some time

Thanks
 

Just IR sensor for prototyping,
will consider other ones for actual implementation
 

varunme said:
eg :1

input port : Portc= 10010000
Outputport: Portd= 11111100


eg :2

input port : Portc= 10001000
Outputport: Portd= 11101110

Hi Varun,
I have a solution, but you have to confirm the scenario first.

eg :3
input port : Portc= 00000010
Outputport: Portd= ???

eg :4
input port : Portc= 00000001
Outputport: Portd= ???

Could you please fill the Outputport for above cases?

Alexandros
 

eg :1

input port : Portc= 10010000
Outputport: Portd= 11111100


eg :2

input port : Portc= 10001000
Outputport: Portd= 11101110


eg :3

input port : Portc= 00000010
Outputport: Portd= 00000011


eg :4

input port : Portc= 00000001
Outputport: Portd= 00000001


The condition of making three adjascent bits is not nessecary, making one adjescent bit high is also handy helping ( shorting two lights facilitates greater coverage of distance) ,
like

eg :1

input port : Portc= 10010000
Outputport: Portd= 11011000


eg :2

input port : Portc= 10001000
Outputport: Portd= 11001100


eg :3

input port : Portc= 00000010
Outputport: Portd= 00000011


eg :4

input port : Portc= 00000001
Outputport: Portd= 00000001

the real issue is that only one object is not activating the sensor , many can be there and is not predictable, because it has to be used in traffic.
 

varunme said:
making one adjescent bit high is also handy helping

Code:
unsigned char i;
volatile unsigned char port_C = PORTC;  //save PORTC
volatile unsigned char port_D = 0;  //init variable
  
for(i = 0; i < 8; i++)
{
  if (port_C&(1<<i))
  {
    port_D |= (1<<i);
    if (i)
      port_D |= (1<<(i-1));
  }
}

PORTD = port_D;  //update PORTD

PS: The if (i) line may not be necessary, but I don't want to guess what each compiler would do in this case, this is why I use this if.

EXAMPLE:

PORTC: 01001001
PORTD: 01101101

Hope this is what you are looking for.
Alexandros
 
  • Like
Reactions: varunme

    varunme

    Points: 2
    Helpful Answer Positive Rating
I will check it and reply you,
can we modify the code for PWM and holding 100% until adjescent sensor is activated ?
On compiling, gives

volatile unsigned char port_C = PORTC; //save PORTC
err: constant expression expected.

I am using mikroC
thanks
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top