Question

ARM assembly lang please write code Street Crossing - This consists of a street light (red,yellow,green...

ARM assembly lang please write code
Street Crossing - This consists of a street light (red,yellow,green row of LEDs), and a separate red and green led (walk/dont walk) and a button. When the button is pressed, the red lights light up and the green indicator for walk lights up. Eventually the green and yellow will flash saying time to walk is over, then the red for dont walk lights up, and green for traffic lights up.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

// Traffic light w/ pedestrian button....
// (c)2013 IronCreek Software


#include <avr/io.h>
#include <avr/interrupt.h>

// (LED registers)
// NOTE: All LEDs must be hooked up on the same PORT


#define LED_PORT PORTB
#define LED_DDR DDRB
#define LED_MASK 0x1F

// LED pins
#define PED_GO 0x01
#define PED_STOP 0x02
#define GREEN 0x04
#define YELLOW 0x08
#define RED 0x10

// Pedestrian button PORT & PIN
#define BTN_PIN PIND
#define BTN_PORT PORTD
#define BTN_DDR DDRD
#define BTN 0x80

namespace
{
// Index into LED_STATES for code clarity below
#define STOP 3
#define CROSS 4
#define END_CYCLE 4
#define END_CROSS 7

// Delays are in 16.384ms units (1 = 16.384ms)
// First column has delays, second column has LED bits
const uint8_t LED_STATES[][2] = {
// Normal cycle
{ 25, PED_STOP | RED | YELLOW },
{ 200, PED_STOP | GREEN },
{ 50, PED_STOP | YELLOW },
{ 200, PED_STOP | RED, },

// Pedestrian cycle
{ 25, PED_STOP | RED },
{ 150, PED_GO | RED },
{ 25, PED_STOP | RED },
};

// Helper variables for timer
volatile uint8_t timer = 0;
volatile uint8_t change_state = 0;

ISR(TIMER0_OVF_vect)
{
if (change_state == 0 && --timer == 0)
change_state = 1;
}

void setLights(const uint8_t state)
{
LED_PORT = LED_STATES[state][1];
timer = LED_STATES[state][0];
}
}

__attribute__((OS_main)) int main()
{
uint8_t state = STOP;
uint8_t ped_request = 0;

// Setup ports
LED_DDR |= LED_MASK;
BTN_PORT |= BTN; // Enable pull-up

setLights(state);

// Start timer
TIMSK0 |= (1 << TOIE0);
TCCR0B |= (1 << CS02) | (1 << CS00);

sei();

// Main loop
for(;;)
{
if (change_state)
{
++state;

if (state == END_CYCLE || state == END_CROSS)
state = 0;

if (state == STOP && ped_request)
{
state = CROSS;
ped_request = 0;
}

setLights(state);
change_state = 0;
}

// Check pedestrian crossing button
if ((BTN_PIN & BTN) == 0 && state < CROSS)
ped_request = 1;
}
}

Add a comment
Know the answer?
Add Answer to:
ARM assembly lang please write code Street Crossing - This consists of a street light (red,yellow,green...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • write code in ARM assembly lang Ladder Game - This game involves a setup of LEDs...

    write code in ARM assembly lang Ladder Game - This game involves a setup of LEDs in a row and a button. The goal is to get from the bottom led all the way to the top without them resetting. The LEDs will flash and you can only move up one led at a time, when the led is lit up, or else you get reset to the bottom.

  • Hi, Please can anyone help me to solve this question in ARM assembly language ASAP?? Thank...

    Hi, Please can anyone help me to solve this question in ARM assembly language ASAP?? Thank you, Task 4 On the Cornish, there is a pedestrian traffic light with a push button. Under normal condition, the green light is on for the cars to go, and the pedestrian light is red. When a pedestrian wants to cross, he/she presses on the push button and the red light turns on for the cars and green for pedestrian. Design this traffic light...

  • Can someone please show me a circuit diagram so i can see how to construct this...

    Can someone please show me a circuit diagram so i can see how to construct this on a bread board i am id 6 yhanks in advance EEET-2251: Course & Projoct Guide 2018 EEET-2251: Cousc &Projoct Guide 2018 affic Light Controller A single switch must set your HC74 based state machine to the initial state (the U state This lab will get you to design a simple controller for a pedestrian crossing based on synchronous digital logic. You will master...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT