PIC 16F877A traffic system

Thread Starter

Aamil

Joined Jan 2, 2015
23
You are getting ahead of yourself. You need to find a transmitter module, then write the method of communicating with it. Have you found one?

I am of a different opinion from Ernie - I think interrupts should be used. At the very least, they allow your main code to scale while maintaining the functionality the interrupt handles. Since we don't know what the end goal looks like, I would go with interrupts, but that's me.

Either way, you'll need to pick your transmitter before you can write code for it.
I have found transmitter module as in link below

http://www.ebay.com/itm/IC2262-2272...ing-Receiver-Transmitter-Module-/131198056389
One of my friend also suggested to use interrupts to make the code simple. Let me work hard to find the best.. Your suggestions are always welcome

Specification:

Remote control
1.Operating voltage: DC12V (27A/12V battery x1)
2.Operating Current: 10mA @ 12V
3.Radiated power: 10mw @ 12V
4..Transmission distance :50-100M (Open field, the receiver sensitivity of -100dbm)
5.Transmitting frequency: 315MHZ
6.Modulation mode: ASK (Amplitude Modulation)
7.Encoder types: fixed code


With decoding receiver board
1.operating voltage DC5V
2.receiver sensitivity is-98db. Leg 7 bits, respectively, VT, D3, D2, D1, D0, the +5 V and GND.
3.VT is a valid signal high output pin Upon receiving a valid signal, the pin output high, may also drive the relay.
4.Size: 6.6*22*41mm


Note:
There are four buttons on the remote control, and respectively correspond to the four data bits to the receiving board output pin D0, D1, D2, and D3 of. Press the buttons transmit signals, the corresponding data bit is output high.
 

Thread Starter

Aamil

Joined Jan 2, 2015
23
I tried to control each step by giving 5V at port D.. But traffic automatically starts as if there is no control inputs..
I used port D pins for each line .. RD0 -RD1-RD2-RD3 for step 1, step 2, step 3 , step4 respectively..
But these port levels does not have any effect on the traffic system..

if(RD2==1)

{
//Step 3: Red-Red-Green-Red
RA0=1; //Red ON
RA1=0; //Green
RA2=1; //Red ON
RA3=0; //Green
RB1=0; //Red
RB2=1; //Green ON
RB4=1; //Red ON
RB5=0; //Green
}
__delay_ms(5000);
CLRWDT();


if(RD3==1)
{
//Step 4:Red-Red-Red-Green
RA0=1; //Red ON
RA1=0; //Green
RA2=1; //Red
RA3=0; //Green ON
RB1=1; //Red
RB2=0; //Green
RB4=0; //Red ON
RB5=1; //Green

__delay_ms(5000);
CLRWDT();

}
 
Last edited:

ErnieM

Joined Apr 24, 2011
8,415
Does the transmitter actually drive the inputs as you expect?

Where is the initial value when the program starts?

Where is the state when NO inputs are present?
 

tshuck

Joined Oct 18, 2012
3,534
I tried to control each step by giving 5V at port D.. But traffic automatically starts as if there is no control inputs..
I used port D pins for each line .. RD0 -RD1-RD2-RD3 for step 1, step 2, step 3 , step4 respectively..
But these port levels does not have any effect on the traffic system..

Please see the code I am using.. Whats wrong in this
[...]
if(RD2==1)

{
//Step 3: Red-Red-Green-Red
RA0=1; //Red ON
RA1=0; //Green
RA2=1; //Red ON
RA3=0; //Green
RB1=0; //Red
RB2=1; //Green ON
RB4=1; //Red ON
RB5=0; //Green
}
__delay_ms(5000); //should this really be outside your 'if' statement?
CLRWDT();
It takes 5 seconds to get around your loop, are you holding the button for that long?

Were you to use interrupt, you could sense a change, note the input sequence, and save that for the main loop to handle, that way, you won't miss the button press in your 5 second long loop.
 

ErnieM

Joined Apr 24, 2011
8,415
It seems the button is supposed to be missed (or ignored) for the first 5 seconds. As we don't have a spec to check that's an open item for the TS to explain.

But we're still not doing anything requiring an interrupt.
 

Thread Starter

Aamil

Joined Jan 2, 2015
23
It seems the button is supposed to be missed (or ignored) for the first 5 seconds. As we don't have a spec to check that's an open item for the TS to explain.

But we're still not doing anything requiring an interrupt.
You guys are right...I made a stupid mistake of putting the delay outside the loop.. I kept it inside.. and I can turn each lane green by connecting 5V to port D pins..
 
Last edited:

ErnieM

Joined Apr 24, 2011
8,415
Now only automatic system works irrespective of port D inputs.. What is wrong I am doing?
I have no idea what is wrong since I have no idea what constitutes "right'.

Before any software or hardware is built a specification should be written. It is a document that answers all questions someone looking at your system could have.

Obviously when you are just working by yourself this can just be some mental notes but when you start asking other people for assistance they need to know what you are doing.

An "automatic system" has very little meaning. Terms such as "works" or "doesn't work" are just terrible. What works? what doesn't work? What constitutes working?

So far you show us some code and expect us to know what you want it to do. Now is the time for you to tell us what you want this to do.
 

tshuck

Joined Oct 18, 2012
3,534
It seems the button is supposed to be missed (or ignored) for the first 5 seconds. As we don't have a spec to check that's an open item for the TS to explain.

But we're still not doing anything requiring an interrupt.
No, nothing requiring an interrrupt, but using interrupts could have allowed the OP to see the changes occurring after the 5 seconds, alerting him/her to the fact that there is an extra delay somewhere.

Just because something does not require the speed of interrupts, it does not mean they would not prove a benefit now, or in future revisions and code changes. If the OP decided later to use interrupts to deal with the completed system, the code would have to be reworked.

Of course, this would have been readily apparent had we had a specification.
 

Thread Starter

Aamil

Joined Jan 2, 2015
23
The Specification is simple.. This is an Intelligent ambulance system with remote control

There are three things in project...
  • ambulance,
  • traffic system
  • hospital

The project has
  1. 4-way Traffic system using PIC (each lane gets 10 Second green then 30 second red)
  2. Ambulance driver wireless controls the traffic system using RF remote
  3. Ambulance has patient data monitoring system (PMS) - using PIC16F877A, sensors and LCD display
  4. Patient data is sent to Hospital via GSM messages (I am interfacing GSM module with PIC)
Remote has 4 buttons which can be used to make a particular lane/way green. When an ambulance comes to the traffic, the driver will press the remote button so that he can pass through the traffic without any delay.

So what I have done,
  • I made a traffic system which automatically changes the green /red lights (Yellow is ignored for making project simple) -----------------working fine
  • I interfaced a 4 button remote with the traffic system so that Ambulance driver can make his way green (to avoid waiting in traffic)----working fine now
  • I am yet to complete GSM-PIC interfacing .... Work in progress
Let me know if you have any questions
 
Last edited:
Top