Below is some sample code I gathered from a friends program that I commented and modified.
So far, I understand why we set up the clocks and how to turn them on. I also understand equating the addresses for the pins being used, weather for a control register or a direction register.
What I don't get is how to set values for the GPIO. I don't understand the section: Initialize GPIO's and setup I/O status in the code below.
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ;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 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 ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ;///////////////////////////////////////////////////////////////////////////////// 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, binary of 3E, into the Sim_SCGC5 register ;Which turns on the port clocks A-E. ;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ;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 <~~~~~~~~~~~~~~~~~~~~~~~~~~~!!! How do we determine this value? !!! STR R1,[R0] ;Put value into GPIOA LDR R0,=GPIOB_PDDR ;Load address of GPIOB to R0 LDR R1,=0x000C0000 ;Load value to R1 <~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ And this value STR R1,[R0] ;Put value into GPIOB LDR R0,=GPIOD_PDDR ;Load address of GPIOD to R0 LDR R1,=0x00000002 ;Load value to R1 <~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ And this value STR R1,[R0] ;Put value into GPIOD