AnsweredAssumed Answered

KL25Z Traffic light program - code issue (Possibly breadboard as well)

Question asked by Kaleem Graham on Nov 30, 2017
Latest reply on Dec 4, 2017 by Mark Butcher

Hello everyone, I'm trying to do a traffic light program using the FRDM-KL25Z board, with uVision 5 Keil compiler. So far I've managed to execute the code however it only lights up my green LED instead of the red and yellow and also does not execute in a loop. My code so far, and the image is also attached below. 

 

SIM_SCG85 EQU 0x40048038; clock
PORTB_PCR0 EQU 0x4004A000; RED
PORTB_PCR1 EQU 0x4004A004; YELLOW
PORTB_PCR2 EQU 0x4004A008; GREEN
GPIOB_PDDR EQU 0x400FF054; Direction of Data
GPIOB_PSOR EQU 0x400FF044; Set Bits
GPIOB_PCOR EQU 0x400FF048; Clear Bits
RED_MASK EQU 0x00000002
YELLOW_MASK EQU 0x00000004
GREEN_MASK EQU 0x00000008
DELAY_CNT EQU 0x00800000
         AREA asm_area, CODE, READONLY
         EXPORT asm_main

asm_main

         BL init_gpio
loop
         BL redon
         LDR r0,=DELAY_CNT
         BL delay
         BL redoff
         BL greenon
         LDR r0,=DELAY_CNT
         BL greenoff
         BL yellowon
         BL delay
         BL yellowoff
         B loop
redon
         LDR r0,=GPIOB_PSOR
         LDR r1,[r0]
         LDR r2,=RED_MASK
         ORRS r1, r2
         STR r1,[r0]
         BX LR
redoff
         LDR r0,=GPIOB_PCOR
         LDR r1,[r0]
         LDR r2,=RED_MASK
         ORRS r1, r2
         STR r1,[r0]
         BX LR
yellowon
         LDR r0,=GPIOB_PSOR
         LDR r1, [r0]
         LDR r2,=YELLOW_MASK
         ORRS r1,r2
         STR r1,[r0]
         BX LR
yellowoff
         LDR r0,=GPIOB_PCOR
         LDR r1,[r0]
         LDR r2,=YELLOW_MASK
         ORRS r1,r2
         STR r1,[r0]
         BX LR
greenon
         LDR r0,=GPIOB_PSOR
         LDR r1,[r0]
         LDR r2,=GREEN_MASK
         ORRS r1,r2
         STR r1,[r0]
         BX LR
greenoff
         LDR r0,=GPIOB_PSOR
           LDR r1,[r0]
           LDR r2,=GREEN_MASK
           ORRS r1,r2
            STR r1,[r0]
            BX LR
delay
 SUBS r0, #1
BNE delay
BX LR
init_gpio
LDR r0,=SIM_SCG85 ; Turns on clock
LDR r1,[r0]
LDR r2,=0x00003E00
ORRS r1,r2
STR r1,[r0]

LDR r0,=PORTB_PCR0 ; Output Red
LDR r1,=0x00000100
STR r1,[r0]

LDR r0,=PORTB_PCR1 ; Output Yellow
LDR r1,=0x00000100
STR r1,[r0]

LDR r0,=PORTB_PCR2 ; Output Green
LDR r1,=0x00000100
STR r1,[r0]


END

Attachments

Outcomes