Mpi Lab1
Mpi Lab1
Mpi Lab1
Lab Report # 1
Introduction to KEIL & ARM Assembly
Submitted By:
Riyan Ali Alvi
Abdul Rehman Al Nasir
Munad e Ali
DATED: 9-MAR-2022
1. Create new project in µVision5 and setup STM32F103C8 board CMSIS core and device
startup libraries in runtime environment.
2. Create new Assembler source file (.s).
3. On-board RTC-LED is connected with Port C13, PC13 is connected to Advanced Peripheral
Bus2 (ABP2). Clock on PC13 is enabled by changing bit 4 of ABP2 enable register which is
at 0x18 offset from RCC register located at 0x4002100.So existing value of register is
LOADED into stack register and OR operation is applied with new information and again
STORED back into the memory.
4. Configuration of Pin 13 is set to output push pull and Mode is set to 2MHz clock in
GPIOC_CRH register which is located at 0x04 offset from GPIOC base address at
0x4001100 (from memory map in user_manual).Memory register is altered by using same
technique used in previous step.
5. BSRR is used for atomic control over a single pin of a port, so Pin is set and reset repeatedly
by changing corresponding bits of pin 13 to turn LED on and off. BSRR is located at and
offset of 0x10 from GPIOC base address. BSRR is WRITE-ONLY register so we cannot
change information present in it , we just LOAD new information into the register
6. After turning ON of OFF LED program enters into a loop which last for 1 second and then
performs the next operation.
5. Code
; ******* Constants *******
;Delay interval= 2M clock units. = 1sec
;due to 8 machine cycle execution.
;Overheads are ignored
; **************************
RCC_BASE EQU 0x40021000 ;From memory map Reset and clock control RCC
APB2ENR_OFFSET EQU 0x18 ;Peripheral bus 2 Clock Enable Register
RCC_APB2ENR EQU RCC_BASE + APB2ENR_OFFSET
GPIOC_BSRR_OFFSET EQU 0x10 ;GPIOC Bit Set/Reset register offset for GPIO C start value
GPIOC_BSRR EQU GPIOC_BASE + GPIOC_BSRR_OFFSET
;***************LOOPSTART HERE*******************
;******************** Repetition To ON OFF LED
Loop ;LABEL
;**************TO ON LED***********************
LDR R0, =GPIOC_BSRR
LDR R1, =LED_ON
STR R1, [R0]
;***********************************************
LDR R7, =DELAY_INTERVAL
MOV R3, R7
BL delay
B turnOFF
;**********************DELAY********************
;*Assume 8 Machine cylce for execute delay func*
delay
CBZ R3, delayend
SUBS R3, #1
B delay1
delayend
BX LR
;***********************************************
;*****************TO OFF LED********************
turnOFF
; Set output low
LDR R0, =GPIOC_BSRR ; R0=0x40011010
LDR R1, =LED_OFF
STR R1, [R0]
GPIOC_Init
NOP
ALIGN
END
6. Simulation Results:
Simulations were performed in Proteus Professional 8 with BLUEPILL libraries
LED is connected to Pin C13which is acting as sink and oscilloscope is connected to pin13
to visualize change in state
7. Conclusion
The code executed perfectly on STM32 board and computer simulation. Proper workflow was
followed to achieve this objective. The fact that microcontroller takes some time to execute
single instruction was used to construct a loop which repeatedly ran a single instruction for a
specified number of times to achieve a perceivable delay by human eye.