Hello all, thanks for the community, you guys are great, I was able to make progress from my last post.
I have a question in regard to my code for a project I started in school.
I was able to equate addresses, initialize the clock pins, and define the I/O pins for use.
I wrote a code that steps through the three colors on the on board LED. What I aim to do now, is to take input from a pin PORTA_PCR13 and set the led to one color when the button is not pressed, and another color when the button is pressed.
In C++ I would use an If, Then statement. However, I am unsure as to how I can implement this in ASM. Below is my code.
Any advice?
;Memory Address information found in the KL25P80M48SF0RM document ||||||||||||||||
;/////////////////////////////////////////////////////////////////////////////////
SIM_SCGC5 EQU 0x40048038 ;SIM_SCGC5 address The control for each ports Clock Gate
PORTB_PCR18 EQU 0x4004A000 + 4 * 18 ;PORTB_PCR18 address LED Pin for RED
;Our added code to the example code found above in the lab manual
PORTB_PCR19 EQU 0x4004A04C ;PORTB_PCR19 address LED Pin for GREEN
PORTA_PCR13 EQU 0x40049034 ;PORTA_PCR13 address Pin used for button
PORTD_PCR1 EQU 0x4004C004 ;PORTD_PCR1 address LED Pin for BLUE
GPIOA_PDDR EQU 0x400FF014 ;GPIOA_PDDR Register Address PDDR is Port Data Direction Register
GPIOB_PDDR EQU 0x400FF054 ;GPIOA_PDDR Register Address This sets the pin as input or output
GPIOD_PDDR EQU 0x400FF0D4 ;GPIOB_PDDR Register Address
GPIOA_PDIR EQU 0x400FF010 ;GPIOA_PDIR Register Address This is the Port Data Input Register
GPIOB_PDOR EQU 0x400FF040
GPIOD_PDOR EQU 0x400FF0C0
AREA asm_area, CODE, READONLY
EXPORT asm_main
asm_main ;assembly entry point for C function, do not delete
; Add program code below here
;Initialize clock pins |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;/////////////////////////////////////////////////////////////////////////////////
BL init_gpio
loop
B loop
init_gpio
LDR R0,=SIM_SCGC5 ;Load address of SIM_SCGC5 to R0
LDR R1,[R0] ;Put value of SIM_SCGC5 into R1
LDR R2,=0x00003E00 ;Load value to turn on all port clocks into R2
ORRS R1,R2 ;OR R2 into R1 for use of masking
STR R1,[R0] ;Put value back into SIM_SCGC5,
;This puts 0011111000000000, bianary of 3E, into the Sim_SCGC5 register
;Which turns on the port clocks A-E. See Onur Yilmaz - GPIO.ppt Slide 3
LDR R0,=PORTB_PCR18 ;Load address of PORTB_PCR18 to R0
LDR R1,=0x00000100 ;Load value to R1
STR R1,[R0] ;Put value into PORTB_PCR18
LDR R0,=PORTB_PCR19 ;Load address of PORTB_PCR19 to R0
LDR R1,=0x00000100 ;Load value to R1
STR R1,[R0] ;Put value into PORTB_PCR19
LDR R0,=PORTD_PCR1 ;Load address of PORTD_PCR1 to R0
LDR R1,=0x00000100 ;Load value to R1
STR R1,[R0] ;Put value into PORTD_PCR1
LDR R0,=PORTA_PCR13 ;Load address of PORTA_PCR13 to R0
LDR R1,=0x00000102 ;Load value to R1
STR R1,[R0] ;Put value into PORTA_PCR13
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
;Initialize GPIO's and setup I/O status ||||||||||||||||||||||||||||||||||||||||||
;/////////////////////////////////////////////////////////////////////////////////
LDR R0,=GPIOA_PDDR ;Load address of GPIOA to R0
LDR R1,=0x00000000 ;Load value to R1 Set to ALL INPUTS. O input, 1 Output. Convert to Binary to see what PTB is set
STR R1,[R0] ;Put value into GPIOA
LDR R0,=GPIOB_PDDR ;Load address of GPIOB to R0
LDR R1,=0x000C0000 ;Load value to R1 Outputs configured on PTB18 and PTB19, the LEDs on thos ports as outputs
STR R1,[R0] ;Put value into GPIOB
LDR R0,=GPIOD_PDDR ;Load address of GPIOD to R0
LDR R1,=0x00000002 ;Load value to R1 Output configured on PTC1
STR R1,[R0] ;Put value into GPIOD
;this is where a loop would exist
;read the PDIR to take an input and branch to a location that will enable the color
;loop
;LDR R0,=GPIOA_PDIR
;LDR R1,[R0]
;LDR R2, =0x00002000 ;Must check this block of code
;ANDS R1,R2 ;Not sure if it takes an input from pin A13
;CMP R1,R2
;BEQ loop
LDR R0,=GPIOB_PDOR
LDR R1,=0xFFFFFFFF
STR R1,[R0]
LDR R0,=GPIOD_PDOR
LDR R1,=0xFFFFFFFF
STR R1,[R0]
LDR R0,=GPIOB_PDOR
LDR R1,=0x00040000
STR R1,[R0]
LDR R0,=GPIOB_PDOR
LDR R1,=0xFFFFFFFF
STR R1,[R0]
LDR R0,=GPIOB_PDOR
LDR R1,=0x00080000
STR R1,[R0]
LDR R0,=GPIOB_PDOR
LDR R1,=0xFFFFFFFF
STR R1,[R0]
LDR R0,=GPIOD_PDOR
LDR R1,=0xFFFFFFFD
STR R1,[R0]
LDR R0,=GPIOD_PDOR
LDR R1,=0xFFFFFFFF
STR R1,[R0]
BX LR
;Control indivual pins or LED's ||||||||||||||||||||||||||||||||||||||||||||||||||
;/////////////////////////////////////////////////////////////////////////////////
LDR R2, =0x00000000 ;Counter to see Iif button is held down
LDR R4,= 0x00000000 ;Counter for LED COLOR CYLE
;///////////////////////////////////////////////////
; Put constants here
AREA data_area, DATA, READWRITE
; Put variables here
END
Thanks in advance.