Advertisement

PIC Traffic Lights

Not rated 27,290

#PIC #traffic lights #LED #PICBASIC #programming #microcontroller #compiler #HEX file #parallel port #serial port
PIC Traffic Lights
PIC Traffic Lights

Description: All that remains now is for the code to be compiled and converted to a HEX file that the PIC can understand. This is achieved easily with the PIC compiler that comes with the PICBASIC package. The PIC is programmed with any of the parallel or serial port programmers that are available free of charge from the internet. If the LEDs are arranged as per the diagram of the prototype box, FIG 1, the LEDs on the left of the PIC will be referred to as LEDs A, and those on the right as LEDs B. Number them, starting from the top of LED A, with the RED LED being number 0, the next one down being AMBER and numbered 1, and the bottom one being GREEN, numbered 2. The right-hand side LEDs, starting from the top, are numbered 4 for the top RED LED, with number 5 allocated for the middle AMBER LED, and the bottom GREEN LED is numbered 6. The loop is the start of this program and is appropriately named loop, as that is what the program does; it continuously loops until switched off. It must be followed by a colon. HighO places a logic high on portB pin 0, consequently lighting LED 0. The colon separates the first statement (high 0) from the next one on the same line. If the next statement (high 6) were placed on the next line, there would be no need for the colon; it simply saves space. Pause1000 is an instruction to tell the PIC to delay for 1 second. The actual time will depend on the clock frequency of the PIC. As a rule of thumb, 1000 can be regarded as 1 second and 5000 as 5 seconds. The portB pins are placed in a register called b1. This could have been named b0, b2, b3, etc. There are, of course, only so many of these registers in each PIC. Low b1 instructs that everything in register b1 goes to logic 0. In this case, all the pins in portB, 0 to 7, are set low in sequence from pin 0 to pin 7. Hence the reason for the next b1. If a command such as `for b1 = 0 to 3: next b1` were used, it would only place the portB pins 0, 1, 2, and 3 to a logic low. The first line of the main listing (high 0: high 6: pause 5000) turns on RED LED A and GREEN LED B, which then stay on for about 5 seconds before proceeding to the next stage. RED A stays on, AMBER is off, AMBER B is on, and both GREEN A and GREEN B are off, and this sequence continues. The 0.5-second pause at the end of the sequence is there to avoid errors at the return of the sequence. Fig. 2 shows the complete two-traffic lights circuit. It is simple. It will be evident from Fig. 2 that the circuit is not overly complex. Series resistors of approximately 100 ohms should be placed between the ports and the LEDs to limit the current. Programming the PIC is straightforward, but the necessary software is required. PICBASIC is available from MAPLINS, and the programmer software and circuit diagrams can be obtained free of charge from the internet. It is possible to know someone who already possesses both types of software. The PICBASIC available for free on the internet is a competent compiler, but it is somewhat more complex as it requires additional information to be typed in along with the program listing. It is less user-friendly compared to the PICBASIC programmer produced by Micro Engineering Labs Inc. No response was received from the PICBASIC community when assistance was requested. If programming capabilities are unavailable or if a working set of traffic lights is desired (with the ability to remotely operate the LEDs), a pre-programmed PIC can be supplied. A PCB and an 18-pin holder for the PIC can also be produced. Interested parties can receive the HEX code upon providing a floppy disk and return postage. The pre-programmed PICs could be supplied at a cost of £5, including postage and packaging. The PCB and IC holder could also be provided for £5, including postage and packaging. The compiler then converts this assembly language into hexadecimal code. This conversion is not shown, as it appears as a block of letters and numbers, making it unrecognizable. The list of components includes: R1 4.7K Resistor, R2 R3 R4 470R, 4 MHz crystal, C1 C2 22pF capacitor, C3 0.1µF, LED1 Green LED, LED2 Orange LED, LED3 Red LED, IC1 PIC 16C84, PCB Pins.

The described circuit represents a simple traffic light control system utilizing a PIC microcontroller, specifically the PIC 16C84. The programming of the PIC is carried out using the PICBASIC language, which allows for straightforward manipulation of the microcontroller's GPIO (General Purpose Input/Output) pins to control the state of the LEDs.

In the schematic, the microcontroller is connected to three LEDs on the left side (LEDs A) and three more on the right side (LEDs B). The LEDs are arranged in a sequence that represents a typical traffic light: RED, AMBER, and GREEN. Each LED is connected to a corresponding pin on portB of the PIC, with current-limiting resistors included to protect the LEDs from excessive current, which can lead to premature failure.

The program begins execution in a loop, continuously cycling through the states of the LEDs. The use of the `high` and `low` commands allows the program to turn specific LEDs on and off, while the `pause` command introduces delays to create a realistic traffic light sequence. The timing of these delays can be adjusted based on the desired traffic light operation.

The circuit design should also consider the power supply requirements for the PIC and the LEDs, ensuring that the voltage levels are compatible with the components used. The inclusion of bypass capacitors near the power pins of the PIC is advisable to stabilize the supply voltage and reduce noise.

In summary, the traffic light control circuit is a practical application of microcontroller technology that demonstrates fundamental concepts of digital electronics, programming, and circuit design. The simplicity of the design, combined with the flexibility offered by the PIC microcontroller, makes it an excellent project for those interested in learning about embedded systems.All that remains now is for the code to be `, compiled and converted to a HEX file that the PIC can understand. This is achieved easily with the PIC compiler that comes with the PICBASIC package. The PIC is programmed with any of the parallel or serial port programmers that are available free of charge from the NET.

If you arrange the LEDs as the diagram of my prototype box, FIG 1, then the LEDs at the left of the PIC we will call LEDs A and to the right of the PIC LEDs B. Number them, starting at the top of LED A the RED LED number 0. The next one down is AMBER and is number 1. The bottom one GREEN is numbered 2. The right hand side LEDs starting from the top is numbered 4 for the top RED LED with number 5 being allocated for the middle, AMBER LED.

The bottom, GREEN LED is number 6. Loop: Is the start of this programme. It is suitably called loop, as that is what the programme does. It loops continuously until it is switched off. It must be followed by the colon. HighO: Places a logicl on portB pinO consequently lighting LED 0. The colon is there to separate the first statement (high 0) from the next one in the same line. If the next statement (high 6) was placed on the next line down there would be no need for the colon. It just saves space. Pause1000 Is an instruction to tell the PIC to delay for 1 second. The actual time will depend on the clock frequency of the PIC. As a rule of thumb 1000 can be regarded as 1 second and 5000 as 5 seconds. The portB pins are placed in a register called bl. This could have been called b0, b2, b3 etc. there are, of course, only so many of these registers in each PIC. Lowbl instructs that everything in register b 1 goes to logic 0. In our case all the pins in portB, 0 to 7 are taken low. It does this in sequence from pin 0 to pin 7. Hence the reason for next bL If we had put `for b1= 0 to 3:next bl` then it would only place the portB pins 0, 1, 2 and 3 to a logic low.

The first line of the `main` listing (high O:high6:pause5000) is placing RED LED A on and GREEN LED B on. It then stays on for about 5 seconds and then goes to the next stage. The RED A stays on AMBER is off AMBER B is on and GREEN A and GREEN ` B is off and so the sequence continues.

The ` 0. 5-second pause on the last line is there to avoid errors at the return of the sequence. Fig. 2. The complete two-traffic lights circuit. Simple isn`t it! It will be obvious by looking at Fig. 2 that there is not much to the circuit. Perhaps series resistors of about 100 0 should be placed in between the ports and the LEDs to limit the current. The programming of the PIC is very simple but you will need the necessary software. PICBASIC is available from MAPLINS and the programmer software and circuit diagrams are available free of charge off the NET.

You may know someone who already has both of these types of software. The PICBASIC available free on the NET is probably a good compiler, but is a bit more involved in that you have to type in some other information as well as your programme listing. It is not as `user friendly` as the PICBASIC programmer produced by Micro Engineering Labs Inc. I had no reply either from the NET PICBASIC people when I asked for some advice. If you do not have any means of programming or you prefer not to anyway, but would like a working set of traffic lights (you can remotely operate the LEDs) then I can supply you with a pre-programmed PIC.

I can also produce a PCB and an 18-pin holder for the PIC. If anyone is interested I can just send the HEX code on receipt of a floppy disc and the return postage. The preprogrammed PICs I could supply at say £5 including P and P. the PCB and IC holder I could also send for £5 including P and P. The compiler then goes on to change rgis assembly language into hexadecimal code. I have not shown this as it appears as a block of letters and numbers and you cannot recognise any of the stages in it.

List of components:- R1 4. K Resistor. 1 R2 R3 R4 470R. 2 # 4Mhz crystal. 1 C1 C2 22pf capacitor. 2 C3 0. 1 Mf. 1 LED1 Green LED. 1 LED2 Orange LED. 1 LED3 Red LED. 1 IC1 PIC 16C84. 1 PCB Pins. 2

Related Circuits