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

Hệ thống nhúng - Chương 5 pot

18 247 1

Đ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 18
Dung lượng 675,5 KB

Nội dung

1 Hệ thống nhúng Thạc sĩ Lê Mạnh Hải Embedded Systems 2 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 3 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. 4 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”. 5 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' }; 6 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 and many more. 7 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. 8 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. 9 Testing 10 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. [...]... i++) a[ i] = i; // 2 sequential access using a pointer pi = a; for( i=0; i . 1 Hệ thống nhúng Thạc sĩ Lê Mạnh Hải Embedded Systems 2 Lesson 5 : Taking a look under the hood Motivation: • Memory space allocation • . simulator. • Use the “New Project Set-up” checklist to create a new project called “Strings” and a new source file similarly called “strings.c”. 5 The flight 1. char s [5] = { 'H', 'E',. 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

Ngày đăng: 01/08/2014, 21:20

TỪ KHÓA LIÊN QUAN