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 84 0
  • Loading ...
1/22 trang

Thông tin tài liệu

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

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)... 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) XoaKyTuTrongChuoi_C Call a C Program #include "stm32l1xx.h" extern void loaikytu(char *str,unsigned char kytu); char string[] = "lieneeeeeeechieeeeeeeeu\0"; int main(){ asm{ nop } loaikytu(string,'e'); while(1); } b Assemply Program ;******************** (C) Yifeng ZHU ******************** ; @file main.s ; @author Yifeng Zhu ; @version V1.0.0 ; @date May-5-2012 ; @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: ; http://www.eece.maine.edu/~zhu/book ;******************************************************** ; 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 RCC_AHBENR_GPIOBEN ; - BLUE LED: connected to PB6 (GPIO Port B, PIN 6), CLK RCC_AHBENR_GPIOBEN ; - 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 removeCharacter, CODE ALIGN loaikytu EXPORT PROC loaikytu ;loai ky tu khoi chuoi ;vao : r0 chua dia chi cua chuoi, r1 chua ky tu ;ra : khong PUSH {lr,r4,r5} loop LDRB r2,[r0],#1 CBZ r2,stop ;load string ;if -> stop CMP r2,r1 BNE loop ;if r2!= r1 continue SUB r0,#1 ;else loai ky tu khoi chuoi MOV r4,r0 loai LDRB cac ky tu phia sau ve phia truoc STRB r5,[r4],#1 CMP r5,#0 BEQ loop r5,[r4,#1] ;di chuyen B loai stop POP {lr,r4,r5} BX lr ENDP NoiChuoi_S Call a C Program #include #include #include "stm32l1xx.h" void strct(char * dst, char* src){ while(*dst++); while(*dst++ == *src++); } b Assemply Program ;******************** (C) Yifeng ZHU ******************** ; @file main.s ; @author Yifeng Zhu ; @version V1.0.0 ; @date May-5-2012 ; @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: ; http://www.eece.maine.edu/~zhu/book ;******************************************************** ; 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 RCC_AHBENR_GPIOBEN ; - BLUE LED: connected to PB6 (GPIO Port B, PIN 6), CLK RCC_AHBENR_GPIOBEN ; - 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 IMPORT strcat AREA main, CODE, READONLY EXPORT main ; make main visible to linker ENTRY main PROC NOP ldr r0,=str1 ldr r1,=str2 bl strcat stop B stop ENDP product bx PROC lr ENDP AREA myData, DATA, READWRITE ALIGN str1 DCB space 100 str2 DCB "this is tha thu",0 " ma minh ve len thoi",0 END 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"; char *str1 = s1; char *str2 = s2; int main(){ asm{ nop } hoandoi(&str1,&str2); str1[0] = '1'; str2[0] = '2'; while(1); } b Assemply Program ;******************** (C) Yifeng ZHU ******************** ; @file main.s ; @author Yifeng Zhu ; @version V1.0.0 ; @date May-5-2012 ; @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: ; http://www.eece.maine.edu/~zhu/book ;******************************************************** ; 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 RCC_AHBENR_GPIOBEN ; - BLUE LED: connected to PB6 (GPIO Port B, PIN 6), CLK RCC_AHBENR_GPIOBEN ; - 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 hoandoi PROC EXPORT hoandoi ;ham hoan doi chuoi (hoan doi tro) ;vao : r0, r1 chua dia chi cua tro tro den chuoi ;ra : void ldr r2,[r0] ldr r3,[r1] str r2,[r1] str r3,[r0] bx lr ENDP TimKyTuTrongChuoi_S Call a C Program char *search(char * s, char c){ char *p = 0; for(;*s;s++) if(*s == c) p = s; return p; } b Assemply Program ;******************** (C) Yifeng ZHU ******************** ; @file main.s ; @author Yifeng Zhu ; @version V1.0.0 ; @date May-5-2012 ; @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: ; http://www.eece.maine.edu/~zhu/book ;******************************************************** ; 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 RCC_AHBENR_GPIOBEN ; - BLUE LED: connected to PB6 (GPIO Port B, PIN 6), CLK RCC_AHBENR_GPIOBEN ; - 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 IMPORT search AREA main, CODE, READONLY EXPORT main ; make main visible to linker ENTRY main NOP ldr r0,=str1 ldr r1,='u' bl search PROC ldr r0,[r0] stop B stop ENDP product PROC bx lr ENDP AREA myData, DATA, READWRITE ALIGN str1 DCB "this is tha thu",0 space 100 str2 DCB " ma minh ve len thoi",0 END Struct_S Call a C Program struct Student_T{char c1;char c2;int score;char c3; } students[10]; void khoiTaoStruct(){ int i; for( i=0 ; i
- Xem thêm -

Xem thêm: 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), 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)

Gợi ý tài liệu liên quan cho bạn

Nhận lời giải ngay chưa đến 10 phút Đăng bài tập ngay