1. Trang chủ
  2. » Công Nghệ Thông Tin

Lập trình vi điều khiển STM32L152 bài tập chương 10 sách Embedded Systems with ARM CortexM Microcontrollers in Assembly Language and C (Third Edition – Dr Yifeng Zhu)

22 552 4

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 22
Dung lượng 432,52 KB
File đính kèm CODE CHƯƠNG 10 STM32L152.rar (86 KB)

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Bài tập có lời giải và code đính kèm chương 10 sách vi điều khiển Embedded Systems with ARM CortexM Microcontrollers in Assembly Language and C (Third Edition – Dr Yifeng Zhu ) , bao gồm các bài tập: Viết chương trình con loại bỏ các lần xuất hiện của một ký tự trong chuỗi, nối chuỗi, đảo chuỗi, tìm ký tự trong chuỗi, tìm số lớn nhất trong bốn số, kiểm tra số đối xứng (số palindrome)...

Trang 1

LẬP TRÌNH VI ĐIỀU KHIỂN STM32L152

(Sách Embedded Systems with ARM Cortex-M Microcontrollers

in Assembly Language and C (Third Edition) – Dr Yifeng Zhu )

BÀI TẬP CHƯƠNG 10 (Có code đính kèm)

1 XoaKyTuTrongChuoi_C Call

a C Program

#include "stm32l1xx.h"

extern void loaikytu(char *str,unsigned char kytu);

char string[] = "lieneeeeeeechieeeeeeeeu\0";

Trang 2

; @note

; @brief Assembly code for STM32L1xx Discovery Kit

; @note

; This code is for the book "Embedded Systems with ARM Cortex-M3

; Microcontrollers in Assembly Language and C, Yifeng Zhu,

; ISBN-10: 0982692625

; @attension

; This code is provided for education purpose The author shall not be

; held liable for any direct, indirect or consequential damages, for any

; reason whatever More information can be found from book website:

; - RESET Pushbutton: connected RESET

; - GREEN LED: connected to PB7 (GPIO Port B, PIN 7), CLK

Trang 3

INCLUDE stm32l1xx_tim_constants.s ; TIM Constants

ALIGN

;loai 1 ky tu ra khoi 1 chuoi

;vao : r0 chua dia chi cua chuoi, r1 chua ky tu

;ra : khong

CMP r2,r1

MOV r4,r0

cac ky tu phia sau ve phia truoc

STRB r5,[r4],#1

CMP r5,#0

BEQ loop

Trang 5

; This code is for the book "Embedded Systems with ARM Cortex-M3

; Microcontrollers in Assembly Language and C, Yifeng Zhu,

; ISBN-10: 0982692625

; @attension

; This code is provided for education purpose The author shall not be

; held liable for any direct, indirect or consequential damages, for any

; reason whatever More information can be found from book website:

; - RESET Pushbutton: connected RESET

; - GREEN LED: connected to PB7 (GPIO Port B, PIN 7), CLK

INCLUDE stm32l1xx_constants.s ; Load Constant Definitions

INCLUDE stm32l1xx_tim_constants.s ; TIM Constants

Trang 6

IMPORT strcat

AREA main, CODE, READONLY

EXPORT main ; make main visible to linker ENTRY

Trang 7

END

3 DaoChuoi_C Call

a C Program

#include "stm32l1xx.h"

extern void hoandoi(char** str1,char** str2);

char s1[] = "day la cai tha thu \0";

char s2[] = "ma minh ve len thoi\0";

Trang 8

; This code is for the book "Embedded Systems with ARM Cortex-M3

; Microcontrollers in Assembly Language and C, Yifeng Zhu,

; ISBN-10: 0982692625

; @attension

; This code is provided for education purpose The author shall not be

; held liable for any direct, indirect or consequential damages, for any

; reason whatever More information can be found from book website:

; - RESET Pushbutton: connected RESET

; - GREEN LED: connected to PB7 (GPIO Port B, PIN 7), CLK

RCC_AHBENR_GPIOBEN

; - BLUE LED: connected to PB6 (GPIO Port B, PIN 6), CLK

RCC_AHBENR_GPIOBEN

Trang 9

; - Linear touch sensor/touchkeys: PA6, PA7 (group 2), PC4, PC5 (group 9), PB0, PB1 (group 3)

INCLUDE stm32l1xx_constants.s ; Load Constant Definitions

INCLUDE stm32l1xx_tim_constants.s ; TIM Constants

AREA bai10_3,code

ALIGN

EXPORT hoandoi

;ham hoan doi 2 chuoi (hoan doi con tro)

;vao : r0, r1 chua dia chi cua con tro tro den 2 chuoi

Trang 10

; This code is for the book "Embedded Systems with ARM Cortex-M3

; Microcontrollers in Assembly Language and C, Yifeng Zhu,

; ISBN-10: 0982692625

; @attension

; This code is provided for education purpose The author shall not be

; held liable for any direct, indirect or consequential damages, for any

; reason whatever More information can be found from book website:

; http://www.eece.maine.edu/~zhu/book

;********************************************************

Trang 11

; STM32L1xx Discovery Kit:

; - USER Pushbutton: connected to PA0 (GPIO Port A, PIN 0), CLK

RCC_AHBENR_GPIOAEN

; - RESET Pushbutton: connected RESET

; - GREEN LED: connected to PB7 (GPIO Port B, PIN 7), CLK

INCLUDE stm32l1xx_constants.s ; Load Constant Definitions

INCLUDE stm32l1xx_tim_constants.s ; TIM Constants

AREA main, CODE, READONLY

EXPORT main ; make main visible to linker

Trang 13

; This code is for the book "Embedded Systems with ARM Cortex-M3

; Microcontrollers in Assembly Language and C, Yifeng Zhu,

; ISBN-10: 0982692625

; @attension

; This code is provided for education purpose The author shall not be

; held liable for any direct, indirect or consequential damages, for any

; reason whatever More information can be found from book website:

; http://www.eece.maine.edu/~zhu/book

;********************************************************

; STM32L1xx Discovery Kit:

Trang 14

; - USER Pushbutton: connected to PA0 (GPIO Port A, PIN 0), CLK

RCC_AHBENR_GPIOAEN

; - RESET Pushbutton: connected RESET

; - GREEN LED: connected to PB7 (GPIO Port B, PIN 7), CLK

INCLUDE stm32l1xx_constants.s ; Load Constant Definitions

INCLUDE stm32l1xx_tim_constants.s ; TIM Constants

AREA main, CODE, READONLY

EXPORT main ; make main visible to linker

Trang 15

mov r2,#0 ;bien lap tinh

beq stop

Trang 17

; This code is for the book "Embedded Systems with ARM Cortex-M3

; Microcontrollers in Assembly Language and C, Yifeng Zhu,

; ISBN-10: 0982692625

; @attension

; This code is provided for education purpose The author shall not be

; held liable for any direct, indirect or consequential damages, for any

; reason whatever More information can be found from book website:

; - RESET Pushbutton: connected RESET

; - GREEN LED: connected to PB7 (GPIO Port B, PIN 7), CLK

RCC_AHBENR_GPIOBEN

; - BLUE LED: connected to PB6 (GPIO Port B, PIN 6), CLK

RCC_AHBENR_GPIOBEN

Trang 18

; - Linear touch sensor/touchkeys: PA6, PA7 (group 2), PC4, PC5 (group 9), PB0, PB1 (group 3)

INCLUDE stm32l1xx_constants.s ; Load Constant Definitions

INCLUDE stm32l1xx_tim_constants.s ; TIM Constants

AREA bai10_4,code

ALIGN

EXPORT max4

;ham tinh max 4 so nguyen co dau

;vao : r0-r4 chua 4 so nguyen

;ra : r0 chua max

Trang 20

; Microcontrollers in Assembly Language and C, Yifeng Zhu,

; ISBN-10: 0982692625

; @attension

; This code is provided for education purpose The author shall not be

; held liable for any direct, indirect or consequential damages, for any

; reason whatever More information can be found from book website:

; - RESET Pushbutton: connected RESET

; - GREEN LED: connected to PB7 (GPIO Port B, PIN 7), CLK

INCLUDE stm32l1xx_constants.s ; Load Constant Definitions

INCLUDE stm32l1xx_tim_constants.s ; TIM Constants

AREA bai10_7,code

ALIGN

Trang 21

sodoixung PROC

;ham kiem tra so doi xung

;vao : r0 chua so can kiem tra

;ra : r0 = 1 neu la so doi xung va nguoc lai

Trang 22

udiv r1,r2

Ngày đăng: 18/01/2018, 11:03

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm

w