Hệ thống nhúng - Chương 5
lượt xem 18
download
In this lesson we will review the basics of string declaration as an excuse to introduce the memory allocation techniques used by the MPLAB C30 compiler. The RISC architecture of the PIC24 poses some interesting challenges and offers innovative solutions.
Bình luận(0) Đăng nhập để gửi bình luận!
Nội dung Text: Hệ thống nhúng - Chương 5
- Embedded Systems Hệ thống nhúng Thạc sĩ Lê Mạnh Hải 1
- Lesson 5 : Taking a look under the hood Motivation: • Memory space allocation • Program space visibility • Investigating memory allocation • Looking at the MAP • Pointers • The heap • MPLAB® C30 memory models 2
- Flight plan • In this lesson we will review the basics of string declaration as an excuse to introduce the memory allocation techniques used by the MPLAB C30 compiler. • The RISC architecture of the PIC24 poses some interesting challenges and offers innovative solutions. 3
- Preflight checklist • This lesson will be performed exclusively with software tools including the MPLAB IDE, MPLAB C30 compiler and the MPLAB SIM simulator. • Use the “New Project Set-up” checklist to create a new project called “Strings” and a new source file similarly called “strings.c”. 4
- The flight 1. char s[5] = { 'H', 'E', 'L', 'L', 'O'}; 2. char s[5] = "HELLO"; 3. char s[] = "HELLO"; 4. char s[6] = { 'H', 'E', 'L', 'L', 'O', '\0' }; 5
- The flight char c; // declare c as an 8-bit signed integer c = 'a'; // assign to it the value corresponding to 'a' in the ASCII table c ++; // increment it... it will represent the ASCII character 'b' now Something wrong here char s[15]; // declare s as a string of 15 characters s = "Hello!"; // Error! This does not work! copy the content of a string onto another: strcpy( s, "HELLO"); // s : "HELLO" append (or concatenate) two strings: strcat( s, " WORLD"); // s : "HELLO WORLD" determine the length of a string: i = strlen( s); // i : 11 6 and many more.
- Memory space allocation char s[] = "Flying with the PIC24"; const char s[] = "Flying with the PIC24"; strcpy( s, “HELLO”); The string “HELLO” was implicitly defi ned as of const char type, and similarly assigned to the const section in program memory to be accessible via the Program Space Visibility window. 7
- Program space visibility • The PIC24 architecture is somewhat different from most other 16-bit microcontroller architectures you might be familiar with. It was designed for maximum effi ciency according to the Harvard model, as opposed to the more common Von Neumann model. • The big difference between the two is that there are two completely separated and independent buses available, one for access to the Program Memory (Flash) and one for access to the Data Memory (RAM). • The PIC24 architecture offers two methods to read data from program memory: using special table access instructions (tblrd) and through a second mechanism, called the Program Space Visibility or PSV. This is a window of up to 32K bytes of program memory accessible from the data memory bus. In other words the PSV is a bridge between the program memory bus and the data memory bus. 8
- Testing 9
- Post-flight briefing • In this lesson, we have learned not only what data types are available and how much memory is allocated to them, but also how they affect the resulting compiled program—code size and the execution speed. • We used the MPLAB SIM simulator Stopwatch function to measure the number of instruction cycles (and therefore time) required for the execution of a series of code segments. • Some of the information gathered will, hopefully, be useful to guide our actions in the future when balancing our needs for precision and performance in embedded-control applications. 10
- Investigating memory allocation #include #include // 1. variable declarations const char a[] = “Learn to fly with the PIC24”; char b[100] = “”; // 2. main program main() { strcpy( b, “MPLAB C30”); // assign new content to b } //main 11
- Watch window 12
- 13
- Pointers int *pi; // define a pointer to an integer int i; // index/counter int a[10]; // the array of integers // 1. sequential access using array indexing for( i=0; i
- Pointers // 2. sequential access to array using pointers for( i=0, p=a; i
- The heap • What is heap? • The “heap” is the area of data memory reserved for such use, and a set of functions, part of the standard C library “stdlib.h”, provides the tools to allocate and free the memory blocks. • void *malloc(size_t size); takes a block of memory of requested size from the heap, and returns a pointer to it. • void free(void *ptr); 16
- Exercises Develop new string manipulation functions to perform the following operations: 1. Search for a string in an array of strings, sequential. 2. Implement a Binary search. 3. Develop a simple Hash Table management library. 17
- What (pg 89 – pg103) is next? • CHAPTER 7: Communication – Synchronous serial interfaces – Asynchronous serial interfaces – Parallel interfaces – Synchronous communication using the SPI modules – Testing the Read Status Register command – Writing to the EEPROM – Reading the memory contents – A nonvolatile storage library – Testing the new NVM library • CHAPTER 8: Asynchronous communication (pg 104 – pg125) – UART configuration – Sending and receiving data – Testing the serial – communication routines 18
CÓ THỂ BẠN MUỐN DOWNLOAD
-
Giáo trình Wincc cho hệ thống Scada
134 p | 1316 | 649
-
Sửa lỗi windows khi bị lỗi hệ thống
3 p | 375 | 116
-
Hệ thống thông tin quản lý phần 5
11 p | 163 | 29
-
PHÂN TÍCH THIẾT KẾ HỆ THỐNG THÔNG TIN - TRẦN ĐÌNH QUẾ - 5
16 p | 153 | 20
-
5 tính năng bảo mật hay nhất của thiết bị Cisco M
6 p | 133 | 17
-
Phát hành Hệ quản trị CSDL Firebird 2.5
5 p | 113 | 14
-
5 phần mềm tăng tốc hệ thống tốt nhất
11 p | 143 | 12
-
5 công cụ giúp chuyển đổi giao diện Windows thành hệ điều hành khác
8 p | 105 | 10
-
Sanboxie Control 3.5 - Môi trường ảo thử nghiệm phần mềm
6 p | 125 | 9
-
5 thủ thuật tinh chỉnh registry để tối ưu hóa hệ thống của bạn
8 p | 85 | 9
-
Bài giảng Nhập môn hệ thống thông tin - Bài 5: Tổ chức dữ liệu và thông tin
37 p | 81 | 8
-
5 dấu hiệu máy tính nhiễm phần mềm độc hại
3 p | 84 | 7
-
5 cách đảm bảo người dùng không bị “theo dõi” trên Internet
10 p | 90 | 7
-
5 hệ điều hành đã bị quên lãng
6 p | 72 | 7
-
Bài giảng Phân tích thiết kế hệ thống thông tin: Bài 5 - TS. Trần Mạnh Tuấn
41 p | 37 | 6
-
Top 5 công cụ miễn phí giúp sao lưu ảnh trên Instagram
7 p | 86 | 4
-
5 bước giúp an toàn cho các máy chủ ảo.
5 p | 62 | 3
-
Bài giảng CAD/CAM/CNC - Bài 5: Hệ thống CAD
22 p | 5 | 2
Chịu trách nhiệm nội dung:
Nguyễn Công Hà - Giám đốc Công ty TNHH TÀI LIỆU TRỰC TUYẾN VI NA
LIÊN HỆ
Địa chỉ: P402, 54A Nơ Trang Long, Phường 14, Q.Bình Thạnh, TP.HCM
Hotline: 093 303 0098
Email: support@tailieu.vn