Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

need to help to write a code for Car door signal program You will write assembly

ID: 3793363 • Letter: N

Question

need to help to write a code for Car door signal program

You will write assembly code that inputs from PF0, PF4 and outputs to PF1 and PF3. The address definitions for Port F are available in lm4f120.s or tm4c123gh6pm.s file (listed below) and already placed in your starter file main.s:
GPIO_PORTF_DATA_R EQU 0x400253FC

GPIO_PORTF_DIR_R   EQU 0x40025400

GPIO_PORTF_AFSEL_R EQU 0x40025420

GPIO_PORTF_PUR_R   EQU 0x40025510

GPIO_PORTF_DEN_R   EQU 0x4002551C

GPIO_PORTF_LOCK_R EQU 0x40025520

GPIO_PORTF_CR_R       EQU 0x40025524

GPIO_PORTF_AMSEL_R EQU 0x40025528

GPIO_PORTF_PCTL_R EQU 0x4002552C

GPIO_LOCK_KEY        EQU 0x4C4F434B ; Unlocks the GPIO_CR register

SYSCTL_RCGCGPIO_R EQU   0x400FE608

The opening comments include: file name, overall objectives, hardware connections, specific functions, author name, TA, and date. The equ pseudo-op is used to define port addresses. Global variables are declared in RAM, and the main program is placed in EEPROM. The 32-bit contents at ROM address 0x00000004 define where the computer will begin execution after a power is turned on or after the reset button is pressed.

;****************** main.s ***************

; Program written by: Your Name

; Date Created: 1/15/2017

; Last Modified: 1/15/2017

; Brief description of the program

; The objective of this system is to implement a Car door signal system

; Hardware connections: Inputs are negative logic; output is positive logic

; PF0 is right-door input sensor (1 means door is open, 0 means door is closed)

; PF4 is left-door input sensor (1 means door is open, 0 means door is closed)

; PF3 is Safe (Green) LED signal - ON when both doors are closed, otherwise OFF

; PF1 is Unsafe (Red) LED signal - ON when either (or both) doors are open, otherwise OFF

; The specific operation of this system

;   Turn Unsafe LED signal ON if any or both doors are open, otherwise turn the Safe LED signal ON

;   Only one of the two LEDs must be ON at any time.

; NOTE: Do not use any conditional branches in your solution.

;      We want you to think of the solution in terms of logical and shift operations

Program 0.2. Required comments at the top of every file.

To interact with the I/O during simulation, make sure that View->Periodic Window Update is checked or the simulator will not update! Then, execute the Peripherals->TExaS Port F command. When running the simulator, we check and uncheck bits in the I/O Port box to change input pins (1) (2) and (3). We observe output pin in the window (4). You can also see the other DIR AFSEL DEN and PUR registers.

Explanation / Answer

#include "tm4c123ge6pm.h"

unsigned long In; // input from PF4

unsigned long Out; // output to PF2 (blue LED)

//   Function Prototypes

void PortF_Init(void);

// 3. Subroutines Section

// MAIN: Mandatory for a C Program to be executable

int main(void){    // initialize PF0 and PF4 and make them inputs

PortF_Init();    // make PF3-1 out (PF3-1 built-in LEDs)

while(1){

    In = GPIO_PORTF_DATA_R&0x10;   // read PF4 into Sw1

    In = In>>2;                    // shift into position PF2

    Out = GPIO_PORTF_DATA_R;

    Out = Out&0xFB;

    Out = Out|In;

    GPIO_PORTF_DATA_R = Out;        // output

}

}

// Subroutine to initialize port F pins for input and output

// PF4 is input SW1 and PF2 is output Blue LED

// Inputs: None

// Outputs: None

// Notes: ...

void PortF_Init(void){ volatile unsigned long delay;

SYSCTL_RCGC2_R |= 0x00000020;     // 1) activate clock for Port F

delay = SYSCTL_RCGC2_R;           // allow time for clock to start

GPIO_PORTF_LOCK_R = 0x4C4F434B;   // 2) unlock GPIO Port F

GPIO_PORTF_CR_R = 0x1F;           // allow changes to PF4-0

// only PF0 needs to be unlocked, other bits can't be locked

GPIO_PORTF_AMSEL_R = 0x00;        // 3) disable analog on PF

  GPIO_PORTF_PCTL_R = 0x00000000;   // 4) PCTL GPIO on PF4-0

  GPIO_PORTF_DIR_R = 0x0E;          // 5) PF4,PF0 in, PF3-1 out

GPIO_PORTF_AFSEL_R = 0x00;        // 6) disable alt funct on PF7-0

GPIO_PORTF_PUR_R = 0x11;          // enable pull-up on PF0 and PF4

GPIO_PORTF_DEN_R = 0x1F;          // 7) enable digital I/O on PF4-0

}