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

Using FRDM-KL25Z to implement a Passenger Seat Belt Controller Requirements: The

ID: 3691328 • Letter: U

Question

Using FRDM-KL25Z to implement a Passenger Seat Belt Controller Requirements:

The controller job is to flash a LED if a passenger sits in a seat and does not fasten the seat belt within 5 seconds. The system has two inputs: 1- a sensor for the seat to know when a person sat down (Seat input signal) 2- a seat belt sensor that tells when the belt is fastened (Belt input signal) Note: you can use ON/OFF switches to represent the seat and belt inputs. The system has 3 outputs 1- Yellow LED to indicate that a passenger has sat down 2- Green LED to indicate that the passenger has fasten the seat belt 3- Flashing red LED to indicate that the 5 seconds has elapsed while the passenger did not fasten the belt.

Write out code using Keil uVision5

   SIM_SCGC5 EQU 0x40048038
  
;Port B register address
   GPIOB_PSOR EQU 0x400FF044 ;GPIOB_PSOR address
   GPIOB_PCOR EQU 0x400FF048 ;GPIOB_PCOR address
   GPIOB_PDDR EQU 0x400FF054 ;GPIOB_PDDR address
      
;Port D register address
   GPIOD_PDIR EQU 0x400FF0D0 ;GPIOD_PDIR address
   GPIOD_PDDR EQU 0x400FF0D4 ;GPIOD_PDDR address
  
;3 outputs
   PORTB_PCR1 EQU 0X4004A004 ;GREEN LED
   PORTB_PCR2 EQU 0x4004A008 ;YELLOW LED
   PORTB_PCR3 EQU 0X4004A00C ;FLASHING RED
      
;2 inputs
   PORTD_PCR0 EQU 0X4004C000 ;SEAT INPUT SIGNAL
   PORTD_PCR2 EQU 0X4004C008 ;BELT INPUT SIGNAL
  
;INPUT MASKS
   SEAT_MASK EQU 0X00000001 ;SEAT MASK 2^0
   BELT_MASK EQU 0X00000004 ;BELT MASK 2^2
  
;OUTPUT MASKS
   GREEN_MASK EQU 0X00000002; MASK FOR GREEN LED
   YELLOW_MASK EQU 0X00000004; MASK FOR YELLOW LED
   RED_MASK EQU 0X00000008; MASK FOR RED LED

SO FAR THIS IS WHAT I HAVE

Explanation / Answer

note:instead of yellow i have taken blue color

SIM_SCGC5 EQU 0x40048038 ;SIM_SCGC5 address

PORTB_PCR18 EQU 0x4004A000 + 4 * 18 ;PORTB_PCR18 address

PORTB_PCR19 EQU 0x4004A000 + 4 * 19 ;PORTB_PCR18 address

PORTD_PCR1 EQU 0x4004C000 + 4 * 1 ;PORTD_PCR1 address

PORTD_PCR3 EQU 0x4004C000 + 4 * 3 ;PORTD_PCR3 address

GPIOB_PSOR EQU 0x400FF044 ;GPIOB_PSOR address

GPIOB_PCOR EQU 0x400FF048 ;GPIOB_PCOR address

GPIOB_PTOR EQU 0x400FF04C ;GPIOB_PTOR address

GPIOB_PDDR EQU 0x400FF054 ;GPIOB_PDDR address

GPIOD_PSOR EQU 0x400FF0C4 ;GPIOD_PDIR address

GPIOD_PCOR EQU 0x400FF0C8 ;GPIOD_PDIR address

GPIOD_PDIR EQU 0x400FF0D0 ;GPIOD_PDIR address

GPIOD_PDDR EQU 0x400FF0D4 ;GPIOD_PDDR address

BLUE_MASK EQU 0x00000002

RED_MASK EQU 0x00040000

GREEN_MASK EQU 0x00080000

BUTTON_MASK EQU 0X00000008

DELAY_CNT EQU 0X00800000

AREA asm_area, CODE, READONLY

EXPORT asm_main

asm_main ;assembly entry point for C function, do not delete

; Add program code here

BL init_gpio

loop

BL redon

LDR R0, =DELAY_CNT

BL delay

BL redoff

LDR R0, =DELAY_CNT

BL delay

B loop

redon

LDR R0,=GPIOB_PCOR ;Load address of GPIOB_PCOR to R0

LDR R1,=RED_MASK ;Load value to R1

STR R1,[R0] ;Put value into GPIOB_PCOR

BX LR

redoff

LDR R0,=GPIOB_PSOR ;Load address of GPIOB_PSOR to R0

LDR R1,=RED_MASK ;Load value to R1

STR R1,[R0] ;Put value into GPIOB_PSOR

BX LR

redtoggle

LDR R0,=GPIOB_PTOR ;Load address of GPIOD_PTOR to R0

LDR R1,=RED_MASK ;Load value to R1

STR R1,[R0] ;Put value into GPIOD_PTOR

BX LR

delay

SUBS R0, #1

BNE delay

BX LR

init_gpio

; Turns on clocks for all ports

LDR R0,=SIM_SCGC5 ;Load address of SIM_SCGC5 to R0

LDR R1,[R0] ;Get original value of SIM_SCGC5

LDR R2,=0x00003E00 ;Load mask for bits to set to R2

ORRS R1,R2 ;Set bits with OR of orig val and mask

STR R1,[R0] ;Put new value back into SIM_SCGC5

; Setup PORTB Pin 18 to be output

LDR R0,=PORTB_PCR18 ;Load address of PORTB_PCR18 to R0

LDR R1,=0x00000100 ;Load new value to R1

STR R1,[R0] ;Put value into PORTB_PCR18

; Setup PORTB Pin 19 to be output

LDR R0,=PORTB_PCR19 ;Load address of PORTB_PCR19 to R0

LDR R1,=0x00000100 ;Load new value to R1

STR R1,[R0] ;Put value into PORTB_PCR19

; Setup PORTD Pin 1 to be output

LDR R0,=PORTD_PCR1 ;Load address of PORTD_PCR1 to R0

LDR R1,=0x00000100 ;Load new value to R1

STR R1,[R0] ;Put value into PORTD_PCR1

; Setup PORTD Pin 3 to be input

LDR R0,=PORTD_PCR3 ;Load address of PORTD_PCR3 to R0

LDR R1,=0x00000103 ;Load new value to R1

STR R1,[R0] ;Put value into PORTD_PCR3

;Setup R2 for mask for Green and Red LED control lines

LDR R2,= GREEN_MASK :OR: RED_MASK

;Set bits in DDR register to enable outputs to drive LED's

LDR R0,=GPIOB_PDDR ;Load address of GPIOB_PDDR to R0

LDR R1,[R0] ;Get original value of GPIOB_PDDR

ORRS R1,R2 ;Set bits with OR of orig val and mask

STR R1,[R0] ;Put new value back into GPIOB_PDDR

;Turn off LED's by setting control lines

LDR R0,=GPIOB_PSOR ;Load address of GPIOB_PSOR to R0

LDR R1,[R0] ;Get original value of GPIOB_PSOR

ORRS R1,R2 ;Set bits with OR of orig val and mask

STR R1,[R0] ;Put new value back into GPIOB_PSOR

;Setup R2 for mask for Blue LED control line

LDR R2,=BLUE_MASK

;Setup R3 for mask of pushbutton input

LDR R3,=:NOT: BUTTON_MASK

;Set bits in DDR register to enable outputs to drive LED's

; and ensure inputs are clear

LDR R0,=GPIOD_PDDR ;Load address of GPIOD_PDDR to R0

LDR R1,[R0] ;Get original value of GPIOD_PDDR into R1

ORRS R1,R2 ;OR original value with mask to set bits

ANDS R1,R3 ;AND value with mask to clear bits

STR R1,[R0] ;Put new value back into GPIOD_PDDR

;Turn off LED's by setting control lines

LDR R0,=GPIOD_PSOR ;Load address of GPIOD_PSOR to R0

LDR R1,[R0] ;Get original value of GPIOD_PSOR into R1

ORRS R1,R2 ;OR original value with mask to set bits

STR R1,[R0] ;Put new value back into GPIOD_PSOR

BX LR

END

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote