Program C Ansi Programming Embedded Systems in C and C++ phần 2

Tham khảo tài liệu 'program c ansi programming embedded systems in c and c++ phần 2', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | The P2LTCH register is located in a special region of memory called the I O space at offset 0xFF5E. Unfortunately registers within the I O space of an 80x86 processor can be accessed only by using the assembly language instructions in and out. The C language has no built-in support for these operations. Its closest replacements are the library routines inport and outport which are declared in the PC-specific header file . Ideally we would just include that header file and call those library routines from our embedded program. However because they are part of the DOS programmer s library we ll have to assume the worst that they won t work on our system. At the very least we shouldn t rely on them in our very first program. An implementation of the toggleLed routine that is specific to the Arcom board and does not rely on any library routines is shown below. The actual algorithm is straightforward read the contents of the P2LTCH register toggle the bit that controls the LED of interest and write the new value back into the register. You will notice that although this routine is written in C the functional part is actually implemented in assembly language. This is a handy technique known as inline assembly that separates the programmer from the intricacies of C s function calling and parameter passing conventions but still gives her the full expressive power of assembly language. 2 2 Unfortunately the exact syntax of inline assembly varies from compiler to compiler. In the example I m using the format preferred by the Borland C compiler. Borland s inline assembly format is one of the best because it supports references to variables and constants that are defined within the C code. define P2LTCH 0xFF5E The offset of the P2LTCH register. Function toggleLed Description Toggle the state of one or both LEDs. Notes This function is specific to Arcom s Target188EB board. Returns None defined. void toggleLed unsigned char ledMask asm mov dx P2LTCH Load the address of the

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
2    82    2    25-04-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.