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
Hi everyone sir,i'm needed help because don't know Using the FRDM-KL25Z board, with uVision 5 Keil compiler. 2 ways traffic light with pedestrian crossing button traffic light program. C programming
Kaleem
I see GPIOB_PDDR defined but I don't see it used. Without setting the ports to outputs it would be normal that no LEDs light.
Why do you write in assembler - I thought this was abolished 40 years ago (and give to the compiler to do) ;-)
Regards
Mark
Hello Mark, I have utilized GPIOB_PDDR in my updated code which can be found here CodePaste.NET - Traffic light code , However now none of the diodes are coming on, could there be an issue with the way i have things set?
The error I keep getting is a cpu reset by debugger.
Kaleem
Have you correctly enabled clocks to the ports?
Regards
Mark
Yes I have the code to enable all clocks would be,
SIM_SCG85 EQU 0x40048038; clock address
; Turns on clock
LDR r0,=SIM_SCGC5
LDR r1,[r0]
LDR r2,=0x00003E00
ORRS r1,r2
STR r1,[r0]
I've also tried disabling watchdog which didn't help either.
Kaleem
The port clock gate looks OK.
Why not single step the code to see what works and what not?
Regards
Mark