AV314 Lab-5
AV314 Lab-5
Time Diagram
Time (s) Red Light (PORTC.F1) Yellow Light (PORTC.F2) Green Light (PORTC.F4) Display (7-Segment)
Simulation in Proteus
• Open Proteus and start the simulation.
• Press the button connected to PORTC.F0 to start the traffic light sequence.
• Observe the LEDs lighting up in the sequence: Red for 10 counts, Yellow for 2 counts, Green for
15 counts.
• Verify the countdown on the seven-segment displays corresponding to each light sequence:
o Red counts down from 10 to 1.
o Yellow counts down from 2 to 1.
o Green counts down from 15 to 1.
• Ensure the timing and transitions are correct as per the code.
Key Characteristics of Common Cathode vs. Common Anode
Feature Common Cathode Common Anode
How Segments Turn ON Apply 0 (low) to the anode pin Apply 1 (high) to the cathode pin
Code Behavior 0 in PORTD lights the segment 1 in PORTD lights the segment
unsigned short mask(unsigned short num) { The mask function
switch (num) { converts the digit
case 0: return 0xC0; // 11000000: Segments a, b, c, d,
e, f to its
case 1: return 0xF9; // 11111001: Segments b, c corresponding
case 2: return 0xA4; // 10100100: Segments a, b, g, e, d seven-segment
case 3: return 0xB0; // 10110000: Segments a, b, g, c, d
case 4: return 0x99; // 10011001: Segments f, g, b, c encoding
case 5: return 0x92; // 10010010: Segments a, f, g, c, d
case 6: return 0x82; // 10000010: Segments a, f, g, e,
d, c
case 7: return 0xF8; // 11111000: Segments a, b, c
case 8: return 0x80; // 10000000: All segments ON
case 9: return 0x90; // 10010000: Segments a, b, g, c, f
default: return 0xFF; // All segments OFF
}
}
void Red() {
PORTC.F1 = 1; PORTC.F2 = 0; PORTC.F4 = 0; // Turn on Red
light Traffic Light LED
display_countdown(10); // Countdown for 10 seconds
Control
}
void Yellow() {
PORTC.F1 = 0; PORTC.F2 = 1; PORTC.F4 = 0; // Turn on Yellow
light
display_countdown(5); // Countdown for 5 seconds
}
void Green() {
PORTC.F1 = 0; PORTC.F2 = 0; PORTC.F4 = 1; // Turn on Green
light
display_countdown(10); // Countdown for 10 seconds
}
void main() {
// Initialize ports
TRISC.F1 = 0; // Configure PORTC.F1 (Red LED) as output Initial Configuration
TRISC.F2 = 0; // Configure PORTC.F2 (Yellow LED) as output
TRISC.F4 = 0; // Configure PORTC.F4 (Green LED) as output
TRISD = 0x00; // Configure PORTD (7-segment display) as
output
TRISE = 0x00; // Configure PORTE (digit control) as output
TRISC.F0 = 1; // Configure PORTC.F0 (button input) as input
// Clear ports
PORTC = 0x00; // Turn off all LEDs
PORTD = 0x00; // Clear 7-segment display
PORTE = 0x00; // Disable both digits
while (1) {
if (PORTC.F0 == 1) { // Button pressed If Enable button is
Red(); pressed Control LED
Yellow(); on off
Green();
} else { // Button not pressed
PORTC = 0x00; // Turn off all LEDs
PORTD = 0x00; // Clear 7-segment display
}
}
}
Lab Tasks
1. Implement above code in Proteus, write pseudo code and explain working.
2. Develop a code for three traffic signals working on above principle (two traffic lights, 4 seven
segment display, 4 enable pins)