Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
2004 Microchip Technology Inc. DS51456B<br />
dsPIC<br />
®<br />
Language Tools<br />
Libraries<br />
2004 Microchip Technology Inc DS51456B<br />
dsPIC<br />
®<br />
Công cụ Ngôn ngữ<br />
Thư viện<br />
DS51456B-page ii<br />
2004 Microchip Technology Inc.<br />
DS51456B trang ii<br />
2004 Microchip Technology Inc<br />
Information contained in this publication regarding device<br />
applications and the like is provided only for your convenience<br />
and may be superseded by updates. It is your responsibility to<br />
ensure that your application meets with your specifications.<br />
MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF<br />
ANY KIND WHETHER EXPRESS OR IMPLIED,<br />
WRITTEN OR ORAL, STATUTORY OR OTHERWISE,<br />
RELATED TO THE INFORMATION, INCLUDING BUT NOT<br />
LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE,<br />
MERCHANTABILITY OR FITNESS FOR PURPOSE.<br />
Microchip disclaims all liability arising fromthis information and<br />
its use. Use of Microchip’s products as critical components in<br />
life support systems is not authorized except with express<br />
written approval by Microchip. No licenses are conveyed,<br />
implicitly or otherwise, under anyMicrochip intellectual property<br />
rights.<br />
Trademarks<br />
The Microchip name and logo, the Microchip logo, Accuron,<br />
dsPIC, KEELOQ, microID, MPLAB, PIC, PICmicro, PICSTART,<br />
PRO MATE, PowerSmart, rfPIC, and SmartShunt are<br />
registered trademarks of Microchip Technology Incorporated<br />
in the U.S.A. and other countries.<br />
AmpLab, FilterLab, MXDEV, MXLAB, PICMASTER, SEEVAL,<br />
SmartSensor and The Embedded Control Solutions Company<br />
are registered trademarks of Microchip Technology<br />
Incorporated in the U.S.A.<br />
Analog-for-the-Digital Age, Application Maestro, dsPICDEM,<br />
dsPICDEM.net, dsPICworks, ECAN, ECONOMONITOR,<br />
FanSense, FlexROM, fuzzyLAB, In-Circuit Serial<br />
Programming, ICSP, ICEPIC, Migratable Memory, MPASM,<br />
MPLIB, MPLINK, MPSIM, PICkit, PICDEM, PICDEM.net,<br />
PICLAB, PICtail, PowerCal, PowerInfo, PowerMate,<br />
PowerTool, rfLAB, rfPICDEM, Select Mode, Smart Serial,<br />
Thông tin trong ấn phẩm này liên quan đến thiết bị<br />
ứng dụng và như thế chỉ được cung cấp thuận tiện cho bạn<br />
và có thể được thay thế bởi bản cập nhật. Đó là trách nhiệm của bạn để<br />
đảm bảo rằng ứng dụng của bạn đáp ứng với các thông số kỹ thuật của bạn.<br />
Microchip KHÔNG GIỚI THIỆU HOẶC BẢO ĐẢM NÀO CHO DÙ RÕ<br />
RÀNG HAY NGỤ Ý,<br />
VĂN BẢN HAY LỜI NÓI, LUẬT ĐỊNH HAY,<br />
LIÊN QUAN ĐẾN NHỮNG THÔNG TIN, BAO GỒM NHƯNG KHÔNG<br />
GIỚI HẠN CỦA ĐIỀU KIỆN, CHẤT LƯỢNG, HIỆU QUẢ,<br />
MUA BÁN, HOẶC CHO MỤC ĐÍCH.<br />
Microchip từ chối mọi trách nhiệm pháp lý phát sinh fromthis thông tin và<br />
sử dụng của nó. Sử dụng các sản phẩm của Microchip là thành phần quan trọng<br />
trong<br />
hệ thống hỗ trợ cuộc sống không được phép trừ với tốc<br />
Văn bản chấp thuận Microchip. Không có giấy phép được truyền đạt,<br />
ngầm hay không, sở hữu trí tuệ thuộc anyMicrochip<br />
quyền.<br />
Nhãn hiệu hàng hóa<br />
Tên Microchip, biểu tượng, biểu tượng Microchip, Accuron,<br />
dsPIC, KEELOQ, microID, MPLAB, PIC, PICmicro, picstart,<br />
PRO MATE, PowerSmart, rfPIC, và là SmartShunt<br />
thương hiệu đã đăng ký của Microchip Technology Incorporated<br />
ở Mỹ và các nước khác.<br />
AmpLab, Filterlab, MXDEV, MXLAB, PICMASTER, SEEVAL,<br />
Các nhúng Công ty Giải pháp kiểm soát và SmartSensor<br />
là thương hiệu đã đăng ký của công nghệ vi mạch<br />
Thành lập tại Hoa Kỳ<br />
Analog-cho-the-đại kỹ thuật số, ứng dụng Maestro, dsPICDEM,<br />
dsPICDEM.net, dsPICworks, ECAN, ECONOMONITOR,<br />
FanSense, FlexROM, fuzzyLAB, In-Circuit Serial<br />
Lập trình, ICSP, ICEPIC, Migratable nhớ, MPASM,<br />
MPLIB, MPLINK, MPSIM, PICkit, PICDEM, PICDEM.net,<br />
PICLAB, PICtail, PowerCal, PowerInfo, PowerMate,<br />
PowerTool, rfLAB, rfPICDEM, Chọn chế độ, Smart Serial,
SmartTel and Total Endurance are trademarks of Microchip<br />
Technology Incorporated in the U.S.A. and other countries.<br />
SQTP is a service mark of Microchip Technology Incorporated<br />
in the U.S.A.<br />
All other trademarks mentioned herein are property of their<br />
respective companies.<br />
© 2004, Microchip Technology Incorporated, Printed in the<br />
U.S.A., All Rights Reserved.<br />
Printed on recycled paper.<br />
Note the following details of the code protection feature on Microchip devices:<br />
• Microchip products meet the specification contained in their particular<br />
Microchip Data Sheet.<br />
• Microchip believes that its family of products is one of the mostsecure<br />
families of its kind on the market today, when used in the<br />
intended manner and under normal conditions.<br />
• There are dishonest and possibly illegal methods used to breach the code<br />
protection feature. All of these methods, to our<br />
knowledge, require using the Microchip products in a manner outside the<br />
operating specifications contained in Microchip’s Data<br />
Sheets. Most likely, the person doing so isengaged in theft of intellectual<br />
property.<br />
• Microchip is willing to work with the customer who is concerned about the<br />
integrity of their code.<br />
• Neither Microchip nor any other semiconductor manufacturer can guarantee<br />
the security of their code. Code protection does not<br />
mean that we are guaranteeing the product as “unbreakable.”<br />
Code protection is constantly evolving. We at Microchip are committed to<br />
continuously improving the code protection features ofour<br />
products. Attempts to break Microchip’s code protection feature may be a<br />
violation of the Digital Millennium Copyright Act. If such acts<br />
allow unauthorized access to your software or other copyrighted work, you may<br />
have a right to sue for relief under that Act.<br />
Microchip received ISO/TS-16949:2002 quality systemcertification for<br />
its worldwide headquarters, design and wafer fabrication facilities in<br />
Chandler and Tempe, Arizona and Mountain View, California in<br />
October 2003. The Company’squality system processes and<br />
procedures are for its PICmicro<br />
®<br />
8-bit MCUs, KEELOQ®<br />
code hopping<br />
devices, Serial EEPROMs, microperipherals, nonvolatile memory and<br />
analog products. In addition, Microchip’s quality system for the design<br />
and manufacture of development systems is ISO 9001:2000 certified.<br />
SmartTel và Tổng Sức chịu đựng là thương hiệu của Microchip<br />
Công nghệ Được thành lập tại Hoa Kỳ và các nước khác.<br />
SQTP là nhãn hiệu của Microchip Technology Incorporated<br />
ở Mỹ<br />
Tất cả thương hiệu khác được đề cập trong tài liệu này là tài sản của họ<br />
công ty tương ứng.<br />
© 2004, Microchip Technology Incorporated, in trong<br />
Mỹ, Tất cả các quyền.<br />
Được in trên giấy tái chế.<br />
Lưu ý các chi tiết sau đây của tính năng mã bảo vệ trên các thiết bị vi mạch:<br />
• Các sản phẩm vi mạch đáp ứng các đặc điểm kỹ thuật đặc biệt chứa dữ liệu<br />
Microchip Bảng của họ.<br />
• Microchip tin rằng gia đình của các sản phẩm là một trong những gia đình<br />
mostsecure của loại hình này trên thị trường hiện nay, khi được sử dụng trong<br />
định cách thức và điều kiện bình thường.<br />
• Có nhiều phương pháp không trung thực và có thể là bất hợp pháp được sử<br />
dụng để vi phạm các tính năng bảo vệ mã. Tất cả những phương pháp này, để<br />
chúng tôi<br />
kiến thức, yêu cầu sử dụng các sản phẩm vi mạch một cách bên ngoài các thông<br />
số kỹ thuật điều hành có trong dữ liệu của Microchip<br />
Tờ. Nhiều khả năng, người làm như vậy isengaged trong hành vi trộm cắp sở<br />
hữu trí tuệ.<br />
• Microchip sẵn sàng làm việc với các khách hàng quan tâm đến tính toàn vẹn<br />
của mã của họ.<br />
• Không Microchip cũng không phải bất kỳ nhà sản xuất bán dẫn khác có thể<br />
đảm bảo sự an toàn của mã của họ. Mã bảo vệ không<br />
có nghĩa là chúng tôi đảm bảo sản phẩm là "không thể phá vỡ."<br />
Mã bảo vệ không ngừng phát triển. Hiện tại Microchip cam kết liên tục cải thiệ<br />
các tính năng bảo vệ mã ofour<br />
sản phẩm. Những nỗ lực để phá vỡ tính năng mã bảo vệ vi mạch có thể là một<br />
vi phạm Đạo luật Bản quyền Thiên niên kỷ kỹ thuật số. Nếu hành vi đó<br />
cho phép truy cập trái phép vào phần mềm của bạn hoặc tác phẩm khác, bạn có<br />
thể có quyền khởi kiện cho cứu trợ theo Đạo luật đó.<br />
Microchip nhận chứng chỉ ISO / TS-16949: 2002 chất lượng cho<br />
systemcertification<br />
trụ sở chính trên toàn thế giới, thiết kế và chế tạo wafer cơ sở của nó trong<br />
Chandler và Tempe, Arizona và Mountain View, California<br />
Tháng Mười năm 2003 quy trình hệ thống và Company'squality<br />
thủ tục cho PICmicro của mình<br />
®<br />
8-bit MCUs, KEELOQ®<br />
đang nhảy<br />
thiết bị, EEPROM Serial, microperipherals, bộ nhớ không bay hơi và<br />
các sản phẩm tương tự. Ngoài ra, hệ thống chất lượng của Microchip cho việc<br />
thiết kế<br />
và sản xuất các hệ thống phát triển là tiêu chuẩn ISO 9001: 2000 được chứng
dsPIC<br />
®LANGUAGE TOOLS<br />
LIBRARIES<br />
2004 Microchip Technology Inc. DS51456B-page iii<br />
Table of Contents<br />
Preface<br />
........................................................................................................................... 1<br />
Chapter 1. Library Overview<br />
1.1 Introduction .....................................................................................................<br />
7<br />
1.2 OMF-Specific Libraries/StarTup Modules ......................................................<br />
7<br />
1.3 Startup Code ..................................................................................................<br />
8<br />
1.4 DSP Library ....................................................................................................<br />
8<br />
1.5 dsPIC Peripheral Libraries .............................................................................<br />
8<br />
1.6 Standard C Libraries (with Math Functions) ...................................................<br />
8<br />
1.7 MPLAB C30 Built-in Functions<br />
....................................................................... 8<br />
Chapter 2. DSP Library<br />
2.1 Introduction .....................................................................................................<br />
9<br />
2.2 Using the DSP Library ..................................................................................<br />
10<br />
2.3 Vector Functions ..........................................................................................<br />
13<br />
2.4 Window Functions ........................................................................................<br />
26<br />
2.5 Matrix Functions ...........................................................................................<br />
31<br />
2.6 Filtering Functions ........................................................................................<br />
38<br />
2.7 Transform Functions ....................................................................................<br />
58<br />
Chapter 3. dsPIC Peripheral Libraries<br />
3.1 Introduction ...................................................................................................<br />
73<br />
3.2 Using the dsPIC Peripheral Libraries ...........................................................<br />
74<br />
3.3 External LCD Functions ...............................................................................<br />
74<br />
3.4 CAN Functions .............................................................................................<br />
81<br />
3.5 ADC12 Functions .........................................................................................<br />
95<br />
nhận.<br />
dsPIC<br />
®LANGUAGE CÔNG CỤ<br />
THƯ VIỆN<br />
2004 Microchip Technology Inc DS51456B trang iii<br />
Mục lục<br />
Lời nói đầu 1<br />
Chương 1 Thư viện Tổng quan<br />
1.1 Giới thiệu 7<br />
1.2 OMF-cụ thể thư viện / khởi động module .......................................... ...........<br />
7<br />
1.3 Startup Mã ............................................... .................................................. . 8<br />
1.4 DSP Thư viện ............................................... .................................................<br />
8 ...<br />
1,5 dsPIC Thư viện ngoại vi .............................................. ............................... 8<br />
1.6 Tiêu chuẩn C Thư viện (với các hàm toán học) .........................................<br />
.......... 8<br />
1,7 MPLAB C30 Built-in chức năng ...........................................<br />
............................ 8<br />
Chương 2 DSP Thư viện<br />
2.1 Giới thiệu 9<br />
2.2 Sử dụng thư viện DSP ............................................. .....................................<br />
10<br />
2.3 Chức năng Vector ............................................... ...........................................<br />
13<br />
2.4 Chức năng Window ............................................... ........................................<br />
26<br />
2.5 Chức năng Matrix ............................................... ...........................................<br />
31<br />
2.6 Chức năng lọc ............................................... ......................................... 38<br />
2.7 Chuyển đổi chức năng ............................................... ....................................<br />
58<br />
Chương 3: dsPIC Thư viện ngoại vi<br />
3.1 Giới thiệu ................................................ .................................................. .<br />
73<br />
3.2 Sử dụng thư viện dsPIC ngoại vi ............................................ ............... 74<br />
3.3 Chức năng màn hình LCD bên ngoài ..............................................<br />
................................. 74<br />
3.4 Chức năng CAN ............................................... .............................................<br />
81<br />
3,5 ADC12 Chức năng ............................................... .........................................<br />
95<br />
3.6 Chức năng ADC10 ............................................... ........................................<br />
102<br />
3.7 Chức năng hẹn giờ ............................................... ..........................................<br />
109<br />
Chức năng lập lại 3,8 / Control ............................................. ...............................
3.6 ADC10 Functions .......................................................................................<br />
102<br />
3.7 Timer Functions ..........................................................................................<br />
109<br />
3.8 Reset/Control Functions .............................................................................<br />
117<br />
3.9 I/O Port Functions ......................................................................................<br />
120<br />
3.10 Input Capture Functions ...........................................................................<br />
125<br />
3.11 Output Compare Functions ......................................................................<br />
131<br />
3.12 UART Functions .......................................................................................<br />
141<br />
3.13 DCI Functions ...........................................................................................<br />
150<br />
3.14 SPI Functions ...........................................................................................<br />
158<br />
3.15 QEI Functions ...........................................................................................<br />
166<br />
3.16 PWM Functions ........................................................................................<br />
171<br />
3.17 I2C Functions ...........................................................................................<br />
183<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page iv<br />
2004 Microchip Technology Inc.<br />
Chapter 4. Standard C Libraries with Math Functions<br />
4.1 Introduction .................................................................................................<br />
193<br />
4.2 Using the Standard C Libraries ..................................................................<br />
194<br />
4.3 diagnostics ...............................................................................<br />
195<br />
4.4 character handling .....................................................................<br />
196<br />
4.5 errors .........................................................................................<br />
205<br />
4.6 floating-point characteristics ........................................................<br />
206<br />
4.7 implementation-defined limits ....................................................<br />
211<br />
4.8 localization ................................................................................<br />
213<br />
4.9 non-local jumps .......................................................................<br />
214<br />
4.10 signal handling ........................................................................<br />
117<br />
3,9 I / O Port Chức năng ............................................ ..........................................<br />
120<br />
3.10 Input Capture chức năng .............................................. .............................<br />
125<br />
3.11 ra so sánh chức năng .............................................. ........................ 131<br />
3.12 Chức năng UART ............................................... ........................................<br />
141<br />
3.13 DCI chức năng ............................................... ............................................<br />
150<br />
3.14 SPI Chức năng ............................................... ............................................<br />
158<br />
3.15 QEI Chức năng ............................................... ............................................<br />
166<br />
3.16 Chức năng PWM ............................................... .........................................<br />
171<br />
3.17 I2C chức năng ............................................... ............................................<br />
183<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang iv<br />
2004 Microchip Technology Inc<br />
Chương 4 Thư viện chuẩn C với các hàm toán<br />
4.1 Giới thiệu ................................................ ................................................. 193<br />
4.2 Sử dụng thư viện chuẩn C ............................................ ...................... 194<br />
4.3 chẩn đoán ................................................. .............................. 195<br />
4.4 xử lý nhân vật ................................................ ..................... 196<br />
4.5 lỗi ................................................. ........................................ 205<br />
4.6 đặc điểm nổi .............................................. .......... 206<br />
4.7 giới hạn thực hiện xác định .............................................. ...... 211<br />
4.8 nội địa hóa ................................................. ............................... 213<br />
4.9 nhảy không địa phương .............................................. ......................... 214<br />
4.10 xử lý tín hiệu ................................................ ........................ 215<br />
4.11 danh sách đối số biến ............................................... ............ 221<br />
4.12 định nghĩa chung ................................................ ................ 223<br />
4.13 đầu vào và đầu ra ............................................... ......................... 225<br />
4.14 chức năng tiện ích ................................................ ......................... 270<br />
4.15 chức năng chuỗi ................................................ ........................ 294<br />
4.16 ngày và thời gian chức năng .............................................. ............... 317<br />
4.17 chức năng toán học ................................................ ............ 325<br />
4.18 pic30-libs .............................................. .................................................. 36<br />
..<br />
Chương 5 MPLAB C30 Built-in chức năng<br />
5.1 Giới thiệu ................................................ ................................................. 375
215<br />
4.11 variable argument lists ...........................................................<br />
221<br />
4.12 common definitions ................................................................<br />
223<br />
4.13 input and output ........................................................................<br />
225<br />
4.14 utility functions .........................................................................<br />
270<br />
4.15 string functions ........................................................................<br />
294<br />
4.16 date and time functions .............................................................<br />
317<br />
4.17 mathematical functions............................................................ 325<br />
4.18 pic30-libs ..................................................................................................<br />
366<br />
Chapter 5. MPLAB C30 Built-in Functions<br />
5.1 Introduction .................................................................................................<br />
375<br />
5.2 Built-In Function List ...................................................................................<br />
376<br />
5.3 Built-In Function Error Messages ...............................................................<br />
379<br />
Appendix A. ASCII Character Set<br />
.............................................................................381<br />
Index<br />
...........................................................................................................................383<br />
Worldwide Sales and Service<br />
...................................................................................400<br />
dsPIC<br />
®LANGUAGE TOOLS<br />
LIBRARIES<br />
2004 Microchip Technology Inc. DS51456B-page 1<br />
Preface<br />
INTRODUCTION<br />
The purpose of this document is to define and describe the libraries that are<br />
available<br />
for use with Microchip Technology’s dsPIC language tools, based on GCC<br />
(GNU<br />
Compiler Collection) technology. The related language tools are:<br />
•MPLAB®<br />
ASM30 Assembler<br />
• MPLAB C30 C Compiler<br />
• MPLAB LINK30 Linker<br />
• MPLAB LIB30 Archiver/Librarian<br />
• Other Utilities<br />
5.2 Built-In Danh sách Chức năng ............................................<br />
....................................... 376<br />
5.3 Tin nhắn Chức năng Lỗi Built-In ........................................... ....................<br />
379<br />
Phụ lục A. ASCII Character Set ............................................<br />
................................. 381<br />
Chỉ số<br />
...........................................................................................................................38<br />
Bán hàng trên toàn thế giới và Dịch vụ ..............................................<br />
..................................... 400<br />
dsPIC<br />
®LANGUAGE CÔNG CỤ<br />
THƯ VIỆN<br />
2004 Microchip Technology Inc DS51456B trang 1<br />
Lời nói đầu<br />
GIỚI THIỆU<br />
Mục đích của tài liệu này là để xác định và mô tả các thư viện có sẵn<br />
để sử dụng với các công cụ ngôn ngữ dsPIC của Microchip Technology, dựa<br />
trên GCC (GNU<br />
Bộ sưu tập) công nghệ biên dịch. Các công cụ ngôn ngữ liên quan là:<br />
• MPLAB®<br />
ASM30 Assembler<br />
• MPLAB C30 C Compiler<br />
• MPLAB LINK30 Linker<br />
• MPLAB LIB30 Archiver / Thư viện<br />
• Các tiện ích khác<br />
Mục thảo luận trong chương này bao gồm:<br />
• Về hướng dẫn này<br />
• Giới thiệu sách<br />
• Khắc phục sự cố<br />
• Các trang web Microchip<br />
• Hệ thống Phát triển Dịch vụ khách hàng thông báo thay đổi<br />
• Hỗ trợ khách hàng<br />
THÔNG BÁO CHO KHÁCH HÀNG<br />
Tất cả tài liệu trở nên lỗi thời, và sách hướng dẫn này cũng không ngoại<br />
lệ. Công cụ Microchip<br />
và các tài liệu liên tục phát triển để đáp ứng nhu cầu khách hàng, vì vậy một số<br />
thực tế<br />
hộp thoại và / hoặc mô tả cụ thể khác fromthose trong tài liệu này. Vui lòng<br />
tham khảo<br />
để trang web của chúng tôi (www.microchip.com) để có được những tài liệu<br />
mới nhất hiện có.<br />
Các tài liệu được xác định với một "DS" number.This số nằm ở phía dưới<br />
mỗi trang, ở phía trước của số trang. Công ước số cho DS
Items discussed in this chapter include:<br />
• About This Guide<br />
• Recommended Reading<br />
• Troubleshooting<br />
• The Microchip Web Site<br />
• Development Systems Customer Change Notification Service<br />
• Customer Support<br />
NOTICE TO CUSTOMERS<br />
All documentation becomes dated, and this manual is no exception. Microchip<br />
tools<br />
and documentation are constantly evolving to meet customer needs, so some<br />
actual<br />
dialogs and/or tool descriptions may differ fromthose in this document. Please<br />
refer<br />
to our web site (www.microchip.com) to obtain the latest documentation<br />
available.<br />
Documents are identified with a “DS” number.This number is located on the<br />
bottom<br />
of each page, in front of the page number. The numbering convention for the<br />
DS<br />
number is “DSXXXXXA”, where “XXXXX” isthe document number and “A”<br />
is the<br />
revision level of the document.<br />
For the most up-to-date information on development tools, see the MPLAB IDE<br />
on-line help. Select the Help menu, and then Topics to open a list of available<br />
on-line<br />
help files.<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
số là "DSXXXXXA", trong đó "XXXXX" isthe số tài liệu và "A" là<br />
mức độ sửa đổi của tài liệu.<br />
Đối với các thông tin mới nhất được cập nhật lên công cụ phát triển, xem<br />
MPLAB IDE<br />
giúp đỡ trên mạng. Chọn menu Help, và sau đó chủ đề để mở một danh sách có<br />
sẵn trên mạng<br />
tập tin trợ giúp.<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 2<br />
VỀ HƯỚNG DẪN NÀY<br />
Giao diện tài liệu<br />
2004 Microchip Technology Inc<br />
Tài liệu này mô tả làm thế nào để sử dụng công cụ ngôn ngữ GNU để viết mã<br />
cho dsPIC<br />
®<br />
ứng dụng vi điều khiển. Cách bố trí tài liệu như sau:<br />
• Chương 1: Thư viện Overview- đưa ra một cái nhìn tổng quan của các thư<br />
viện.<br />
• Chương 2: DSP Library- liệt kê các chức năng thư viện cho các hoạt động<br />
DSP.<br />
• Chương 3: Thiết bị ngoại vi dsPIC Libraries- liệt kê các chức năng thư viện và<br />
macro cho<br />
phần mềm điện thoại dsPIC và phần cứng hoạt động ngoại vi.<br />
• Chương 4: Thư viện chuẩn C với Toán Functions- liệt kê các chức năng thư<br />
viện<br />
và macro cho hoạt động C chuẩn.<br />
• Chương 5: MPLAB C30 Built-in Functions- liệt kê các chức năng tích hợp củ<br />
C<br />
biên dịch, MPLAB C30.<br />
Lời nói đầu<br />
DS51456B-page 2<br />
2004 Microchip Technology Inc.<br />
2004 Microchip Technology Inc DS51456B trang 3<br />
ABOUT THIS GUIDE<br />
Document Layout<br />
This document describes how to use GNU language tools to write code for<br />
dsPIC<br />
®<br />
microcontroller applications. The document layout is as follows:<br />
• Chapter 1: Library Overview– gives an overview of libraries.<br />
• Chapter 2: DSP Library– lists the library functions for DSP operation.<br />
• Chapter 3: dsPIC Peripherals Libraries– lists the library functions and macros<br />
for<br />
dsPIC device software and hardware peripheral operation.<br />
• Chapter 4: Standard C Library with Math Functions– lists the library functions<br />
Ước sử dụng trong hướng dẫn này<br />
Hướng dẫn này sử dụng các công ước tài liệu sau đây:<br />
ƯỚC TÀI LIỆU<br />
Mô tả Đại diện Ví dụ<br />
Font Arial:<br />
Hướng dẫn nhân vật nghiêng sách Tham chiếu MPLAB IDE của người sử dụng<br />
Văn bản nhấn mạnh ... là onlycompiler ...<br />
Mũ ban đầu Một cửa sổ cửa sổ Output<br />
Một hộp thoại hộp thoại Settings<br />
Một lựa chọn trình đơn chọn Enable Lập trình viên<br />
Giá Một tên trường trong một cửa sổ hoặc
and macros for standard C operation.<br />
• Chapter 5: MPLAB C30 Built-in Functions– lists the built-in functions of the<br />
C<br />
compiler, MPLAB C30.<br />
Preface<br />
2004 Microchip Technology Inc. DS51456B-page 3<br />
Conventions Used in this Guide<br />
This manual uses the following documentation conventions:<br />
DOCUMENTATION CONVENTIONS<br />
Description Represents Examples<br />
Arial font:<br />
Italic characters Referenced books MPLAB IDE User’s Guide<br />
Emphasized text ...is the onlycompiler...<br />
Initial caps A window the Output window<br />
A dialog the Settings dialog<br />
A menu selection select Enable Programmer<br />
Quotes A field name in a window or<br />
dialog<br />
“Save project before build”<br />
Underlined, italic text with<br />
right angle bracket<br />
A menu path File>Save<br />
Bold characters A dialog button ClickOK<br />
A tab Click the Powertab<br />
‘bnnnn A binary number where nis a<br />
digit<br />
‘b00100, ‘b10<br />
Text in angle brackets < > A key on the keyboard Press , <br />
Courier font:<br />
Plain Courier Sample source code #define START<br />
Filenames autoexec.bat<br />
File paths c:\mcc18\h<br />
Keywords _asm, _endasm, static<br />
Command-line options -Opa+, -OpaBit values 0, 1<br />
Italic Courier A variable argument file.o, where filecan be<br />
any valid filename<br />
0xnnnn A hexadecimal number where<br />
nis a hexadecimal digit<br />
0xFFFF, 0x007A<br />
thoại<br />
"Lưu dự án trước khi xây dựng"<br />
Gạch chân, in nghiêng với<br />
khung góc bên phải<br />
Một con đường menu File> Save<br />
Một nhân vật đậm ClickOK nút thoại<br />
Một tab Nhấp vào PowerTab<br />
'Bnnnn Một số nhị phân, nơi một NIS<br />
chữ số<br />
'B00100,' b10<br />
Văn bản trong dấu ngoặc nhọn Một phím trên bàn phím Nhấn ,<br />
Phông chữ Courier:<br />
Đồng bằng chuyển phát nhanh Mẫu mã nguồn # xác định BẮT ĐẦU<br />
Tên tập tin autoexec.bat<br />
File đường dẫn C: \ mcc18 \ h<br />
Từ khóa _asm, _endasm, tĩnh<br />
Tùy chọn dòng lệnh -Opa +, -OpaBit giá trị 0, 1<br />
Nghiêng Courier Một lập luận biến file.o, nơi filecan được<br />
bất cứ tên tập tin hợp lệ<br />
0xnnnn Một số hệ thập lục phân nơi<br />
NIS một chữ số thập lục phân<br />
0xFFFF, 0x007A<br />
Dấu ngoặc vuông [] đối số tùy chọn mcc18 [tùy chọn] tập tin<br />
[Tùy chọn]<br />
Dấu ngoặc nhọn và ống<br />
nhân vật: {|}<br />
Lựa chọn loại trừ lẫn nhau<br />
lập luận; một lựa chọn hoặc<br />
errorlevel {0 | 1}<br />
Bầu dục ... thay thế lặp đi lặp lại var_name văn bản [,<br />
var_name ...]<br />
Đại diện cho mã được cung cấp bởi<br />
người sử dụng<br />
void main (void)<br />
{...<br />
}<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ
Square brackets [ ] Optional arguments mcc18 [options] file<br />
[options]<br />
Curly brackets and pipe<br />
character: { | }<br />
Choice of mutually exclusive<br />
arguments; an OR selection<br />
errorlevel {0|1}<br />
Ellipses... Replaces repeated text var_name [,<br />
var_name...]<br />
Represents code supplied by<br />
user<br />
void main (void)<br />
{ ...<br />
}<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B trang 4<br />
ĐỌC ĐỀ NGHỊ<br />
2004 Microchip Technology Inc<br />
Tài liệu này mô tả chức năng thư viện dsPIC và các macro. Để biết thêm thông<br />
tin về<br />
dsPIC công cụ ngôn ngữ và sử dụng các công cụ khác, sau đây được khuyến cá<br />
đọc:<br />
README tập tin<br />
Đối với các thông tin mới nhất về các công cụ vi mạch, đọc các tập tin<br />
README liên quan (ASCII<br />
tập tin văn bản) kèm với phần mềm.<br />
Bắt đầu với dsPIC bằng các ngôn ngữ (DS51316)<br />
Hướng dẫn cài đặt và làm việc với các công cụ ngôn ngữ Microchip (MPLAB<br />
ASM30,<br />
MPLAB LINK30 và MPLAB C30) cho dsPIC điều khiển tín hiệu số (DSC của)<br />
Ví dụ bằng cách sử dụng mô phỏng dsPIC, MPLAB SIM30, được cung cấp.<br />
Hướng dẫn MPLAB ASM30, MPLAB LINK30 và tiện ích của người sử dụng<br />
(DS51317)<br />
Hướng dẫn sử dụng để lắp ráp dsPIC DSC, MPLAB ASM30, dsPIC DSC mối<br />
liên kết,<br />
MPLAB LINK30 và tiện ích DSC dsPIC khác nhau, bao gồm MPLAB LIB30<br />
DS51456B-page 4<br />
2004 Microchip Technology Inc.<br />
Archiver / thư viện.<br />
RECOMMENDED READING<br />
This document describes dsPIC library functions and macros. For more<br />
information on<br />
dsPIC language tools and the use of other tools, the following are recommended<br />
reading:<br />
README Files<br />
For the latest information on Microchip tools, read the associated README<br />
files (ASCII<br />
text files) included with the software.<br />
Getting Started with dsPIC Language Tools (DS51316)<br />
A guide to installing and working with the Microchip language tools (MPLAB<br />
ASM30,<br />
MPLAB LINK30 and MPLAB C30) for dsPIC digital signal controllers<br />
(DSC’s).<br />
Examples using the dsPIC simulator, MPLAB SIM30, are provided.<br />
MPLAB ASM30, MPLAB LINK30 and Utilities User's Guide (DS51317)<br />
A guide to using the dsPIC DSC assembler, MPLAB ASM30, dsPIC DSC<br />
linker,<br />
MPLAB LINK30 and various dsPIC DSC utilities, including MPLAB LIB30<br />
archiver/librarian.<br />
MPLAB C30 C Compiler User's Guide (DS51284)<br />
A guide to using the dsPIC DSC C compiler. MPLAB LINK30 is used with this<br />
tool.<br />
GNU HTML documentation<br />
Hướng dẫn MPLAB C30 C Compiler của người sử dụng (DS51284)<br />
Hướng dẫn sử dụng trình biên dịch C dsPIC DSC. MPLAB LINK30 được sử<br />
dụng với công cụ này.<br />
Tài liệu GNU HTML<br />
Tài liệu này được cung cấp trên các công cụ ngôn ngữ CD-ROM. Nó mô tả các<br />
công cụ phát triển tiêu chuẩn GNU, khi mà những công cụ này được dựa.<br />
dsPIC30F gia đình Tổng quan (DS70043)<br />
Tổng quan về các thiết bị và kiến trúc dsPIC30F.<br />
Reference Manual dsPIC30F Lập trình (DS70030)<br />
Hướng dẫn lập trình để thiết bị dsPIC30F. Bao gồm mô hình của lập trình viên<br />
và<br />
hướng dẫn thiết lập.<br />
Trang web Microchip<br />
Các trang web của Microchip (http://www.microchip.com) có chứa một sự giàu<br />
có của<br />
tài liệu hướng dẫn. Bảng dữ liệu cá nhân, ứng dụng ghi chú, hướng dẫn và<br />
hướng dẫn sử dụng<br />
tất cả đều có sẵn để dễ dàng tải về. Tất cả tài liệu trong Adobe Acrobat (<strong>pdf</strong>)<br />
định dạng.<br />
Giải đáp thắc mắc<br />
Xem READMEfiles thông tin về các vấn đề chung không được giải quyết trong<br />
này<br />
tài liệu.<br />
Lời nói đầu
This documentation is provided on the language tool CD-ROM. It describes the<br />
standard GNU development tools, upon which these tools are based.<br />
dsPIC30F Family Overview (DS70043)<br />
An overview of the dsPIC30F devices and architecture.<br />
dsPIC30F Programmer’s Reference Manual (DS70030)<br />
Programmer’s guide to dsPIC30F devices. Includes the programmer’s model<br />
and<br />
instruction set.<br />
Microchip Web Site<br />
The Microchip web site (http://www.microchip.com) contains a wealth of<br />
documentation. Individual data sheets, application notes, tutorials and user’s<br />
guides<br />
are all available for easy download. All documentation is in Adobe Acrobat<br />
(<strong>pdf</strong>) format.<br />
TROUBLESHOOTING<br />
See the READMEfiles for information on common problems not addressed in<br />
this<br />
document.<br />
Preface<br />
2004 Microchip Technology Inc. DS51456B-page 5<br />
THE MICROCHIP WEB SITE<br />
Microchip provides online support via our WWW site at www.microchip.com.<br />
This web<br />
site is used as a means to make files and information easily available to<br />
customers.<br />
Accessible by using your favorite Internet browser, the web site contains the<br />
following<br />
information:<br />
• Product Support– Data sheets and errata, application notes and sample<br />
programs, design resources, user’s guides and hardware support documents,<br />
latest software releases and archived software<br />
• General Technical Support– Frequently Asked Questions (FAQ), technical<br />
support requests, online discussion groups, Microchip consultant program<br />
member listing<br />
• Business of Microchip– Product selector and ordering guides, latest Microchip<br />
press releases, listing of seminars and events, listings of Microchip sales offices,<br />
distributors and factory representatives<br />
DEVELOPMENT SYSTEMS CUSTOMER CHANGE NOTIFICATION<br />
SERVICE<br />
Microchip’s customer notification service helps keep customers current on<br />
Microchip<br />
products. Subscribers will receive e-mail notification whenever there are<br />
changes,<br />
2004 Microchip Technology Inc DS51456B trang 5<br />
THE vi mạch WEBSITE<br />
Microchip cung cấp hỗ trợ trực tuyến thông qua trang web cá nhân của chúng<br />
tôi tại www.microchip.com. Web này<br />
trang web được sử dụng như một phương tiện để làm cho các tập tin và thông<br />
tin dễ dàng có sẵn cho khách hàng.<br />
Truy cập bằng cách sử dụng trình duyệt Internet yêu thích của bạn, các trang<br />
web có chứa những điều sau đây<br />
thông tin:<br />
• Sản phẩm tấm Support dữ liệu và errata, ứng dụng ghi chú và mẫu<br />
các chương trình, nguồn lực thiết kế, hướng dẫn sử dụng và các tài liệu hỗ trợ<br />
phần cứng,<br />
phiên bản phần mềm mới nhất và phần mềm lưu trữ<br />
• Tổng kỹ thuật Support câu hỏi thường gặp (FAQ), kỹ thuật<br />
yêu cầu hỗ trợ, các nhóm thảo luận trực tuyến, chương trình tư vấn Microchip<br />
danh sách thành viên<br />
• kinh doanh của Vi mạch chọn sản phẩm và đặt hàng hướng dẫn, vi mạch mới<br />
nhất<br />
thông cáo báo chí, danh sách các cuộc hội thảo và các sự kiện, danh sách các vi<br />
mạch văn phòng kinh doanh,<br />
các nhà phân phối và đại diện nhà máy<br />
HỆ THỐNG PHÁT TRIỂN KHÁCH HÀNG DỊCH VỤ THAY ĐỔI THÔNG<br />
BÁO<br />
Dịch vụ thông báo khách hàng của Microchip giúp giữ khách hàng hiện tại về v<br />
mạch<br />
sản phẩm. Thuê bao sẽ nhận được thông báo e-mail bất cứ khi nào có sự thay<br />
đổi,<br />
cập nhật, sửa đổi hoặc errata liên quan đến một gia đình phát triển sản phẩm<br />
hoặc công cụ định<br />
quan tâm.<br />
Để đăng ký, truy cập vào trang web của Microchip tại www.microchip.com, hã<br />
nhấp vào khách hàng<br />
Thay đổi Thông báo và làm theo hướng dẫn đăng ký.<br />
Các hệ thống phát triển loại nhóm sản phẩm là:<br />
• Compilers- Các thông tin mới nhất về các trình biên dịch Microchip C và ngô<br />
ngữ khác<br />
công cụ. Chúng bao gồm các MPLAB C17, MPLAB C18 và MPLAB C30 C<br />
trình biên dịch;<br />
Lắp ráp MPASM và MPLAB ASM30; MPLINK và MPLAB LINK30<br />
Các mối liên kết đối tượng; và MPLIB và MPLAB LIB30 đối tượng thư<br />
viện.<br />
• Emulators- Các thông tin mới nhất về Microchip emulators.This trong mạch<br />
bao gồm ICE 4000 MPLAB ICE 2000 và MPLAB.<br />
• In-Circuit Debuggers- Các thông tin mới nhất về vi mạch trong mạch<br />
gỡ rối, MPLAB ICD 2.<br />
• MPLAB IDE- Các thông tin mới nhất về Microchip MPLAB IDE, Windows
updates, revisions or errata related to a specified product family or development<br />
tool of<br />
interest.<br />
To register, access the Microchip web site at www.microchip.com, click on<br />
Customer<br />
Change Notification and follow the registration instructions.<br />
The Development Systems product group categories are:<br />
• Compilers– The latest information on Microchip C compilers and other<br />
language<br />
tools. These include the MPLAB C17, MPLAB C18 and MPLAB C30 C<br />
compilers;<br />
MPASM and MPLAB ASM30 assemblers; MPLINK and MPLAB<br />
LINK30<br />
object linkers; and MPLIB and MPLAB LIB30 object librarians.<br />
• Emulators– The latest information on Microchip in-circuit emulators.This<br />
includes the MPLAB ICE 2000 and MPLAB ICE 4000.<br />
• In-Circuit Debuggers– The latest information on the Microchip in-circuit<br />
debugger, MPLAB ICD 2.<br />
• MPLAB IDE– The latest information on Microchip MPLAB IDE, the<br />
Windows<br />
®<br />
Integrated Development Environment for development systems tools. This list<br />
is<br />
focused on the MPLAB IDE, MPLAB SIM and MPLAB SIM30 simulators,<br />
MPLAB<br />
IDE Project Manager and general editing and debugging features.<br />
• Programmers– The latest information on Microchip programmers. These<br />
include<br />
the MPLAB PM3 and PRO MATE<br />
®<br />
II device programmers and the PICSTART<br />
®<br />
Plus development programmer.<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
®<br />
Môi trường phát triển tích hợp cho các hệ thống công cụ phát triển. Danh sách<br />
này là<br />
tập trung vào các IDE MPLAB, MPLAB SIM và MPLAB SIM30 mô phỏng,<br />
MPLAB<br />
IDE Quản lý dự án và chỉnh sửa và gỡ lỗi các tính năng nói chung.<br />
• Programmers- Các thông tin mới nhất về lập trình vi mạch. Chúng bao gồm<br />
MPLAB PM3 và PRO MATE<br />
®<br />
Lập trình thiết bị II và Picstart<br />
®<br />
Cộng với lập trình viên phát triển.<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 6<br />
HỖ TRỢ KHÁCH HÀNG<br />
2004 Microchip Technology Inc<br />
Người sử dụng các sản phẩm vi mạch có thể nhận được hỗ trợ thông qua một số<br />
kênh:<br />
• Nhà phân phối hoặc đại diện<br />
• Văn phòng kinh doanh địa phương<br />
• Kỹ sư ứng dụng Field (FAE)<br />
• Hỗ trợ kỹ thuật<br />
• Phát triển hệ thống thông tin đường<br />
Khách hàng nên liên hệ với nhà phân phối, đại diện, lĩnh vực kỹ sư ứng dụng<br />
của họ<br />
(FAE) để hỗ trợ. Văn phòng kinh doanh tại địa phương cũng có sẵn để giúp<br />
khách hàng. Một danh sách các<br />
văn phòng bán hàng và các địa điểm được bao gồm trong phần sau của tài liệu<br />
này.<br />
Hỗ trợ kỹ thuật có sẵn thông qua trang web tại địa chỉ:<br />
http://support.microchip.com<br />
Ngoài ra, có một Hệ thống Thông tin Phát triển dòng trong đó liệt kê mới nhất<br />
các phiên bản của hệ thống sản phẩm phần mềm phát triển của vi mạch. Đây là<br />
đường<br />
cung cấp thông tin về cách khách hàng có thể nhận được bộ dụng cụ nâng cấp<br />
hiện có.<br />
DS51456B-page 6<br />
2004 Microchip Technology Inc.<br />
Các con số Hệ thống thông tin phát triển dòng là:<br />
CUSTOMER SUPPORT<br />
Users of Microchip products can receive assistance through several channels:<br />
• Distributor or Representative<br />
• Local Sales Office<br />
• Field Application Engineer (FAE)<br />
• Technical Support<br />
1-800-755-2345 - Hoa Kỳ và hầu hết Canada<br />
1-480-792-7302 - Địa điểm quốc tế khác<br />
dsPIC<br />
®LANGUAGE CÔNG CỤ<br />
THƯ VIỆN<br />
2004 Microchip Technology Inc DS51456B trang 7
• Development Systems Information Line<br />
Customers should contact their distributor, representative or field application<br />
engineer<br />
(FAE) for support. Local sales offices are also available to help customers. A<br />
listing of<br />
sales offices and locations is included in the back of this document.<br />
Technical support is available through the web site at:<br />
http://support.microchip.com<br />
In addition, there is a Development Systems Information Line which lists the<br />
latest<br />
versions of Microchip's development systems software products. This line also<br />
provides information on how customers can receive currently available upgrade<br />
kits.<br />
The Development Systems Information Line numbers are:<br />
1-800-755-2345 – United States and most of Canada<br />
1-480-792-7302 – Other International Locations<br />
dsPIC<br />
®LANGUAGE TOOLS<br />
LIBRARIES<br />
2004 Microchip Technology Inc. DS51456B-page 7<br />
Chapter 1. Library Overview<br />
1.1 INTRODUCTION<br />
A library is a collection of functions grouped for reference and ease of linking.<br />
See the<br />
MPLAB ASM30, MPLAB LINK30 and Utilities User's Guidefor more<br />
information about<br />
making and using libraries.<br />
1.1.1 Assembly Code Applications<br />
Free versions of the dsPIC language tool libraries are available from the<br />
Microchip web<br />
site. DSP and dsPIC peripheral libraries are provided with object files and<br />
source code.<br />
A math library containing functionsfrom the standard C header file is<br />
provided as an object file only. The completestandard C library is provided with<br />
the<br />
MPLAB C30 C compiler.<br />
1.1.2 C Code Applications<br />
The dsPIC language tool libraries are included in the c:\pic30_tools\lib<br />
directory, where c:\pic30_toolsis the MPLAB C30 C compiler install directory.<br />
These can be linked directly into an application with MPLAB LINK30.<br />
1.1.3 Chapter Organization<br />
This chapter is organized as follows:<br />
• OMF-Specific Libraries/StarTup Modules<br />
Chương 1 Thư viện Tổng quan<br />
1.1 GIỚI THIỆU<br />
Một thư viện là một tập hợp các chức năng được nhóm lại để tham khảo và dễ<br />
dàng liên kết. Xem<br />
MPLAB ASM30, MPLAB LINK30 và Guidefor tiện ích của người sử dụng<br />
thêm thông tin về<br />
lập và sử dụng thư viện.<br />
1.1.1 ứng dụng Mã hội<br />
Phiên bản miễn phí của các thư viện công cụ ngôn ngữ dsPIC có sẵn từ các<br />
trang web Microchip<br />
trang web. DSP và dsPIC thư viện ngoại vi được cung cấp với các tập tin đối<br />
tượng và mã nguồn.<br />
Một thư viện toán học có chứa functionsfrom tiêu chuẩn tập tin C tiêu đề là<br />
cung cấp như một tập tin duy nhất đối tượng. Thư viện completestandard C<br />
được cung cấp cùng với<br />
Trình biên dịch MPLAB C30 C.<br />
1.1.2 ứng dụng C Mã<br />
Các thư viện công cụ ngôn ngữ dsPIC có trong c: \ pic30_tools \ lib<br />
thư mục, trong đó c: \ pic30_toolsis trình biên dịch MPLAB C30 C thư mục cài<br />
đặt.<br />
Đây có thể được liên kết trực tiếp vào một ứng dụng với MPLAB LINK30.<br />
1.1.3 Tổ chức Chương<br />
Chương này được tổ chức như sau:<br />
• OMF-cụ thể thư viện / khởi động mô-đun<br />
• Startup Mã<br />
• Thư viện DSP<br />
• Thư viện ngoại vi dsPIC<br />
• Tiêu chuẩn C Thư viện (với các hàm toán học)<br />
• MPLAB C30 Built-in chức năng<br />
THƯ VIỆN 1.2 OMF-CỤ THỂ / MODULES STARTUP<br />
Tập tin thư viện và mô-đun khởi động là OMF specificto (Object Định dạng<br />
Module). Một OMF<br />
có thể là một trong các cách sau:<br />
• COFF - Đây là mặc định.<br />
• ELF - Các định dạng được sử dụng để gỡ lỗi các tập tin đối tượng là ELF lùn<br />
2.0.<br />
Có hai cách để chọn OMF:<br />
1 Đặt biến môi trường được gọi là PIC30_OMFfor tất cả các công cụ.<br />
2. Chọn OMF trên dòng lệnh khi envoking công cụ, ví dụ, -omf = omfor<br />
-momf = OMF.<br />
công cụ dsPIC đầu tiên sẽ tìm kiếm tập tin thư viện chung khi xây dựng ứng<br />
dụng của bạn (không OMF<br />
đặc điểm kỹ thuật). Nếu những điều này không thể được tìm thấy, công cụ sẽ<br />
xem xét chi tiết kỹ thuật của bạn OMF
• Startup Code<br />
• DSP Library<br />
• dsPIC Peripheral Libraries<br />
• Standard C Libraries (with Math Functions)<br />
• MPLAB C30 Built-in Functions<br />
1.2 OMF-SPECIFIC LIBRARIES/STARTUP MODULES<br />
Library files and startup modules are specificto OMF (Object Module Format).<br />
An OMF<br />
can be one of the following:<br />
• COFF - This is the default.<br />
• ELF - The debugging format used for ELF object files is DWARF 2.0.<br />
There are two ways to select the OMF:<br />
1. Set an environment variable called PIC30_OMFfor all tools.<br />
2. Select the OMF on the command line when envoking the tool, i.e., -<br />
omf=omfor<br />
-momf=omf.<br />
dsPIC tools will first look for generic library files when building your<br />
application (no OMF<br />
specification). If these cannot be found, the tools will look at your OMF<br />
specifications<br />
and determine which library file to use.<br />
As an example, if libdsp.ais not found and no environment variable or<br />
command-line opton is set, the file libdsp-coff.awill be used by default.<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 8<br />
1.3 STARTUP CODE<br />
2004 Microchip Technology Inc.<br />
In order to initialize variables in data memory, the linker creates a data<br />
initialization<br />
template. This template must be processed at startup, before the application<br />
proper<br />
takes control. For C programs, this function is performed by the startup modules<br />
in<br />
libpic30-coff.a (either crt0.oor crt1.o) or libpic30-elf.a (either<br />
crt0.eoor crt1.eo). Assembly language programs can utilize these modules<br />
directly by linking with the desired startup module file. The source code for the<br />
startup<br />
modules is provided in corresponding .sfiles.<br />
The primary startup module (crt0) initializes all variables (variables without<br />
initializers<br />
are set to zero as required by the ANSI standard) except for variables in the<br />
persistent<br />
và xác định các tập tin thư viện để sử dụng.<br />
Ví dụ, nếu libdsp.ais không tìm thấy và không có biến môi trường hoặc<br />
dòng lệnh opton được thiết lập, các tập tin libdsp-coff.awill được sử dụng theo<br />
mặc định.<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 8<br />
1.3 STARTUP MÃ<br />
2004 Microchip Technology Inc<br />
Để khởi tạo các biến trong bộ nhớ dữ liệu, các mối liên kết tạo ra một khởi tạo<br />
dữ liệu<br />
mẫu. Mẫu này phải được xử lý lúc khởi động, trước khi áp dụng thích hợp<br />
mất quyền kiểm soát. Đối với chương trình C, chức năng này được thực hiện<br />
bằng các bộ phận khởi động trong<br />
libpic30-coff.a (hoặc crt1.o crt0.oor) hoặc libpic30-elf.a (hoặc<br />
crt0.eoor crt1.eo). Các chương trình ngôn ngữ lắp ráp có thể sử dụng các môđun<br />
trực tiếp bằng cách liên kết với các tập tin khởi động mô-đun mong muốn. Các<br />
mã nguồn cho khởi động<br />
module được cung cấp trong .sfiles tương ứng.<br />
Các mô-đun khởi động chính (crt0) khởi tạo tất cả các biến (biến mà không cần<br />
khởi tạo<br />
được thiết lập để không theo yêu cầu của tiêu chuẩn ANSI), trừ các biến trong<br />
dai dẳng<br />
phần dữ liệu. Các mô-đun khởi động thay thế (crt1) không thực hiện khởi tạo dữ<br />
liệu.<br />
Để biết thêm về mã khởi động, xem MPLAB ASM30, MPLAB LINK30 và tiện<br />
ích của người sử dụng<br />
Guideand, cho các ứng dụng C, hướng dẫn người sử dụng MPLAB C30 C<br />
Compiler.<br />
1.4 DSP THƯ VIỆN<br />
Thư viện DSP (libdsp-omf.a) cung cấp một tập hợp các hoạt động xử lý tín hiệu<br />
kỹ thuật số để một chương trình mục tiêu để thực hiện trên một dsPIC30F điều<br />
khiển tín hiệu số (DSC).<br />
Tổng cộng, 49 chức năng được hỗ trợ bởi các thư viện DSP.<br />
1,5 dsPIC PERIPHERAL THƯ VIỆN<br />
Các dsPIC (phần mềm và phần cứng) peripherallibraries cung cấp chức năng và<br />
macro<br />
lập và kiểm soát thiết bị ngoại vi dsPIC30F DSC. Ví dụ về sử dụng cũng có<br />
cung cấp trong mỗi chương liên quan đến cuốn sách này.<br />
Các thư viện này là bộ xử lý cụ thể và các hình thức libpDevice-omf.a, nơi<br />
Thiết bị = dsPIC số thiết bị (ví dụ, libp30F6014-coff.afor các dsPIC30F6014<br />
thiết bị.)<br />
1.6 TIÊU CHUẨN THƯ VIỆN C (với các hàm toán)<br />
Một bộ hoàn chỉnh của ANSI-89 thư viện phù hợp được cung cấp. Các tiêu<br />
chuẩn thư viện C<br />
tập tin được libc-omf.a (được viết bởi Dinkumware, một nhà lãnh đạo ngành
data section. The alternate startup module (crt1) performs no data initialization.<br />
For more on startup code, see the MPLAB ASM30, MPLAB LINK30 and<br />
Utilities User’s<br />
Guideand, for C applications, the MPLAB C30 C Compiler User’s Guide.<br />
1.4 DSP LIBRARY<br />
The DSP library (libdsp-omf.a) provides a set of digital signal processing<br />
operations to a program targeted for execution on a dsPIC30F digital signal<br />
controller (DSC).<br />
In total, 49 functions are supported by the DSP Library.<br />
1.5 dsPIC PERIPHERAL LIBRARIES<br />
The dsPIC (software and hardware) peripherallibraries provide functions and<br />
macros<br />
for setting up and controlling dsPIC30F DSC peripherals. Examples of use are<br />
also<br />
provided in each related chapter of this book.<br />
These libraries are processor-specific and of the form libpDevice-omf.a, where<br />
Device= dsPIC device number (e.g., libp30F6014-coff.afor the dsPIC30F6014<br />
device.)<br />
1.6 STANDARD C LIBRARIES (WITH MATH FUNCTIONS)<br />
A complete set of ANSI-89 conforming libraries are provided. The standard C<br />
library<br />
files are libc-omf.a(written by Dinkumware, an industry leader) and libm-omf.a<br />
(math functions, written by Microchip.)<br />
Additionally, some dsPIC standard C library helper functions, and standard<br />
functions<br />
that must be modified for use with dsPIC devices, are in libpic30-omf.a.<br />
A typical C application will require all three libraries.<br />
1.7 MPLAB C30 BUILT-IN FUNCTIONS<br />
The MPLAB C30 C compiler contains built-in functions that, to the developer,<br />
work like<br />
library functions.<br />
dsPIC<br />
®LANGUAGE TOOLS<br />
LIBRARIES<br />
2004 Microchip Technology Inc. DS51456B-page 9<br />
Chapter 2. DSP Library<br />
2.1 INTRODUCTION<br />
The DSP Library provides a set of digital signal processing operations to a<br />
program targeted for execution on a dsPIC30F digital signalcontroller (DSC).<br />
The library has been<br />
designed to provide you, the C software developer, with efficient<br />
implementation of the<br />
most common signal processing functions. In total, 49 functions are supported<br />
by the<br />
công nghiệp) và libm-omf.a<br />
(Chức năng toán học, được viết bởi Microchip.)<br />
Ngoài ra, một số tiêu chuẩn dsPIC chức năng trợ giúp thư viện C, và các chức<br />
năng tiêu chuẩn<br />
đó phải được sửa đổi để sử dụng với các thiết bị dsPIC, trong libpic30-omf.a.<br />
Một ứng dụng điển hình C sẽ yêu cầu tất cả ba thư viện.<br />
1,7 MPLAB C30 chức năng được xây dựng-IN<br />
Trình biên dịch MPLAB C30 C có tích hợp chức năng đó, để phát triển, làm<br />
việc như thế<br />
chức năng thư viện.<br />
dsPIC<br />
®LANGUAGE CÔNG CỤ<br />
THƯ VIỆN<br />
2004 Microchip Technology Inc DS51456B trang 9<br />
Chương 2 DSP Thư viện<br />
2.1 GIỚI THIỆU<br />
Thư viện DSP cung cấp một tập hợp các hoạt động xử lý tín hiệu kỹ thuật số để<br />
một chương trình mục tiêu để thực hiện trên một số signalcontroller dsPIC30F<br />
(DSC). Các thư viện đã được<br />
được thiết kế để cung cấp cho bạn, các nhà phát triển phần mềm C, với việc<br />
thực hiện có hiệu quả các<br />
hầu hết các chức năng xử lý tín hiệu thông thường. Tổng cộng, 49 chức năng<br />
được hỗ trợ bởi<br />
Thư viện DSP.<br />
Mục tiêu hàng đầu của thư viện là để giảm thiểu thời gian thực hiện từng chức<br />
năng. Để<br />
đạt được mục tiêu này, Thư viện DSP chủ yếu viết bằng lắp ráp tối ưu hóa<br />
ngôn ngữ. Bằng cách sử dụng thư viện DSP, bạn có thể nhận ra lợi ích quan<br />
trọng trong thực hiện<br />
tốc độ trên mã tương đương viết bằng ANSI C.Additionally, kể từ khi Thư viện<br />
DSP có<br />
được thử nghiệm chặt chẽ, sử dụng thư viện DSP sẽ cho phép bạn rút ngắn ứng<br />
dụng của bạn<br />
thời gian phát triển.<br />
2.1.1 ứng dụng Mã hội<br />
Một phiên bản miễn phí của thư viện này và tập tin tiêu đề liên quan của nó có<br />
sẵn từ<br />
Trang web của Microchip. Mã nguồn được bao gồm.<br />
2.1.2 ứng dụng C Mã<br />
Trình biên dịch MPLAB C30 C thư mục cài đặt (C: \ pic30_tools) chứa các<br />
thư mục con với các tập tin thư viện liên quan sau đây:<br />
• thư viện DSP lib- / lưu trữ các tập tin<br />
• src \ dsp- mã nguồn cho các chức năng thư viện và một tập tin thực thi để xây<br />
dựng lại thư viện<br />
• Hỗ trợ \ h- tập tin tiêu đề cho thư viện DSP
DSP Library.<br />
A primary goal of the library is to minimize the execution time of each function.<br />
To<br />
achieve this goal, the DSP Library is predominantly written in optimized<br />
assembly<br />
language. By using the DSP Library, you can realize significant gains in<br />
execution<br />
speed over equivalent code written in ANSI C.Additionally, since the DSP<br />
Library has<br />
been rigorously tested, using the DSP Library will allow you to shorten your<br />
application<br />
development time.<br />
2.1.1 Assembly Code Applications<br />
A free version of this library and its associated header file is available from the<br />
Microchip web site. Source code is included.<br />
2.1.2 C Code Applications<br />
The MPLAB C30 C compiler install directory (c:\pic30_tools) contains the<br />
following subdirectories with library-related files:<br />
• lib– DSP library/archive files<br />
• src\dsp– source code for library functions and a batch file to rebuild the library<br />
• support\h– header file for DSP library<br />
2.1.3 Chapter Organization<br />
This chapter is organized as follows:<br />
• Using the DSP Library<br />
• Vector Functions<br />
• Window Functions<br />
• Matrix Functions<br />
• Filtering Functions<br />
• Transform Functions<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 10<br />
2.2 USING THE DSP LIBRARY<br />
2.2.1 Building with the DSP Library<br />
2004 Microchip Technology Inc.<br />
Building an application which utilizes the DSP Library requires only two files:<br />
dsp.h<br />
and libdsp-omf.a. dsp.his a header file which provides all the function<br />
prototypes,<br />
#definesand typedefsused by the library. libdsp-omf.ais the archived library<br />
file which contains all the individual object files for each library function. (See<br />
Section 1.2 “OMF-Specific Libraries/StarTup Modules”for more on OMF-<br />
2.1.3 Tổ chức Chương<br />
Chương này được tổ chức như sau:<br />
• Sử dụng thư viện DSP<br />
• Chức năng Vector<br />
• Chức năng Window<br />
• Chức năng Matrix<br />
• Chức năng lọc<br />
• Chuyển đổi chức năng<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 10<br />
2.2 SỬ DỤNG THƯ VIỆN DSP<br />
2.2.1 Xây dựng với Thư viện DSP<br />
2004 Microchip Technology Inc<br />
Xây dựng một ứng dụng mà sử dụng các thư viện DSP chỉ yêu cầu hai tập tin:<br />
dsp.h<br />
và libdsp-omf.a. dsp.his một tập tin tiêu đề, cung cấp tất cả các mẫu thử nghiệm<br />
chức năng,<br />
#definesand typedefsused bởi thư viện. libdsp-omf.ais thư viện lưu trữ<br />
tập tin có chứa tất cả các tập tin đối tượng riêng cho mỗi chức năng thư<br />
viện. (Xem<br />
Mục 1.2 "Thư viện OMF-cụ thể / khởi động mô-đun" để biết thêm về OMF cụ<br />
thể<br />
thư viện).<br />
Khi biên dịch một ứng dụng, dsp.hmust được tham chiếu (sử dụng # include)<br />
của tất cả các<br />
tập tin mã nguồn mà gọi một chức năng trong thư viện DSP hoặc sử dụng các<br />
ký hiệu hoặc typedefs của nó.<br />
Khi kết nối một ứng dụng, libdsp-omf.amust được cung cấp như một đầu vào<br />
cho các mối liên kết<br />
(Bằng cách sử dụng chuyển đổi -llinker --libraryor) như vậy mà các chức năng<br />
được sử dụng bởi<br />
ứng dụng có thể được kết nối vào ứng dụng.<br />
Các mối liên kết sẽ đặt các chức năng của thư viện DSP thành một phần văn bả<br />
đặc biệt có tên<br />
.libdsp. Điều này có thể được nhìn thấy bằng cách nhìn vào các tập tin bản đồ<br />
được tạo ra bởi các mối liên kết.<br />
2.2.2 Mô hình bộ nhớ<br />
Thư viện DSP được xây dựng withthe "mã nhỏ" và "dữ liệu nhỏ" mô hình bộ<br />
nhớ để tạo ra các thư viện nhỏ nhất có thể. Kể từ khi một số các DSP chức năng<br />
thư viện được viết<br />
trong C và sử dụng các thư viện nổi điểm của trình biên dịch, mối liên kết kịch<br />
bản MPLAB C30<br />
các tập tin đặt .libmand .libdsptext phần tiếp theo với nhau. Điều này đảm bảo<br />
rằng<br />
thư viện DSP có thể sử dụng các hướng dẫn an toàn RCALL để gọi cần dấu<br />
chấm động
specific<br />
libraries.)<br />
When compiling an application, dsp.hmust be referenced (using #include) by all<br />
source files which call a function in the DSP Library or use its symbols or<br />
typedefs.<br />
When linking an application, libdsp-omf.amust be provided as an input to the<br />
linker<br />
(using the --libraryor -llinker switch) such that the functions used by the<br />
application may be linked into the application.<br />
The linker will place the functions of the DSP library into a special text section<br />
named<br />
.libdsp. This may be seen by looking at the map file generated by the linker.<br />
2.2.2 Memory Models<br />
The DSP Library is built withthe “small code” and “small data” memory models<br />
to create the smallest library possible. Since several of the DSP library functions<br />
are written<br />
in C and make use of the compiler’s floating-point library, the MPLAB C30<br />
linker script<br />
files place the .libmand .libdsptext sections next to each other. This ensures that<br />
the DSP library may safely use the RCALL instruction to call the required<br />
floating-point<br />
routines in the floating-point library.<br />
2.2.3 DSP Library Function Calling Convention<br />
All the object modules within the DSP Library are compliant with the C<br />
compatibility<br />
guidelines for the dsPIC30F DSC and follow the function call conventions<br />
documented<br />
in the Microchip MPLAB C30 C Compiler User’s Guide. Specifically,<br />
functions may use<br />
the first eight working registers (W0 through W7) as function arguments. Any<br />
additional<br />
function arguments are passed through the stack.<br />
The working registers W0 to W7 are treated as scratch memory, and their values<br />
may<br />
not be preserved after the function call. On the other hand, if any of the working<br />
registers W8 to W13 are used by a function, the working register is first saved,<br />
the register<br />
is used and then its original value is restored upon function return. The return<br />
value of<br />
a (non void) function is available in working register W0 (also referred to as<br />
WREG).<br />
When needed, the run time software stack is used following the C system stack<br />
rules<br />
described in the MPLAB C30 Compiler User’s Guide. Based on these<br />
guidelines, the<br />
object modules of the DSP Library can be linked to either a C program, an<br />
assembly<br />
program or a program which combines code in both languages.<br />
thói quen trong thư viện nổi-điểm.<br />
2.2.3 DSP Thư viện Chức năng gọi hội nghị<br />
Tất cả các mô-đun đối tượng trong thư viện DSP là phù hợp với khả năng tương<br />
thích C<br />
hướng dẫn cho dsPIC30F DSC và thực hiện theo các quy ước chức năng gọi tài<br />
liệu<br />
trong hướng dẫn người sử dụng Microchip MPLAB C30 C Compiler. Cụ thể, c<br />
thể sử dụng chức năng<br />
tám đăng ký làm việc đầu tiên (W0 qua W7) như các đối số chức năng. Bất kỳ<br />
bổ sung<br />
đối số chức năng được chuyển qua ống khói.<br />
Các hoạt động đăng ký W0 để W7 đang được coi là bộ nhớ đầu, và giá trị của<br />
chúng có thể<br />
không được bảo quản sau khi cuộc gọi chức năng. Mặt khác, nếu một trong các<br />
hoạt động đăng ký W8 để W13 được sử dụng bởi một chức năng, đăng ký làm<br />
việc lần đầu tiên được cứu, đăng ký<br />
sử dụng và sau đó là giá trị ban đầu của nó được phục hồi chức năng sau khi trở<br />
lại. Giá trị trả lại<br />
một (không void) chức năng có sẵn trong hoạt động đăng ký W0 (còn được gọi<br />
là WREG).<br />
Khi cần thiết, thời gian chạy phần mềm ngăn xếp được sử dụng theo các quy tắ<br />
ngăn xếp hệ thống C<br />
được mô tả trong hướng dẫn người sử dụng MPLAB C30 Compiler. Dựa trên<br />
các nguyên tắc này, các<br />
module đối tượng của Thư viện DSP có thể được liên kết đến một chương trình<br />
C, một hội đồng<br />
chương trình hoặc một chương trình kết hợp mã trong cả hai ngôn ngữ.<br />
2.2.4 Các loại dữ liệu<br />
Các hoạt động được cung cấp bởi thư viện DSP đã được thiết kế để tận dụng lợ<br />
thế<br />
các tập lệnh DSP và các tính năng kiến trúc của dsPIC30F DSC. Trong ý nghĩa<br />
này,<br />
hầu hết các hoạt động được tính bằng số học phân đoạn.<br />
Thư viện DSP định nghĩa một kiểu phân đoạn từ một loại nguyên:<br />
ifndef phân đoạn<br />
typedef int phân đoạn;<br />
# endif<br />
Các loại dữ liệu phân đoạn được sử dụng để đại diện cho dữ liệu có 1 dấu hiệu<br />
bit và 15<br />
bit phân đoạn. Dữ liệu trong đó sử dụng định dạng này thường được gọi là<br />
"1,15" dữ liệu.<br />
DSP Thư viện<br />
2004 Microchip Technology Inc DS51456B trang 11<br />
Đối với các chức năng mà sử dụng số nhân, kết quả được tính toán bằng cách sử<br />
dụng ắc quy 40-bit, và "9,31" số học được sử dụng. Định dạng dữ liệu này có 9<br />
bit dấu hiệu / độ lớn và<br />
31 bit phân đoạn, trong đó quy định thêm tính toán khoảng không trên phạm vi<br />
(-1.00 Đến ~ + 1,00) được cung cấp bởi các định dạng 1.15. Đương nhiên khi<br />
các chức năng cung cấp
2.2.4 Data Types<br />
The operations provided by the DSP Library have been designed to take<br />
advantage of<br />
the DSP instruction set and architectural features of the dsPIC30F DSC. In this<br />
sense,<br />
most operations are computed using fractional arithmetic.<br />
The DSP Library defines a fractional type from an integer type:<br />
#ifndef fractional<br />
typedef int fractional;<br />
#endif<br />
The fractional data type is used to represent data that has 1 sign bit, and 15<br />
fractional bits. Data which uses this format is commonly referred to as “1.15”<br />
data.<br />
DSP Library<br />
2004 Microchip Technology Inc. DS51456B-page 11<br />
For functions which use the multiplier, results are computed using the 40-bit<br />
accumulator, and “9.31” arithmetic is utilized. This data format has 9<br />
sign/magnitude bits and<br />
31 fractional bits, which provides for extra computational headroom above the<br />
range<br />
(-1.00 to ~+1.00) provided by the 1.15 format. Naturally when these functions<br />
provide<br />
a result, they revert to a fractional data type, with 1.15 format.<br />
The use of fractional arithmetic imposes some constraints on the allowable set<br />
of values to be input to a particular function. If these constraints are ensured, the<br />
operations<br />
provided by the DSP Library typically produce numerical results correct to 14<br />
bits. However, several functions perform implicit scaling to the input data<br />
and/or output results,<br />
which may decrease the resolution of the output values (when compared to a<br />
floating<br />
point implementation.)<br />
A subset of operations in the DSP Library,which require a higher degree of<br />
numerical<br />
resolution, do operate in floating point arithmetic. Nevertheless, the results of<br />
these<br />
operations are transformed into fractional values for integration with the<br />
application.<br />
The only exception to this is the MatrixInvertfunction which computes the<br />
inversion of a floating point matrix in floating point arithmetic, and provides the<br />
results in<br />
floating point format.<br />
2.2.5 Data Memory Usage<br />
The DSP Library performs no allocation of RAM, and leaves this task to you. If<br />
you do<br />
not allocate the appropriate amount of memory and align the data properly,<br />
undesired<br />
Kết quả là, họ trở lại với một kiểu dữ liệu phân đoạn, với các định dạng 1.15.<br />
Việc sử dụng số học phân đoạn áp đặt một số hạn chế trên các thiết lập cho<br />
phép các giá trị là đầu vào cho một chức năng cụ thể. Nếu những khó khăn này<br />
được đảm bảo, các hoạt động<br />
được cung cấp bởi thư viện DSP thường tạo ra kết quả tính toán chính xác đến<br />
14 bit. Tuy nhiên, một số chức năng thực hiện ngầm rộng để các dữ liệu đầu và<br />
và / hoặc kết quả đầu ra,<br />
mà có thể làm giảm độ phân giải của các giá trị đầu ra (khi so sánh với một nổi<br />
thực hiện điểm.)<br />
Một tập hợp các hoạt động trong thư viện DSP, đòi hỏi một mức độ cao hơn củ<br />
số<br />
độ phân giải, không hoạt động nổi điểm số học. Tuy nhiên, kết quả của những<br />
hoạt động được chuyển thành giá trị phân đoạn hội nhập với các ứng dụng.<br />
Ngoại lệ duy nhất này là MatrixInvertfunction mà tính đảo ngược của một ma<br />
trận điểm nổi trong số học dấu chấm, và cung cấp các kết quả trong<br />
nổi định dạng điểm.<br />
2.2.5 Bộ nhớ sử dụng dữ liệu<br />
Thư viện DSP thực hiện không phân bổ bộ nhớ RAM, và để lại nhiệm vụ này<br />
cho bạn. Nếu bạn làm<br />
không phân bổ số tiền thích hợp của bộ nhớ và sắp xếp dữ liệu đúng cách,<br />
không mong muốn<br />
Kết quả sẽ xảy ra khi chức năng thực hiện. Ngoài ra, để giảm thiểu thời gian<br />
thực hiện,<br />
Thư viện DSP sẽ làm không có kiểm tra trên các đối số chức năng cung cấp<br />
(bao gồm cả<br />
con trỏ đến bộ nhớ dữ liệu), để xác định xem họ có giá trị.<br />
Hầu hết các chức năng chấp nhận dữ liệu con trỏ như là đối số chức năng, có<br />
chứa các dữ liệu<br />
được vận hành trên, và thường cũng là vị trí để lưu kết quả. Để thuận tiện,<br />
hầu hết các chức năng trong thư viện DSP mong đợi đối số đầu vào của họ đượ<br />
phân bổ trong<br />
không gian mặc định bộ nhớ RAM (X-dữ liệu hoặc Y-Data), và đầu ra được lưu<br />
trữ trở lại<br />
không gian bộ nhớ RAM mặc định. Tuy nhiên, chức năng tính toán chuyên sâu<br />
hơn<br />
yêu cầu một số toán hạng nằm trong X-Data và Y-Data (hoặc bộ nhớ chương<br />
trình và<br />
Y-Data), để các hoạt động có thể tận dụng lợi thế của dữ liệu kép khả năng lấy<br />
kiến trúc dsPIC30F.<br />
2.2.6 CORCON Đăng ký sử dụng<br />
Nhiều chức năng của thư viện DSP đặt điện thoại dsPIC30F thành một hoạt<br />
động đặc biệt<br />
chế độ bằng cách thay đổi đăng ký CORCON. Trên sự xâm nhập của các chức<br />
năng này, các<br />
CORCON đăng ký được đẩy vào stack. Sau đó nó được sửa đổi để thực hiện<br />
một cách chính xác<br />
mong muốn hoạt động, và cuối cùng đăng ký CORCON được xuất hiện từ ngăn<br />
xếp để bảo toàn giá trị ban đầu của nó. Cơ chế này cho phép các thư viện để<br />
thực thi như một cách chính xác như
esults will occur when the function executes. In addition, to minimize<br />
execution time,<br />
the DSP Library will do no checking on the provided function arguments<br />
(including<br />
pointers to data memory), to determine if they are valid.<br />
Most functions accept data pointers as function arguments, which contain the<br />
data to<br />
be operated on, and typically also the location to store the result. For<br />
convenience,<br />
most functions in the DSP Library expect their input arguments to be allocated<br />
in the<br />
default RAM memory space (X-Data or Y-Data), and the output to be stored<br />
back into<br />
the default RAM memory space. However, the more computational intensive<br />
functions<br />
require that some operands reside in X-Data and Y-Data (or program memory<br />
and<br />
Y-Data), so that the operation can take advantage of the dual data fetch<br />
capability of<br />
the dsPIC30F architecture.<br />
2.2.6 CORCON Register Usage<br />
Many functions of the DSP Library place the dsPIC30F device into a special<br />
operating<br />
mode by modifying the CORCON register. On the entry of these functions, the<br />
CORCON register is pushed to the stack. It is then modified to correctly<br />
perform the<br />
desired operation, and lastly the CORCON register is popped from the stack to<br />
preserve its original value. This mechanism allows the library to execute as<br />
correctly as<br />
possible, without disrupting CORCON setting.<br />
When the CORCON register is modified, it is typically set to 0x00F0. This<br />
places the<br />
dsPIC30F device into the following operational mode:<br />
• DSP multiplies are set to used signed and fractional data<br />
• Accumulator saturation is enabled for Accumulator A and Accumulator B<br />
• Saturation mode is set to 9.31 saturation (Super Saturation)<br />
• Data Space Write Saturation is enabled<br />
• Program Space Visibility disabled<br />
• Convergent (unbiased) rounding is enabled<br />
For a detailed explanation of the CORCON register and its effects, refer to the<br />
dsPIC30F Family Reference Manual.<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
có thể, mà không làm gián đoạn thiết lập CORCON.<br />
Khi đăng ký CORCON được sửa đổi, nó thường được thiết lập để 0x00F0. Điều<br />
này đặt các<br />
dsPIC30F thiết bị vào chế độ hoạt động sau đây:<br />
• bội DSP được thiết lập để được sử dụng chữ ký và dữ liệu phân đoạn<br />
• ác bão hòa được kích hoạt cho ác A và B ác<br />
• Chế độ bão hòa được thiết lập là 9,31 bão hòa (Super Saturation)<br />
• Không gian dữ liệu Viết Saturation được kích hoạt<br />
• Không gian Chương trình Tầm nhìn bị vô hiệu hóa<br />
• hội tụ (không thiên vị) làm tròn được kích hoạt<br />
Đối với một lời giải thích chi tiết về đăng ký CORCON và ảnh hưởng của nó,<br />
hãy tham khảo<br />
dsPIC30F Family Reference Manual.<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 12<br />
2.2.7 tràn và Saturation Xử lý<br />
2004 Microchip Technology Inc<br />
Thư viện DSP thực hiện computationsusing nhất 9,31 bão hòa, nhưng phải lưu<br />
trữ<br />
đầu ra của chức năng định dạng 1.15. Nếu trong quá trình hoạt động của ắc quy<br />
trong bão hòa sử dụng (đi trên 0x7F FFFFFFFF hoặc thấp hơn 0x80 0000<br />
0000), các bit bão hòa tương ứng (SA hoặc SB) trong Statusregister sẽ được<br />
thiết lập. Bit này sẽ ở lại thiết lập<br />
cho đến khi nó bị xóa. Điều này cho phép bạn kiểm tra SA hoặc SB sau khi<br />
chức năng thực hiện và<br />
để xác định xem hành động cần được thực hiện để mở rộng các dữ liệu đầu vào<br />
cho các chức năng.<br />
Tương tự như vậy, nếu tính toán thực hiện với kết quả ác trong một tràn (các<br />
ắc đi trên 0x00 7FFF FFFF hoặc thấp hơn 0xFF 8000 0000), bit tràn tương ứng<br />
(viêm khớp hoặc OB) trong tình trạng đăng ký sẽ được thiết lập.Không giống<br />
như các bit trạng thái SA và SB, viêm khớp và OB sẽ không ở lại cho đến khi<br />
thiết lập theyare xóa. Những bit này được cập nhật mỗi<br />
Hiện một thao tác dùng ắc được thực hiện. Nếu vượt quá phạm vi quy định này<br />
đánh dấu một sự kiện quan trọng, bạn nên cho phép bẫy ác tràn<br />
thông qua các bit hình trứng và OVBTE vào sổ đăng ký INTCON1. Điều này s<br />
có tác dụng<br />
tạo ra một lỗi số học Trap ngay asthe tình trạng tràn xảy ra, và bạn<br />
sau đó có thể có những hành động cần thiết.<br />
2.2.8 Tích hợp với ngắt và một RTOS<br />
Thư viện DSP có thể dễ dàng được tích hợp vào một ứng dụng mà sử dụng ngắ<br />
hoặc một RTOS, nhưng nguyên tắc nhất định phải được tuân thủ. Để giảm thiểu<br />
thời gian thực hiện, các<br />
DSP Thư viện sử dụng DOloops, REPEATloops, modulo địa chỉ và đảo ngược<br />
bit<br />
DS51456B-page 12<br />
2004 Microchip Technology Inc.<br />
giải quyết. Mỗi thành phần này là một nguồn tài nguyên hữu hạn phần cứng trê
2.2.7 Overflow and Saturation Handling<br />
The DSP Library performs most computationsusing 9.31 saturation, but must<br />
store the<br />
output of the function in 1.15 format. If during the course of operation the<br />
accumulator<br />
in use saturates (goes above 0x7F FFFFFFFF or below 0x80 0000 0000), the<br />
corresponding saturation bit (SA or SB) in the Statusregister will be set. This bit<br />
will stay set<br />
until it is cleared. This allows you to inspect SA or SB after the function<br />
executes and<br />
to determine if action should be taken to scale the input data to the function.<br />
Similarly, if a computation performed with the accumulator results in an<br />
overflow (the<br />
accumulator goes above 0x00 7FFF FFFF or below 0xFF 8000 0000), the<br />
corresponding overflow bit (OA or OB) in the Status register will be set. Unlike<br />
the SA and SB status bits, OA and OB will not stay set until theyare cleared.<br />
These bits are updated each<br />
time an operation using accumulator is executed. If exceeding this specified<br />
range<br />
marks an important event, you are advised to enable the Accumulator Overflow<br />
Trap<br />
via the OVATE and OVBTE bits in the INTCON1 register. This will have the<br />
effect of<br />
generating an Arithmetic Error Trap as soon asthe Overflow condition occurs,<br />
and you<br />
may then take the required action.<br />
2.2.8 Integrating with Interrupts and an RTOS<br />
The DSP Library may easily be integrated into an application which utilizes<br />
interrupts<br />
or an RTOS, yet certain guidelines must be followed. To minimize execution<br />
time, the<br />
DSP Library utilizes DOloops, REPEATloops, modulo addressing and bitreversed<br />
addressing. Each of these components is a finite hardware resource on the<br />
dsPIC30F<br />
DSC, and the background code must consider the use of each resource when<br />
disrupting execution of a DSP Library function.<br />
When integrating with the DSP Library, you must examine the Function Profile<br />
of each<br />
function description to determine which resources are used. If a library function<br />
will be<br />
interrupted, it is your responsibility to save and restore the contents of all<br />
registers used<br />
by the function, including the state of the DO, REPEATand special addressing<br />
hardware. Naturally this also includes saving and restoring the contents of the<br />
CORCON<br />
and Status registers.<br />
2.2.9 Rebuilding the DSP Library<br />
dsPIC30F<br />
DSC, và mã nền phải xem xét việc sử dụng tài nguyên mỗi khi<br />
làm gián đoạn thực hiện một chức năng DSP Thư viện.<br />
Khi kết hợp với Thư viện DSP, bạn phải kiểm tra các chức năng của từng hồ sơ<br />
Mô tả chức năng để xác định các nguồn lực được sử dụng. Nếu một chức năng<br />
thư viện sẽ<br />
bị gián đoạn, bạn có trách nhiệm lưu và khôi phục lại nội dung của tất cả các<br />
đăng ký sử dụng<br />
bởi các chức năng, bao gồm cả trạng thái của DO, REPEATand đặc biệt phần<br />
cứng giải quyết. Đương nhiên điều này cũng bao gồm lưu trữ và khôi phục lại<br />
nội dung của CORCON<br />
và tình trạng đăng ký.<br />
2.2.9 Xây dựng lại thư viện DSP<br />
Một tập tin thực thi có tên makedsplib.batis cung cấp để xây dựng lại thư viện<br />
DSP. Các<br />
Trình biên dịch MPLAB C30 là cần thiết để xây dựng lại các thư viện DSP, và<br />
hàng loạt tập tin giả<br />
trình biên dịch được cài đặt trong thư mục mặc định, c: \ pic30_tools. Nếu công<br />
cụ ngôn ngữ của bạn được cài đặt trong một thư mục khác, bạn phải thay đổi<br />
các thư mục trong<br />
tập tin thực thi để phù hợp với vị trí của công cụ ngôn ngữ của bạn.<br />
DSP Thư viện<br />
2004 Microchip Technology Inc DS51456B trang 13<br />
2.3 chức năng VECTOR<br />
Phần này trình bày các khái niệm về một vector phân đoạn, như xem xét bởi<br />
DSP<br />
Thư viện, và mô tả các chức năng cá nhân đó thực hiện các hoạt động vector.<br />
2.3.1 Fractional Vector hoạt động<br />
Một vector phân đoạn là một tập hợp các giá trị số, các yếu tố vector, phân bổ<br />
liên tục kế nhau trong bộ nhớ, với người đầu tiên elementAt địa chỉ bộ nhớ thấp<br />
nhất. Một từ<br />
bộ nhớ (hai byte) được sử dụng để lưu trữ các giá trị của mỗi phần tử, và số<br />
lượng này<br />
phải được hiểu như là một phân số đại diện trong các định dạng dữ liệu 1.15.<br />
Một con trỏ giải quyết các yếu tố đầu tiên của vector được sử dụng như một xử<br />
lý cung cấp<br />
tiếp cận với mỗi giá trị vector. Địa chỉ của phần tử đầu tiên được gọi là<br />
địa chỉ cơ sở của vector. Bởi vì mỗi phần tử của vector là 16 bit, các cơ sở<br />
địa chỉ mustbe liên kết đến một địa chỉ mặc.<br />
Một thỏa thuận chiều của một vector chứa để lưu trữ bộ nhớ<br />
mô hình của thiết bị, do đó yếu tố thứ n của một vector N phần tử có thể được<br />
truy cập<br />
từ địa chỉ cơ sở BA của vector như:<br />
BA + 2 (n-1), cho 1 ≤n ≤N.<br />
Các hệ số 2 được sử dụng vì các byte khả năng của dsPIC30F giải quyết<br />
thiết bị.
A batch file named makedsplib.batis provided to rebuild the DSP library. The<br />
MPLAB C30 compiler is required to rebuild the DSP library, and the batch file<br />
assumes<br />
that the compiler is installed in the default directory, c:\pic30_tools. If your<br />
language tools are installed in a different directory, you must modify the<br />
directories in the<br />
batch file to match the location of your language tools.<br />
DSP Library<br />
2004 Microchip Technology Inc. DS51456B-page 13<br />
2.3 VECTOR FUNCTIONS<br />
This section presents the concept of a fractional vector, as considered by the<br />
DSP<br />
Library, and describes the individual functions which perform vector operations.<br />
2.3.1 Fractional Vector Operations<br />
A fractional vector is a collection of numerical values, the vector elements,<br />
allocated<br />
contiguously in memory, with the first elementat the lowest memory address.<br />
One word<br />
of memory (two bytes) is used to store the value of each element, and this<br />
quantity<br />
must be interpreted as a fractional number represented in the 1.15 data format.<br />
A pointer addressing the first element of the vector is used as a handle which<br />
provides<br />
access to each of the vector values. The address of the first element is referred<br />
to as<br />
the base address of the vector. Because each element of the vector is 16 bits, the<br />
base<br />
address mustbe aligned to an even address.<br />
The one dimensional arrangement of a vector accommodates to the memory<br />
storage<br />
model of the device, so that the n-th element of an N-element vector can be<br />
accessed<br />
from the vector's base address BA as:<br />
BA + 2(n-1), for 1 ≤n ≤N.<br />
The factor of 2 is used because of the byte addressing capabilities of the<br />
dsPIC30F<br />
device.<br />
Unary and binary fractional vector operations are implemented in this library.<br />
The operand vector in a unary operation is called the source vector. In a binary<br />
operation the<br />
first operand is referred to as the source one vector, and the second as the source<br />
two<br />
vector. Each operation applies some computation to one or several elements of<br />
the<br />
source vector(s). Some operations produce a result which is a scalar value (also<br />
to be<br />
interpreted as a 1.15 fractional number), while other operations produce a result<br />
Hoạt động vector phân đoạn nguyên phân và nhị phân được thực hiện trong thư<br />
viện này. Các vector toán hạng trong một hoạt động nguyên phân được gọi là<br />
vector nguồn. Trong một hoạt động nhị phân<br />
toán hạng đầu tiên được gọi là một trong những nguồn vector, và thứ hai là<br />
nguồn hai<br />
vector. Mỗi hoạt động áp dụng một số tính toán cho một hoặc một số yếu tố của<br />
vector nguồn (s). Một số hoạt động sản xuất một kết quả mà là một giá trị vô<br />
hướng (cũng được<br />
hiểu là một số phân đoạn 1.15), trong khi các hoạt động khác tạo ra một kết quả<br />
mà<br />
là một vector. Khi kết quả cũng là một vector, điều này được gọi là vector đích.<br />
Một số hoạt động dẫn đến một vector cho phép tính toán tại chỗ. Điều này có<br />
nghĩa<br />
kết quả của các hoạt động được đặt trở lại vào vector nguồn (hoặc nguồn một<br />
vector<br />
cho các hoạt động nhị phân). Trong trường hợp này, các vector điểm đến được<br />
cho là (vật lý) thay thế<br />
nguồn (một) vector. Nếu một hoạt động có thể được tính tại chỗ, nó được chỉ<br />
định như vậy<br />
trong các ý kiến được cung cấp với mô tả chức năng.<br />
Đối với một số hoạt động nhị phân, hai toán hạng có thể giống nhau (vật lý)<br />
nguồn<br />
vector, có nghĩa là các hoạt động được áp dụng cho các vector nguồn và bản<br />
thân. Nếu loại<br />
tính toán là có thể cho một hoạt động nào đó, nó được chỉ định như vậy trong<br />
các ý kiến<br />
cung cấp với mô tả chức năng.<br />
Một số hoạt động có thể được cả hai tự áp dụng và tính toán tại chỗ.<br />
Tất cả các hoạt động vector phân đoạn trong thislibrary mất như một tham số số<br />
phần tử<br />
(Số phần tử) của vector toán hạng (s). Căn cứ vào giá trị của tham số này<br />
giả định sau đây được thực hiện:<br />
a) Tổng kích thước của tất cả các vectơ tham gia vào một hoạt động cụ thể nằm<br />
trong<br />
phạm vi của bộ nhớ dữ liệu có sẵn cho các thiết bị mục tiêu.<br />
b) Trong trường hợp hoạt động nhị phân, cardinalities của cả hai vectơ toán<br />
hạng phải<br />
tuân thủ các quy tắc của vector đại số (đặc biệt, xem các ghi nhận cho<br />
VectorConvolveand VectorCorrelatefunctions).<br />
c) Các vector đích mustbe đủ để chấp nhận các kết quả của một lớn<br />
hoạt động.<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 14<br />
2.3.2 Xem xét tài khoản<br />
2004 Microchip Technology Inc<br />
a) Không kiểm tra ranh giới được thực hiện bởi các chức năng này. Trong phạm
which<br />
is a vector. When the result is also a vector, this is referred to as the destination<br />
vector.<br />
Some operations resulting in a vector allow computation in place. This means<br />
the<br />
results of the operation are placed back into the source vector (or the source one<br />
vector<br />
for binary operations). In this case, the destination vector is said to (physically)<br />
replace<br />
the source (one) vector. If an operation can be computed in place, it is indicated<br />
as such<br />
in the comments provided with the function description.<br />
For some binary operations, the two operands can be the same (physical) source<br />
vector, which means the operation is applied to the source vector and itself. If<br />
this type<br />
of computation is possible for a given operation,it is indicated as such in the<br />
comments<br />
provided with the function description.<br />
Some operations can be both self applicable and computed in place.<br />
All the fractional vector operations in thislibrary take as an argument the<br />
cardinality<br />
(number of elements) of the operand vector(s). Based on the value of this<br />
argument the<br />
following assumptions are made:<br />
a) The sum of sizes of all the vectors involved in a particular operation falls<br />
within<br />
the range of available data memory for the target device.<br />
b) In the case of binary operations, the cardinalities of both operand vectors<br />
must<br />
obey the rules of vector algebra (particularly, see remarks for the<br />
VectorConvolveand VectorCorrelatefunctions).<br />
c) The destination vector mustbe large enough to accept the results of an<br />
operation.<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 14<br />
2.3.2 User Considerations<br />
2004 Microchip Technology Inc.<br />
a) No boundary checking is performed by these functions. Out of range<br />
cardinalities<br />
(including zero length vectors) as well as nonconforming use of source vector<br />
sizes in binary operations may produce unexpected results.<br />
b) The vector addition and subtraction operations could lead to saturation if the<br />
sum<br />
of corresponding elements in the source vector(s) is greater than 1-2<br />
vi cardinalities<br />
(Bao gồm cả không vector chiều dài) cũng như sử dụng không phù hợp của<br />
vector nguồn<br />
kích thước trong các hoạt động nhị phân có thể tạo ra kết quả bất ngờ.<br />
b) Các cộng và trừ các hoạt động vector có thể dẫn đến bão hòa nếu tổng<br />
các yếu tố tương ứng trong vector nguồn (s) lớn hơn 1-2<br />
-15<br />
hoặc<br />
nhỏ hơn -1,0. Tương tự, các vector chấm sản phẩm và các hoạt động năng lượn<br />
có thể dẫn đến bão hòa nếu tổng sản phẩm lớn hơn 1-2<br />
-15<br />
hoặc nhỏ hơn<br />
hơn -1,0.<br />
c) Đó là khuyến cáo rằng tình trạng đăng ký (SR) được xem xét sau khi hoàn<br />
thành<br />
mỗi lần gọi hàm. Đặc biệt, người dùng có thể kiểm tra việc SA, SB và SAB cờ<br />
sau<br />
hàm trả về để xác định độ bão hòa xảy ra.<br />
d) Tất cả các chức năng đã được thiết kế để hoạt động trên các vector phân đoạn<br />
phân bổ<br />
trong không gian bộ nhớ RAM mặc định (X-Y-dữ liệu hoặc dữ liệu).<br />
e) Các hoạt động đó trả về một vector đích có thể được lồng vào nhau, do đó, v<br />
dụ<br />
nếu:<br />
a = OP1 (b, c), với b = OP2 (d) và c = op3 (e, f), sau đó<br />
a = OP1 (OP2 (d), op3 (e, f))<br />
2.3.3 Bình luận khác<br />
Mô tả các chức năng giới hạn phạm vi của nó những gì có thể được coi là<br />
thường xuyên<br />
sử dụng các hoạt động này. Tuy nhiên, vì không có kiểm tra biên giới được thự<br />
hiện trong quá trình<br />
tính toán của các chức năng này, bạn có quyền tự do để giải thích các hoạt động<br />
của mình và<br />
kết quả là nó phù hợp với một số nhu cầu đặc biệt.<br />
Ví dụ, trong khi tính toán VectorMaxfunction, chiều dài của vector nguồn<br />
có thể là lớn hơn numElems. Trong trường hợp này, các chức năng sẽ được sử<br />
dụng để tìm<br />
giá trị tối đa onlyamong các numElemselements đầu tiên của vector nguồn.<br />
Một ví dụ khác, bạn có thể quan tâm đến việc thay thế numElemselements của<br />
một vector điểm nằm giữa Nand N + numElems-1, với numElemselements từ<br />
một vector nguồn nằm giữa các yếu tố mand M + numElems-1. Sau đó,<br />
VectorCopyfunction có thể được sử dụng như sau:<br />
phân đoạn * DSTV [DST_ELEMS] = {...};<br />
phân đoạn * srcV [SRC_ELEMS] = {...};
-15<br />
or<br />
smaller than -1.0. Analogously, the vector dot product and power operations<br />
could lead to saturation if the sum of products is greater than 1-2<br />
-15<br />
or smaller<br />
than -1.0.<br />
c) It is recommended that the Status register (SR) be examined after completion<br />
of<br />
each function call. In particular, users can inspect the SA, SB and SAB flags<br />
after<br />
the function returns to determine if saturation occurred.<br />
d) All the functions have been designed to operate on fractional vectors<br />
allocated<br />
in default RAM memory space (X-Data or Y-Data).<br />
e) Operations which return a destination vector can be nested, so that for<br />
instance<br />
if:<br />
a = Op1 (b, c), with b = Op2 (d), and c = Op3 (e, f), then<br />
a = Op1 (Op2 (d), Op3 (e, f))<br />
2.3.3 Additional Remarks<br />
The description of the functions limits its scope to what could be considered the<br />
regular<br />
usage of these operations. However, since no boundary checking is performed<br />
during<br />
computation of these functions, you have the freedom to interpret the operation<br />
and its<br />
results as it fits some particular needs.<br />
For instance, while computing the VectorMaxfunction, the length of the source<br />
vector<br />
could be greater than numElems. In this case, the function would be used to find<br />
the<br />
maximum value onlyamong the first numElemselements of the source vector.<br />
As another example, you may be interested in replacing numElemselements of a<br />
destination vector located between Nand N+numElems-1, with<br />
numElemselements from<br />
a source vector located between elements Mand M+numElems-1. Then, the<br />
VectorCopyfunction could be used as follows:<br />
fractional* dstV[DST_ELEMS] = {...};<br />
fractional* srcV[SRC_ELEMS] = {...};<br />
int n = NUM_ELEMS;<br />
int N = N_PLACE; /* NUM_ELEMS+N ≤DST_ELEMS */<br />
int M = M_PLACE; /* NUM_ELEMS+M ≤SRC_ELEMS */<br />
fractional* dstVector = dstV+N;<br />
int n = NUM_ELEMS;<br />
int N = N_PLACE; / * NUM_ELEMS + N ≤DST_ELEMS * /<br />
int M = M_PLACE; / * NUM_ELEMS + M ≤SRC_ELEMS * /<br />
phân đoạn * dstVector = DSTV + N;<br />
phân đoạn * srcVector = srcV + M;<br />
dstVector VectorCopy = (n, dstVector, srcVector);<br />
Cũng trong bối cảnh này, VectorZeroPadfunction có thể hoạt động tại chỗ, nơi<br />
bây giờ<br />
DSTV = srcV, numElemsis số phần tử atthe đầu vector nguồn<br />
bảo tồn, và numZerosthe số phần tử ở đuôi vector để thiết lập để không.<br />
Khả năng khác có thể được khai thác từ thực tế là không có kiểm tra ranh giới<br />
thực hiện.<br />
DSP Thư viện<br />
2004 Microchip Technology Inc DS51456B trang 15<br />
2.3.4 Chức năng cá nhân<br />
Trong phần tiếp theo, các chức năng cá nhân thực hiện các hoạt động vector<br />
được mô tả.<br />
VectorAdd<br />
Mô tả: VectorAddadds giá trị của mỗi elementin nguồn một vector<br />
với đối tác của mình trong nguồn hai véc tơ, và đặt kết quả trong<br />
vector đích.<br />
Bao gồm: dsp.h<br />
Nguyên mẫu: ở ngoài phân đoạn * VectorAdd (<br />
int numElems,<br />
phân đoạn * DSTV,<br />
phân đoạn * srcV1,<br />
phân đoạn * srcV2<br />
);<br />
Đối số: numElems số phần tử trong vector nguồn<br />
DSTV con trỏ tới vector điểm đến<br />
con trỏ srcV1 nguồn một vector<br />
con trỏ srcV2 nguồn hai vector<br />
Quay trở lại giá trị: Con trỏ trỏ tới địa chỉ cơ sở của vector đích.<br />
Ghi chú: Nếu giá trị tuyệt đối của srcV1 [n] + srcV2 [n] là lớn hơn 1-2<br />
-15<br />
,<br />
hoạt động này dẫn đến độ bão hòa cho các phần tử n-thứ.<br />
Chức năng này có thể được tính tại chỗ.<br />
Chức năng này có thể tự áp dụng.<br />
Source File: vadd.asm
fractional* srcVector = srcV+M;<br />
dstVector = VectorCopy (n, dstVector, srcVector);<br />
Also in this context, the VectorZeroPadfunction can operate in place, where<br />
now<br />
dstV = srcV, numElemsis the number of elements atthe beginning of source<br />
vector<br />
to preserve, and numZerosthe number of elements at the vector tail to set to<br />
zero.<br />
Other possibilities can be exploited from the fact that no boundary checking is<br />
performed.<br />
DSP Library<br />
2004 Microchip Technology Inc. DS51456B-page 15<br />
2.3.4 Individual Functions<br />
In what follows, the individual functions implementing vector operations are<br />
described.<br />
VectorAdd<br />
Description: VectorAddadds the value of each elementin the source one vector<br />
with its counterpart in the source two vector, and places the result in the<br />
destination vector.<br />
Include: dsp.h<br />
Prototype: extern fractional* VectorAdd (<br />
int numElems,<br />
fractional* dstV,<br />
fractional* srcV1,<br />
fractional* srcV2<br />
);<br />
Arguments: numElems number of elements in source vectors<br />
dstV pointer to destination vector<br />
srcV1 pointer to source one vector<br />
srcV2 pointer to source two vector<br />
Return Value: Pointer to base address of destination vector.<br />
Remarks: If the absolute value of srcV1[n] + srcV2[n]is larger than 1-2<br />
-15<br />
,<br />
this operation results in saturation for the n-th element.<br />
This function can be computed in place.<br />
This function can be self applicable.<br />
Source File: vadd.asm<br />
Function Profile: System resources usage:<br />
W0..W4 used, not restored<br />
ACCA used, not restored<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W4 sử dụng, không được khôi phục<br />
ACCA được sử dụng, không được khôi phục<br />
CORCON lưu, sử dụng, phục hồi<br />
DOand REPEATinstruction sử dụng:<br />
1 DOinstructions cấp<br />
không REPEATinstructions<br />
Từ chương trình (hướng dẫn 24-bit):<br />
13<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
17 + 3 (numElems)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 16 2004 Microchip Technology Inc<br />
VectorConvolve<br />
Mô tả: VectorConvolvecomputes chập giữa hai nguồn<br />
vectơ, và lưu trữ các kết quả trong một vector đích. Kết quả là<br />
tính như sau:<br />
, 0 ≤n
CORCON saved, used, restored<br />
DOand REPEATinstruction usage:<br />
1 level DOinstructions<br />
no REPEATinstructions<br />
Program words (24-bit instructions):<br />
13<br />
Cycles (including C-function call and return overheads):<br />
17 + 3(numElems)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 16 2004 Microchip Technology Inc.<br />
VectorConvolve<br />
Description: VectorConvolvecomputes the convolution between two source<br />
vectors, and stores the result in a destination vector. The result is<br />
computed as follows:<br />
, for 0 ≤n
This function can beself applicable.<br />
Source File: vcon.asm<br />
yn() xk()hn k – ()<br />
k0=<br />
n<br />
∑ =<br />
yn() xk()hn k – ()<br />
knM–1+ =<br />
n<br />
∑ =<br />
yn() xk()hn k – ()<br />
knM–1+ =<br />
N1–<br />
∑ =<br />
DSP Library<br />
2004 Microchip Technology Inc. DS51456B-page 17<br />
.<br />
Function Profile: System resources usage:<br />
W0..W7 used, not restored<br />
W8..W10 saved, used, restored<br />
ACCA used, not restored<br />
CORCON saved, used, restored<br />
DOand REPEATinstruction usage:<br />
2 level DOinstructions<br />
no REPEATinstructions<br />
Program words (24-bit instructions):<br />
58<br />
Cycles (including C-function call and return overheads):<br />
For N = numElems1, and M = numElems2,<br />
, for M
fractional* srcV<br />
);<br />
Arguments: numElems number of elements in source vector<br />
dstV pointer to destination vector<br />
srcV pointer to source vector<br />
Return Value: Pointer to base address of destination vector.<br />
Remarks: The destination vector mustalready exist. Destination vectors must<br />
have, at least, numElemselements, but could be longer.<br />
This function can be computed in place. See Additional Remarks at the<br />
end of the section for comments on this mode of operation.<br />
Source File: vcopy.asm<br />
Function Profile: System resources usage:<br />
W0..W3 used, not restored<br />
DOand REPEATinstruction usage:<br />
no DOinstructions<br />
1 level REPEATinstructions<br />
Program words (24-bit instructions):<br />
6<br />
Cycles (including C-function call and return overheads):<br />
12 + numElems<br />
VectorConvolve (Continued)<br />
28 13M 6 m<br />
m1=<br />
M<br />
∑ NM– ()73M + () ++ +<br />
28 13M 6 m<br />
m1=<br />
M<br />
∑ ++<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 18 2004 Microchip Technology Inc.<br />
VectorCorrelate<br />
Description: VectorCorrelatecomputes the correlation between two source<br />
vectors, and stores the result in a destination vector. The result is<br />
computed as follows:<br />
, for 0 ≤n
size M (with M ≤N.)<br />
Include: dsp.h<br />
Prototype: extern fractional* VectorCorrelate (<br />
int numElems1,<br />
int numElems2,<br />
fractional* dstV,<br />
fractional* srcV1,<br />
fractional* srcV2<br />
);<br />
Arguments: numElems1 number of elements in source one vector<br />
numElems2 number of elements in source two vector<br />
dstV pointer to destination vector<br />
srcV1 pointer to source one vector<br />
srcV2 pointer to source two vector<br />
Return Value: Pointer to base address of destination vector.<br />
Remarks: The number of elements in the source two vector mustbe less than or<br />
equal to the number of elements in the source one vector.<br />
The destination vector mustalready exist, with exactly<br />
numElems1+numElems2-1number of elements.<br />
This function can beself applicable.<br />
This function uses VectorConvolve.<br />
Source File: vcor.asm<br />
Function Profile: System resources usage:<br />
W0..W7 used, not restored,<br />
plus resources from VectorConvolve<br />
DOand REPEATinstruction usage:<br />
1 level DOinstructions<br />
no REPEATinstructions,<br />
plus DO/REPEATinstructions from<br />
VectorConvolve<br />
Program words (24-bit instructions):<br />
14,<br />
plus program words from VectorConvolve<br />
Cycles (including C-function call and return overheads):<br />
19 + floor(M/2)*3, with M = numElems2,<br />
plus cycles from VectorConvolve.<br />
Note:In the description of VectorConvolvethe number of cycles<br />
reported includes 4 cycles of C-function call overhead. Thus, the<br />
number of actual cycles from VectorConvolveto add to<br />
Lưu ý: Trong các mô tả về số VectorConvolvethe của chu kỳ<br />
báo cáo bao gồm 4 chu kỳ của C-chức năng gọi điện trên không. Như vậy,<br />
số chu kỳ thực tế từ VectorConvolveto thêm vào<br />
VectorCorrelateis 4 ít hơn bất cứ số được báo cáo cho một<br />
đứng một mình VectorConvolve.<br />
rn () xk () yk n + ()<br />
k0 =<br />
N1-<br />
Σ =<br />
DSP Thư viện<br />
2004 Microchip Technology Inc DS51456B trang 19<br />
.<br />
VectorDotProduct<br />
Mô tả: VectorDotProductcomputes tổng các sản phẩm giữa<br />
các yếu tố tương ứng của nguồn một và nguồn hai vectơ.<br />
Bao gồm: dsp.h<br />
Nguyên mẫu: ở ngoài VectorDotProduct phân đoạn (<br />
int numElems,<br />
phân đoạn * srcV1,<br />
phân đoạn * srcV2<br />
);<br />
Đối số: numElems số phần tử trong vector nguồn<br />
con trỏ srcV1 nguồn một vector<br />
con trỏ srcV2 nguồn hai vector<br />
Quay trở lại giá trị: Giá trị tổng sản phẩm.<br />
Ghi chú: Nếu giá trị tuyệt đối của ofproducts tiền lớn hơn 1-2<br />
-15<br />
, Điều này<br />
hoạt động dẫn đến bão hòa.<br />
Chức năng này có thể tự áp dụng.<br />
Source File: vdot.asm<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W2 sử dụng, không được khôi phục<br />
W4..W5 sử dụng, không được khôi phục<br />
ACCA được sử dụng, không được khôi phục<br />
CORCON lưu, sử dụng, phục hồi<br />
DOand REPEATinstruction sử dụng:<br />
1 DOinstructions cấp<br />
không REPEATinstructions
VectorCorrelateis 4 less than whatever number is reported for a<br />
stand alone VectorConvolve.<br />
rn () xk()yk n + ()<br />
k0=<br />
N1–<br />
∑ =<br />
DSP Library<br />
2004 Microchip Technology Inc. DS51456B-page 19<br />
.<br />
VectorDotProduct<br />
Description: VectorDotProductcomputes the sum of the products between<br />
corresponding elements of the source one and source two vectors.<br />
Include: dsp.h<br />
Prototype: extern fractional VectorDotProduct (<br />
int numElems,<br />
fractional* srcV1,<br />
fractional* srcV2<br />
);<br />
Arguments: numElems number of elements in source vectors<br />
srcV1 pointer to source one vector<br />
srcV2 pointer to source two vector<br />
Return Value: Value of the sum of products.<br />
Remarks: If the absolute value of the sum ofproducts is larger than 1-2<br />
-15<br />
, this<br />
operation results in saturation.<br />
This function can be self applicable.<br />
Source File: vdot.asm<br />
Function Profile: System resources usage:<br />
W0..W2 used, not restored<br />
W4..W5 used, not restored<br />
ACCA used, not restored<br />
CORCON saved, used, restored<br />
DOand REPEATinstruction usage:<br />
1 level DOinstructions<br />
no REPEATinstructions<br />
Program words (24-bit instructions):<br />
13<br />
Cycles (including C-function call and return overheads):<br />
Từ chương trình (hướng dẫn 24-bit):<br />
13<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
17 + 3 (numElems)<br />
VectorMax<br />
Mô tả: VectorMaxfinds yếu tố cuối cùng trong vector nguồn có giá trị<br />
lớn hơn hoặc bằng bất kỳ yếu tố vector trước. Sau đó, kết quả đầu ra<br />
rằng giá trị tối đa và chỉ số của phần tử tối đa.<br />
Bao gồm: dsp.h<br />
Nguyên mẫu: ở ngoài phân đoạn VectorMax (<br />
int numElems,<br />
phân đoạn * srcV,<br />
int * maxIndex<br />
);<br />
Đối số: numElems số phần tử trong vector nguồn<br />
srcV con trỏ tới vector nguồn<br />
maxIndex con trỏ để giữ cho chỉ số (cuối cùng) yếu tố tối đa<br />
Quay trở lại giá trị: giá trị tối đa trong vector.<br />
Ghi chú: Nếu srcV [i] = srcV [j] = maxVal, và i
17 + 3(numElems)<br />
VectorMax<br />
Description: VectorMaxfinds the last element in the source vector whose value<br />
is<br />
greater than or equal to any previous vector element. Then, it outputs<br />
that maximum value and the index of the maximum element.<br />
Include: dsp.h<br />
Prototype: extern fractional VectorMax (<br />
int numElems,<br />
fractional* srcV,<br />
int* maxIndex<br />
);<br />
Arguments: numElems number of elements in source vector<br />
srcV pointer to source vector<br />
maxIndex pointer to holder for index of (last) maximum element<br />
Return Value: Maximum value in vector.<br />
Remarks: If srcV[i] = srcV[j] = maxVal, and i < j, then<br />
*maxIndex= j.<br />
Source File: vmax.asm<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
VectorMin<br />
Mô tả: VectorMinfinds yếu tố cuối cùng trong vector nguồn có giá trị<br />
nhỏ hơn hoặc bằng bất kỳ yếu tố vector trước. Sau đó, nó ra mà<br />
giá trị tối thiểu và chỉ số của các yếu tố tối thiểu.<br />
Bao gồm: dsp.h<br />
Nguyên mẫu: ở ngoài VectorMin phân đoạn (<br />
int numElems,<br />
phân đoạn * srcV,<br />
int * minIndex<br />
);<br />
Đối số: numElems số phần tử trong vector nguồn<br />
srcV con trỏ tới vector nguồn<br />
minIndex con trỏ để giữ cho chỉ số (cuối cùng) yếu tố tối thiểu<br />
Quay trở lại giá trị: giá trị tối thiểu trong vector.<br />
Ghi chú: Nếu srcV [i] = srcV [j] = minVal, và i srcV[n+1], 0 ≤n < numElems-1<br />
VectorMin<br />
Description: VectorMinfinds the last element in the source vector whose value<br />
is<br />
13<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
14<br />
nếu numElems = 1<br />
20 + 8 (numElems-2)<br />
nếu srcV [n] ≥ srcV [n + 1], 0 ≤n
less than or equal to any previous vector element. Then, it outputs that<br />
minimum value and the index of the minimum element.<br />
Include: dsp.h<br />
Prototype: extern fractional VectorMin (<br />
int numElems,<br />
fractional* srcV,<br />
int* minIndex<br />
);<br />
Arguments: numElems number of elements in source vector<br />
srcV pointer to source vector<br />
minIndex pointer to holder for index of (last) minimum element<br />
Return Value: Minimum value in vector.<br />
Remarks: If srcV[i] = srcV[j] = minVal, and i < j, then<br />
*minIndex= j.<br />
Source File: vmin.asm<br />
Function Profile: System resources usage:<br />
W0..W5 used, not restored<br />
DOand REPEATinstruction usage:<br />
no DOinstructions<br />
no REPEATinstructions<br />
Program words (24-bit instructions):<br />
13<br />
Cycles (including C-function call and return overheads):<br />
14<br />
if numElems= 1<br />
20 + 8(numElems-2)<br />
if srcV[n] ≥ srcV[n+1], 0 ≤n < numElems-1<br />
19 + 7(numElems-2)<br />
if srcV[n] < srcV[n+1], 0 ≤n < numElems-1<br />
VectorMax (Continued)<br />
DSP Library<br />
2004 Microchip Technology Inc. DS51456B-page 21<br />
VectorMultiply<br />
Description: VectorMultiplymultiplies the value of each element in source one<br />
vector with its counterpart in source two vector, and places the result in<br />
the corresponding element of destination vector.<br />
Include: dsp.h<br />
Prototype: extern fractional* VectorMultiply (<br />
int numElems,<br />
Nguyên mẫu: ở ngoài phân đoạn * VectorMultiply (<br />
int numElems,<br />
phân đoạn * DSTV,<br />
phân đoạn * srcV1,<br />
phân đoạn * srcV2<br />
);<br />
Đối số: numElems số phần tử trong vector nguồn<br />
DSTV con trỏ tới vector điểm đến<br />
con trỏ srcV1 nguồn một vector<br />
con trỏ srcV2 nguồn hai vector<br />
Quay trở lại giá trị: Con trỏ trỏ tới địa chỉ cơ sở của vector đích.<br />
Bình luận: hoạt động này còn được gọi là vector yếu tố-by-yếu tố<br />
nhân.<br />
Chức năng này có thể được tính tại chỗ.<br />
Chức năng này có thể tự áp dụng.<br />
Source File: vmul.asm<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W5 sử dụng, không được khôi phục<br />
ACCA được sử dụng, không được khôi phục<br />
CORCON lưu, sử dụng, phục hồi<br />
DOand REPEATinstruction sử dụng:<br />
1 DOinstructions cấp<br />
không REPEATinstructions<br />
Từ chương trình (hướng dẫn 24-bit):<br />
14<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
17 + 4 (numElems)<br />
VectorNegate<br />
Mô tả: VectorNegatenegates (thay đổi là dấu hiệu của) các giá trị của<br />
các yếu tố trong vector nguồn, và những nơi họ ở đích đến<br />
vector.<br />
Bao gồm: dsp.h<br />
Nguyên mẫu: ở ngoài phân đoạn * VectorNeg (<br />
int numElems,<br />
phân đoạn * DSTV,<br />
phân đoạn * srcV<br />
);<br />
Đối số: numElems số phần tử trong vector nguồn<br />
DSTV con trỏ tới vector điểm đến
fractional* dstV,<br />
fractional* srcV1,<br />
fractional* srcV2<br />
);<br />
Arguments: numElems number of elements in source vector<br />
dstV pointer to destination vector<br />
srcV1 pointer to source one vector<br />
srcV2 pointer to source two vector<br />
Return Value: Pointer to base address of destination vector.<br />
Remarks: This operation is also known as vector element-by-element<br />
multiplication.<br />
This function can be computed in place.<br />
This function can be self applicable.<br />
Source File: vmul.asm<br />
Function Profile: System resources usage:<br />
W0..W5 used, not restored<br />
ACCA used, not restored<br />
CORCON saved, used, restored<br />
DOand REPEATinstruction usage:<br />
1 level DOinstructions<br />
no REPEATinstructions<br />
Program words (24-bit instructions):<br />
14<br />
Cycles (including C-function call and return overheads):<br />
17 + 4(numElems)<br />
VectorNegate<br />
Description: VectorNegatenegates (changes the sign of) the values of the<br />
elements in the source vector, and places them in the destination<br />
vector.<br />
Include: dsp.h<br />
Prototype: extern fractional* VectorNeg (<br />
int numElems,<br />
fractional* dstV,<br />
fractional* srcV<br />
);<br />
Arguments: numElems number of elements in source vector<br />
dstV pointer to destination vector<br />
srcV pointer to source vector<br />
Return Value: Pointer to base address of destination vector.<br />
srcV con trỏ tới vector nguồn<br />
Quay trở lại giá trị: Con trỏ trỏ tới địa chỉ cơ sở của vector đích.<br />
Bình luận: Giá trị đảo dấu của 0x8000 được thiết lập để 0x7FFF.<br />
Chức năng này có thể được tính tại chỗ.<br />
Source File: vneg.asm<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 22 2004 Microchip Technology Inc<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W5 sử dụng, không được khôi phục<br />
ACCA được sử dụng, không được khôi phục<br />
CORCON lưu, sử dụng, phục hồi<br />
DOand REPEATinstruction sử dụng:<br />
1 DOinstructions cấp<br />
không REPEATinstructions<br />
Từ chương trình (hướng dẫn 24-bit):<br />
16<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
19 + 4 (numElems)<br />
VectorPower<br />
Mô tả: VectorPowercomputes sức mạnh của một vector nguồn là tổng của<br />
các ô vuông của các yếu tố của nó.<br />
Bao gồm: dsp.h<br />
Prototype: fractionalVectorPower ở ngoài (<br />
int numElems,<br />
phân đoạn * srcV<br />
);<br />
Đối số: numElems số phần tử trong vector nguồn<br />
srcV con trỏ tới vector nguồn<br />
Quay trở lại giá trị: Giá trị của quyền lực của vector (tổng bình phương).<br />
Ghi chú: Nếu giá trị tuyệt đối của tổng bình phương lớn hơn 1-2<br />
-15<br />
, Điều này<br />
kết quả hoạt động trong độ bão hòa<br />
Chức năng này có thể áp dụng beself.<br />
Source File: vpow.asm<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W2 sử dụng, không được khôi phục
Remarks: The negated value of 0x8000 is set to 0x7FFF.<br />
This function can be computed in place.<br />
Source File: vneg.asm<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 22 2004 Microchip Technology Inc.<br />
Function Profile: System resources usage:<br />
W0..W5 used, not restored<br />
ACCA used, not restored<br />
CORCON saved, used, restored<br />
DOand REPEATinstruction usage:<br />
1 level DOinstructions<br />
no REPEATinstructions<br />
Program words (24-bit instructions):<br />
16<br />
Cycles (including C-function call and return overheads):<br />
19 + 4(numElems)<br />
VectorPower<br />
Description: VectorPowercomputes the power of a source vector as the sum of<br />
the squares of its elements.<br />
Include: dsp.h<br />
Prototype: extern fractionalVectorPower (<br />
int numElems,<br />
fractional* srcV<br />
);<br />
Arguments: numElems number of elements in source vector<br />
srcV pointer to source vector<br />
Return Value: Value of the vector’s power (sum of squares).<br />
Remarks: If the absolute value of the sum of squares is larger than 1-2<br />
-15<br />
, this<br />
operation results in saturation<br />
This function can beself applicable.<br />
Source File: vpow.asm<br />
Function Profile: System resources usage:<br />
W0..W2 used, not restored<br />
W4 used, not restored<br />
ACCA used, not restored<br />
W4 sử dụng, không được khôi phục<br />
ACCA được sử dụng, không được khôi phục<br />
CORCON lưu, sử dụng, phục hồi<br />
DOand REPEATinstruction sử dụng:<br />
không DOinstructions<br />
1 REPEATinstructions cấp<br />
Từ chương trình (hướng dẫn 24-bit):<br />
12<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
16 + 2 (numElems)<br />
VectorNegate (Tiếp theo)<br />
DSP Thư viện<br />
2004 Microchip Technology Inc DS51456B trang 23<br />
VectorScale<br />
Mô tả: VectorScalescales (bội) các giá trị của tất cả các yếu tố trong<br />
vector nguồn bởi một giá trị quy mô, và đặt kết quả ở đích đến<br />
vector.<br />
Bao gồm: dsp.h<br />
Nguyên mẫu: ở ngoài phân đoạn * VectorScale (<br />
int numElems,<br />
phân đoạn * DSTV,<br />
phân đoạn * srcV,<br />
phân đoạn sclVal<br />
);<br />
Đối số: numElems số phần tử trong vector nguồn<br />
DSTV con trỏ tới vector điểm đến<br />
srcV con trỏ tới vector nguồn<br />
sclVal giá trị mà quy mô các yếu tố vector<br />
Quay trở lại giá trị: Con trỏ trỏ tới địa chỉ cơ sở của vector đích.<br />
Bình luận: sclValmust là một số phân đoạn trong định dạng 1.15.<br />
Chức năng này có thể được tính tại chỗ.<br />
Source File: vscl.asm<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W5 sử dụng, không được khôi phục<br />
ACCA được sử dụng, không được khôi phục<br />
CORCON lưu, sử dụng, phục hồi<br />
DOand REPEATinstruction sử dụng:<br />
1 DOinstructions cấp<br />
không REPEATinstructions
CORCON saved, used, restored<br />
DOand REPEATinstruction usage:<br />
no DOinstructions<br />
1 level REPEATinstructions<br />
Program words (24-bit instructions):<br />
12<br />
Cycles (including C-function call and return overheads):<br />
16 + 2(numElems)<br />
VectorNegate (Continued)<br />
DSP Library<br />
2004 Microchip Technology Inc. DS51456B-page 23<br />
VectorScale<br />
Description: VectorScalescales (multiplies) the values of all the elements in the<br />
source vector by a scale value, and places the result in the destination<br />
vector.<br />
Include: dsp.h<br />
Prototype: extern fractional* VectorScale (<br />
int numElems,<br />
fractional* dstV,<br />
fractional* srcV,<br />
fractional sclVal<br />
);<br />
Arguments: numElems number of elements in source vector<br />
dstV pointer to destination vector<br />
srcV pointer to source vector<br />
sclVal value by which to scale vector elements<br />
Return Value: Pointer to base address of destination vector.<br />
Remarks: sclValmust be a fractional number in 1.15 format.<br />
This function can be computed in place.<br />
Source File: vscl.asm<br />
Function Profile: System resources usage:<br />
W0..W5 used, not restored<br />
ACCA used, not restored<br />
CORCON saved, used, restored<br />
DOand REPEATinstruction usage:<br />
1 level DOinstructions<br />
no REPEATinstructions<br />
Program words (24-bit instructions):<br />
14<br />
Từ chương trình (hướng dẫn 24-bit):<br />
14<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
18 + 3 (numElems)<br />
VectorSubtract<br />
Mô tả: VectorSubtractsubtracts giá trị của mỗi phần tử trong mã nguồn<br />
hai vector từ đối tác của mình trong nguồn một véc tơ, và những nơi<br />
dẫn đến việc vector đích.<br />
Bao gồm: dsp.h<br />
Nguyên mẫu: ở ngoài phân đoạn * VectorSubtract (<br />
int numElems,<br />
phân đoạn * DSTV,<br />
phân đoạn * srcV1,<br />
phân đoạn * srcV2<br />
);<br />
Đối số: numElems số phần tử trong vector nguồn<br />
DSTV con trỏ tới vector điểm đến<br />
con trỏ srcV1 nguồn onevector (để trừ)<br />
srcV2 con trỏ đến nguồn hai vector (số bị trừ)<br />
Quay trở lại giá trị: Con trỏ trỏ tới địa chỉ cơ sở của vector đích.<br />
Ghi chú: Nếu giá trị tuyệt đối của srcV1 [n] - srcV2 [n] là lớn hơn 1-2<br />
-15<br />
,<br />
hoạt động này dẫn đến độ bão hòa cho các phần tử n-thứ.<br />
Chức năng này có thể được tính tại chỗ.<br />
Chức năng này có thể tự áp dụng.<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 24 2004 Microchip Technology Inc<br />
Source File: vsub.asm<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W4 sử dụng, không được khôi phục<br />
ACCA được sử dụng, không được khôi phục<br />
ACCB sử dụng, không được khôi phục<br />
CORCON lưu, sử dụng, phục hồi<br />
DOand REPEATinstruction sử dụng:<br />
1 DOinstructions cấp<br />
không REPEATinstructions
Cycles (including C-function call and return overheads):<br />
18 + 3(numElems)<br />
VectorSubtract<br />
Description: VectorSubtractsubtracts the value of each element in the source<br />
two vector from its counterpart in the source one vector, and places the<br />
result in the destination vector.<br />
Include: dsp.h<br />
Prototype: extern fractional* VectorSubtract (<br />
int numElems,<br />
fractional* dstV,<br />
fractional* srcV1,<br />
fractional* srcV2<br />
);<br />
Arguments: numElems number of elements in source vectors<br />
dstV pointer to destination vector<br />
srcV1 pointer to source onevector (minuend)<br />
srcV2 pointer to source two vector (subtrahend)<br />
Return Value: Pointer to base address of destination vector.<br />
Remarks: If the absolute value of srcV1[n] - srcV2[n]is larger than 1-2<br />
-15<br />
,<br />
this operation results in saturation for the n-th element.<br />
This function can be computed in place.<br />
This function can be self applicable.<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
Từ chương trình (hướng dẫn 24-bit):<br />
14<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
17 + 4 (numElems)<br />
VectorZeroPad<br />
Mô tả: VectorZeroPadcopies vector nguồn vào đầu<br />
(Đã có sẵn) vector đích, và sau đó lấp đầy với các số không<br />
numZeroselements của vector điểm còn lại:<br />
DSTV [n] = srcV [n], 0 ≤n
Cycles (including C-function call and return overheads):<br />
17 + 4(numElems)<br />
VectorZeroPad<br />
Description: VectorZeroPadcopies the source vector into the beginning of the<br />
(already existing) destination vector, and then fills with zeros the<br />
remaining numZeroselements of destination vector:<br />
dstV[n]= srcV[n], 0 ≤n < numElems<br />
dstV[n]= 0, numElems≤n
plus program words from VectorCopy<br />
Cycles (including C-function call and return overheads):<br />
18 + numZeros<br />
plus cycles from VectorCopy.<br />
Note:In the description of VectorCopy, the number of cycles reported<br />
includes 3 cycles of C-function calloverhead. Thus, the number of<br />
actual cycles from VectorCopyto add to VectorCorrelateis 3 less<br />
than whatever number is reported for a stand alone VectorCopy.<br />
VectorZeroPad (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
thành<br />
mỗi lần gọi hàm.<br />
d) Kể từ khi chức năng khởi tạo cửa sổ được thực hiện trong C, tham khảo ý<br />
kiến<br />
tài liệu điện tử bao gồm trong bản phát hành cho số cập nhật lên chu kỳ<br />
thông tin.<br />
2.4.2 Chức năng cá nhân<br />
Trong phần tiếp theo, các chức năng cá nhân thực hiện các hoạt động cửa sổ là<br />
mô tả.<br />
BartlettInit<br />
Mô tả: BartlettInitinitializes một cửa sổ Barlett numElems dài.<br />
Bao gồm: dsp.h<br />
Nguyên mẫu: ở ngoài phân đoạn * BartlettInit (<br />
DS51456B-page 26<br />
2004 Microchip Technology Inc.<br />
int numElems,<br />
2.4 WINDOW FUNCTIONS<br />
A window is a vector with a specific value distribution within its domain (0 ≤n<br />
<<br />
numElems). The particular value distribution depends on the characteristics of<br />
the<br />
window being generated.<br />
Given a vector, its value distribution may be modified by applying a window to<br />
it. In<br />
these cases, the window musthave the same number of elements as the vector to<br />
modify.<br />
Before a vector can be windowed, the window must be created. Window<br />
initialization<br />
operations are provided which generate the values of the window elements. For<br />
higher<br />
numerical precision, these values are computed in floating point arithmetic, and<br />
the<br />
resulting quantities stored as 1.15 fractionals.<br />
To avoid excessive overhead when applying a window operation, a particular<br />
window<br />
could be generated once and used many times during the execution of the<br />
program.<br />
Thus, it is advisable to store the window returned by any of the initialization<br />
operations<br />
in a permanent (static) vector.<br />
2.4.1 User Considerations<br />
a) All the window initialization functions have been designed to generate<br />
window<br />
vectors allocated in default RAM memory space (X-Data or Y-Data).<br />
b) The windowing function is designed to operate on vectors allocated in default<br />
RAM memory space (X-Data or Y-Data).<br />
* phân đoạn cửa sổ<br />
);<br />
Đối số: numElems số phần tử trong cửa sổ<br />
cửa sổ con trỏ đến cửa sổ phải được khởi tạo<br />
Quay trở lại giá trị: Con trỏ trỏ tới địa chỉ cơ sở của cửa sổ khởi tạo.<br />
Chú ý: windowvector mustalready tồn tại, với chính xác numElemsnumber<br />
các yếu tố.<br />
Source File: initbart.c<br />
DSP Thư viện<br />
2004 Microchip Technology Inc DS51456B trang 27<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W7 sử dụng, không được khôi phục<br />
W8..W14 lưu, sử dụng, không được khôi phục<br />
DOand REPEATinstruction sử dụng:<br />
Không<br />
Từ chương trình (hướng dẫn 24-bit):<br />
Xem các tập tin "Readme cho dsPIC bằng các ngôn ngữ Libraries.txt" cho<br />
thông tin này.<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
Xem các tập tin "Readme cho dsPIC bằng các ngôn ngữ Libraries.txt" cho<br />
thông tin này.<br />
BlackmanInit<br />
Mô tả: BlackmanInitinitializes một Blackman (3 học kỳ) cửa sổ của chiều dài<br />
numElems.<br />
Bao gồm: dsp.h<br />
Nguyên mẫu: ở ngoài phân đoạn * BlackmanInit (
c) It is recommended that the Status register (SR) be examined after completion<br />
of<br />
each function call.<br />
d) Since the window initialization functions are implemented in C, consult the<br />
electronic documentation included in the release for up-to-date cycle count<br />
information.<br />
2.4.2 Individual Functions<br />
In what follows, the individual functions implementing window operations are<br />
described.<br />
BartlettInit<br />
Description: BartlettInitinitializes a Barlett window of length numElems.<br />
Include: dsp.h<br />
Prototype: extern fractional* BartlettInit (<br />
int numElems,<br />
fractional* window<br />
);<br />
Arguments: numElems number of elements in window<br />
window pointer to window to be initialized<br />
Return Value: Pointer to base address of initialized window.<br />
Remarks: The windowvector mustalready exist, with exactly numElemsnumber<br />
of elements.<br />
Source File: initbart.c<br />
int numElems,<br />
* phân đoạn cửa sổ<br />
);<br />
Đối số: numElems số phần tử trong cửa sổ<br />
cửa sổ con trỏ đến cửa sổ phải được khởi tạo<br />
Quay trở lại giá trị: Con trỏ trỏ tới địa chỉ cơ sở của cửa sổ khởi tạo.<br />
Chú ý: windowvector mustalready tồn tại, với chính xác numElemsnumber<br />
các yếu tố.<br />
Source File: initblck.c<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W7 sử dụng, không được khôi phục<br />
W8..W14 lưu, sử dụng, không được khôi phục<br />
DOand REPEATinstruction sử dụng:<br />
Không<br />
Từ chương trình (hướng dẫn 24-bit):<br />
Xem file "readme.txt" trong pic30_tools \ src \ DSP cho thông tin này.<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
Xem file "readme.txt" trong pic30_tools \ src \ DSP cho thông tin này.<br />
BartlettInit (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DSP Library<br />
2004 Microchip Technology Inc. DS51456B-page 27<br />
DS51456B trang 28<br />
HammingInit<br />
2004 Microchip Technology Inc<br />
Function Profile: System resources usage:<br />
W0..W7 used, not restored<br />
W8..W14 saved, used, not restored<br />
DOand REPEATinstruction usage:<br />
None<br />
Program words (24-bit instructions):<br />
See the file “Readme for dsPIC Language Tools Libraries.txt” for<br />
this information.<br />
Cycles (including C-function call and return overheads):<br />
See the file “Readme for dsPIC Language Tools Libraries.txt” for<br />
this information.<br />
BlackmanInit<br />
Description: BlackmanInitinitializes a Blackman (3 terms) window of length<br />
numElems.<br />
Include: dsp.h<br />
Mô tả: HammingInitinitializes một cửa sổ Hamming của numElems dài.<br />
Bao gồm: dsp.h<br />
Nguyên mẫu: ở ngoài phân đoạn * HammingInit (<br />
int numElems,<br />
* phân đoạn cửa sổ<br />
);<br />
Đối số: numElems số phần tử trong cửa sổ<br />
cửa sổ con trỏ đến cửa sổ phải được khởi tạo<br />
Quay trở lại giá trị: Con trỏ trỏ tới địa chỉ cơ sở của cửa sổ khởi tạo.<br />
Chú ý: windowvector mustalready tồn tại, với chính xác numElemsnumber<br />
các yếu tố.<br />
Source File: inithamm.c<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W7 sử dụng, không được khôi phục<br />
W8..W14 lưu, sử dụng, không được khôi phục
Prototype: extern fractional* BlackmanInit (<br />
int numElems,<br />
fractional* window<br />
);<br />
Arguments: numElems number of elements in window<br />
window pointer to window to be initialized<br />
Return Value: Pointer to base address of initialized window.<br />
Remarks: The windowvector mustalready exist, with exactly numElemsnumber<br />
of elements.<br />
Source File: initblck.c<br />
Function Profile: System resources usage:<br />
W0..W7 used, not restored<br />
W8..W14 saved, used, not restored<br />
DOand REPEATinstruction usage:<br />
None<br />
Program words (24-bit instructions):<br />
See the file “readme.txt” in pic30_tools\src\dsp for this information.<br />
Cycles (including C-function call and return overheads):<br />
See the file “readme.txt” in pic30_tools\src\dsp for this information.<br />
BartlettInit (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 28 2004 Microchip Technology Inc.<br />
HammingInit<br />
Description: HammingInitinitializes a Hamming window of length numElems.<br />
Include: dsp.h<br />
Prototype: extern fractional* HammingInit (<br />
int numElems,<br />
fractional* window<br />
);<br />
Arguments: numElems number of elements in window<br />
window pointer to window to be initialized<br />
Return Value: Pointer to base address of initialized window.<br />
Remarks: The windowvector mustalready exist, with exactly numElemsnumber<br />
of elements.<br />
Source File: inithamm.c<br />
Function Profile: System resources usage:<br />
W0..W7 used, not restored<br />
DOand REPEATinstruction sử dụng:<br />
Không<br />
Từ chương trình (hướng dẫn 24-bit):<br />
Xem file "readme.txt" trong pic30_tools \ src \ DSP cho thông tin này.<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
Xem file "readme.txt" trong pic30_tools \ src \ DSP cho thông tin này.<br />
HanningInit<br />
Mô tả: HanningInitinitializes một cửa sổ Hanning của numElems dài.<br />
Bao gồm: dsp.h<br />
Nguyên mẫu: ở ngoài phân đoạn * HanningInit (<br />
int numElems,<br />
* phân đoạn cửa sổ<br />
);<br />
Đối số: numElems số phần tử trong cửa sổ<br />
cửa sổ con trỏ đến cửa sổ phải được khởi tạo<br />
Quay trở lại giá trị: Con trỏ trỏ tới địa chỉ cơ sở của cửa sổ khởi tạo.<br />
Chú ý: windowvector mustalready tồn tại, với chính xác numElemsnumber<br />
các yếu tố.<br />
Source File: inithann.c<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W7 sử dụng, không được khôi phục<br />
W8..W14 lưu, sử dụng, không được khôi phục<br />
DOand REPEATinstruction sử dụng:<br />
Không<br />
Từ chương trình (hướng dẫn 24-bit):<br />
Xem file "readme.txt" trong pic30_tools \ src \ DSP cho thông tin này.<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
Xem file "readme.txt" trong pic30_tools \ src \ DSP cho thông tin này.<br />
DSP Thư viện<br />
2004 Microchip Technology Inc DS51456B trang 29<br />
KaiserInit<br />
Mô tả: KaiserInitinitializes một cửa sổ Kaiser với hình dạng xác định bằng<br />
Lập luận của betaValand numElems dài.<br />
Bao gồm: dsp.h<br />
Nguyên mẫu: ở ngoài phân đoạn * KaiserInit (<br />
int numElems,<br />
* phân đoạn cửa sổ,<br />
nổi betaVal<br />
);
W8..W14 saved, used, not restored<br />
DOand REPEATinstruction usage:<br />
None<br />
Program words (24-bit instructions):<br />
See the file “readme.txt” in pic30_tools\src\dsp for this information.<br />
Cycles (including C-function call and return overheads):<br />
See the file “readme.txt” in pic30_tools\src\dsp for this information.<br />
HanningInit<br />
Description: HanningInitinitializes a Hanning window of length numElems.<br />
Include: dsp.h<br />
Prototype: extern fractional* HanningInit (<br />
int numElems,<br />
fractional* window<br />
);<br />
Arguments: numElems number of elements in window<br />
window pointer to window to be initialized<br />
Return Value: Pointer to base address of initialized window.<br />
Remarks: The windowvector mustalready exist, with exactly numElemsnumber<br />
of elements.<br />
Source File: inithann.c<br />
Function Profile: System resources usage:<br />
W0..W7 used, not restored<br />
W8..W14 saved, used, not restored<br />
DOand REPEATinstruction usage:<br />
None<br />
Program words (24-bit instructions):<br />
See the file “readme.txt” in pic30_tools\src\dsp for this information.<br />
Cycles (including C-function call and return overheads):<br />
See the file “readme.txt” in pic30_tools\src\dsp for this information.<br />
DSP Library<br />
2004 Microchip Technology Inc. DS51456B-page 29<br />
KaiserInit<br />
Description: KaiserInitinitializes a Kaiser window with shape determined by<br />
argument betaValand of length numElems.<br />
Include: dsp.h<br />
Prototype: extern fractional* KaiserInit (<br />
int numElems,<br />
fractional* window,<br />
float betaVal<br />
Đối số: numElems số phần tử trong cửa sổ<br />
cửa sổ con trỏ đến cửa sổ phải được khởi tạo<br />
betaVal tham số hình cửa sổ<br />
Quay trở lại giá trị: Con trỏ trỏ tới địa chỉ cơ sở của cửa sổ khởi tạo.<br />
Chú ý: windowvector mustalready tồn tại, với chính xác numElemsnumber<br />
các yếu tố.<br />
Source File: initkais.c<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W7 sử dụng, không được khôi phục<br />
W8..W14 lưu, sử dụng, không được khôi phục<br />
DOand REPEATinstruction sử dụng:<br />
Không<br />
Từ chương trình (hướng dẫn 24-bit):<br />
Xem file "readme.txt" trong pic30_tools \ src \ DSP cho thông tin này.<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
Xem file "readme.txt" trong pic30_tools \ src \ DSP cho thông tin này.<br />
VectorWindow<br />
Mô tả: VectorWindowapplies một cửa sổ để một vector nguồn được đưa ra, và<br />
các cửa hàng<br />
vector cửa sổ kết quả trong một vector đích.<br />
Bao gồm: dsp.h<br />
Nguyên mẫu: ở ngoài phân đoạn * VectorWindow (<br />
int numElems,<br />
phân đoạn * DSTV,<br />
phân đoạn * srcV,<br />
* phân đoạn cửa sổ<br />
);<br />
Đối số: numElems số phần tử trong vector nguồn<br />
DSTV con trỏ tới vector điểm đến<br />
srcV con trỏ tới vector nguồn<br />
cửa sổ con trỏ đến cửa sổ khởi tạo<br />
Quay trở lại giá trị: Con trỏ trỏ tới địa chỉ cơ sở của vector đích.<br />
Chú ý: musthave windowvector đã được khởi tạo, với chính xác<br />
numElemsnumber của các yếu tố.<br />
Chức năng này có thể được tính tại chỗ.<br />
Chức năng này có thể tự áp dụng.<br />
Chức năng này sử dụng VectorMultiply.<br />
Source File: dowindow.asm<br />
dsPIC<br />
®
);<br />
Arguments: numElems number of elements in window<br />
window pointer to window to be initialized<br />
betaVal window shaping parameter<br />
Return Value: Pointer to base address of initialized window.<br />
Remarks: The windowvector mustalready exist, with exactly numElemsnumber<br />
of elements.<br />
Source File: initkais.c<br />
Function Profile: System resources usage:<br />
W0..W7 used, not restored<br />
W8..W14 saved, used, not restored<br />
DOand REPEATinstruction usage:<br />
None<br />
Program words (24-bit instructions):<br />
See the file “readme.txt” in pic30_tools\src\dsp for this information.<br />
Cycles (including C-function call and return overheads):<br />
See the file “readme.txt” in pic30_tools\src\dsp for this information.<br />
VectorWindow<br />
Description: VectorWindowapplies a window to a given source vector, and<br />
stores<br />
the resulting windowed vector in a destination vector.<br />
Include: dsp.h<br />
Prototype: extern fractional* VectorWindow (<br />
int numElems,<br />
fractional* dstV,<br />
fractional* srcV,<br />
fractional* window<br />
);<br />
Arguments: numElems number of elements in source vector<br />
dstV pointer to destination vector<br />
srcV pointer to source vector<br />
window pointer to initialized window<br />
Return Value: Pointer to base address of destination vector.<br />
Remarks: The windowvector musthave already been initialized, with exactly<br />
numElemsnumber of elements.<br />
This function can be computed in place.<br />
This function can be self applicable.<br />
This function uses VectorMultiply.<br />
Source File: dowindow.asm<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 30<br />
2004 Microchip Technology Inc<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
nguồn lực từ VectorMultiply<br />
DOand REPEATinstruction sử dụng:<br />
không DOinstructions<br />
không REPEATinstructions,<br />
cộng với DO / REPEATfrom VectorMultiply<br />
Từ chương trình (hướng dẫn 24-bit):<br />
3,<br />
cộng thêm từ chương trình từ VectorMultiply<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
9,<br />
cộng với chu kỳ từ VectorMultiply.<br />
Lưu ý: Trong các mô tả về số VectorMultiplythe của chu kỳ<br />
báo cáo bao gồm 3 chu kỳ của C-chức năng gọi điện trên không. Như vậy,<br />
số chu kỳ thực tế từ VectorMultiplyto thêm vào<br />
VectorWindowis 3 ít hơn bất cứ số được báo cáo cho một đứng<br />
một mình<br />
VectorMultiply.<br />
VectorWindow (Tiếp theo)<br />
DSP Thư viện<br />
2004 Microchip Technology Inc DS51456B trang 31<br />
2,5 chức năng MATRIX<br />
Phần này trình bày các khái niệm về một ma trận phân đoạn, như xem xét bởi<br />
DSP<br />
Thư viện, và mô tả các chức năng cá nhân đó thực hiện hoạt động ma trận.<br />
2.5.1 Fractional hoạt động Matrix<br />
Một ma trận phân đoạn là một tập hợp các giá trị số, các yếu tố ma trận, phân b<br />
liên tục kế nhau trong bộ nhớ, với người đầu tiên elementAt địa chỉ bộ nhớ thấp<br />
nhất. Một từ<br />
bộ nhớ (hai byte) được sử dụng để lưu trữ các giá trị của mỗi phần tử, và số<br />
lượng này<br />
phải được hiểu như là một phân số đại diện trong định dạng 1.15.<br />
Một con trỏ địa chỉ phần tử đầu tiên của ma trận được sử dụng như một xử lý<br />
cung cấp<br />
tiếp cận với mỗi giá trị ma trận. Địa chỉ của phần tử đầu tiên được gọi là<br />
địa chỉ cơ sở của ma trận. Bởi vì mỗi phần tử của ma trận là 16 bit, các cơ sở<br />
địa chỉ mustbe liên kết đến một địa chỉ mặc.<br />
Việc bố trí hai chiều của một matrixis mô phỏng trong lĩnh vực bộ nhớ lưu trữ<br />
bằng cách đặt các thành phần của nó được tổ chức hàng để lớn. Như vậy, giá trị<br />
đầu tiên trong bộ nhớ là
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 30<br />
2004 Microchip Technology Inc.<br />
Function Profile: System resources usage:<br />
resources from VectorMultiply<br />
DOand REPEATinstruction usage:<br />
no DOinstructions<br />
no REPEATinstructions,<br />
plus DO/REPEATfrom VectorMultiply<br />
Program words (24-bit instructions):<br />
3,<br />
plus program words from VectorMultiply<br />
Cycles (including C-function call and return overheads):<br />
9,<br />
plus cycles from VectorMultiply.<br />
Note:In the description of VectorMultiplythe number of cycles<br />
reported includes 3 cycles of C-function call overhead. Thus, the<br />
number of actual cycles from VectorMultiplyto add to<br />
VectorWindowis 3 less than whatever number is reported for a stand<br />
alone<br />
VectorMultiply.<br />
VectorWindow (Continued)<br />
DSP Library<br />
2004 Microchip Technology Inc. DS51456B-page 31<br />
2.5 MATRIX FUNCTIONS<br />
This section presents the concept of a fractional matrix, as considered by the<br />
DSP<br />
Library, and describes the individual functions which perform matrix<br />
operations.<br />
2.5.1 Fractional Matrix Operations<br />
A fractional matrix is a collection of numerical values, the matrix elements,<br />
allocated<br />
contiguously in memory, with the first elementat the lowest memory address.<br />
One word<br />
of memory (two bytes) is used to store the value of each element, and this<br />
quantity<br />
must be interpreted as a fractional number represented in 1.15 format.<br />
A pointer addressing the first element of the matrix is used as a handle which<br />
provides<br />
access to each of the matrix values. The address of the first element is referred<br />
to as<br />
các yếu tố đầu tiên của dòng đầu tiên. Tiếp sau đó là phần còn lại của các phần<br />
tử của hàng đầu tiên.<br />
Sau đó, các phần tử của hàng thứ hai được lưu trữ, và như vậy, cho đến khi tất<br />
cả các hàng trong<br />
bộ nhớ. Bằng cách này, các phần tử ở hàng r và cột c của một ma trận với hàng<br />
R và C<br />
cột nằm từ ma trận cơ sở địa chỉ cử nhân tại:<br />
BA + 2 (C (r-1) + c-1), cho 1 ≤r ≤R, 1 ≤c ≤C.<br />
Lưu ý rằng hệ số 2 được sử dụng vì các byte khả năng của địa chỉ<br />
dsPIC30F.<br />
Hoạt động ma trận phân đoạn nguyên phân và nhị phân được thực hiện trong<br />
thư viện này. Các<br />
ma trận toán hạng trong một hoạt động nguyên phân được gọi là nguồn ma<br />
trận. Trong một hoạt động nhị phân<br />
toán hạng đầu tiên được gọi là nguồn một ma trận, và ma trận thứ hai là<br />
nguồn hai ma trận. Mỗi hoạt động áp dụng một số tính toán cho một hoặc một<br />
số<br />
các yếu tố của nguồn ma trận (CES). Các hoạt động hợp kết quả trong một ma<br />
trận, gọi là<br />
ma trận đích.<br />
Một số hoạt động kết quả trong một ma trận cho phép tính toán tại chỗ. Điều<br />
này có nghĩa<br />
kết quả của các hoạt động được đặt trở lại vào ma trận nguồn (hoặc nguồn một<br />
ma trận<br />
cho một hoạt động nhị phân). Trong trường hợp này, ma trận điểm đến được<br />
cho là (vật lý) thay thế<br />
nguồn (một) ma trận. Nếu một hoạt động có thể được tính tại chỗ, nó được chỉ<br />
định như<br />
như trong các ý kiến được cung cấp với mô tả chức năng.<br />
Đối với một số hoạt động nhị phân, hai toán hạng có thể giống nhau (vật lý)<br />
nguồn<br />
ma trận, có nghĩa là các hoạt động được áp dụng cho ma trận nguồn và bản<br />
thân. Nếu loại<br />
tính toán là có thể cho một hoạt động nào đó, nó được chỉ định như vậy trong<br />
các ý kiến<br />
cung cấp với mô tả chức năng.<br />
Một số hoạt động có thể tự áp dụng và tính toán tại chỗ.<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 32<br />
2004 Microchip Technology Inc<br />
Tất cả các hoạt động ma trận phân đoạn trong thư viện này có số lượng hàng<br />
như các đối số<br />
và số lượng các cột của ma trận toán hạng (CES). Căn cứ vào các giá trị của các<br />
đối số giả định sau đây được thực hiện:<br />
a) Tổng kích thước của tất cả các ma trận tham gia vào một hoạt động cụ thể<br />
nằm trong
the base address of the matrix. Because each element of the matrix is 16 bits, the<br />
base<br />
address mustbe aligned to an even address.<br />
The two dimensional arrangement of a matrixis emulated in the memory storage<br />
area<br />
by placing its elements organized in row major order. Thus, the first value in<br />
memory is<br />
the first element of the first row. It is followed by the rest of the elements of the<br />
first row.<br />
Then, the elements of the second row are stored, and so on, until all the rows are<br />
in<br />
memory. This way, the element at row r and column c of a matrix with R rows<br />
and C<br />
columns is located from the matrix base address BA at:<br />
BA + 2(C(r-1) + c-1), for 1 ≤r ≤R, 1 ≤c ≤C.<br />
Note that the factor of 2 is used because of the byte addressing capabilities of<br />
the<br />
dsPIC30F.<br />
Unary and binary fractional matrix operations are implemented in this library.<br />
The<br />
operand matrix in a unary operation is called the source matrix. In a binary<br />
operation<br />
the first operand is referred to as the source one matrix, and the second matrix<br />
as the<br />
source two matrix. Each operation applies some computation to one or several<br />
elements of the source matrix(ces). The operations result in a matrix, referred to<br />
as the<br />
destination matrix.<br />
Some operations resulting in a matrix allow computation in place. This means<br />
the<br />
results of the operation is placed back into the source matrix (or the source one<br />
matrix<br />
for a binary operation). In this case, the destination matrix is said to (physically)<br />
replace<br />
the source (one) matrix. If an operation can be computed in place, it is indicated<br />
as<br />
such in the comments provided with the function description.<br />
For some binary operations, the two operands can be the same (physical) source<br />
matrix, which means the operation is applied to the source matrix and itself. If<br />
this type<br />
of computation is possible for a given operation,it is indicated as such in the<br />
comments<br />
provided with the function description.<br />
Some operations can be self applicable and computed in place.<br />
dsPIC<br />
®<br />
phạm vi của bộ nhớ dữ liệu có sẵn cho các thiết bị mục tiêu.<br />
b) Trong trường hợp hoạt động nhị phân số hàng và cột của toán hạng<br />
ma trận mustobey các quy tắc của vector đại số; tức là, cho ma trận cộng và trừ<br />
hai ma trận phải có cùng số hàng và cột,<br />
trong khi cho phép nhân ma trận, số lượng các cột của toán hạng phải đầu tiên<br />
giống như số lượng hàng của toán hạng thứ hai. Nguồn ma trận<br />
các hoạt động đảo ngược phải vuông (cùng một số hàng như của<br />
cột), và không ít (yếu tố quyết định của nó khác nhau hơn không).<br />
c) ma trận điểm đến mustbe đủ lớn để chấp nhận các kết quả của một hoạt động<br />
2.5.2 Xem xét tài khoản<br />
a) Không kiểm tra ranh giới được thực hiện bởi các chức năng này. Trong phạm<br />
vi kích thước<br />
(Bao gồm cả hàng không và / hoặc không có ma trận cột) cũng như sử dụng<br />
không phù hợp<br />
nguồn kích thước ma trận trong hoạt động nhị phân có thể tạo ra kết quả bất<br />
ngờ.<br />
b) Các cộng và trừ các hoạt động ma trận có thể dẫn đến bão hòa nếu tổng<br />
các yếu tố tương ứng trong nguồn (s) ma trận (CES) lớn hơn 1-2<br />
-15<br />
hoặc<br />
nhỏ hơn -1.<br />
c) Các hoạt động nhân ma trận có thể dẫn đến bão hòa nếu tổng sản phẩm<br />
các hàng và cột bộ kết quả tương ứng trong giá trị lớn hơn 1-2<br />
-15<br />
hoặc<br />
nhỏ hơn -1.<br />
d) Đó là khuyến cáo rằng tình trạng đăng ký (SR) được kiểm tra sau khi hoàn<br />
thành<br />
mỗi lần gọi hàm. Đặc biệt, người dùng có thể kiểm tra việc SA, SB và SAB cờ<br />
sau<br />
hàm trả về để xác định độ bão hòa xảy ra.<br />
e) Tất cả các chức năng đã được thiết kế để hoạt động trên các ma trận phân<br />
đoạn phân bổ<br />
trong không gian bộ nhớ RAM mặc định (X-Y-dữ liệu hoặc dữ liệu).<br />
e) Các hoạt động đó trả về một ma trận điểm đến có thể được lồng vào nhau, do<br />
đó ví dụ<br />
nếu:<br />
a = OP1 (b, c), với b = OP2 (d) và c = op3 (e, f), sau đó<br />
a = OP1 (OP2 (d), op3 (e, f))<br />
2.5.3 Bình luận khác<br />
Mô tả các chức năng giới hạn phạm vi của nó những gì có thể được coi là<br />
thường xuyên<br />
sử dụng các hoạt động này. Tuy nhiên, vì không có kiểm tra biên giới được thự<br />
hiện trong quá trình<br />
tính toán của các chức năng này, bạn có quyền tự do để giải thích các hoạt động
Language Tools Libraries<br />
DS51456B-page 32<br />
2004 Microchip Technology Inc.<br />
All the fractional matrix operations in this library take as arguments the number<br />
of rows<br />
and the number of columns of the operand matrix(ces). Based on the values of<br />
these<br />
argument the following assumptions are made:<br />
a) The sum of sizes of all the matrices involved in a particular operation falls<br />
within<br />
the range of available data memory for the target device.<br />
b) In the case of binary operations the number of rows and columns of the<br />
operand<br />
matrices mustobey the rules of vector algebra; i.e., for matrix addition and<br />
subtraction the two matrices must have the same number of rows and columns,<br />
while for matrix multiplication, the number of columns of the first operand must<br />
be the same as the number of rows of the second operand. The source matrix to<br />
the inversion operation must be square (the same number of rows as of<br />
columns), and non-singular (its determinant different than zero).<br />
c) The destination matrix mustbe large enough to accept the results of an<br />
operation.<br />
2.5.2 User Considerations<br />
a) No boundary checking is performed by these functions. Out of range<br />
dimensions<br />
(including zero row and/or zero column matrices) as well as nonconforming use<br />
of source matrix sizes in binary operations may produce unexpected results.<br />
b) The matrix addition and subtraction operations could lead to saturation if the<br />
sum<br />
of corresponding elements in the source(s) matrix(ces) is greater than 1-2<br />
-15<br />
or<br />
smaller than -1.<br />
c) The matrix multiplication operation could lead to saturation if the sum of<br />
products<br />
of corresponding row and column sets results in a value greater than 1-2<br />
-15<br />
or<br />
hnical Support1.<br />
d) It is recommended that the status register (SR) is examined after completion<br />
of<br />
each function call. In particular, users can inspect the SA, SB and SAB flags<br />
after<br />
the function returns to determine if saturation occurred.<br />
e) All the functions have been designed to operate on fractional matrices<br />
allocated<br />
của mình và<br />
kết quả là nó phù hợp với một số nhu cầu đặc biệt.<br />
Ví dụ, trong khi tính toán MatrixMultiplyfunction, kích thước của<br />
intervining ma trận không nhất thiết cần phải được {numRows1,<br />
numCos1Rows2} cho<br />
nguồn một ma trận, {numCols1Rows2, numCols2} cho nguồn hai ma trận, và<br />
{numRows1,<br />
numCols2} cho ma trận đích. Trong thực tế, tất cả các thatis cần thiết là kích<br />
thước của chúng lớn<br />
đủ để trong quá trình tính toán các con trỏ cũng không vượt quá mức phạm vi<br />
bộ nhớ của họ.<br />
Một ví dụ khác, khi một ma trận nguồn kích thước {numrows, numCols} là<br />
hoán, ma trận điểm có kích thước {numCols, numrows}. Như vậy, đúng cách<br />
nói các hoạt động có thể được tính ở vị trí onlyif ma trận nguồn là hình vuông.<br />
Tuy nhiên, các hoạt động có thể được áp dụng thành công tại chỗ để không<br />
vuông<br />
ma trận; tất cả những gì cần phải được giữ trong tâm trí là implicitchange kích<br />
thước.<br />
DSP Thư viện<br />
2004 Microchip Technology Inc DS51456B trang 33<br />
Khả năng khác có thể được khai thác từ thực tế là không có kiểm tra ranh giới<br />
thực hiện.<br />
2.5.4 Chức năng cá nhân<br />
Trong phần tiếp theo, các chức năng cá nhân thực hiện hoạt động ma trận được<br />
mô tả.<br />
MatrixAdd<br />
Mô tả: MatrixAddadds giá trị của mỗi elementin nguồn một ma trận<br />
với đối tác của mình trong nguồn hai ma trận, và đặt kết quả trong<br />
ma trận đích.<br />
Bao gồm: dsp.h<br />
Nguyên mẫu: ở ngoài phân đoạn * MatrixAdd (<br />
int numrows,<br />
numCols int,<br />
phân đoạn * dstM,<br />
phân đoạn * srcM1,<br />
phân đoạn * srcM2<br />
);<br />
Đối số: numrows số hàng trong ma trận nguồn<br />
numCols số lượng cột trong ma trận nguồn<br />
dstM con trỏ đến ma trận điểm<br />
srcM1 con trỏ đến nguồn một ma trận<br />
srcM2 con trỏ đến nguồn hai ma trận<br />
Quay trở lại giá trị: Con trỏ trỏ tới địa chỉ cơ sở của ma trận đích.
in default RAM memory space (X-Data or Y-Data).<br />
f) Operations which return a destination matrix can be nested, so that for<br />
instance<br />
if:<br />
a = Op1 (b, c), with b = Op2 (d), and c = Op3 (e, f), then<br />
a = Op1 (Op2 (d), Op3 (e, f))<br />
2.5.3 Additional Remarks<br />
The description of the functions limits its scope to what could be considered the<br />
regular<br />
usage of these operations. However, since no boundary checking is performed<br />
during<br />
computation of these functions, you have the freedom to interpret the operation<br />
and its<br />
results as it fits some particular needs.<br />
For instance, while computing the MatrixMultiplyfunction, the dimensions of<br />
the<br />
intervining matrices does not necessarily need to be {numRows1,<br />
numCos1Rows2} for<br />
source one matrix, {numCols1Rows2, numCols2} for source two matrix, and<br />
{numRows1,<br />
numCols2} for destination matrix. In fact, all thatis needed is that their sizes are<br />
large<br />
enough so that during computation the pointers do no exceed over their memory<br />
range.<br />
As another example, when a source matrix of dimension {numRows, numCols}<br />
is<br />
transposed, the destination matrix has dimensions {numCols, numRows}. Thus,<br />
properly<br />
speaking the operation can be computed in place onlyif source matrix is square.<br />
Nevertheless, the operation can be successfully applied in place to non square<br />
matrices; all that needs to be kept in mind is the implicitchange of dimensions.<br />
DSP Library<br />
2004 Microchip Technology Inc. DS51456B-page 33<br />
Other possibilities can be exploited from the fact that no boundary checking is<br />
performed.<br />
2.5.4 Individual Functions<br />
In what follows, the individual functions implementing matrix operations are<br />
described.<br />
MatrixAdd<br />
Description: MatrixAddadds the value of each elementin the source one matrix<br />
with its counterpart in the source two matrix, and places the result in the<br />
destination matrix.<br />
Include: dsp.h<br />
Prototype: extern fractional* MatrixAdd (<br />
Ghi chú: Nếu giá trị tuyệt đối của srcM1 [r] [c] + srcM2 [r] [c] lớn hơn<br />
1-2<br />
-15<br />
, Kết quả hoạt động này trong độ bão hòa cho (r, c) các yếu tố -thứ.<br />
Chức năng này có thể được tính tại chỗ.<br />
Chức năng này có thể tự áp dụng.<br />
Source File: madd.asm<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W4 sử dụng, không được khôi phục<br />
ACCA được sử dụng, không được khôi phục<br />
CORCON lưu, sử dụng, phục hồi<br />
DOand REPEATinstruction sử dụng:<br />
1 DOinstructions cấp<br />
không REPEATinstructions<br />
Từ chương trình (hướng dẫn 24-bit):<br />
14<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
20 + 3 (numrows * numCols)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 34 2004 Microchip Technology Inc<br />
MatrixMultiply<br />
Mô tả: MatrixMultiplyperforms phép nhân ma trận giữa<br />
một nguồn và nguồn hai ma trận, và đặt kết quả trong<br />
ma trận đích. Tượng trưng:<br />
trong đó:<br />
0 ≤i
int numRows,<br />
int numCols,<br />
fractional* dstM,<br />
fractional* srcM1,<br />
fractional* srcM2<br />
);<br />
Arguments: numRows number of rows in source matrices<br />
numCols number of columns in source matrices<br />
dstM pointer to destination matrix<br />
srcM1 pointer to source one matrix<br />
srcM2 pointer to source two matrix<br />
Return Value: Pointer to base address of destination matrix.<br />
Remarks: If the absolute value of srcM1[r][c]+srcM2[r][c]is larger than<br />
1-2<br />
-15<br />
, this operation results in saturation for the (r,c)-th element.<br />
This function can be computed in place.<br />
This function can be self applicable.<br />
Source File: madd.asm<br />
Function Profile: System resources usage:<br />
W0..W4 used, not restored<br />
ACCA used, not restored<br />
CORCON saved, used, restored<br />
DOand REPEATinstruction usage:<br />
1 level DOinstructions<br />
no REPEATinstructions<br />
Program words (24-bit instructions):<br />
14<br />
Cycles (including C-function call and return overheads):<br />
20 + 3(numRows*numCols)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 34 2004 Microchip Technology Inc.<br />
MatrixMultiply<br />
Description: MatrixMultiplyperforms the matrix multiplication between the<br />
source one and source two matrices,and places the result in the<br />
destination matrix. Symbolically:<br />
where:<br />
Đối số: số numRows1 hàng trong nguồn một ma trận<br />
numCols1Rows2 số lượng cột trong nguồn một ma trận; mà<br />
mustbe giống như số hàng trong nguồn<br />
hai ma trận<br />
numCols2 số lượng cột trong hai nguồn ma trận<br />
dstM con trỏ đến ma trận điểm<br />
srcM1 con trỏ đến nguồn một ma trận<br />
srcM2 con trỏ đến nguồn hai ma trận<br />
Quay trở lại giá trị: Con trỏ trỏ tới địa chỉ cơ sở của ma trận đích.<br />
Ghi chú: Nếu giá trị tuyệt đối của<br />
lớn hơn 1-2<br />
-15<br />
, Hoạt động này dẫn đến độ bão hòa cho<br />
(I, j) yếu tố -thứ.<br />
Nếu nguồn một ma trận hình vuông, sau đó chức năng này có thể được tính<br />
tại chỗ và có thể tự áp dụng. Xem Bình luận bổ sung tại các<br />
bắt đầu của phần cho ý kiến về chế độ này hoạt động.<br />
Source File: mmul.asm<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W7 sử dụng, không được khôi phục<br />
W8..W13 lưu, sử dụng, phục hồi<br />
ACCA được sử dụng, không được khôi phục<br />
CORCON lưu, sử dụng, phục hồi<br />
DOand REPEATinstruction sử dụng:<br />
2 DOinstructions cấp<br />
không REPEATinstructions<br />
Từ chương trình (hướng dẫn 24-bit):<br />
35<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
36 + numRows1 * (8 + numCols2 * (7 + 4 * numCols1Rows2))<br />
dstM tôi [] j [] srcM1 tôi [] k [] () srcM2i k [] j [] () k<br />
Σ =<br />
srcM1 tôi [] k [] () srcM2i k [] j [] () k<br />
Σ<br />
DSP Thư viện<br />
2004 Microchip Technology Inc DS51456B trang 35<br />
MatrixScale<br />
Mô tả: MatrixScalescales (bội) các giá trị của tất cả các yếu tố trong<br />
nguồn ma trận bởi một giá trị quy mô, và đặt kết quả ở đích đến
0 ≤i < numRows1<br />
0 ≤j < numCols2<br />
0 ≤k < numCols1Rows2<br />
Include: dsp.h<br />
Prototype: extern fractional* MatrixMultiply (<br />
int numRows1,<br />
int numCols1Rows2,<br />
int numCols2,<br />
fractional* dstM,<br />
fractional* srcM1,<br />
fractional* srcM2<br />
);<br />
Arguments: numRows1 number of rows in source one matrix<br />
numCols1Rows2 number of columns in source one matrix; which<br />
mustbe the same as number of rows in source<br />
two matrix<br />
numCols2 number of columns in source two matrix<br />
dstM pointer to destination matrix<br />
srcM1 pointer to source one matrix<br />
srcM2 pointer to source two matrix<br />
Return Value: Pointer to base address of destination matrix.<br />
Remarks: If the absolute value of<br />
is larger than 1-2<br />
-15<br />
, this operation results in saturation for the<br />
(i,j)-th element.<br />
If the source one matrix is squared,then this function can be computed<br />
in place and can be self applicable. See Additional Remarks at the<br />
beginning of the section for comments on this mode of operation.<br />
Source File: mmul.asm<br />
Function Profile: System resources usage:<br />
W0..W7 used, not restored<br />
W8..W13 saved, used, restored<br />
ACCA used, not restored<br />
CORCON saved, used, restored<br />
DOand REPEATinstruction usage:<br />
2 level DOinstructions<br />
no REPEATinstructions<br />
Program words (24-bit instructions):<br />
ma trận.<br />
Bao gồm: dsp.h<br />
Nguyên mẫu: ở ngoài phân đoạn * MatrixScale (<br />
int numrows,<br />
numCols int,<br />
phân đoạn * dstM,<br />
phân đoạn * srcM,<br />
phân đoạn sclVal<br />
);<br />
Đối số: numrows số hàng trong ma trận nguồn<br />
numCols số lượng cột trong ma trận nguồn<br />
dstM con trỏ đến ma trận điểm<br />
con trỏ srcM để ma trận nguồn<br />
sclVal giá trị mà quy mô các yếu tố ma trận<br />
Quay trở lại giá trị: Con trỏ trỏ tới địa chỉ cơ sở của ma trận đích.<br />
Bình luận: Chức năng này có thể được tính tại chỗ.<br />
Source File: mscl.asm<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W5 sử dụng, không được khôi phục<br />
ACCA được sử dụng, không được khôi phục<br />
CORCON lưu, sử dụng, phục hồi<br />
DOand REPEATinstruction sử dụng:<br />
1 DOinstructions cấp<br />
không REPEATinstructions<br />
Từ chương trình (hướng dẫn 24-bit):<br />
14<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
20 + 3 (numrows * numCols)<br />
MatrixSubtract<br />
Mô tả: MatrixSubtractsubtracts giá trị của mỗi phần tử trong mã nguồn<br />
hai ma trận từ đối tác của mình trong nguồn một ma trận, và đặt<br />
kết quả trong ma trận đích.<br />
Bao gồm: dsp.h<br />
Nguyên mẫu: ở ngoài phân đoạn * MatrixSubtract (<br />
int numrows,<br />
numCols int,<br />
phân đoạn * dstM,<br />
phân đoạn * srcM1,<br />
phân đoạn * srcM2
35<br />
Cycles (including C-function call and return overheads):<br />
36+numRows1*(8+numCols2*(7+4*numCols1Rows2))<br />
dstM i []j [] srcM1 i []k [] ()srcM2i k []j [] () k<br />
∑ =<br />
srcM1 i []k [] ()srcM2i k []j [] () k<br />
∑<br />
DSP Library<br />
2004 Microchip Technology Inc. DS51456B-page 35<br />
MatrixScale<br />
Description: MatrixScalescales (multiplies) the values of all elements in the<br />
source matrix by a scale value, and places the result in the destination<br />
matrix.<br />
Include: dsp.h<br />
Prototype: extern fractional* MatrixScale (<br />
int numRows,<br />
int numCols,<br />
fractional* dstM,<br />
fractional* srcM,<br />
fractional sclVal<br />
);<br />
Arguments: numRows number of rows in source matrix<br />
numCols number of columns in source matrix<br />
dstM pointer to destination matrix<br />
srcM pointer to source matrix<br />
sclVal value by which to scale matrix elements<br />
Return Value: Pointer to base address of destination matrix.<br />
Remarks: This function can be computed in place.<br />
Source File: mscl.asm<br />
Function Profile: System resources usage:<br />
W0..W5 used, not restored<br />
ACCA used, not restored<br />
CORCON saved, used, restored<br />
DOand REPEATinstruction usage:<br />
1 level DOinstructions<br />
no REPEATinstructions<br />
Program words (24-bit instructions):<br />
14<br />
Cycles (including C-function call and return overheads):<br />
);<br />
Đối số: numrows số hàng trong ma trận nguồn (CES)<br />
numCols số lượng cột trong ma trận nguồn (CES)<br />
dstM con trỏ đến ma trận điểm<br />
srcM1 con trỏ đến mã nguồn một ma trận (số để trừ)<br />
srcM2 con trỏ đến nguồn hai ma trận (số bị trừ)<br />
Quay trở lại giá trị: Con trỏ trỏ tới địa chỉ cơ sở của ma trận đích.<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 36 2004 Microchip Technology Inc<br />
Ghi chú: Nếu giá trị tuyệt đối của srcM1 [r] [c] -srcM2 [r] [c] lớn hơn<br />
1-2<br />
-15<br />
, Kết quả hoạt động này trong độ bão hòa cho (r, c) các yếu tố -thứ.<br />
Chức năng này có thể được tính tại chỗ.<br />
Chức năng này có thể áp dụng beself.<br />
Source File: msub.asm<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W4 sử dụng, không được khôi phục<br />
ACCA được sử dụng, không được khôi phục<br />
ACCB sử dụng, không được khôi phục<br />
CORCON lưu, sử dụng, phục hồi<br />
DOand REPEATinstruction sử dụng:<br />
1 DOinstructions cấp<br />
không REPEATinstructions<br />
Từ chương trình (hướng dẫn 24-bit):<br />
15<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
20 + 4 (numrows * numCols)<br />
MatrixTranspose<br />
Mô tả: MatrixTransposetransposes các hàng của các cột trong nguồn<br />
ma trận, và những nơi ma trận kết quả indestination. Trong thực tế:<br />
dstM [i] [j] = srcM [j] [i],<br />
0 ≤i
20 + 3(numRows*numCols)<br />
MatrixSubtract<br />
Description: MatrixSubtractsubtracts the value of each element in the source<br />
two matrix from its counterpart in the source one matrix, and places the<br />
result in the destination matrix.<br />
Include: dsp.h<br />
Prototype: extern fractional* MatrixSubtract (<br />
int numRows,<br />
int numCols,<br />
fractional* dstM,<br />
fractional* srcM1,<br />
fractional* srcM2<br />
);<br />
Arguments: numRows number of rows in source matrix(ces)<br />
numCols number of columns in source matrix(ces)<br />
dstM pointer to destination matrix<br />
srcM1 pointer to source one matrix (minuend)<br />
srcM2 pointer to source two matrix (subtrahend)<br />
Return Value: Pointer to base address of destination matrix.<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
phân đoạn * dstM,<br />
phân đoạn * srcM<br />
);<br />
Đối số: numrows số hàng trong ma trận nguồn<br />
numCols số lượng cột trong ma trận nguồn<br />
dstM con trỏ đến ma trận điểm<br />
con trỏ srcM để ma trận nguồn<br />
Quay trở lại giá trị: Con trỏ trỏ tới địa chỉ cơ sở của ma trận đích.<br />
Ghi chú: Nếu nguồn ma trận là hình vuông, chức năng này có thể được tính tại<br />
chỗ.<br />
Xem Bình luận bổ sung tại đầu phần cho ý kiến<br />
về chế độ này hoạt động.<br />
Source File: mtrp.asm<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W5 sử dụng, không được khôi phục<br />
DOand REPEATinstruction sử dụng:<br />
2 DOinstructions cấp<br />
không REPEATinstructions<br />
Từ chương trình (hướng dẫn 24-bit):<br />
14<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
16 + numCols * (6 + (numrows-1) * 3)<br />
MatrixSubtract (Tiếp theo)<br />
DS51456B-page 36<br />
2004 Microchip Technology Inc.<br />
DSP Thư viện<br />
Remarks: If the absolute value of srcM1[r][c]-srcM2[r][c]is larger than<br />
1-2<br />
-15<br />
, this operation results in saturation for the (r,c)-th element.<br />
This function can be computed in place.<br />
This function can beself applicable.<br />
Source File: msub.asm<br />
Function Profile: System resources usage:<br />
W0..W4 used, not restored<br />
ACCA used, not restored<br />
ACCB used, not restored<br />
CORCON saved, used, restored<br />
DOand REPEATinstruction usage:<br />
1 level DOinstructions<br />
no REPEATinstructions<br />
Program words (24-bit instructions):<br />
2004 Microchip Technology Inc DS51456B trang 37<br />
2.5.5 Ma trận Inversion<br />
Kết quả của việc đảo ngược một không ít, hình vuông, ma trận phân đoạn là mộ<br />
ma trận vuông<br />
(Các kích thước tương tự) mà giá trị phần tử không nhất thiết phải hạn chế đến<br />
bộ phân đoạn rời rạc {-1, ..., 1-2<br />
-15<br />
}. Vì vậy, không có hoạt động ma trận đảo ngược được cung cấp cho<br />
ma trận phân đoạn.<br />
Tuy nhiên, kể từ khi ma trận đảo ngược là một hoạt động veryuseful, một thực<br />
hiện dựa trên<br />
ở điểm nổi đại diện số lượng và số học được cung cấp trong DSP<br />
Thư viện. Mô tả của nó sau.<br />
MatrixInvert<br />
Mô tả: MatrixInvertcomputes nghịch đảo của nguồn ma trận, và những nơi<br />
kết quả trong ma trận đích.<br />
Bao gồm: dsp.h
15<br />
Cycles (including C-function call and return overheads):<br />
20 + 4(numRows*numCols)<br />
MatrixTranspose<br />
Description: MatrixTransposetransposes the rows by the columns in the source<br />
matrix, and places the result indestination matrix. In effect:<br />
dstM[i][j]= srcM[j][i],<br />
0 ≤i < numRows, 0 ≤j < numCols.<br />
Include: dsp.h<br />
Prototype: extern fractional* MatrixTranspose (<br />
int numRows,<br />
int numCols,<br />
fractional* dstM,<br />
fractional* srcM<br />
);<br />
Arguments: numRows number of rows in source matrix<br />
numCols number of columns in source matrix<br />
dstM pointer to destination matrix<br />
srcM pointer to source matrix<br />
Return Value: Pointer to base address of destination matrix.<br />
Remarks: If the source matrix is square, this function can be computed in place.<br />
See Additional Remarks at the beginning of the section for comments<br />
on this mode of operation.<br />
Source File: mtrp.asm<br />
Function Profile: System resources usage:<br />
W0..W5 used, not restored<br />
DOand REPEATinstruction usage:<br />
2 level DOinstructions<br />
no REPEATinstructions<br />
Program words (24-bit instructions):<br />
14<br />
Cycles (including C-function call and return overheads):<br />
16 + numCols*(6 + (numRows-1)*3)<br />
MatrixSubtract (Continued)<br />
DSP Library<br />
2004 Microchip Technology Inc. DS51456B-page 37<br />
2.5.5 Matrix Inversion<br />
The result of inverting a non-singular, square, fractional matrix is another<br />
square matrix<br />
Prototype: phao ở ngoài * MatrixInvert (<br />
numRowsCols int,<br />
* nổi dstM,<br />
float * srcM,<br />
* nổi pivotFlag,<br />
int * swappedRows,<br />
int * swappedCols<br />
);<br />
Đối số: numRowCols số hàng và cột trong (hình vuông) nguồn<br />
ma trận<br />
dstM con trỏ đến ma trận điểm<br />
con trỏ srcM để ma trận nguồn<br />
Cần thiết để sử dụng nội bộ:<br />
pivotFlag con trỏ đến một vector numRowsCols dài<br />
swappedRows con trỏ đến một vector numRowsCols dài<br />
swappedCols con trỏ đến một vector numRowsCols dài<br />
Quay trở lại giá trị: Con trỏ trỏ tới địa chỉ cơ sở của ma trận điểm đến, hoặc<br />
NULLif nguồn ma trận<br />
là số ít.<br />
Bình luận: Mặc dù các vectơ pivotFlag, swappedRows, và<br />
swappedCols, là để dùng nội bộ thì phải giao trước<br />
gọi chức năng này.<br />
Nếu ma trận nguồn là số ít (yếu tố quyết định bằng không) ma trận không<br />
không có tính khả nghịch. Trong trường hợp này hàm trả về NULL.<br />
Chức năng này có thể được tính tại chỗ.<br />
Source File: minv.asm (lắp ráp từ C-code)<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W7 sử dụng, không được khôi phục<br />
W8, W14 lưu, sử dụng, phục hồi<br />
DOand REPEATinstruction sử dụng:<br />
Không<br />
Từ chương trình (hướng dẫn 24-bit):<br />
Xem file "readme.txt" trong pic30_tools \ src \ DSP cho thông tin này.<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
Xem file "readme.txt" trong pic30_tools \ src \ DSP cho thông tin này.<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 38<br />
2.6 CHỨC NĂNG LỌC<br />
2004 Microchip Technology Inc
(of the same dimension) whose element values are not necessarily constrained<br />
to the<br />
discrete fractional set {-1, ..., 1-2<br />
-15<br />
}. Thus, no matrix inversion operation is provided for<br />
fractional matrices.<br />
However, since matrix inversion is a veryuseful operation, an implementation<br />
based<br />
on floating point number representation and arithmetic is provided within the<br />
DSP<br />
Library. Its description follows.<br />
MatrixInvert<br />
Description: MatrixInvertcomputes the inverse of the source matrix, and places<br />
the result in the destination matrix.<br />
Include: dsp.h<br />
Prototype: extern float* MatrixInvert (<br />
int numRowsCols,<br />
float* dstM,<br />
float* srcM,<br />
float* pivotFlag,<br />
int* swappedRows,<br />
int* swappedCols<br />
);<br />
Arguments: numRowCols number of rows and columns in (square) source<br />
matrix<br />
dstM pointer to destination matrix<br />
srcM pointer to source matrix<br />
Required for internal use:<br />
pivotFlag pointer to a length numRowsCols vector<br />
swappedRows pointer to a length numRowsCols vector<br />
swappedCols pointer to a length numRowsCols vector<br />
Return Value: Pointer to base address of destination matrix, or NULLif source<br />
matrix<br />
is singular.<br />
Remarks: Even though the vectors pivotFlag, swappedRows, and<br />
swappedCols, are for internal use only, they must be allocated prior to<br />
calling this function.<br />
If source matrix is singular (determinant equal to zero) the matrix does<br />
not have an inverse. In this case the function returns NULL.<br />
This function can be computed in place.<br />
Source File: minv.asm(assembled from C-code)<br />
Phần này trình bày các khái niệm về một bộ lọc phân đoạn, như xem xét bởi<br />
DSP<br />
Thư viện, và mô tả các chức năng cá nhân đó thực hiện các hoạt động lọc.<br />
2.6.1 Hoạt động lọc Fractional<br />
Lọc các chuỗi dữ liệu được đại diện bởi phân đoạn vector x [n] (0 ≤n
Function Profile: System resources usage:<br />
W0..W7 used, not restored<br />
W8, W14 saved, used, restored<br />
DOand REPEATinstruction usage:<br />
None<br />
Program words (24-bit instructions):<br />
See the file “readme.txt” in pic30_tools\src\dsp for this information.<br />
Cycles (including C-function call and return overheads):<br />
See the file “readme.txt” in pic30_tools\src\dsp for this information.<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
mà một [m] = 0 khi 1 ≤m<br />
rằng một [0] ≠ 0, và [m] ≠ 0 cho một số m {1, ..., M}. Phân loại khác trong FIR<br />
và hạch toán bộ lọc IIR gia đình cho các tác động của các hoạt động gây ra trên<br />
dữ liệu đầu vào<br />
trình tự.<br />
Hơn nữa, mặc dù lọc giải phương trình khác biệt consistson nói<br />
ở trên, một số triển khai có sẵn trong đó hiệu quả hơn tính toán trực tiếp của<br />
phương trình khác biệt. Ngoài ra, một số hiện thực khác được thiết kế để<br />
thực hiện các hoạt động lọc theo buộc áp đặt bởi số học phân đoạn.<br />
Tất cả những nhận xét này dẫn đến một sự gia tăng của hoạt động lọc, trong đó<br />
có một tập hợp con<br />
được cung cấp bởi thư viện DSP.<br />
yn [] ap [] - () yn p - [] () p1 =<br />
P1-<br />
DS51456B-page 38<br />
2004 Microchip Technology Inc.<br />
Σ + bm [] () xn m - [] ()<br />
2.6 FILTERING FUNCTIONS<br />
This section presents the concept of a fractional filter, as considered by the DSP<br />
Library, and describes the individual functions which perform filter operations.<br />
2.6.1 Fractional Filter Operations<br />
Filtering the data sequence represented by fractional vector x[n] (0 ≤n
history of the filter. After performing the filtering operation, the delay contains<br />
a set of<br />
the most recently filtered data samples, and of the most recent output samples.<br />
(Note<br />
that to ensure correct operation of a particular filter implementation, it is<br />
advisable to<br />
initialize the delay values to zero by calling the corresponding initialization<br />
function.)<br />
In the filter implementations provided with the DSP Library the input data<br />
sequence is<br />
referred to as the sequence of source samples, while the resulting filtered<br />
sequence is<br />
called the destination samples. The filter coefficients (a,b) and delay are usually<br />
thought of as making up a filter structure. In all filter implementations, the input<br />
and<br />
và bộ hệ số có thể tạo ra kết quả bất ngờ.<br />
d) Đó là khuyến cáo rằng tình trạng đăng ký (SR) được kiểm tra sau khi hoàn<br />
thành<br />
mỗi lần gọi hàm. Đặc biệt, người dùng có thể kiểm tra việc SA, SB và SAB cờ<br />
sau<br />
hàm trả về để xác định độ bão hòa xảy ra.<br />
e) Các hoạt động đó trả về một vector đích có thể được lồng vào nhau, do đó, v<br />
dụ<br />
nếu:<br />
a = OP1 (b, c), với b = OP2 (d) và c = op3 (e, f), sau đó<br />
a = OP1 (OP2 (d), op3 (e, f))<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
output data samples may be allocated in default RAM memory space (X-Data or<br />
DS51456B trang 40<br />
2004 Microchip Technology Inc<br />
Y-Data). Filter coefficients may reside either in X-Data memory or program<br />
memory,<br />
and filter delay values must be accessed onlyfrom Y-Data.<br />
2.6.2 FIR and IIR Filter Implementations<br />
The properties of a filter depend on the value distribution of its coefficients. In<br />
particular,<br />
two types of filters are of special interest: Finite Impulse Response (FIR) filters,<br />
for<br />
which a[m] = 0 when 1 ≤m
DSP Library<br />
2004 Microchip Technology Inc. DS51456B-page 39<br />
2.6.3 Single Sample Filtering<br />
The filtering functions provided in the DSP Library are designed for block<br />
processing.<br />
Each filter function accepts an argument named numSampswhich indicates the<br />
number of words of input data (block size) to operate on. If single sample<br />
filtering is desired,<br />
you may set numSampsto 1. This will have the effect of filtering one input<br />
sample, and<br />
the function will compute a singleoutput sample from the filter.<br />
2.6.4 User Considerations<br />
All the fractional filtering operations in this library rely on the values of either<br />
input<br />
parameters or data structure elements to specify the number of samples to<br />
process,<br />
and the sizes of the coefficients and delay vectors. Based on these values the<br />
following<br />
assumptions are made:<br />
a) The sum of sizes of all the vectors (sample sequences) involved in a<br />
particular<br />
operation falls within the range of available data memory for the target device.<br />
b) The destination vector mustbe large enough to accept the results of an<br />
operation.<br />
c) No boundary checking is performed by these functions. Out of range sizes<br />
(including zero length vectors) as well as nonconforming use of source vectors<br />
and coefficient sets may produce unexpected results.<br />
d) It is recommended that the Status register (SR) is examined after completion<br />
of<br />
each function call. In particular, users can inspect the SA, SB and SAB flags<br />
after<br />
the function returns to determine if saturation occurred.<br />
e) Operations which return a destination vector can be nested, so that for<br />
instance<br />
if:<br />
a = Op1 (b, c), with b = Op2 (d), and c = Op3 (e, f), then<br />
a = Op1 (Op2 (d), Op3 (e, f))<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 40<br />
2.6.5 Individual Functions<br />
2004 Microchip Technology Inc.<br />
In what follows, the individual functions implementing filtering operations are<br />
described. For further discussions on digital filters, please consult Alan<br />
delayBase địa chỉ cơ sở cho sự chậm trễ đệm<br />
địa chỉ kết thúc delayEnd cho sự chậm trễ đệm<br />
trì hoãn giá trị hiện tại của con trỏ chậm trễ (cũng d)<br />
Bình luận: Số lượng các hệ số trong bộ lọc là M.<br />
Hệ số, h [m], được định nghĩa trong 0 ≤m<br />
bộ nhớ.<br />
Chậm trễ đệm d [m], được định nghĩa trong 0 ≤m<br />
Nếu hệ số được lưu trữ trong không gian X-Data, coeffsBasepoints đến<br />
địa chỉ thực tế mà hệ số được phân bổ. Nếu hệ số là<br />
lưu trữ trong bộ nhớ chương trình, coeffsBaseis bù đắp từ chương trình<br />
trang ranh giới có chứa các hệ số địa chỉ trong trang<br />
nơi mà hệ số được phân bổ. Giá trị sau này có thể được tính toán<br />
bằng cách sử dụng psvoffset hành lắp ráp nội tuyến ().<br />
coeffsEndis địa chỉ trong không gian X-Data (hoặc bù đắp nếu trong chương<br />
trình<br />
bộ nhớ) của byte cuối cùng của bộ đệm hệ số bộ lọc.<br />
Nếu hệ số được lưu trữ trong không gian X-Data, coeffsPagemust được thiết lập<br />
để<br />
0xff00 (được định nghĩa COEFFS_IN_DATA giá trị). Nếu hệ số được lưu trữ<br />
trong<br />
bộ nhớ chương trình, nó là số trang chương trình có chứa các hệ số. Giá trị sau<br />
này có thể được tính toán bằng cách sử dụng lắp ráp nội tuyến<br />
điều hành psvpage ().<br />
delayBasepoints đến địa chỉ thực tế nơi mà các bộ đệm chậm trễ được phân bổ.<br />
delayEndis địa chỉ của người cuối cùng byteof bộ đệm chậm trễ lọc.<br />
DSP Thư viện<br />
2004 Microchip Technology Inc DS51456B trang 41<br />
Khi các hệ số và bộ đệm chậm trễ được thực hiện như tròn<br />
tăng bộ đệm modulo, cả coeffsBaseand<br />
delayBase mustbe liên kết đến một quyền lực 'không' của hai địa chỉ<br />
(coeffsEndand delayEndare địa chỉ lẻ). Cho dù các bộ đệm<br />
thực hiện như bộ đệm tròn tăng modulo hoặc không được chỉ định trong<br />
phần nhận xét của mỗi bộ lọc FIR mô tả chức năng.<br />
Khi các hệ số và bộ đệm chậm trễ không được thực hiện như tròn (tăng) theo<br />
modulo bộ đệm, coeffsBaseand<br />
delayBase không cần tobe liên kết quyền lực một 'không' của hai địa chỉ,<br />
và các giá trị của coeffsEndand delayEndare bỏ qua trong<br />
đặc biệt FIR Bộ lọc chức năng thực hiện.<br />
FIR<br />
Mô tả: FIRapplies một bộ lọc FIR với chuỗi các mẫu nguồn, đặt<br />
kết quả trong các mẫu đến sequenceof, và cập nhật sự chậm trễ<br />
giá trị.
Oppenheim and<br />
Ronald Schafer’s Discrete-Time Signal Processing, Prentice Hall, 1989. For<br />
implementation details of Least Mean Square FIR filters, please refer to T.<br />
Hsia’s Convergence<br />
Analysis of LMS and NLMS Adaptive Algorithms, Proc. ICASSP, pp. 667-670,<br />
1983, as<br />
well as Sangil Park and Garth Hillman’s On Acoustic-Echo Cancellation<br />
Implementation with Multiple Cascadable Adaptive FIR Filter Chips, Proc.<br />
ICASSP,<br />
1989.<br />
FIRStruct<br />
Structure: FIRStructdescribes the filter structure for any of the FIR filters.<br />
Include: dsp.h<br />
Declaration: typedef struct {<br />
int numCoeffs;<br />
fractional* coeffsBase;<br />
fractional* coeffsEnd;<br />
int coeffsPage;<br />
fractional* delayBase;<br />
fractional* delayEnd;<br />
fractional* delay;<br />
} FIRStruct;<br />
Parameters: numCoeffs number of coefficients in filter (also M)<br />
coeffsBase base address for filtercoefficients (also h)<br />
coeffsEnd end address for filter coefficients<br />
coeffsPage coefficients buffer page number<br />
delayBase base address for delay buffer<br />
delayEnd end address for delay buffer<br />
delay current value of delay pointer (also d)<br />
Remarks: Number of coefficients in filter is M.<br />
Coefficients, h[m], defined in 0 ≤m
If coefficients are stored in X-Data space, coeffsPagemust be set to<br />
0xFF00 (defined value COEFFS_IN_DATA). If coefficients are stored in<br />
program memory, it is the program page number containing the coefficients.<br />
This latter value can be calculated using the inline assembly<br />
operator psvpage().<br />
delayBasepoints to the actual address where the delay buffer is allocated.<br />
delayEndis the address of the last byteof the filter delay buffer.<br />
DSP Library<br />
2004 Microchip Technology Inc. DS51456B-page 41<br />
When the coefficients and delay buffers are implemented as circular<br />
increasing modulo buffers, both coeffsBaseand<br />
delayBase mustbe aligned to a ‘zero’ power of two address (coeffsEndand<br />
delayEndare odd addresses). Whether these buffers are<br />
implemented as circular increasing modulo buffers or not is indicated in<br />
the remarks section of each FIR filter function description.<br />
When the coefficients and delay buffers are not implemented as circular<br />
(increasing) modulo buffers, coeffsBaseand<br />
delayBase do not need tobe aligned to a ‘zero’ power of two address,<br />
and the values of coeffsEndand delayEndare ignored within the<br />
particular FIR Filter function implementation.<br />
FIR<br />
Description: FIRapplies an FIR filter to the sequence of source samples, places<br />
the<br />
results in the sequenceof destination samples, and updates the delay<br />
values.<br />
Include: dsp.h<br />
Prototype: extern fractional* FIR (<br />
int numSamps,<br />
fractional* dstSamps,<br />
fractional* srcSamps,<br />
FIRStruct* filter<br />
);<br />
Arguments: numSamps number of input samples to filter (also N)<br />
dstSamps pointer to destination samples (also y)<br />
srcSamps pointer to source samples (also x)<br />
filter pointer to FIRStructfilter structure<br />
Return Value: Pointer to base address of destination samples.<br />
Remarks: Number of coefficients in filter is M.<br />
Coefficients, h[m], defined in 0 ≤m
modulo buffer.<br />
Source samples, x[n], defined in 0 ≤n
int numSamps,<br />
fractional* dstSamps,<br />
fractional* srcSamps,<br />
FIRStruct* filter,<br />
int rate<br />
);<br />
Arguments: numSamps number of outputsamples (also N, N = Rp, p integer)<br />
dstSamp pointer to destination samples (also y)<br />
srcSamps pointer to source samples (also x)<br />
filter pointer to FIRStructfilter structure<br />
rate rate of decimation (downsampling factor, also R)<br />
Return Value: Pointer to base address of destination samples.<br />
Remarks: Number of coefficients in filter is M,with M an integer multiple of R.<br />
Coefficients, h[m], defined in 0 ≤m
FIRDelayInit<br />
Description: FIRDelayInitinitializes to zero the delay values in an FIRStruct<br />
filter structure.<br />
Include: dsp.h<br />
Prototype: extern void FIRDelayInit (<br />
FIRStruct* filter<br />
);<br />
Arguments: filter pointer to FIRStructfilter structure.<br />
Remarks: See description of FIRStructstructure above.<br />
Note:FIR interpolator's delay is initialized by function<br />
FIRInterpDelayInit.<br />
Source File: firdelay.asm<br />
Function Profile: System resources usage:<br />
W0..W2 used, not restored<br />
DOand REPEATinstruction usage:<br />
no DOinstructions<br />
1 level REPEATinstructions<br />
Program words (24-bit instructions):<br />
7<br />
Cycles (including C-function call and return overheads):<br />
11 + M<br />
FIRDecimate (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 44 2004 Microchip Technology Inc.<br />
FIRInterpolate<br />
Description: FIRInterpolateinterpolates the sequence of source samples at a<br />
rate of 1 to R; or equivalently, it upsamples the signal by a factor of R.<br />
Effectively,<br />
y[n] = x[n/R].<br />
To diminish the effect of aliasing, the source samples are first<br />
upsampled and then filtered. The interpolated results are stored in the<br />
sequence of destination samples,and the delay values updated.<br />
Include: dsp.h<br />
Prototype: extern fractional* FIRInterpolate (<br />
int numSamps,<br />
fractional* dstSamps,<br />
fractional* srcSamps,<br />
CORCON lưu, sử dụng, phục hồi<br />
PSVPAG lưu, sử dụng, phục hồi (nếu<br />
hệ số P trong bộ nhớ)<br />
DOand REPEATinstruction sử dụng:<br />
2 DOinstructions cấp<br />
1 REPEATinstructions cấp<br />
Từ chương trình (hướng dẫn 24-bit):<br />
63<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
45 + 6 (M / R) + N (14 + M / R + 3M + 5R), hoặc<br />
48 + 6 (M / R) + N (14 + M / R + 4M + 5R) nếu hệ số P trong bộ nhớ.<br />
DSP Thư viện<br />
2004 Microchip Technology Inc DS51456B trang 45<br />
FIRInterpDelayInit<br />
Mô tả: FIRInterpDelayInitinitializes bằng không các giá trị chậm trễ trong một<br />
Cấu trúc FIRStructfilter, tối ưu hóa để sử dụng với một nội suy FIR<br />
bộ lọc.<br />
Bao gồm: dsp.h<br />
Prototype: ngoài void FIRDelayInit (<br />
FIRStruct * bộ lọc,<br />
int tỷ lệ<br />
);<br />
Đối số: lọc con trỏ đến cấu trúc FIRStructfilter<br />
tỷ lệ tỷ lệ nội suy (upsampling yếu tố, cũng R)<br />
Bình luận: Delay, d [m], được định nghĩa trong 0 ≤m<br />
hệ số trong xen vào.<br />
Xem mô tả các FIRStructstructure trên.<br />
Source File: firintdl.asm<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W4 sử dụng, không được khôi phục<br />
DOand REPEATinstruction sử dụng:<br />
không DOinstructions<br />
1 REPEATinstructions cấp<br />
Từ chương trình (hướng dẫn 24-bit):<br />
13<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
10 + 7M / R<br />
FIRLattice<br />
Mô tả: FIRLatticeuses thực hiện một cấu trúc mạng tinh thể áp dụng một FIR
FIRStruct* filter,<br />
int rate<br />
);<br />
Arguments: numSamps number of input samples (also N, N = Rp, p integer)<br />
dstSamps pointer to destination samples (also y)<br />
srcSamps pointer to source samples (also x)<br />
filter pointer to FIRStructfilter structure<br />
rate rate of interpolation (upsampling factor, also R)<br />
Return Value: Pointer to base address of destination samples.<br />
Remarks: Number of coefficients in filter is M,with M an integer multiple of R.<br />
Coefficients, h[m], defined in 0 ≤m
filter.<br />
Include: dsp.h<br />
Prototype: extern void FIRDelayInit (<br />
FIRStruct* filter,<br />
int rate<br />
);<br />
Arguments: filter pointer to FIRStructfilter structure<br />
rate rate of interpolation (upsampling factor, also R)<br />
Remarks: Delay, d[m], defined in 0 ≤m
circular modulo buffer.<br />
Delay, d[m], defined in 0 ≤m
FIRStruct* filter,<br />
fractional* refSamps,<br />
fractional muVal<br />
);<br />
Arguments: numSamps number of input samples (also N)<br />
dstSamps pointer to destination samples (also y)<br />
srcSamps pointer to source samples (also x)<br />
filter pointer to FIRStructfilter structure<br />
refSamps pointer to reference samples (also r)<br />
muVal adapting factor (also mu)<br />
Return Value: Pointer to base address of destination samples.<br />
FIRLattice (Continued)<br />
DSP Library<br />
2004 Microchip Technology Inc. DS51456B-page 47<br />
Remarks: Number of coefficients in filter is M.<br />
Coefficients, h[m], defined in 0 ≤m
XMODSTRT saved, used, restored<br />
XMODEND saved, used, restored<br />
YMODSTRT saved, used, restored<br />
DOand REPEATinstruction usage:<br />
2 level DOinstructions<br />
1 level REPEATinstructions<br />
Program words (24-bit instructions):<br />
76<br />
Cycles (including C-function call and return overheads):<br />
61 + N(13 + 5M)<br />
FIRLMSNorm<br />
Description: FIRLMSNormapplies an adaptive FIR filter to the sequence of<br />
source<br />
samples, stores the results in the sequence of destination samples,<br />
and updates the delay values.<br />
The filter coefficients are also updated, at a sample-per-sample basis,<br />
using a Normalized Least Mean Square algorithm applied according to<br />
the values of the reference samples.<br />
Include: dsp.h<br />
FIRLMS (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
energyEstimateis cập nhật với giá trị E [N-1] (có thể được sử dụng<br />
là giá trị khởi động cho một cuộc gọi chức năng tiếp theo nếu lọc một<br />
mở rộng của tín hiệu đầu vào).<br />
Các hoạt động có thể dẫn đến bão hòa nếu giá trị tuyệt đối của (r [n] -<br />
y [n]) lớn hơn hoặc bằng một.<br />
Lưu ý: Một biểu hiện cho ước tính năng lượng là:<br />
E [n] = (x [n])<br />
2<br />
+ (X [n-1)<br />
2<br />
+ ... + (X [n-M + 2])<br />
2<br />
.<br />
Vì vậy, để tránh bão hòa trong khi tính toán dự toán, đầu vào<br />
giá trị mẫu nên bị trói buộc để<br />
, 0 ≤n
energyEstimate estimated energy value for the last M input<br />
signal samples, with M the number of filter<br />
coefficients<br />
Return Value: Pointer to base address of destination samples.<br />
Remarks: Number of coefficients in filter is M.<br />
Coefficients, h[m], defined in 0 ≤m
, for 0 ≤n
fractional* delayBase<br />
);<br />
Arguments: filter pointer to FIRStructfilter structure<br />
numCoeffs number of coefficients in filter (also M)<br />
coeffsBase base address for filter coefficients (also h)<br />
coeffsPage coefficient buffer page number<br />
delayBase base address for delay buffer<br />
Remarks: See description of FIRStructstructure above.<br />
Upon completion, FIRStructInitinitializes the coeffsEndand<br />
delayEndpointers accordingly. Also, delayis set equal to<br />
delayBase.<br />
Source File: firinit.asm<br />
Function Profile: System resources usage:<br />
W0..W5 used, not restored<br />
DOand REPEATinstruction usage:<br />
no DOinstructions<br />
no REPEATinstructions<br />
Program words (24-bit instructions):<br />
10<br />
Cycles (including C-function call and return overheads):<br />
19<br />
FIRLMSNorm (Continued)<br />
dsPIC<br />
®<br />
anguage Tools Libraries<br />
Bình luận: Có 5 hệ số mỗi secondorder (trùng phương) phần<br />
sắp xếp trong tập lệnh {a2 [s], a1 [s], b2 [s], b1 [s], b0 [s]}, 0 ≤s<br />
Giá trị hệ số nên được tạo ra với thiết kế bộ lọc dsPICFD<br />
gói từ Momentum Data Systems, Inc, hoặc công cụ tương tự.<br />
Việc chậm trễ được tạo thành oftwo lời của nhà nước lọc mỗi section {d1 [s],<br />
d2 [s]}, 0 ≤s
} IIRCanonicStruct;<br />
extern fractional* IIRCanonic (<br />
int numSamps,<br />
fractional* dstSamps,<br />
fractional* srcSamps,<br />
IIRCanonicStruct* filter<br />
);<br />
Arguments: Filter structure:<br />
numSectionsLess1 1 less than number of cascaded second<br />
order (biquadratic) sections (also S-1)<br />
coeffsBase pointer to filter coefficients (also {a, b}),<br />
either within X-Data or program memory<br />
coeffsPage coefficients buffer page number, or 0xFF00<br />
(defined value COEFFS_IN_DATA)if<br />
coefficients in data space<br />
delayBase pointer to filter delay (also d), onlyin Y-Data<br />
initialGain initial gain value<br />
finalShift output scaling (shift left)<br />
Filter Description:<br />
numSamps number of input samples to filter (also N)<br />
dstSamps pointer to destination samples (also y)<br />
srcSamps pointer to source samples (also x)<br />
filter pointer to IIRCanonicStructfilter structure<br />
Return Value: Pointer to base address of destination samples.<br />
Remarks: There are 5 coefficients per secondorder (biquadratic) sections<br />
arranged in the ordered set {a2[s], a1[s], b2[s], b1[s], b0[s]}, 0 ≤s
Source File: iircan.asm<br />
DSP Library<br />
2004 Microchip Technology Inc. DS51456B-page 51<br />
Function Profile: System resources usage:<br />
W0..W7 used, not restored<br />
W8..W11 saved, used, restored<br />
ACCA used, not restored<br />
CORCON saved, used, restored<br />
PSVPAG saved, used, restored<br />
DOand REPEATinstruction usage:<br />
2 level DOinstructions<br />
1 level REPEATinstructions<br />
Program words (24-bit instructions):<br />
42<br />
Cycles (including C-function call and return overheads):<br />
36 + N(8 + 7S), or<br />
39 + N(9 + 12S) if coefficients in program memory.<br />
IIRCanonicInit<br />
Description: IIRCanonicInitinitializes to zero the delay values in an<br />
IIRCanonicStructfilter structure.<br />
Include: dsp.h<br />
Prototype: extern void IIRCanonicInit (<br />
IIRCanonicStruct* filter<br />
);<br />
Arguments: Filter structure:<br />
(See description of IIRCanonicfunction).<br />
Initialization Description:<br />
filter pointer to IIRCanonicStructfilter structure<br />
Remarks: Two words of filter state per second order section {d1[s], d2[s]},<br />
0 ≤s
10 + S2.<br />
IIRCanonic (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 52 2004 Microchip Technology Inc.<br />
IIRLattice<br />
Description: IIRLatticeuses a lattice structure implementation to apply an IIR<br />
filter to the sequence ofsource samples. It thenplaces the results in<br />
the sequence of destination samples, and updates the delay values.<br />
Include: dsp.h<br />
Prototype: typedef struct {<br />
int order;<br />
fractional* kappaVals;<br />
fractional* gammaVals;<br />
int coeffsPage;<br />
fractional* delay;<br />
} IIRLatticeStruct;<br />
extern fractional* IIRLattice (<br />
int numSamps,<br />
fractional* dstSamps,<br />
fractional* srcSamps,<br />
IIRLatticeStruct* filter<br />
);<br />
Arguments: Filter structure:<br />
order filter order (also M, M ≤N; see FIRLatticefor N)<br />
kappaVals base address for lattice coefficients (also k), either in<br />
X-Data or program memory<br />
gammaVals base address for ladder coefficients (also g), either in<br />
X-Data or program memory. If NULL, the function will<br />
implement an all-pole filter.<br />
coeffsPage coefficients buffer page number, or 0xFF00<br />
(defined value COEFFS_IN_DATA)if<br />
coefficients in data space<br />
delay base address for delay (also d), onlyin Y-Data<br />
Filter Description:<br />
numSamps number of input samples to filter (also N, N ≥M; see<br />
IIRLatticeStructfor M)<br />
dstSamps pointer to destination samples (also y)<br />
W0..W7 sử dụng, không được khôi phục<br />
W8..W13 lưu, sử dụng, phục hồi<br />
ACCA được sử dụng, không được khôi phục<br />
ACCB sử dụng, không được khôi phục<br />
CORCON lưu, sử dụng, phục hồi<br />
DOand REPEATinstruction sử dụng:<br />
2 DOinstructions cấp<br />
không REPEATinstructions<br />
Từ chương trình (hướng dẫn 24-bit):<br />
76<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
46 + N (16 + 7M), hoặc<br />
49 + N (20 + 8M) nếu hệ số trong bộ nhớ chương trình.<br />
Nếu thực hiện một bộ lọc tất cả cực:<br />
46 + N (16 + 6M), hoặc<br />
49 + N (16 + 7M) nếu hệ số trong bộ nhớ chương trình<br />
IIRLatticeInit<br />
Mô tả: IIRLatticeInitinitializes bằng không các giá trị chậm trễ trong một<br />
Cấu trúc IIRLatticeStructfilter.<br />
Bao gồm: dsp.h<br />
Prototype: ngoài void IIRLatticeInit (<br />
IIRLatticeStruct * bộ lọc<br />
);<br />
Lập luận: Cấu trúc bộ lọc:<br />
(Xem mô tả các IIRLatticefunction).<br />
Khởi tạo Mô tả:<br />
lọc con trỏ đến cấu trúc IIRLatticeStructfilter.<br />
Source File: iirlattd.asm<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W2 sử dụng, không được khôi phục<br />
DOand REPEATinstruction sử dụng:<br />
không DOinstructions<br />
1 REPEATinstructions cấp<br />
Từ chương trình (hướng dẫn 24-bit):<br />
6<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
10 + M<br />
IIRLattice (Tiếp theo)<br />
dsPIC
srcSamps pointer to source samples (also x)<br />
filter pointer to IIRLatticeStructfilter structure<br />
Return Value: Pointer to base address of destination samples.<br />
Remarks: Lattice coefficients, k[m], defined in 0 ≤m ≤M.<br />
Ladder coefficients, g[m], defined in 0 ≤m ≤M (unless if implementing<br />
an all-pole filter).<br />
Delay, d[m], defined in 0 ≤m ≤M.<br />
Source samples, x[n], defined in 0 ≤n
IIRLatticeInit<br />
Description: IIRLatticeInitinitializes to zero the delay values in an<br />
IIRLatticeStructfilter structure.<br />
Include: dsp.h<br />
Prototype: extern void IIRLatticeInit (<br />
IIRLatticeStruct* filter<br />
);<br />
Arguments: Filter structure:<br />
(See description of IIRLatticefunction).<br />
Initialization Description:<br />
filter pointer to IIRLatticeStructfilter structure.<br />
Source File: iirlattd.asm<br />
Function Profile: System resources usage:<br />
W0..W2 used, not restored<br />
DOand REPEATinstruction usage:<br />
no DOinstructions<br />
1 level REPEATinstructions<br />
Program words (24-bit instructions):<br />
6<br />
Cycles (including C-function call and return overheads):<br />
10 + M<br />
IIRLattice (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
numSamps số lượng mẫu đầu vào để lọc (còn N)<br />
dstSamps con trỏ đến mẫu đích (còn y)<br />
srcSamps con trỏ đến mã nguồn mẫu (còn x)<br />
lọc con trỏ đến cấu trúc IIRTransposedStructfilter<br />
Quay trở lại giá trị: Con trỏ trỏ tới địa chỉ cơ sở của mẫu đích.<br />
Bình luận: Có 5 hệ số mỗi đơn hàng thứ hai (trùng phương) phần<br />
sắp xếp trong tập lệnh {b0 [s], b1 [s], a1 [s], b2 [s], a2 [s]}, 0 ≤s<br />
Giá trị hệ số nên được tạo ra với thiết kế bộ lọc dsPICFD<br />
gói từ Momentum Data Systems, Inc, hoặc công cụ tương tự.<br />
Việc chậm trễ được tạo thành từ hai bộ đệm độc lập, mỗi bộ đệm<br />
có chứa một từ của nhà nước lọc mỗi section {d2 [s], d1 [s]}, 0 ≤s
} IIRTransposedStruct;<br />
extern fractional* IIRTransposed (<br />
int numSamps,<br />
fractional* dstSamps,<br />
fractional* srcSamps,<br />
IIRTransposedStruct* filter<br />
);<br />
Arguments: Filter structure:<br />
numSectionsLess1 1 less than number of cascaded second<br />
order (biquadratic) sections (also S-1)<br />
coeffsBase pointer to filter coefficients (also {a, b}),<br />
either in X-Data or program memory<br />
coeffsPage coefficient buffer page number, or 0xFF00<br />
(defined value COEFFS_IN_DATA)if<br />
coefficients in data space<br />
delayBase1 pointer to filter state 1, with one word of<br />
delay per second order section (also d1),<br />
onlyin Y-Data<br />
delayBase2 pointer to filter state 2, with one word of<br />
delay per second order section (also d2),<br />
onlyin Y-Data<br />
finalShift output scaling (shift left)<br />
Filter Description:<br />
numSamps number of input samples to filter (also N)<br />
dstSamps pointer to destination samples (also y)<br />
srcSamps pointer to source samples (also x)<br />
filter pointer to IIRTransposedStructfilter structure<br />
Mô tả: IIRTransposedInitinitializes bằng không các giá trị chậm trễ trong một<br />
Cấu trúc IIRTransposedStructfilter.<br />
Bao gồm: dsp.h<br />
Prototype: ngoài void IIRTransposedInit (<br />
IIRTransposedStruct * bộ lọc<br />
);<br />
Lập luận: Cấu trúc bộ lọc:<br />
(Xem mô tả các IIRTransposedfunction).<br />
Khởi tạo Mô tả:<br />
lọc con trỏ đến cấu trúc IIRTransposedStructfilter.<br />
Bình luận: Sự chậm trễ được tạo thành từ hai bộ đệm độc lập, mỗi bộ đệm<br />
có chứa một từ của nhà nước lọc mỗi section {d2 [s], d1 [s]}, 0 ≤s
the number of bits to shift: negativeindicates shift left, positive is shift<br />
right.<br />
Source File: iirtrans.asm<br />
DSP Library<br />
2004 Microchip Technology Inc. DS51456B-page 55<br />
Function Profile: System resources usage:<br />
W0..W7 used, not restored<br />
W8..W11 saved, used, restored<br />
ACCA used, not restored<br />
ACCB used, not restored<br />
CORCON saved, used, restored<br />
PSVPAG saved, used, restored<br />
DOand REPEATinstruction usage:<br />
2 level DOinstructions<br />
1 level REPEATinstructions<br />
Program words (24-bit instructions):<br />
48<br />
Cycles (including C-function call and return overheads):<br />
35 + N(11 + 11S), or<br />
38 + N( 9 + 17S) if coefficients in P memory.<br />
S is number of second order sections.<br />
IIRTransposedInit<br />
Description: IIRTransposedInitinitializes to zero the delay values in an<br />
IIRTransposedStructfilter structure.<br />
Include: dsp.h<br />
Prototype: extern void IIRTransposedInit (<br />
IIRTransposedStruct* filter<br />
);<br />
Arguments: Filter structure:<br />
(See description of IIRTransposedfunction).<br />
Initialization Description:<br />
filter pointer to IIRTransposedStructfilter structure.<br />
Remarks: The delay is made up of two independent buffers, each buffer<br />
containing one word of filter state per section {d2[s], d1[s]}, 0 ≤s
no REPEATinstructions<br />
Program words (24-bit instructions):<br />
8<br />
Cycles (including C-function call and return overheads):<br />
11 + 2S,<br />
S is number of second order sections.<br />
IIRTransposed (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 56<br />
2004 Microchip Technology Inc.<br />
2.6.6 OCTAVE model for analysis of IIRLatticefilter<br />
The following OCTAVE model may be used to examine the performance of an<br />
IIR<br />
Lattice Filter prior to using the fractionalimplementation provided by the<br />
function<br />
IIRLattice.<br />
function [out, del, forward, backward] = iirlatt (in, kappas, gammas, delay)<br />
## FUNCTION.-## IIRLATT: IIR Fileter Lattice implementation.<br />
##<br />
## [out, del, forward, backward] = iirlatt (in,kappas, gammas, delay)<br />
##<br />
## forward: records intermediate forward values.<br />
## backward: records intermediate backward values.<br />
#..............................................................................<br />
## Get implicit parameters.<br />
numSamps = length(in); numKapps = length(kappas);<br />
if (gammas != 0)<br />
numGamms = length(gammas);<br />
else<br />
numGamms = 0;<br />
endif<br />
numDels = length(delay); filtOrder = numDels-1;<br />
## Error check.<br />
if (numGamms != 0)<br />
if (numGamms != numKapps)<br />
fprintf ("ERROR! %d should be equal to%d.\n", numGamms, numKapps);<br />
return;<br />
endif<br />
endif<br />
hiện tại = sau;<br />
cuối<br />
del (M + 1) = sau;<br />
## Cấu trúc thang (tính đầu ra).<br />
if (gam mầu == 0)<br />
ra (n) = del (M + 1);<br />
khác<br />
cho m = 1: M + 1<br />
ra (n) = ra (n) + gam mầu (M + 2-m) * del (m);<br />
endfor<br />
endif<br />
endfor<br />
## Quay trở lại.<br />
trở lại;<br />
# ................................................. .............................<br />
endfunction<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 58<br />
2.7 BIẾN ĐỔI CHỨC NĂNG<br />
2004 Microchip Technology Inc<br />
Phần này trình bày các khái niệm về một phân đoạn chuyển đổi, như xem xét<br />
bởi DSP<br />
Thư viện, và mô tả các chức năng cá nhân đó thực hiện chuyển đổi hoạt động.<br />
2.7.1 Fractional Chuyển đổi hoạt động<br />
Một phân đoạn chuyển đổi là một tuyến tính, thời gian bất biến, hoạt động rời<br />
rạc mà khi áp dụng cho<br />
một chuỗi mẫu miền thời gian phân đoạn, kết quả trong một tần số phân đoạn<br />
trong miền tần số. Ngược lại, ngược lại phân đoạn chuyển đổi hoạt động, khi áp<br />
dụng cho<br />
dữ liệu miền tần số, kết quả là đại diện miền thời gian của mình.<br />
Một tập hợp các biến đổi (và một tập hợp các biến đổi nghịch đảo) được cung<br />
cấp bởi DSP<br />
Thư viện. Tập đầu tiên áp dụng một biến đổi Fourier rời rạc (hoặc nghịch đảo<br />
của nó) vào một phức tạp<br />
tập hợp dữ liệu (xem dưới đây để mô tả các giá trị phân số phức tạp). Tập thứ<br />
hai<br />
áp dụng một loại II Discrete Cosine Transform (DCT) cho một chuỗi giá trị<br />
thực. Những<br />
biến đổi đã được thiết kế toeither hoạt động out-of-địa điểm, hoặc tại chỗ. Các<br />
cựu<br />
loại populates một chuỗi đầu ra với kết quả của việc chuyển đổi. Năm thứ hai,<br />
trình tự đầu vào (vật lý) được thay thế bằng các trình tự chuyển đổi. Đối với<br />
ngoài ra hoạt động, đủ bộ nhớ để chấp nhận các kết quả của việc tính toán phải
if (numDels != numKapps)<br />
fprintf ("ERROR! %d should equal to %d.\n", numDels, numKapps);<br />
return;<br />
endif<br />
## Initialize.<br />
M = filtOrder; out = zeros(numSamps,1); del = delay;<br />
forward = zeros(numSamps*M,1); backward = forward; i = 0;<br />
## Filter samples.<br />
for n = 1:numSamps<br />
## Get new sample.<br />
current = in(n);<br />
IIRLattice OCTAVE model<br />
DSP Library<br />
2004 Microchip Technology Inc. DS51456B-page 57<br />
## Lattice structure.<br />
for m = 1:M<br />
after = current - kappas(M+1-m) * del(m+1);<br />
del(m) = del(m+1) + kappas(M+1-m) * after;<br />
i = i+1;<br />
forward(i) = current;<br />
backward(i) = after;<br />
current = after;<br />
end<br />
del(M+1) = after;<br />
## Ladder structure (computes output).<br />
if (gammas == 0)<br />
out(n) = del(M+1);<br />
else<br />
for m = 1:M+1<br />
out(n) = out(n) + gammas(M+2-m)*del(m);<br />
endfor<br />
endif<br />
endfor<br />
## Return.<br />
return;<br />
#..............................................................................<br />
endfunction<br />
dsPIC<br />
®<br />
được cung cấp.<br />
Các biến đổi sử dụng chuyển đổi các yếu tố (hoặc hằng số) mà phải được cung<br />
cấp cho<br />
chức năng biến đổi trong các yếu tố invocation.These của nó, đó là dữ liệu phức<br />
tạp<br />
bộ, được tính trong số học dấu chấm, và sau đó chuyển đổi thành fractionals ch<br />
sử dụng bởi các hoạt động. Để tránh chi phí tính toán quá nhiều khi áp dụng<br />
chuyển đổi, một tập hợp các yếu tố chuyển đổi có thể được tạo ra một lần và sử<br />
dụng<br />
nhiều lần trong quá trình thực hiện chương trình. Vì vậy, nó được khuyến khích<br />
để lưu trữ các<br />
yếu tố trở bởi bất kỳ hoạt động khởi tạo trong một vĩnh viễn (tĩnh) phức tạp<br />
vector. Nó cũng là thuận lợi để tạo ra các yếu tố "off-line", và đặt chúng trong<br />
bộ nhớ chương trình, và sử dụng chúng khi chương trình được thực hiện sau<br />
đó. Bằng cách này, không chỉ<br />
chu kỳ, nhưng cũng có bộ nhớ RAM sẽ được lưu khi thiết kế một ứng dụng liên<br />
quan đến việc<br />
biến đổi.<br />
2.7.2 Vectors Complex Fractional<br />
Một vector dữ liệu phức tạp được thể hiện bằng một tập hợp dữ liệu trong đó<br />
mỗi cặp giá trị<br />
đại diện cho một phần tử của vector. Giá trị đầu tiên trong cặp là một phần thực<br />
sự của<br />
yếu tố, và thứ hai phần ảo của nó. Cả hai phần thực và phần ảo là<br />
được lưu trữ trong bộ nhớ bằng cách sử dụng một từ (hai byte) cho mỗi, và phả<br />
được hiểu là<br />
1,15 fractionals. Như với các vector phân đoạn, phân đoạn phức tạp vector lưu<br />
trữ của nó<br />
các yếu tố liên tiếp trong bộ nhớ.<br />
Việc tổ chức dữ liệu trong một phân đoạn vector phức tạp có thể được giải<br />
quyết bằng các<br />
cấu trúc dữ liệu sau đây:<br />
#ifdef phân đoạn<br />
ifndef fractcomplex<br />
struct {<br />
phân đoạn sản;<br />
IMAG phân đoạn;<br />
} Fractcomplex;<br />
# endif<br />
# endif<br />
DSP Thư viện<br />
2004 Microchip Technology Inc DS51456B trang 59<br />
2.7.3 Xem xét tài khoản<br />
a) Không kiểm tra ranh giới được thực hiện bởi các chức năng này. Trong phạm<br />
vi kích thước<br />
(Bao gồm cả không vector chiều dài) cũng như sử dụng không phù hợp của
Language Tools Libraries<br />
DS51456B-page 58<br />
2.7 TRANSFORM FUNCTIONS<br />
2004 Microchip Technology Inc.<br />
This section presents the concept of a fractional transform, as considered by the<br />
DSP<br />
Library, and describes the individual functions which perform transform<br />
operations.<br />
2.7.1 Fractional Transform Operations<br />
A fractional transform is a linear, time invariant, discrete operation that when<br />
applied to<br />
a fractional time domain sample sequence, results in a fractional frequency in<br />
the frequency domain. Conversely, inverse fractional transform operation, when<br />
applied to<br />
frequency domain data, results in its time domain representation.<br />
A set of transforms (and a subset of inverse transforms) are provided by the<br />
DSP<br />
Library. The first set applies a Discrete Fourier transform (or its inverse) to a<br />
complex<br />
data set (see below for a description of fractional complex values). The second<br />
set<br />
applies a Type II Discrete Cosine Transform (DCT) to a real valued sequence.<br />
These<br />
transforms have been designed toeither operate out-of-place, or in-place. The<br />
former<br />
type populates an output sequence with the results of the transformation. In the<br />
latter,<br />
the input sequence is (physically) replaced by the transformed sequence. For<br />
out-of-place operations, enough memory to accept the results of the<br />
computation must<br />
be provided.<br />
The transforms make use of transform factors (or constants) which must be<br />
supplied to<br />
the transforming function during its invocation.These factors, which are<br />
complex data<br />
sets, are computed in floating point arithmetic, and then transformed into<br />
fractionals for<br />
use by the operations. To avoid excessive computational overhead when<br />
applying a<br />
transformation, a particular set of transform factors could be generated once and<br />
used<br />
many times during the execution of the program. Thus, it is advisable to store<br />
the<br />
factors returned by any of the initialization operations in a permanent (static)<br />
complex<br />
vector. It is also advantageous to generate the factors “off-line”, and place them<br />
in program memory, and use them when the program is later executing. This<br />
way, not only<br />
cycles, but also RAM memory is saved when designing an application which<br />
nguồn phức tạp<br />
vectơ và bộ yếu tố có thể tạo ra kết quả bất ngờ.<br />
b) Đó là khuyến cáo rằng tình trạng đăng ký (SR) được kiểm tra sau khi hoàn<br />
thành<br />
mỗi lần gọi hàm. Đặc biệt, người dùng có thể kiểm tra việc SA, SB và SAB cờ<br />
sau<br />
hàm trả về để xác định độ bão hòa xảy ra.<br />
c) Các vectơ đầu vào và đầu ra phức tạp liên quan đến gia đình của biến đổi<br />
mustbe phân bổ trong bộ nhớ Y-Data. Chuyển dạng các yếu tố có thể được phân<br />
bổ hoặc<br />
trong X-dữ liệu hoặc bộ nhớ chương trình.<br />
d) Bởi vì chút đảo ngược quyết yêu cầu vector thiết lập để được Modulo liên<br />
kết, các<br />
đầu vào và đầu ra phức tạp vector trong hoạt động bằng cách sử dụng một cách<br />
rõ ràng hoặc ngầm<br />
các BitReverseComplexfunction phải được phân bổ đúng cách.<br />
e) Các hoạt động đó trở về một điểm đến vector phức tạp có thể được lồng vào<br />
nhau, để cho<br />
Chẳng hạn, nếu:<br />
a = OP1 (b, c), với b = OP2 (d) và c = op3 (e, f), sau đó<br />
a = OP1 (OP2 (d), op3 (e, f)).<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 60<br />
2.7.4 Chức năng cá nhân<br />
2004 Microchip Technology Inc<br />
Trong phần tiếp theo, các chức năng cá nhân thực hiện chuyển đổi và nghịch<br />
đảo<br />
hoạt động được mô tả.<br />
BitReverseComplex<br />
Mô tả: BitReverseComplexreorganizes các yếu tố của một vector phức tạp<br />
trong bit thứ tự ngược lại.<br />
Bao gồm: dsp.h<br />
Prototype: fractcomplex extern * BitReverseComplex (<br />
int log2N,<br />
fractcomplex * srcCV<br />
);<br />
Đối số: log2N dựa 2 logarit của N (số yếu tố phức tạp trong<br />
vector nguồn)<br />
srcCV con trỏ đến nguồn vector phức tạp<br />
Quay trở lại giá trị: Con trỏ trỏ tới địa chỉ cơ sở của nguồn vector phức tạp.<br />
Bình luận: N mustbe một sức mạnh nguyên 2.<br />
Các srcCVvector phải được phân bổ tại một liên kết modulo N.
involves<br />
transformations.<br />
2.7.2 Fractional Complex Vectors<br />
A complex data vector is represented by a data set in which every pair of values<br />
represents an element of the vector. The first value in the pair is the real part of<br />
the<br />
element, and the second its imaginary part. Both the real and imaginary parts are<br />
stored in memory using one word (two bytes) for each, and must be interpreted<br />
as<br />
1.15 fractionals. As with the fractional vector, the fractional complex vector<br />
stores its<br />
elements consecutively in memory.<br />
The organization of data in a fractional complex vector may be addressed by the<br />
following data structure:<br />
#ifdef fractional<br />
#ifndef fractcomplex<br />
typedef struct {<br />
fractional real;<br />
fractional imag;<br />
} fractcomplex;<br />
#endif<br />
#endif<br />
DSP Library<br />
2004 Microchip Technology Inc. DS51456B-page 59<br />
2.7.3 User Considerations<br />
a) No boundary checking is performed by these functions. Out of range sizes<br />
(including zero length vectors) as well as nonconforming use of source complex<br />
vectors and factor sets may produce unexpected results.<br />
b) It is recommended that the Status register (SR) is examined after completion<br />
of<br />
each function call. In particular, users can inspect the SA, SB and SAB flags<br />
after<br />
the function returns to determine if saturation occurred.<br />
c) The input and output complex vectors involved in the family of<br />
transformations<br />
mustbe allocated in Y-Data memory. Transforms factors may be allocated either<br />
in X-Data or program memory.<br />
d) Because bit reverse addressing requires the vector set to be modulo aligned,<br />
the<br />
input and output complex vectors in operations using either explicitly or<br />
implicitly<br />
the BitReverseComplexfunction must be properly allocated.<br />
e) Operations which return a destination complex vector can be nested, so that<br />
Chức năng này hoạt động tại chỗ.<br />
Source File: bitrev.asm<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W7 sử dụng, không được khôi phục<br />
MODCON lưu, sử dụng, phục hồi<br />
XBREV lưu, sử dụng, phục hồi<br />
DOand REPEATinstruction sử dụng:<br />
1 DOinstructions cấp<br />
không REPEATinstructions<br />
Từ chương trình (hướng dẫn 24-bit):<br />
27<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
Chuyển đổi Size # # Complex yếu tố chu kỳ<br />
32 điểm 32 245<br />
64 điểm 64 485<br />
128 điểm 128 945<br />
256 điểm 256 1905<br />
DSP Thư viện<br />
2004 Microchip Technology Inc DS51456B trang 61<br />
CosFactorInit<br />
Mô tả: CosFactorInitgenerates nửa đầu tập hợp các yếu tố cosin<br />
yêu cầu của một loại II Discrete Cosine Transform, và đặt kết quả<br />
trong vector đến phức tạp. Hiệu quả, tập chứa<br />
giá trị:<br />
, Trong đó 0 ≤k<br />
Bao gồm: dsp.h<br />
Prototype: fractcomplex extern * CosFactorInit (<br />
int log2N,<br />
fractcomplex * cosFactors<br />
);<br />
Đối số: log2N dựa 2 logarit của N (số yếu tố phức tạp<br />
cần thiết bởi một DCT)<br />
cosFactors con trỏ đến các yếu tố phức tạp cosine<br />
Quay trở lại giá trị: Con trỏ trỏ tới địa chỉ cơ sở các yếu tố cos.<br />
Bình luận: N mustbe một sức mạnh nguyên 2.<br />
Chỉ có N / 2 cosinefactors đầu tiên được tạo ra.<br />
Một vector phức tạp có kích thước N / 2 musthave đã được phân bổ và<br />
giao cho cosFactorsprior để gọi hàm. Các phức tạp<br />
vector shouldreside trong bộ nhớ X-Data.
for<br />
instance if:<br />
a = Op1 (b, c), with b = Op2 (d), and c = Op3 (e, f), then<br />
a = Op1 (Op2 (d), Op3 (e, f)).<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
Các yếu tố được tính trong số học dấu chấm và chuyển đổi thành 1,15<br />
fractionals phức tạp.<br />
Source File: initcosf.c<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W7 sử dụng, không được khôi phục<br />
W8..W14 lưu, sử dụng, phục hồi<br />
DOand REPEATinstruction sử dụng:<br />
DS51456B-page 60<br />
2004 Microchip Technology Inc.<br />
Không<br />
2.7.4 Individual Functions<br />
In what follows, the individual functions implementing transform and inverse<br />
transform<br />
operations are described.<br />
BitReverseComplex<br />
Description: BitReverseComplexreorganizes the elements of a complex vector<br />
in bit reverse order.<br />
Include: dsp.h<br />
Prototype: extern fractcomplex* BitReverseComplex (<br />
int log2N,<br />
fractcomplex* srcCV<br />
);<br />
Arguments: log2N based 2 logarithm of N (number of complex elements in<br />
source vector)<br />
srcCV pointer to source complex vector<br />
Return Value: Pointer to base address of source complex vector.<br />
Remarks: N mustbe an integer power of 2.<br />
The srcCVvector must be allocated at a modulo alignment of N.<br />
This function operates in place.<br />
Source File: bitrev.asm<br />
Function Profile: System resources usage:<br />
W0..W7 used, not restored<br />
MODCON saved, used, restored<br />
XBREV saved, used, restored<br />
DOand REPEATinstruction usage:<br />
1 level DOinstructions<br />
no REPEATinstructions<br />
Program words (24-bit instructions):<br />
27<br />
Cycles (including C-function call and return overheads):<br />
Transform Size # Complex Elements # Cycles<br />
32 point 32 245<br />
Từ chương trình (hướng dẫn 24-bit):<br />
Xem file "readme.txt" trong pic30_tools \ src \ DSP cho thông tin này.<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
Xem file "readme.txt" trong pic30_tools \ src \ DSP cho thông tin này.<br />
DCT<br />
Mô tả: DCTcomputes rời rạc Cosine Transform của một vector nguồn, và<br />
lưu trữ các kết quả trong vector đích.<br />
Bao gồm: dsp.h<br />
Nguyên mẫu: ở ngoài phân đoạn * DCT (<br />
int log2N,<br />
phân đoạn * DSTV,<br />
phân đoạn * srcV,<br />
fractcomplex * cosFactors,<br />
fractcomplex * twidFactors,<br />
int factPage<br />
);<br />
CN k () e<br />
j<br />
πk<br />
2N<br />
------- =<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 62 2004 Microchip Technology Inc<br />
Đối số: log2N dựa 2 logarit của N (số phức tạp<br />
phần tử trong vector nguồn)<br />
dstCV con trỏ tới vector điểm đến<br />
srcCV con trỏ tới vector nguồn<br />
cosFactors con trỏ đến các yếu tố cosin<br />
twidFactors con trỏ đến các yếu tố quay vòng
64 point 64 485<br />
128 point 128 945<br />
256 point 256 1905<br />
DSP Library<br />
2004 Microchip Technology Inc. DS51456B-page 61<br />
CosFactorInit<br />
Description: CosFactorInitgenerates the first half of the set of cosine factors<br />
required by a Type II Discrete Cosine Transform, and places the result<br />
in the complex destination vector. Effectively, the set contains the<br />
values:<br />
, where 0 ≤k
and<br />
stores the results in the destination vector.<br />
Include: dsp.h<br />
Prototype: extern fractional* DCT (<br />
int log2N,<br />
fractional* dstV,<br />
fractional* srcV,<br />
fractcomplex* cosFactors,<br />
fractcomplex* twidFactors,<br />
int factPage<br />
);<br />
CN k () e<br />
j<br />
πk<br />
2N<br />
-------=<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
cộng thêm từ chương trình từ VectorZeroPad, và DCTIP.<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
22<br />
cộng với chu kỳ từ VectorZeroPad, và DCTIP.<br />
Lưu ý: Trong các mô tả về số VectorZeroPadthe của chu kỳ<br />
báo cáo bao gồm 4 chu kỳ của C-chức năng gọi điện trên không. Như vậy,<br />
số chu kỳ thực tế từ VectorZeroPadto thêm vào DCTis 4 ít<br />
hơn bất cứ số được báo cáo cho một đứng một mình VectorZeroPad.<br />
Trong cùng một cách, số chu kỳ thực tế từ DCTIPto thêm vào DCT<br />
3 ít hơn bất cứ điều gì numberis báo cáo cho một đứng một mình DCTIP.<br />
DCT (Tiếp theo)<br />
12N () /<br />
DSP Thư viện<br />
2004 Microchip Technology Inc DS51456B trang 63<br />
DCTIP<br />
Mô tả: DCTIPcomputes rời rạc Cosine Transform của một vector nguồn trong<br />
nơi.<br />
Bao gồm: dsp.h<br />
Nguyên mẫu: ở ngoài phân đoạn * DCTIP (<br />
DS51456B-page 62<br />
2004 Microchip Technology Inc.<br />
int log2N,<br />
Arguments: log2N based 2 logarithm of N (number of complex<br />
elements in source vector)<br />
dstCV pointer to destination vector<br />
srcCV pointer to source vector<br />
cosFactors pointer to cosine factors<br />
twidFactors pointer to twiddle factors<br />
factPage memory page for transform factors<br />
Return Value: Pointer to base address of destination vector.<br />
Remarks: N mustbe an integer power of 2.<br />
This function operates out of place. A vector of size 2N elements, must<br />
already have been allocated and assigned to dstV.<br />
The dstVvector must be allocated at a modulo alignment of N.<br />
The results of computation are stored in the first N elements of the<br />
destination vector.<br />
To avoid saturation (overflow) during computation, the values of the<br />
source vector shouldbe in the range [-0.5, 0.5].<br />
Only the first N/2 cosine factors are needed.<br />
Only the first N/2 twiddle factors are needed.<br />
If the transform factors are stored in X-Data space, cosFactorsand<br />
phân đoạn * srcV,<br />
fractcomplex * cosFactors,<br />
fractcomplex * twidFactors,<br />
int factPage<br />
);<br />
Đối số: log2N dựa 2 logarit của N (số yếu tố phức tạp<br />
trong vector nguồn)<br />
srcCV con trỏ tới vector nguồn<br />
cosFactors con trỏ đến các yếu tố cosin<br />
twidFactors con trỏ đến các yếu tố quay vòng<br />
trang bộ nhớ factPage cho chuyển đổi các yếu tố<br />
Quay trở lại giá trị: Con trỏ trỏ tới địa chỉ cơ sở của vector đích.<br />
Bình luận: N mustbe một sức mạnh nguyên 2.<br />
Chức năng này hy vọng rằng sourcevector đã không đệm để<br />
chiều dài 2N.<br />
Các srcVvector phải được phân bổ tại một liên kết modulo N.<br />
Các kết quả tính toán được lưu trữ trong các yếu tố đầu tiên của nguồn N<br />
vector.<br />
Để tránh bão hòa (overflow) trong tính toán, giá trị của các
twidFactorspoint to the actual address where the factors are<br />
allocated. If the transform factors are stored in program memory,<br />
cosFactorsand twidFactorsare the offset from the program page<br />
boundary where the factors are allocated. This latter value can be<br />
calculated using the inline assembly operator psvoffset().<br />
If the transform factors are stored in X-Data space, factPagemust be<br />
set to 0xFF00 (defined value COEFFS_IN_DATA). If they are stored in<br />
program memory, factPageis the program page number containing<br />
the factors. This latter value can be calculated using the inline<br />
assembly operator psvpage().<br />
The twiddle factors mustbe initialized with conjFlagset to a value<br />
different than zero.<br />
Only the first N/2 cosine factors are needed.<br />
Output is scaled by the factor<br />
Source File: dctoop.asm<br />
Function Profile: System resources usage:<br />
W0..W5 used, not restored<br />
plus system resources from VectorZeroPad, and DCTIP.<br />
DOand REPEATinstruction usage:<br />
no DOinstructions<br />
no REPEATinstructions<br />
plus DO/REPEATinstructions from VectorZeroPad, and DCTIP.<br />
Program words (24-bit instructions):<br />
nguồn vector shouldbe trong khoảng [-0.5, 0.5].<br />
Chỉ có các yếu tố N / 2 cos đầu tiên là cần thiết.<br />
Chỉ có các yếu tố N / 2 quay vòng đầu tiên là cần thiết.<br />
Nếu các yếu tố chuyển đổi được lưu trữ trong không gian X-Data,<br />
cosFactorsand<br />
twidFactorspoint đến địa chỉ thực tế nơi mà các yếu tố này<br />
phân bổ. Nếu các yếu tố chuyển đổi được lưu trữ trong bộ nhớ chương trình,<br />
cosFactorsand twidFactorsare bù đắp từ trang chương trình<br />
ranh giới nơi các yếu tố được phân bổ. Giá trị sau này có thể<br />
tính bằng cách sử dụng psvoffset hành lắp ráp nội tuyến ().<br />
Nếu các yếu tố chuyển đổi được lưu trữ trong không gian X-Data, factPagemus<br />
được<br />
thiết lập để 0xff00 (được định nghĩa COEFFS_IN_DATA giá trị). Nếu chúng<br />
được lưu trữ trong<br />
bộ nhớ chương trình, factPageis số trang có chứa chương trình<br />
các yếu tố. Giá trị sau này có thể được tính toán bằng cách sử dụng nội tuyến<br />
hành lắp ráp psvpage ().<br />
Các yếu tố quay vòng mustbe khởi tạo với conjFlagset đến một giá trị<br />
khác nhau hơn không.<br />
Kết quả sẽ được thu nhỏ lại bởi yếu tố.<br />
Source File: dctoop.asm<br />
12N () /<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
16<br />
DS51456B trang 64<br />
2004 Microchip Technology Inc<br />
plus program words from VectorZeroPad, and DCTIP.<br />
Cycles (including C-function call and return overheads):<br />
22<br />
plus cycles from VectorZeroPad, and DCTIP.<br />
Note:In the description of VectorZeroPadthe number of cycles<br />
reported includes 4 cycles of C-function call overhead. Thus, the<br />
number of actual cycles from VectorZeroPadto add to DCTis 4 less<br />
than whatever number is reported for a stand alone VectorZeroPad.<br />
In the same way, the number of actual cycles from DCTIPto add to DCT<br />
is 3 less than whatever numberis reported for a stand alone DCTIP.<br />
DCT (Continued)<br />
12N () ⁄<br />
DSP Library<br />
2004 Microchip Technology Inc. DS51456B-page 63<br />
DCTIP<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W7 sử dụng, không được khôi phục<br />
W8..W13 lưu, sử dụng, phục hồi<br />
ACCA được sử dụng, không được khôi phục<br />
CORCON lưu, sử dụng, phục hồi<br />
PSVPAG lưu, sử dụng, phục hồi (nếu<br />
hệ số P trong bộ nhớ)<br />
DOand REPEATinstruction sử dụng:<br />
1 DOinstructions cấp<br />
1 REPEATinstructions cấp<br />
cộng với DO / REPEATinstructions từ<br />
IFFTComplexIP.<br />
Từ chương trình (hướng dẫn 24-bit):<br />
92<br />
cộng thêm từ chương trình từ IFFTComplexIP.
Description: DCTIPcomputes the Discrete Cosine Transform of a source vector<br />
in<br />
place.<br />
Include: dsp.h<br />
Prototype: extern fractional* DCTIP (<br />
int log2N,<br />
fractional* srcV,<br />
fractcomplex* cosFactors,<br />
fractcomplex* twidFactors,<br />
int factPage<br />
);<br />
Arguments: log2N based 2 logarithm of N (number of complex elements<br />
in source vector)<br />
srcCV pointer to source vector<br />
cosFactors pointer to cosine factors<br />
twidFactors pointer to twiddle factors<br />
factPage memory page for transform factors<br />
Return Value: Pointer to base address of destination vector.<br />
Remarks: N mustbe an integer power of 2.<br />
This function expects that the sourcevector has been zero padded to<br />
length 2N.<br />
The srcVvector must be allocated at a modulo alignment of N.<br />
The results of computation are stored in the first N elements of source<br />
vector.<br />
To avoid saturation (overflow) during computation, the values of the<br />
source vector shouldbe in the range [-0.5, 0.5].<br />
Only the first N/2 cosine factors are needed.<br />
Only the first N/2 twiddle factors are needed.<br />
If the transform factors are stored in X-Data space, cosFactorsand<br />
twidFactorspoint to the actual address where the factors are<br />
allocated. If the transform factors are stored in program memory,<br />
cosFactorsand twidFactorsare the offset from the program page<br />
boundary where the factors are allocated. This latter value can be<br />
calculated using the inline assembly operator psvoffset().<br />
If the transform factors are stored in X-Data space, factPagemust be<br />
set to 0xFF00 (defined value COEFFS_IN_DATA). If they are stored in<br />
program memory, factPageis the program page number containing<br />
the factors. This latter value can be calculated using the inline<br />
assembly operator psvpage().<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
71 + 10N, hoặc<br />
73 + 11N nếu các yếu tố trong bộ nhớ chương trình,<br />
cộng với chu kỳ từ IFFTComplexIP<br />
Lưu ý: Trong các mô tả về số IFFTComplexIPthe của chu kỳ<br />
báo cáo bao gồm 4 chu kỳ của C-chức năng gọi điện trên không. Như vậy,<br />
số chu kỳ thực tế từ IFFTComplexIPto thêm vào DCTIPis 4<br />
ít hơn bất cứ số được báo cáo cho một đứng một mình<br />
IFFTComplexIP.<br />
FFTComplex<br />
Mô tả: FFTComplexcomputes rời rạc đổi Fourier của một nguồn<br />
vector phức tạp, và lưu trữ các kết quả trong các địa điểm phức tạp<br />
vector.<br />
Bao gồm: dsp.h<br />
Prototype: fractcomplex extern * FFTComplex (<br />
int log2N,<br />
fractcomplex * dstCV,<br />
fractcomplex * srcCV,<br />
fractcomplex * twidFactors,<br />
int factPage<br />
);<br />
Đối số: log2N dựa 2 logarit của N (số yếu tố phức tạp<br />
trong vector nguồn)<br />
dstCV con trỏ đến đích vector phức tạp<br />
srcCV con trỏ đến nguồn vector phức tạp<br />
địa chỉ twidFactors cơ sở các yếu tố quay vòng<br />
trang bộ nhớ factPage cho chuyển đổi các yếu tố<br />
Quay trở lại giá trị: Con trỏ trỏ tới địa chỉ cơ sở của địa điểm vector phức tạp.<br />
DCTIP (Tiếp theo)<br />
DSP Thư viện<br />
2004 Microchip Technology Inc DS51456B trang 65<br />
Bình luận: N mustbe một sức mạnh nguyên 2.<br />
Chức năng này hoạt động trên place.A vector phức tạp, đủ để lớn<br />
nhận được kết quả của hoạt động này, mustalready đã được giao<br />
và giao cho dstCV.<br />
Các dstCVvector phải được phân bổ tại một liên kết modulo N.<br />
Các yếu tố trong nguồn vector phức tạp được dự kiến trong trật tự tự nhiên.<br />
Các yếu tố trong điểm đến vector phức tạp được tạo ra trong tự nhiên<br />
trật tự.
The twiddle factors mustbe initialized with conjFlagset to a value<br />
different than zero.<br />
Output is scaled by the factor .<br />
Source File: dctoop.asm<br />
12N () ⁄<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
Để tránh bão hòa (overflow) duringcomputation, tầm quan trọng của<br />
giá trị của các nguồn phức tạp vector shouldbe trong khoảng [-0.5, 0.5].<br />
Chỉ có các yếu tố N / 2 quay vòng đầu tiên là cần thiết.<br />
Nếu các yếu tố quay vòng được lưu trữ trong không gian X-Data,<br />
twidFactorspoints<br />
đến địa chỉ thực tế mà các yếu tố được phân bổ. Nếu quay vòng<br />
yếu tố được lưu trữ trong bộ nhớ chương trình, twidFactorsis bù đắp từ<br />
ranh giới trang chương trình mà các yếu tố được phân bổ. Sau này<br />
giá trị có thể được tính bằng cách sử dụng toán tử lắp ráp nội tuyến<br />
DS51456B-page 64<br />
2004 Microchip Technology Inc.<br />
psvoffset ().<br />
Function Profile: System resources usage:<br />
W0..W7 used, not restored<br />
W8..W13 saved, used, restored<br />
ACCA used, not restored<br />
CORCON saved, used, restored<br />
PSVPAG saved, used, restored (only if<br />
coefficients in P memory)<br />
DOand REPEATinstruction usage:<br />
1 level DOinstructions<br />
1 level REPEATinstructions<br />
plus DO/REPEATinstructions from<br />
IFFTComplexIP.<br />
Program words (24-bit instructions):<br />
92<br />
plus program words from IFFTComplexIP.<br />
Cycles (including C-function call and return overheads):<br />
71 + 10N, or<br />
73 + 11N if factors in program memory,<br />
plus cycles from IFFTComplexIP<br />
Note:In the description of IFFTComplexIPthe number of cycles<br />
reported includes 4 cycles of C-function call overhead. Thus, the<br />
number of actual cycles from IFFTComplexIPto add to DCTIPis 4<br />
less than whatever number is reported for a stand alone<br />
IFFTComplexIP.<br />
FFTComplex<br />
Description: FFTComplexcomputes the Discrete Fourier Transform of a source<br />
complex vector, and stores the results in the destination complex<br />
vector.<br />
Include: dsp.h<br />
Prototype: extern fractcomplex*FFTComplex (<br />
Nếu các yếu tố quay vòng được lưu trữ trong không gian X-Data, factPagemust<br />
được<br />
thiết lập để 0xff00 (được định nghĩa COEFFS_IN_DATA giá trị). Nếu chúng<br />
được lưu trữ trong<br />
bộ nhớ chương trình, factPageis số trang có chứa chương trình<br />
các yếu tố. Giá trị sau này có thể được tính toán bằng cách sử dụng nội tuyến<br />
hành lắp ráp psvpage ().<br />
Các yếu tố quay vòng mustbe khởi tạo với conjFlagset không.<br />
Kết quả sẽ được thu nhỏ lại bởi yếu tố 1 / N.<br />
Source File: fftoop.asm<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W4 sử dụng, không được khôi phục<br />
cộng với tài nguyên hệ thống từ VectorCopy, FFTComplexIP, và<br />
BitReverseComplex.<br />
DOand REPEATinstruction sử dụng:<br />
không DOinstructions<br />
không REPEATinstructions<br />
cộng với DO / REPEATinstructions từ VectorCopy, FFTComplexIP,<br />
và BitReverseComplex.<br />
Từ chương trình (hướng dẫn 24-bit):<br />
17<br />
cộng thêm từ chương trình từ VectorCopy, FFTComplexIP, và<br />
BitReverseComplex.<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
23<br />
cộng với chu kỳ từ VectorCopy, FFTComplexIP, và<br />
BitReverseComplex.<br />
Lưu ý: Trong các mô tả về số VectorCopythe chu kỳ báo cáo<br />
bao gồm 3 chu kỳ của C-chức năng calloverhead. Như vậy, số lượng<br />
chu kỳ thực tế từ VectorCopyto thêm vào FFTComplexis 3 ít hơn<br />
bất cứ số được báo cáo cho một đứng một mình VectorCopy. Trong
int log2N,<br />
fractcomplex* dstCV,<br />
fractcomplex* srcCV,<br />
fractcomplex* twidFactors,<br />
int factPage<br />
);<br />
Arguments: log2N based 2 logarithm of N (number of complex elements<br />
in source vector)<br />
dstCV pointer to destination complex vector<br />
srcCV pointer to source complex vector<br />
twidFactors base address of twiddle factors<br />
factPage memory page for transform factors<br />
Return Value: Pointer to base address of destination complex vector.<br />
DCTIP (Continued)<br />
DSP Library<br />
2004 Microchip Technology Inc. DS51456B-page 65<br />
Remarks: N mustbe an integer power of 2.<br />
This function operates out of place.A complex vector, large enough to<br />
receive the results of the operation, mustalready have been allocated<br />
and assigned to dstCV.<br />
The dstCVvector must be allocated at a modulo alignment of N.<br />
The elements in source complex vector are expected in natural order.<br />
The elements in destination complex vector are generated in natural<br />
order.<br />
To avoid saturation (overflow) duringcomputation, the magnitude of the<br />
values of the source complex vector shouldbe in the range [-0.5, 0.5].<br />
Only the first N/2 twiddle factors are needed.<br />
If the twiddle factors are stored in X-Data space, twidFactorspoints<br />
to the actual address where the factors are allocated. If the twiddle<br />
factors are stored in program memory, twidFactorsis the offset from<br />
the program page boundary where the factors are allocated. This latter<br />
value can be calculated using the inline assembly operator<br />
psvoffset().<br />
If the twiddle factors are stored in X-Data space, factPagemust be<br />
set to 0xFF00 (defined value COEFFS_IN_DATA). If they are stored in<br />
program memory, factPageis the program page number containing<br />
the factors. This latter value can be calculated using the inline<br />
assembly operator psvpage().<br />
The twiddle factors mustbe initialized with conjFlagset to zero.<br />
cùng một cách, số chu kỳ thực tế từ FFTComplexIPto thêm vào<br />
FFTComplexis 4 ít hơn bất cứ số được báo cáo cho một đứng<br />
FFTComplexIP mình. Và những từ BitReverseComplexare 2<br />
ít hơn bất cứ số được báo cáo cho một FFTComplex đứng một mình.<br />
FFTComplex (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 66<br />
FFTComplexIP<br />
2004 Microchip Technology Inc<br />
Mô tả: FFTComplexIPcomputes rời rạc đổi Fourier của một nguồn<br />
vector phức tạp tại chỗ ..<br />
Bao gồm: dsp.h<br />
Prototype: fractcomplex extern * FFTComplexIP (<br />
int log2N,<br />
fractcomplex * srcCV,<br />
fractcomplex * twidFactors,<br />
int factPage<br />
);<br />
Đối số: log2N dựa 2 logarit của N (số phức tạp<br />
phần tử trong vector nguồn)<br />
srcCV con trỏ đến nguồn vector phức tạp<br />
địa chỉ twidFactors cơ sở các yếu tố quay vòng<br />
trang bộ nhớ factPage cho chuyển đổi các yếu tố<br />
Quay trở lại giá trị: Con trỏ trỏ tới địa chỉ cơ sở của nguồn vector phức tạp.<br />
Bình luận: N mustbe một sức mạnh nguyên 2.<br />
Các yếu tố trong nguồn vector phức tạp được dự kiến trong trật tự tự nhiên.<br />
Các kết quả chuyển đổi được lưu trữ trong bit thứ tự ngược.<br />
Để tránh bão hòa (overflow) trong tính toán, độ lớn của<br />
giá trị của các vector phức tạp nguồn nên trong khoảng [-0.5, 0.5].<br />
Chỉ có các yếu tố N / 2 quay vòng đầu tiên là cần thiết.<br />
Nếu các yếu tố quay vòng được lưu trữ trong không gian X-Data,<br />
twidFactorspoints<br />
đến địa chỉ thực tế mà các yếu tố được phân bổ. Nếu quay vòng<br />
yếu tố được lưu trữ trong bộ nhớ chương trình, twidFactorsis bù đắp từ<br />
ranh giới trang chương trình mà các yếu tố được phân bổ. Sau này<br />
giá trị có thể được tính bằng cách sử dụng toán tử lắp ráp nội tuyến<br />
psvoffset ().<br />
Nếu các yếu tố quay vòng được lưu trữ trong không gian X-Data, factPagemust<br />
được<br />
thiết lập để 0xff00 (được định nghĩa COEFFS_IN_DATA giá trị). Nếu chúng
Output is scaled by the factor 1/N.<br />
Source File: fftoop.asm<br />
Function Profile: System resources usage:<br />
W0..W4 used, not restored<br />
plus system resources from VectorCopy, FFTComplexIP, and<br />
BitReverseComplex.<br />
DOand REPEATinstruction usage:<br />
no DOinstructions<br />
no REPEATinstructions<br />
plus DO/REPEATinstructions from VectorCopy, FFTComplexIP,<br />
and BitReverseComplex.<br />
Program words (24-bit instructions):<br />
17<br />
plus program words from VectorCopy, FFTComplexIP, and<br />
BitReverseComplex.<br />
Cycles (including C-function call and return overheads):<br />
23<br />
plus cycles from VectorCopy, FFTComplexIP, and<br />
BitReverseComplex.<br />
Note:In the description of VectorCopythe number of cycles reported<br />
includes 3 cycles of C-function calloverhead. Thus, the number of<br />
actual cycles from VectorCopyto add to FFTComplexis 3 less than<br />
whatever number is reported for a stand alone VectorCopy. In the<br />
same way, the number of actual cycles from FFTComplexIPto add to<br />
FFTComplexis 4 less than whatever number is reported for a stand<br />
alone FFTComplexIP. And those from BitReverseComplexare 2<br />
less than whatever number is reported for a stand alone FFTComplex.<br />
FFTComplex (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 66<br />
FFTComplexIP<br />
2004 Microchip Technology Inc.<br />
Description: FFTComplexIPcomputes the Discrete Fourier Transform of a<br />
source<br />
complex vector in place..<br />
Include: dsp.h<br />
Prototype: extern fractcomplex*FFTComplexIP (<br />
int log2N,<br />
được lưu trữ trong<br />
bộ nhớ chương trình, factPageis số trang có chứa chương trình<br />
các yếu tố. Giá trị sau này có thể được tính toán bằng cách sử dụng nội tuyến<br />
hành lắp ráp psvpage ().<br />
Các yếu tố quay vòng mustbe khởi tạo với conjFlagset không.<br />
Kết quả sẽ được thu nhỏ lại bởi yếu tố 1 / N.<br />
Source File: fft.asm<br />
DSP Thư viện<br />
2004 Microchip Technology Inc DS51456B trang 67<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W7 sử dụng, không được khôi phục<br />
W8..W13 lưu, sử dụng, phục hồi<br />
ACCA được sử dụng, không được khôi phục<br />
ACCB sử dụng, không được khôi phục<br />
CORCON lưu, sử dụng, phục hồi<br />
PSVPAG lưu, sử dụng, phục hồi (nếu<br />
hệ số P trong bộ nhớ)<br />
DOand REPEATinstruction sử dụng:<br />
2 DOinstructions cấp<br />
không REPEATinstructions<br />
Từ chương trình (hướng dẫn 24-bit):<br />
59<br />
Chu kỳ (bao gồm C-functioncall và trả các chi phí):<br />
Chuyển đổi kích thước<br />
# Nếu chu kỳ quay vòng<br />
Các yếu tố trong X-mem<br />
# Nếu chu kỳ quay vòng<br />
Các yếu tố trong P-mem<br />
32 điểm 1633 1795<br />
64 điểm 3739 4125<br />
128 điểm 8485 9383<br />
256 điểm 19.055 21.105<br />
IFFTComplex<br />
Mô tả: IFFTComplexcomputes các Inverse Discrete đổi Fourier của một<br />
nguồn vector phức tạp, và lưu trữ các kết quả ở đích đến<br />
vector phức tạp.<br />
Bao gồm: dsp.h<br />
Prototype: fractcomplex extern * IFFTComplex (<br />
int log2N,
fractcomplex* srcCV,<br />
fractcomplex* twidFactors,<br />
int factPage<br />
);<br />
Arguments: log2N based 2 logarithm of N (number of complex<br />
elements in source vector)<br />
srcCV pointer to source complex vector<br />
twidFactors base address of twiddle factors<br />
factPage memory page for transform factors<br />
Return Value: Pointer to base address of source complex vector.<br />
Remarks: N mustbe an integer power of 2.<br />
The elements in source complex vector are expected in natural order.<br />
The resulting transform is stored in bit reverse order.<br />
To avoid saturation (overflow) during computation, the magnitude of the<br />
values of the source complex vector should be in the range [-0.5, 0.5].<br />
Only the first N/2 twiddle factors are needed.<br />
If the twiddle factors are stored in X-Data space, twidFactorspoints<br />
to the actual address where the factors are allocated. If the twiddle<br />
factors are stored in program memory, twidFactorsis the offset from<br />
the program page boundary where the factors are allocated. This latter<br />
value can be calculated using the inline assembly operator<br />
psvoffset().<br />
If the twiddle factors are stored in X-Data space, factPagemust be<br />
set to 0xFF00 (defined value COEFFS_IN_DATA). If they are stored in<br />
program memory, factPageis the program page number containing<br />
the factors. This latter value can be calculated using the inline<br />
assembly operator psvpage().<br />
The twiddle factors mustbe initialized with conjFlagset to zero.<br />
Output is scaled by the factor 1/N.<br />
Source File: fft.asm<br />
DSP Library<br />
2004 Microchip Technology Inc. DS51456B-page 67<br />
Function Profile: System resources usage:<br />
W0..W7 used, not restored<br />
W8..W13 saved, used, restored<br />
ACCA used, not restored<br />
ACCB used, not restored<br />
CORCON saved, used, restored<br />
PSVPAG saved, used, restored (only if<br />
fractcomplex * dstCV,<br />
fractcomplex * srcCV,<br />
fractcomplex * twidFactors,<br />
int factPage<br />
);<br />
Đối số: log2N dựa 2 logarit của N (số yếu tố phức tạp<br />
trong vector nguồn)<br />
dstCV con trỏ đến đích vector phức tạp<br />
srcCV con trỏ đến nguồn vector phức tạp<br />
địa chỉ twidFactors cơ sở các yếu tố quay vòng<br />
trang bộ nhớ factPage cho chuyển đổi các yếu tố<br />
Quay trở lại giá trị: Con trỏ trỏ tới địa chỉ cơ sở của địa điểm vector phức tạp.<br />
FFTComplexIP (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 68<br />
2004 Microchip Technology Inc<br />
Bình luận: N mustbe một sức mạnh nguyên 2.<br />
Chức năng này hoạt động trên place.A vector phức tạp, đủ để lớn<br />
nhận được kết quả của hoạt động này, mustalready đã được giao<br />
và giao cho dstCV.<br />
Các dstCVvector phải được phân bổ tại một liên kết modulo N.<br />
Các yếu tố trong nguồn vector phức tạp được dự kiến trong trật tự tự nhiên.<br />
Các yếu tố trong điểm đến vector phức tạp được tạo ra trong tự nhiên<br />
trật tự.<br />
Để tránh bão hòa (overflow) trong tính toán, độ lớn của<br />
giá trị của các nguồn phức tạp vector shouldbe trong khoảng [-0.5, 0.5].<br />
Nếu các yếu tố quay vòng được lưu trữ trong không gian X-Data,<br />
twidFactorspoints<br />
đến địa chỉ thực tế mà các yếu tố được phân bổ. Nếu quay vòng<br />
yếu tố được lưu trữ trong bộ nhớ chương trình, twidFactorsis bù đắp từ<br />
ranh giới trang chương trình mà các yếu tố được phân bổ. Sau này<br />
giá trị có thể được tính bằng cách sử dụng toán tử lắp ráp nội tuyến<br />
psvoffset ().<br />
Nếu các yếu tố quay vòng được lưu trữ trong không gian X-Data, factPagemust<br />
được<br />
thiết lập để 0xff00 (được định nghĩa COEFFS_IN_DATA giá trị). Nếu chúng<br />
được lưu trữ trong<br />
bộ nhớ chương trình, factPageis số trang có chứa chương trình<br />
các yếu tố. Giá trị sau này có thể được tính toán bằng cách sử dụng nội tuyến<br />
hành lắp ráp psvpage ().
coefficients in P memory)<br />
DOand REPEATinstruction usage:<br />
2 level DOinstructions<br />
no REPEATinstructions<br />
Program words (24-bit instructions):<br />
59<br />
Cycles (including C-functioncall and return overheads):<br />
Transform Size<br />
# Cycles if Twiddle<br />
Factors in X-mem<br />
# Cycles if Twiddle<br />
Factors in P-mem<br />
32 point 1,633 1,795<br />
64 point 3,739 4,125<br />
128 point 8,485 9,383<br />
256 point 19,055 21,105<br />
IFFTComplex<br />
Description: IFFTComplexcomputes the Inverse Discrete Fourier Transform of<br />
a<br />
source complex vector, and stores the results in the destination<br />
complex vector.<br />
Include: dsp.h<br />
Prototype: extern fractcomplex*IFFTComplex (<br />
int log2N,<br />
fractcomplex* dstCV,<br />
fractcomplex* srcCV,<br />
fractcomplex* twidFactors,<br />
int factPage<br />
);<br />
Arguments: log2N based 2 logarithm of N (number of complex elements<br />
in source vector)<br />
dstCV pointer to destination complex vector<br />
srcCV pointer to source complex vector<br />
twidFactors base address of twiddle factors<br />
factPage memory page for transform factors<br />
Return Value: Pointer to base address of destination complex vector.<br />
FFTComplexIP (Continued)<br />
dsPIC<br />
®<br />
Các yếu tố quay vòng mustbe khởi tạo với conjFlagset đến một giá trị<br />
khác hơn không.<br />
Chỉ có các yếu tố N / 2 quay vòng đầu tiên là cần thiết.<br />
Source File: ifftoop.asm<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W4 sử dụng, không được khôi phục<br />
cộng với tài nguyên hệ thống từ VectorCopy, và IFFTComplexIP.<br />
DOand REPEATinstruction sử dụng:<br />
không DOinstructions<br />
không REPEATinstructions<br />
cộng với DO / REPEATinstructions từ VectorCopy, và<br />
IFFTComplexIP.<br />
Từ chương trình (hướng dẫn 24-bit):<br />
12<br />
cộng thêm từ chương trình từ VectorCopy, và IFFTComplexIP.<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
15<br />
cộng với chu kỳ từ VectorCopy, và IFFTComplexIP.<br />
Lưu ý: Trong các mô tả về số VectorCopythe chu kỳ báo cáo<br />
bao gồm 3 chu kỳ của C-chức năng gọi điện trên không. Như vậy, số lượng<br />
chu kỳ thực tế từ VectorCopyto thêm vào IFFTComplexis 3 ít hơn<br />
bất cứ số được báo cáo cho một đứng một mình VectorCopy. Trong<br />
cùng một cách, số chu kỳ thực tế từ IFFTComplexIPto thêm vào<br />
IFFTComplexis 4 ít hơn bất cứ số được báo cáo cho một đứng<br />
IFFTComplexIP mình.<br />
IFFTComplex (Tiếp theo)<br />
DSP Thư viện<br />
2004 Microchip Technology Inc DS51456B trang 69<br />
IFFTComplexIP<br />
Mô tả: IFFTComplexIPcomputes các Inverse Discrete đổi Fourier của<br />
một nguồn vector phức tạp tại chỗ ..<br />
Bao gồm: dsp.h<br />
Prototype: fractcomplex extern * IFFTComplexIP (<br />
int log2N,<br />
fractcomplex * srcCV,<br />
fractcomplex * twidFactors,<br />
int factPage<br />
);<br />
Đối số: log2N dựa 2 logarit của N (số yếu tố phức tạp
Language Tools Libraries<br />
DS51456B-page 68 2004 Microchip Technology Inc.<br />
Remarks: N mustbe an integer power of 2.<br />
This function operates out of place.A complex vector, large enough to<br />
receive the results of the operation, mustalready have been allocated<br />
and assigned to dstCV.<br />
The dstCVvector must be allocated at a modulo alignment of N.<br />
The elements in source complex vector are expected in natural order.<br />
The elements in destination complex vector are generated in natural<br />
order.<br />
To avoid saturation (overflow) during computation, the magnitude of the<br />
values of the source complex vector shouldbe in the range [-0.5, 0.5].<br />
If the twiddle factors are stored in X-Data space, twidFactorspoints<br />
to the actual address where the factors are allocated. If the twiddle<br />
factors are stored in program memory, twidFactorsis the offset from<br />
the program page boundary where the factors are allocated. This latter<br />
value can be calculated using the inline assembly operator<br />
psvoffset().<br />
If the twiddle factors are stored in X-Data space, factPagemust be<br />
set to 0xFF00 (defined value COEFFS_IN_DATA). If they are stored in<br />
program memory, factPageis the program page number containing<br />
the factors. This latter value can be calculated using the inline<br />
assembly operator psvpage().<br />
The twiddle factors mustbe initialized with conjFlagset to a value<br />
other than zero.<br />
Only the first N/2 twiddle factors are needed.<br />
Source File: ifftoop.asm<br />
Function Profile: System resources usage:<br />
W0..W4 used, not restored<br />
plus system resources from VectorCopy, and IFFTComplexIP.<br />
trong vector nguồn)<br />
srcCV con trỏ đến nguồn vector phức tạp<br />
địa chỉ twidFactors cơ sở các yếu tố quay vòng<br />
trang bộ nhớ factPage cho chuyển đổi các yếu tố<br />
Quay trở lại giá trị: Con trỏ trỏ tới địa chỉ cơ sở của nguồn vector phức tạp.<br />
Bình luận: N mustbe một sức mạnh nguyên 2.<br />
Các yếu tố trong nguồn vector phức tạp được dự kiến trong bit ngược<br />
trật tự. Các kết quả chuyển đổi được lưu trữ trong trật tự tự nhiên.<br />
Các srcCVvector phải được phân bổ tại một liên kết modulo N.<br />
Để tránh bão hòa (overflow) duringcomputation, tầm quan trọng của<br />
giá trị của các nguồn phức tạp vector shouldbe trong khoảng [-0.5, 0.5].<br />
Nếu các yếu tố quay vòng được lưu trữ trong không gian X-Data,<br />
twidFactorspoints<br />
đến địa chỉ thực tế mà các yếu tố được phân bổ. Nếu quay vòng<br />
yếu tố được lưu trữ trong bộ nhớ chương trình, twidFactorsis bù đắp từ<br />
ranh giới trang chương trình mà các yếu tố được phân bổ. Sau này<br />
giá trị có thể được tính bằng cách sử dụng toán tử lắp ráp nội tuyến<br />
psvoffset ().<br />
Nếu các yếu tố quay vòng được lưu trữ trong không gian X-Data, factPagemust<br />
được<br />
thiết lập để 0xff00 (được định nghĩa COEFFS_IN_DATA giá trị). Nếu chúng<br />
được lưu trữ trong<br />
bộ nhớ chương trình, factPageis số trang có chứa chương trình<br />
các yếu tố. Giá trị sau này có thể được tính toán bằng cách sử dụng nội tuyến<br />
hành lắp ráp psvpage ().<br />
Các yếu tố quay vòng mustbe khởi tạo với conjFlagset đến một giá trị<br />
khác hơn không.<br />
Chỉ có các yếu tố N / 2 quay vòng đầu tiên là cần thiết.<br />
Source File: ifft.asm<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DOand REPEATinstruction usage:<br />
DS51456B trang 70<br />
2004 Microchip Technology Inc<br />
no DOinstructions<br />
no REPEATinstructions<br />
plus DO/REPEATinstructions from VectorCopy, and<br />
IFFTComplexIP.<br />
Program words (24-bit instructions):<br />
12<br />
plus program words from VectorCopy, and IFFTComplexIP.<br />
Cycles (including C-function call and return overheads):<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W3 sử dụng, không được khôi phục<br />
cộng với tài nguyên hệ thống từ FFTComplexIP, và<br />
BitReverseComplex.<br />
DOand REPEATinstruction sử dụng:<br />
không DOinstructions<br />
không REPEATinstructions<br />
cộng với DO / REPEATinstructions từ FFTComplexIP, và
15<br />
plus cycles from VectorCopy, and IFFTComplexIP.<br />
Note:In the description of VectorCopythe number of cycles reported<br />
includes 3 cycles of C-function call overhead. Thus, the number of<br />
actual cycles from VectorCopyto add to IFFTComplexis 3 less than<br />
whatever number is reported for a stand alone VectorCopy. In the<br />
same way, the number of actual cycles from IFFTComplexIPto add to<br />
IFFTComplexis 4 less than whatever number is reported for a stand<br />
alone IFFTComplexIP.<br />
IFFTComplex (Continued)<br />
DSP Library<br />
2004 Microchip Technology Inc. DS51456B-page 69<br />
IFFTComplexIP<br />
Description: IFFTComplexIPcomputes the Inverse Discrete Fourier Transform<br />
of<br />
a source complex vector in place..<br />
Include: dsp.h<br />
Prototype: extern fractcomplex*IFFTComplexIP (<br />
int log2N,<br />
fractcomplex* srcCV,<br />
fractcomplex* twidFactors,<br />
int factPage<br />
);<br />
Arguments: log2N based 2 logarithm of N (number of complex elements<br />
in source vector)<br />
srcCV pointer to source complex vector<br />
twidFactors base address of twiddle factors<br />
factPage memory page for transform factors<br />
Return Value: Pointer to base address of source complex vector.<br />
Remarks: N mustbe an integer power of 2.<br />
The elements in source complex vector are expected in bit reverse<br />
order. The resulting transform is stored in natural order.<br />
The srcCVvector must be allocated at a modulo alignment of N.<br />
To avoid saturation (overflow) duringcomputation, the magnitude of the<br />
values of the source complex vector shouldbe in the range [-0.5, 0.5].<br />
If the twiddle factors are stored in X-Data space, twidFactorspoints<br />
to the actual address where the factors are allocated. If the twiddle<br />
factors are stored in program memory, twidFactorsis the offset from<br />
the program page boundary where the factors are allocated. This latter<br />
BitReverseComplex.<br />
Từ chương trình (hướng dẫn 24-bit):<br />
11<br />
cộng thêm từ chương trình từ FFTComplexIP, và<br />
BitReverseComplex.<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
15<br />
cộng với chu kỳ từ FFTComplexIP, và BitReverseComplex.<br />
Lưu ý: Trong các mô tả về số FFTComplexIPthe của chu kỳ<br />
báo cáo bao gồm 3 chu kỳ của C-chức năng gọi điện trên không. Như vậy,<br />
số chu kỳ thực tế từ FFTComplexIPto thêm vào<br />
IFFTComplexIPis 3 ít hơn bất cứ số được báo cáo cho một<br />
đứng một mình<br />
FFTComplexIP. Trong cùng một cách, số chu kỳ thực tế từ<br />
BitReverseComplexto thêm vào IFFTComplexIPis 2 ít hơn<br />
bất cứ số được báo cáo cho một đứng một mình BitReverseComplex.<br />
TwidFactorInit<br />
Mô tả: TwidFactorInitgenerates nửa đầu tập hợp các yếu tố quay vòng<br />
yêu cầu của một Discrete Fourier Transform hoặc rời rạc Cosine Transform,<br />
và đặt kết quả trong vector đến phức tạp. Có hiệu quả,<br />
tập hợp chứa các giá trị:<br />
, Trong đó 0 ≤k ≤N / 2, cho conjFlag = 0<br />
, Trong đó 0 ≤k ≤N / 2, cho conjFlag! = 0<br />
Bao gồm: dsp.h<br />
Prototype: fractcomplex extern * TwidFactorInit (<br />
int log2N,<br />
fractcomplex * twidFactors,<br />
int conjFlag<br />
);<br />
Đối số: log2N dựa 2 logarit của N (số yếu tố phức tạp<br />
cần thiết bởi một DFT)<br />
twidFactors con trỏ đến các yếu tố quay vòng phức tạp<br />
conjFlag cờ để cho biết giá trị liên hợp ornot là<br />
để được tạo ra<br />
Quay trở lại giá trị: Con trỏ trỏ tới địa chỉ cơ sở các yếu tố quay vòng.<br />
IFFTComplexIP (Tiếp theo)<br />
WN k () e<br />
j<br />
2πk
value can be calculated using the inline assembly operator<br />
psvoffset().<br />
If the twiddle factors are stored in X-Data space, factPagemust be<br />
set to 0xFF00 (defined value COEFFS_IN_DATA). If they are stored in<br />
program memory, factPageis the program page number containing<br />
the factors. This latter value can be calculated using the inline<br />
assembly operator psvpage().<br />
The twiddle factors mustbe initialized with conjFlagset to a value<br />
other than zero.<br />
Only the first N/2 twiddle factors are needed.<br />
Source File: ifft.asm<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 70 2004 Microchip Technology Inc.<br />
Function Profile: System resources usage:<br />
W0..W3 used, not restored<br />
plus system resources from FFTComplexIP, and<br />
BitReverseComplex.<br />
DOand REPEATinstruction usage:<br />
no DOinstructions<br />
no REPEATinstructions<br />
plus DO/REPEATinstructions from FFTComplexIP, and<br />
BitReverseComplex.<br />
Program words (24-bit instructions):<br />
11<br />
plus program words from FFTComplexIP, and<br />
BitReverseComplex.<br />
Cycles (including C-function call and return overheads):<br />
15<br />
plus cycles from FFTComplexIP, and BitReverseComplex.<br />
Note:In the description of FFTComplexIPthe number of cycles<br />
reported includes 3 cycles of C-function call overhead. Thus, the<br />
number of actual cycles from FFTComplexIPto add to<br />
IFFTComplexIPis 3 less than whatever number is reported for a<br />
stand alone<br />
FFTComplexIP. In the same way, the number of actual cycles from<br />
BitReverseComplexto add to IFFTComplexIPis 2 less than<br />
whatever number is reported for a stand alone BitReverseComplex.<br />
N<br />
--------- - -<br />
=<br />
WN k () e<br />
j<br />
2πk<br />
N<br />
--------- - =<br />
DSP Thư viện<br />
2004 Microchip Technology Inc DS51456B trang 71<br />
Bình luận: N mustbe một sức mạnh nguyên 2.<br />
Chỉ có các yếu tố N / 2 quay vòng đầu tiên được tạo ra.<br />
Giá trị của conjFlagdetermines dấu trong lập luận của<br />
hàm mũ. Đối với phía trước phép biến đổi Fourier, conjFlag<br />
nên được thiết lập để "0". Đối nghịch đảo phép biến đổi Fourier rời rạc và<br />
Cosin Transforms, conjFlagshould được thiết lập để "1".<br />
Một vector phức tạp có kích thước N / 2 phải đã được phân bổ và<br />
giao cho twidFactorsprior để gọi hàm. Các phức tạp<br />
vector shouldbe phân bổ trong bộ nhớ X-Data.<br />
Các yếu tố tính toán trong số học dấu chấm và chuyển đổi thành 1,15<br />
fractionals phức tạp.<br />
Source File: inittwid.c<br />
Chức năng thông tin: sử dụng nguồn tài nguyên của hệ thống:<br />
W0..W7 sử dụng, không được khôi phục<br />
W8..W14 lưu, sử dụng, phục hồi<br />
DOand REPEATinstruction sử dụng:<br />
Không<br />
Từ chương trình (hướng dẫn 24-bit):<br />
Xem file "readme.txt" trong pic30_tools \ src \ DSP cho thông tin này.<br />
Chu kỳ (bao gồm cả cuộc gọi C-chức năng và trả các chi phí):<br />
Xem file "readme.txt" trong pic30_tools \ src \ DSP cho thông tin này.<br />
TwidFactorInit (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 72 2004 Microchip Technology Inc<br />
GHI CHÚ:<br />
dsPIC<br />
®LANGUAGE CÔNG CỤ
TwidFactorInit<br />
Description: TwidFactorInitgenerates the first half of the set of twiddle factors<br />
required by a Discrete Fourier Transform or Discrete Cosine Transform,<br />
and places the result in the complex destination vector. Effectively, the<br />
set contains the values:<br />
, where 0 ≤k ≤N/2, for conjFlag= 0<br />
, where 0 ≤k ≤N/2, for conjFlag! = 0<br />
Include: dsp.h<br />
Prototype: extern fractcomplex*TwidFactorInit (<br />
int log2N,<br />
fractcomplex* twidFactors,<br />
int conjFlag<br />
);<br />
Arguments: log2N based 2 logarithm of N (number of complex factors<br />
needed by a DFT)<br />
twidFactors pointer to complex twiddle factors<br />
conjFlag flag to indicate whether ornot conjugate values are<br />
to be generated<br />
Return Value: Pointer to base address of twiddle factors.<br />
IFFTComplexIP (Continued)<br />
WN k() e<br />
j<br />
2πk<br />
N<br />
--------- - –<br />
=<br />
WN k() e<br />
j<br />
2πk<br />
N<br />
--------- -=<br />
DSP Library<br />
2004 Microchip Technology Inc. DS51456B-page 71<br />
Remarks: N mustbe an integer power of 2.<br />
Only the first N/2 twiddle factors are generated.<br />
The value of conjFlagdetermines the sign in the argument of the<br />
exponential function. For forward Fourier Transforms, conjFlag<br />
should be set to ‘0’. For inverse Fourier Transforms and Discrete<br />
Cosine Transforms, conjFlagshould be set to ‘1’.<br />
THƯ VIỆN<br />
2004 Microchip Technology Inc DS51456B trang 73<br />
Chương 3: dsPIC Thư viện ngoại vi<br />
3.1 GIỚI THIỆU<br />
Chương này làm rõ chức năng và các macro có trong thiết bị ngoại vi dsPIC<br />
thư viện. Ví dụ về sử dụng cũng được cung cấp.<br />
Mã kích thước cho mỗi chức năng thư viện hoặc vĩ mô có thể được tìm thấy<br />
trong các tập tin readme.txtin<br />
pic30_tools \ src \ ngoại vi.<br />
3.1.1 ứng dụng .Assembly Mã<br />
Phiên bản miễn phí của các thư viện và các tập tin tiêu đề liên quan có sẵn từ<br />
Trang web của Microchip. Mã nguồn được bao gồm.<br />
3.1.2 ứng dụng C Mã<br />
Trình biên dịch MPLAB C30 C thư mục cài đặt (C: \ pic30_tools) chứa các<br />
thư mục con với các tập tin thư viện liên quan sau đây:<br />
• lib- dsPIC tập tin thư viện ngoại vi<br />
• src \ peripheral- mã nguồn cho các chức năng thư viện và một tập tin thực thi<br />
để xây dựng lại<br />
thư viện<br />
• tập tin tiêu đề hỗ trợ \ h- cho các thư viện<br />
3.1.3 Tổ chức Chương<br />
Chương này được tổ chức như sau:<br />
• Sử dụng thư viện dsPIC ngoại vi<br />
Chức năng phần mềm<br />
• Chức năng màn hình LCD bên ngoài<br />
Chức năng phần cứng<br />
• Chức năng CAN<br />
• Chức năng ADC12<br />
• Chức năng ADC10<br />
• Chức năng hẹn giờ<br />
• Chức năng lập lại / Control<br />
• I / O Port Chức năng<br />
• Input Capture chức năng<br />
• Đầu ra so sánh chức năng<br />
• Chức năng UART<br />
• Chức năng DCI<br />
• Chức năng SPI<br />
• Chức năng QEI<br />
• Chức năng PWM<br />
• Chức năng I2C
A complex vector of size N/2 must have already been allocated and<br />
assigned to twidFactorsprior to invoking the function. The complex<br />
vector shouldbe allocated in X-Data memory.<br />
Factors computed in floating point arithmetic and converted to 1.15<br />
complex fractionals.<br />
Source File: inittwid.c<br />
Function Profile: System resources usage:<br />
W0..W7 used, not restored<br />
W8..W14 saved, used, restored<br />
DOand REPEATinstruction usage:<br />
None<br />
Program words (24-bit instructions):<br />
See the file “readme.txt” in pic30_tools\src\dsp for this information.<br />
Cycles (including C-function call and return overheads):<br />
See the file “readme.txt” in pic30_tools\src\dsp for this information.<br />
TwidFactorInit (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 72<br />
NOTES:<br />
dsPIC<br />
®LANGUAGE TOOLS<br />
LIBRARIES<br />
2004 Microchip Technology Inc.<br />
2004 Microchip Technology Inc. DS51456B-page 73<br />
Chapter 3. dsPIC Peripheral Libraries<br />
3.1 INTRODUCTION<br />
This chapter documents the functions and macros contained in the dsPIC<br />
peripheral<br />
libraries. Examples of use are also provided.<br />
Code size for each library function or macro may be found in the file<br />
readme.txtin<br />
pic30_tools\src\peripheral.<br />
3.1.1 .Assembly Code Applications<br />
Free versions of these libraries and associated header files are available from the<br />
Microchip web site. Source code is included.<br />
3.1.2 C Code Applications<br />
The MPLAB C30 C compiler install directory (c:\pic30_tools) contains the<br />
following subdirectories with library-related files:<br />
• lib– dsPIC peripheral library files<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 74<br />
2004 Microchip Technology Inc<br />
3.2 SỬ DỤNG THƯ VIỆN dsPIC PERIPHERAL<br />
Xây dựng một ứng dụng mà sử dụng các thư viện ngoại vi dsPIC đòi hỏi một<br />
tập tin thư viện xử lý cụ thể và một tập tin tiêu đề cho mỗi module ngoại vi.<br />
Đối với mỗi thiết bị ngoại vi, phần đầu tập tin tương ứng cung cấp tất cả các<br />
mẫu thử nghiệm chức năng,<br />
#definesand typedefsused bởi thư viện. Các tập tin thư viện lưu trữ có chứa tất<br />
cả các<br />
đối tượng tập tin cá nhân cho mỗi chức năng thư viện.<br />
Các tập tin tiêu đề là của peripheral.h hình thức, nơi ngoại vi = tên của<br />
đặc biệt hữu thiết bị ngoại vi sử dụng (ví dụ, can.hfor CAN).<br />
Các tập tin thư viện có dạng libpDevice-omf.a, nơi thiết bị thiết bị = dsPIC<br />
số lượng (ví dụ, libp30F6014-coff.afor thiết bị dsPIC30F6014.) Xem<br />
Mục 1.2 "Thư viện OMF-cụ thể / khởi động mô-đun" để biết thêm về OMF cụ<br />
thể<br />
thư viện.<br />
Khi biên dịch một ứng dụng, tập tin tiêu đề phải được tham chiếu (sử dụng #<br />
include) bởi<br />
tất cả các file nguồn mà gọi một chức năng trong thư viện hoặc sử dụng các ký<br />
hiệu hoặc typedefs của nó.<br />
Khi kết nối một ứng dụng, tập tin thư viện phải được cung cấp như một đầu vào<br />
để mối liên kết<br />
(Bằng cách sử dụng chuyển đổi -llinker --libraryor) như vậy mà các chức năng<br />
được sử dụng bởi<br />
ứng dụng có thể được kết nối vào ứng dụng.<br />
Các tập tin thực thi makeplib.batmay được sử dụng để làm lại các thư viện. Mặ<br />
định<br />
Hành vi này là để xây dựng thư viện ngoại vi cho tất cả các bộ vi xử lý mục tiêu<br />
hỗ trợ; Tuy nhiên,<br />
bạn có thể chọn một bộ xử lý đặc biệt để xây dựng bằng cách đặt tên nó trên<br />
dòng lệnh. Đối với<br />
Ví dụ:<br />
30f6014 makeplib.bat<br />
hoặc<br />
makeplib.bat 30F6014<br />
sẽ xây dựng thư viện cho các thiết bị dsPIC30F6014.<br />
3.3 CHỨC NĂNG LCD NGOÀI<br />
Phần này bao gồm một danh sách các chức năng riêng biệt để giao tiếp với P-te<br />
PCOG1602B<br />
Bộ điều khiển màn hình LCD và một ví dụ về việc sử dụng các chức năng trong<br />
phần này. Chức năng có thể<br />
được thực hiện như các macro.<br />
Các chức năng màn hình LCD bên ngoài chỉ được hỗ trợ cho các thiết bị sau
• src\peripheral– source code for library functions and a batch file to rebuild<br />
the library<br />
• support\h– header files for libraries<br />
3.1.3 Chapter Organization<br />
This chapter is organized as follows:<br />
• Using the dsPIC Peripheral Libraries<br />
Software Functions<br />
• External LCD Functions<br />
Hardware Functions<br />
• CAN Functions<br />
• ADC12 Functions<br />
• ADC10 Functions<br />
• Timer Functions<br />
• Reset/Control Functions<br />
• I/O Port Functions<br />
• Input Capture Functions<br />
• Output Compare Functions<br />
• UART Functions<br />
• DCI Functions<br />
• SPI Functions<br />
• QEI Functions<br />
• PWM Functions<br />
• I2C Functions<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 74<br />
2004 Microchip Technology Inc.<br />
3.2 USING THE dsPIC PERIPHERAL LIBRARIES<br />
Building an application which utilizes the dsPIC Peripheral Libraries requires a<br />
processor-specific library file and a header file for each peripheral module.<br />
For each peripheral, the corresponding header file provides all the function<br />
prototypes,<br />
#definesand typedefsused by the library. The archived library file contains all<br />
the<br />
individual object files for each library function.<br />
The header files are of the form peripheral.h, where peripheral= name of the<br />
particular peripheral being used (e.g., can.hfor CAN.)<br />
The library files are of the form libpDevice-omf.a, where Device= dsPIC device<br />
number (e.g., libp30F6014-coff.afor the dsPIC30F6014 device.) See<br />
Section 1.2 “OMF-Specific Libraries/StarTup Modules”for more on OMFđây:<br />
• dsPIC30F5011<br />
• dsPIC30F5013<br />
• dsPIC30F6010<br />
• dsPIC30F6011<br />
• dsPIC30F6012<br />
• dsPIC30F6013<br />
• dsPIC30F6014<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 75<br />
3.3.1 Chức năng cá nhân<br />
BusyXLCD<br />
Kiểm tra chức năng này cho cờ bận rộn của P-tec PCOG1602B LCD: Mô tả<br />
điều khiển.<br />
Bao gồm: xlcd.h<br />
Prototype: char BusyXLCD (void);<br />
Lập luận: Không<br />
Quay trở lại giá trị: Nếu "1" được trả lại, nó cho thấy rằng bộ điều khiển màn<br />
hình LCD là bận rộn và không thể<br />
thực hiện bất kỳ lệnh.<br />
Nếu "0" được trả lại, nó chỉ ra rằng màn hình LCD đã sẵn sàng cho lệnh tiếp<br />
theo.<br />
Ghi chú: Chức năng này trả về trạng thái của cờ bận rộn của P-tec<br />
PCOG1602B LCD điều khiển.<br />
Source File: BusyXLCD.c<br />
Mã số Ví dụ: trong khi (BusyXLCD ());<br />
OpenXLCD<br />
Mô tả: Chức năng này cấu hình I / O pins và khởi tạo các P-tec<br />
PCOG1602B LCD điều khiển.<br />
Bao gồm: xlcd.h<br />
Prototype: void OpenXLCD (unsigned char lcdtype);<br />
Đối số: lcdtype này chứa các thông số điều khiển LCD được<br />
cấu hình như dưới đây:<br />
Loại giao diện<br />
FOUR_BIT<br />
EIGHT_BIT<br />
Số dòng<br />
SINGLE_LINE<br />
TWO_LINE<br />
Phân khúc hướng truyền dữ liệu
specific<br />
libraries.<br />
When compiling an application, header file must be referenced (using #include)<br />
by<br />
all source files which call a function in the library or use its symbols or<br />
typedefs.<br />
When linking an application, the library file must be provided as an input to the<br />
linker<br />
(using the --libraryor -llinker switch) such that the functions used by the<br />
application may be linked into the application.<br />
The batch file makeplib.batmay be used to remake the libraries. The default<br />
behavior is to build peripheral libraries for all supported target processors;<br />
however,<br />
you may select a particular processor to build by naming it on the command<br />
line. For<br />
example:<br />
makeplib.bat 30f6014<br />
or<br />
makeplib.bat 30F6014<br />
will rebuild the library for the dsPIC30F6014 device.<br />
3.3 EXTERNAL LCD FUNCTIONS<br />
This section contains a list of individual functions for interfacing with P-tec<br />
PCOG1602B<br />
LCD controller and an example of use of the functions in this section. Functions<br />
may<br />
be implemented as macros.<br />
The external LCD functions are only supported for the following devices:<br />
• dsPIC30F5011<br />
• dsPIC30F5013<br />
• dsPIC30F6010<br />
• dsPIC30F6011<br />
• dsPIC30F6012<br />
• dsPIC30F6013<br />
• dsPIC30F6014<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 75<br />
3.3.1 Individual Functions<br />
BusyXLCD<br />
Description: This function checks for the busy flag of the P-tec PCOG1602B<br />
LCD<br />
controller.<br />
Include: xlcd.h<br />
Prototype: char BusyXLCD(void);<br />
SEG1_50_SEG51_100<br />
SEG1_50_SEG100_51<br />
SEG100_51_SEG50_1<br />
SEG100_51_SEG1_50<br />
COM truyền dữ liệu hướng<br />
COM1_COM16<br />
COM16_COM1<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này cấu hình các chân I / O dùng để điều khiển P-tec<br />
PCOG1602B LCD điều khiển. Nó cũng khởi tạo controller.The LCD<br />
I / O pin định nghĩa đó phải được thực hiện để đảm bảo rằng màn hình LCD bê<br />
ngoài<br />
hoạt động chính xác là:<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 76<br />
Điều khiển I / O pin định nghĩa<br />
RW_PIN PORTxbits.Rx?<br />
TRIS_RW TRISxbits.Rx?<br />
RS_PIN PORTxbits.Rx?<br />
TRIS_RS TRISxbits.Rx?<br />
E_PIN PORTxbits.Rx?<br />
TRIS_E TRISxbits.Rx?<br />
nơi XIS các PORT,? là số pin<br />
Pin định nghĩa dữ liệu<br />
DATA_PIN_? PORTxbits.RD?<br />
2004 Microchip Technology Inc<br />
TRIS_DATA_PIN_? TRISxbits.TRISD?<br />
nơi XIS các PORT,? là số pin<br />
Các chân dữ liệu có thể từ một trong hai cảng hoặc từ nhiều cổng.<br />
Các chân điều khiển có thể được trên bất kỳ cổng và không phải để được vào<br />
cùng một cổng. Giao diện dữ liệu phải được xác định là 4-bit hoặc 8-bit.<br />
Giao diện 8-bit được định nghĩa khi một<br />
# xác định EIGHT_BIT_INTERFACE được bao gồm trong các tập tin tiêu đề<br />
xlcd.h. Nếu không xác định được bao gồm, thenthe giao diện 4-bit được bao<br />
gồm.<br />
Sau khi các định nghĩa này đã được thực hiện, người dùng phải biên dịch<br />
mã ứng dụng vào một đối tượng được liên kết.<br />
Chức năng này cũng đòi hỏi phải có ba thói quen bên ngoài cho sự chậm trễ cụ<br />
thể:<br />
DelayFor18TCY () 18 Tcy chậm trễ
Arguments: None<br />
Return Value: If ‘1’ is returned, it indicates that the LCD controller is busy and<br />
can not<br />
take any command.<br />
If ‘0’ is returned, it indicates that the LCD is ready for next command.<br />
Remarks: This function returns the status of the busy flag of the P-tec<br />
PCOG1602B LCD controller.<br />
Source File: BusyXLCD.c<br />
Code Example: while(BusyXLCD());<br />
OpenXLCD<br />
Description: This function configures the I/O pins and initializes the P-tec<br />
PCOG1602B LCD controller.<br />
Include: xlcd.h<br />
Prototype: void OpenXLCD (unsigned char lcdtype);<br />
Arguments: lcdtype This contains the LCD controller parameters to be<br />
configured as defined below:<br />
Type of interface<br />
FOUR_BIT<br />
EIGHT_BIT<br />
Number of lines<br />
SINGLE_LINE<br />
TWO_LINE<br />
Segment data transfer direction<br />
SEG1_50_SEG51_100<br />
SEG1_50_SEG100_51<br />
SEG100_51_SEG50_1<br />
SEG100_51_SEG1_50<br />
COM data transfer direction<br />
COM1_COM16<br />
COM16_COM1<br />
Return Value: None<br />
Remarks: This function configures the I/O pins used to control the P-tec<br />
PCOG1602B LCD controller. It also initializes the LCD controller.The<br />
I/O pin definitions that must be made to ensure that the external LCD<br />
operates correctly are:<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 76<br />
2004 Microchip Technology Inc.<br />
DelayPORXLCD () chậm trễ 15ms<br />
DelayXLCD () 5ms chậm trễ<br />
Delay100XLCD () 100Tcy chậm trễ<br />
Source File: openXLCD.c<br />
Mã số Ví dụ: OpenXLCD (EIGHT_BIT & TWO_LINE<br />
& SEG1_50_SEG51_100 & COM1_COM16);<br />
putsXLCD<br />
putrsXLCD<br />
Mô tả: Chức năng này ghi một chuỗi ký tự cho PCOG1602B P-tec<br />
LCD điều khiển.<br />
Bao gồm: xlcd.h<br />
Prototype: void putsXLCD (char * buffer);<br />
làm mất hiệu lực putrsXLCD (char rom const * đệm);<br />
Đối số: đệm Con trỏ trỏ tới các nhân vật để bewritten với bộ điều khiển màn<br />
hình LCD.<br />
Trở lại giá trị: Không<br />
Ghi chú: Các chức năng viết một chuỗi ký tự nằm trong các bufferto<br />
P-tec PCOG1602B LCD điều khiển cho đến khi một nhân vật NULL là gặp<br />
phải<br />
trong chuỗi.<br />
Đối với màn hình hiển thị liên tục của dữ liệu bằng văn bản cho P-tec<br />
PCOG1602B LCD<br />
điều khiển, bạn có thể thiết lập màn hình hiển thị trong một chế độ Shift.<br />
Source File: PutsXLCD.c<br />
PutrsXLCD.c<br />
Mã số Ví dụ: char display_char [13];<br />
putsXLCD (display_char);<br />
OpenXLCD (Tiếp theo)<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 77<br />
ReadAddrXLCD<br />
Mô tả: Chức năng này đọc các byte địa chỉ từ P-tec PCOG1602B LCD<br />
điều khiển.<br />
Bao gồm: xlcd.h<br />
Prototype: unsigned char ReadAddrXLCD (void);<br />
Lập luận: Không<br />
Trở lại giá trị: Chức năng này trả về một 8-bit là địa chỉ 7-bit ở phía dưới<br />
7 bit của byte và cờ BUSYstatus trong bit thứ 8.<br />
Ghi chú: Chức năng này đọc các byte địa chỉ từ P-tec PCOG1602B LCD<br />
điều khiển. Người dùng đầu tiên phải kiểm tra xem nếu bộ điều khiển màn hình<br />
LCD đang bận
Control I/O pin definitions<br />
RW_PIN PORTxbits.Rx?<br />
TRIS_RW TRISxbits.Rx?<br />
RS_PIN PORTxbits.Rx?<br />
TRIS_RS TRISxbits.Rx?<br />
E_PIN PORTxbits.Rx?<br />
TRIS_E TRISxbits.Rx?<br />
where xis the PORT, ?is the pin number<br />
Data pin definitions<br />
DATA_PIN_? PORTxbits.RD?<br />
TRIS_DATA_PIN_? TRISxbits.TRISD?<br />
where xis the PORT, ?is the pin number<br />
The Data pins can be from either one port or from multiple ports.<br />
The control pins can be on any port and are not required to be on the<br />
same port. The data interface must be defined as either 4-bit or 8-bit.<br />
The 8-bit interface is defined when a<br />
#define EIGHT_BIT_INTERFACE is included in the header file<br />
xlcd.h. If no define is included, thenthe 4-bit interface is included.<br />
After these definitions have been made, the user must compile the<br />
application code into an object to be linked.<br />
This function also requires three external routines for specific delays:<br />
DelayFor18TCY() 18 Tcy delay<br />
DelayPORXLCD() 15ms delay<br />
DelayXLCD() 5ms delay<br />
Delay100XLCD() 100Tcy delay<br />
Source File: openXLCD.c<br />
Code Example: OpenXLCD(EIGHT_BIT &TWO_LINE<br />
& SEG1_50_SEG51_100 &COM1_COM16);<br />
putsXLCD<br />
bằng cách gọi BusyXLCD () chức năng.<br />
Địa chỉ đọc từ bộ điều khiển cho máy phát điện nhân vật<br />
RAM hoặc bộ nhớ RAM hiển thị dữ liệu tùy thuộc vào trước<br />
Đặt ?? RamAddr () chức năng được gọi là nơi ?? có thể quản trị hoặc<br />
DD.<br />
Source File: ReadAddrXLCD.c<br />
Mã số Ví dụ: địa chỉ char;<br />
trong khi (BusyXLCD ());<br />
địa chỉ = ReadAddrXLCD ();<br />
ReadDataXLCD<br />
Mô tả: Chức năng này đọc một dữ liệu bytefrom P-tec PCOG1602B LCD<br />
điều khiển.<br />
Bao gồm: xlcd.h<br />
Prototype: char ReadDataXLCD (void);<br />
Lập luận: Không<br />
Ghi chú: Chức năng này đọc một dữ liệu bytefrom P-tec PCOG1602B LCD<br />
điều khiển. Người dùng đầu tiên phải kiểm tra xem nếu bộ điều khiển màn hình<br />
LCD đang bận<br />
bằng cách gọi BusyXLCD () chức năng.<br />
Đọc dữ liệu từ bộ điều khiển là cho RAM máy phát điện nhân vật hoặc<br />
RAM hiển thị dữ liệu tùy thuộc vào trước Set ?? RamAddr ()<br />
chức năng được gọi là nơi ?? hoặc là CG hay DD.<br />
Trở lại giá trị: Chức năng này trả về giá trị dữ liệu 8-bit chỉ bởi địa chỉ.<br />
Source File: ReadDataXLCD.c<br />
Mã số Ví dụ: char dữ liệu;<br />
trong khi (BusyXLCD ());<br />
dữ liệu = ReadDataXLCD ();<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
putrsXLCD<br />
Description: This function writes a string of characters to the P-tec PCOG1602B<br />
DS51456B trang 78<br />
SetCGRamAddr<br />
2004 Microchip Technology Inc<br />
LCD controller.<br />
Include: xlcd.h<br />
Prototype: void putsXLCD (char *buffer);<br />
void putrsXLCD (const rom char *buffer);<br />
Arguments: buffer Pointer to the characters to bewritten to the LCD controller.<br />
Return Value: None<br />
Remarks: These functions write a string of characters located in bufferto the<br />
P-tec PCOG1602B LCD controller till a NULL character is encountered<br />
Mô tả: Chức năng này đặt địa chỉ máy phát điện nhân vật.<br />
Bao gồm: xlcd.h<br />
Prototype: void SetCGRamAddr (unsigned char CGaddr);<br />
Đối số: CGaddr địa chỉ máy phát điện nhân vật.<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này đặt địa chỉ máy phát điện nhân vật của P-tec<br />
PCOG1602B LCD điều khiển. Người dùng đầu tiên phải kiểm tra xem nếu<br />
điều khiển là bận rộn bằng cách gọi BusyXLCD () chức năng.
in the string.<br />
For continuous display of data written to the P-tec PCOG1602B LCD<br />
controller, you could set up the display in a Shift mode.<br />
Source File: PutsXLCD.c<br />
PutrsXLCD.c<br />
Code Example: char display_char[13];<br />
putsXLCD(display_char);<br />
OpenXLCD (Continued)<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 77<br />
ReadAddrXLCD<br />
Description: This function reads the address byte from the P-tec PCOG1602B<br />
LCD<br />
controller.<br />
Include: xlcd.h<br />
Prototype: unsigned char ReadAddrXLCD (void);<br />
Arguments: None<br />
Return Value: This function returns an 8-bit which is the 7-bit address in the<br />
lower<br />
7 bits of the byte and the BUSYstatus flag in the 8th bit.<br />
Remarks: This function reads the address byte from the P-tec PCOG1602B<br />
LCD<br />
controller. The user must first check to see if the LCD controller is busy<br />
by calling the BusyXLCD()function.<br />
The address read from the controller is for the character generator<br />
RAM or the display data RAM depending on the previous<br />
Set??RamAddr()function that was called where ?? can be CG or<br />
DD.<br />
Source File: ReadAddrXLCD.c<br />
Code Example: char address;<br />
while(BusyXLCD());<br />
address = ReadAddrXLCD();<br />
ReadDataXLCD<br />
Description: This function reads a data bytefrom the P-tec PCOG1602B LCD<br />
controller.<br />
Include: xlcd.h<br />
Prototype: char ReadDataXLCD (void);<br />
Arguments: None<br />
Remarks: This function reads a data bytefrom the P-tec PCOG1602B LCD<br />
controller. The user must first check to see if the LCD controller is busy<br />
Source File: SetCGRamAddr.c<br />
Mã số Ví dụ: char cgaddr = 0x1f;<br />
trong khi (BusyXLCD ());<br />
SetCGRamAddr (cgaddr);<br />
SetDDRamAddr<br />
Mô tả: Chức năng này đặt địa chỉ hiển thị dữ liệu.<br />
Bao gồm: xlcd.h<br />
Prototype: void SetDDRamAddr (unsigned char DDaddr);<br />
Đối số: DDaddr địa chỉ dữ liệu hiển thị.<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này đặt dataaddress hiển thị của PCOG1602B P-tec<br />
LCD điều khiển. Người dùng đầu tiên phải kiểm tra xem nếu bộ điều khiển là<br />
bận rộn<br />
bằng cách gọi BusyXLCD () chức năng.<br />
Source File: SetDDRamAddr.c<br />
Mã số Ví dụ: char ddaddr = 0x10;<br />
trong khi (BusyXLCD ());<br />
SetDDRamAddr (ddaddr);<br />
WriteDataXLCD<br />
Mô tả: Chức năng này ghi một byte dữ liệu (một nhân vật) từ P-tec<br />
PCOG1602B LCD điều khiển.<br />
Bao gồm: xlcd.h<br />
Prototype: void WriteDataXLCD (dữ liệu char);<br />
Đối số: dữ liệu Giá trị của datacan được bất kỳ giá trị 8-bit, nhưng nên<br />
tương ứng với các bảng tính RAM của P-tec<br />
PCOG1602B LCD điều khiển.<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này ghi một dữ liệu byteto P-tec PCOG1602B LCD<br />
điều khiển. Người dùng đầu tiên phải kiểm tra xem nếu bộ điều khiển màn hình<br />
LCD đang bận<br />
bằng cách gọi BusyXLCD () chức năng.<br />
Đọc dữ liệu từ bộ điều khiển là cho RAM máy phát điện nhân vật hoặc<br />
RAM hiển thị dữ liệu tùy thuộc vào trước Set ?? RamAddr ()<br />
chức năng được gọi là nơi ?? đề cập đến một trong hai CG hoặc DD.<br />
Source File: WriteDataXLCD.c<br />
Mã số Ví dụ: WriteDataXLCD (0x30);<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 79<br />
WriteCmdXLCD<br />
Mô tả: Chức năng này ghi một commandto P-tec PCOG1602B LCD
y calling the BusyXLCD()function.<br />
The data read from the controller is for the character generator RAM or<br />
the display data RAM depending on the previous Set??RamAddr()<br />
function that was called where ?? is either CG or DD.<br />
Return Value: This function returns the 8-bit data value pointed by the address.<br />
Source File: ReadDataXLCD.c<br />
Code Example: char data;<br />
while (BusyXLCD());<br />
data = ReadDataXLCD();<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
điều khiển.<br />
Bao gồm: xlcd.h<br />
Prototype: void WriteCmdXLCD (unsigned char cmd);<br />
Đối số: cmd này chứa các thông số điều khiển màn hình LCD được cấu hình<br />
như<br />
quy định dưới đây:<br />
Loại giao diện<br />
FOUR_BIT<br />
EIGHT_BIT<br />
Số dòng<br />
SINLE_LINE<br />
TWO_LINE<br />
Phân khúc hướng truyền dữ liệu<br />
DS51456B-page 78<br />
SetCGRamAddr<br />
2004 Microchip Technology Inc.<br />
SEG1_50_SEG51_100<br />
SEG1_50_SEG100_51<br />
Description: This function sets the character generator address.<br />
Include: xlcd.h<br />
Prototype: void SetCGRamAddr(unsigned char CGaddr);<br />
Arguments: CGaddr Character generator address.<br />
Return Value: None<br />
Remarks: This function sets the character generator address of the P-tec<br />
PCOG1602B LCD controller. The user must first check to see if the<br />
controller is busy by calling the BusyXLCD()function.<br />
Source File: SetCGRamAddr.c<br />
Code Example: char cgaddr = 0x1F;<br />
while (BusyXLCD());<br />
SetCGRamAddr(cgaddr);<br />
SetDDRamAddr<br />
Description: This function sets the display data address.<br />
Include: xlcd.h<br />
Prototype: void SetDDRamAddr(unsigned char DDaddr);<br />
Arguments: DDaddr Display data address.<br />
Return Value: None<br />
Remarks: This function sets the display dataaddress of the P-tec PCOG1602B<br />
LCD controller. The user must first check to see if the controller is busy<br />
by calling the BusyXLCD()function.<br />
Source File: SetDDRamAddr.c<br />
Code Example: char ddaddr = 0x10;<br />
while (BusyXLCD());<br />
SetDDRamAddr(ddaddr);<br />
SEG100_51_SEG50_1<br />
SEG100_51_SEG1_50<br />
COM truyền dữ liệu hướng<br />
COM1_COM16<br />
COM16_COM1<br />
Hiển thị On / Off kiểm soát<br />
DON<br />
Lột nón<br />
CURSOR_ON<br />
CURSOR_OFF<br />
BLINK_ON<br />
BLINK_OFF<br />
Con trỏ hoặc hiển thị định nghĩa phím Shift<br />
SHIFT_CUR_LEFT<br />
SHIFT_CUR_RIGHT<br />
SHIFT_DISP_LEFT<br />
SHIFT_DISP_RIGHT<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này viết các byte lệnh cho P-tec PCOG1602B LCD<br />
điều khiển. Người dùng đầu tiên phải kiểm tra xem nếu bộ điều khiển màn hình<br />
LCD đang bận<br />
bằng cách gọi BusyXLCD () chức năng.<br />
Source File: WriteCmdXLCD.c<br />
Mã số Ví dụ: trong khi (BusyXLCD ());<br />
WriteCmdXLCD (EIGHT_BIT & TWO_LINE);
WriteDataXLCD<br />
Description: This function writes a data byte (one character) from the P-tec<br />
PCOG1602B LCD controller.<br />
Include: xlcd.h<br />
Prototype: void WriteDataXLCD (char data);<br />
Arguments: data The value of datacan be any 8-bit value, but should<br />
correspond to the character RAM table of the P-tec<br />
PCOG1602B LCD controller.<br />
Return Value: None<br />
Remarks: This function writes a data byteto the P-tec PCOG1602B LCD<br />
controller. The user must first check to see if the LCD controller is busy<br />
by calling the BusyXLCD()function.<br />
The data read from the controller is for the character generator RAM or<br />
the display data RAM depending on the previous Set??RamAddr()<br />
function that was called where ??refers to either CG or DD.<br />
Source File: WriteDataXLCD.c<br />
Code Example: WriteDataXLCD(0x30);<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 79<br />
WriteCmdXLCD<br />
Description: This function writes a commandto the P-tec PCOG1602B LCD<br />
controller.<br />
Include: xlcd.h<br />
Prototype: void WriteCmdXLCD (unsigned char cmd);<br />
Arguments: cmd This contains the LCD controller parameters to be configured<br />
as<br />
defined below:<br />
Type of interface<br />
FOUR_BIT<br />
EIGHT_BIT<br />
Number of lines<br />
SINLE_LINE<br />
TWO_LINE<br />
Segment data transfer direction<br />
SEG1_50_SEG51_100<br />
SEG1_50_SEG100_51<br />
SEG100_51_SEG50_1<br />
SEG100_51_SEG1_50<br />
COM data transfer direction<br />
WriteCmdXLCD (DON);<br />
WriteCmdXLCD (SHIFT_DISP_LEFT);<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 80 2004 Microchip Technology Inc<br />
3.3.2 Ví dụ về sử dụng<br />
# xác định __dsPIC30F6014__<br />
# include<br />
# include<br />
/ * Giữ địa chỉ của tin nhắn * /<br />
char * buffer;<br />
dữ liệu char;<br />
mesg1 char [] = {'H', 'A', 'R', 'D', 'W', 'A', 'R', 'E', '\ 0'};<br />
mesg2 char [] = {'P', 'E', 'R', 'tôi', 'P', 'H', 'E', 'R', 'A', 'L'<br />
'', 'L', 'tôi', 'B', '', '\ 0'};<br />
int main (void)<br />
{<br />
/ * Giao diện Set 8 bit và hai màn hình hiển thị dòng * /<br />
OpenXLCD (EIGHT_BIT & TWO_LINE & SEG1_50_SEG51_100<br />
& COM1_COM16);<br />
/ * Chờ cho đến khi bộ điều khiển màn hình LCD đang bận rộn * /<br />
trong khi (BusyXLCD ());<br />
/ * Bật màn hình * /<br />
WriteCmdXLCD (DON & CURSOR_ON & BLINK_OFF);<br />
đệm = mesg1;<br />
PutsXLCD (đệm);<br />
trong khi (BusyXLCD ());<br />
/ * Thiết lập địa chỉ DDRAM đến 0x40 để dispaly dữ liệu trong dòng thứ hai *<br />
SetDDRamAddr (0x40);<br />
trong khi (BusyXLCD ());<br />
đệm = mesg2;<br />
PutsXLCD (đệm);<br />
trong khi (BusyXLCD ());<br />
trở về 0;<br />
}<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 81<br />
3.4 chức năng CAN<br />
Phần này bao gồm một danh sách các chức năng riêng biệt cho CAN và một ví
COM1_COM16<br />
COM16_COM1<br />
Display On/Off control<br />
DON<br />
DOFF<br />
CURSOR_ON<br />
CURSOR_OFF<br />
BLINK_ON<br />
BLINK_OFF<br />
Cursor or Display Shift defines<br />
SHIFT_CUR_LEFT<br />
SHIFT_CUR_RIGHT<br />
SHIFT_DISP_LEFT<br />
SHIFT_DISP_RIGHT<br />
Return Value: None<br />
Remarks: This function writes the command byte to the P-tec PCOG1602B<br />
LCD<br />
controller. The user must first check to see if the LCD controller is busy<br />
by calling the BusyXLCD() function.<br />
Source File: WriteCmdXLCD.c<br />
Code Example: while(BusyXLCD());<br />
WriteCmdXLCD(EIGHT_BIT & TWO_LINE);<br />
WriteCmdXLCD(DON);<br />
WriteCmdXLCD(SHIFT_DISP_LEFT);<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 80<br />
3.3.2 Example of Use<br />
#define __dsPIC30F6014__<br />
#include <br />
#include<br />
/* holds the address of message */<br />
char * buffer;<br />
char data ;<br />
2004 Microchip Technology Inc.<br />
char mesg1[] = {'H','A','R','D','W','A','R','E','\0'};<br />
char mesg2[] = {'P','E','R','I','P’,’H’,’E’,’R’,’A’,’L’<br />
dụ về việc sử dụng<br />
chức năng. Chức năng có thể được thực hiện như các macro.<br />
3.4.1 Chức năng cá nhân<br />
CAN1AbortAll<br />
CAN2AbortAll<br />
Mô tả: Chức năng này khởi hủy bỏ ofall các truyền cấp phát.<br />
Bao gồm: can.h<br />
Prototype: void CAN1AbortAll (void);<br />
làm mất hiệu lực CAN2AbortAll (void);<br />
Lập luận: Không<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này đặt bit ABAT trong CiCTRL đăng ký do đó việc bắt<br />
đầu<br />
hủy bỏ tất cả các truyền cấp phát. Tuy nhiên, việc truyền tải là<br />
đã được tiến hành sẽ không được hủy bỏ. Bit này được xóa bởi<br />
phần cứng khi truyền thông đã thành công<br />
hủy bỏ.<br />
Source File: CAN1AbortAll.c<br />
CAN2AbortAll.c<br />
Mã số Ví dụ: CAN1AbortAll ();<br />
CAN1GetRXErrorCount<br />
CAN2GetRXErrorCount<br />
Mô tả: Chức năng này trả về giá trị nhận được số lỗi.<br />
Bao gồm: can.h<br />
Prototype: unsigned char CAN1GetRXErrorCount (void);<br />
unsigned char CAN2GetRXErrorCount (void);<br />
Lập luận: Không<br />
Quay trở lại giá trị: nội dung của CiRERRCNT, đó là 8 bit.<br />
Bình luận: Chức năng này trả về nội dung của CiRERRCNT (byte thấp của<br />
CIEC<br />
đăng ký) mà chỉ ra được lỗi đếm.<br />
Source File: CAN1GetRXErrorCount.c<br />
CAN2GetRXErrorCount.c<br />
Mã số Ví dụ: unsigned char rx_error_count;<br />
rx_error_count = CAN1GetRXErrorCount ();<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
‘ ‘, ‘L’,’I’,’B’,’ ‘,'\0'};<br />
DS51456B trang 82<br />
2004 Microchip Technology Inc<br />
int main(void)<br />
CAN1GetTXErrorCount
{<br />
/* Set 8bit interface and two line display */<br />
OpenXLCD(EIGHT_BIT & TWO_LINE & SEG1_50_SEG51_100<br />
& COM1_COM16);<br />
/* Wait till LCD controller is busy */<br />
while(BusyXLCD());<br />
/* Turn on the display */<br />
WriteCmdXLCD(DON & CURSOR_ON & BLINK_OFF);<br />
buffer = mesg1;<br />
PutsXLCD(buffer);<br />
while(BusyXLCD());<br />
/* Set DDRam address to 0x40 to dispaly data in the second line */<br />
SetDDRamAddr(0x40);<br />
while(BusyXLCD());<br />
buffer = mesg2;<br />
PutsXLCD(buffer);<br />
while(BusyXLCD());<br />
return 0;<br />
}<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 81<br />
3.4 CAN FUNCTIONS<br />
This section contains a list of individual functions for CAN and an example of<br />
use of the<br />
functions. Functions may be implemented as macros.<br />
3.4.1 Individual Functions<br />
CAN1AbortAll<br />
CAN2AbortAll<br />
Description: This function initiates abort ofall the pending transmissions.<br />
Include: can.h<br />
Prototype: void CAN1AbortAll(void);<br />
void CAN2AbortAll(void);<br />
Arguments: None<br />
Return Value: None<br />
Remarks: This function sets the ABAT bit in CiCTRL register thus initiating the<br />
abort of all pending transmission. However, the transmission which is<br />
already in progress will not be aborted. This bit gets cleared by<br />
hardware when the message transmission has been succesfully<br />
aborted.<br />
CAN2GetTXErrorCount<br />
Mô tả: Chức năng này trả về giá trị số lỗi truyền.<br />
Bao gồm: can.h<br />
Prototype: unsigned char CAN1GetTXErrorCount (void);<br />
unsigned char CAN2GetTXErrorCount (void);<br />
Lập luận: Không<br />
Quay trở lại giá trị: nội dung của CiTERRCNT, đó là 8 bit.<br />
Bình luận: Chức năng này trả về nội dung của CiTERRCNT (byte trên của<br />
CIEC<br />
đăng ký) mà chỉ ra số lượng lỗi phát.<br />
Source File: CAN1GetTXErrorCount.c<br />
CAN2GetTXErrorCount.c<br />
Mã số Ví dụ: unsigned char tx_error_count;<br />
tx_error_count = CAN1GetTXErrorCount ();<br />
CAN1IsBusOff<br />
CAN2IsBusOff<br />
Mô tả: Chức năng này xác định liệu các nút CAN đang ở chế độ BusOff.<br />
Bao gồm: can.h<br />
Prototype: char CAN1IsBusOff (void);<br />
char CAN2IsBusOff (void);<br />
Lập luận: Không<br />
Quay trở lại giá trị: Nếu giá trị của TXBO là "1", sau đó "1" được trả lại, chỉ ra<br />
rằng các xe buýt<br />
đã bị tắt do lỗi trong truyền tải.<br />
Nếu giá trị của TXBO là "0", sau đó "0" được trả lại, chỉ ra rằng các xe buýt<br />
không được tắt.<br />
Ghi chú: Chức năng này trả về tình trạng ofthe TXBO chút CiINTF đăng ký.<br />
Source File: CAN1IsBusOff.c<br />
CAN2IsBusOff.c<br />
Mã số Ví dụ: trong khi (CAN1IsBusOff ());<br />
CAN1IsRXReady<br />
CAN2IsRXReady<br />
Mô tả: Chức năng này trả về tình trạng bộ đệm nhận đầy đủ.<br />
Bao gồm: can.h<br />
Prototype: char CAN1IsRXReady (char);<br />
CAN2IsRXReady char (char);<br />
Đối số: buffno Giá trị của buffno cho bộ đệm nhận có tình trạng<br />
được yêu cầu.<br />
Quay trở lại giá trị: Nếu RXFUL là 1, nó chỉ ra rằng bộ đệm nhận có chứa một<br />
đã nhận<br />
tin nhắn.
Source File: CAN1AbortAll.c<br />
CAN2AbortAll.c<br />
Code Example: CAN1AbortAll();<br />
CAN1GetRXErrorCount<br />
CAN2GetRXErrorCount<br />
Description: This function returns the receive error count value.<br />
Include: can.h<br />
Prototype: unsigned char CAN1GetRXErrorCount(void);<br />
unsigned char CAN2GetRXErrorCount(void);<br />
Arguments: None<br />
Return Value: contents of CiRERRCNT, which is 8 bits.<br />
Remarks: This function returns the contents of CiRERRCNT (lower byte of<br />
CiEC<br />
register) which indicates the receive error count.<br />
Source File: CAN1GetRXErrorCount.c<br />
CAN2GetRXErrorCount.c<br />
Code Example: unsigned char rx_error_count;<br />
rx_error_count = CAN1GetRXErrorCount();<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 82<br />
CAN1GetTXErrorCount<br />
CAN2GetTXErrorCount<br />
2004 Microchip Technology Inc.<br />
Description: This function returns the transmit error count value.<br />
Include: can.h<br />
Prototype: unsigned char CAN1GetTXErrorCount(void);<br />
unsigned char CAN2GetTXErrorCount(void);<br />
Arguments: None<br />
Return Value: contents of CiTERRCNT, which is 8 bits.<br />
Remarks: This function returns the contents of CiTERRCNT (upper byte of<br />
CiEC<br />
register) which indicates the transmit error count.<br />
Source File: CAN1GetTXErrorCount.c<br />
CAN2GetTXErrorCount.c<br />
Code Example: unsigned char tx_error_count;<br />
tx_error_count = CAN1GetTXErrorCount();<br />
CAN1IsBusOff<br />
CAN2IsBusOff<br />
Description: This function determines whether the CAN node is in BusOff<br />
Nếu RXFUL là 0, nó chỉ ra rằng bộ đệm nhận được mở cửa để nhận<br />
tin nhắn mới.<br />
Ghi chú: Chức năng này trả về tình trạng ofthe bit RXFUL của Nhận kiểm soát<br />
đăng ký.<br />
Source File: CAN1IsRXReady.c<br />
CAN2IsRXReady.c<br />
Mã số Ví dụ: char rx_1_status;<br />
rx_1_status = CAN1IsRXReady (1);<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 83<br />
CAN1IsRXPassive<br />
CAN2IsRXPassive<br />
Mô tả: Chức năng này xác định nếu người nhận là lỗi nhà nước thụ động.<br />
Bao gồm: can.h<br />
Prototype: char CAN1IsRXPassive (void);<br />
char CAN2IsRXPassive (void);<br />
Lập luận: Không<br />
Quay trở lại giá trị: Nếu giá trị của RXEP là "1", sau đó "1" được trả lại, chỉ ra<br />
các nút<br />
sẽ bị động do lỗi trong tiếp nhận.<br />
Nếu giá trị của RXEP là "0", sau đó "0" được trả lại, cho thấy không có lỗi trên<br />
xe buýt.<br />
Ghi chú: Chức năng này trả về tình trạng ofthe RXEP chút CiINTF đăng ký.<br />
Source File: CAN1IsRXPassive.c<br />
CAN2IsRXPassive.c<br />
Mã số Ví dụ: char rx_bus_status;<br />
rx_bus_status = CAN1IsRXPassive ();<br />
CAN1IsTXPassive<br />
CAN2IsTXPassive<br />
Mô tả: Chức năng này xác định nếu phát là lỗi nhà nước thụ động.<br />
Bao gồm: can.h<br />
Prototype: char CAN1IsTXPassive (void);<br />
char CAN2IsTXPassive (void);<br />
Lập luận: Không<br />
Quay trở lại giá trị: Nếu giá trị của TXEP là "1", sau đó "1" được trả lại, cho<br />
thấy lỗi trên<br />
chuyển xe buýt và xe buýt sẽ bị động.<br />
Nếu giá trị của TXEP là "0", sau đó "0" được trả lại, cho thấy không có lỗi trên<br />
chuyển xe buýt.<br />
Ghi chú: Chức năng này trả về trạng thái của bit TXEP của CiINTF đăng ký.
mode.<br />
Include: can.h<br />
Prototype: char CAN1IsBusOff(void);<br />
char CAN2IsBusOff(void);<br />
Arguments: None<br />
Return Value: If the value of TXBO is ‘1’, then ‘1’ is returned, indicating that<br />
the bus<br />
has been turned off due to error in transmission.<br />
If the value of TXBO is ‘0’, then ‘0’ is returned, indicating that the bus<br />
not been turned off.<br />
Remarks: This function returns the status ofthe TXBO bit of CiINTF register.<br />
Source File: CAN1IsBusOff.c<br />
CAN2IsBusOff.c<br />
Code Example: while(CAN1IsBusOff());<br />
CAN1IsRXReady<br />
CAN2IsRXReady<br />
Description: This function returns the receive buffer full status.<br />
Include: can.h<br />
Prototype: char CAN1IsRXReady(char);<br />
char CAN2IsRXReady(char);<br />
Arguments: buffno The value of buffno indicates the receive buffer whose<br />
status<br />
is required.<br />
Return Value: If RXFUL is 1, it indicates that the receive buffer contains a<br />
received<br />
message.<br />
If RXFUL is 0, it indicates that the receive buffer is open to receive a<br />
new message.<br />
Remarks: This function returns the status ofthe RXFUL bit of Receive Control<br />
register.<br />
Source File: CAN1IsRXReady.c<br />
CAN2IsRXReady.c<br />
Code Example: char rx_1_status;<br />
rx_1_status = CAN1IsRXReady(1);<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 83<br />
CAN1IsRXPassive<br />
CAN2IsRXPassive<br />
Description: This function determines if the receiver is in Error Passive state.<br />
Include: can.h<br />
Prototype: char CAN1IsRXPassive(void);<br />
Source File: CAN1IsTXPassive.c<br />
CAN2IsTXPassive.c<br />
Mã số Ví dụ: char tx_bus_status;<br />
tx_bus_status = CAN1IsTXPassive ();<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 84<br />
CAN1IsTXReady<br />
CAN2IsTXReady<br />
2004 Microchip Technology Inc<br />
Mô tả: Chức năng này trả về tình trạng phát cho thấy nếu nút CAN<br />
sẵn sàng để truyền tiếp theo.<br />
Bao gồm: can.h<br />
Prototype: char CAN1IsTXReady (char);<br />
CAN2IsTXReady char (char);<br />
Đối số: buffno Giá trị của buffno cho bộ đệm truyền có<br />
tình trạng là bắt buộc.<br />
Quay trở lại giá trị: Nếu TXREQ là "1", nó sẽ trả về "0" chỉ ra rằng bộ đệm<br />
truyền không phải là<br />
sản phẩm nào.<br />
Nếu TXREQ là "0", nó sẽ trả về "1" chỉ ra rằng bộ đệm truyền rỗng<br />
và máy phát đã sẵn sàng để truyền tiếp theo.<br />
Ghi chú: Chức năng này trả về complimentof bit TXREQ Tình trạng trong<br />
Truyền đăng ký kiểm soát.<br />
Source File: CAN1IsTXReady.c<br />
CAN2IsTXReady.c<br />
Mã số Ví dụ: char tx_2_status;<br />
tx_2_status = CAN1IsTXReady (2);<br />
CAN1ReceiveMessage<br />
CAN2ReceiveMessage<br />
Mô tả: Chức năng này đọc dữ liệu từ bộ đệm nhận.<br />
Bao gồm: can.h<br />
Prototype: void CAN1ReceiveMessage (unsigned char *<br />
dữ liệu, datalen unsigned char, char MsgFlag);<br />
khoảng trống CAN2ReceiveMessage (unsigned char *<br />
dữ liệu, datalen unsigned char, char MsgFlag);<br />
Đối số: dữ liệu Con trỏ đến vị trí mà nhận được dữ liệu là được<br />
được lưu trữ từ.<br />
datalen Số lượng các byte dữ liệu dự kiến.<br />
MsgFlag Số đệm nơi dữ liệu được nhận.
char CAN2IsRXPassive(void);<br />
Arguments: None<br />
Return Value: If the value of RXEP is ‘1’, then ‘1’ is returned, indicating the<br />
node<br />
going passive due to error in reception.<br />
If the value of RXEP is ‘0’, then ‘0’ is returned, indicating no error on<br />
bus.<br />
Remarks: This function returns the status ofthe RXEP bit of CiINTF register.<br />
Source File: CAN1IsRXPassive.c<br />
CAN2IsRXPassive.c<br />
Code Example: char rx_bus_status;<br />
rx_bus_status = CAN1IsRXPassive();<br />
CAN1IsTXPassive<br />
CAN2IsTXPassive<br />
Description: This function determines if the transmitter is in Error Passive state.<br />
Include: can.h<br />
Prototype: char CAN1IsTXPassive(void);<br />
char CAN2IsTXPassive(void);<br />
Arguments: None<br />
Return Value: If the value of TXEP is ‘1’, then ‘1’ is returned, indicating error<br />
on<br />
transmit bus and the bus going passive.<br />
If the value of TXEP is ‘0’, then ‘0’ is returned, indicating no error on<br />
transmit bus.<br />
Remarks: This function returns the status of the TXEP bit of CiINTF register.<br />
Source File: CAN1IsTXPassive.c<br />
CAN2IsTXPassive.c<br />
Code Example: char tx_bus_status;<br />
tx_bus_status = CAN1IsTXPassive();<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 84<br />
CAN1IsTXReady<br />
CAN2IsTXReady<br />
2004 Microchip Technology Inc.<br />
Description: This function returns the transmitter status indicating if the CAN<br />
node is<br />
ready for next transmission.<br />
Include: can.h<br />
Prototype: char CAN1IsTXReady(char);<br />
Nếu "1", các dữ liệu từ CiRX1B1 để CiRX1B4 được đọc.<br />
Nếu "0" hay nói cách khác, các dữ liệu từ CiRX0B1 để CiRX0B4 là<br />
đọc.<br />
Ghi chú: Chức năng này đọc dữ liệu nhận được vào các vị trí chỉ bởi đầu vào<br />
dữ liệu tham số.<br />
Quay trở lại giá trị: Không có.<br />
Source File: CAN1ReceiveMessage.c<br />
CAN2ReceiveMessage.c<br />
Mã số Ví dụ: unsigned char * rx_data;<br />
CAN1ReceiveMessage (rx_data, 5, 0);<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 85<br />
CAN1SendMessage<br />
CAN2SendMessage<br />
Mô tả: Chức năng này ghi dữ liệu được truyền đến TX đăng ký, thiết lập dữ liệu<br />
chiều dài và bắt đầu truyền.<br />
Bao gồm: can.h<br />
Prototype: void CAN1SendMessage (int sid,<br />
eid unsigned long, unsigned char * dữ liệu,<br />
datalen unsigned char, char MsgFlag);<br />
khoảng trống CAN2SendMessage (int sid,<br />
eid unsigned long, unsigned char * dữ liệu,<br />
datalen unsigned char, char MsgFlag);<br />
Đối số: Sid giá trị 16-bit được ghi vào sổ đăng ký CiTXnSID.<br />
CAN_TX_SID (x) XIS giá trị SID yêu cầu.<br />
Yêu cầu thay thế từ xa<br />
CAN_SUB_REM_TX_REQ<br />
CAN_SUB_NOR_TX_REQ<br />
Loại tin nhắn ID<br />
CAN_TX_EID_EN<br />
CAN_TX_EID_DIS<br />
Eid giá trị 32-bit được ghi vào CiTXnEID và<br />
CiTXnDLC đăng ký.<br />
CAN_TX_EID (x) XIS giá trị EID yêu cầu.<br />
Yêu cầu thay thế từ xa<br />
CAN_REM_TX_REQ<br />
CAN_NOR_TX_REQ<br />
dữ liệu Con trỏ đến vị trí mà dữ liệu được truyền là<br />
lưu trữ.
char CAN2IsTXReady(char);<br />
Arguments: buffno The value of buffno indicates the transmit buffer whose<br />
status is required.<br />
Return Value: If TXREQ is ‘1’, it returns ‘0’ indicating that the transmit buffer<br />
is not<br />
empty.<br />
If TXREQ is ‘0’, it returns ‘1’ indicating that the transmit buffer is empty<br />
and the transmitter is ready for next transmission.<br />
Remarks: This function returns the complimentof the TXREQ Status bit in the<br />
Transmit Control register.<br />
Source File: CAN1IsTXReady.c<br />
CAN2IsTXReady.c<br />
Code Example: char tx_2_status;<br />
tx_2_status = CAN1IsTXReady(2);<br />
CAN1ReceiveMessage<br />
CAN2ReceiveMessage<br />
Description: This function read the data from the receive buffer.<br />
Include: can.h<br />
Prototype: void CAN1ReceiveMessage(unsigned char *<br />
data, unsigned char datalen, char MsgFlag);<br />
datalen Số lượng các byte dữ liệu được truyền đi.<br />
MsgFlag Số lượng bộ đệm ("0", "1" hoặc "2") từ nơi dữ liệu có<br />
truyền đi.<br />
Nếu "1", dữ liệu được wriiten vào CiTX1B1 để CiTX1B4.<br />
Nếu '2', dữ liệu được wriiten vào CiTX2B1 để CiTX2B4.<br />
Nếu "0" hay nói cách khác, các dữ liệu được ghi vào CiTX0B1 để<br />
CiTX0B4.<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này ghi các giá trị định danh vào SID và EID đăng ký,<br />
dữ liệu được truyền vào TX reg, thiết lập chiều dài dữ liệu và tu<br />
truyền bằng cách thiết lập TXREQ bit.<br />
Source File: CAN1SendMessage.c<br />
CAN2SendMessage.c<br />
Mã số Ví dụ: CAN1SendMessage ((CAN_TX_SID (1920)) và<br />
(CAN_TX_EID_EN) & (CAN_SUB_NOR_TX_REQ),<br />
(CAN_TX_EID (12.344)) & (CAN_NOR_TX_REQ),<br />
Txdata, datalen, tx_rx_no);<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
void CAN2ReceiveMessage(unsigned char *<br />
data, unsigned char datalen,char MsgFlag);<br />
Arguments: data The pointer to the location where received data is to be<br />
DS51456B trang 86<br />
CAN1SetFilter<br />
CAN2SetFilter<br />
2004 Microchip Technology Inc<br />
stored from.<br />
datalen The number of bytes of data expected.<br />
MsgFlag The buffer number where data is received.<br />
If ‘1’, the data from CiRX1B1 to CiRX1B4 is read.<br />
If ‘0’ or otherwise, the data from CiRX0B1 to CiRX0B4 is<br />
read.<br />
Remarks: This function reads the received data into the locations pointed by<br />
input<br />
parameter data.<br />
Return Value: None.<br />
Source File: CAN1ReceiveMessage.c<br />
CAN2ReceiveMessage.c<br />
Code Example: unsigned char*rx_data;<br />
CAN1ReceiveMessage(rx_data, 5, 0);<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 85<br />
CAN1SendMessage<br />
Mô tả: Chức năng này đặt giá trị bộ lọc chấp nhận (SID và EID) cho<br />
bộ lọc quy định.<br />
Bao gồm: can.h<br />
Prototype: void CAN1SetFilter (char filter_no, int sid,<br />
unsigned eid dài);<br />
khoảng trống CAN2SetFilter (char filter_no, int sid,<br />
unsigned eid dài);<br />
Đối số: filter_no Các bộ lọc (0, 1, 2, 3, 4 hoặc 5) mà giá trị bộ lọc mới<br />
phải được cấu hình.<br />
sid giá trị 16-bit được ghi vào sổ đăng ký CiRXFnSID.<br />
CAN_FILTER_SID (x) XIS giá trị SID yêu cầu.<br />
Loại tin nhắn được nhận<br />
CAN_RX_EID_EN<br />
CAN_RX_EID_DIS<br />
Eid giá trị 32-bit được ghi vào CiRXFnEIDH và<br />
CiRXFnEIDL đăng ký.
CAN2SendMessage<br />
Description: This function writes data to be transmitted to TX registers, sets the<br />
data<br />
length and initiates the transmission.<br />
Include: can.h<br />
Prototype: void CAN1SendMessage(unsigned int sid,<br />
unsigned long eid, unsigned char *data,<br />
unsigned char datalen, char MsgFlag);<br />
void CAN2SendMessage(unsigned int sid,<br />
unsigned long eid, unsigned char *data,<br />
unsigned char datalen, char MsgFlag);<br />
Arguments: sid The 16-bit value to be written into CiTXnSID registers.<br />
CAN_TX_SID(x) xis the required SID value.<br />
Substitute Remote Request<br />
CAN_SUB_REM_TX_REQ<br />
CAN_SUB_NOR_TX_REQ<br />
Message ID Type<br />
CAN_TX_EID_EN<br />
CAN_TX_EID_DIS<br />
eid The 32-bit value to be written into CiTXnEID and<br />
CiTXnDLC registers.<br />
CAN_TX_EID(x) xis the required EID value.<br />
Substitute Remote Request<br />
CAN_REM_TX_REQ<br />
CAN_NOR_TX_REQ<br />
data The pointer to the location where data to be transmitted is<br />
stored.<br />
datalen The number of bytes of data to be transmitted.<br />
MsgFlag The buffer number (‘0’, ‘1’ or ‘2’) from where data is<br />
transmitted.<br />
If ‘1’, the data is wriiten into CiTX1B1 to CiTX1B4.<br />
If ‘2’, the data is wriiten into CiTX2B1 to CiTX2B4.<br />
If ‘0’ or otherwise, the data is written into CiTX0B1 to<br />
CiTX0B4.<br />
Return Value: None<br />
Remarks: This function writes the identifier values into SID and EID registers,<br />
data to be transmitted into TX reg, sets the data length and initiates<br />
transmission by setting TXREQ bit.<br />
Source File: CAN1SendMessage.c<br />
CAN_FILTER_EID (x) XIS giá trị EID yêu cầu.<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này ghi giá trị 16-bit của sidinto đăng ký CiRXFnSID<br />
và hoặc giá trị 32-bit của eidinto các CiRXFnEIDH và CiRXFnEIDL<br />
đăng ký tương ứng với bộ lọc theo quy định của filter_no.<br />
Lọc 0 được thực hiện như là mặc định.<br />
Source File: CAN1SetFilter.c<br />
CAN2SetFilter.c<br />
Mã số Ví dụ: CAN1SetFilter (1, CAN_FILTER_SID (7) &<br />
CAN_RX_EID_EN, CAN_FILTER_EID (3));<br />
CAN1SetMask<br />
CAN2SetMask<br />
Mô tả: Chức năng này đặt giá trị mặt nạ chấp nhận (SID và EID) cho<br />
mặt nạ chỉ định.<br />
Bao gồm: can.h<br />
Prototype: void CAN1SetMask (char mask_no, int sid,<br />
unsigned eid dài);<br />
khoảng trống CAN2SetMask (char mask_no, int sid,<br />
unsigned eid dài);<br />
Đối số: mask_no Mặt nạ ("0" hoặc "1") mà giá trị mặt nạ phải<br />
cấu hình.<br />
sid giá trị 16-bit được ghi vào sổ đăng ký CiRXMnSID.<br />
CAN_MASK_SID (x) XIS giá trị SID yêu cầu.<br />
Trận đấu / bỏ qua tin nhắn typespecified trong bộ lọc<br />
CAN_MATCH_FILTER_TYPE<br />
CAN_IGNORE_FILTER_TYPE<br />
Eid giá trị 32-bit được ghi vào CiRXMnEIDH và<br />
CiRXMnEIDL đăng ký.<br />
CAN_MASK_EID (x) XIS giá trị EID yêu cầu.<br />
Trở lại giá trị: Không<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 87<br />
Ghi chú: Chức năng này ghi giá trị 16-bit của sidinto đăng ký CiRXFnSID<br />
và hoặc giá trị 32-bit của eidinto các CiRXFnEIDH và CiRXFnEIDL<br />
đăng ký tương ứng tothe mặt nạ theo quy định của mask_no.<br />
Lọc 0 được thực hiện như là mặc định.<br />
Source File: CAN1SetMask.c<br />
CAN2SetMask.c<br />
Mã số Ví dụ: CAN1SetMask (1, CAN_MASK_SID (7) &
CAN2SendMessage.c<br />
Code Example: CAN1SendMessage((CAN_TX_SID(1920)) &<br />
(CAN_TX_EID_EN) & (CAN_SUB_NOR_TX_REQ),<br />
(CAN_TX_EID(12344)) & (CAN_NOR_TX_REQ),<br />
Txdata, datalen, tx_rx_no);<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 86<br />
CAN1SetFilter<br />
CAN2SetFilter<br />
2004 Microchip Technology Inc.<br />
Description: This function sets the acceptance filter values (SID and EID) for<br />
the<br />
specified filter.<br />
Include: can.h<br />
Prototype: void CAN1SetFilter(char filter_no, unsigned int sid,<br />
unsigned long eid);<br />
void CAN2SetFilter(char filter_no, unsigned int sid,<br />
unsigned long eid);<br />
Arguments: filter_no The filter (0, 1, 2, 3, 4 or 5) for which new filter values<br />
have to be configured.<br />
sid The 16-bit value to be written into CiRXFnSID registers.<br />
CAN_FILTER_SID(x) xis the required SID value.<br />
Type of message to be received<br />
CAN_RX_EID_EN<br />
CAN_RX_EID_DIS<br />
eid The 32-bit value to be written into CiRXFnEIDH and<br />
CiRXFnEIDL registers.<br />
CAN_FILTER_EID(x) xis the required EID value.<br />
Return Value: None<br />
Remarks: This function writes the 16-bit value of sidinto the CiRXFnSID<br />
register<br />
and or the 32-bit value of eidinto the CiRXFnEIDH and CiRXFnEIDL<br />
registers corresponding to the filter specified by filter_no.<br />
Filter 0 is taken as default.<br />
Source File: CAN1SetFilter.c<br />
CAN2SetFilter.c<br />
Code Example: CAN1SetFilter(1, CAN_FILTER_SID(7) &<br />
CAN_RX_EID_EN, CAN_FILTER_EID(3));<br />
CAN1SetMask<br />
CAN_MATCH_FILTER_TYPE, CAN_MASK_EID (3));<br />
CAN1SetOperationMode<br />
CAN2SetOperationMode<br />
Mô tả: Chức năng này cấu hình các module CAN<br />
Bao gồm: can.h<br />
Prototype: void CAN1SetOperationMode (int config);<br />
khoảng trống CAN2SetOperationMode (int config);<br />
Đối số: cấu hình giá trị 16-bit được nạp vào CiCTRL đăng ký, các<br />
sự kết hợp của các định nghĩa sau đây.<br />
CAN_IDLE_CONCAN Mở ở chế độ nhàn rỗi<br />
CAN_IDLE_STOPCAN Dừng ở chế độ nhàn rỗi<br />
CAN_MASTERCLOCK_1FCANis ngoại tệ<br />
CAN_MASTERCLOCK_0FCANis 4 ngoại tệ<br />
CAN phương thức hoạt động<br />
CAN_REQ_OPERMODE_NOR<br />
CAN_REQ_OPERMODE_DIS<br />
CAN_REQ_OPERMODE_LOOPBK<br />
CAN_REQ_OPERMODE_LISTENONLY<br />
CAN_REQ_OPERMODE_CONFIG<br />
CAN_REQ_OPERMODE_LISTENALL<br />
THỂ Chụp Bật / Tắt<br />
CAN_CAPTURE_EN<br />
CAN_CAPTURE_DIS<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này cấu hình các bit sau CiCTRL: -CSIDL,<br />
REQOP và CANCKS<br />
Source File: CAN1SetOperationMode.c<br />
CAN2SetOperationMode.c<br />
Mã số Ví dụ: CAN1SetOperationMode (CAN_IDLE_STOP &<br />
CAN_MASTERCLOCK_0 & CAN_REQ_OPERMODE_DIS &<br />
CAN_CAPTURE_DIS);<br />
CAN1SetMask (Tiếp theo)<br />
CAN2SetMask<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 88 2004 Microchip Technology Inc<br />
CAN1SetOperationModeNoWait<br />
CAN2SetOperationModeNoWait
CAN2SetMask<br />
Description: This function sets the acceptance mask values (SID and EID) for<br />
the<br />
specified mask.<br />
Include: can.h<br />
Prototype: void CAN1SetMask(char mask_no, unsigned int sid,<br />
unsigned long eid);<br />
void CAN2SetMask(char mask_no, unsigned int sid,<br />
unsigned long eid);<br />
Arguments: mask_no The mask (‘0’ or ‘1’) for which mask values have to be<br />
configured.<br />
sid The 16-bit value to be written into CiRXMnSID registers.<br />
CAN_MASK_SID(x) xis the required SID value.<br />
Match/ignore message typespecified in filter<br />
CAN_MATCH_FILTER_TYPE<br />
CAN_IGNORE_FILTER_TYPE<br />
eid The 32-bit value to be written into CiRXMnEIDH and<br />
CiRXMnEIDL registers.<br />
CAN_MASK_EID(x) xis the required EID value.<br />
Return Value: None<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 87<br />
Remarks: This function writes the 16-bit value of sidinto the CiRXFnSID<br />
register<br />
and or the 32-bit value of eidinto the CiRXFnEIDH and CiRXFnEIDL<br />
registers corresponding tothe mask specified by mask_no.<br />
Filter 0 is taken as default.<br />
Source File: CAN1SetMask.c<br />
CAN2SetMask.c<br />
Code Example: CAN1SetMask(1, CAN_MASK_SID(7) &<br />
CAN_MATCH_FILTER_TYPE, CAN_MASK_EID(3));<br />
CAN1SetOperationMode<br />
CAN2SetOperationMode<br />
Description: This function configures the CAN module<br />
Include: can.h<br />
Prototype: void CAN1SetOperationMode(unsigned int config);<br />
void CAN2SetOperationMode(unsigned int config);<br />
Arguments: config The 16-bit value to be loaded into CiCTRL register, the<br />
combination of the following defines.<br />
CAN_IDLE_CONCAN On in Idle mode<br />
Mô tả: Chức năng này hủy bỏ các truyền cấp phát và cấu hình CAN<br />
mô-đun<br />
Bao gồm: can.h<br />
Prototype: void CAN1SetOperationModeNoWait (<br />
int config);<br />
khoảng trống CAN2SetOperationModeNoWait (<br />
int config);<br />
Đối số: cấu hình giá trị 16-bit được loadedinto CiCTRL đăng ký,<br />
sự kết hợp của các định nghĩa sau đây.<br />
CAN_IDLE_CON_NO_WAITCAN Mở ở chế độ nhàn rỗi<br />
CAN_IDLE_STOP_NO_WAITCAN Dừng ở chế độ nhàn rỗi<br />
CAN_MASTERCLOCK_1_NO_WAITFCANis ngoại tệ<br />
CAN_MASTERCLOCK_0_NO_WAITFCANis 4 ngoại tệ<br />
CAN phương thức hoạt động<br />
CAN_REQ_OPERMODE_NOR_NO_WAIT<br />
CAN_REQ_OPERMODE_DIS_NO_WAIT<br />
CAN_REQ_OPERMODE_LOOPBK_NO_WAIT<br />
CAN_REQ_OPERMODE_LISTENONLY_NO_WAIT<br />
CAN_REQ_OPERMODE_CONFIG_NO_WAIT<br />
CAN_REQ_OPERMODE_LISTENALL_NO_WAIT<br />
THỂ Chụp Bật / Tắt<br />
CAN_CAPTURE_EN_NO_WAIT<br />
CAN_CAPTURE_DIS_NO_WAIT<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này đặt bit Abort do đó bắt đầu hủy bỏ tất cả các cấp phát<br />
truyền và cấu hình các bit sau CiCTRL: -CSIDL,<br />
REQOP và CANCKS<br />
Source File: CAN1SetOperationModeNoWait.c<br />
CAN2SetOperationModeNoWait.c<br />
Mã số Ví dụ: CAN1SetOperationModeNoWait (CAN_IDLE_CON &<br />
CAN_MASTERCLOCK_1 & CAN_REQ_OPERMODE_LISTEN &<br />
CAN_CAPTURE_DIS_NO_WAIT);<br />
CAN1SetRXMode<br />
CAN2SetRXMode<br />
Mô tả: Chức năng này cấu hình thu CAN.<br />
Bao gồm: can.h<br />
Prototype: void CAN1SetRXMode (char buffno, int<br />
config);<br />
khoảng trống CAN2SetRXMode (char buffno, int
CAN_IDLE_STOPCAN Stop in Idle mode<br />
CAN_MASTERCLOCK_1FCANis FCY<br />
CAN_MASTERCLOCK_0FCANis 4 FCY<br />
CAN modes of operation<br />
CAN_REQ_OPERMODE_NOR<br />
CAN_REQ_OPERMODE_DIS<br />
CAN_REQ_OPERMODE_LOOPBK<br />
CAN_REQ_OPERMODE_LISTENONLY<br />
CAN_REQ_OPERMODE_CONFIG<br />
CAN_REQ_OPERMODE_LISTENALL<br />
CAN Capture Enable/Disable<br />
CAN_CAPTURE_EN<br />
CAN_CAPTURE_DIS<br />
Return Value: None<br />
Remarks: This function configures the following bits of CiCTRL:-CSIDL,<br />
REQOP and CANCKS<br />
Source File: CAN1SetOperationMode.c<br />
CAN2SetOperationMode.c<br />
Code Example: CAN1SetOperationMode(CAN_IDLE_STOP &<br />
CAN_MASTERCLOCK_0 & CAN_REQ_OPERMODE_DIS &<br />
CAN_CAPTURE_DIS);<br />
CAN1SetMask (Continued)<br />
CAN2SetMask<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 88<br />
CAN1SetOperationModeNoWait<br />
CAN2SetOperationModeNoWait<br />
2004 Microchip Technology Inc.<br />
Description: This function aborts the pending transmissions and configures the<br />
CAN<br />
module<br />
Include: can.h<br />
Prototype: void CAN1SetOperationModeNoWait(<br />
unsigned int config);<br />
void CAN2SetOperationModeNoWait(<br />
unsigned int config);<br />
Arguments: config The 16-bit value to be loadedinto CiCTRL register, the<br />
combination of the following defines.<br />
config);<br />
Đối số: buffno buffno cho biết reg kiểm soát được cấu hình.<br />
cấu hình giá trị được ghi vào CiRXnCON reg, sự kết hợp<br />
các định nghĩa sau đây.<br />
Rõ ràng chút RXFUL<br />
CAN_RXFUL_CLEAR<br />
Đôi đệm cho phép / vô hiệu hóa<br />
CAN_BUF0_DBLBUFFER_EN<br />
CAN_BUF0_DBLBUFFER_DIS<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 89<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này cấu hình các bit sau CiRXnCON đăng ký:<br />
RXRTR, RXFUL (chỉ 0), RXM và DBEN<br />
Source File: CAN1SetRXMode.c<br />
CAN2SetRXMode.c<br />
Mã số Ví dụ: CAN1SetRXMode (0, CAN_RXFUL_CLEAR &<br />
CAN_BUF0_DBLBUFFER_EN);<br />
CAN1SetTXMode (chức năng)<br />
CAN2SetTXMode<br />
Mô tả: Chức năng này cấu hình các module CAN phát<br />
Bao gồm: can.h<br />
Prototype: void CAN1SetTXMode (char buffno, int<br />
config);<br />
khoảng trống CAN2SetTXMode (char buffno, int<br />
config);<br />
Đối số: buffno buffno cho biết reg kiểm soát được cấu hình.<br />
cấu hình giá trị được ghi vào CiTXnCON reg, sự kết hợp<br />
các định nghĩa sau đây.<br />
Gửi tin nhắn yêu cầu<br />
CAN_TX_REQ<br />
CAN_TX_STOP_REQ<br />
Ưu tiên truyền tin nhắn<br />
CAN_TX_PRIORITY_HIGH<br />
CAN_TX_PRIORITY_HIGH_INTER<br />
CAN_TX_PRIORITY_LOW_INTER<br />
CAN_TX_PRIORITY_LOW<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này cấu hình các bit sau CiTXnCON đăng ký:
CAN_IDLE_CON_NO_WAITCAN On in Idle mode<br />
CAN_IDLE_STOP_NO_WAITCAN Stop in Idle mode<br />
CAN_MASTERCLOCK_1_NO_WAITFCANis FCY<br />
CAN_MASTERCLOCK_0_NO_WAITFCANis 4 FCY<br />
CAN modes of operation<br />
CAN_REQ_OPERMODE_NOR_NO_WAIT<br />
CAN_REQ_OPERMODE_DIS_NO_WAIT<br />
CAN_REQ_OPERMODE_LOOPBK_NO_WAIT<br />
CAN_REQ_OPERMODE_LISTENONLY_NO_WAIT<br />
CAN_REQ_OPERMODE_CONFIG_NO_WAIT<br />
CAN_REQ_OPERMODE_LISTENALL_NO_WAIT<br />
CAN Capture Enable/Disable<br />
CAN_CAPTURE_EN_NO_WAIT<br />
CAN_CAPTURE_DIS_NO_WAIT<br />
Return Value: None<br />
Remarks: This function sets the Abort bit thus initiating abort of all pending<br />
transmissions and configures the following bits of CiCTRL:-CSIDL,<br />
REQOP and CANCKS<br />
Source File: CAN1SetOperationModeNoWait.c<br />
CAN2SetOperationModeNoWait.c<br />
Code Example: CAN1SetOperationModeNoWait(CAN_IDLE_CON &<br />
CAN_MASTERCLOCK_1 & CAN_REQ_OPERMODE_LISTEN &<br />
CAN_CAPTURE_DIS_NO_WAIT);<br />
CAN1SetRXMode<br />
CAN2SetRXMode<br />
Description: This function configures the CAN receiver.<br />
Include: can.h<br />
Prototype: void CAN1SetRXMode(char buffno, unsigned int<br />
config);<br />
void CAN2SetRXMode(char buffno, unsigned int<br />
config);<br />
Arguments: buffno buffno indicates the control reg to be configured.<br />
config The value to be written into CiRXnCON reg, the combination<br />
of the following defines.<br />
Clear RXFUL bit<br />
CAN_RXFUL_CLEAR<br />
Double buffer enable/disable<br />
CAN_BUF0_DBLBUFFER_EN<br />
CAN_BUF0_DBLBUFFER_DIS<br />
TXRTR, TXREQ, DLC, TXPRI <br />
Source File: CAN1SetTXMode.c<br />
CAN2SetTXMode.c<br />
Mã số Ví dụ: CAN1SetTXMode (1, CAN_TX_STOP_REQ &<br />
CAN_TX_PRIORITY_HIGH);<br />
CAN1SetRXMode (Tiếp theo)<br />
CAN2SetRXMode<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 90 2004 Microchip Technology Inc<br />
CAN1Initialize<br />
CAN2Initialize<br />
Mô tả: Chức năng này cấu hình các module CAN<br />
Bao gồm: can.h<br />
Prototype: void CAN1Initialize (int config1,<br />
int config2);<br />
khoảng trống CAN2Initialize (int config1,<br />
int config2);<br />
Đối số: config1 giá trị được ghi vào CiCFG1 đăng ký,<br />
sự kết hợp của các định nghĩa sau đây.<br />
Sync rộng nhảy<br />
CAN_SYNC_JUMP_WIDTH1<br />
CAN_SYNC_JUMP_WIDTH2<br />
CAN_SYNC_JUMP_WIDTH3<br />
CAN_SYNC_JUMP_WIDTH4<br />
Tốc độ Baud prescaler<br />
CAN_BAUD_PRE_SCALE (x) (((x-1) & 0x3F) | 0xC0)<br />
config2 giá trị được ghi vào CiCFG2 đăng ký, các<br />
sự kết hợp của các định nghĩa sau đây.<br />
Xe buýt CAN chọn lọc dòng để đánh thức<br />
CAN_WAKEUP_BY_FILTER_EN<br />
CAN_WAKEUP_BY_FILTER_DIS<br />
THỂ lan truyền chiều dài phân đoạn<br />
CAN_PROPAGATIONTIME_SEG_TQ (x)<br />
(((X-1) & 0x7) | 0xC7F8)<br />
THỂ giai đoạn đoạn 1 dài<br />
CAN_PHASE_SEG1_TQ (x)<br />
((((X-1) & 0x7) * 0x8) | 0xC7C7)
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 89<br />
Return Value: None<br />
Remarks: This function configures the following bits of CiRXnCON register:<br />
RXRTR, RXFUL (only 0), RXM and DBEN<br />
Source File: CAN1SetRXMode.c<br />
CAN2SetRXMode.c<br />
Code Example: CAN1SetRXMode(0,CAN_RXFUL_CLEAR &<br />
CAN_BUF0_DBLBUFFER_EN);<br />
CAN1SetTXMode (function)<br />
CAN2SetTXMode<br />
Description: This function configures the CAN transmitter module<br />
Include: can.h<br />
Prototype: void CAN1SetTXMode(char buffno, unsigned int<br />
config);<br />
void CAN2SetTXMode(char buffno, unsigned int<br />
config);<br />
Arguments: buffno buffno indicates the control reg to be configured.<br />
config The value to be written into CiTXnCON reg, the combination<br />
of the following defines.<br />
Message send request<br />
CAN_TX_REQ<br />
CAN_TX_STOP_REQ<br />
Message transmission priority<br />
CAN_TX_PRIORITY_HIGH<br />
CAN_TX_PRIORITY_HIGH_INTER<br />
CAN_TX_PRIORITY_LOW_INTER<br />
CAN_TX_PRIORITY_LOW<br />
Return Value: None<br />
Remarks: This function configures the following bits of CiTXnCON register:<br />
TXRTR, TXREQ, DLC, TXPRI<br />
Source File: CAN1SetTXMode.c<br />
CAN2SetTXMode.c<br />
Code Example: CAN1SetTXMode(1, CAN_TX_STOP_REQ &<br />
CAN_TX_PRIORITY_HIGH);<br />
CAN1SetRXMode (Continued)<br />
CAN2SetRXMode<br />
dsPIC<br />
®<br />
THỂ giai đoạn 2 đoạn dài<br />
CAN_PHASE_SEG2_TQ (x)<br />
((((X-1) & 0x7) * 0x100) | 0xC0FF)<br />
THỂ giai đoạn chế độ đoạn 2<br />
CAN_SEG2_FREE_PROG<br />
CAN_SEG2_TIME_LIMIT_SET<br />
Mẫu của các dòng xe buýt CAN<br />
CAN_SAMPLE3TIMES<br />
CAN_SAMPLE1TIME<br />
Trở lại giá trị: Không<br />
Bình luận: Chức năng này cấu hình các bit sau CiCFG1 và CiCFG2<br />
đăng ký:<br />
SJW , BRP , CANCAP, WAKEFIL, SEG2PH ,<br />
SEGPHTS, SAM, SEG1PH , PRSEG <br />
Source File: CAN1Initialize.c<br />
CAN2Initialize.c<br />
Mã số Ví dụ: CAN1Initialize (CAN_SYNC_JUMP_WIDTH2 &<br />
CAN_BAUD_PRE_SCALE (2),<br />
CAN_WAKEUP_BY_FILTER_DIS &<br />
CAN_PHASE_SEG2_TQ (5) và<br />
CAN_PHASE_SEG1_TQ (4) và<br />
CAN_PROPAGATIONTIME_SEG_TQ (4) và<br />
CAN_SEG2_FREE_PROG &<br />
CAN_SAMPLE1TIME);<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 91<br />
ConfigIntCAN1<br />
ConfigIntCAN2<br />
Mô tả: Chức năng này cấu hình CAN ngắt<br />
Bao gồm: can.h<br />
Prototype: void ConfigIntCAN1 (int config1,<br />
int config2);<br />
làm mất hiệu lực ConfigIntCAN2 (unsigned int config1,<br />
int config2);<br />
Đối số: config1 cá nhân ngắt bật / tắt thông tin theo quy định<br />
dưới đây:<br />
Người dùng phải nhập một trong hai tùy chọn vô hiệu hóa enableor cho tất cả<br />
các<br />
ngắt cá nhân.<br />
Cho phép ngắt
Language Tools Libraries<br />
DS51456B-page 90 2004 Microchip Technology Inc.<br />
CAN1Initialize<br />
CAN2Initialize<br />
Description: This function configures the CAN module<br />
Include: can.h<br />
Prototype: void CAN1Initialize(unsigned int config1,<br />
unsigned int config2);<br />
void CAN2Initialize(unsigned int config1,<br />
unsigned int config2);<br />
Arguments: config1 The value to be written into CiCFG1 register, the<br />
combination of the following defines.<br />
Sync jump width<br />
CAN_SYNC_JUMP_WIDTH1<br />
CAN_SYNC_JUMP_WIDTH2<br />
CAN_SYNC_JUMP_WIDTH3<br />
CAN_SYNC_JUMP_WIDTH4<br />
Baud Rate prescaler<br />
CAN_BAUD_PRE_SCALE(x)(((x-1) & 0x3f) | 0xC0)<br />
config2 The value to be written into CiCFG2 register, the<br />
combination of the following defines.<br />
CAN bus line filter selection for wake-up<br />
CAN_WAKEUP_BY_FILTER_EN<br />
CAN_WAKEUP_BY_FILTER_DIS<br />
CAN propagation segment length<br />
CAN_PROPAGATIONTIME_SEG_TQ(x)<br />
(((x-1) & 0x7) | 0xC7F8)<br />
CAN phase segment 1 length<br />
CAN_PHASE_SEG1_TQ(x)<br />
((((x-1) & 0x7) *0x8) | 0xC7C7)<br />
CAN phase segment 2 length<br />
CAN_PHASE_SEG2_TQ(x)<br />
((((x-1) & 0x7) *0x100) | 0xC0FF)<br />
CAN phase segment 2 mode<br />
CAN_SEG2_FREE_PROG<br />
CAN_SEG2_TIME_LIMIT_SET<br />
Sample of the CAN bus line<br />
CAN_SAMPLE3TIMES<br />
CAN_SAMPLE1TIME<br />
CAN_INDI_INVMESS_EN<br />
CAN_INDI_WAK_EN<br />
CAN_INDI_ERR_EN<br />
CAN_INDI_TXB2_EN<br />
CAN_INDI_TXB1_EN<br />
CAN_INDI_TXB0_EN<br />
CAN_INDI_RXB1_EN<br />
CAN_INDI_RXB0_EN<br />
Gián đoạn vô hiệu hóa<br />
CAN_INDI_INVMESS_DIS<br />
CAN_INDI_WAK_DIS<br />
CAN_INDI_ERR_DIS<br />
CAN_INDI_TXB2_DIS<br />
CAN_INDI_TXB1_DIS<br />
CAN_INDI_TXB0_DIS<br />
CAN_INDI_RXB1_DIS<br />
CAN_INDI_RXB0_DIS<br />
config2 THỂ gián đoạn ưu tiên và bật / tắt thông tin<br />
quy định dưới đây:<br />
THỂ Ngắt bật / tắt<br />
CAN_INT_ENABLE<br />
CAN_INT_DISABLE<br />
THỂ Ngắt ưu tiên<br />
CAN_INT_PRI_0<br />
CAN_INT_PRI_1<br />
CAN_INT_PRI_2<br />
CAN_INT_PRI_3<br />
CAN_INT_PRI_4<br />
CAN_INT_PRI_5<br />
CAN_INT_PRI_6<br />
CAN_INT_PRI_7<br />
Trở lại giá trị: Không<br />
Bình luận: Chức năng này cấu hình ngắt CAN. Nó cho phép / vô hiệu hóa<br />
CAN cá nhân ngắt. Nó cũng cho phép / vô hiệu hóa các THỂ gián đoạn<br />
và đặt ưu tiên.<br />
Source File: ConfigIntCAN1.c<br />
ConfigIntCAN2.c<br />
dsPIC<br />
®
Return Value: None<br />
Remarks: This function configures the following bits of CiCFG1 and CiCFG2<br />
registers:<br />
SJW, BRP, CANCAP, WAKEFIL, SEG2PH,<br />
SEGPHTS, SAM, SEG1PH, PRSEG<br />
Source File: CAN1Initialize.c<br />
CAN2Initialize.c<br />
Code Example: CAN1Initialize(CAN_SYNC_JUMP_WIDTH2 &<br />
CAN_BAUD_PRE_SCALE(2),<br />
CAN_WAKEUP_BY_FILTER_DIS &<br />
CAN_PHASE_SEG2_TQ(5) &<br />
CAN_PHASE_SEG1_TQ(4) &<br />
CAN_PROPAGATIONTIME_SEG_TQ(4) &<br />
CAN_SEG2_FREE_PROG &<br />
CAN_SAMPLE1TIME);<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 91<br />
ConfigIntCAN1<br />
ConfigIntCAN2<br />
Description: This function configures the CAN Interrupts<br />
Include: can.h<br />
Prototype: void ConfigIntCAN1(unsigned int config1,<br />
unsigned int config2);<br />
void ConfigIntCAN2(unsigned int config1,<br />
unsigned int config2);<br />
Arguments: config1 individual interrupt enable/disable information as defined<br />
below:<br />
User must enter either enableor disable option for all the<br />
individual interrupts.<br />
Interrupt enable<br />
CAN_INDI_INVMESS_EN<br />
CAN_INDI_WAK_EN<br />
CAN_INDI_ERR_EN<br />
CAN_INDI_TXB2_EN<br />
CAN_INDI_TXB1_EN<br />
CAN_INDI_TXB0_EN<br />
CAN_INDI_RXB1_EN<br />
CAN_INDI_RXB0_EN<br />
Interrupt disable<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 92<br />
3.4.2 Macros cá nhân<br />
2004 Microchip Technology Inc<br />
Mã số Ví dụ: ConfigIntCAN1 (CAN_INDI_INVMESS_EN &<br />
CAN_INDI_WAK_DIS &<br />
CAN_INDI_ERR_DIS &<br />
CAN_INDI_TXB2_DIS &<br />
CAN_INDI_TXB1_DIS &<br />
CAN_INDI_TXB0_DIS &<br />
CAN_INDI_RXB1_DIS &<br />
CAN_INDI_RXB0_DIS,<br />
CAN_INT_PRI_3 &<br />
CAN_INT_ENABLE);<br />
EnableIntCAN1<br />
EnableIntCAN2<br />
Mô tả: Phần này cho phép THỂ gián đoạn.<br />
Bao gồm: can.h<br />
Lập luận: Không<br />
Bình luận: Đây bộ vĩ mô THỂ Interrupt Enable bit Interrupt Enable kiểm soát<br />
đăng ký.<br />
Mã số Ví dụ: EnableIntCAN1;<br />
DisableIntCAN1<br />
DisableIntCAN2<br />
Mô tả: vĩ mô này vô hiệu hóa CAN gián đoạn.<br />
Bao gồm: can.h<br />
Lập luận: Không<br />
Bình luận: điều này sẽ xóa vĩ mô THỂ Ngắt Enablebit của Interrupt Enable<br />
kiểm soát<br />
đăng ký.<br />
Mã số Ví dụ: DisableIntCAN2;<br />
SetPriorityIntCAN1<br />
SetPriorityIntCAN2<br />
Mô tả: Đây bộ vĩ mô ưu tiên cho CAN gián đoạn.<br />
Bao gồm: can.h<br />
Đối số: ưu tiên<br />
Bình luận: Đây bộ vĩ mô THỂ Ngắt bit ưu tiên của ngắt ưu tiên kiểm soát<br />
đăng ký.<br />
Mã số Ví dụ: SetPriorityIntCAN1 (2);<br />
ConfigIntCAN1 (Tiếp theo)<br />
ConfigIntCAN2
CAN_INDI_INVMESS_DIS<br />
CAN_INDI_WAK_DIS<br />
CAN_INDI_ERR_DIS<br />
CAN_INDI_TXB2_DIS<br />
CAN_INDI_TXB1_DIS<br />
CAN_INDI_TXB0_DIS<br />
CAN_INDI_RXB1_DIS<br />
CAN_INDI_RXB0_DIS<br />
config2 CAN interrupt priority and enable/disable information as<br />
defined below:<br />
CAN Interrupt enable/disable<br />
CAN_INT_ENABLE<br />
CAN_INT_DISABLE<br />
CAN Interrupt priority<br />
CAN_INT_PRI_0<br />
CAN_INT_PRI_1<br />
CAN_INT_PRI_2<br />
CAN_INT_PRI_3<br />
CAN_INT_PRI_4<br />
CAN_INT_PRI_5<br />
CAN_INT_PRI_6<br />
CAN_INT_PRI_7<br />
Return Value: None<br />
Remarks: This function configures the CAN interrupts. It enables/disables the<br />
individual CAN interrupts. It also enables/disables the CAN interrupt<br />
and sets priority.<br />
Source File: ConfigIntCAN1.c<br />
ConfigIntCAN2.c<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 92 2004 Microchip Technology Inc.<br />
3.4.2 Individual Macros<br />
Code Example: ConfigIntCAN1(CAN_INDI_INVMESS_EN &<br />
CAN_INDI_WAK_DIS &<br />
CAN_INDI_ERR_DIS &<br />
CAN_INDI_TXB2_DIS &<br />
CAN_INDI_TXB1_DIS &<br />
CAN_INDI_TXB0_DIS &<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 93<br />
3.4.3 Ví dụ về sử dụng<br />
# xác định __dsPIC30F6014__<br />
# include<br />
# include<br />
# xác định dataarray 0x1820<br />
int main (void)<br />
{<br />
/ * Chiều dài của dữ liệu truyền tobe / đọc * /<br />
datalen unsigned char;<br />
unsigned char Txdata [] =<br />
{'M', 'tôi', 'C', 'R', 'O', 'C', 'H', 'tôi', 'P', '\ 0'};<br />
int TXConfig, RXConfig;<br />
unsigned longMaskID, MessageID;<br />
char FilterNo, tx_rx_no;<br />
unsigned char * datareceived = (unsigned char *)<br />
dataarray; / * Giữ dữ liệu nhận được * /<br />
/ * Thiết lập yêu cầu chế độ cấu hình * /<br />
CAN1SetOperationMode (CAN_IDLE_CON &<br />
CAN_MASTERCLOCK_1 &<br />
CAN_REQ_OPERMODE_CONFIG &<br />
CAN_CAPTURE_DIS);<br />
trong khi (C1CTRLbits.OPMODE
CAN_INDI_RXB1_DIS &<br />
CAN_INDI_RXB0_DIS ,<br />
CAN_INT_PRI_3 &<br />
CAN_INT_ENABLE);<br />
EnableIntCAN1<br />
EnableIntCAN2<br />
Description: This macro enables the CAN interrupt.<br />
Include: can.h<br />
Arguments: None<br />
Remarks: This macro sets CAN Interrupt Enable bit of Interrupt Enable Control<br />
register.<br />
Code Example: EnableIntCAN1;<br />
DisableIntCAN1<br />
DisableIntCAN2<br />
Description: This macro disables the CAN interrupt.<br />
Include: can.h<br />
Arguments: None<br />
Remarks: This macro clears CAN Interrupt Enablebit of Interrupt Enable<br />
Control<br />
CAN_MATCH_FILTER_TYPE, CAN_MASK_EID (12.344));<br />
/ * Thiết lập chế độ máy phát và nhận * /<br />
tx_rx_no = 0;<br />
CAN1SetTXMode (tx_rx_no,<br />
CAN_TX_STOP_REQ &<br />
CAN_TX_PRIORITY_HIGH);<br />
CAN1SetRXMode (tx_rx_no,<br />
CAN_RXFUL_CLEAR &<br />
CAN_BUF0_DBLBUFFER_EN);<br />
/ * Tải nhắn ID, dữ liệu vào bộ đệm truyền và thiết lập<br />
truyền yêu cầu bit * /<br />
datalen = 8;<br />
CAN1SendMessage ((CAN_TX_SID (1920)) và CAN_TX_EID_EN &<br />
CAN_SUB_NOR_TX_REQ,<br />
(CAN_TX_EID (12.344)) & CAN_NOR_TX_REQ,<br />
Txdata, datalen, tx_rx_no);<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
register.<br />
DS51456B trang 94<br />
2004 Microchip Technology Inc<br />
Code Example: DisableIntCAN2;<br />
SetPriorityIntCAN1<br />
SetPriorityIntCAN2<br />
Description: This macro sets priority for CAN interrupt.<br />
Include: can.h<br />
Arguments: priority<br />
Remarks: This macro sets CAN Interrupt Priority bits of Interrupt Priority<br />
Control<br />
register.<br />
Code Example: SetPriorityIntCAN1(2);<br />
ConfigIntCAN1 (Continued)<br />
ConfigIntCAN2<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 93<br />
3.4.3 Example of Use<br />
#define __dsPIC30F6014__<br />
#include<br />
#include<br />
#define dataarray 0x1820<br />
int main(void)<br />
/ * Thiết lập yêu cầu chế độ lặp vòng * /<br />
CAN1SetOperationMode (CAN_IDLE_CON & CAN_CAPTURE_DIS &<br />
CAN_MASTERCLOCK_1 &<br />
CAN_REQ_OPERMODE_LOOPBK);<br />
trong khi (C1CTRLbits.OPMODE = 2);<br />
/ * Chờ cho đến khi hoàn toàn messageis truyền * /<br />
trong khi (! CAN1IsTXReady (0))<br />
/ * Chờ cho đến khi nhận được bộ đệm chứa tin nhắn hợp lệ * /<br />
trong khi (CAN1IsRXReady (0));<br />
/ * Đọc dữ liệu nhận được fromreceive đệm và lưu nó vào<br />
sử dụng dataarray xác định * /<br />
CAN1ReceiveMessage (datareceived, datalen, tx_rx_no);<br />
trong khi (1);<br />
trở về 0;<br />
}<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 95<br />
3,5 ADC12 chức năng<br />
Phần này bao gồm một danh sách các chức năng cá nhân cho 12 bit ADC và<br />
một ví dụ về
{<br />
/* Length of data tobe transmitted/read */<br />
unsigned char datalen;<br />
unsigned char Txdata[] =<br />
{'M','I','C','R','O','C','H','I','P','\0'};<br />
unsigned int TXConfig, RXConfig;<br />
unsigned longMaskID,MessageID;<br />
char FilterNo,tx_rx_no;<br />
unsigned char * datareceived = (unsigned char *)<br />
dataarray; /* Holds the data received */<br />
/* Set request for configuration mode */<br />
CAN1SetOperationMode(CAN_IDLE_CON &<br />
CAN_MASTERCLOCK_1 &<br />
CAN_REQ_OPERMODE_CONFIG &<br />
CAN_CAPTURE_DIS);<br />
while(C1CTRLbits.OPMODE
CAN_BUF0_DBLBUFFER_EN);<br />
/* Load message ID , Data into transmit buffer and set<br />
transmit request bit */<br />
datalen = 8;<br />
CAN1SendMessage((CAN_TX_SID(1920)) & CAN_TX_EID_EN &<br />
CAN_SUB_NOR_TX_REQ,<br />
(CAN_TX_EID(12344))& CAN_NOR_TX_REQ,<br />
Txdata,datalen,tx_rx_no);<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 94<br />
/* Set request for Loopback mode */<br />
2004 Microchip Technology Inc.<br />
CAN1SetOperationMode(CAN_IDLE_CON & CAN_CAPTURE_DIS &<br />
CAN_MASTERCLOCK_1 &<br />
CAN_REQ_OPERMODE_LOOPBK);<br />
while(C1CTRLbits.OPMODE !=2);<br />
/* Wait till messageis transmitted completely */<br />
while(!CAN1IsTXReady(0))<br />
/* Wait till receive buffer contain valid message */<br />
while(!CAN1IsRXReady(0));<br />
/* Read received data fromreceive buffer and store it into<br />
user defined dataarray */<br />
CAN1ReceiveMessage(datareceived, datalen, tx_rx_no);<br />
while(1);<br />
return 0;<br />
}<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 95<br />
3.5 ADC12 FUNCTIONS<br />
This section contains a list of individual functions for the 12 bit ADC and an<br />
example of<br />
use of the functions. Functions may be implemented as macros.<br />
3.5.1 Individual Functions<br />
BusyADC12<br />
Description: This function returns the ADC conversion status.<br />
Include: adc12.h<br />
Prototype: char BusyADC12(void);<br />
Arguments: None<br />
DS51456B trang 96<br />
Ưu tiên ngắt ADC<br />
ADC_INT_PRI_0<br />
ADC_INT_PRI_1<br />
ADC_INT_PRI_2<br />
ADC_INT_PRI_3<br />
ADC_INT_PRI_4<br />
ADC_INT_PRI_5<br />
ADC_INT_PRI_6<br />
ADC_INT_PRI_7<br />
Trở lại giá trị: Không<br />
2004 Microchip Technology Inc<br />
Bình luận: Chức năng này sẽ xóa sạch các (ADIF) bit Cờ ngắt và sau đó đặt<br />
gián đoạn ưu tiên và cho phép / vô hiệu hóa ngắt.<br />
Source File: ConfigIntADC12.c<br />
Mã số Ví dụ: ConfigIntADC12 (ADC_INT_PRI_6 &<br />
ADC_INT_ENABLE);<br />
ConvertADC12<br />
Mô tả: Chức năng này bắt đầu chuyển đổi A / D.<br />
Bao gồm: adc12.h<br />
Prototype: void ConvertADC12 (void);<br />
Lập luận: Không<br />
Trở lại giá trị: Không<br />
Bình luận: Chức năng này sẽ xóa sạch các ADCON1 bit và do đó dừng lại lấy<br />
mẫu<br />
và bắt đầu chuyển đổi.<br />
Điều này chỉ xảy ra khi nguồn kích hoạt cho việc chuyển đổi A / D<br />
chọn làm bằng tay, bằng cách xóa ADCON1 bit.<br />
Source File: ConvertADC12.c<br />
Mã số Ví dụ: ConvertADC12 ();<br />
OpenADC12<br />
Mô tả: Chức năng này cấu hình ADC.<br />
Bao gồm: adc12.h<br />
Prototype: void OpenADC12 (int config1,<br />
int config2,<br />
int config3,<br />
int configport,<br />
int configscan)<br />
Đối số: config1 này chứa các thông số phải được cấu hình trong<br />
ADCON1 đăng ký theo quy định dưới đây:<br />
Mô-đun On / Off
Return Value: If the value of DONE is ‘0’, then ‘1’ is returned, indicating that<br />
the ADC<br />
is busy in conversion.<br />
If the value of DONE is ‘1’, then ‘0’ is returned, indicating that the ADC<br />
has completed conversion.<br />
Remarks: This function returns the complement of the ADCON1 bit<br />
status which indicates whether the ADC is busy in conversion.<br />
Source File: BusyADC12.c<br />
Code Example: while(BusyADC12());<br />
CloseADC12<br />
Description: This function turns off the ADC module and disables the ADC<br />
interrupts.<br />
Include: adc12.h<br />
Prototype: void CloseADC12(void);<br />
Arguments: None<br />
Return Value: None<br />
Remarks: This function first disables the ADC interrupt and then turns off the<br />
ADC<br />
module.The Interrupt Flag bit (ADIF) is also cleared.<br />
Source File: CloseADC12.c<br />
Code Example: CloseADC12();<br />
ConfigIntADC12<br />
Description: This function configures the ADC interrupt.<br />
Include: adc12.h<br />
Prototype: void ConfigIntADC12(unsigned int config);<br />
Arguments: config ADC interrupt priority and enable/disable information as<br />
defined below:<br />
ADC Interrupt enable/disable<br />
ADC_INT_ENABLE<br />
ADC_INT_DISABLE<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 96<br />
ADC Interrupt priority<br />
ADC_INT_PRI_0<br />
ADC_INT_PRI_1<br />
ADC_INT_PRI_2<br />
ADC_INT_PRI_3<br />
ADC_INT_PRI_4<br />
2004 Microchip Technology Inc.<br />
ADC_MODULE_ON<br />
ADC_MODULE_OFF<br />
Hoạt động chế độ nhàn rỗi<br />
ADC_IDLE_CONTINUE<br />
ADC_IDLE_STOP<br />
ConfigIntADC12 (Tiếp theo)<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 97<br />
Định dạng đầu ra kết quả<br />
ADC_FORMAT_SIGN_FRACT<br />
ADC_FORMAT_FRACT<br />
ADC_FORMAT_SIGN_INT<br />
ADC_FORMAT_INTG<br />
Chuyển đổi nguồn kích hoạt<br />
ADC_CLK_AUTO<br />
ADC_CLK_TMR<br />
ADC_CLK_INT0<br />
ADC_CLK_MANUAL<br />
Tự động lấy mẫu chọn<br />
ADC_AUTO_SAMPLING_ON<br />
ADC_AUTO_SAMPLING_OFF<br />
Mẫu cho phép<br />
ADC_SAMP_ON<br />
ADC_SAMP_OFF<br />
config2 này chứa các thông số phải được cấu hình trong<br />
ADCON2 đăng ký theo quy định dưới đây:<br />
Điện áp tham khảo<br />
ADC_VREF_AVDD_AVSS<br />
ADC_VREF_EXT_AVSS<br />
ADC_VREF_AVDD_EXT<br />
ADC_VREF_EXT_EXT<br />
Lựa chọn quét<br />
ADC_SCAN_ON<br />
ADC_SCAN_OFF<br />
Số mẫu giữa ngắt<br />
ADC_SAMPLES_PER_INT_1<br />
ADC_SAMPLES_PER_INT_2<br />
.....<br />
ADC_SAMPLES_PER_INT_15
ADC_INT_PRI_5<br />
ADC_INT_PRI_6<br />
ADC_INT_PRI_7<br />
Return Value: None<br />
Remarks: This function clears the Interrupt Flag (ADIF) bit and then sets the<br />
interrupt priority and enables/disables the interrupt.<br />
Source File: ConfigIntADC12.c<br />
Code Example: ConfigIntADC12(ADC_INT_PRI_6 &<br />
ADC_INT_ENABLE);<br />
ConvertADC12<br />
Description: This function starts A/D conversion.<br />
Include: adc12.h<br />
Prototype: void ConvertADC12(void);<br />
Arguments: None<br />
Return Value: None<br />
Remarks: This function clears the ADCON1 bit and thus stops<br />
sampling<br />
and starts conversion.<br />
This happens only when trigger source for the A/D conversion is<br />
selected as Manual, by clearing the ADCON1 bits.<br />
Source File: ConvertADC12.c<br />
Code Example: ConvertADC12();<br />
ADC_SAMPLES_PER_INT_16<br />
Chế độ đệm chọn<br />
ADC_ALT_BUF_ON<br />
ADC_ALT_BUF_OFF<br />
Chế độ mẫu thay thế đầu vào chọn<br />
ADC_ALT_INPUT_ON<br />
ADC_ALT_INPUT_OFF<br />
config3 này chứa các thông số phải được cấu hình trong<br />
ADCON3 đăng ký theo quy định dưới đây:<br />
Bit Thời gian tự động mẫu<br />
ADC_SAMPLE_TIME_0<br />
ADC_SAMPLE_TIME_1<br />
.....<br />
ADC_SAMPLE_TIME_30<br />
ADC_SAMPLE_TIME_31<br />
Chuyển đổi đồng hồ Nguồn chọn<br />
ADC_CONV_CLK_INTERNAL_RC<br />
ADC_CONV_CLK_SYSTEM<br />
OpenADC12 (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
OpenADC12<br />
DS51456B trang 98<br />
2004 Microchip Technology Inc<br />
Description: This function configures the ADC.<br />
Include: adc12.h<br />
Prototype: void OpenADC12(unsigned int config1,<br />
unsigned int config2,<br />
unsigned int config3,<br />
unsigned int configport,<br />
unsigned int configscan)<br />
Arguments: config1 This contains the parameters to be configured in the<br />
ADCON1 register as defined below:<br />
Module On/Off<br />
ADC_MODULE_ON<br />
ADC_MODULE_OFF<br />
Idle mode operation<br />
ADC_IDLE_CONTINUE<br />
ADC_IDLE_STOP<br />
ConfigIntADC12 (Continued)<br />
Đồng hồ chuyển đổi chọn<br />
ADC_CONV_CLK_Tcy2<br />
ADC_CONV_CLK_Tcy<br />
ADC_CONV_CLK_3Tcy2<br />
.....<br />
ADC_CONV_CLK_32Tcy<br />
configport này chứa pin chọn được cấu hình vào<br />
ADPCFG đăng ký theo quy định dưới đây:<br />
ENABLE_ALL_ANA<br />
ENABLE_ALL_DIG<br />
ENABLE_AN0_ANA<br />
ENABLE_AN1_ANA<br />
ENABLE_AN2_ANA<br />
.....<br />
ENABLE_AN15_ANA<br />
configscan này bao gồm các lựa chọn tham số quét là
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 97<br />
Result output format<br />
ADC_FORMAT_SIGN_FRACT<br />
ADC_FORMAT_FRACT<br />
ADC_FORMAT_SIGN_INT<br />
ADC_FORMAT_INTG<br />
Conversion trigger source<br />
ADC_CLK_AUTO<br />
ADC_CLK_TMR<br />
ADC_CLK_INT0<br />
ADC_CLK_MANUAL<br />
Auto sampling select<br />
ADC_AUTO_SAMPLING_ON<br />
ADC_AUTO_SAMPLING_OFF<br />
Sample enable<br />
ADC_SAMP_ON<br />
ADC_SAMP_OFF<br />
config2 This contains the parameters to be configured in the<br />
ADCON2 register as defined below:<br />
Voltage Reference<br />
ADC_VREF_AVDD_AVSS<br />
ADC_VREF_EXT_AVSS<br />
ADC_VREF_AVDD_EXT<br />
ADC_VREF_EXT_EXT<br />
Scan selection<br />
ADC_SCAN_ON<br />
ADC_SCAN_OFF<br />
Number of samples between interrupts<br />
ADC_SAMPLES_PER_INT_1<br />
ADC_SAMPLES_PER_INT_2<br />
.....<br />
ADC_SAMPLES_PER_INT_15<br />
ADC_SAMPLES_PER_INT_16<br />
Buffer mode select<br />
ADC_ALT_BUF_ON<br />
ADC_ALT_BUF_OFF<br />
Alternate Input Sample mode select<br />
ADC_ALT_INPUT_ON<br />
cấu hình vào sổ đăng ký theo quy định ADCSSL<br />
dưới đây:<br />
SCAN_NONE<br />
SCAN_ALL<br />
SKIP_SCAN_AN0<br />
SKIP_SCAN_AN1<br />
.....<br />
SKIP_SCAN_AN15<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này cấu hình ADC cho các thông số sau:<br />
Chế độ hoạt động, hành vi chế độ Sleep, dữ liệu o / p định dạng, mẫu CLK<br />
Nguồn, VREFsource, Số mẫu / int, đệm chế độ Fill, thay thế i / p<br />
mẫu mod, tự động thời gian mẫu, Convclock nguồn, Conv Đồng hồ Chọn<br />
bit, các bit Cảng Config kiểm soát.<br />
Source File: OpenADC12.c<br />
Mã số Ví dụ: OpenADC12 (ADC_MODULE_OFF &<br />
ADC_IDLE_CONTINUE &<br />
ADC_FORMAT_INTG &<br />
ADC_AUTO_SAMPLING_ON,<br />
ADC_VREF_AVDD_AVSS &<br />
ADC_SCAN_OFF &<br />
ADC_BUF_MODE_OFF &<br />
ADC_ALT_INPUT_ON &<br />
ADC_SAMPLES_PER_INT_15,<br />
ADC_SAMPLE_TIME_4 &<br />
ADC_CONV_CLK_SYSTEM &<br />
ADC_CONV_CLK_Tcy,<br />
ENABLE_AN0_ANA,<br />
SKIP_SCAN_AN1 &<br />
SKIP_SCAN_AN2 &<br />
SKIP_SCAN_AN5 &<br />
SKIP_SCAN_AN7);<br />
OpenADC12 (Tiếp theo)<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 99<br />
ReadADC12<br />
Mô tả: Chức năng này đọc ADC Bufferregister trong đó có các<br />
giá trị chuyển đổi.<br />
Bao gồm: adc12.h
ADC_ALT_INPUT_OFF<br />
config3 This contains the parameters to be configured in the<br />
ADCON3 register as defined below:<br />
Auto Sample Time bits<br />
ADC_SAMPLE_TIME_0<br />
ADC_SAMPLE_TIME_1<br />
.....<br />
ADC_SAMPLE_TIME_30<br />
ADC_SAMPLE_TIME_31<br />
Conversion Clock Source select<br />
ADC_CONV_CLK_INTERNAL_RC<br />
ADC_CONV_CLK_SYSTEM<br />
OpenADC12 (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
Nguyên mẫu: int ReadADC12 (unsigned char bufIndex);<br />
Đối số: bufIndex Đây là số lượng bộ đệm ADC mà là để được đọc.<br />
Trở lại giá trị: Không<br />
Bình luận: Chức năng này trả về nội dung ofthe ADC đệm đăng ký. Người sử<br />
dụng<br />
nên cung cấp bufIndexvalue giữa 0-15 để đảm bảo chính xác<br />
đọc của ADCBUF0 ADCBUFF để đăng ký.<br />
Source File: ReadADC12.c<br />
Mã số Ví dụ: kết quả int unsigned;<br />
kết quả = ReadADC12 (5);<br />
StopSampADC12<br />
Mô tả: Chức năng này giống hệt với ConvertADC12.<br />
Source File: #defineto ConvertADC12in adc12.h<br />
SetChanADC12<br />
Mô tả: Chức năng này đặt ra các yếu tố đầu vào tích cực và tiêu cực đối với mẫ<br />
ghép kênh A và B.<br />
Bao gồm: adc12.h<br />
DS51456B-page 98<br />
2004 Microchip Technology Inc.<br />
Prototype: void SetChanADC12 (kênh unsigned int);<br />
Conversion clock select<br />
ADC_CONV_CLK_Tcy2<br />
ADC_CONV_CLK_Tcy<br />
ADC_CONV_CLK_3Tcy2<br />
.....<br />
ADC_CONV_CLK_32Tcy<br />
configport This contains the pin select to be configured into the<br />
ADPCFG register as defined below:<br />
ENABLE_ALL_ANA<br />
ENABLE_ALL_DIG<br />
ENABLE_AN0_ANA<br />
ENABLE_AN1_ANA<br />
ENABLE_AN2_ANA<br />
.....<br />
ENABLE_AN15_ANA<br />
configscan This contains the scan select parameter to be<br />
configured into the ADCSSL register as defined<br />
below:<br />
SCAN_NONE<br />
SCAN_ALL<br />
SKIP_SCAN_AN0<br />
SKIP_SCAN_AN1<br />
Đối số: kênh này có chứa các lựa chọn tham số đầu vào được cấu hình<br />
vào ADCHS đăng ký theo quy định dưới đây:<br />
A / D kênh 0 tích cực i / p chọn cho MẪU A<br />
ADC_CH0_POS_SAMPLEA_AN0<br />
ADC_CH0_POS_SAMPLEA_AN1<br />
.....<br />
ADC_CH0_POS_SAMPLEA_AN15<br />
A / D kênh 0 âm i / p chọn cho MẪU A<br />
ADC_CH0_NEG_SAMPLEA_AN1<br />
ADC_CH0_NEG_SAMPLEA_NVREF<br />
A / D kênh 0 tích cực i / p chọn cho MẪU B<br />
ADC_CH0_POS_SAMPLEB_AN0<br />
ADC_CH0_POS_SAMPLEB_AN1<br />
.....<br />
ADC_CH0_POS_SAMPLEB_AN15<br />
A / D kênh 0 âm i / p chọn cho MẪU B<br />
ADC_CH0_NEG_SAMPLEB_AN1<br />
ADC_CH0_NEG_SAMPLEB_NVREF<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này cấu hình các yếu tố đầu vào cho Multiplexers mẫu A<br />
và B<br />
bằng văn bản cho đăng ký ADCHS.
.....<br />
SKIP_SCAN_AN15<br />
Return Value: None<br />
Remarks: This function configures the ADC for the following parameters:<br />
Operating mode, Sleep mode behavior, Data o/p format, Sample Clk<br />
Source, VREFsource, No of samples/int, Buffer Fill mode, Alternate i/p<br />
sample mod, Auto sample time, Convclock source, Conv Clock Select<br />
bits, Port Config Control bits.<br />
Source File: OpenADC12.c<br />
Code Example: OpenADC12(ADC_MODULE_OFF &<br />
ADC_IDLE_CONTINUE &<br />
ADC_FORMAT_INTG &<br />
ADC_AUTO_SAMPLING_ON,<br />
ADC_VREF_AVDD_AVSS &<br />
ADC_SCAN_OFF &<br />
ADC_BUF_MODE_OFF &<br />
ADC_ALT_INPUT_ON &<br />
ADC_SAMPLES_PER_INT_15,<br />
ADC_SAMPLE_TIME_4 &<br />
ADC_CONV_CLK_SYSTEM &<br />
ADC_CONV_CLK_Tcy,<br />
ENABLE_AN0_ANA,<br />
SKIP_SCAN_AN1 &<br />
SKIP_SCAN_AN2 &<br />
SKIP_SCAN_AN5 &<br />
SKIP_SCAN_AN7);<br />
OpenADC12 (Continued)<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 99<br />
ReadADC12<br />
Description: This function reads the ADC Bufferregister which contains the<br />
conversion value.<br />
Include: adc12.h<br />
Prototype: unsigned int ReadADC12(unsigned char bufIndex);<br />
Arguments: bufIndex This is the ADC buffer number which is to be read.<br />
Return Value: None<br />
Remarks: This function returns the contents ofthe ADC Buffer register. User<br />
should provide bufIndexvalue between 0 to 15 to ensure correct<br />
read of the ADCBUF0 to ADCBUFF register.<br />
Source File: SetChanADC12.c<br />
Mã số Ví dụ: SetChanADC12 (ADC_CH0_POS_SAMPLEA_AN4 &<br />
ADC_CH0_NEG_SAMPLEA_NVREF);<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 100 2004 Microchip Technology Inc<br />
3.5.2 Macros cá nhân<br />
EnableIntADC<br />
Mô tả: vĩ mô này cho phép ADC gián đoạn.<br />
Bao gồm: adc12.h<br />
Lập luận: Không<br />
Bình luận: Đây bộ vĩ mô ADC Interrupt Enable bit Interrupt Enable kiểm soát<br />
đăng ký.<br />
Mã số Ví dụ: EnableIntADC;<br />
DisableIntADC<br />
Mô tả: vĩ mô này vô hiệu hóa ADC gián đoạn.<br />
Bao gồm: adc12.h<br />
Lập luận: Không<br />
Bình luận: vĩ mô này xóa ADC ngắt Enablebit của Interrupt Enable kiểm soát<br />
đăng ký.<br />
Mã số Ví dụ: DisableIntADC;<br />
SetPriorityIntADC<br />
Mô tả: Điều này đặt ra ưu tiên vĩ mô cho ADC gián đoạn.<br />
Bao gồm: adc12.h<br />
Đối số: ưu tiên<br />
Bình luận: vĩ mô này đặt ADC ngắt bit ưu tiên của ngắt ưu tiên kiểm soát<br />
đăng ký.<br />
Mã số Ví dụ: SetPriorityIntADC (6);<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 101<br />
3.5.3 Ví dụ về sử dụng<br />
# xác định __dsPIC30F6014__<br />
# include<br />
# include<br />
int Channel, PinConfig, Scanselect, Adcon3_reg, Adcon2_reg,<br />
Adcon1_reg;<br />
int main (void)<br />
{
Source File: ReadADC12.c<br />
Code Example: unsigned int result;<br />
result = ReadADC12(5);<br />
StopSampADC12<br />
Description: This function is identical to ConvertADC12.<br />
Source File: #defineto ConvertADC12in adc12.h<br />
SetChanADC12<br />
Description: This function sets the positive and negative inputs for sample<br />
multiplexers A and B.<br />
Include: adc12.h<br />
Prototype: void SetChanADC12(unsigned int channel);<br />
Arguments: channel This contains the input select parameter to be configured<br />
into ADCHS register as defined below:<br />
A/D Channel 0 positive i/p select for SAMPLE A<br />
ADC_CH0_POS_SAMPLEA_AN0<br />
ADC_CH0_POS_SAMPLEA_AN1<br />
.....<br />
ADC_CH0_POS_SAMPLEA_AN15<br />
A/D Channel 0 negative i/p select for SAMPLE A<br />
ADC_CH0_NEG_SAMPLEA_AN1<br />
ADC_CH0_NEG_SAMPLEA_NVREF<br />
A/D Channel 0 positive i/p select for SAMPLE B<br />
ADC_CH0_POS_SAMPLEB_AN0<br />
ADC_CH0_POS_SAMPLEB_AN1<br />
.....<br />
ADC_CH0_POS_SAMPLEB_AN15<br />
A/D Channel 0 negative i/p select for SAMPLE B<br />
ADC_CH0_NEG_SAMPLEB_AN1<br />
ADC_CH0_NEG_SAMPLEB_NVREF<br />
Return Value: None<br />
Remarks: This function configures the inputs for the sample multiplexers A and<br />
B<br />
by writing to the ADCHS register.<br />
Source File: SetChanADC12.c<br />
Code Example: SetChanADC12(ADC_CH0_POS_SAMPLEA_AN4 &<br />
ADC_CH0_NEG_SAMPLEA_NVREF);<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
int kết quả [20], i;<br />
ADCON1bits.ADON = 0; / * Tắt ADC * /<br />
Kênh = ADC_CH0_POS_SAMPLEA_AN4 &<br />
ADC_CH0_NEG_SAMPLEA_NVREF &<br />
ADC_CH0_POS_SAMPLEB_AN2 &<br />
ADC_CH0_NEG_SAMPLEB_AN1;<br />
SetChanADC12 (Channel);<br />
ConfigIntADC12 (ADC_INT_DISABLE);<br />
PinConfig = ENABLE_AN4_ANA;<br />
Scanselect = SKIP_SCAN_AN2 & SKIP_SCAN_AN5 &<br />
SKIP_SCAN_AN9 & SKIP_SCAN_AN10 &<br />
SKIP_SCAN_AN14 & SKIP_SCAN_AN15;<br />
Adcon3_reg = ADC_SAMPLE_TIME_10 &<br />
ADC_CONV_CLK_SYSTEM &<br />
ADC_CONV_CLK_13Tcy;<br />
Adcon2_reg = ADC_VREF_AVDD_AVSS &<br />
ADC_SCAN_OFF &<br />
ADC_ALT_BUF_OFF &<br />
ADC_ALT_INPUT_OFF &<br />
ADC_SAMPLES_PER_INT_16;<br />
Adcon1_reg = ADC_MODULE_ON &<br />
ADC_IDLE_CONTINUE &<br />
ADC_FORMAT_INTG &<br />
ADC_CLK_MANUAL &<br />
ADC_AUTO_SAMPLING_OFF;<br />
OpenADC12 (Adcon1_reg, Adcon2_reg,<br />
Adcon3_reg, PinConfig, Scanselect);<br />
i = 0;<br />
trong khi (i
DS51456B-page 100<br />
3.5.2 Individual Macros<br />
EnableIntADC<br />
2004 Microchip Technology Inc.<br />
Description: This macro enables the ADC interrupt.<br />
Include: adc12.h<br />
Arguments: None<br />
Remarks: This macro sets ADC Interrupt Enable bit of Interrupt Enable Control<br />
register.<br />
Code Example: EnableIntADC;<br />
DisableIntADC<br />
Description: This macro disables the ADC interrupt.<br />
Include: adc12.h<br />
Arguments: None<br />
Remarks: This macro clears ADC Interrupt Enablebit of Interrupt Enable<br />
Control<br />
register.<br />
Code Example: DisableIntADC;<br />
SetPriorityIntADC<br />
Description: This macro sets priority for ADC interrupt.<br />
Include: adc12.h<br />
Arguments: priority<br />
Remarks: This macro sets ADC Interrupt Priority bits of Interrupt Priority<br />
Control<br />
register.<br />
Code Example: SetPriorityIntADC(6);<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 101<br />
3.5.3 Example of Use<br />
#define __dsPIC30F6014__<br />
#include <br />
#include<br />
unsigned int Channel, PinConfig, Scanselect, Adcon3_reg, Adcon2_reg,<br />
Adcon1_reg;<br />
int main(void)<br />
{<br />
unsigned int result[20], i;<br />
ADCON1bits.ADON = 0; /* turn off ADC */<br />
Channel = ADC_CH0_POS_SAMPLEA_AN4 &<br />
ADC_CH0_NEG_SAMPLEA_NVREF &<br />
ADC_CH0_POS_SAMPLEB_AN2&<br />
}<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 102<br />
3,6 ADC10 chức năng<br />
2004 Microchip Technology Inc<br />
Phần này bao gồm một danh sách các chức năng cá nhân cho 10 bit ADC và<br />
một ví dụ về<br />
sử dụng các chức năng. Chức năng có thể được thực hiện như các macro.<br />
3.6.1 Chức năng cá nhân<br />
BusyADC10<br />
Mô tả: Chức năng này trả về tình trạng chuyển đổi ADC.<br />
Bao gồm: adc10.h<br />
Prototype: char BusyADC10 (void);<br />
Lập luận: Không<br />
Quay trở lại giá trị: Nếu giá trị của DONE là "0", sau đó "1" được trả lại, chỉ ra<br />
rằng ADC<br />
đang bận rộn trong việc chuyển đổi.<br />
Nếu giá trị của DONE là "1", sau đó "0" được trả lại, chỉ ra rằng ADC<br />
đã hoàn thành chuyển đổi.<br />
Bình luận: Chức năng này trả về bổ sung của ADCON1 bit<br />
tình trạng mà chỉ ra cho dù ADC là bận rộn trong việc chuyển đổi.<br />
Source File: BusyADC10.c<br />
Mã số Ví dụ: trong khi (BusyADC10 ());<br />
CloseADC10<br />
Mô tả: Chức năng này sẽ tắt các mô-đun ADC và vô hiệu hóa các ngắt ADC.<br />
Bao gồm: adc10.h<br />
Prototype: void CloseADC10 (void);<br />
Lập luận: Không<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này đầu tiên vô hiệu hóa các ADC gián đoạn và sau đó tắt<br />
ADC<br />
module.The Cờ ngắt bit (ADIF) cũng sẽ bị xóa.<br />
Source File: CloseADC10.c<br />
Mã số Ví dụ: CloseADC10 ();<br />
ConfigIntADC10<br />
Mô tả: Chức năng này cấu hình ADC gián đoạn.<br />
Bao gồm: adc10.h<br />
Prototype: void ConfigIntADC10 (int config);<br />
Lập luận: config ADC gián đoạn ưu tiên và bật / tắt thông tin<br />
quy định dưới đây:
ADC_CH0_NEG_SAMPLEB_AN1;<br />
SetChanADC12(Channel);<br />
ConfigIntADC12(ADC_INT_DISABLE);<br />
PinConfig = ENABLE_AN4_ANA;<br />
Scanselect = SKIP_SCAN_AN2 & SKIP_SCAN_AN5 &<br />
SKIP_SCAN_AN9 & SKIP_SCAN_AN10 &<br />
SKIP_SCAN_AN14 & SKIP_SCAN_AN15 ;<br />
Adcon3_reg = ADC_SAMPLE_TIME_10 &<br />
ADC_CONV_CLK_SYSTEM &<br />
ADC_CONV_CLK_13Tcy;<br />
Adcon2_reg = ADC_VREF_AVDD_AVSS &<br />
ADC_SCAN_OFF &<br />
ADC_ALT_BUF_OFF &<br />
ADC_ALT_INPUT_OFF &<br />
ADC_SAMPLES_PER_INT_16;<br />
Adcon1_reg = ADC_MODULE_ON &<br />
ADC_IDLE_CONTINUE &<br />
ADC_FORMAT_INTG &<br />
ADC_CLK_MANUAL &<br />
ADC_AUTO_SAMPLING_OFF;<br />
OpenADC12(Adcon1_reg, Adcon2_reg,<br />
Adcon3_reg,PinConfig, Scanselect);<br />
i = 0;<br />
while( i
3.6 ADC10 FUNCTIONS<br />
This section contains a list of individual functions for the 10 bit ADC and an<br />
example of<br />
use of the functions. Functions may be implemented as macros.<br />
3.6.1 Individual Functions<br />
BusyADC10<br />
Description: This function returns the ADC conversion status.<br />
Include: adc10.h<br />
Prototype: char BusyADC10(void);<br />
Arguments: None<br />
Return Value: If the value of DONE is ‘0’, then ‘1’ is returned, indicating that<br />
the ADC<br />
is busy in conversion.<br />
If the value of DONE is ‘1’, then ‘0’ is returned, indicating that the ADC<br />
has completed conversion.<br />
Remarks: This function returns the complement of the ADCON1 bit<br />
status which indicates whether the ADC is busy in conversion.<br />
Source File: BusyADC10.c<br />
Code Example: while(BusyADC10());<br />
CloseADC10<br />
Description: This function turns off the ADC module and disables the ADC<br />
interrupts.<br />
Include: adc10.h<br />
Prototype: void CloseADC10(void);<br />
Arguments: None<br />
Return Value: None<br />
Remarks: This function first disables the ADC interrupt and then turns off the<br />
ADC<br />
module.The Interrupt Flag bit (ADIF) is also cleared.<br />
Source File: CloseADC10.c<br />
Code Example: CloseADC10();<br />
ConfigIntADC10<br />
Description: This function configures the ADC interrupt.<br />
Include: adc10.h<br />
Prototype: void ConfigIntADC10(unsigned int config);<br />
Arguments: config ADC interrupt priority and enable/disable information as<br />
defined below:<br />
ADC Interrupt enable/disable<br />
ADC_INT_ENABLE<br />
ADC_INT_DISABLE<br />
ADC Interrupt priority<br />
int configscan)<br />
Đối số: config1 này chứa các thông số phải được cấu hình trong<br />
ADCON1 đăng ký theo quy định dưới đây:<br />
Mô-đun On / Off<br />
ADC_MODULE_ON<br />
ADC_MODULE_OFF<br />
Hoạt động chế độ nhàn rỗi<br />
ADC_IDLE_CONTINUE<br />
ADC_IDLE_STOP<br />
Định dạng đầu ra kết quả<br />
ADC_FORMAT_SIGN_FRACT<br />
ADC_FORMAT_FRACT<br />
ADC_FORMAT_SIGN_INT<br />
ADC_FORMAT_INTG<br />
Chuyển đổi nguồn kích hoạt<br />
ADC_CLK_AUTO<br />
ADC_CLK_MPWM<br />
ADC_CLK_TMR<br />
ADC_CLK_INT0<br />
ADC_CLK_MANUAL<br />
ConfigIntADC10 (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 104 2004 Microchip Technology Inc<br />
Tự động lấy mẫu chọn<br />
ADC_AUTO_SAMPLING_ON<br />
ADC_AUTO_SAMPLING_OFF<br />
Đồng thời lấy mẫu<br />
ADC_SAMPLE_SIMULTANEOUS<br />
ADC_SAMPLE_INDIVIDUAL<br />
Mẫu cho phép<br />
ADC_SAMP_ON<br />
ADC_SAMP_OFF<br />
config2 này chứa các thông số phải được cấu hình trong<br />
ADCON2 đăng ký theo quy định dưới đây:<br />
Điện áp tham khảo<br />
ADC_VREF_AVDD_AVSS<br />
ADC_VREF_EXT_AVSS
ADC_INT_PRI_0<br />
ADC_INT_PRI_1<br />
ADC_INT_PRI_2<br />
ADC_INT_PRI_3<br />
ADC_INT_PRI_4<br />
ADC_INT_PRI_5<br />
ADC_INT_PRI_6<br />
ADC_INT_PRI_7<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 103<br />
Return Value: None<br />
Remarks: This function clears the Interrupt Flag (ADIF) bit and then sets the<br />
interrupt priority and enables/disables the interrupt.<br />
Source File: ConfigIntADC10.c<br />
Code Example: ConfigIntADC10(ADC_INT_PRI_3 &<br />
ADC_INT_DISABLE);<br />
ConvertADC10<br />
Description: This function starts the A/D conversion.<br />
Include: adc10.h<br />
Prototype: void ConvertADC10(void);<br />
Arguments: None<br />
Return Value: None<br />
Remarks: This function clears the ADCON1bit and thus stops<br />
sampling<br />
and starts conversion.<br />
This happens only when trigger source for the A/D conversion is<br />
selected as Manual, by clearing the ADCON1 bits.<br />
Source File: ConvertADC10.c<br />
Code Example: ConvertADC10();<br />
OpenADC10<br />
Description: This function configures the ADC.<br />
Include: adc10.h<br />
Prototype: void OpenADC10(unsigned int config1,<br />
unsigned int config2,<br />
unsigned int config3,<br />
unsigned int configport,<br />
unsigned int configscan)<br />
Arguments: config1 This contains the parameters to be configured in the<br />
ADCON1 register as defined below:<br />
ADC_VREF_AVDD_EXT<br />
ADC_VREF_EXT_EXT<br />
Lựa chọn quét<br />
ADC_SCAN_ON<br />
ADC_SCAN_OFF<br />
Kênh A / D sử dụng<br />
ADC_CONVERT_CH0123<br />
ADC_CONVERT_CH01<br />
ADC_CONVERT_CH0<br />
Số mẫu giữa ngắt<br />
ADC_SAMPLES_PER_INT_1<br />
ADC_SAMPLES_PER_INT_2<br />
.....<br />
ADC_SAMPLES_PER_INT_15<br />
ADC_SAMPLES_PER_INT_16<br />
Chế độ đệm chọn<br />
ADC_ALT_BUF_ON<br />
ADC_ALT_BUF_OFF<br />
Chế độ mẫu thay thế đầu vào chọn<br />
ADC_ALT_INPUT_ON<br />
ADC_ALT_INPUT_OFF<br />
config3 này chứa các thông số phải được cấu hình trong<br />
ADCON3 đăng ký theo quy định dưới đây:<br />
Bit Thời gian tự động mẫu<br />
ADC_SAMPLE_TIME_0<br />
ADC_SAMPLE_TIME_1<br />
.....<br />
ADC_SAMPLE_TIME_30<br />
ADC_SAMPLE_TIME_31<br />
Chuyển đổi đồng hồ Nguồn chọn<br />
ADC_CONV_CLK_INTERNAL_RC<br />
ADC_CONV_CLK_SYSTEM<br />
Đồng hồ chuyển đổi chọn<br />
ADC_CONV_CLK_Tcy2<br />
ADC_CONV_CLK_Tcy<br />
ADC_CONV_CLK_3Tcy2<br />
.....<br />
ADC_CONV_CLK_32Tcy<br />
OpenADC10 (Tiếp theo)
Module On/Off<br />
ADC_MODULE_ON<br />
ADC_MODULE_OFF<br />
Idle mode operation<br />
ADC_IDLE_CONTINUE<br />
ADC_IDLE_STOP<br />
Result output format<br />
ADC_FORMAT_SIGN_FRACT<br />
ADC_FORMAT_FRACT<br />
ADC_FORMAT_SIGN_INT<br />
ADC_FORMAT_INTG<br />
Conversion trigger source<br />
ADC_CLK_AUTO<br />
ADC_CLK_MPWM<br />
ADC_CLK_TMR<br />
ADC_CLK_INT0<br />
ADC_CLK_MANUAL<br />
ConfigIntADC10 (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 104 2004 Microchip Technology Inc.<br />
Auto sampling select<br />
ADC_AUTO_SAMPLING_ON<br />
ADC_AUTO_SAMPLING_OFF<br />
Simultaneous Sampling<br />
ADC_SAMPLE_SIMULTANEOUS<br />
ADC_SAMPLE_INDIVIDUAL<br />
Sample enable<br />
ADC_SAMP_ON<br />
ADC_SAMP_OFF<br />
config2 This contains the parameters to be configured in the<br />
ADCON2 register as defined below:<br />
Voltage Reference<br />
ADC_VREF_AVDD_AVSS<br />
ADC_VREF_EXT_AVSS<br />
ADC_VREF_AVDD_EXT<br />
ADC_VREF_EXT_EXT<br />
Scan selection<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 105<br />
configport này chứa các selectto pin được cấu hình vào<br />
ADPCFG đăng ký theo quy định dưới đây:<br />
ENABLE_ALL_ANA<br />
ENABLE_ALL_DIG<br />
ENABLE_AN0_ANA<br />
ENABLE_AN1_ANA<br />
ENABLE_AN2_ANA<br />
.....<br />
ENABLE_AN15_ANA<br />
configscan này bao gồm các lựa chọn tham số quét là<br />
cấu hình vào sổ đăng ký theo quy định ADCSSL<br />
dưới đây:<br />
SCAN_NONE<br />
SCAN_ALL<br />
SKIP_SCAN_AN0<br />
SKIP_SCAN_AN1<br />
.....<br />
SKIP_SCAN_AN15<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này cấu hình ADC cho các thông số sau:<br />
Chế độ hoạt động, hành vi chế độ Sleep, dữ liệu o / p định dạng, mẫu CLK<br />
Nguồn, VREFsource, Số mẫu / int, đệm chế độ Fill, thay thế i / p<br />
mẫu mod, tự động thời gian mẫu, Chuyển đổi nguồn đồng hồ, Đồng hồ Chọn<br />
Conv<br />
bit, các bit Cảng Config kiểm soát.<br />
Source File: OpenADC10.c<br />
Mã số Ví dụ: OpenADC10 (ADC_MODULE_OFF &<br />
ADC_IDLE_STOP &<br />
ADC_FORMAT_SIGN_FRACT &<br />
ADC_CLK_INT0 &<br />
ADC_SAMPLE_INDIVIDUAL &<br />
ADC_AUTO_SAMPLING_ON,<br />
ADC_VREF_AVDD_AVSS &<br />
ADC_SCAN_OFF &<br />
ADC_BUF_MODE_OFF &<br />
ADC_ALT_INPUT_ON &<br />
ADC_CONVERT_CH0 &<br />
ADC_SAMPLES_PER_INT_10,
ADC_SCAN_ON<br />
ADC_SCAN_OFF<br />
A/D channels utilized<br />
ADC_CONVERT_CH0123<br />
ADC_CONVERT_CH01<br />
ADC_CONVERT_CH0<br />
Number of samples between interrupts<br />
ADC_SAMPLES_PER_INT_1<br />
ADC_SAMPLES_PER_INT_2<br />
.....<br />
ADC_SAMPLES_PER_INT_15<br />
ADC_SAMPLES_PER_INT_16<br />
Buffer mode select<br />
ADC_ALT_BUF_ON<br />
ADC_ALT_BUF_OFF<br />
Alternate Input Sample mode select<br />
ADC_ALT_INPUT_ON<br />
ADC_ALT_INPUT_OFF<br />
config3 This contains the parameters to be configured in the<br />
ADCON3 register as defined below:<br />
Auto Sample Time bits<br />
ADC_SAMPLE_TIME_0<br />
ADC_SAMPLE_TIME_1<br />
.....<br />
ADC_SAMPLE_TIME_30<br />
ADC_SAMPLE_TIME_31<br />
Conversion Clock Source select<br />
ADC_CONV_CLK_INTERNAL_RC<br />
ADC_CONV_CLK_SYSTEM<br />
Conversion clock select<br />
ADC_CONV_CLK_Tcy2<br />
ADC_CONV_CLK_Tcy<br />
ADC_CONV_CLK_3Tcy2<br />
.....<br />
ADC_CONV_CLK_32Tcy<br />
OpenADC10 (Continued)<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 105<br />
configport This contains the pin selectto be configured into the<br />
ADC_SAMPLE_TIME_4 &<br />
ADC_CONV_CLK_SYSTEM &<br />
ADC_CONV_CLK_Tcy,<br />
ENABLE_AN1_ANA,<br />
SKIP_SCAN_AN0 &<br />
SKIP_SCAN_AN3 &<br />
SKIP_SCAN_AN4 &<br />
SKIP_SCAN_AN5);<br />
OpenADC10 (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 106<br />
ReadADC10<br />
2004 Microchip Technology Inc<br />
Mô tả: Chức năng này đọc ADC Bufferregister trong đó có các<br />
giá trị chuyển đổi.<br />
Bao gồm: adc10.h<br />
Nguyên mẫu: int ReadADC10 (unsigned char bufIndex);<br />
Đối số: bufIndex Đây là số lượng bộ đệm ADC mà là để được đọc.<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này trả về các nội dung của đăng ký ADC đệm. Người sử<br />
dụng<br />
nên cung cấp bufIndexvalue giữa "0" đến "15" để đảm bảo chính xác<br />
đọc của ADCBUF0 để ADCBUFF.<br />
Source File: ReadADC10.c<br />
Mã số Ví dụ: kết quả int unsigned;<br />
kết quả = ReadADC10 (3);<br />
StopSampADC10<br />
Mô tả: Chức năng này giống hệt với ConvertADC10.<br />
Source File: #defineto ConvertADC10in adc10.h<br />
SetChanADC10<br />
Mô tả: Chức năng này đặt ra các yếu tố đầu vào tích cực và tiêu cực đối với mẫ<br />
ghép kênh A và B.<br />
Bao gồm: adc10.h<br />
Prototype: void SetChanADC10 (kênh unsigned int);<br />
Đối số: kênh này có chứa các selectparameter đầu vào phải được cấu hình<br />
vào ADCHS đăng ký theo quy định dưới đây:<br />
A / D Channel 1, 2, 3 đầu vào âm cho mẫu A<br />
ADC_CHX_NEG_SAMPLEA_AN9AN10AN11<br />
ADC_CHX_NEG_SAMPLEA_AN6AN7AN8
ADPCFG register as defined below:<br />
ENABLE_ALL_ANA<br />
ENABLE_ALL_DIG<br />
ENABLE_AN0_ANA<br />
ENABLE_AN1_ANA<br />
ENABLE_AN2_ANA<br />
.....<br />
ENABLE_AN15_ANA<br />
configscan This contains the scan select parameter to be<br />
configured into the ADCSSL register as defined<br />
below:<br />
SCAN_NONE<br />
SCAN_ALL<br />
SKIP_SCAN_AN0<br />
SKIP_SCAN_AN1<br />
.....<br />
SKIP_SCAN_AN15<br />
Return Value: None<br />
Remarks: This function configures the ADC for the following parameters:<br />
Operating mode, Sleep mode behavior, Data o/p format, Sample Clk<br />
Source, VREFsource, No of samples/int, Buffer Fill mode, Alternate i/p<br />
sample mod, Auto sample time, Conv clock source, Conv Clock Select<br />
bits, Port Config Control bits.<br />
Source File: OpenADC10.c<br />
Code Example: OpenADC10(ADC_MODULE_OFF &<br />
ADC_IDLE_STOP &<br />
ADC_FORMAT_SIGN_FRACT &<br />
ADC_CLK_INT0 &<br />
ADC_SAMPLE_INDIVIDUAL &<br />
ADC_AUTO_SAMPLING_ON,<br />
ADC_VREF_AVDD_AVSS &<br />
ADC_SCAN_OFF &<br />
ADC_BUF_MODE_OFF &<br />
ADC_ALT_INPUT_ON &<br />
ADC_CONVERT_CH0 &<br />
ADC_SAMPLES_PER_INT_10,<br />
ADC_SAMPLE_TIME_4 &<br />
ADC_CONV_CLK_SYSTEM &<br />
ADC_CONV_CLK_Tcy,<br />
ADC_CHX_NEG_SAMPLEA_NVREF<br />
A / D Channel 1, 2, 3 đầu vào âm cho mẫu B<br />
ADC_CHX_NEG_SAMPLEB_AN9AN10AN11<br />
ADC_CHX_NEG_SAMPLEB_AN6AN7AN8<br />
ADC_CHX_NEG_SAMPLEB_NVREF<br />
A / D Channel 1, 2, 3 đầu vào của mẫu A<br />
ADC_CHX_POS_SAMPLEA_AN3AN4AN5<br />
ADC_CHX_POS_SAMPLEA_AN0AN1AN2<br />
A / D Channel 1, 2, 3 đầu vào của mẫu B<br />
ADC_CHX_POS_SAMPLEA_AN3AN4AN5<br />
ADC_CHX_POS_SAMPLEB_AN0AN1AN2<br />
A / D kênh 0 tích cực i / p chọn cho mẫu A<br />
ADC_CH0_POS_SAMPLEA_AN0<br />
ADC_CH0_POS_SAMPLEA_AN1<br />
.....<br />
ADC_CH0_POS_SAMPLEA_AN15<br />
A / D kênh 0 âm i / p chọn cho mẫu A<br />
ADC_CH0_NEG_SAMPLEA_AN1<br />
ADC_CH0_NEG_SAMPLEA_NVREF<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 107<br />
3.6.2 Macros cá nhân<br />
A / D kênh 0 tích cực i / p chọn cho mẫu B<br />
ADC_CH0_POS_SAMPLEB_AN0<br />
ADC_CH0_POS_SAMPLEB_AN1<br />
.....<br />
ADC_CH0_POS_SAMPLEB_AN15<br />
A / D kênh 0 âm i / p chọn cho mẫu B<br />
ADC_CH0_NEG_SAMPLEB_AN1<br />
ADC_CH0_NEG_SAMPLEB_NVREF<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này cấu hình ghép kênh đầu vào cho mẫu A và B bằng<br />
bằng văn bản cho đăng ký ADCHS.<br />
Source File: SetChanADC10.c<br />
Mã số Ví dụ: SetChanADC10 (ADC_CH0_POS_SAMPLEA_AN0 &<br />
ADC_CH0_NEG_SAMPLEA_NVREF);<br />
EnableIntADC<br />
Mô tả: vĩ mô này cho phép ADC gián đoạn.<br />
Bao gồm: adc10.h
ENABLE_AN1_ANA,<br />
SKIP_SCAN_AN0 &<br />
SKIP_SCAN_AN3 &<br />
SKIP_SCAN_AN4 &<br />
SKIP_SCAN_AN5);<br />
OpenADC10 (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 106 2004 Microchip Technology Inc.<br />
ReadADC10<br />
Description: This function reads the ADC Bufferregister which contains the<br />
conversion value.<br />
Include: adc10.h<br />
Prototype: unsigned int ReadADC10(unsigned char bufIndex);<br />
Arguments: bufIndex This is the ADC buffer number which is to be read.<br />
Return Value: None<br />
Remarks: This function returns the contents of the ADC Buffer register. User<br />
should provide bufIndexvalue between ‘0’ to ‘15’ to ensure correct<br />
read of the ADCBUF0 to ADCBUFF.<br />
Source File: ReadADC10.c<br />
Code Example: unsigned int result;<br />
result = ReadADC10(3);<br />
StopSampADC10<br />
Description: This function is identical to ConvertADC10.<br />
Source File: #defineto ConvertADC10in adc10.h<br />
SetChanADC10<br />
Description: This function sets the positive and negative inputs for the sample<br />
multiplexers A and B.<br />
Include: adc10.h<br />
Prototype: void SetChanADC10(unsigned int channel);<br />
Arguments: channel This contains the input selectparameter to be configured<br />
into the ADCHS register as defined below:<br />
A/D Channel 1, 2, 3 Negative input for Sample A<br />
ADC_CHX_NEG_SAMPLEA_AN9AN10AN11<br />
ADC_CHX_NEG_SAMPLEA_AN6AN7AN8<br />
ADC_CHX_NEG_SAMPLEA_NVREF<br />
A/D Channel 1, 2, 3 Negative input for Sample B<br />
ADC_CHX_NEG_SAMPLEB_AN9AN10AN11<br />
Lập luận: Không<br />
Bình luận: Đây bộ vĩ mô ADC Interrupt Enable bit Interrupt Enable kiểm soát<br />
đăng ký.<br />
Mã số Ví dụ: EnableIntADC;<br />
DisableIntADC<br />
Mô tả: vĩ mô này vô hiệu hóa ADC gián đoạn.<br />
Bao gồm: adc10.h<br />
Lập luận: Không<br />
Bình luận: vĩ mô này xóa ADC ngắt Enablebit của Interrupt Enable kiểm soát<br />
đăng ký.<br />
Mã số Ví dụ: DisableIntADC;<br />
SetPriorityIntADC<br />
Mô tả: Điều này đặt ra ưu tiên vĩ mô cho ADC gián đoạn.<br />
Bao gồm: adc10.h<br />
Đối số: ưu tiên<br />
Bình luận: vĩ mô này đặt ADC ngắt bit ưu tiên của ngắt ưu tiên kiểm soát<br />
đăng ký.<br />
Mã số Ví dụ: SetPriorityIntADC (2);<br />
SetChanADC10 (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 108 2004 Microchip Technology Inc<br />
3.6.3 Ví dụ về sử dụng<br />
# xác định __dsPIC30F6010__<br />
# include<br />
# include<br />
int Channel, PinConfig, Scanselect, Adcon3_reg, Adcon2_reg,<br />
Adcon1_reg;<br />
int main (void)<br />
{<br />
int kết quả [20], i;<br />
ADCON1bits.ADON = 0; / * Tắt ADC * /<br />
Kênh = ADC_CH0_POS_SAMPLEA_AN4 &<br />
ADC_CH0_NEG_SAMPLEA_NVREF &<br />
ADC_CH0_POS_SAMPLEB_AN2 &<br />
ADC_CH0_NEG_SAMPLEB_AN1;<br />
SetChanADC1 (Channel);<br />
ConfigIntADC10 (ADC_INT_DISABLE);
ADC_CHX_NEG_SAMPLEB_AN6AN7AN8<br />
ADC_CHX_NEG_SAMPLEB_NVREF<br />
A/D Channel 1, 2, 3 Positive input for Sample A<br />
ADC_CHX_POS_SAMPLEA_AN3AN4AN5<br />
ADC_CHX_POS_SAMPLEA_AN0AN1AN2<br />
A/D Channel 1, 2, 3 Positive input for Sample B<br />
ADC_CHX_POS_SAMPLEA_AN3AN4AN5<br />
ADC_CHX_POS_SAMPLEB_AN0AN1AN2<br />
A/D Channel 0 positive i/p select for Sample A<br />
ADC_CH0_POS_SAMPLEA_AN0<br />
ADC_CH0_POS_SAMPLEA_AN1<br />
.....<br />
ADC_CH0_POS_SAMPLEA_AN15<br />
A/D Channel 0 negative i/p select for Sample A<br />
ADC_CH0_NEG_SAMPLEA_AN1<br />
ADC_CH0_NEG_SAMPLEA_NVREF<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 107<br />
3.6.2 Individual Macros<br />
A/D Channel 0 positive i/p select for Sample B<br />
ADC_CH0_POS_SAMPLEB_AN0<br />
ADC_CH0_POS_SAMPLEB_AN1<br />
.....<br />
ADC_CH0_POS_SAMPLEB_AN15<br />
A/D Channel 0 negative i/p select for Sample B<br />
ADC_CH0_NEG_SAMPLEB_AN1<br />
ADC_CH0_NEG_SAMPLEB_NVREF<br />
Return Value: None<br />
Remarks: This function configures the inputs for sample multiplexers A and B<br />
by<br />
writing to ADCHS register.<br />
Source File: SetChanADC10.c<br />
Code Example: SetChanADC10(ADC_CH0_POS_SAMPLEA_AN0 &<br />
ADC_CH0_NEG_SAMPLEA_NVREF);<br />
EnableIntADC<br />
Description: This macro enables the ADC interrupt.<br />
Include: adc10.h<br />
Arguments: None<br />
Remarks: This macro sets ADC Interrupt Enable bit of Interrupt Enable Control<br />
PinConfig = ENABLE_AN4_ANA;<br />
Scanselect = SKIP_SCAN_AN2 & SKIP_SCAN_AN5 &<br />
SKIP_SCAN_AN9 & SKIP_SCAN_AN10 &<br />
SKIP_SCAN_AN14 & SKIP_SCAN_AN15;<br />
Adcon3_reg = ADC_SAMPLE_TIME_10 &<br />
ADC_CONV_CLK_SYSTEM &<br />
ADC_CONV_CLK_13Tcy;<br />
Adcon2_reg = ADC_VREF_AVDD_AVSS &<br />
ADC_SCAN_OFF &<br />
ADC_ALT_BUF_OFF &<br />
ADC_ALT_INPUT_OFF &<br />
ADC_CONVERT_CH0123 &<br />
ADC_SAMPLES_PER_INT_16;<br />
Adcon1_reg = ADC_MODULE_ON &<br />
ADC_IDLE_CONTINUE &<br />
ADC_FORMAT_INTG &<br />
ADC_CLK_MANUAL &<br />
ADC_SAMPLE_SIMULTANEOUS &<br />
ADC_AUTO_SAMPLING_OFF;<br />
OpenADC10 (Adcon1_reg, Adcon2_reg,<br />
Adcon3_reg, PinConfig, Scanselect);<br />
i = 0;<br />
trong khi (i
egister.<br />
Code Example: EnableIntADC;<br />
DisableIntADC<br />
Description: This macro disables the ADC interrupt.<br />
Include: adc10.h<br />
Arguments: None<br />
Remarks: This macro clears ADC Interrupt Enablebit of Interrupt Enable<br />
Control<br />
register.<br />
Code Example: DisableIntADC;<br />
SetPriorityIntADC<br />
Description: This macro sets priority for ADC interrupt.<br />
Include: adc10.h<br />
Arguments: priority<br />
Remarks: This macro sets ADC Interrupt Priority bits of Interrupt Priority<br />
Control<br />
register.<br />
Code Example: SetPriorityIntADC(2);<br />
SetChanADC10 (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
3.7.1 Chức năng cá nhân<br />
CloseTimer1<br />
CloseTimer2<br />
CloseTimer3<br />
CloseTimer4<br />
CloseTimer5<br />
Mô tả: Chức năng này sẽ tắt các mô-đun bộ đếm thời gian 16-bit.<br />
Bao gồm: timer.h<br />
Prototype: void CloseTimer1 (void);<br />
làm mất hiệu lực CloseTimer2 (void);<br />
làm mất hiệu lực CloseTimer3 (void);<br />
làm mất hiệu lực CloseTimer4 (void);<br />
làm mất hiệu lực CloseTimer5 (void);<br />
Lập luận: Không<br />
Trở lại giá trị: Không<br />
Bình luận: Chức năng này đầu tiên vô hiệu hóa 16-bit giờ gián đoạn và sau đó<br />
tắt<br />
các mô-đun bộ đếm thời gian. Các bit Cờ ngắt (TXIF) cũng sẽ bị xóa.<br />
Source File: CloseTimer1.c<br />
CloseTimer2.c<br />
CloseTimer3.c<br />
CloseTimer4.c<br />
DS51456B-page 108<br />
3.6.3 Example of Use<br />
2004 Microchip Technology Inc.<br />
CloseTimer5.c<br />
Mã số Ví dụ: CloseTimer1 ();<br />
#define __dsPIC30F6010__<br />
#include <br />
#include<br />
unsigned int Channel, PinConfig, Scanselect, Adcon3_reg, Adcon2_reg,<br />
Adcon1_reg;<br />
int main(void)<br />
{<br />
unsigned int result[20], i;<br />
ADCON1bits.ADON = 0; /* turn off ADC */<br />
Channel = ADC_CH0_POS_SAMPLEA_AN4 &<br />
ADC_CH0_NEG_SAMPLEA_NVREF &<br />
ADC_CH0_POS_SAMPLEB_AN2 &<br />
ADC_CH0_NEG_SAMPLEB_AN1;<br />
SetChanADC1(Channel);<br />
ConfigIntADC10(ADC_INT_DISABLE);<br />
PinConfig = ENABLE_AN4_ANA;<br />
CloseTimer23<br />
CloseTimer45<br />
Mô tả: Chức năng này sẽ tắt các mô-đun bộ đếm thời gian 32-bit.<br />
Bao gồm: timer.h<br />
Prototype: void CloseTimer23 (void)<br />
CloseTimer45 trống (void)<br />
Lập luận: Không<br />
Trở lại giá trị: Không<br />
Bình luận: Chức năng này vô hiệu hóa 32-bit giờ gián đoạn và sau đó tắt<br />
hẹn giờ ngắt module.The Flagbit (TXIF) cũng sẽ bị xóa.<br />
CloseTimer23turns tắt Timer2 và vô hiệu hóa Timer3 ngắt.<br />
CloseTimer45turns tắt Timer4 và vô hiệu hóa Timer5 ngắt.<br />
Source File: CloseTimer23.c<br />
CloseTimer45.c<br />
Mã số Ví dụ: CloseTimer23 ();<br />
dsPIC
Scanselect = SKIP_SCAN_AN2 & SKIP_SCAN_AN5 &<br />
SKIP_SCAN_AN9 & SKIP_SCAN_AN10 &<br />
SKIP_SCAN_AN14 & SKIP_SCAN_AN15;<br />
Adcon3_reg = ADC_SAMPLE_TIME_10 &<br />
ADC_CONV_CLK_SYSTEM &<br />
ADC_CONV_CLK_13Tcy;<br />
Adcon2_reg = ADC_VREF_AVDD_AVSS &<br />
ADC_SCAN_OFF &<br />
ADC_ALT_BUF_OFF &<br />
ADC_ALT_INPUT_OFF &<br />
ADC_CONVERT_CH0123 &<br />
ADC_SAMPLES_PER_INT_16;<br />
Adcon1_reg = ADC_MODULE_ON &<br />
ADC_IDLE_CONTINUE &<br />
ADC_FORMAT_INTG &<br />
ADC_CLK_MANUAL &<br />
ADC_SAMPLE_SIMULTANEOUS &<br />
ADC_AUTO_SAMPLING_OFF;<br />
OpenADC10(Adcon1_reg, Adcon2_reg,<br />
Adcon3_reg,PinConfig, Scanselect);<br />
i = 0;<br />
while(i
3.7.1 Individual Functions<br />
CloseTimer1<br />
CloseTimer2<br />
CloseTimer3<br />
CloseTimer4<br />
CloseTimer5<br />
Description: This function turns off the 16-bit timer module.<br />
Include: timer.h<br />
Prototype: void CloseTimer1(void);<br />
void CloseTimer2(void);<br />
void CloseTimer3(void);<br />
void CloseTimer4(void);<br />
void CloseTimer5(void);<br />
Arguments: None<br />
Return Value: None<br />
Remarks: This function first disables the 16-bit timer interrupt and then turns<br />
off<br />
the timer module. The Interrupt Flag bit (TxIF) is also cleared.<br />
Source File: CloseTimer1.c<br />
CloseTimer2.c<br />
CloseTimer3.c<br />
CloseTimer4.c<br />
CloseTimer5.c<br />
Code Example: CloseTimer1();<br />
CloseTimer23<br />
CloseTimer45<br />
Description: This function turns off the 32-bit timer module.<br />
Include: timer.h<br />
Prototype: void CloseTimer23 (void)<br />
void CloseTimer45 (void)<br />
Arguments: None<br />
Return Value: None<br />
Remarks: This function disables the 32-bit timer interrupt and then turns off the<br />
timer module.The Interrupt Flagbit (TxIF) is also cleared.<br />
CloseTimer23turns off Timer2 and disables Timer3 Interrupt.<br />
CloseTimer45turns off Timer4 and disables Timer5 Interrupt.<br />
Source File: CloseTimer23.c<br />
CloseTimer45.c<br />
Code Example: CloseTimer23();<br />
ConfigIntTimer45<br />
Mô tả: Chức năng này cấu hình 32-bit giờ gián đoạn.<br />
Bao gồm: timer.h<br />
Prototype: void ConfigIntTimer23 (int config);<br />
làm mất hiệu lực ConfigIntTimer45 (int config);<br />
Lập luận: config Thơi gian gián đoạn ưu tiên và bật / tắt thông tin<br />
quy định dưới đây:<br />
Tx_INT_PRIOR_7<br />
Tx_INT_PRIOR_6<br />
Tx_INT_PRIOR_5<br />
Tx_INT_PRIOR_4<br />
Tx_INT_PRIOR_3<br />
Tx_INT_PRIOR_2<br />
Tx_INT_PRIOR_1<br />
Tx_INT_PRIOR_0<br />
Tx_INT_ON<br />
Tx_INT_OFF<br />
Trở lại giá trị: Không<br />
Bình luận: Chức năng này sẽ xóa sạch các 32-bit Cờ ngắt (TXIF) bit và sau đó<br />
đặt<br />
gián đoạn ưu tiên và cho phép / vô hiệu hóa ngắt.<br />
Source File: ConfigIntTimer23.c<br />
ConfigIntTimer45.c<br />
Mã số Ví dụ: ConfigIntTimer23 (T3_INT_PRIOR_5 & T3_INT_ON);<br />
OpenTimer1<br />
OpenTimer2<br />
OpenTimer3<br />
OpenTimer4<br />
OpenTimer5<br />
Mô tả: Chức năng này cấu hình các mô-đun bộ đếm thời gian 16-bit.<br />
Bao gồm: timer.h<br />
Prototype: void OpenTimer1 (int config,<br />
unsigned int thời gian)<br />
làm mất hiệu lực OpenTimer2 (unsigned int config,<br />
unsigned int thời gian)<br />
làm mất hiệu lực OpenTimer3 (unsigned int config,<br />
unsigned int thời gian)<br />
làm mất hiệu lực OpenTimer4 (unsigned int config,<br />
unsigned int thời gian)<br />
làm mất hiệu lực OpenTimer5 (unsigned int config,
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 110<br />
ConfigIntTimer1<br />
ConfigIntTimer2<br />
ConfigIntTimer3<br />
ConfigIntTimer4<br />
ConfigIntTimer5<br />
2004 Microchip Technology Inc.<br />
Description: This function configures the 16-bit timer interrupt.<br />
Include: timer.h<br />
Prototype: void ConfigIntTimer1(unsigned int config);<br />
void ConfigIntTimer2(unsigned int config);<br />
void ConfigIntTimer3(unsigned int config);<br />
void ConfigIntTimer4(unsigned int config);<br />
void ConfigIntTimer5(unsigned int config);<br />
Arguments: config Timer interrupt priority and enable/disable information as<br />
defined below:<br />
Tx_INT_PRIOR_7<br />
Tx_INT_PRIOR_6<br />
Tx_INT_PRIOR_5<br />
Tx_INT_PRIOR_4<br />
Tx_INT_PRIOR_3<br />
Tx_INT_PRIOR_2<br />
Tx_INT_PRIOR_1<br />
Tx_INT_PRIOR_0<br />
Tx_INT_ON<br />
Tx_INT_OFF<br />
Return Value: None<br />
Remarks: This function clears the 16-bit InterruptFlag (TxIF) bit and then sets<br />
the<br />
interrupt priority and enables/disables the interrupt.<br />
Source File: ConfigIntTimer1.c<br />
ConfigIntTimer2.c<br />
ConfigIntTimer3.c<br />
ConfigIntTimer4.c<br />
ConfigIntTimer5.c<br />
Code Example: ConfigIntTimer1(T1_INT_PRIOR_3 & T1_INT_ON);<br />
dsPIC Peripheral Libraries<br />
unsigned int thời gian)<br />
Đối số: cấu hình này bao gồm các thông số phải được cấu hình trong TxCON<br />
đăng ký theo quy định dưới đây:<br />
Thơi gian Mô-đun On / Off<br />
Tx_ON<br />
Tx_OFF<br />
Thơi gian Mô-đun chế độ Chờ On / Off<br />
Tx_IDLE_CON<br />
Tx_IDLE_STOP<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 112 2004 Microchip Technology Inc<br />
Tích lũy thời gian hẹn giờ Cổng phép<br />
Tx_GATE_ON<br />
Tx_GATE_OFF<br />
Thơi gian prescaler<br />
Tx_PS_1_1<br />
Tx_PS_1_8<br />
Tx_PS_1_64<br />
Tx_PS_1_128<br />
Hẹn giờ đồng hồ đồng bộ cho phép<br />
Tx_SYNC_EXT_ON<br />
Tx_SYNC_EXT_OFF<br />
Nguồn đồng hồ hẹn giờ<br />
Tx_SOURCE_EXT<br />
Tx_SOURCE_INT<br />
Giai đoạn này có giá trị phù hợp với thời gian được lưu trữ vào<br />
PR đăng ký<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này cấu hình 16-bit Thơi gian kiểm soát và thiết lập<br />
giá trị phù hợp với thời gian vào sổ đăng ký PR<br />
Source File: OpenTimer1.c<br />
OpenTimer2.c<br />
OpenTimer3.c<br />
OpenTimer4.c<br />
OpenTimer5.c<br />
Mã số Ví dụ: OpenTimer1 (T1_ON & T1_GATE_OFF &<br />
T1_PS_1_8 & T1_SYNC_EXT_OFF &
2004 Microchip Technology Inc. DS51456B-page 111<br />
ConfigIntTimer23<br />
ConfigIntTimer45<br />
Description: This function configures the 32-bit timer interrupt.<br />
Include: timer.h<br />
Prototype: void ConfigIntTimer23(unsigned int config);<br />
void ConfigIntTimer45(unsigned int config);<br />
Arguments: config Timer interrupt priority and enable/disable information as<br />
defined below:<br />
Tx_INT_PRIOR_7<br />
Tx_INT_PRIOR_6<br />
Tx_INT_PRIOR_5<br />
Tx_INT_PRIOR_4<br />
Tx_INT_PRIOR_3<br />
Tx_INT_PRIOR_2<br />
Tx_INT_PRIOR_1<br />
Tx_INT_PRIOR_0<br />
Tx_INT_ON<br />
Tx_INT_OFF<br />
Return Value: None<br />
Remarks: This function clears the 32-bit Interrupt Flag (TxIF) bit and then sets<br />
the<br />
interrupt priority and enables/disables the interrupt.<br />
Source File: ConfigIntTimer23.c<br />
ConfigIntTimer45.c<br />
Code Example: ConfigIntTimer23(T3_INT_PRIOR_5 & T3_INT_ON);<br />
OpenTimer1<br />
OpenTimer2<br />
OpenTimer3<br />
OpenTimer4<br />
OpenTimer5<br />
Description: This function configures the 16-bit timer module.<br />
Include: timer.h<br />
Prototype: void OpenTimer1(unsigned int config,<br />
unsigned int period)<br />
void OpenTimer2(unsigned int config,<br />
unsigned int period)<br />
void OpenTimer3(unsigned int config,<br />
unsigned int period)<br />
T1_SOURCE_INT, 0xFF);<br />
OpenTimer23<br />
OpenTimer45<br />
Mô tả: Chức năng này cấu hình các mô-đun bộ đếm thời gian 32-bit.<br />
Bao gồm: timer.h<br />
Prototype: void OpenTimer23 (int config,<br />
thời gian dài không dấu);<br />
khoảng trống OpenTimer45 (int config,<br />
thời gian dài không dấu);<br />
Đối số: cấu hình này bao gồm các thông số hy vọng sẽ được cấu hình trong<br />
TxCON<br />
đăng ký theo quy định dưới đây:<br />
Mô-đun giờ On / Off<br />
Tx_ON<br />
Tx_OFF<br />
Thơi gian Mô-đun chế độ Chờ On / Off<br />
Tx_IDLE_CON<br />
Tx_IDLE_STOP<br />
Tích lũy thời gian hẹn giờ Cổng phép<br />
Tx_GATE_ON<br />
Tx_GATE_OFF<br />
OpenTimer1 (Tiếp theo)<br />
OpenTimer2<br />
OpenTimer3<br />
OpenTimer4<br />
OpenTimer5<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 113<br />
Thơi gian prescaler<br />
Tx_PS_1_1<br />
Tx_PS_1_8<br />
Tx_PS_1_64<br />
Tx_PS_1_128<br />
Hẹn giờ đồng hồ đồng bộ cho phép<br />
Tx_SYNC_EXT_ON<br />
Tx_SYNC_EXT_OFF<br />
Nguồn đồng hồ hẹn giờ<br />
Tx_SOURCE_EXT<br />
Tx_SOURCE_INT<br />
Giai đoạn này có giá trị phù hợp với thời gian được lưu trữ vào
void OpenTimer4(unsigned int config,<br />
unsigned int period)<br />
void OpenTimer5(unsigned int config,<br />
unsigned int period)<br />
Arguments: config This contains the parameters to be configured in the TxCON<br />
register as defined below:<br />
Timer Module On/Off<br />
Tx_ON<br />
Tx_OFF<br />
Timer Module Idle mode On/Off<br />
Tx_IDLE_CON<br />
Tx_IDLE_STOP<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 112 2004 Microchip Technology Inc.<br />
Timer Gate time accumulation enable<br />
Tx_GATE_ON<br />
Tx_GATE_OFF<br />
Timer prescaler<br />
Tx_PS_1_1<br />
Tx_PS_1_8<br />
Tx_PS_1_64<br />
Tx_PS_1_128<br />
Timer Synchronous clock enable<br />
Tx_SYNC_EXT_ON<br />
Tx_SYNC_EXT_OFF<br />
Timer clock source<br />
Tx_SOURCE_EXT<br />
Tx_SOURCE_INT<br />
period This contains the period match value to be stored into the<br />
PR register<br />
Return Value: None<br />
Remarks: This function configures the 16-bit Timer Control register and sets the<br />
period match value into the PR register<br />
Source File: OpenTimer1.c<br />
OpenTimer2.c<br />
OpenTimer3.c<br />
OpenTimer4.c<br />
32-bit PR đăng ký.<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này cấu hình 32-bit Thơi gian kiểm soát và thiết lập<br />
giá trị phù hợp với thời gian vào sổ đăng ký PR<br />
Source File: OpenTimer23.c<br />
OpenTimer45.c<br />
Mã số Ví dụ: OpenTimer23 (T2_ON & T2_GATE_OFF &<br />
T2_PS_1_8 & T2_32BIT_MODE_ON &<br />
T2_SYNC_EXT_OFF &<br />
T2_SOURCE_INT, 0xFFFF);<br />
ReadTimer1<br />
ReadTimer2<br />
ReadTimer3<br />
ReadTimer4<br />
ReadTimer5<br />
Mô tả: Chức năng này sẽ đọc nội dung của 16-bit Thơi gian đăng ký.<br />
Bao gồm: timer.h<br />
Nguyên mẫu: int ReadTimer1 (void);<br />
int ReadTimer2 (void);<br />
int ReadTimer3 (void);<br />
int ReadTimer4 (void);<br />
int ReadTimer5 (void);<br />
Lập luận: Không<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này trả về các nội dung của 16-bit TMR đăng ký.<br />
Source File: ReadTimer1.c<br />
ReadTimer2.c<br />
ReadTimer3.c<br />
ReadTimer4.c<br />
ReadTimer5.c<br />
Mã số Ví dụ: int timer1_value;<br />
timer1_value = ReadTimer1 ();<br />
OpenTimer23 (Tiếp theo)<br />
OpenTimer45<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 114 2004 Microchip Technology Inc<br />
ReadTimer23
OpenTimer5.c<br />
Code Example: OpenTimer1(T1_ON & T1_GATE_OFF &<br />
T1_PS_1_8 & T1_SYNC_EXT_OFF &<br />
T1_SOURCE_INT, 0xFF);<br />
OpenTimer23<br />
OpenTimer45<br />
Description: This function configures the 32-bit timer module.<br />
Include: timer.h<br />
Prototype: void OpenTimer23(unsigned int config,<br />
unsigned long period);<br />
void OpenTimer45(unsigned int config,<br />
unsigned long period);<br />
Arguments: config This contains the parameters tobe configured in the TxCON<br />
register as defined below:<br />
Timer module On/Off<br />
Tx_ON<br />
Tx_OFF<br />
Timer Module Idle mode On/Off<br />
Tx_IDLE_CON<br />
Tx_IDLE_STOP<br />
Timer Gate time accumulation enable<br />
Tx_GATE_ON<br />
Tx_GATE_OFF<br />
OpenTimer1 (Continued)<br />
OpenTimer2<br />
OpenTimer3<br />
OpenTimer4<br />
OpenTimer5<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 113<br />
Timer prescaler<br />
Tx_PS_1_1<br />
Tx_PS_1_8<br />
Tx_PS_1_64<br />
Tx_PS_1_128<br />
Timer Synchronous clock enable<br />
Tx_SYNC_EXT_ON<br />
Tx_SYNC_EXT_OFF<br />
Timer clock source<br />
ReadTimer45<br />
Mô tả: Chức năng này sẽ đọc nội dung của 32-bit Thơi gian đăng ký.<br />
Bao gồm: timer.h<br />
Prototype: ReadTimer23 unsigned dài (void);<br />
ReadTimer45 unsigned dài (void);<br />
Lập luận: Không<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này trả về contentsof 32-bit TMR đăng ký.<br />
Source File: ReadTimer23.c<br />
ReadTimer45.c<br />
Mã số Ví dụ: unsigned timer23_value dài;<br />
timer23_value = ReadTimer23 ();<br />
WriteTimer1<br />
WriteTimer2<br />
WriteTimer3<br />
WriteTimer4<br />
WriteTimer5<br />
Mô tả: Chức năng này ghi giá trị 16-bit vào sổ đăng ký hẹn giờ.<br />
Bao gồm: timer.h<br />
Prototype: void WriteTimer1 (int giờ);<br />
làm mất hiệu lực WriteTimer2 (int giờ);<br />
làm mất hiệu lực WriteTimer3 (int giờ);<br />
làm mất hiệu lực WriteTimer4 (int giờ);<br />
làm mất hiệu lực WriteTimer5 (int giờ);<br />
Đối số: giờ này là giá trị 16-bit được lưu trữ vào TMR đăng ký.<br />
Trở lại giá trị: Không<br />
Bình luận: Không có<br />
Source File: WriteTimer1.c<br />
WriteTimer2.c<br />
WriteTimer3.c<br />
WriteTimer4.c<br />
WriteTimer5.c<br />
Mã số Ví dụ: int timer_init = 0xAB;<br />
WriteTimer1 (timer_init);<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 115<br />
3.7.2 Macros cá nhân<br />
WriteTimer23<br />
WriteTimer45
Tx_SOURCE_EXT<br />
Tx_SOURCE_INT<br />
period This contains the period match value to be stored into the<br />
32-bit PR register.<br />
Return Value: None<br />
Remarks: This function configures the 32-bit Timer Control register and sets the<br />
period match value into the PR register<br />
Source File: OpenTimer23.c<br />
OpenTimer45.c<br />
Code Example: OpenTimer23(T2_ON & T2_GATE_OFF &<br />
T2_PS_1_8 & T2_32BIT_MODE_ON &<br />
T2_SYNC_EXT_OFF &<br />
T2_SOURCE_INT, 0xFFFF);<br />
ReadTimer1<br />
ReadTimer2<br />
ReadTimer3<br />
ReadTimer4<br />
ReadTimer5<br />
Description: This function reads the contents of the 16-bit Timer register.<br />
Include: timer.h<br />
Prototype: unsigned int ReadTimer1(void);<br />
unsigned int ReadTimer2(void);<br />
unsigned int ReadTimer3(void);<br />
unsigned int ReadTimer4(void);<br />
unsigned int ReadTimer5(void);<br />
Arguments: None<br />
Return Value: None<br />
Remarks: This function returns the contents of the 16-bit TMR register.<br />
Source File: ReadTimer1.c<br />
ReadTimer2.c<br />
ReadTimer3.c<br />
ReadTimer4.c<br />
ReadTimer5.c<br />
Code Example: unsigned int timer1_value;<br />
timer1_value = ReadTimer1();<br />
OpenTimer23 (Continued)<br />
Mô tả: Chức năng này ghi giá trị 32-bit vào sổ đăng ký hẹn giờ.<br />
Bao gồm: timer.h<br />
Prototype: void WriteTimer23 (giờ unsigned long);<br />
làm mất hiệu lực WriteTimer45 (bộ đếm thời gian dài không dấu);<br />
Đối số: giờ này là giá trị 32-bit được lưu trữ vào TMR đăng ký.<br />
Trở lại giá trị: Không<br />
Bình luận: Không có<br />
Source File: WriteTimer23.c<br />
WriteTimer45.c<br />
Mã số Ví dụ: timer23_init unsigned long = 0xABCD;<br />
WriteTimer23 (timer23_init);<br />
EnableIntT1<br />
EnableIntT2<br />
EnableIntT3<br />
EnableIntT4<br />
EnableIntT5<br />
Mô tả: Phần này cho phép giờ gián đoạn.<br />
Bao gồm: timer.h<br />
Lập luận: Không<br />
Ghi chú: Phần này bộ hẹn giờ ngắt Enable chút ngắt Chức năng Kiểm soát<br />
đăng ký.<br />
Mã số Ví dụ: EnableIntT1;<br />
DisableIntT1<br />
DisableIntT2<br />
DisableIntT3<br />
DisableIntT4<br />
DisableIntT5<br />
Mô tả: vĩ mô này vô hiệu hóa bộ đếm thời gian gián đoạn.<br />
Bao gồm: timer.h<br />
Lập luận: Không<br />
Bình luận: vĩ mô này sẽ xóa Thơi gian ngắt Enable chút ngắt Chức năng Kiểm<br />
soát<br />
đăng ký.<br />
Mã số Ví dụ: DisableIntT2;<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
OpenTimer45<br />
dsPIC<br />
DS51456B trang 116<br />
3.7.3 Ví dụ về sử dụng<br />
2004 Microchip Technology Inc<br />
®<br />
# xác định __dsPIC30F6014__
Language Tools Libraries<br />
DS51456B-page 114 2004 Microchip Technology Inc.<br />
ReadTimer23<br />
ReadTimer45<br />
Description: This function reads the contents of the 32-bit Timer register.<br />
Include: timer.h<br />
Prototype: unsigned long ReadTimer23(void);<br />
unsigned long ReadTimer45(void);<br />
Arguments: None<br />
Return Value: None<br />
Remarks: This function returns the contentsof the 32-bit TMR register.<br />
Source File: ReadTimer23.c<br />
ReadTimer45.c<br />
Code Example: unsigned long timer23_value;<br />
timer23_value = ReadTimer23();<br />
WriteTimer1<br />
WriteTimer2<br />
WriteTimer3<br />
WriteTimer4<br />
WriteTimer5<br />
Description: This function writes the 16-bit value into the Timer register.<br />
Include: timer.h<br />
Prototype: void WriteTimer1(unsigned int timer);<br />
void WriteTimer2(unsigned int timer);<br />
void WriteTimer3(unsigned int timer);<br />
void WriteTimer4(unsigned int timer);<br />
void WriteTimer5(unsigned int timer);<br />
Arguments: timer This is the 16-bit value to be stored into TMR register.<br />
Return Value: None<br />
Remarks: None<br />
Source File: WriteTimer1.c<br />
WriteTimer2.c<br />
WriteTimer3.c<br />
WriteTimer4.c<br />
WriteTimer5.c<br />
Code Example: unsigned int timer_init = 0xAB;<br />
WriteTimer1(timer_init);<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 115<br />
# include<br />
# include<br />
int timer_value;<br />
khoảng trống __attribute __ ((__ interrupt__)) _T1Interrupt (void)<br />
{<br />
PORTDbits.RD1 = 1; / * Tắt đèn LED trên RD1 * /<br />
(0) WriteTimer1;<br />
IFS0bits.T1IF = 0; / * Thơi gian gián đoạn rõ ràng cờ * /<br />
}<br />
int main (void)<br />
{<br />
int match_value;<br />
TRISDbits.TRISD1 = 0;<br />
PORTDbits.RD1 = 1; / * Tắt đèn LED trên RD1 * /<br />
/ * Cho phép ngắt Timer1 và ưu tiên để "1" * /<br />
ConfigIntTimer1 (T1_INT_PRIOR_1 & T1_INT_ON);<br />
(0) WriteTimer1;<br />
match_value = 0xFFF;<br />
OpenTimer1 (T1_ON & T1_GATE_OFF & T1_IDLE_STOP &<br />
T1_PS_1_1 & T1_SYNC_EXT_OFF &<br />
T1_SOURCE_INT, match_value);<br />
/ * Chờ cho đến khi bộ đếm thời gian phù hợp với giá trị khoảng thời gian * /<br />
trong khi (1)<br />
{<br />
timer_value = ReadTimer1 ();<br />
if (timer_value> = 0x7FF)<br />
{<br />
PORTDbits.RD1 = 0; / * Bật đèn LED trên RD1 * /<br />
}<br />
}<br />
CloseTimer1 ();<br />
}<br />
SetPriorityIntT1<br />
SetPriorityIntT2<br />
SetPriorityIntT3<br />
SetPriorityIntT4<br />
SetPriorityIntT5<br />
Mô tả: Điều này đặt ra ưu tiên vĩ mô cho giờ gián đoạn.<br />
Bao gồm: timer.h
3.7.2 Individual Macros<br />
WriteTimer23<br />
WriteTimer45<br />
Description: This function writes the 32-bit value into the Timer register.<br />
Include: timer.h<br />
Prototype: void WriteTimer23(unsigned long timer);<br />
void WriteTimer45(unsigned long timer);<br />
Arguments: timer This is the 32-bit value to be stored into TMR register.<br />
Return Value: None<br />
Remarks: None<br />
Source File: WriteTimer23.c<br />
WriteTimer45.c<br />
Code Example: unsigned long timer23_init = 0xABCD;<br />
WriteTimer23(timer23_init);<br />
EnableIntT1<br />
EnableIntT2<br />
EnableIntT3<br />
EnableIntT4<br />
EnableIntT5<br />
Description: This macro enables the timer interrupt.<br />
Include: timer.h<br />
Arguments: None<br />
Remarks: This macro sets Timer Interrupt Enable bit of Interrupt Enable<br />
Control<br />
register.<br />
Code Example: EnableIntT1;<br />
DisableIntT1<br />
DisableIntT2<br />
DisableIntT3<br />
DisableIntT4<br />
DisableIntT5<br />
Description: This macro disables the timer interrupt.<br />
Include: timer.h<br />
Arguments: None<br />
Remarks: This macro clears Timer Interrupt Enable bit of Interrupt Enable<br />
Control<br />
register.<br />
Code Example: DisableIntT2;<br />
dsPIC<br />
®<br />
Đối số: ưu tiên<br />
Ghi chú: Phần này thiết lập hẹn giờ ngắt Prioritybits của ngắt ưu tiên kiểm soát<br />
đăng ký.<br />
Mã số Ví dụ: SetPriorityIntT4 (7);<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 117<br />
Chức năng thiết lập lại 3,8 / CONTROL<br />
Phần này bao gồm một danh sách các chức năng cá nhân để lập lại /<br />
Control. Chức năng có thể<br />
thực hiện như các macro.<br />
3.8.1 Chức năng cá nhân<br />
isBOR<br />
Mô tả: chức năng này sẽ kiểm tra nếu đặt lại là do màu nâu ra phát hiện.<br />
Bao gồm: reset.h<br />
Prototype: char isBOR (void);<br />
Lập luận: Không<br />
Trở lại giá trị: Chức năng này trả về RCON tình trạng bit.<br />
Nếu giá trị trả về là 1, sau đó đặt lại là do màu nâu-out.<br />
Nếu giá trị trả về là 0, sau đó không có màu nâu-out xảy ra.<br />
Bình luận: Không có<br />
Source File: isBOR.c<br />
Mã số Ví dụ: char reset_state;<br />
reset_state = isBOR ();<br />
isPOR<br />
Mô tả: chức năng này sẽ kiểm tra nếu đặt lại là do điện vào Reset.<br />
Bao gồm: reset.h<br />
Prototype: char isPOR (void);<br />
Lập luận: Không<br />
Trở lại giá trị: Chức năng này trả về RCON tình trạng bit.<br />
Nếu giá trị trả về là 1, sau đó đặt lại là do nguồn.<br />
Nếu giá trị trả về là 0, sau đó không có điện vào thiết lập lại xảy ra.<br />
Bình luận: Không có<br />
Source File: isPOR.c<br />
Mã số Ví dụ: char reset_state;<br />
reset_state = isPOR ();<br />
isLVD<br />
Mô tả: chức năng này sẽ kiểm tra nếu phát hiện điện áp thấp ngắt cờ được thiết<br />
lập.<br />
Bao gồm: reset.h<br />
Prototype: char isLVD (void);
Language Tools Libraries<br />
DS51456B-page 116 2004 Microchip Technology Inc.<br />
3.7.3 Example of Use<br />
#define __dsPIC30F6014__<br />
#include <br />
#include<br />
unsigned int timer_value;<br />
void __attribute__((__interrupt__)) _T1Interrupt(void)<br />
{<br />
PORTDbits.RD1 = 1; /* turn off LED on RD1 */<br />
WriteTimer1(0);<br />
IFS0bits.T1IF = 0; /* Clear Timer interrupt flag */<br />
}<br />
int main(void)<br />
{<br />
unsigned int match_value;<br />
TRISDbits.TRISD1 = 0;<br />
PORTDbits.RD1 = 1; /* turn off LED on RD1 */<br />
/* Enable Timer1 Interrupt and Priority to "1" */<br />
ConfigIntTimer1(T1_INT_PRIOR_1 & T1_INT_ON);<br />
WriteTimer1(0);<br />
match_value = 0xFFF;<br />
OpenTimer1(T1_ON & T1_GATE_OFF & T1_IDLE_STOP &<br />
T1_PS_1_1 & T1_SYNC_EXT_OFF &<br />
T1_SOURCE_INT, match_value);<br />
/* Wait till the timer matches with the period value */<br />
while(1)<br />
{<br />
timer_value = ReadTimer1();<br />
if(timer_value >= 0x7FF)<br />
{<br />
PORTDbits.RD1 = 0; /* turn on LED on RD1 */<br />
}<br />
}<br />
CloseTimer1();<br />
}<br />
SetPriorityIntT1<br />
SetPriorityIntT2<br />
SetPriorityIntT3<br />
Lập luận: Không<br />
Quay trở lại giá trị: Chức năng này trả về IFS2 tình trạng bit.<br />
Nếu giá trị trả về là 1, sau đó phát hiện điện áp thấp ngắt xảy ra.<br />
Nếu giá trị trả về là 0, sau đó phát hiện điện áp thấp ngắt đã không xảy ra.<br />
Bình luận: Không có<br />
Source File: isLVD.c<br />
Mã số Ví dụ: char LVD;<br />
LVD = isLVD ();<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 118<br />
isMCLR<br />
2004 Microchip Technology Inc<br />
Mô tả: chức năng kiểm tra nếu điều kiện lập lại này là do MCLRpin sẽ thấp.<br />
Bao gồm: reset.h<br />
Prototype: char isMCLR (void);<br />
Lập luận: Không<br />
Trở lại giá trị: Chức năng này trả về RCON tình trạng bit.<br />
Nếu giá trị trả về là 1, sau đó thiết lập lại xảy ra do MCLRpin sẽ thấp.<br />
Nếu giá trị trả về là 0, sau đó đặt lại không phải do MCLRgoing thấp.<br />
Bình luận: Không có<br />
Source File: isMCLR.c<br />
Mã số Ví dụ: char reset_state;<br />
reset_state = isMCLR ();<br />
isWDTTO<br />
Mô tả: chức năng kiểm tra nếu điều kiện lập lại này là do WDT time-out.<br />
Bao gồm: reset.h<br />
Prototype: char isWDTTO (void);<br />
Lập luận: Không<br />
Trở lại giá trị: Chức năng này trả về RCON tình trạng bit.<br />
Nếu giá trị trả về là 1, sau đó thiết lập lại xảy ra do WDT time-out.<br />
Nếu giá trị trả về là 0, sau đó đặt lại không phải do WDT time-out.<br />
Bình luận: Không có<br />
Source File: isWDTTO.c<br />
Mã số Ví dụ: char reset_state;<br />
reset_state = isWDTTO ();<br />
isWDTWU<br />
Mô tả: chức năng này sẽ kiểm tra nếu đánh thức từ giấc ngủ là do WDT timeout.<br />
Bao gồm: reset.h
SetPriorityIntT4<br />
SetPriorityIntT5<br />
Description: This macro sets priority for timer interrupt.<br />
Include: timer.h<br />
Arguments: priority<br />
Remarks: This macro sets Timer Interrupt Prioritybits of Interrupt Priority<br />
Control<br />
register.<br />
Code Example: SetPriorityIntT4(7);<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 117<br />
3.8 RESET/CONTROL FUNCTIONS<br />
This section contains a list of individual functions for Reset/Control. Functions<br />
may be<br />
implemented as macros.<br />
3.8.1 Individual Functions<br />
isBOR<br />
Description: This function checks if Reset is due to brown-out detect.<br />
Include: reset.h<br />
Prototype: char isBOR(void);<br />
Arguments: None<br />
Return Value: This function returns the RCON bit status.<br />
If return value is 1, then reset is due to brown-out.<br />
If return value is 0, then no brown-out occurred.<br />
Remarks: None<br />
Source File: isBOR.c<br />
Code Example: char reset_state;<br />
reset_state = isBOR();<br />
isPOR<br />
Description: This function checks if Reset is due to Power on Reset.<br />
Include: reset.h<br />
Prototype: char isPOR(void);<br />
Arguments: None<br />
Return Value: This function returns the RCON bit status.<br />
If return value is 1, then reset is due to Power on.<br />
If return value is 0, then no Power on reset occurred.<br />
Remarks: None<br />
Source File: isPOR.c<br />
Code Example: char reset_state;<br />
reset_state = isPOR();<br />
Prototype: char isWDTWU (void);<br />
Lập luận: Không<br />
Trở lại giá trị: Chức năng này trả về tình trạng của RCON và<br />
RCONbit<br />
Nếu giá trị trả về là "1", sau đó Wake-up từ Sleep xảy ra do WDT<br />
time-out.<br />
Nếu giá trị trả về là "0", sau đó Wake-up từ Sleep không phải là do WDT<br />
time-out.<br />
Bình luận: Không có<br />
Source File: isWDTWU.c<br />
Mã số Ví dụ: char reset_state;<br />
reset_state = isWDTWU ();<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 119<br />
3.8.2 Macros cá nhân<br />
isWU<br />
Mô tả: chức năng này sẽ kiểm tra nếu đánh thức từ giấc ngủ là do MCLR, POR<br />
Ban đại diện hay bất kỳ gián đoạn.<br />
Bao gồm: reset.h<br />
Prototype: char isWU (void);<br />
Lập luận: Không<br />
Quay trở lại giá trị: chức năng này sẽ kiểm tra nếu đánh thức từ giấc ngủ đã xảy<br />
ra.<br />
Nếu có, nó sẽ kiểm tra cho là nguyên nhân cho đánh thức.<br />
nếu "1", đánh thức là do sự xuất hiện của bị gián đoạn.<br />
nếu "2", báo thức là do MCLR.<br />
nếu '3', báo thức là do POR.<br />
nếu '4', báo thức là do Ban đại diện.<br />
Nếu đánh thức từ giấc ngủ đã không xảy ra, sau đó giá trị "0" được trả về.<br />
Bình luận: Không có<br />
Source File: isWU.c<br />
Mã số Ví dụ: char reset_state;<br />
reset_state = isWU ();<br />
DisableInterrupts<br />
Mô tả: vĩ mô này vô hiệu hóa tất cả các ngắt ngoại vi cho số quy định của<br />
chu kỳ hướng dẫn.<br />
Bao gồm: reset.h<br />
Đối số: chu kỳ<br />
Ghi chú: Phần này hướng dẫn thực hiện Disi để vô hiệu hóa tất cả các thiết bị<br />
ngoại vi
isLVD<br />
Description: This function checks if Low voltage detect interrupt flag is set.<br />
Include: reset.h<br />
Prototype: char isLVD(void);<br />
Arguments: None<br />
Return Value: This function returns the IFS2 bit status.<br />
If return value is 1, then low voltage detect interrupt occurred.<br />
If return value is 0, then low voltage detect interrupt did not occur.<br />
Remarks: None<br />
Source File: isLVD.c<br />
Code Example: char lvd;<br />
lvd = isLVD();<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 118<br />
isMCLR<br />
2004 Microchip Technology Inc.<br />
Description: This function checks if Reset condition is due to MCLRpin going<br />
low.<br />
Include: reset.h<br />
Prototype: char isMCLR(void);<br />
Arguments: None<br />
Return Value: This function returns the RCON bit status.<br />
If return value is 1, then reset occurred due to MCLRpin going low.<br />
If return value is 0, then reset is not due to MCLRgoing low.<br />
Remarks: None<br />
Source File: isMCLR.c<br />
Code Example: char reset_state;<br />
reset_state = isMCLR();<br />
isWDTTO<br />
Description: This function checks if Reset condition is due to WDT time-out.<br />
Include: reset.h<br />
Prototype: char isWDTTO(void);<br />
Arguments: None<br />
Return Value: This function returns the RCON bit status.<br />
If return value is 1, then reset occurred due to WDT time-out.<br />
If return value is 0, then reset is not due to WDT time-out.<br />
Remarks: None<br />
Source File: isWDTTO.c<br />
ngắt cho số quy định của chu kỳ hướng dẫn.<br />
Mã số Ví dụ: DisableInterrupts (15);<br />
PORStatReset<br />
Mô tả: Đây vĩ mô bit bộ của POR RCON đăng ký để thiết lập lại nhà nước.<br />
Bao gồm: reset.h<br />
Lập luận: Không<br />
Bình luận: Không có<br />
Mã số Ví dụ: PORStatReset;<br />
BORStatReset<br />
Mô tả: Đây bộ vĩ mô BOR chút RCON đăng ký để thiết lập lại nhà nước.<br />
Bao gồm: reset.h<br />
Lập luận: Không<br />
Bình luận: Không có<br />
Mã số Ví dụ: BORStatReset;<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 120<br />
3,9 I / O PORT chức năng<br />
2004 Microchip Technology Inc<br />
Phần này bao gồm một danh sách các individualfunctions cho I / O port. Chức<br />
năng có thể<br />
thực hiện như các macro.<br />
3.9.1 Chức năng cá nhân<br />
WDTSWEnable<br />
Mô tả: Đây vĩ mô lần lượt trên bộ đếm thời gian cơ quan giám sát<br />
Bao gồm: reset.h<br />
Lập luận: Không<br />
Bình luận: vĩ mô này đặt phần mềm WDT Enable (SWDTEN) chút RCON<br />
đăng ký<br />
Mã số Ví dụ: WDTSWEnable;<br />
WDTSWDisable<br />
Mô tả: vĩ mô này sẽ xóa phần mềm WDT Enable (SWDTEN) chút RCON<br />
đăng ký<br />
Bao gồm: reset.h<br />
Lập luận: Không<br />
Ghi chú: Phần này sẽ vô hiệu hóa WDT ifFWDTEN Fuse bit "0".<br />
Mã số Ví dụ: WDTSWDisable;<br />
CloseINT0<br />
CloseINT1<br />
CloseINT2
Code Example: char reset_state;<br />
reset_state = isWDTTO();<br />
isWDTWU<br />
Description: This function checks if Wake-up from Sleep is due to WDT timeout.<br />
Include: reset.h<br />
Prototype: char isWDTWU(void);<br />
Arguments: None<br />
Return Value: This function returns the status of RCON and<br />
RCONbits<br />
If return value is ‘1’, then Wake-up from Sleep occurred due to WDT<br />
time-out.<br />
If return value is ‘0’, then Wake-up from Sleep is not due to WDT<br />
time-out.<br />
Remarks: None<br />
Source File: isWDTWU.c<br />
Code Example: char reset_state;<br />
reset_state = isWDTWU();<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 119<br />
3.8.2 Individual Macros<br />
isWU<br />
Description: This function checks if Wake-up from Sleep is due to MCLR,<br />
POR,<br />
BOR or any interrupt.<br />
Include: reset.h<br />
Prototype: char isWU(void);<br />
Arguments: None<br />
Return Value: This function checks if Wake-up from Sleep has occurred.<br />
If yes, it checks for the cause for wake-up.<br />
if ‘1’, wake-up is due to the occurrence of interrupt.<br />
if ‘2’, wake-up is due to MCLR.<br />
if ‘3’, wake-up is due to POR.<br />
if ‘4’, wake-up is due to BOR.<br />
If Wake-up from Sleep has not occurred, then a value of ‘0’ is returned.<br />
Remarks: None<br />
Source File: isWU.c<br />
Code Example: char reset_state;<br />
reset_state = isWU();<br />
DisableInterrupts<br />
CloseINT3<br />
CloseINT4<br />
Mô tả: Chức năng này vô hiệu hóa ngắt ngoài vào INT pin.<br />
Bao gồm: ports.h<br />
Prototype: void CloseINT0 (void);<br />
làm mất hiệu lực CloseINT1 (void);<br />
làm mất hiệu lực CloseINT2 (void);<br />
làm mất hiệu lực CloseINT3 (void);<br />
làm mất hiệu lực CloseINT4 (void);<br />
Lập luận: Không<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này vô hiệu hóa ngắt INT pin và xóa<br />
tương ứng với cờ ngắt.<br />
Source File: CloseInt0.c<br />
CloseInt1.c<br />
CloseInt2.c<br />
CloseInt3.c<br />
CloseInt4.c<br />
Mã số Ví dụ: CloseINT0 ();<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 121<br />
ConfigINT0<br />
ConfigINT1<br />
ConfigINT2<br />
ConfigINT3<br />
ConfigINT4<br />
Mô tả: Chức năng này cấu hình ngắt INT pin.<br />
Bao gồm: ports.h<br />
Prototype: void ConfigINT0 (int config);<br />
làm mất hiệu lực ConfigINT1 (int config);<br />
làm mất hiệu lực ConfigINT2 (int config);<br />
làm mất hiệu lực ConfigINT3 (int config);<br />
làm mất hiệu lực ConfigINT4 (int config);<br />
Đối số: cấu hình ngắt cạnh, ưu tiên và bật / tắt thông tin<br />
quy định dưới đây:<br />
Lựa chọn cạnh ngắt<br />
RISING_EDGE_INT<br />
FALLING_EDGE_INT<br />
Cho phép ngắt
Description: This macro disables all the peripheral interrupts for specified<br />
number of<br />
instruction cycles.<br />
Include: reset.h<br />
Arguments: cycles<br />
Remarks: This macro executes DISI instruction to disable all the peripheral<br />
interrupts for specified number of instruction cycles.<br />
Code Example: DisableInterrupts(15);<br />
PORStatReset<br />
Description: This macro sets POR bit of RCON register to reset state.<br />
Include: reset.h<br />
Arguments: None<br />
Remarks: None<br />
Code Example: PORStatReset;<br />
BORStatReset<br />
Description: This macro sets BOR bit of RCON register to reset state.<br />
Include: reset.h<br />
Arguments: None<br />
Remarks: None<br />
Code Example: BORStatReset;<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
INT_ENABLE<br />
INT_DISABLE<br />
Ưu tiên ngắt<br />
INT_PRI_0<br />
INT_PRI_1<br />
INT_PRI_2<br />
INT_PRI_3<br />
INT_PRI_4<br />
INT_PRI_5<br />
INT_PRI_6<br />
INT_PRI_7<br />
Trở lại giá trị: Không<br />
Bình luận: chức năng này sẽ xóa cờ ngắt tương ứng với pin INTx và<br />
sau đó chọn cạnh phát hiện cực.<br />
Sau đó, đặt ưu tiên ngắt và cho phép / vô hiệu hóa ngắt.<br />
Source File: ConfigInt0.c<br />
ConfigInt1.c<br />
ConfigInt2.c<br />
ConfigInt3.c<br />
ConfigInt4.c<br />
Mã số Ví dụ: ConfigINT0 (RISING_EDGE_INT & EXT_INT_PRI_5 &<br />
EXT_INT_ENABLE);<br />
dsPIC<br />
DS51456B-page 120<br />
2004 Microchip Technology Inc.<br />
®<br />
3.9 I/O PORT FUNCTIONS<br />
This section contains a list of individualfunctions for I/O ports. Functions may<br />
be<br />
implemented as macros.<br />
3.9.1 Individual Functions<br />
WDTSWEnable<br />
Description: This macro turns on the watchdog timer<br />
Include: reset.h<br />
Arguments: None<br />
Remarks: This macro sets Software WDT Enable (SWDTEN) bit of RCON<br />
register<br />
Code Example: WDTSWEnable;<br />
WDTSWDisable<br />
Description: This macro clears Software WDT Enable (SWDTEN) bit of RCON<br />
register<br />
Include: reset.h<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 122 2004 Microchip Technology Inc<br />
ConfigCNPullups<br />
Mô tả: Chức năng này cấu hình các điện trở kéo lên cho CN chân.<br />
Bao gồm: ports.h<br />
Prototype: void ConfigCNPullups (long int config);<br />
Đối số: cấu hình này là giá trị 32-bit để cấu hình pull-up. Thấp hơn<br />
từ được lưu trữ vào CNPU1 đăng ký và từ trên tiếp theo là<br />
lưu trữ trong CNPU2 đăng ký. 8 bit trên của CNPU2<br />
đăng ký là chưa thực hiện.<br />
Trở lại giá trị: Không<br />
Bình luận: Không có<br />
Source File: ConfigCNPullups.c<br />
Mã số Ví dụ: ConfigCNPullups (0xFFF);<br />
ConfigIntCN
Arguments: None<br />
Remarks: This macro disables WDT ifFWDTEN Fuse bit is ‘0’.<br />
Code Example: WDTSWDisable;<br />
CloseINT0<br />
CloseINT1<br />
CloseINT2<br />
CloseINT3<br />
CloseINT4<br />
Description: This function disables the external interrupt on INT pin.<br />
Include: ports.h<br />
Prototype: void CloseINT0(void);<br />
void CloseINT1(void);<br />
void CloseINT2(void);<br />
void CloseINT3(void);<br />
void CloseINT4(void);<br />
Arguments: None<br />
Return Value: None<br />
Remarks: This function disables the interrupt on INT pin and clears the<br />
corresponding Interrupt flag.<br />
Source File: CloseInt0.c<br />
CloseInt1.c<br />
CloseInt2.c<br />
CloseInt3.c<br />
CloseInt4.c<br />
Code Example: CloseINT0();<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 121<br />
ConfigINT0<br />
ConfigINT1<br />
ConfigINT2<br />
ConfigINT3<br />
ConfigINT4<br />
Description: This function configures the interrupt on INT pin.<br />
Include: ports.h<br />
Prototype: void ConfigINT0(unsigned int config);<br />
void ConfigINT1(unsigned int config);<br />
void ConfigINT2(unsigned int config);<br />
void ConfigINT3(unsigned int config);<br />
void ConfigINT4(unsigned int config);<br />
Mô tả: Chức năng này cấu hình ngắt CN.<br />
Bao gồm: ports.h<br />
Prototype: void ConfigIntCN (long int config);<br />
Đối số: cấu hình này là giá trị 32-bit cho cấu hình CN ngắt.<br />
Thấp hơn 24 bit bao gồm các cá nhân cho phép / vô hiệu hóa<br />
thông tin cho CN ngắt. Thiết lập bit x (x = 0, 1, ...,<br />
23) sẽ cho phép ngắt CNX.<br />
Nhất byte trên các cấu hình bao gồm các ưu tiên ngắt<br />
và Enable / Disable bit.<br />
Từ thấp được lưu trữ vào CNEN1register và tiếp theo<br />
byte trên được lưu trữ vào sổ đăng ký CNEN2 và trên<br />
hầu hết các byte được sử dụng để ưu tiên thiết lập và kích hoạt / vô hiệu hóa<br />
CN ngắt.<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này sẽ xóa sạch các interruptflag CN và cho phép / vô hiệu<br />
hóa<br />
ngắt cá nhân trên CN chân.<br />
Điều này cũng có cấu hình ưu tiên ngắt và cho phép / vô hiệu hóa các CN<br />
Kích hoạt tính năng ngắt bit.<br />
Source File: ConfigIntCN.c<br />
Mã số Ví dụ: // này sẽ cho phép CN0, CN1, CN2 và CN7 chỉ.<br />
ConfigIntCN (CHANGE_INT_OFF & CHANGE_INT_PRI_4 &<br />
0xFF000087);<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 123<br />
3.9.2 Macros cá nhân<br />
EnableCN0<br />
EnableCN1<br />
EnableCN2<br />
.....................<br />
EnableCN23<br />
Mô tả: vĩ mô Điều này cho phép các cá nhân thông báo thay đổi gián đoạn.<br />
Bao gồm: ports.h<br />
Lập luận: Không<br />
Bình luận: Không có<br />
Mã số Ví dụ: EnableCN6;<br />
DisableCN0<br />
DisableCN1<br />
DisableCN2<br />
......................
Arguments: config Interrupt edge, priority and enable/disable information as<br />
defined below:<br />
Interrupt edge selection<br />
RISING_EDGE_INT<br />
FALLING_EDGE_INT<br />
Interrupt enable<br />
INT_ENABLE<br />
INT_DISABLE<br />
Interrupt priority<br />
INT_PRI_0<br />
INT_PRI_1<br />
INT_PRI_2<br />
INT_PRI_3<br />
INT_PRI_4<br />
INT_PRI_5<br />
INT_PRI_6<br />
INT_PRI_7<br />
Return Value: None<br />
Remarks: This function clears the interrupt flag corresponding to the INTx pin<br />
and<br />
then selects the edge detect polarity.<br />
It then sets the interrupt priority and enables/disables the interrupt.<br />
Source File: ConfigInt0.c<br />
ConfigInt1.c<br />
ConfigInt2.c<br />
ConfigInt3.c<br />
ConfigInt4.c<br />
Code Example: ConfigINT0(RISING_EDGE_INT& EXT_INT_PRI_5 &<br />
EXT_INT_ENABLE);<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DisableCN23<br />
Mô tả: vĩ mô này vô hiệu hóa cá nhân thông báo thay đổi gián đoạn.<br />
Bao gồm: ports.h<br />
Lập luận: Không<br />
Bình luận: Không có<br />
Mã số Ví dụ: DisableCN14;<br />
EnableINT0<br />
EnableINT1<br />
EnableINT2<br />
EnableINT3<br />
EnableINT4<br />
Mô tả: vĩ mô này cho phép ngắt ngoài cá nhân.<br />
Bao gồm: ports.h<br />
Lập luận: Không<br />
Bình luận: Không có<br />
Mã số Ví dụ: EnableINT2;<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 124 2004 Microchip Technology Inc<br />
DisableINT0<br />
DisableINT1<br />
DisableINT2<br />
DisableINT3<br />
DisableINT4<br />
Mô tả: vĩ mô này vô hiệu hóa ngắt ngoài cá nhân.<br />
Bao gồm: ports.h<br />
Lập luận: Không<br />
Bình luận: Không có<br />
Mã số Ví dụ: DisableINT2;<br />
SetPriorityInt0<br />
SetPriorityInt1<br />
DS51456B-page 122<br />
ConfigCNPullups<br />
2004 Microchip Technology Inc.<br />
SetPriorityInt2<br />
SetPriorityInt3<br />
Description: This function configures the pull-up resistors for CN pins.<br />
Include: ports.h<br />
Prototype: void ConfigCNPullups(long int config);<br />
Arguments: config This is the 32-bit value for configuring pull-ups. The lower<br />
word is stored into CNPU1 register and next upper word is<br />
SetPriorityInt4<br />
Mô tả: Đây ưu tiên bộ vĩ mô cho ngắt ngoài.<br />
Bao gồm: ports.h<br />
Đối số: ưu tiên<br />
Ghi chú: Phần này thiết lập ngắt ngoài bit ưu tiên của ưu tiên ngắt
stored into CNPU2 register. The upper 8 bits of CNPU2<br />
register are unimplemented.<br />
Return Value: None<br />
Remarks: None<br />
Source File: ConfigCNPullups.c<br />
Code Example: ConfigCNPullups(0xFFF);<br />
ConfigIntCN<br />
Description: This function configures the CN interrupts.<br />
Include: ports.h<br />
Prototype: void ConfigIntCN(long int config);<br />
Arguments: config This is the 32-bit value for configuring the CN interrupts.<br />
The lower 24 bits contain the individual enable/disable<br />
information for the CN interrupts. Setting bit x (x = 0, 1, ...,<br />
23) would enable the CNx interrupt.<br />
The upper most byte of config contains the Interrupt Priority<br />
and Enable/Disable bits.<br />
The lower word is stored into the CNEN1register and next<br />
upper byte is stored into the CNEN2 register and the upper<br />
most byte is used for setting priority and enable/disable the<br />
CN interrupts.<br />
Return Value: None<br />
Remarks: This function clears the CN interruptflag and enables/disables the<br />
individual interrupts on CN pins.<br />
This also configures the interrupt priority and enables/disables the CN<br />
Interrupt Enable bit.<br />
Source File: ConfigIntCN.c<br />
Code Example: // This would enable CN0, CN1, CN2 and CN7 only.<br />
ConfigIntCN(CHANGE_INT_OFF & CHANGE_INT_PRI_4 &<br />
0xFF000087);<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 123<br />
3.9.2 Individual Macros<br />
EnableCN0<br />
EnableCN1<br />
EnableCN2<br />
.....................<br />
EnableCN23<br />
Description: This macro enables the individual change notification interrupt.<br />
Include: ports.h<br />
Kiểm soát đăng ký.<br />
Mã số Ví dụ: SetPriorityInt4 (6);<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 125<br />
3.10 VÀO CHỨC NĂNG CAPTURE<br />
Phần này bao gồm một danh sách các chức năng riêng biệt cho Input Capture<br />
module và một<br />
ví dụ về việc sử dụng các chức năng. Chức năng có thể được thực hiện như các<br />
macro.<br />
3.10.1 Chức năng cá nhân<br />
CloseCapture1<br />
CloseCapture2<br />
CloseCapture3<br />
CloseCapture4<br />
CloseCapture5<br />
CloseCapture6<br />
CloseCapture7<br />
CloseCapture8<br />
Mô tả: Chức năng này sẽ tắt các mô-đun Input Capture.<br />
Bao gồm: InCap.h<br />
Prototype: void CloseCapture1 (void);<br />
làm mất hiệu lực CloseCapture2 (void);<br />
làm mất hiệu lực CloseCapture3 (void);<br />
làm mất hiệu lực CloseCapture4 (void);<br />
làm mất hiệu lực CloseCapture5 (void);<br />
làm mất hiệu lực CloseCapture6 (void);<br />
làm mất hiệu lực CloseCapture7 (void);<br />
làm mất hiệu lực CloseCapture8 (void);<br />
Lập luận: Không<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này vô hiệu hóa các Input Capture gián đoạn và sau đó tắt<br />
module.The ngắt Flagbit cũng sẽ bị xóa.<br />
Source File: CloseCapture1.c<br />
CloseCapture2.c<br />
CloseCapture3.c<br />
CloseCapture4.c<br />
CloseCapture5.c<br />
CloseCapture6.c<br />
CloseCapture7.c<br />
CloseCapture8.c
Arguments: None<br />
Remarks: None<br />
Code Example: EnableCN6;<br />
DisableCN0<br />
DisableCN1<br />
DisableCN2<br />
......................<br />
DisableCN23<br />
Description: This macro disables individual change notification interrupt.<br />
Include: ports.h<br />
Arguments: None<br />
Remarks: None<br />
Code Example: DisableCN14;<br />
EnableINT0<br />
EnableINT1<br />
EnableINT2<br />
EnableINT3<br />
EnableINT4<br />
Description: This macro enables the individual external interrupt.<br />
Include: ports.h<br />
Arguments: None<br />
Remarks: None<br />
Code Example: EnableINT2;<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 124 2004 Microchip Technology Inc.<br />
DisableINT0<br />
DisableINT1<br />
DisableINT2<br />
DisableINT3<br />
DisableINT4<br />
Description: This macro disables the individual external interrupt.<br />
Include: ports.h<br />
Arguments: None<br />
Remarks: None<br />
Code Example: DisableINT2;<br />
SetPriorityInt0<br />
SetPriorityInt1<br />
Mã số Ví dụ: CloseCapture1 ();<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 126 2004 Microchip Technology Inc<br />
ConfigIntCapture1<br />
ConfigIntCapture2<br />
ConfigIntCapture3<br />
ConfigIntCapture4<br />
ConfigIntCapture5<br />
ConfigIntCapture6<br />
ConfigIntCapture7<br />
ConfigIntCapture8<br />
Mô tả: Chức năng này cấu hình Input Capture gián đoạn.<br />
Bao gồm: InCap.h<br />
Prototype: void ConfigIntCapture1 (int config);<br />
làm mất hiệu lực ConfigIntCapture2 (int config);<br />
làm mất hiệu lực ConfigIntCapture3 (int config);<br />
làm mất hiệu lực ConfigIntCapture4 (int config);<br />
làm mất hiệu lực ConfigIntCapture5 (int config);<br />
làm mất hiệu lực ConfigIntCapture6 (int config);<br />
làm mất hiệu lực ConfigIntCapture7 (int config);<br />
làm mất hiệu lực ConfigIntCapture8 (int config);<br />
Lập luận: config Input Capture gián đoạn ưu tiên và cho phép / vô hiệu hóa<br />
thông tin theo quy định dưới đây:<br />
Ngắt bật / tắt<br />
IC_INT_ON<br />
IC_INT_OFF<br />
Ưu tiên ngắt<br />
IC_INT_PRIOR_0<br />
IC_INT_PRIOR_1<br />
IC_INT_PRIOR_2<br />
IC_INT_PRIOR_3<br />
IC_INT_PRIOR_4<br />
IC_INT_PRIOR_5<br />
IC_INT_PRIOR_6<br />
IC_INT_PRIOR_7<br />
Trở lại giá trị: Không<br />
Bình luận: Chức năng này sẽ xóa sạch các ngắt Flagbit và sau đó đặt ngắt
SetPriorityInt2<br />
SetPriorityInt3<br />
SetPriorityInt4<br />
Description: This macro sets priority for external interrupts.<br />
Include: ports.h<br />
Arguments: priority<br />
Remarks: This macro sets External Interrupt Priority bits of Interrupt Priority<br />
Control register.<br />
Code Example: SetPriorityInt4(6);<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 125<br />
3.10 INPUT CAPTURE FUNCTIONS<br />
This section contains a list of individual functions for Input Capture module and<br />
an<br />
example of use of the functions. Functions may be implemented as macros.<br />
3.10.1 Individual Functions<br />
CloseCapture1<br />
CloseCapture2<br />
CloseCapture3<br />
CloseCapture4<br />
CloseCapture5<br />
CloseCapture6<br />
CloseCapture7<br />
CloseCapture8<br />
Description: This function turns off the Input Capture module.<br />
Include: InCap.h<br />
Prototype: void CloseCapture1(void);<br />
void CloseCapture2(void);<br />
void CloseCapture3(void);<br />
void CloseCapture4(void);<br />
void CloseCapture5(void);<br />
void CloseCapture6(void);<br />
void CloseCapture7(void);<br />
void CloseCapture8(void);<br />
Arguments: None<br />
Return Value: None<br />
Remarks: This function disables the Input Capture interrupt and then turns off<br />
the<br />
module.The Interrupt Flagbit is also cleared.<br />
Source File: CloseCapture1.c<br />
ưu tiên và cho phép / vô hiệu hóa ngắt.<br />
Source File: ConfigIntCapture1.c<br />
ConfigIntCapture2.c<br />
ConfigIntCapture3.c<br />
ConfigIntCapture4.c<br />
ConfigIntCapture5.c<br />
ConfigIntCapture6.c<br />
ConfigIntCapture7.c<br />
ConfigIntCapture8.c<br />
Mã số Ví dụ: ConfigIntCapture1 (IC_INT_ON & IC_INT_PRIOR_1);<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 127<br />
OpenCapture1<br />
OpenCapture2<br />
OpenCapture3<br />
OpenCapture4<br />
OpenCapture5<br />
OpenCapture6<br />
OpenCapture7<br />
OpenCapture8<br />
Mô tả: Chức năng này cấu hình mô-đun Input Capture.<br />
Bao gồm: InCap.h<br />
Prototype: void OpenCapture1 (int config);<br />
làm mất hiệu lực OpenCapture2 (int config);<br />
làm mất hiệu lực OpenCapture3 (int config);<br />
làm mất hiệu lực OpenCapture4 (int config);<br />
làm mất hiệu lực OpenCapture5 (int config);<br />
làm mất hiệu lực OpenCapture6 (int config);<br />
làm mất hiệu lực OpenCapture7 (int config);<br />
làm mất hiệu lực OpenCapture8 (int config);<br />
Đối số: cấu hình này bao gồm các thông số phải được cấu hình trong<br />
ICxCON đăng ký theo quy định dưới đây:<br />
Hoạt động chế độ nhàn rỗi<br />
IC_IDLE_CON<br />
IC_IDLE_STOP<br />
Đồng hồ chọn<br />
IC_TIMER2_SRC<br />
IC_TIMER3_SRC<br />
Chụp mỗi ngắt
CloseCapture2.c<br />
CloseCapture3.c<br />
CloseCapture4.c<br />
CloseCapture5.c<br />
CloseCapture6.c<br />
CloseCapture7.c<br />
CloseCapture8.c<br />
Code Example: CloseCapture1();<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 126 2004 Microchip Technology Inc.<br />
ConfigIntCapture1<br />
ConfigIntCapture2<br />
ConfigIntCapture3<br />
ConfigIntCapture4<br />
ConfigIntCapture5<br />
ConfigIntCapture6<br />
ConfigIntCapture7<br />
ConfigIntCapture8<br />
Description: This function configures the Input Capture interrupt.<br />
Include: InCap.h<br />
Prototype: void ConfigIntCapture1(unsigned int config);<br />
void ConfigIntCapture2(unsigned int config);<br />
void ConfigIntCapture3(unsigned int config);<br />
void ConfigIntCapture4(unsigned int config);<br />
void ConfigIntCapture5(unsigned int config);<br />
void ConfigIntCapture6(unsigned int config);<br />
void ConfigIntCapture7(unsigned int config);<br />
void ConfigIntCapture8(unsigned int config);<br />
Arguments: config Input Capture interrupt priority and enable/disable<br />
information as defined below:<br />
Interrupt enable/disable<br />
IC_INT_ON<br />
IC_INT_OFF<br />
Interrupt Priority<br />
IC_INT_PRIOR_0<br />
IC_INT_PRIOR_1<br />
IC_INT_PRIOR_2<br />
IC_INT_4CAPTURE<br />
IC_INT_3CAPTURE<br />
IC_INT_2CAPTURE<br />
IC_INT_1CAPTURE<br />
IC_INTERRUPT<br />
Chế độ IC chọn<br />
IC_EVERY_EDGE<br />
IC_EVERY_16_RISE_EDGE<br />
IC_EVERY_4_RISE_EDGE<br />
IC_EVERY_RISE_EDGE<br />
IC_EVERY_FALL_EDGE<br />
IC_INPUTCAP_OFF<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này cấu hình Input Capture Mô-đun kiểm soát đăng ký<br />
(ICxCON) với các thông số sau: Đồng hồ lựa chọn, chụp mỗi<br />
gián đoạn, chế độ chụp hoạt động.<br />
Source File: OpenCapture1.c<br />
OpenCapture2.c<br />
OpenCapture3.c<br />
OpenCapture4.c<br />
OpenCapture5.c<br />
OpenCapture6.c<br />
OpenCapture7.c<br />
OpenCapture8.c<br />
Mã số Ví dụ: OpenCapture1 (IC_IDLE_CON & IC_TIMER2_SRC &<br />
IC_INT_1CAPTURE & IC_EVERY_RISE_EDGE);<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 128 2004 Microchip Technology Inc<br />
ReadCapture1<br />
ReadCapture2<br />
ReadCapture3<br />
ReadCapture4<br />
ReadCapture5<br />
ReadCapture6<br />
ReadCapture7<br />
ReadCapture8<br />
Mô tả: Chức năng này đọc tất cả các cấp phát bộ đệm Input Capture.
IC_INT_PRIOR_3<br />
IC_INT_PRIOR_4<br />
IC_INT_PRIOR_5<br />
IC_INT_PRIOR_6<br />
IC_INT_PRIOR_7<br />
Return Value: None<br />
Remarks: This function clears the Interrupt Flagbit and then sets the interrupt<br />
priority and enables/disables the interrupt.<br />
Source File: ConfigIntCapture1.c<br />
ConfigIntCapture2.c<br />
ConfigIntCapture3.c<br />
ConfigIntCapture4.c<br />
ConfigIntCapture5.c<br />
ConfigIntCapture6.c<br />
ConfigIntCapture7.c<br />
ConfigIntCapture8.c<br />
Code Example: ConfigIntCapture1(IC_INT_ON & IC_INT_PRIOR_1);<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 127<br />
OpenCapture1<br />
OpenCapture2<br />
OpenCapture3<br />
OpenCapture4<br />
OpenCapture5<br />
OpenCapture6<br />
OpenCapture7<br />
OpenCapture8<br />
Description: This function configures the Input Capture module.<br />
Include: InCap.h<br />
Prototype: void OpenCapture1(unsigned int config);<br />
void OpenCapture2(unsigned int config);<br />
void OpenCapture3(unsigned int config);<br />
void OpenCapture4(unsigned int config);<br />
void OpenCapture5(unsigned int config);<br />
void OpenCapture6(unsigned int config);<br />
void OpenCapture7(unsigned int config);<br />
void OpenCapture8(unsigned int config);<br />
Arguments: config This contains the parameters to be configured in the<br />
ICxCON register as defined below:<br />
Bao gồm: InCap.h<br />
Prototype: void ReadCapture1 (int * đệm);<br />
làm mất hiệu lực ReadCapture2 (int * đệm);<br />
làm mất hiệu lực ReadCapture3 (int * đệm);<br />
làm mất hiệu lực ReadCapture4 (int * đệm);<br />
làm mất hiệu lực ReadCapture5 (int * đệm);<br />
làm mất hiệu lực ReadCapture6 (int * đệm);<br />
làm mất hiệu lực ReadCapture7 (int * đệm);<br />
làm mất hiệu lực ReadCapture8 (int * đệm);<br />
Đối số: đệm Đây là con trỏ đến vị trí nơi mà các dữ liệu đọc từ<br />
Input Capture bộ đệm phải được lưu trữ.<br />
Trở lại giá trị: Không<br />
Bình luận: Chức năng này đọc tất cả các cấp phát Input Capture bộ đệm cho đến<br />
khi bộ đệm<br />
được sản phẩm nào được chỉ định bởi ICxCON bit bị xóa.<br />
Source File: ReadCapture1.c<br />
ReadCapture2.c<br />
ReadCapture3.c<br />
ReadCapture4.c<br />
ReadCapture5.c<br />
ReadCapture6.c<br />
ReadCapture7.c<br />
ReadCapture8.c<br />
Mã số Ví dụ: int * đệm = 0x1900;<br />
ReadCapture1 (đệm);<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 129<br />
3.10.2 Macros cá nhân<br />
EnableIntIC1<br />
EnableIntIC2<br />
EnableIntIC3<br />
EnableIntIC4<br />
EnableIntIC5<br />
EnableIntIC6<br />
EnableIntIC7<br />
EnableIntIC8<br />
Mô tả: vĩ mô này cho phép ngắt trên màn hình sự kiện.<br />
Bao gồm: InCap.h<br />
Lập luận: Không<br />
Bình luận: Đây vĩ mô bộ Input Capture Interrupt Enable bit Interrupt Enable
Idle mode operation<br />
IC_IDLE_CON<br />
IC_IDLE_STOP<br />
Clock select<br />
IC_TIMER2_SRC<br />
IC_TIMER3_SRC<br />
Captures per interrupt<br />
IC_INT_4CAPTURE<br />
IC_INT_3CAPTURE<br />
IC_INT_2CAPTURE<br />
IC_INT_1CAPTURE<br />
IC_INTERRUPT<br />
IC mode select<br />
IC_EVERY_EDGE<br />
IC_EVERY_16_RISE_EDGE<br />
IC_EVERY_4_RISE_EDGE<br />
IC_EVERY_RISE_EDGE<br />
IC_EVERY_FALL_EDGE<br />
IC_INPUTCAP_OFF<br />
Return Value: None<br />
Remarks: This function configures the Input Capture Module Control register<br />
(ICxCON) with the following parameters: Clock select, Captures per<br />
interrupt, Capture mode of operation.<br />
Source File: OpenCapture1.c<br />
OpenCapture2.c<br />
OpenCapture3.c<br />
OpenCapture4.c<br />
OpenCapture5.c<br />
OpenCapture6.c<br />
OpenCapture7.c<br />
OpenCapture8.c<br />
Code Example: OpenCapture1(IC_IDLE_CON & IC_TIMER2_SRC &<br />
IC_INT_1CAPTURE & IC_EVERY_RISE_EDGE);<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 128 2004 Microchip Technology Inc.<br />
ReadCapture1<br />
ReadCapture2<br />
Kiểm soát đăng ký.<br />
Mã số Ví dụ: EnableIntIC7;<br />
DisableIntIC1<br />
DisableIntIC2<br />
DisableIntIC3<br />
DisableIntIC4<br />
DisableIntIC5<br />
DisableIntIC6<br />
DisableIntIC7<br />
DisableIntIC8<br />
Mô tả: vĩ mô này vô hiệu hóa ngắt trên màn hình sự kiện.<br />
Bao gồm: InCap.h<br />
Lập luận: Không<br />
Bình luận: vĩ mô này xóa Input Capture Interrupt Enable bit Interrupt Enable<br />
Kiểm soát đăng ký.<br />
Mã số Ví dụ: DisableIntIC7;<br />
SetPriorityIntIC1<br />
SetPriorityIntIC2<br />
SetPriorityIntIC3<br />
SetPriorityIntIC4<br />
SetPriorityIntIC5<br />
SetPriorityIntIC6<br />
SetPriorityIntIC7<br />
SetPriorityIntIC8<br />
Mô tả: Điều này đặt ra ưu tiên vĩ mô cho thu nhập bị gián đoạn.<br />
Bao gồm: InCap.h<br />
Đối số: ưu tiên<br />
Bình luận: vĩ mô bộ Input Capture này bit ưu tiên của ngắt ưu tiên ngắt<br />
Kiểm soát đăng ký.<br />
Mã số Ví dụ: SetPriorityIntIC4 (1);<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 130 2004 Microchip Technology Inc<br />
3.10.3 Ví dụ sử dụng<br />
# xác định __dsPIC30F6014__<br />
# include<br />
# include<br />
int Interrupt_Count = 0, Int_flag, đếm;
ReadCapture3<br />
ReadCapture4<br />
ReadCapture5<br />
ReadCapture6<br />
ReadCapture7<br />
ReadCapture8<br />
Description: This function reads all the pending Input Capture buffers.<br />
Include: InCap.h<br />
Prototype: void ReadCapture1(unsigned int *buffer);<br />
void ReadCapture2(unsigned int *buffer);<br />
void ReadCapture3(unsigned int *buffer);<br />
void ReadCapture4(unsigned int *buffer);<br />
void ReadCapture5(unsigned int *buffer);<br />
void ReadCapture6(unsigned int *buffer);<br />
void ReadCapture7(unsigned int *buffer);<br />
void ReadCapture8(unsigned int *buffer);<br />
Arguments: buffer This is the pointer to the locations where the data read from<br />
the Input Capture buffers have to be stored.<br />
Return Value: None<br />
Remarks: This function reads all the pending Input Capture buffers till the<br />
buffers<br />
are empty indicated by the ICxCON bit getting cleared.<br />
Source File: ReadCapture1.c<br />
ReadCapture2.c<br />
ReadCapture3.c<br />
ReadCapture4.c<br />
ReadCapture5.c<br />
ReadCapture6.c<br />
ReadCapture7.c<br />
ReadCapture8.c<br />
Code Example: unsigned int *buffer = 0x1900;<br />
ReadCapture1(buffer);<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 129<br />
3.10.2 Individual Macros<br />
EnableIntIC1<br />
EnableIntIC2<br />
EnableIntIC3<br />
EnableIntIC4<br />
int timer_first_edge, timer_second_edge;<br />
khoảng trống __attribute __ ((__ interrupt__)) _IC1Interrupt (void)<br />
{<br />
Interrupt_Count ++;<br />
if (Interrupt_Count == 1)<br />
ReadCapture1 (& timer_first_edge);<br />
else if (Interrupt_Count == 2)<br />
ReadCapture1 (& timer_second_edge);<br />
Int_flag = 1;<br />
IFS0bits.IC1IF = 0;<br />
}<br />
int main (void)<br />
{<br />
giai đoạn int unsigned;<br />
Int_flag = 0;<br />
TRISDbits.TRISD0 = 0; / * Đầu ra cảnh báo về RD0 * /<br />
PORTDbits.RD0 = 1;<br />
/ * Cho phép ngắt Timer1 và ưu tiên để "1" * /<br />
ConfigIntCapture1 (IC_INT_PRIOR_1 & IC_INT_ON);<br />
T3CON = 0x8000; / * Timer 3 On * /<br />
/ * Cấu hình các InputCapture trong dừng ở chế độ nhàn rỗi, Timer<br />
3 như là nguồn, làm gián đoạn trên màn hình 1, I / C vào mỗi mùa thu<br />
cạnh * /<br />
OpenCapture1 (IC_IDLE_STOP & IC_TIMER3_SRC &<br />
IC_INT_1CAPTURE & IC_EVERY_FALL_EDGE);<br />
trong khi (1)<br />
{<br />
trong khi (Int_flag); / * Chờ đợi ở đây cho đến khi sự kiện bắt đầu * /<br />
Int_flag = 0;<br />
trong khi (Int_flag); / * Chờ đợi ở đây cho đến khi sự kiện bắt giữ tiếp theo * /<br />
/ * Tính đếm thời gian giữa hai sự kiện chụp * /<br />
thời gian = timer_second_edge - timer_first_edge;<br />
/ * Nếu tính thời gian giữa hai sự kiện chụp nhiều hơn<br />
0x200 tính, thiết lập báo động trên RD0 * /<br />
if (giai đoạn> = 0x200)<br />
{<br />
/ * Thiết lập báo động và chờ đợi đôi khi rõ ràng và báo động * /<br />
PORTDbits.RD0 = 0;<br />
trong khi (count
EnableIntIC5<br />
EnableIntIC6<br />
EnableIntIC7<br />
EnableIntIC8<br />
Description: This macro enables the interrupt on capture event.<br />
Include: InCap.h<br />
Arguments: None<br />
Remarks: This macro sets Input Capture Interrupt Enable bit of Interrupt Enable<br />
Control register.<br />
Code Example: EnableIntIC7;<br />
DisableIntIC1<br />
DisableIntIC2<br />
DisableIntIC3<br />
DisableIntIC4<br />
DisableIntIC5<br />
DisableIntIC6<br />
DisableIntIC7<br />
DisableIntIC8<br />
Description: This macro disables the interrupt on capture event.<br />
Include: InCap.h<br />
Arguments: None<br />
Remarks: This macro clears Input Capture Interrupt Enable bit of Interrupt<br />
Enable<br />
Control register.<br />
Code Example: DisableIntIC7;<br />
SetPriorityIntIC1<br />
SetPriorityIntIC2<br />
SetPriorityIntIC3<br />
SetPriorityIntIC4<br />
SetPriorityIntIC5<br />
SetPriorityIntIC6<br />
SetPriorityIntIC7<br />
SetPriorityIntIC8<br />
Description: This macro sets priority for input capture interrupt.<br />
Include: InCap.h<br />
Arguments: priority<br />
Remarks: This macro sets Input Capture Interrupt Priority bits of Interrupt<br />
Priority<br />
Control register.<br />
Code Example: SetPriorityIntIC4(1);<br />
{<br />
tính ++;<br />
}<br />
PORTDbits.RD0 = 1;<br />
}<br />
Interrupt_Count = 0;<br />
count = 0;<br />
}<br />
CloseCapture1 ();<br />
}<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 131<br />
3.11 OUTPUT SO SÁNH CHỨC NĂNG<br />
Phần này bao gồm một danh sách các chức năng riêng cho đầu ra so sánh các<br />
mô-đun và một<br />
ví dụ về việc sử dụng các chức năng. Chức năng có thể được thực hiện như các<br />
macro.<br />
3.11.1 Chức năng cá nhân<br />
CloseOC1<br />
CloseOC2<br />
CloseOC3<br />
CloseOC4<br />
CloseOC5<br />
CloseOC6<br />
CloseOC7<br />
CloseOC8<br />
Mô tả: Chức năng này sẽ tắt đầu ra so sánh các mô-đun.<br />
Bao gồm: outcompare.h<br />
Prototype: void CloseOC1 (void);<br />
làm mất hiệu lực CloseOC2 (void);<br />
làm mất hiệu lực CloseOC3 (void);<br />
làm mất hiệu lực CloseOC4 (void);<br />
làm mất hiệu lực CloseOC5 (void);<br />
làm mất hiệu lực CloseOC6 (void);<br />
làm mất hiệu lực CloseOC7 (void);<br />
làm mất hiệu lực CloseOC8 (void);<br />
Lập luận: Không<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này vô hiệu hóa các đầu ra so sánh gián đoạn và sau đó tắt<br />
bit module.The Cờ ngắt cũng sẽ bị xóa.
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 130 2004 Microchip Technology Inc.<br />
3.10.3 Example of Use<br />
#define __dsPIC30F6014__<br />
#include <br />
#include<br />
int Interrupt_Count = 0 , Int_flag, count;<br />
unsigned int timer_first_edge, timer_second_edge;<br />
void __attribute__((__interrupt__)) _IC1Interrupt(void)<br />
{<br />
Interrupt_Count++;<br />
if(Interrupt_Count == 1)<br />
ReadCapture1(&timer_first_edge);<br />
else if(Interrupt_Count == 2)<br />
ReadCapture1(&timer_second_edge);<br />
Int_flag = 1;<br />
IFS0bits.IC1IF = 0;<br />
}<br />
int main(void)<br />
{<br />
unsigned int period;<br />
Int_flag = 0;<br />
TRISDbits.TRISD0 = 0; /*Alarm output on RD0 */<br />
PORTDbits.RD0 = 1;<br />
/* Enable Timer1 Interrupt and Priority to '1' */<br />
ConfigIntCapture1(IC_INT_PRIOR_1 & IC_INT_ON);<br />
T3CON = 0x8000; /* Timer 3 On */<br />
/* Configure the InputCapture in stop in idle mode , Timer<br />
3 as source , interrupt on capture 1, I/C on every fall<br />
edge */<br />
OpenCapture1(IC_IDLE_STOP & IC_TIMER3_SRC &<br />
IC_INT_1CAPTURE & IC_EVERY_FALL_EDGE);<br />
while(1)<br />
{<br />
while(!Int_flag); /* wait here till first capture event */<br />
Int_flag = 0;<br />
while(!Int_flag); /* wait here till next capture event */<br />
Source File: CloseOC1.c<br />
CloseOC2.c<br />
CloseOC3.c<br />
CloseOC4.c<br />
CloseOC5.c<br />
CloseOC6.c<br />
CloseOC7.c<br />
CloseOC8.c<br />
Mã số Ví dụ: CloseOC1 ();<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 132 2004 Microchip Technology Inc<br />
ConfigIntOC1<br />
ConfigIntOC2<br />
ConfigIntOC3<br />
ConfigIntOC4<br />
ConfigIntOC5<br />
ConfigIntOC6<br />
ConfigIntOC7<br />
ConfigIntOC8<br />
Mô tả: Chức năng này cấu hình ra so sánh gián đoạn.<br />
Bao gồm: outcompare.h<br />
Prototype: void ConfigIntOC1 (int config);<br />
làm mất hiệu lực ConfigIntOC2 (int config);<br />
làm mất hiệu lực ConfigIntOC3 (int config);<br />
làm mất hiệu lực ConfigIntOC4 (int config);<br />
làm mất hiệu lực ConfigIntOC5 (int config);<br />
làm mất hiệu lực ConfigIntOC6 (int config);<br />
làm mất hiệu lực ConfigIntOC7 (int config);<br />
làm mất hiệu lực ConfigIntOC8 (int config);<br />
Lập luận: config ra so sánh ngắt ưu tiên và cho phép / vô hiệu hóa<br />
thông tin theo quy định dưới đây:<br />
Ngắt bật / tắt<br />
OC_INT_ON<br />
OC_INT_OFF<br />
Ưu tiên ngắt<br />
OC_INT_PRIOR_0<br />
OC_INT_PRIOR_1
* calculate time count between two capture events */<br />
period = timer_second_edge - timer_first_edge;<br />
/* if the time count between two capture events is more than<br />
0x200 counts, set alarm on RD0 */<br />
if(period >= 0x200)<br />
{<br />
/* set alarm and wait for sometime and clear alarm */<br />
PORTDbits.RD0 = 0;<br />
while(count
void CloseOC4(void);<br />
void CloseOC5(void);<br />
void CloseOC6(void);<br />
void CloseOC7(void);<br />
void CloseOC8(void);<br />
Arguments: None<br />
Return Value: None<br />
Remarks: This function disables the Output Compare interrupt and then turns<br />
off<br />
the module.The Interrupt Flag bit is also cleared.<br />
Source File: CloseOC1.c<br />
CloseOC2.c<br />
CloseOC3.c<br />
CloseOC4.c<br />
CloseOC5.c<br />
CloseOC6.c<br />
CloseOC7.c<br />
CloseOC8.c<br />
Code Example: CloseOC1();<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
int value1, value2 int);<br />
khoảng trống OpenOC6 (int config,<br />
int value1, value2 int);<br />
khoảng trống OpenOC7 (int config,<br />
int value1, value2 int);<br />
khoảng trống OpenOC8 (int config,<br />
int value1, value2 int);<br />
Đối số: cấu hình này bao gồm các thông số phải được cấu hình trong<br />
OCxCON đăng ký theo quy định dưới đây:<br />
Hoạt động chế độ nhàn rỗi<br />
OC_IDLE_STOP<br />
OC_IDLE_CON<br />
Đồng hồ chọn<br />
OC_TIMER2_SRC<br />
OC_TIMER3_SRC<br />
Đầu ra so sánh phương thức hoạt động<br />
OC_PWM_FAULT_PIN_ENABLE<br />
OC_PWM_FAULT_PIN_DISABLE<br />
OC_CONTINUE_PULSE<br />
OC_SINGLE_PULSE<br />
OC_TOGGLE_PULSE<br />
OC_HIGH_LOW<br />
DS51456B-page 132<br />
ConfigIntOC1<br />
ConfigIntOC2<br />
ConfigIntOC3<br />
ConfigIntOC4<br />
ConfigIntOC5<br />
ConfigIntOC6<br />
ConfigIntOC7<br />
ConfigIntOC8<br />
2004 Microchip Technology Inc.<br />
OC_LOW_HIGH<br />
OC_OFF<br />
value1 này chứa các giá trị được lưu trữ trong OCxRS thứ<br />
Đăng ký.<br />
value2 này chứa các giá trị được lưu trữ trong OCxR chính<br />
Đăng ký.<br />
Trở lại giá trị: Không<br />
dsPIC<br />
®<br />
Description: This function configures the Output Compare interrupt.<br />
Thư viện Công cụ Ngôn ngữ<br />
Include: outcompare.h<br />
DS51456B trang 134<br />
2004 Microchip Technology Inc<br />
Prototype: void ConfigIntOC1(unsigned int config);<br />
void ConfigIntOC2(unsigned int config);<br />
void ConfigIntOC3(unsigned int config);<br />
void ConfigIntOC4(unsigned int config);<br />
void ConfigIntOC5(unsigned int config);<br />
void ConfigIntOC6(unsigned int config);<br />
Bình luận: Chức năng này cấu hình đăng ký OutputCompare Mô-đun điều khiể<br />
(OCxCON) với các thông số sau:<br />
Đồng hồ lựa chọn, phương thức hoạt động, hoạt động ở chế độ Idle.<br />
Nó cũng có cấu hình OCxRS và OCxR đăng ký.<br />
Source File: OpenOC1.c<br />
OpenOC2.c
void ConfigIntOC7(unsigned int config);<br />
void ConfigIntOC8(unsigned int config);<br />
Arguments: config Output Compare interrupt priority and enable/disable<br />
information as defined below:<br />
Interrupt enable/disable<br />
OC_INT_ON<br />
OC_INT_OFF<br />
Interrupt Priority<br />
OC_INT_PRIOR_0<br />
OC_INT_PRIOR_1<br />
OC_INT_PRIOR_2<br />
OC_INT_PRIOR_3<br />
OC_INT_PRIOR_4<br />
OC_INT_PRIOR_5<br />
OC_INT_PRIOR_6<br />
OC_INT_PRIOR_7<br />
Return Value: None<br />
Remarks: This function clears the Interrupt Flagbit and then sets the interrupt<br />
priority and enables/disables the interrupt.<br />
Source File: ConfigIntOC1.c<br />
ConfigIntOC2.c<br />
ConfigIntOC3.c<br />
ConfigIntOC4.c<br />
ConfigIntOC5.c<br />
ConfigIntOC6.c<br />
ConfigIntOC7.c<br />
ConfigIntOC8.c<br />
Code Example: ConfigIntOC1(OC_INT_ON & OC_INT_PRIOR_2);<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 133<br />
OpenOC1<br />
OpenOC2<br />
OpenOC3<br />
OpenOC4<br />
OpenOC5<br />
OpenOC6<br />
OpenOC7<br />
OpenOC8<br />
Description: This function configures the Output Compare module.<br />
OpenOC3.c<br />
OpenOC4.c<br />
OpenOC5.c<br />
OpenOC6.c<br />
OpenOC7.c<br />
OpenOC8.c<br />
Mã số Ví dụ: OpenOC1 (OC_IDLE_CON & OC_TIMER2_SRC &<br />
OC_PWM_FAULT_PIN_ENABLE, 0x80, 0x60);<br />
OpenOC1 (Tiếp theo)<br />
OpenOC2<br />
OpenOC3<br />
OpenOC4<br />
OpenOC5<br />
OpenOC6<br />
OpenOC7<br />
OpenOC8<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 135<br />
ReadDCOC1PWM<br />
ReadDCOC2PWM<br />
ReadDCOC3PWM<br />
ReadDCOC4PWM<br />
ReadDCOC5PWM<br />
ReadDCOC6PWM<br />
ReadDCOC7PWM<br />
ReadDCOC8PWM<br />
Mô tả: Chức năng này đọc các chu kỳ nhiệm vụ từ đầu ra so sánh thứ<br />
đăng ký.<br />
Bao gồm: outcompare.h<br />
Nguyên mẫu: int ReadDCOC1PWM (void);<br />
int ReadDCOC2PWM (void);<br />
int ReadDCOC3PWM (void);<br />
int ReadDCOC4PWM (void);<br />
int ReadDCOC5PWM (void);<br />
int ReadDCOC6PWM (void);<br />
int ReadDCOC7PWM (void);<br />
int ReadDCOC8PWM (void);<br />
Lập luận: Không<br />
Trở lại giá trị: Chức năng này trả về nội dung của OCxRS đăng ký khi đầu ra
Include: outcompare.h<br />
Prototype: void OpenOC1(unsigned int config,<br />
unsigned int value1, unsigned int value2);<br />
void OpenOC2(unsigned int config,<br />
unsigned int value1, unsigned int value2);<br />
void OpenOC3(unsigned int config,<br />
unsigned int value1, unsigned int value2);<br />
void OpenOC4(unsigned int config,<br />
unsigned int value1, unsigned int value2);<br />
void OpenOC5(unsigned int config,<br />
unsigned int value1, unsigned int value2);<br />
void OpenOC6(unsigned int config,<br />
unsigned int value1, unsigned int value2);<br />
void OpenOC7(unsigned int config,<br />
unsigned int value1, unsigned int value2);<br />
void OpenOC8(unsigned int config,<br />
unsigned int value1, unsigned int value2);<br />
Arguments: config This contains the parameters to be configured in the<br />
OCxCON register as defined below:<br />
Idle mode operation<br />
OC_IDLE_STOP<br />
OC_IDLE_CON<br />
Clock select<br />
OC_TIMER2_SRC<br />
OC_TIMER3_SRC<br />
Output Compare modes of operation<br />
OC_PWM_FAULT_PIN_ENABLE<br />
OC_PWM_FAULT_PIN_DISABLE<br />
OC_CONTINUE_PULSE<br />
OC_SINGLE_PULSE<br />
OC_TOGGLE_PULSE<br />
OC_HIGH_LOW<br />
OC_LOW_HIGH<br />
OC_OFF<br />
value1 This contains the value to be stored into OCxRS Secondary<br />
Register.<br />
value2 This contains the value to be stored into OCxR Main<br />
Register.<br />
Return Value: None<br />
Hãy so sánh các mô-đun ở chế độ PWM. Else '-1' được trả lại<br />
Bình luận: Chức năng này đọc các chu kỳ nhiệm vụ từ đầu ra so sánh thứ<br />
Đăng ký (OCxRS) khi so sánh các mô-đun đầu ra ở chế độ PWM.<br />
Nếu không có trong chế độ PWM, chức năng trả về giá trị của '-1'.<br />
Source File: ReadDCOC1PWM.c<br />
ReadDCOC2PWM.c<br />
ReadDCOC3PWM.c<br />
ReadDCOC4PWM.c<br />
ReadDCOC5PWM.c<br />
ReadDCOC6PWM.c<br />
ReadDCOC7PWM.c<br />
ReadDCOC8PWM.c<br />
Mã số Ví dụ: int compare_reg;<br />
compare_reg = ReadDCOC1PWM ();<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 136 2004 Microchip Technology Inc<br />
ReadRegOC1<br />
ReadRegOC2<br />
ReadRegOC3<br />
ReadRegOC4<br />
ReadRegOC5<br />
ReadRegOC6<br />
ReadRegOC7<br />
ReadRegOC8<br />
Mô tả: Chức năng này đọc cycleregisters nhiệm vụ khi ra so sánh<br />
mô-đun không có trong chế độ PWM.<br />
Bao gồm: outcompare.h<br />
Nguyên mẫu: int ReadRegOC1 (char reg);<br />
int ReadRegOC2 (char reg);<br />
int ReadRegOC3 (char reg);<br />
int ReadRegOC4 (char reg);<br />
int ReadRegOC5 (char reg);<br />
int ReadRegOC6 (char reg);<br />
int ReadRegOC7 (char reg);<br />
int ReadRegOC8 (char reg);<br />
Đối số:<br />
reg Điều này cho thấy nếu đọc nên xảy ra từ chính hoặc
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 134<br />
2004 Microchip Technology Inc.<br />
Remarks: This function configures the OutputCompare Module Control register<br />
(OCxCON)with the following parameters:<br />
Clock select, mode of operation, operation in Idle mode.<br />
It also configures the OCxRS and OCxR registers.<br />
Source File: OpenOC1.c<br />
OpenOC2.c<br />
OpenOC3.c<br />
OpenOC4.c<br />
OpenOC5.c<br />
OpenOC6.c<br />
OpenOC7.c<br />
OpenOC8.c<br />
Code Example: OpenOC1(OC_IDLE_CON & OC_TIMER2_SRC &<br />
OC_PWM_FAULT_PIN_ENABLE, 0x80, 0x60);<br />
OpenOC1 (Continued)<br />
OpenOC2<br />
OpenOC3<br />
OpenOC4<br />
OpenOC5<br />
OpenOC6<br />
OpenOC7<br />
OpenOC8<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 135<br />
ReadDCOC1PWM<br />
ReadDCOC2PWM<br />
ReadDCOC3PWM<br />
ReadDCOC4PWM<br />
ReadDCOC5PWM<br />
ReadDCOC6PWM<br />
ReadDCOC7PWM<br />
ReadDCOC8PWM<br />
Description: This function reads the duty cycle from the Output Compare<br />
Secondary<br />
register.<br />
ghi chu kỳ nhiệm vụ thứ hai của đầu ra so sánh các mô-đun.<br />
Nếu Regis "1", sau đó các nội dung của chính Chu kỳ đăng ký<br />
(OCxR) được đọc.<br />
Nếu Regis "0", sau đó các nội dung của Duty Cycle thứ cấp đăng ký<br />
(OCxRS) được đọc.<br />
Quay trở lại giá trị: Nếu Regis "1", sau đó các nội dung của chính Chu kỳ đăng<br />
ký (OCxR) là<br />
đọc.<br />
Nếu Regis "0", sau đó các nội dung của Duty Cycle thứ cấp đăng ký<br />
(OCxRS) được đọc.<br />
Nếu so sánh các mô-đun đầu ra ở chế độ PWM, '-1' được trả về.<br />
Chú ý: đọc của Chu kỳ chỉ registerhappens khi đầu ra so sánh<br />
mô-đun không có trong chế độ PWM. Khác, một giá trị của '-1' được trả về.<br />
Source File: ReadRegOC1.c<br />
ReadRegOC2.c<br />
ReadRegOC3.c<br />
ReadRegOC4.c<br />
ReadRegOC5.c<br />
ReadRegOC6.c<br />
ReadRegOC7.c<br />
ReadRegOC8.c<br />
Mã số Ví dụ: int dutycycle_reg;<br />
dutycycle_reg = ReadRegOC1 (1);<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 137<br />
SetDCOC1PWM<br />
SetDCOC2PWM<br />
SetDCOC3PWM<br />
SetDCOC4PWM<br />
SetDCOC5PWM<br />
SetDCOC6PWM<br />
SetDCOC7PWM<br />
SetDCOC8PWM<br />
Mô tả: Chức năng này cấu hình ra so sánh Chu kỳ thứ<br />
Đăng ký (OCxRS) khi module đang ở chế độ PWM.<br />
Bao gồm: outcompare.h<br />
Prototype: void SetDCOC1PWM (int dutycycle);<br />
khoảng trống SetDCOC2PWM (int dutycycle);<br />
khoảng trống SetDCOC3PWM (int dutycycle);<br />
khoảng trống SetDCOC4PWM (int dutycycle);
Include: outcompare.h<br />
Prototype: unsigned int ReadDCOC1PWM(void);<br />
unsigned int ReadDCOC2PWM(void);<br />
unsigned int ReadDCOC3PWM(void);<br />
unsigned int ReadDCOC4PWM(void);<br />
unsigned int ReadDCOC5PWM(void);<br />
unsigned int ReadDCOC6PWM(void);<br />
unsigned int ReadDCOC7PWM(void);<br />
unsigned int ReadDCOC8PWM(void);<br />
Arguments: None<br />
Return Value: This function returns the content of OCxRS register when Output<br />
Compare module is in PWM mode. Else ‘-1’ is returned<br />
Remarks: This function reads the duty cycle from the Output Compare<br />
Secondary<br />
register (OCxRS) when Output Compare module is in PWM mode.<br />
If not in PWM mode, the functions returns a value of ‘-1’.<br />
Source File: ReadDCOC1PWM.c<br />
ReadDCOC2PWM.c<br />
ReadDCOC3PWM.c<br />
ReadDCOC4PWM.c<br />
ReadDCOC5PWM.c<br />
khoảng trống SetDCOC5PWM (int dutycycle);<br />
khoảng trống SetDCOC6PWM (int dutycycle);<br />
khoảng trống SetDCOC7PWM (int dutycycle);<br />
khoảng trống SetDCOC8PWM (int dutycycle);<br />
Đối số: dutycycle Đây là giá trị chu kỳ nhiệm vụ được lưu trữ vào đầu ra<br />
So sánh thứ Chu kỳ đăng ký (OCxRS.)<br />
Trở lại giá trị: Không<br />
Chú ý: Đầu ra so sánh thứ DutyCycle đăng ký (OCxRS) sẽ<br />
cấu hình với giá trị mới nếu các mô-đun ở chế độ PWM.<br />
Source File: SetDCOC1PWM.c<br />
SetDCOC2PWM.c<br />
SetDCOC3PWM.c<br />
SetDCOC4PWM.c<br />
SetDCOC5PWM.c<br />
SetDCOC6PWM.c<br />
SetDCOC7PWM.c<br />
SetDCOC8PWM.c<br />
Mã số Ví dụ: SetDCOC1PWM (dutycycle);<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
ReadDCOC6PWM.c<br />
ReadDCOC7PWM.c<br />
ReadDCOC8PWM.c<br />
Code Example: unsigned int compare_reg;<br />
compare_reg = ReadDCOC1PWM();<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B trang 138<br />
SetPulseOC1<br />
SetPulseOC2<br />
SetPulseOC3<br />
SetPulseOC4<br />
SetPulseOC5<br />
SetPulseOC6<br />
SetPulseOC7<br />
2004 Microchip Technology Inc<br />
DS51456B-page 136<br />
ReadRegOC1<br />
ReadRegOC2<br />
ReadRegOC3<br />
ReadRegOC4<br />
ReadRegOC5<br />
ReadRegOC6<br />
ReadRegOC7<br />
ReadRegOC8<br />
2004 Microchip Technology Inc.<br />
SetPulseOC8<br />
Mô tả: Chức năng này cấu hình ra so sánh chính và phụ<br />
đăng ký (OCxR và OCxRS) whenthe mô-đun không có trong chế độ PWM.<br />
Bao gồm: outcompare.h<br />
Prototype: void SetPulseOC1 (int pulse_start,<br />
int pulse_stop);<br />
khoảng trống SetPulseOC2 (int pulse_start,<br />
int pulse_stop);<br />
khoảng trống SetPulseOC3 (int pulse_start,<br />
Description: This function reads the duty cycleregisters when Output Compare<br />
u nsigned int pulse_stop);
module is not in PWM mode.<br />
Include: outcompare.h<br />
Prototype: unsigned int ReadRegOC1(char reg);<br />
unsigned int ReadRegOC2(char reg);<br />
unsigned int ReadRegOC3(char reg);<br />
unsigned int ReadRegOC4(char reg);<br />
unsigned int ReadRegOC5(char reg);<br />
unsigned int ReadRegOC6(char reg);<br />
unsigned int ReadRegOC7(char reg);<br />
unsigned int ReadRegOC8(char reg);<br />
Arguments:<br />
reg This indicates if the read should happen from the main or<br />
secondary duty cycle registers of Output Compare module.<br />
If regis ‘1’, then the contents of Main Duty Cycle register<br />
(OCxR) is read.<br />
If regis ‘0’, then the contents of Secondary Duty Cycle register<br />
(OCxRS) is read.<br />
Return Value: If regis ‘1’, then the contents of Main Duty Cycle register<br />
(OCxR) is<br />
read.<br />
If regis ‘0’, then the contents of Secondary Duty Cycle register<br />
(OCxRS) is read.<br />
If Output Compare module is in PWM mode, ‘-1’ is returned.<br />
Remarks: The read of Duty Cycle registerhappens only when Output Compare<br />
module is not in PWM mode. Else, a value of ‘-1’ is returned.<br />
Source File: ReadRegOC1.c<br />
ReadRegOC2.c<br />
ReadRegOC3.c<br />
ReadRegOC4.c<br />
ReadRegOC5.c<br />
ReadRegOC6.c<br />
ReadRegOC7.c<br />
ReadRegOC8.c<br />
Code Example: unsigned int dutycycle_reg;<br />
dutycycle_reg = ReadRegOC1(1);<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 137<br />
SetDCOC1PWM<br />
SetDCOC2PWM<br />
khoảng trống SetPulseOC4 (int pulse_start,<br />
int pulse_stop);<br />
khoảng trống SetPulseOC5 (int pulse_start,<br />
int pulse_stop);<br />
khoảng trống SetPulseOC6 (int pulse_start,<br />
int pulse_stop);<br />
khoảng trống SetPulseOC7 (int pulse_start,<br />
int pulse_stop);<br />
khoảng trống SetPulseOC8 (int pulse_start,<br />
int pulse_stop);<br />
Đối số: pulse_start này là giá trị được lưu trữ vào đầu ra so sánh<br />
Đăng ký chính (OCxR).<br />
pulse_stop Đây là giá trị được lưu trữ vào đầu ra so sánh<br />
Đăng ký thứ cấp (OCxRS).<br />
Trở lại giá trị: Không<br />
Chú ý: Đầu ra so sánh đăng ký nhiệm vụ chu kỳ (OCxR và OCxRS) sẽ<br />
cấu hình với giá trị mới mô-đun chỉ ifthe không ở chế độ PWM.<br />
Source File: SetPulseOC1.c<br />
SetPulseOC2.c<br />
SetPulseOC3.c<br />
SetPulseOC4.c<br />
SetPulseOC5.c<br />
SetPulseOC6.c<br />
SetPulseOC7.c<br />
SetPulseOC8.c<br />
Mã số Ví dụ: pulse_start = 0x40;<br />
pulse_stop = 0x60;<br />
SetPulseOC1 (pulse_start, pulse_stop);<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 139<br />
3.11.2 Macros cá nhân<br />
EnableIntOC1<br />
EnableIntOC2<br />
EnableIntOC3<br />
EnableIntOC4<br />
EnableIntOC5<br />
EnableIntOC6<br />
EnableIntOC7<br />
EnableIntOC8
SetDCOC3PWM<br />
SetDCOC4PWM<br />
SetDCOC5PWM<br />
SetDCOC6PWM<br />
SetDCOC7PWM<br />
SetDCOC8PWM<br />
Description: This function configures the Output Compare Secondary Duty<br />
Cycle<br />
register (OCxRS )when the module is in PWM mode.<br />
Include: outcompare.h<br />
Prototype: void SetDCOC1PWM(unsigned int dutycycle);<br />
void SetDCOC2PWM(unsigned int dutycycle);<br />
void SetDCOC3PWM(unsigned int dutycycle);<br />
void SetDCOC4PWM(unsigned int dutycycle);<br />
void SetDCOC5PWM(unsigned int dutycycle);<br />
void SetDCOC6PWM(unsigned int dutycycle);<br />
void SetDCOC7PWM(unsigned int dutycycle);<br />
void SetDCOC8PWM(unsigned int dutycycle);<br />
Arguments: dutycycle This is the duty cycle value to be stored into Output<br />
Compare Secondary Duty Cycle register (OCxRS.)<br />
Return Value: None<br />
Remarks: The Output Compare Secondary DutyCycle register (OCxRS) will be<br />
configured with new value only if the module is in PWM mode.<br />
Source File: SetDCOC1PWM.c<br />
SetDCOC2PWM.c<br />
SetDCOC3PWM.c<br />
SetDCOC4PWM.c<br />
SetDCOC5PWM.c<br />
SetDCOC6PWM.c<br />
SetDCOC7PWM.c<br />
SetDCOC8PWM.c<br />
Code Example: SetDCOC1PWM(dutycycle);<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
Mô tả: vĩ mô này cho phép ngắt trên đầu ra so sánh trận đấu.<br />
Bao gồm: outcompare.h<br />
Lập luận: Không<br />
Bình luận: Đây bộ vĩ mô ra so sánh (OC) Interrupt Enable bit Interrupt<br />
Cho phép đăng ký kiểm soát.<br />
Mã số Ví dụ: EnableIntOC8;<br />
DisableIntOC1<br />
DisableIntOC2<br />
DisableIntOC3<br />
DisableIntOC4<br />
DisableIntOC5<br />
DisableIntOC6<br />
DisableIntOC7<br />
DisableIntOC8<br />
Mô tả: vĩ mô này vô hiệu hóa ngắt vào trận đấu so sánh.<br />
Bao gồm: outcompare.h<br />
Lập luận: Không<br />
Bình luận: vĩ mô này sẽ xóa OC Interrupt Enable bit Interrupt Enable kiểm soát<br />
đăng ký.<br />
Mã số Ví dụ: DisableIntOC7;<br />
SetPriorityIntIC1<br />
SetPriorityIntIC2<br />
SetPriorityIntIC3<br />
SetPriorityIntIC4<br />
SetPriorityIntIC5<br />
SetPriorityIntIC6<br />
SetPriorityIntIC7<br />
SetPriorityIntIC8<br />
Mô tả: Điều này đặt ra ưu tiên vĩ mô cho đầu ra so sánh gián đoạn.<br />
Bao gồm: outcompare.h<br />
Đối số: ưu tiên<br />
Bình luận: Đây bộ vĩ mô OC ngắt bit ưu tiên của ngắt ưu tiên kiểm soát<br />
đăng ký.<br />
Mã số Ví dụ: SetPriorityIntOC4 (0);<br />
dsPIC<br />
DS51456B-page 138<br />
SetPulseOC1<br />
2004 Microchip Technology Inc.<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
SetPulseOC2<br />
SetPulseOC3<br />
DS51456B trang 140<br />
3.11.3 Ví dụ sử dụng<br />
2004 Microchip Technology Inc
SetPulseOC4<br />
SetPulseOC5<br />
SetPulseOC6<br />
SetPulseOC7<br />
SetPulseOC8<br />
Description: This function configures the Output Compare main and secondary<br />
registers (OCxR and OCxRS ) whenthe module is not in PWM mode.<br />
Include: outcompare.h<br />
Prototype: void SetPulseOC1(unsigned int pulse_start,<br />
unsigned int pulse_stop);<br />
void SetPulseOC2(unsigned int pulse_start,<br />
unsigned int pulse_stop);<br />
void SetPulseOC3(unsigned int pulse_start,<br />
u nsigned int pulse_stop);<br />
void SetPulseOC4(unsigned int pulse_start,<br />
unsigned int pulse_stop);<br />
void SetPulseOC5(unsigned int pulse_start,<br />
unsigned int pulse_stop);<br />
void SetPulseOC6(unsigned int pulse_start,<br />
unsigned int pulse_stop);<br />
void SetPulseOC7(unsigned int pulse_start,<br />
unsigned int pulse_stop);<br />
void SetPulseOC8(unsigned int pulse_start,<br />
unsigned int pulse_stop);<br />
Arguments: pulse_start This is the value to be stored into Output Compare<br />
Main register (OCxR).<br />
pulse_stop This is the value to be stored into Output Compare<br />
Secondary register (OCxRS).<br />
Return Value: None<br />
Remarks: The Output Compare duty cycle registers (OCxR and OCxRS) will be<br />
configured with new values only ifthe module is not in PWM mode.<br />
Source File: SetPulseOC1.c<br />
SetPulseOC2.c<br />
SetPulseOC3.c<br />
SetPulseOC4.c<br />
SetPulseOC5.c<br />
SetPulseOC6.c<br />
SetPulseOC7.c<br />
SetPulseOC8.c<br />
# xác định __dsPIC30F6014__<br />
# include<br />
# include<br />
/ * Đây là ISR tương ứng với OC1 ngắt * /<br />
khoảng trống __attribute __ ((__ interrupt__)) _OC1Interrupt (void)<br />
{<br />
IFS0bits.OC1IF = 0;<br />
}<br />
int main (void)<br />
{<br />
/ * Giữ giá trị mà tại đó OCX Pin được điều khiển * cao /<br />
int pulse_start;<br />
/ * Giữ giá trị mà tại đó OCX Pin được điều khiển * thấp /<br />
int pulse_stop;<br />
/ * Tắt OC1 mô-đun * /<br />
CloseOC1 ();<br />
/ * Cấu hình đầu ra compare1 ngắt * /<br />
ConfigIntOC1 (OC_INT_OFF & OC_INT_PRIOR_5);<br />
/ * Cấu hình OC1 mô-đun cho yêu cầu độ rộng xung * /<br />
pulse_start = 0x40;<br />
pulse_stop = 0x60;<br />
PR3 = 0x80;<br />
PR1 = 0xffff;<br />
TMR1 = 0x0000;<br />
T3CON = 0x8000;<br />
T1CON = 0x8000;<br />
/ * Cấu hình đầu ra so sánh các mô-đun để 'khởi OCX pin<br />
thấp và tạo ra liên tục pulse'mode * /<br />
OpenOC1 (OC_IDLE_CON & OC_TIMER3_SRC &<br />
OC_CONTINUE_PULSE,<br />
pulse_stop, pulse_start);<br />
/ * Tạo xung liên tục cho đến khi đạt TMR1 0xff00 * /<br />
trong khi (TMR1
Code Example: pulse_start = 0x40 ;<br />
pulse_stop = 0x60 ;<br />
SetPulseOC1(pulse_start, pulse_stop);<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 139<br />
3.11.2 Individual Macros<br />
EnableIntOC1<br />
EnableIntOC2<br />
EnableIntOC3<br />
EnableIntOC4<br />
EnableIntOC5<br />
EnableIntOC6<br />
EnableIntOC7<br />
EnableIntOC8<br />
Description: This macro enables the interrupt on output compare match.<br />
Include: outcompare.h<br />
Arguments: None<br />
Remarks: This macro sets Output Compare (OC) Interrupt Enable bit of<br />
Interrupt<br />
Enable Control register.<br />
Code Example: EnableIntOC8;<br />
DisableIntOC1<br />
DisableIntOC2<br />
DisableIntOC3<br />
DisableIntOC4<br />
DisableIntOC5<br />
DisableIntOC6<br />
DisableIntOC7<br />
DisableIntOC8<br />
Description: This macro disables the interrupt on compare match.<br />
Include: outcompare.h<br />
Arguments: None<br />
Remarks: This macro clears OC Interrupt Enable bit of Interrupt Enable Control<br />
register.<br />
Code Example: DisableIntOC7;<br />
SetPriorityIntIC1<br />
SetPriorityIntIC2<br />
SetPriorityIntIC3<br />
SetPriorityIntIC4<br />
3.12 chức năng UART<br />
Phần này bao gồm một danh sách các chức năng riêng cho module UART và<br />
một ví dụ về<br />
sử dụng các chức năng. Chức năng có thể được thực hiện như các macro.<br />
3.12.1 Chức năng cá nhân<br />
BusyUART1<br />
BusyUART2<br />
Mô tả: Chức năng này trả về tình trạng truyền UART.<br />
Bao gồm: uart.h<br />
Prototype: char BusyUART1 (void);<br />
char BusyUART2 (void);<br />
Lập luận: Không<br />
Quay trở lại giá trị: Nếu "1" được trả lại, nó chỉ ra rằng UART là bận rộn trong<br />
truyền tải và<br />
UxSTA bit "0".<br />
Nếu "0" được trả lại, nó chỉ ra rằng UART là không bận rộn và UxSTA<br />
bit '1'.<br />
Bình luận: Chức năng này trả về tình trạng của UART. Điều này cho thấy nếu<br />
UART<br />
là bận rộn trong truyền như được chỉ ra bởi các UxSTA bit.<br />
Source File: BusyUART1.c<br />
BusyUART2.c<br />
Mã số Ví dụ: trong khi (BusyUART1 ());<br />
CloseUART1<br />
CloseUART2<br />
Mô tả: Chức năng này sẽ tắt các mô-đun UART<br />
Bao gồm: uart.h<br />
Prototype: void CloseUART1 (void);<br />
làm mất hiệu lực CloseUART2 (void);<br />
Lập luận: Không<br />
Trở lại giá trị: Không<br />
Bình luận: Chức năng này đầu tiên sẽ tắt các module UART và sau đó vô hiệu<br />
hóa<br />
UART truyền và nhận interrupts.The Cờ ngắt bit cũng có<br />
xóa.<br />
Source File: CloseUART1.c<br />
CloseUART2.c<br />
Mã số Ví dụ: CloseUART1 ();<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ
SetPriorityIntIC5<br />
SetPriorityIntIC6<br />
SetPriorityIntIC7<br />
SetPriorityIntIC8<br />
Description: This macro sets priority for output compare interrupt.<br />
Include: outcompare.h<br />
Arguments: priority<br />
Remarks: This macro sets OC Interrupt Priority bits of Interrupt Priority Control<br />
register.<br />
Code Example: SetPriorityIntOC4(0);<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 140 2004 Microchip Technology Inc.<br />
3.11.3 Example of Use<br />
#define __dsPIC30F6014__<br />
#include<br />
#include<br />
/* This is ISR corresponding to OC1 interrupt */<br />
void __attribute__((__interrupt__)) _OC1Interrupt(void)<br />
{<br />
IFS0bits.OC1IF = 0;<br />
}<br />
int main(void)<br />
{<br />
/* Holds the value at which OCx Pin to be driven high */<br />
unsigned int pulse_start ;<br />
/* Holds the value at which OCx Pin to be driven low */<br />
unsigned int pulse_stop;<br />
/* Turn off OC1 module */<br />
CloseOC1();<br />
/* Configure output compare1 interrupt */<br />
ConfigIntOC1(OC_INT_OFF & OC_INT_PRIOR_5);<br />
/* Configure OC1 module for required pulse width */<br />
pulse_start = 0x40;<br />
pulse_stop = 0x60;<br />
PR3 = 0x80 ;<br />
PR1 = 0xffff;<br />
TMR1 = 0x0000;<br />
DS51456B trang 142<br />
ConfigIntUART1<br />
ConfigIntUART2<br />
2004 Microchip Technology Inc<br />
Mô tả: Chức năng này cấu hình UART ngắt.<br />
Bao gồm: uart.h<br />
Prototype: void ConfigIntUART1 (int config);<br />
làm mất hiệu lực ConfigIntUART2 (int config);<br />
Lập luận: config cá nhân gián đoạn bật / tắt thông tin theo quy định<br />
dưới đây:<br />
Nhận ngắt cho phép<br />
UART_RX_INT_EN<br />
UART_RX_INT_DIS<br />
Nhận ưu tiên ngắt<br />
UART_RX_INT_PR0<br />
UART_RX_INT_PR1<br />
UART_RX_INT_PR2<br />
UART_RX_INT_PR3<br />
UART_RX_INT_PR4<br />
UART_RX_INT_PR5<br />
UART_RX_INT_PR6<br />
UART_RX_INT_PR7<br />
Truyền gián đoạn cho phép<br />
UART_TX_INT_EN<br />
UART_TX_INT_DIS<br />
Truyền ưu tiên ngắt<br />
UART_TX_INT_PR0<br />
UART_TX_INT_PR1<br />
UART_TX_INT_PR2<br />
UART_TX_INT_PR3<br />
UART_TX_INT_PR4<br />
UART_TX_INT_PR5<br />
UART_TX_INT_PR6<br />
UART_TX_INT_PR7<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này cho phép / vô hiệu hóa các UART truyền và nhận<br />
ngắt và thiết lập các ưu tiên ngắt.<br />
Source File: ConfigIntUART1.c<br />
ConfigIntUART2.c<br />
Mã số Ví dụ: ConfigIntUART1 (UART_RX_INT_EN & UART_RX_INT_PR5<br />
&
T3CON = 0x8000;<br />
T1CON = 0X8000;<br />
/* Configure Output Compare module to 'initialise OCx pin<br />
low and generate continuous pulse'mode */<br />
OpenOC1(OC_IDLE_CON & OC_TIMER3_SRC &<br />
OC_CONTINUE_PULSE,<br />
pulse_stop, pulse_start);<br />
/* Generate continuous pulse till TMR1 reaches 0xff00 */<br />
while(TMR1
Description: This function turns off the UART module<br />
Include: uart.h<br />
Prototype: void CloseUART1(void);<br />
void CloseUART2(void);<br />
Arguments: None<br />
Return Value: None<br />
Remarks: This function first turns off the UART module and then disables the<br />
UART transmit and receive interrupts.The Interrupt Flag bits are also<br />
cleared.<br />
Source File: CloseUART1.c<br />
CloseUART2.c<br />
Code Example: CloseUART1();<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 142 2004 Microchip Technology Inc.<br />
ConfigIntUART1<br />
ConfigIntUART2<br />
Description: This function configures the UART Interrupts.<br />
Include: uart.h<br />
Prototype: void ConfigIntUART1(unsigned int config);<br />
void ConfigIntUART2(unsigned int config);<br />
Arguments: config Individual interrupt enable/disable information as defined<br />
below:<br />
Receive Interrupt enable<br />
UART_RX_INT_EN<br />
UART_RX_INT_DIS<br />
Receive Interrupt Priority<br />
UART_RX_INT_PR0<br />
UART_RX_INT_PR1<br />
UART_RX_INT_PR2<br />
UART_RX_INT_PR3<br />
UART_RX_INT_PR4<br />
UART_RX_INT_PR5<br />
UART_RX_INT_PR6<br />
UART_RX_INT_PR7<br />
Transmit Interrupt enable<br />
UART_TX_INT_EN<br />
UART_TX_INT_DIS<br />
Giao tiếp UART với chân ALT chỉ có sẵn cho<br />
thiết bị nhất định và các bảng dữ liệu phù hợp nên<br />
gọi.<br />
UART Dịch vụ báo thức vào Start<br />
UART_EN_WAKE<br />
UART_DIS_WAKE<br />
Chế độ UART lặp bật / tắt<br />
UART_EN_LOOPBACK<br />
UART_DIS_LOOPBACK<br />
Đầu vào để Capture mô-đun<br />
UART_EN_ABAUD<br />
UART_DIS_ABAUD<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 144 2004 Microchip Technology Inc<br />
Chẵn lẻ và bit dữ liệu chọn<br />
UART_NO_PAR_9BIT<br />
UART_ODD_PAR_8BIT<br />
UART_EVEN_PAR_8BIT<br />
UART_NO_PAR_8BIT<br />
Số Dừng bit<br />
UART_2STOPBITS<br />
UART_1STOPBIT<br />
config2 này chứa các thông số phải được cấu hình trong<br />
UxSTA đăng ký theo quy định dưới đây:<br />
Chế độ UART truyền gián đoạn chọn<br />
UART_INT_TX_BUF_EMPTY<br />
UART_INT_TX<br />
UART Transmit lao bit<br />
UART_TX_PIN_NORMAL<br />
UART_TX_PIN_LOW<br />
UART truyền cho phép / vô hiệu hóa<br />
UART_TX_ENABLE<br />
UART_TX_DISABLE<br />
UART nhận chế độ ngắt chọn<br />
UART_INT_RX_BUF_FUL<br />
UART_INT_RX_3_4_FUL<br />
UART_INT_RX_CHAR
Transmit Interrupt Priority<br />
UART_TX_INT_PR0<br />
UART_TX_INT_PR1<br />
UART_TX_INT_PR2<br />
UART_TX_INT_PR3<br />
UART_TX_INT_PR4<br />
UART_TX_INT_PR5<br />
UART_TX_INT_PR6<br />
UART_TX_INT_PR7<br />
Return Value: None<br />
Remarks: This function enables/disables the UART transmit and receive<br />
interrupts and sets the interrupt priorities.<br />
Source File: ConfigIntUART1.c<br />
ConfigIntUART2.c<br />
Code Example: ConfigIntUART1(UART_RX_INT_EN &<br />
UART_RX_INT_PR5 &<br />
UART_TX_INT_EN & UART_TX_INT_PR3);<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 143<br />
DataRdyUART1<br />
DataRdyUART2<br />
Description: This function returns the UART receive buffer status.<br />
Include: uart.h<br />
Prototype: char DataRdyUART1(void);<br />
char DataRdyUART2(void);<br />
Arguments: None<br />
Return Value: If ‘1’ is returned, it indicates that the receive buffer has a data to<br />
be<br />
read.<br />
If ‘0’ is returned, it indicates that receive buffer does not have any new<br />
data to be read.<br />
Remarks: This function returns the status of the UART receive buffer.<br />
This indicates if the UART receive buffer contains any new data that is<br />
yet to be read as indicated by the UxSTA bit.<br />
Source File: DataRdyUART1.c<br />
DataRdyUART2.c<br />
Code Example: while(DataRdyUART1());<br />
OpenUART1<br />
OpenUART2<br />
Description: This function configures the UART module<br />
Địa chỉ UART phát hiện cho phép / vô hiệu hóa<br />
UART_ADR_DETECT_EN<br />
UART_ADR_DETECT_DIS<br />
UART tràn ngập bit rõ ràng<br />
UART_RX_OVERRUN_CLEAR<br />
ubrg Đây là giá trị được ghi vào UxBRG đăng ký để thiết lập<br />
tốc độ truyền.<br />
Trở lại giá trị: Không<br />
Bình luận: chức năng này cấu hình UART truyền và nhận phần và<br />
thiết lập tốc độ truyền thông tin liên lạc.<br />
Source File: OpenUART1.c<br />
OpenUART2.c<br />
Mã số Ví dụ: baud = 5;<br />
UMODEvalue = UART_EN & UART_IDLE_CON &<br />
UART_DIS_WAKE & UART_EN_LOOPBACK &<br />
UART_EN_ABAUD & UART_NO_PAR_8BIT &<br />
UART_1STOPBIT;<br />
U1STAvalue = UART_INT_TX_BUF_EMPTY &<br />
UART_TX_PIN_NORMAL &<br />
UART_TX_ENABLE &<br />
UART_INT_RX_3_4_FUL &<br />
UART_ADR_DETECT_DIS &<br />
UART_RX_OVERRUN_CLEAR;<br />
OpenUART1 (U1MODEvalue, U1STAvalue, độ truyền);<br />
OpenUART1 (Tiếp theo)<br />
OpenUART2<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 145<br />
ReadUART1<br />
ReadUART2<br />
Mô tả: Chức năng này trả về nội dung của UART nhận được bộ đệm<br />
(UxRXREG)<br />
đăng ký.<br />
Bao gồm: uart.h<br />
Nguyên mẫu: int ReadUART1 (void);<br />
int ReadUART2 (void);<br />
Lập luận: Không<br />
Quay trở lại giá trị: Chức năng này trả về nội dung của Bộ đệm nhận<br />
(UxRXREG)<br />
đăng ký.
Include: uart.h<br />
Prototype: void OpenUART1(unsigned int config1,<br />
unsigned int config2, unsigned int ubrg);<br />
void OpenUART2(unsigned int config1,<br />
unsigned int config2, unsigned int ubrg);<br />
Arguments: config1 This contains the parameters to be configured in the<br />
UxMODE register as defined below:<br />
UART enable/disable<br />
UART_EN<br />
UART_DIS<br />
UART Idle mode operation<br />
UART_IDLE_CON<br />
UART_IDLE_STOP<br />
UART communication with ALT pins<br />
UART_ALTRX_ALTTX<br />
UART_RX_TX<br />
UART communication with ALT pins is available only for<br />
certain devices and the suitable data sheet should be<br />
referred to.<br />
UART Wake-up on Start<br />
UART_EN_WAKE<br />
UART_DIS_WAKE<br />
UART Loopback mode enable/disable<br />
UART_EN_LOOPBACK<br />
UART_DIS_LOOPBACK<br />
Input to Capture module<br />
UART_EN_ABAUD<br />
UART_DIS_ABAUD<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 144 2004 Microchip Technology Inc.<br />
Parity and data bits select<br />
UART_NO_PAR_9BIT<br />
UART_ODD_PAR_8BIT<br />
UART_EVEN_PAR_8BIT<br />
UART_NO_PAR_8BIT<br />
Number of Stop bits<br />
UART_2STOPBITS<br />
Bình luận: Chức năng này trả về các nội dung của bộ đệm nhận đăng ký.<br />
Nếu bit tiếp nhận 9 được kích hoạt, toàn bộ nội dung đăng ký được trả về.<br />
Nếu bit tiếp nhận 8 được kích hoạt, sau đó register được đọc và bit 9 là<br />
đeo mặt nạ.<br />
Source File: ReadUART1.c<br />
ReadUART2.c<br />
Mã số Ví dụ: int rx_data;<br />
Rx_data = ReadUART1 ();<br />
WriteUART1<br />
WriteUART2<br />
Mô tả: Chức năng này ghi dữ liệu được truyền vào bộ đệm truyền<br />
(UxTXREG) đăng ký.<br />
Bao gồm: uart.h<br />
Prototype: void WriteUART1 (dữ liệu int unsigned);<br />
làm mất hiệu lực WriteUART2 (dữ liệu int unsigned);<br />
Đối số: dữ liệu này là các dữ liệu được truyền đi.<br />
Trở lại giá trị: Không<br />
Bình luận: Chức năng này ghi các dữ liệu được truyền vào bộ đệm truyền.<br />
Nếu truyền 9-bit được kích hoạt, giá trị 9-bit được viết vào<br />
truyền đệm.<br />
Nếu truyền 8-bit được kích hoạt, sau đó byte trên được đeo mặt nạ và sau đó<br />
ghi vào bộ đệm truyền.<br />
Source File: WriteUART1.c<br />
WriteUART2.c<br />
Mã số Ví dụ: WriteUART1 (0xFF);<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 146<br />
getsUART1<br />
getsUART2<br />
2004 Microchip Technology Inc<br />
Mô tả: Chức năng này lần đọc một chuỗi các dữ liệu chiều dài quy định và lưu<br />
trữ nó vào<br />
vị trí đệm quy định.<br />
Bao gồm: uart.h<br />
Nguyên mẫu: int getsUART1 (unsigned int dài,<br />
int * buffer, int<br />
uart_data_wait);<br />
int getsUART2 (chiều dài int unsigned,<br />
int * buffer, int
UART_1STOPBIT<br />
config2 This contains the parameters to be configured in the<br />
UxSTA register as defined below:<br />
UART Transmission mode interrupt select<br />
UART_INT_TX_BUF_EMPTY<br />
UART_INT_TX<br />
UART Transmit Break bit<br />
UART_TX_PIN_NORMAL<br />
UART_TX_PIN_LOW<br />
UART transmit enable/disable<br />
UART_TX_ENABLE<br />
UART_TX_DISABLE<br />
UART Receive Interrupt mode select<br />
UART_INT_RX_BUF_FUL<br />
UART_INT_RX_3_4_FUL<br />
UART_INT_RX_CHAR<br />
UART address detect enable/disable<br />
UART_ADR_DETECT_EN<br />
UART_ADR_DETECT_DIS<br />
UART OVERRUN bit clear<br />
UART_RX_OVERRUN_CLEAR<br />
ubrg This is the value to be written into UxBRG register to set the<br />
baud rate.<br />
Return Value: None<br />
Remarks: This functions configures the UART transmit and receive sections<br />
and<br />
sets the communication baud rate.<br />
Source File: OpenUART1.c<br />
OpenUART2.c<br />
Code Example: baud = 5;<br />
UMODEvalue = UART_EN& UART_IDLE_CON &<br />
UART_DIS_WAKE & UART_EN_LOOPBACK &<br />
UART_EN_ABAUD & UART_NO_PAR_8BIT &<br />
UART_1STOPBIT;<br />
U1STAvalue = UART_INT_TX_BUF_EMPTY &<br />
UART_TX_PIN_NORMAL &<br />
UART_TX_ENABLE &<br />
UART_INT_RX_3_4_FUL &<br />
UART_ADR_DETECT_DIS &<br />
uart_data_wait);<br />
Đối số: chiều dài Đây là chiều dài của chuỗi được nhận.<br />
đệm Đây là con trỏ đến vị trí mà các dữ liệu nhận được<br />
phải được lưu trữ.<br />
uart_data_wait Đây là số thời gian chờ cho các mô-đun<br />
đã phải chờ đợi trước khi trở về.<br />
Nếu tính thời gian chờ là 'N', thời gian chờ thực tế<br />
sẽ vào khoảng (19 * N - 1) chu kỳ hướng dẫn.<br />
Trở lại giá trị: Chức năng này trả về số byte chưa được nhận.<br />
Nếu giá trị trả về là "0", nó chỉ ra rằng chuỗi hoàn chỉnh đã được<br />
nhận được.<br />
Nếu giá trị trả về là khác không, nó chỉ ra rằng chuỗi hoàn chỉnh có<br />
không được nhận.<br />
Bình luận: Không có<br />
Source File: getsUART1.c<br />
getsUART2.c<br />
Mã số Ví dụ: Datarem = getsUART1 (6, Rxdata_loc, 40);<br />
putsUART1<br />
putsUART2<br />
Mô tả: Chức năng này ghi một chuỗi các dữ liệu được truyền vào UART<br />
truyền đệm.<br />
Bao gồm: uart.h<br />
Prototype: void putsUART1 (int * đệm);<br />
làm mất hiệu lực putsUART2 (int * đệm);<br />
Đối số: đệm Đây là con trỏ đến chuỗi dữ liệu được truyền đi.<br />
Trở lại giá trị: Không<br />
Bình luận: Chức năng này ghi các dữ liệu được truyền vào bộ đệm truyền<br />
cho đến khi nhân vật NULL là gặp phải.<br />
Một khi bộ đệm truyền là đầy đủ, itwaits đến dữ liệu được truyền và<br />
sau đó ghi dữ liệu tiếp theo vào sổ đăng ký Transmit.<br />
Source File: putsUART1.c<br />
putsUART2.c<br />
Mã số Ví dụ: putsUART1 (Txdata_loc);<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 147<br />
3.12.2 Macros cá nhân<br />
getcUART1<br />
getcUART2<br />
Mô tả: Chức năng này giống hệt nhau toReadUART1 và ReadUART2.
UART_RX_OVERRUN_CLEAR ;<br />
OpenUART1(U1MODEvalue, U1STAvalue, baud);<br />
OpenUART1 (Continued)<br />
OpenUART2<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 145<br />
ReadUART1<br />
ReadUART2<br />
Description: This function returns the content of UART receive buffer<br />
(UxRXREG)<br />
register.<br />
Include: uart.h<br />
Prototype: unsigned int ReadUART1(void);<br />
unsigned int ReadUART2(void);<br />
Arguments: None<br />
Return Value: This function returns the contents of Receive buffer (UxRXREG)<br />
register.<br />
Remarks: This function returns the contents of the Receive Buffer register.<br />
If 9 bit reception is enabled, the entire register content is returned.<br />
If 8 bit reception is enabled, then register is read and the 9th bit is<br />
masked.<br />
Source File: ReadUART1.c<br />
ReadUART2.c<br />
Code Example: unsigned int RX_data;<br />
RX_data = ReadUART1();<br />
WriteUART1<br />
WriteUART2<br />
Description: This function writes data to be transmitted into the transmit buffer<br />
(UxTXREG) register.<br />
Include: uart.h<br />
Prototype: void WriteUART1(unsigned int data);<br />
void WriteUART2(unsigned int data);<br />
Source File: # define để ReadUART1 và ReadUART2 trong uart.h<br />
putcUART1<br />
putcUART2<br />
Mô tả: Chức năng này giống hệt với WriteUART1 và WriteUART2.<br />
Source File: # define để WriteUART1 và WriteUART2 trong uart.h<br />
EnableIntU1RX<br />
EnableIntU2RX<br />
Mô tả: vĩ mô Điều này cho phép các UART nhận được gián đoạn.<br />
Bao gồm: uart.h<br />
Lập luận: Không<br />
Bình luận: vĩ mô bộ UART này Nhận Interrupt Enable bit Interrupt Enable<br />
Kiểm soát đăng ký.<br />
Mã số Ví dụ: EnableIntU2RX;<br />
EnableIntU1TX<br />
EnableIntU2TX<br />
Mô tả: vĩ mô Điều này cho phép các UART truyền gián đoạn.<br />
Bao gồm: uart.h<br />
Lập luận: Không<br />
Bình luận: vĩ mô này đặt UART Transmit Interrupt Enable bit Interrupt Enable<br />
Kiểm soát đăng ký.<br />
Mã số Ví dụ: EnableIntU2TX;<br />
DisableIntU1RX<br />
DisableIntU2RX<br />
Mô tả: vĩ mô này vô hiệu hóa các UART nhận được gián đoạn.<br />
Bao gồm: uart.h<br />
Lập luận: Không<br />
Bình luận: vĩ mô này xóa UART Nhận Interrupt Enable bit Interrupt<br />
Cho phép đăng ký kiểm soát.<br />
Mã số Ví dụ: DisableIntU1RX;<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
Arguments: data This is the data to be transmitted.<br />
Return Value: None<br />
Remarks: This function writes the data to be transmitted into the transmit buffer.<br />
DS51456B trang 148<br />
DisableIntU1TX<br />
DisableIntU2TX<br />
2004 Microchip Technology Inc<br />
If 9-bit transmission is enabled, the 9-bit value is written into the<br />
transmit buffer.<br />
If 8-bit transmission is enabled, then upper byte is masked and then<br />
written into the transmit buffer.<br />
Mô tả: vĩ mô này vô hiệu hóa các UART truyền gián đoạn.<br />
Bao gồm: uart.h<br />
Lập luận: Không<br />
Bình luận: vĩ mô này xóa UART Transmit Interrupt Enable bit Interrupt
Source File: WriteUART1.c<br />
WriteUART2.c<br />
Code Example: WriteUART1(0xFF);<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 146<br />
getsUART1<br />
getsUART2<br />
2004 Microchip Technology Inc.<br />
Description: This function reads a string of data of specified length and stores it<br />
into<br />
the buffer location specified.<br />
Include: uart.h<br />
Prototype: unsigned int getsUART1(unsigned int length,<br />
unsigned int *buffer, unsigned int<br />
uart_data_wait);<br />
unsigned int getsUART2(unsigned int length,<br />
unsigned int *buffer, unsigned int<br />
uart_data_wait);<br />
Arguments: length This is the length of the string to be received.<br />
buffer This is the pointer to the location where the data received<br />
have to be stored.<br />
uart_data_wait This is the timeout count for which the module<br />
has to wait before return.<br />
If the timeout count is ‘N’, the actual timeout<br />
would be about (19*N - 1) instruction cycles.<br />
Return Value: This function returns the number of bytes yet to be received.<br />
If the return value is ‘0’, it indicates that the complete string has been<br />
received.<br />
If the return value is nonzero, it indicates that the complete string has<br />
not been received.<br />
Remarks: None<br />
Source File: getsUART1.c<br />
getsUART2.c<br />
Code Example: Datarem = getsUART1(6, Rxdata_loc, 40);<br />
putsUART1<br />
putsUART2<br />
Description: This function writes a string of data to be transmitted into the<br />
UART<br />
transmit buffer.<br />
Cho phép đăng ký kiểm soát.<br />
Mã số Ví dụ: DisableIntU1TX;<br />
SetPriorityIntU1RX<br />
SetPriorityIntU2RX<br />
Mô tả: Điều này đặt ra ưu tiên vĩ mô cho UART nhận được gián đoạn.<br />
Bao gồm: uart.h<br />
Đối số: ưu tiên<br />
Bình luận: Đây bộ vĩ mô UART Nhận ngắt bit ưu tiên của ưu tiên ngắt<br />
Kiểm soát đăng ký.<br />
Mã số Ví dụ: SetPriorityIntU1RX (6);<br />
SetPriorityIntU1TX<br />
SetPriorityIntU2TX<br />
Mô tả: Điều này đặt ra ưu tiên vĩ mô cho UART truyền gián đoạn.<br />
Bao gồm: uart.h<br />
Đối số: ưu tiên<br />
Bình luận: Đây bộ vĩ mô UART Transmit Interrupt bit ưu tiên của ngắt<br />
Kiểm soát ưu tiên đăng ký.<br />
Mã số Ví dụ: SetPriorityIntU1TX (5);<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 149<br />
3.12.3 Ví dụ sử dụng<br />
# xác định __dsPIC30F6014__<br />
# include<br />
# include<br />
/ * Dữ liệu nhận được lưu trữ trong mảng Buf * /<br />
Buf char [80];<br />
char * Receivedddata = Buf;<br />
/ * Đây là UART1 truyền ISR * /<br />
khoảng trống __attribute __ ((__ interrupt__)) _U1TXInterrupt (void)<br />
{<br />
IFS0bits.U1TXIF = 0;<br />
}<br />
/ * Đây là UART1 nhận ISR * /<br />
khoảng trống __attribute __ ((__ interrupt__)) _U1RXInterrupt (void)<br />
{<br />
IFS0bits.U1RXIF = 0;<br />
/ * Đọc bộ đệm nhận cho đến ít nhất một hoặc nhiều nhân vật có thể<br />
đọc * /<br />
trong khi (DataRdyUART1 ())
Include: uart.h<br />
Prototype: void putsUART1(unsigned int *buffer);<br />
void putsUART2(unsigned int *buffer);<br />
Arguments: buffer This is the pointer to the string of data to be transmitted.<br />
Return Value: None<br />
Remarks: This function writes the data to be transmitted into the transmit buffer<br />
until NULL character is encountered.<br />
Once the transmit buffer is full, itwaits till data gets transmitted and<br />
then writes the next data into the Transmit register.<br />
Source File: putsUART1.c<br />
putsUART2.c<br />
Code Example: putsUART1(Txdata_loc);<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 147<br />
3.12.2 Individual Macros<br />
getcUART1<br />
getcUART2<br />
Description: This function is identical toReadUART1 and ReadUART2.<br />
Source File: #define to ReadUART1 and ReadUART2 in uart.h<br />
putcUART1<br />
putcUART2<br />
Description: This function is identical to WriteUART1 and WriteUART2.<br />
Source File: #define to WriteUART1 and WriteUART2 in uart.h<br />
EnableIntU1RX<br />
EnableIntU2RX<br />
Description: This macro enables the UART receive interrupt.<br />
Include: uart.h<br />
Arguments: None<br />
Remarks: This macro sets UART Receive Interrupt Enable bit of Interrupt<br />
Enable<br />
Control register.<br />
Code Example: EnableIntU2RX;<br />
EnableIntU1TX<br />
EnableIntU2TX<br />
Description: This macro enables the UART transmit interrupt.<br />
Include: uart.h<br />
Arguments: None<br />
Remarks: This macro sets UART Transmit Interrupt Enable bit of Interrupt<br />
Enable<br />
Control register.<br />
{<br />
(* (Receiveddata) ++) = ReadUART1 ();<br />
}<br />
}<br />
int main (void)<br />
{<br />
/ * Dữ liệu được truyền đi bằng cách sử dụng mô-đun giao tiếp UART * /<br />
Txdata char [] = {'M', 'i', 'c', 'r', 'o', 'c', 'h', 'i', 'p', '<br />
',' Tôi ',' C ',' D ',' 2 ',' \ 0 '};<br />
/ * Giữ giá trị đăng ký độ truyền * /<br />
int baudvalue;<br />
/ * Giữ giá trị của UART cấu hình reg * /<br />
int U1MODEvalue;<br />
/ * Giữ các thông tin liên quan đến UART<br />
TX & RX ngắt chế độ * /<br />
int U1STAvalue;<br />
/ * Tắt UART1module * /<br />
CloseUART1 ();<br />
/ * Cấu hình uart1 nhận và truyền gián đoạn * /<br />
ConfigIntUART1 (UART_RX_INT_EN & UART_RX_INT_PR6 &<br />
UART_TX_INT_DIS & UART_TX_INT_PR2);<br />
/ * Cấu hình UART1 mô-đun để truyền 8 bit dữ liệu với một stopbit.<br />
Ngoài ra Kích hoạt chế độ loopback * /<br />
baudvalue = 5;<br />
U1MODEvalue = UART_EN & UART_IDLE_CON &<br />
UART_DIS_WAKE & UART_EN_LOOPBACK &<br />
UART_EN_ABAUD & UART_NO_PAR_8BIT &<br />
UART_1STOPBIT;<br />
U1STAvalue = UART_INT_TX_BUF_EMPTY &<br />
UART_TX_PIN_NORMAL &<br />
UART_TX_ENABLE & UART_INT_RX_3_4_FUL &<br />
UART_ADR_DETECT_DIS &<br />
UART_RX_OVERRUN_CLEAR;<br />
OpenUART1 (U1MODEvalue, U1STAvalue, baudvalue);<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 150 2004 Microchip Technology Inc<br />
/ * Load truyền đệm và truyền đến vô cùng nhân vật là
Code Example: EnableIntU2TX;<br />
DisableIntU1RX<br />
DisableIntU2RX<br />
Description: This macro disables the UART receive interrupt.<br />
Include: uart.h<br />
Arguments: None<br />
Remarks: This macro clears UART Receive Interrupt Enable bit of Interrupt<br />
Enable Control register.<br />
Code Example: DisableIntU1RX;<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 148<br />
DisableIntU1TX<br />
DisableIntU2TX<br />
2004 Microchip Technology Inc.<br />
Description: This macro disables the UART transmit interrupt.<br />
Include: uart.h<br />
Arguments: None<br />
Remarks: This macro clears UART Transmit Interrupt Enable bit of Interrupt<br />
Enable Control register.<br />
Code Example: DisableIntU1TX;<br />
SetPriorityIntU1RX<br />
SetPriorityIntU2RX<br />
Description: This macro sets priority for uart receive interrupt.<br />
Include: uart.h<br />
Arguments: priority<br />
Remarks: This macro sets UART Receive Interrupt Priority bits of Interrupt<br />
Priority<br />
Control register.<br />
Code Example: SetPriorityIntU1RX(6);<br />
SetPriorityIntU1TX<br />
SetPriorityIntU2TX<br />
Description: This macro sets priority for uart transmit interrupt.<br />
Include: uart.h<br />
Arguments: priority<br />
Remarks: This macro sets UART Transmit Interrupt Priority bits of Interrupt<br />
Priority Control register.<br />
Code Example: SetPriorityIntU1TX(5);<br />
dsPIC Peripheral Libraries<br />
gặp phải * /<br />
putsUART1 ((int *) Txdata);<br />
/ * Chờ cho truyền dẫn để hoàn thành * /<br />
trong khi (BusyUART1 ());<br />
/ * Đọc tất cả các dữ liệu còn lại trong bộ đệm nhận là chưa đọc * /<br />
trong khi (DataRdyUART1 ())<br />
{<br />
(* (Receiveddata) ++) = ReadUART1 ();<br />
}<br />
/ * Tắt UART1 mô-đun * /<br />
CloseUART1 ();<br />
trở về 0;<br />
}<br />
3.13 DCI chức năng<br />
Phần này bao gồm một danh sách các individualfunctions cho DCI mô-đun và<br />
một ví dụ về<br />
sử dụng các chức năng. Chức năng có thể được thực hiện như các macro.<br />
3.13.1 Chức năng cá nhân<br />
CloseDCI<br />
Mô tả: Chức năng này sẽ tắt các mô-đun DCI<br />
Bao gồm: dci.h<br />
Prototype: void CloseDCI (void);<br />
Lập luận: Không<br />
Trở lại giá trị: Không<br />
Bình luận: Chức năng này đầu tiên sẽ tắt DCImodule và sau đó vô hiệu hóa các<br />
DCI<br />
interrupt.The Cờ ngắt bit cũng sẽ bị xóa.<br />
Source File: CloseDCI.c<br />
Mã số Ví dụ: CloseDCI ();<br />
BufferEmptyDCI<br />
Mô tả: Chức năng này trả về tình trạng DCI Transmit Buffer Full.<br />
Bao gồm: dci.h<br />
Prototype: char BufferEmptyDCI (void);<br />
Lập luận: Không<br />
Quay trở lại giá trị: Nếu giá trị của TMPTY là "1", sau đó "1" được trả lại, chỉ<br />
ra rằng<br />
truyền đệm trống.<br />
Nếu giá trị của TMPTY là "0", sau đó "0" được trả lại, chỉ ra rằng<br />
truyền đệm là không có sản phẩm nào.<br />
Bình luận: Chức năng này trả về tình trạng của DCISTATbit. Bit này<br />
chỉ ra cho dù bộ đệm truyền rỗng.
2004 Microchip Technology Inc. DS51456B-page 149<br />
3.12.3 Example of Use<br />
#define __dsPIC30F6014__<br />
#include<br />
#include<br />
/* Received data is stored in array Buf */<br />
char Buf[80];<br />
char * Receivedddata = Buf;<br />
/* This is UART1 transmit ISR */<br />
void __attribute__((__interrupt__)) _U1TXInterrupt(void)<br />
{<br />
IFS0bits.U1TXIF = 0;<br />
}<br />
/* This is UART1 receive ISR */<br />
void __attribute__((__interrupt__)) _U1RXInterrupt(void)<br />
{<br />
IFS0bits.U1RXIF = 0;<br />
/* Read the receive buffer till atleast one or more character can be<br />
read */<br />
while( DataRdyUART1())<br />
{<br />
( *( Receiveddata)++) = ReadUART1();<br />
}<br />
}<br />
int main(void)<br />
{<br />
/* Data to be transmitted using UART communication module */<br />
char Txdata[] = {'M','i','c','r','o','c','h','i','p','<br />
','I','C','D','2','\0'};<br />
/* Holds the value of baud register */<br />
unsigned int baudvalue;<br />
/* Holds the value of uart config reg */<br />
unsigned int U1MODEvalue;<br />
/* Holds the information regarding uart<br />
TX & RX interrupt modes */<br />
unsigned int U1STAvalue;<br />
/* Turn off UART1module */<br />
CloseUART1();<br />
/* Configure uart1 receive and transmit interrupt */<br />
Source File: BufferEmptyDCI.c<br />
Mã số Ví dụ: trong khi (BufferEmptyDCI ());<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 151<br />
ConfigIntDCI<br />
Mô tả: Chức năng này cấu hình ngắt DCI.<br />
Bao gồm: dci.h<br />
Prototype: void ConfigIntDCI (int config);<br />
Lập luận: config DCI gián đoạn ưu tiên và bật / tắt thông tin<br />
quy định dưới đây:<br />
DCI ngắt bật / tắt<br />
DCI_INT_ON<br />
DCI_INT_OFF<br />
Ưu tiên DCI ngắt<br />
DCI_INT_PRI_0<br />
DCI_INT_PRI_1<br />
DCI_INT_PRI_2<br />
DCI_INT_PRI_3<br />
DCI_INT_PRI_4<br />
DCI_INT_PRI_5<br />
DCI_INT_PRI_6<br />
DCI_INT_PRI_7<br />
Trở lại giá trị: Không<br />
Bình luận: Chức năng này sẽ xóa sạch các (DCIIF) bit Cờ ngắt và sau đó đặt<br />
gián đoạn ưu tiên và cho phép / vô hiệu hóa ngắt.<br />
Source File: ConfigIntDCI.c<br />
Mã số Ví dụ: ConfigIntDCI (DCI_INT_PRI_6 & DCI_INT_ENABLE);<br />
DataRdyDCI<br />
Mô tả: Chức năng này trả về tình trạng của DCI nhận được bộ đệm.<br />
Bao gồm: dci.h<br />
Prototype: char DataRdyDCI (void);<br />
Lập luận: Không<br />
Quay trở lại giá trị: Nếu giá trị của RFUL là "1", sau đó "1" được trả lại, chỉ ra<br />
rằng dữ liệu<br />
sẵn sàng để được đọc từ bộ đệm nhận.<br />
Nếu giá trị của RFUL là "0", sau đó "0" được trả lại, chỉ ra rằng<br />
nhận được bộ đệm là trống rỗng.<br />
Bình luận: Chức năng này trả về tình trạng của DCISTATbit. Bit này<br />
chỉ ra cho dù các dữ liệu có sẵn trong bộ đệm nhận.<br />
Source File: DataRdyDCI.c
ConfigIntUART1(UART_RX_INT_EN & UART_RX_INT_PR6 &<br />
UART_TX_INT_DIS & UART_TX_INT_PR2);<br />
/* Configure UART1 module to transmit 8 bit data with one stopbit.<br />
Also Enable loopback mode */<br />
baudvalue = 5;<br />
U1MODEvalue = UART_EN & UART_IDLE_CON &<br />
UART_DIS_WAKE & UART_EN_LOOPBACK &<br />
UART_EN_ABAUD & UART_NO_PAR_8BIT &<br />
UART_1STOPBIT;<br />
U1STAvalue = UART_INT_TX_BUF_EMPTY &<br />
UART_TX_PIN_NORMAL &<br />
UART_TX_ENABLE & UART_INT_RX_3_4_FUL &<br />
UART_ADR_DETECT_DIS &<br />
UART_RX_OVERRUN_CLEAR;<br />
OpenUART1(U1MODEvalue, U1STAvalue, baudvalue);<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 150<br />
2004 Microchip Technology Inc.<br />
/* Load transmit buffer and transmit the same till null character is<br />
encountered */<br />
putsUART1 ((unsigned int *)Txdata);<br />
/* Wait for transmission to complete */<br />
while(BusyUART1());<br />
/* Read all the data remaining in receive buffer which are unread */<br />
while(DataRdyUART1())<br />
{<br />
(*( Receiveddata)++) = ReadUART1() ;<br />
}<br />
/* Turn off UART1 module */<br />
CloseUART1();<br />
return 0;<br />
}<br />
3.13 DCI FUNCTIONS<br />
This section contains a list of individualfunctions for DCI module and an<br />
example of<br />
use of the functions. Functions may be implemented as macros.<br />
3.13.1 Individual Functions<br />
CloseDCI<br />
Mã số Ví dụ: trong khi (DataRdyDCI ());<br />
OpenDCI<br />
Mô tả: Chức năng này cấu hình DCI.<br />
Bao gồm: dci.h<br />
Prototype: void OpenDCI (int config1,<br />
int config2,<br />
int config3,<br />
int trans_mask,<br />
recv_mask unsigned int)<br />
Đối số: config1 này chứa các thông số được cấu hình trong<br />
các DCION1 đăng ký theo quy định dưới đây:<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 152 2004 Microchip Technology Inc<br />
Mô-đun On / Off<br />
DCI_EN<br />
DCI_DIS<br />
Hoạt động chế độ nhàn rỗi<br />
DCI_IDLE_CON<br />
DCI_IDLE_STOP<br />
Chế độ DCI lặp phép<br />
DCI_DIGI_LPBACK_EN<br />
DCI_DIGI_LPBACK_DIS<br />
CSCK pin hướng chọn<br />
DCI_SCKD_INP<br />
DCI_SCKD_OUP<br />
Lựa chọn cạnh lấy mẫu DCI<br />
DCI_SAMP_CLK_RIS<br />
DCI_SAMP_CLK_FAL<br />
FS pin hướng chọn<br />
DCI_FSD_INP<br />
DCI_FSD_OUP<br />
dữ liệu được truyền trong Van cân bằng<br />
DCI_TX_LASTVAL_UNF<br />
DCI_TX_ZERO_UNF<br />
SDO tình trạng pin trong quá trình phát vô hiệu hóa<br />
DCI_SDO_TRISTAT<br />
DCI_SDO_ZERO
Description: This function turns off the DCI module<br />
Include: dci.h<br />
Prototype: void CloseDCI(void);<br />
Arguments: None<br />
Return Value: None<br />
Remarks: This function first turns off the DCImodule and then disables the DCI<br />
interrupt.The Interrupt Flag bit is also cleared.<br />
Source File: CloseDCI.c<br />
Code Example: CloseDCI();<br />
BufferEmptyDCI<br />
Description: This function returns the DCI Transmit Buffer Full status.<br />
Include: dci.h<br />
Prototype: char BufferEmptyDCI(void);<br />
Arguments: None<br />
Return Value: If the value of TMPTY is ‘1’, then ‘1’ is returned, indicating that<br />
the<br />
transmit buffer is empty.<br />
If the value of TMPTY is ‘0’, then ‘0’ is returned, indicating that the<br />
transmit buffer is not empty.<br />
Remarks: This function returns the status of the DCISTAT bit. This<br />
bit<br />
indicates whether the transmit buffer is empty.<br />
Source File: BufferEmptyDCI.c<br />
Code Example: while(!BufferEmptyDCI());<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 151<br />
ConfigIntDCI<br />
Description: This function configures the DCI interrupt.<br />
Include: dci.h<br />
Prototype: void ConfigIntDCI(unsigned int config);<br />
Arguments: config DCI interrupt priority and enable/disable information as<br />
defined below:<br />
DCI Interrupt enable/disable<br />
DCI_INT_ON<br />
DCI_INT_OFF<br />
DCI Interrupt priority<br />
DCI_INT_PRI_0<br />
DCI_INT_PRI_1<br />
DCI_INT_PRI_2<br />
DCI_INT_PRI_3<br />
Kiểm soát biện minh dữ liệu<br />
DCI_DJST_ON<br />
DCI_DJST_OFF<br />
Khung chế độ Sync chọn<br />
DCI_FSM_ACLINK_20BIT<br />
DCI_FSM_ACLINK_16BIT<br />
DCI_FSM_I2S<br />
DCI_FSM_MULTI<br />
config2 này chứa các thông số được cấu hình trong<br />
các DCICON2 đăng ký theo quy định dưới đây:<br />
Đệm dài<br />
DCI_BUFF_LEN_4<br />
DCI_BUFF_LEN_3<br />
DCI_BUFF_LEN_2<br />
DCI_BUFF_LEN_1<br />
DCI Khung điều khiển máy phát đồng bộ<br />
DCI_FRAME_LEN_16<br />
DCI_FRAME_LEN_15<br />
DCI_FRAME_LEN_14<br />
.....<br />
DCI_FRAME_LEN_1<br />
DCI kích thước từ dữ liệu<br />
DCI_DATA_WORD_16<br />
DCI_DATA_WORD_15<br />
DCI_DATA_WORD_14<br />
.....<br />
DCI_DATA_WORD_5<br />
DCI_DATA_WORD_4<br />
OpenDCI (Tiếp theo)<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 153<br />
config3 này chứa các bit giá trị máy phát điện đồng hồ để được<br />
cấu hình trong đăng ký DCICON3.<br />
trans_mask / này chứa các truyền / nhận khe<br />
recv_mask Enable bit được cấu hình vào TSCON /<br />
RSCON đăng ký theo quy định dưới đây:<br />
DCI_DIS_SLOT_15<br />
DCI_DIS_SLOT_14<br />
.....
DCI_INT_PRI_4<br />
DCI_INT_PRI_5<br />
DCI_INT_PRI_6<br />
DCI_INT_PRI_7<br />
Return Value: None<br />
Remarks: This function clears the Interrupt Flag (DCIIF) bit and then sets the<br />
interrupt priority and enables/disables the interrupt.<br />
Source File: ConfigIntDCI.c<br />
Code Example: ConfigIntDCI(DCI_INT_PRI_6& DCI_INT_ENABLE);<br />
DataRdyDCI<br />
Description: This function returns the status of DCI receive buffers.<br />
Include: dci.h<br />
Prototype: char DataRdyDCI(void);<br />
Arguments: None<br />
Return Value: If the value of RFUL is ‘1’, then ‘1’ is returned, indicating that<br />
the data is<br />
ready to be read from the receive buffers.<br />
If the value of RFUL is ‘0’, then ‘0’ is returned, indicating that the<br />
receive buffers are empty.<br />
Remarks: This function returns the status of the DCISTAT bit. This bit<br />
indicates whether the data is available in the receive buffers.<br />
Source File: DataRdyDCI.c<br />
Code Example: while(!DataRdyDCI());<br />
OpenDCI<br />
Description: This function configures the DCI.<br />
Include: dci.h<br />
Prototype: void OpenDCI(unsigned int config1,<br />
unsigned int config2,<br />
unsigned int config3,<br />
unsigned int trans_mask,<br />
unsigned int recv_mask)<br />
Arguments: config1 This contains the parameters to be configured in<br />
the DCION1 register as defined below:<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DCI_DIS_SLOT_1<br />
DCI_DIS_SLOT_0<br />
DCI_EN_SLOT_ALL<br />
DCI_DIS_SLOT_ALL<br />
Trở lại giá trị: Không<br />
Bình luận: thói quen này cấu hình các thông số sau:<br />
1. DCICON1 đăng ký:<br />
Bit cho phép,<br />
Khung chế độ Sync,<br />
Giải thích dữ liệu,<br />
Hướng mẫu đồng hồ,<br />
Đồng hồ mẫu,<br />
Cạnh kiểm soát,<br />
Dẫn đầu ra Đồng bộ khung kiểm soát,<br />
Truyền liên tục / Nhận chế độ,<br />
Chế độ Van cân bằng.<br />
2. DCICON2 đăng ký:<br />
Khung Sync phát điện điều khiển,<br />
Kích thước bit dữ liệu Word,<br />
Đệm bit lượng kiểm soát.<br />
3. DCICON3 đăng ký: Clock Generator kiểm soát bit<br />
4. TSCON đăng ký: Truyền khe thời gian Enable bit kiểm soát.<br />
5. RSCON đăng ký: Nhận Giờ Khe cắm Enable bit kiểm soát.<br />
Source File: OpenDCI.c<br />
Mã số Ví dụ: DCICON1value = DCI_EN &<br />
DCI_IDLE_CON &<br />
DCI_DIGI_LPBACK_EN &<br />
DCI_SCKD_OUP &<br />
DCI_SAMP_CLK_FAL &<br />
DCI_FSD_OUP &<br />
DCI_TX_LASTVAL_UNF &<br />
DCI_SDO_TRISTAT &<br />
DCI_DJST_OFF &<br />
DCI_FSM_ACLINK_16BIT;<br />
DCICON2value = DCI_BUFF_LEN_4 &<br />
DCI_FRAME_LEN_2 &<br />
DS51456B-page 152<br />
Module On/Off<br />
DCI_EN<br />
2004 Microchip Technology Inc.<br />
DCI_DATA_WORD_16;<br />
DCICON3value = 0x02;<br />
RSCONvalue = DCI_EN_SLOT_ALL &
DCI_DIS<br />
Idle mode operation<br />
DCI_IDLE_CON<br />
DCI_IDLE_STOP<br />
DCI Loopback mode enable<br />
DCI_DIGI_LPBACK_EN<br />
DCI_DIGI_LPBACK_DIS<br />
CSCK pin direction select<br />
DCI_SCKD_INP<br />
DCI_SCKD_OUP<br />
DCI sampling edge selection<br />
DCI_SAMP_CLK_RIS<br />
DCI_SAMP_CLK_FAL<br />
FS pin direction select<br />
DCI_FSD_INP<br />
DCI_FSD_OUP<br />
data to be transmitted during underflow<br />
DCI_TX_LASTVAL_UNF<br />
DCI_TX_ZERO_UNF<br />
SDO pin status during transmit disable<br />
DCI_SDO_TRISTAT<br />
DCI_SDO_ZERO<br />
Data justification control<br />
DCI_DJST_ON<br />
DCI_DJST_OFF<br />
Frame Sync mode select<br />
DCI_FSM_ACLINK_20BIT<br />
DCI_FSM_ACLINK_16BIT<br />
DCI_FSM_I2S<br />
DCI_FSM_MULTI<br />
config2 This contains the parameters to be configured in<br />
the DCICON2 register as defined below:<br />
Buffer length<br />
DCI_BUFF_LEN_4<br />
DCI_BUFF_LEN_3<br />
DCI_BUFF_LEN_2<br />
DCI_BUFF_LEN_1<br />
DCI Frame sync generator control<br />
DCI_FRAME_LEN_16<br />
DCI_DIS_SLOT_15 &<br />
DCI_DIS_SLOT_9 &<br />
DCI_DIS_SLOT_2;<br />
TSCONvalue = DCI_EN_SLOT_ALL &<br />
DCI_DIS_SLOT_14 &<br />
DCI_DIS_SLOT_8 &<br />
DCI_DIS_SLOT_1;<br />
OpenDCI (DCICON1value, DCICON2value, DCICON3value,<br />
TSCONvalue, RSCONvalue);<br />
OpenDCI (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 154 2004 Microchip Technology Inc<br />
ReadDCI<br />
Mô tả: Chức năng này đọc nội dung của DCI bộ đệm nhận.<br />
Bao gồm: dci.h<br />
Nguyên mẫu: int ReadDCI (unsigned char buffer);<br />
Đối số: bufferThis là số đệm DCI để được đọc.<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này trả về nội dung ofDCI nhận được đệm chỉ bởi<br />
đệm.<br />
Source File: ReadDCI.c<br />
Mã số Ví dụ: int DCI_buf0;<br />
DCI_buf0 = ReadDCI (0);<br />
WriteDCI<br />
Mô tả: Chức năng này ghi các dữ liệu được truyền tới truyền DCI<br />
đệm.<br />
Bao gồm: dci.h<br />
Prototype: void WriteDCI (int data_out,<br />
unsigned char buffer);<br />
Đối số: data_out Đây là các dữ liệu được truyền đi.<br />
đệm Đây là số lượng bộ đệm DCI được ghi.<br />
Trở lại giá trị: Không<br />
Bình luận: Chức năng này tải bộ đệm truyền theo quy định của bufferwith<br />
data_out.<br />
Source File: WriteDCI.c<br />
Mã số Ví dụ: int DCI_tx0 = 0x60;<br />
WriteDCI (DCI_tx0, 0);
DCI_FRAME_LEN_15<br />
DCI_FRAME_LEN_14<br />
.....<br />
DCI_FRAME_LEN_1<br />
DCI data word size<br />
DCI_DATA_WORD_16<br />
DCI_DATA_WORD_15<br />
DCI_DATA_WORD_14<br />
.....<br />
DCI_DATA_WORD_5<br />
DCI_DATA_WORD_4<br />
OpenDCI (Continued)<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 153<br />
config3 This contains the bit clock generator value to be<br />
configured in the DCICON3 register.<br />
trans_mask/ This contains the transmit/receive slot<br />
recv_mask Enable bits to be configured into the TSCON/<br />
RSCON register as defined below:<br />
DCI_DIS_SLOT_15<br />
DCI_DIS_SLOT_14<br />
.....<br />
DCI_DIS_SLOT_1<br />
DCI_DIS_SLOT_0<br />
DCI_EN_SLOT_ALL<br />
DCI_DIS_SLOT_ALL<br />
Return Value: None<br />
Remarks: This routine configures the following parameters:<br />
1. DCICON1 register:<br />
Enable bit,<br />
Frame Sync mode,<br />
Data Justification,<br />
Sample Clock Direction,<br />
Sample Clock,<br />
Edge Control,<br />
Output Frame Synchronization Directions Control,<br />
Continuous Transmit/Receive mode,<br />
Underflow mode.<br />
2. DCICON2 register:<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 155<br />
3.13.2 Macros cá nhân<br />
EnableIntDCI<br />
Mô tả: vĩ mô này cho phép ngắt DCI.<br />
Bao gồm: dci.h<br />
Lập luận: Không<br />
Bình luận: Đây bộ vĩ mô DCI ngắt Enablebit của ngắt Chức năng Kiểm soát<br />
đăng ký.<br />
Mã số Ví dụ: EnableIntDCI;<br />
DisableIntDCI<br />
Mô tả: vĩ mô này vô hiệu hóa ngắt DCI.<br />
Bao gồm: dci.h<br />
Lập luận: Không<br />
Bình luận: vĩ mô này sẽ xóa DCI Interrupt Enable bit Interrupt Enable kiểm soá<br />
đăng ký.<br />
Mã số Ví dụ: DisableIntDCI;<br />
SetPriorityIntDCI<br />
Mô tả: Đây ưu tiên bộ vĩ mô cho DCI bị gián đoạn.<br />
Bao gồm: dci.h<br />
Đối số: ưu tiên<br />
Bình luận: Đây bộ vĩ mô DCI ngắt bit ưu tiên của ngắt ưu tiên kiểm soát<br />
đăng ký.<br />
Mã số Ví dụ: SetPriorityIntDCI (4);<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 156 2004 Microchip Technology Inc<br />
3.13.3 Ví dụ sử dụng<br />
# xác định __dsPIC30F6014__<br />
# include<br />
# include<br />
/ * Dữ liệu nhận được lưu trữ từ 0x1820 trở đi. * /<br />
int * Receiveddata = (int *) 0x1820;<br />
khoảng trống __attribute __ ((__ interrupt__)) _DCIInterrupt (void)<br />
{<br />
IFS2bits.DCIIF = 0;<br />
}<br />
int main (void)
Frame Sync Generator Control,<br />
Data Word Size bits,<br />
Buffer Length Control bits.<br />
3. DCICON3 register: Clock Generator Control bits<br />
4. TSCON register: Transmit TimeSlot Enable Control bits.<br />
5. RSCON register: Receive Time Slot Enable Control bits.<br />
Source File: OpenDCI.c<br />
Code Example: DCICON1value = DCI_EN &<br />
DCI_IDLE_CON &<br />
DCI_DIGI_LPBACK_EN &<br />
DCI_SCKD_OUP &<br />
DCI_SAMP_CLK_FAL &<br />
DCI_FSD_OUP &<br />
DCI_TX_LASTVAL_UNF &<br />
DCI_SDO_TRISTAT &<br />
DCI_DJST_OFF &<br />
DCI_FSM_ACLINK_16BIT ;<br />
DCICON2value = DCI_BUFF_LEN_4 &<br />
DCI_FRAME_LEN_2&<br />
DCI_DATA_WORD_16 ;<br />
DCICON3value = 0x02 ;<br />
RSCONvalue = DCI_EN_SLOT_ALL &<br />
DCI_DIS_SLOT_15 &<br />
DCI_DIS_SLOT_9 &<br />
DCI_DIS_SLOT_2;<br />
TSCONvalue = DCI_EN_SLOT_ALL &<br />
DCI_DIS_SLOT_14 &<br />
DCI_DIS_SLOT_8 &<br />
DCI_DIS_SLOT_1;<br />
OpenDCI(DCICON1value, DCICON2value, DCICON3value,<br />
TSCONvalue, RSCONvalue);<br />
OpenDCI (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 154 2004 Microchip Technology Inc.<br />
ReadDCI<br />
Description: This function reads the contents of DCI receive buffer.<br />
Include: dci.h<br />
{<br />
/ * Dữ liệu được truyền đi bằng cách sử dụng mô-đun DCI * /<br />
data16 unsigned int [] = {0xABCD, 0x1234, 0x1578,<br />
0xfff0, 0xf679};<br />
/ * Giữ thông tin cấu hình * /<br />
int DCICON1value;<br />
/ * Giữ giá trị của framelength, wordsize và chiều dài đệm * /<br />
int DCICON2value;<br />
/ * Giữ thông tin reagarding đồng hồ bit<br />
máy phát điện * /<br />
int DCICON3value;<br />
/ * Giữ các thông tin dữ liệu reagarding hy vọng sẽ nhận được<br />
hoặc bỏ qua trong thời gian này khe cắm * /<br />
int RSCONvalue;<br />
/ * Giữ thông tin reagarding truyền đệm<br />
nội dung được gửi Nam trong giai đoạn khe thời gian * /<br />
int TSCONvalue;<br />
int i;<br />
CloseDCI ();<br />
/ * Cấu hình DCI nhận / truyền gián đoạn * /<br />
ConfigIntDCI (DCI_INT_ON & DCI_INT_PRI_6);<br />
/ * Cấu hình DCI mô-đun để truyền dữ liệu 16 bit với chế độ đa kênh<br />
* /<br />
DCICON1value = DCI_EN & DCI_IDLE_CON &<br />
DCI_DIGI_LPBACK_EN &<br />
DCI_SCKD_OUP &<br />
DCI_SAMP_CLK_FAL &<br />
DCI_FSD_OUP &<br />
DCI_TX_ZERO_UNF &<br />
DCI_SDO_TRISTAT &<br />
DCI_DJST_OFF &<br />
DCI_FSM_MULTI;<br />
DCICON2value = DCI_BUFF_LEN_4 & DCI_FRAME_LEN_4 &<br />
DCI_DATA_WORD_16;<br />
DCICON3value = 0x00;<br />
RSCONvalue = DCI_EN_SLOT_ALL & DCI_DIS_SLOT_11 &<br />
DCI_DIS_SLOT_4 & DCI_DIS_SLOT_5;<br />
TSCONvalue = DCI_EN_SLOT_ALL & DCI_DIS_SLOT_11 &<br />
DCI_DIS_SLOT_4 & DCI_DIS_SLOT_5;
Prototype: unsigned int ReadDCI(unsigned char buffer);<br />
Arguments: bufferThis is the DCI buffer number to be read.<br />
Return Value: None<br />
Remarks: This function returns the contents ofDCI receive buffer pointed by the<br />
buffer.<br />
Source File: ReadDCI.c<br />
Code Example: unsigned int DCI_buf0;<br />
DCI_buf0 = ReadDCI(0);<br />
WriteDCI<br />
Description: This function writes the data to be transmitted to the DCI transmit<br />
buffer.<br />
Include: dci.h<br />
Prototype: void WriteDCI(unsigned int data_out,<br />
unsigned char buffer);<br />
Arguments: data_out This is the data to be transmitted.<br />
buffer This is the DCI buffer number to be written.<br />
Return Value: None<br />
Remarks: This function loads the transmit buffer specified by the bufferwith<br />
data_out.<br />
Source File: WriteDCI.c<br />
Code Example: unsigned int DCI_tx0 = 0x60;<br />
WriteDCI(DCI_tx0, 0);<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 155<br />
3.13.2 Individual Macros<br />
EnableIntDCI<br />
Description: This macro enables the DCI interrupt.<br />
Include: dci.h<br />
Arguments: None<br />
Remarks: This macro sets DCI Interrupt Enablebit of Interrupt Enable Control<br />
register.<br />
Code Example: EnableIntDCI;<br />
DisableIntDCI<br />
Description: This macro disables the DCI interrupt.<br />
Include: dci.h<br />
Arguments: None<br />
Remarks: This macro clears DCI Interrupt Enable bit of Interrupt Enable<br />
Control<br />
register.<br />
OpenDCI (DCICON1value, DCICON2value, DCICON3value,<br />
TSCONvalue, RSCONvalue);<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 157<br />
/ * Load truyền đệm và truyền cùng * /<br />
i = 0;<br />
trong khi (i
Code Example: DisableIntDCI;<br />
SetPriorityIntDCI<br />
Description: This macro sets priority for DCI interrupt.<br />
Include: dci.h<br />
Arguments: priority<br />
Remarks: This macro sets DCI Interrupt Priority bits of Interrupt Priority<br />
Control<br />
register.<br />
Code Example: SetPriorityIntDCI(4);<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
Mô tả: Chức năng này cấu hình SPI ngắt.<br />
Bao gồm: spi.h<br />
Prototype: void ConfigIntSPI1 (int config);<br />
làm mất hiệu lực ConfigIntSPI2 (int config);<br />
Đối số: cấu hình SPI ngắt ưu tiên và bật / tắt thông tin<br />
quy định dưới đây:<br />
Ngắt bật / tắt<br />
SPI_INT_EN<br />
SPI_INT_DIS<br />
Ưu tiên ngắt<br />
SPI_INT_PRI_0<br />
SPI_INT_PRI_1<br />
DS51456B-page 156<br />
3.13.3 Example of Use<br />
2004 Microchip Technology Inc.<br />
SPI_INT_PRI_2<br />
SPI_INT_PRI_3<br />
#define __dsPIC30F6014__<br />
#include<br />
#include<br />
/* Received data is stored from 0x1820 onwards. */<br />
unsigned int * Receiveddata = ( unsigned int *)0x1820;<br />
void __attribute__((__interrupt__)) _DCIInterrupt(void)<br />
{<br />
IFS2bits.DCIIF = 0;<br />
}<br />
int main(void)<br />
{<br />
/* Data to be transmitted using DCI module */<br />
unsigned int data16[] = {0xabcd, 0x1234, 0x1578,<br />
0xfff0, 0xf679};<br />
/* Holds configuration information */<br />
unsigned int DCICON1value;<br />
/* Holds the value of framelength, wordsize and buffer length */<br />
unsigned int DCICON2value;<br />
/* Holds the information reagarding bit clock<br />
generator */<br />
unsigned int DCICON3value ;<br />
/* Holds the information reagarding data tobe received<br />
or ignored during this time slot */<br />
unsigned int RSCONvalue ;<br />
/* Holds the information reagarding transmit buffer<br />
SPI_INT_PRI_4<br />
SPI_INT_PRI_5<br />
SPI_INT_PRI_6<br />
SPI_INT_PRI_7<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này sẽ xóa sạch các bit Cờ ngắt, đặt ưu tiên ngắt và<br />
cho phép / vô hiệu hóa ngắt.<br />
Source File: ConfigIntSPI1.c<br />
ConfigIntSPI2.c<br />
Mã số Ví dụ: ConfigIntSPI1 (SPI_INT_PRI_3 & SPI_INT_EN);<br />
CloseSPI1<br />
CloseSPI2<br />
Mô tả: Chức năng này sẽ tắt các mô-đun SPI<br />
Bao gồm: spi.h<br />
Prototype: void CloseSPI1 (void);<br />
làm mất hiệu lực CloseSPI2 (void);<br />
Lập luận: Không<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này vô hiệu hóa ngắt SPI và sau đó tắt các mô-đun.<br />
Các bit Cờ ngắt cũng sẽ bị xóa.<br />
Source File: CloseSPI1.c<br />
CloseSPI2.c<br />
Mã số Ví dụ: CloseSPI1 ();<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 159
contents are sent duringthe timeslot */<br />
unsigned int TSCONvalue ;<br />
int i ;<br />
CloseDCI();<br />
/* Configure DCI receive/ transmit interrupt */<br />
ConfigIntDCI( DCI_INT_ON & DCI_INT_PRI_6);<br />
/* Configure DCI module to transmit 16bit data with multichannel mode<br />
*/<br />
DCICON1value = DCI_EN & DCI_IDLE_CON &<br />
DCI_DIGI_LPBACK_EN &<br />
DCI_SCKD_OUP &<br />
DCI_SAMP_CLK_FAL &<br />
DCI_FSD_OUP &<br />
DCI_TX_ZERO_UNF &<br />
DCI_SDO_TRISTAT &<br />
DCI_DJST_OFF &<br />
DCI_FSM_MULTI;<br />
DCICON2value = DCI_BUFF_LEN_4 & DCI_FRAME_LEN_4 &<br />
DCI_DATA_WORD_16 ;<br />
DCICON3value = 0x00;<br />
RSCONvalue = DCI_EN_SLOT_ALL & DCI_DIS_SLOT_11 &<br />
DCI_DIS_SLOT_4 & DCI_DIS_SLOT_5;<br />
TSCONvalue = DCI_EN_SLOT_ALL & DCI_DIS_SLOT_11 &<br />
DCI_DIS_SLOT_4 &DCI_DIS_SLOT_5;<br />
OpenDCI(DCICON1value, DCICON2value, DCICON3value,<br />
TSCONvalue, RSCONvalue);<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 157<br />
/* Load transmit buffer and transmit the same */<br />
i = 0;<br />
while( i
* Wait till new data isavailable in RX buffer */<br />
while(!DataRdyDCI());<br />
/* Read all the data remaining in receive buffer which<br />
are unread into user defined data buffer*/<br />
i = 0;<br />
while( i
SPI_INT_PRI_4<br />
SPI_INT_PRI_5<br />
SPI_INT_PRI_6<br />
SPI_INT_PRI_7<br />
Return Value: None<br />
Remarks: This function clears the Interrupt Flag bit, sets the interrupt priority<br />
and<br />
enables/disables the interrupt.<br />
Source File: ConfigIntSPI1.c<br />
ConfigIntSPI2.c<br />
Code Example: ConfigIntSPI1(SPI_INT_PRI_3 & SPI_INT_EN);<br />
CloseSPI1<br />
CloseSPI2<br />
Description: This function turns off the SPI module<br />
Include: spi.h<br />
Prototype: void CloseSPI1(void);<br />
void CloseSPI2(void);<br />
Arguments: None<br />
Return Value: None<br />
Remarks: This function disables the SPI interrupt and then turns off the module.<br />
The Interrupt Flag bit is also cleared.<br />
Source File: CloseSPI1.c<br />
CloseSPI2.c<br />
Code Example: CloseSPI1();<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 159<br />
DataRdySPI1<br />
DataRdySPI2<br />
Description: This function determines if the SPI buffer contains any data to be<br />
read.<br />
Include: spi.h<br />
Prototype: char DataRdySPI1(void);<br />
char DataRdySPI2(void);<br />
Arguments: None<br />
Return Value: If ‘1’ is returned, it indicates that the data has been received in<br />
the<br />
receive buffer and is to be read.<br />
If ‘0’ is returned, it indicates that the receive is not complete and the<br />
receive buffer is empty.<br />
Remarks: This function returns the status of SPI receive buffer. This indicates if<br />
Khung Sync xung điều khiển hướng<br />
FRAME_SYNC_INPUT<br />
FRAME_SYNC_OUTPUT<br />
SDO Pin điều khiển bit<br />
DISABLE_SDO_PIN<br />
ENABLE_SDO_PIN<br />
Word / Chế độ liên lạc Byte<br />
SPI_MODE16_ON<br />
SPI_MODE16_OFF<br />
SPI dữ liệu đầu vào giai đoạn mẫu<br />
SPI_SMP_ON<br />
SPI_SMP_OFF<br />
SPI Clock cạnh Chọn<br />
SPI_CKE_ON<br />
SPI_CKE_OFF<br />
SPI nô lệ chọn cho phép<br />
SLAVE_SELECT_ENABLE_ON<br />
SLAVE_SELECT_ENABLE_OFF<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 161<br />
SPI Clock cực chọn<br />
CLK_POL_ACTIVE_LOW<br />
CLK_POL_ACTIVE_HIGH<br />
Chọn chế độ SPI bit<br />
MASTER_ENABLE_ON<br />
MASTER_ENABLE_OFF<br />
Prescale thứ cấp chọn<br />
SEC_PRESCAL_1_1<br />
SEC_PRESCAL_2_1<br />
SEC_PRESCAL_3_1<br />
SEC_PRESCAL_4_1<br />
SEC_PRESCAL_5_1<br />
SEC_PRESCAL_6_1<br />
SEC_PRESCAL_7_1<br />
SEC_PRESCAL_8_1<br />
Tiểu prescale chọn<br />
PRI_PRESCAL_1_1<br />
PRI_PRESCAL_4_1<br />
PRI_PRESCAL_16_1
the SPI receive buffer contains any new data that is yet to be read as<br />
indicated by the SPIxSTAT bit. This bit is cleared by<br />
hardware when the data is read from the buffer.<br />
Source File: DataRdySPI1.c<br />
DataRdySPI2.c<br />
Code Example: while(DataRdySPI1());<br />
ReadSPI1<br />
ReadSPI2<br />
Description: This function reads the content of the SPI Receive Buffer<br />
(SPIxBUF)<br />
register.<br />
Include: spi.h<br />
Prototype: unsigned int ReadSPI1(void);<br />
unsigned int ReadSPI2(void);<br />
Arguments: None<br />
Return Value: This function returns the content of Receive Buffer (SPIxBUF)<br />
register.<br />
If a value of ‘-1’ is returned, it indicates that there is no data to be read<br />
from the SPI buffer.<br />
Remarks: This function returns the content of the Receive Buffer register.<br />
If 16-bit communication is enabled, the data in the SPIxRBF register is<br />
returned.<br />
If 8-bit communication is enabled, then the lower byte of SPIxBUF is<br />
returned.<br />
The SPIxBUF is read only if it contains any data as indicated by the<br />
SPISTATbit. Otherwise, a value of ‘-1’ is returned.<br />
Source File: ReadSPI1.c<br />
ReadSPI2.c<br />
Code Example: unsigned int RX_data;<br />
RX_data = ReadSPI1();<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 160<br />
WriteSPI1<br />
WriteSPI2<br />
2004 Microchip Technology Inc.<br />
Description: This function writes the data to be transmitted into the Transmit<br />
Buffer<br />
(SPIxBUF) register.<br />
Include: spi.h<br />
PRI_PRESCAL_64_1<br />
config2 này chứa các thông số phải được cấu hình trong<br />
SPIxSTAT đăng ký theo quy định dưới đây:<br />
SPI Enable / Disable<br />
SPI_ENABLE<br />
SPI_DISABLE<br />
SPI hoạt động chế độ Idle<br />
SPI_IDLE_CON<br />
SPI_IDLE_STOP<br />
Nhận rõ ràng tràn cờ bit<br />
SPI_RX_OVFLOW_CLR<br />
Trở lại giá trị: Không<br />
Bình luận: chức năng này khởi tạo các mô-đun SPI và thiết lập chế độ nhàn rỗi<br />
hoạt động.<br />
Source File: OpenSPI1.c<br />
OpenSPI2.c<br />
Mã số Ví dụ: config1 = FRAME_ENABLE_OFF &<br />
FRAME_SYNC_OUTPUT &<br />
ENABLE_SDO_PIN &<br />
SPI_MODE16_ON &<br />
SPI_SMP_ON &<br />
SPI_CKE_OFF &<br />
SLAVE_SELECT_ENABLE_OFF &<br />
CLK_POL_ACTIVE_HIGH &<br />
MASTER_ENABLE_ON &<br />
SEC_PRESCAL_7_1 &<br />
PRI_PRESCAL_64_1;<br />
config2 = SPI_ENABLE &<br />
SPI_IDLE_CON &<br />
SPI_RX_OVFLOW_CLR OpenSPI1 (config1,<br />
config2);<br />
OpenSPI1 (Tiếp theo)<br />
OpenSPI2<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 162 2004 Microchip Technology Inc<br />
putsSPI1<br />
putsSPI2
Prototype: void WriteSPI1(unsigned int data);<br />
void WriteSPI2(unsigned int data);<br />
Arguments: data This is the data to be transmitted which will be stored in SPI<br />
buffer.<br />
Remarks: This function writes the data (byte/word) to be transmitted into the<br />
transmit buffer.<br />
If 16-bit communication is enabled,the 16-bit value is written to the<br />
transmit buffer.<br />
If 8-bit communication is enabled, then upper byte is masked and then<br />
written to the transmit buffer.<br />
Return Value: None<br />
Source File: WriteSPI1.c<br />
WriteSPI2.c<br />
Code Example: WriteSPI1(0x3FFF);<br />
OpenSPI1<br />
OpenSPI2<br />
Description: This function configures the SPI module<br />
Include: spi.h<br />
Prototype: void OpenSPI1(unsigned int config1,<br />
unsigned int config2);<br />
void OpenSPI2(unsigned int config1,<br />
unsigned int config2);<br />
Arguments: config1 This contains the parameters to be configured in the<br />
SPIxCON register as defined below:<br />
Framed SPI support Enable/Disable<br />
FRAME_ENABLE_ON<br />
FRAME_ENABLE_OFF<br />
Frame Sync Pulse direction control<br />
FRAME_SYNC_INPUT<br />
FRAME_SYNC_OUTPUT<br />
SDO Pin Control bit<br />
DISABLE_SDO_PIN<br />
ENABLE_SDO_PIN<br />
Word/Byte Communication mode<br />
SPI_MODE16_ON<br />
SPI_MODE16_OFF<br />
SPI Data Input Sample phase<br />
SPI_SMP_ON<br />
SPI_SMP_OFF<br />
Mô tả: Chức năng này ghi một chuỗi các dữ liệu được truyền vào SPI<br />
truyền đệm.<br />
Bao gồm: spi.h<br />
Nguyên mẫu:<br />
làm mất hiệu lực putsSPI1 (unsigned int dài,<br />
int * wrptr);<br />
làm mất hiệu lực putsSPI2 (unsigned int dài,<br />
int * wrptr);<br />
Đối số: chiều dài Đây là số từ dữ liệu / byte được truyền đi.<br />
wrptr Đây là con trỏ đến chuỗi dữ liệu được truyền đi.<br />
Trở lại giá trị: Không<br />
Ghi chú: Chức năng này ghi chiều dài xác định các từ dữ liệu / byte được<br />
truyền vào bộ đệm truyền.<br />
Một khi bộ đệm truyền đầy, nó chờ đợi cho đến khi dữ liệu được truyền và<br />
sau đó ghi dữ liệu tiếp theo vào sổ đăng ký Transmit.<br />
Việc kiểm soát vẫn còn trong functionif SPI mô-đun isdisabled trong khi điều<br />
này<br />
SPITBF bit được thiết lập.<br />
Source File: putsSPI1.c<br />
putsSPI2.c<br />
Mã số Ví dụ: putsSPI1 (10, Txdata_loc);<br />
getsSPI1<br />
getsSPI2<br />
Mô tả: Chức năng này lần đọc một chuỗi các dữ liệu chiều dài quy định và lưu<br />
trữ nó vào<br />
vị trí quy định.<br />
Bao gồm: spi.h<br />
Nguyên mẫu: int getsSPI1 (<br />
chiều dài int unsigned,<br />
int * rdptr,<br />
int spi_data_wait);<br />
int getsSPI2 (<br />
chiều dài int unsigned,<br />
int * rdptr,<br />
int spi_data_wait);<br />
Đối số: chiều dài Đây là chiều dài của chuỗi được nhận.<br />
rdptr Đây là con trỏ đến vị trí dữ liệu<br />
nhận phải được lưu trữ.<br />
spi_data_wait Đây là số thời gian chờ cho các mô-đun<br />
đã phải chờ đợi trước khi trở về.
SPI Clock Edge Select<br />
SPI_CKE_ON<br />
SPI_CKE_OFF<br />
SPI slave select enable<br />
SLAVE_SELECT_ENABLE_ON<br />
SLAVE_SELECT_ENABLE_OFF<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 161<br />
SPI Clock polarity select<br />
CLK_POL_ACTIVE_LOW<br />
CLK_POL_ACTIVE_HIGH<br />
SPI Mode Select bit<br />
MASTER_ENABLE_ON<br />
MASTER_ENABLE_OFF<br />
Secondary Prescale select<br />
SEC_PRESCAL_1_1<br />
SEC_PRESCAL_2_1<br />
SEC_PRESCAL_3_1<br />
SEC_PRESCAL_4_1<br />
SEC_PRESCAL_5_1<br />
SEC_PRESCAL_6_1<br />
SEC_PRESCAL_7_1<br />
SEC_PRESCAL_8_1<br />
Primary Prescale select<br />
PRI_PRESCAL_1_1<br />
PRI_PRESCAL_4_1<br />
PRI_PRESCAL_16_1<br />
PRI_PRESCAL_64_1<br />
config2 This contains the parameters to be configured in the<br />
SPIxSTAT register as defined below:<br />
SPI Enable/Disable<br />
SPI_ENABLE<br />
SPI_DISABLE<br />
SPI Idle mode operation<br />
SPI_IDLE_CON<br />
SPI_IDLE_STOP<br />
Clear Receive Overflow Flag bit<br />
SPI_RX_OVFLOW_CLR<br />
Return Value: None<br />
Nếu tính thời gian chờ là 'N', thời gian chờ thực tế<br />
sẽ vào khoảng (19 * N - 1) chu kỳ hướng dẫn.<br />
Trở lại giá trị: Chức năng này trả về số byte chưa được nhận.<br />
Nếu giá trị trả về là "0", nó chỉ ra rằng chuỗi hoàn chỉnh đã được<br />
nhận được.<br />
Nếu giá trị trả về là một giá trị khác không, nó cho thấy thatthe chuỗi hoàn<br />
chỉnh có<br />
không được nhận.<br />
Bình luận: Không có<br />
Source File: getsSPI1.c<br />
getsSPI2.c<br />
Mã số Ví dụ: Datarem = getsSPI1 (6, Rxdata_loc, 40);<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 163<br />
3.14.2 Macros cá nhân<br />
getcSPI1<br />
getcSPI2<br />
Mô tả: Chức năng này giống hệt với ReadSPI1 và ReadSPI2.<br />
Source File: # define để ReadSPI1 và ReadSPI2 trong spi.h<br />
putcSPI1<br />
putcSPI2<br />
Mô tả: Chức năng này giống hệt với WriteSPI1 và WriteSPI2.<br />
Source File: # define để WriteSPI1 và WriteSPI2 trong spi.h<br />
EnableIntSPI1<br />
EnableIntSPI2<br />
Mô tả: vĩ mô này cho phép ngắt SPI.<br />
Bao gồm: spi.h<br />
Lập luận: Không<br />
Bình luận: Đây bộ vĩ mô SPI Enablebit ngắt của ngắt Kích hoạt tính năng kiểm<br />
soát<br />
đăng ký.<br />
Mã số Ví dụ: EnableIntSPI1;<br />
DisableIntSPI1<br />
DisableIntSPI2<br />
Mô tả: vĩ mô này vô hiệu hóa ngắt SPI.<br />
Bao gồm: spi.h<br />
Lập luận: Không<br />
Bình luận: vĩ mô này xóa SPI Enablebit ngắt của ngắt Kích hoạt tính năng kiểm<br />
soát<br />
đăng ký.<br />
Mã số Ví dụ: DisableIntSPI2;
Remarks: This functions initializes the SPI module and sets the Idle mode<br />
operation.<br />
Source File: OpenSPI1.c<br />
OpenSPI2.c<br />
Code Example: config1 = FRAME_ENABLE_OFF &<br />
FRAME_SYNC_OUTPUT &<br />
ENABLE_SDO_PIN &<br />
SPI_MODE16_ON &<br />
SPI_SMP_ON &<br />
SPI_CKE_OFF &<br />
SLAVE_SELECT_ENABLE_OFF &<br />
CLK_POL_ACTIVE_HIGH &<br />
MASTER_ENABLE_ON &<br />
SEC_PRESCAL_7_1 &<br />
PRI_PRESCAL_64_1;<br />
config2 = SPI_ENABLE &<br />
SPI_IDLE_CON &<br />
SPI_RX_OVFLOW_CLR OpenSPI1(config1,<br />
config2);<br />
OpenSPI1 (Continued)<br />
OpenSPI2<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 162 2004 Microchip Technology Inc.<br />
putsSPI1<br />
putsSPI2<br />
Description: This function writes a string of data to be transmitted into the SPI<br />
transmit buffer.<br />
Include: spi.h<br />
Prototype:<br />
void putsSPI1(unsigned int length,<br />
unsigned int *wrptr);<br />
void putsSPI2(unsigned int length,<br />
unsigned int *wrptr);<br />
Arguments: length This is the number of data words/bytes to be transmitted.<br />
wrptr This is the pointer to the string of data to be transmitted.<br />
Return Value: None<br />
Remarks: This function writes the specified length of data words/bytes to be<br />
SetPriorityIntSPI1<br />
SetPriorityIntSPI2<br />
Mô tả: Đây ưu tiên bộ vĩ mô cho SPI bị gián đoạn.<br />
Bao gồm: spi.h<br />
Đối số: ưu tiên<br />
Bình luận: vĩ mô này đặt SPI Interrupt bit ưu tiên của ngắt ưu tiên kiểm soát<br />
đăng ký.<br />
Mã số Ví dụ: SetPriorityIntSPI2 (2);<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 164 2004 Microchip Technology Inc<br />
3.14.3 Ví dụ sử dụng<br />
# xác định __dsPIC30F6014__<br />
# include<br />
# include<br />
/ * Dữ liệu nhận được SPI2 * /<br />
int datard;<br />
khoảng trống __attribute __ ((__ interrupt__)) _SPI1Interrupt (void)<br />
{<br />
IFS0bits.SPI1IF = 0;<br />
}<br />
khoảng trống __attribute __ ((__ interrupt__)) _SPI2Interrupt (void)<br />
{<br />
IFS1bits.SPI2IF = 0;<br />
SPI1STATbits.SPIROV = 0; / * Rõ ràng spi1 nhận được tràn<br />
cờ nếu đặt * /<br />
}<br />
int main (void)<br />
{<br />
/ * Giữ các thông tin về SPI configuartion * /<br />
int SPICONValue;<br />
/ * Giữ các thông tin về SPI Enable / Disable * /<br />
int SPISTATValue;<br />
/ * Timeout giá trị trong thời gian đó timer1 là ON * /<br />
int thời gian chờ;<br />
/ * Tắt module SPI * /<br />
CloseSPI1 ();<br />
CloseSPI2 ();
transmitted into the transmit buffer.<br />
Once the transmit buffer is full, it waits till the data gets transmitted and<br />
then writes the next data into the Transmit register.<br />
The control remains in this functionif SPI module isdisabled while<br />
SPITBF bit is set.<br />
Source File: putsSPI1.c<br />
putsSPI2.c<br />
Code Example: putsSPI1(10,Txdata_loc);<br />
getsSPI1<br />
getsSPI2<br />
Description: This function reads a string of data of specified length and stores it<br />
into<br />
the location specified.<br />
Include: spi.h<br />
Prototype: unsigned int getsSPI1(<br />
unsigned int length,<br />
unsigned int *rdptr,<br />
unsigned int spi_data_wait);<br />
unsigned int getsSPI2(<br />
unsigned int length,<br />
unsigned int *rdptr,<br />
unsigned int spi_data_wait);<br />
Arguments: length This is the length of the string to be received.<br />
rdptr This is the pointer to the location where the data<br />
received have to be stored.<br />
spi_data_wait This is the timeout count for which the module<br />
has to wait before return.<br />
If the timeout count is ‘N’, the actual timeout<br />
would be about (19*N - 1) instruction cycles.<br />
Return Value: This function returns the number of bytes yet to be received.<br />
If the return value is a ‘0’, it indicates that the complete string has been<br />
received.<br />
If the return value is a nonzero, it indicates thatthe complete string has<br />
not been received.<br />
Remarks: None<br />
Source File: getsSPI1.c<br />
getsSPI2.c<br />
Code Example: Datarem = getsSPI1(6, Rxdata_loc, 40);<br />
dsPIC Peripheral Libraries<br />
TMR1 = 0;<br />
thời gian chờ = 0;<br />
TRISDbits.TRISD0 = 0;<br />
/ * Cấu hình SPI2 ngắt * /<br />
ConfigIntSPI2 (SPI_INT_EN & SPI_INT_PRI_6);<br />
/ * Cấu hình spi1 mô-đun totransmit giá trị timer1 16 bit<br />
trong chế độ thạc sĩ * /<br />
SPICONValue = FRAME_ENABLE_OFF & FRAME_SYNC_OUTPUT &<br />
ENABLE_SDO_PIN & SPI_MODE16_ON &<br />
SPI_SMP_ON & SPI_CKE_OFF &<br />
SLAVE_SELECT_ENABLE_OFF &<br />
CLK_POL_ACTIVE_HIGH &<br />
MASTER_ENABLE_ON &<br />
SEC_PRESCAL_7_1 &<br />
PRI_PRESCAL_64_1;<br />
SPISTATValue = SPI_ENABLE & SPI_IDLE_CON &<br />
SPI_RX_OVFLOW_CLR;<br />
OpenSPI1 (SPICONValue, SPISTATValue);<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 165<br />
/ * Cấu hình SPI2 mô-đun để nhận được giá trị bộ đếm thời gian 16 bit<br />
chế độ nô lệ * /<br />
SPICONValue = FRAME_ENABLE_OFF & FRAME_SYNC_OUTPUT &<br />
ENABLE_SDO_PIN & SPI_MODE16_ON &<br />
SPI_SMP_OFF & SPI_CKE_OFF &<br />
SLAVE_SELECT_ENABLE_OFF &<br />
CLK_POL_ACTIVE_HIGH &<br />
MASTER_ENABLE_OFF &<br />
SEC_PRESCAL_7_1 &<br />
PRI_PRESCAL_64_1;<br />
SPISTATValue = SPI_ENABLE & SPI_IDLE_CON &<br />
PI_RX_OVFLOW_CLR;<br />
OpenSPI2 (SPICONValue, SPISTATValue);<br />
T1CON = 0x8000;<br />
trong khi (thời gian chờ
2004 Microchip Technology Inc. DS51456B-page 163<br />
3.14.2 Individual Macros<br />
getcSPI1<br />
getcSPI2<br />
Description: This function is identical to ReadSPI1 and ReadSPI2.<br />
Source File: #define to ReadSPI1 and ReadSPI2 in spi.h<br />
putcSPI1<br />
putcSPI2<br />
Description: This function is identical to WriteSPI1 and WriteSPI2.<br />
Source File: #define to WriteSPI1 and WriteSPI2 in spi.h<br />
EnableIntSPI1<br />
EnableIntSPI2<br />
Description: This macro enables the SPI interrupt.<br />
Include: spi.h<br />
Arguments: None<br />
Remarks: This macro sets SPI Interrupt Enablebit of Interrupt Enable Control<br />
register.<br />
Code Example: EnableIntSPI1;<br />
DisableIntSPI1<br />
DisableIntSPI2<br />
Description: This macro disables the SPI interrupt.<br />
Include: spi.h<br />
Arguments: None<br />
Remarks: This macro clears SPI Interrupt Enablebit of Interrupt Enable Control<br />
register.<br />
Code Example: DisableIntSPI2;<br />
SetPriorityIntSPI1<br />
SetPriorityIntSPI2<br />
Description: This macro sets priority for SPI interrupt.<br />
Include: spi.h<br />
Arguments: priority<br />
Remarks: This macro sets SPI Interrupt Priority bits of Interrupt Priority Control<br />
register.<br />
Code Example: SetPriorityIntSPI2(2);<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
WriteSPI1 (TMR1);<br />
trong khi (SPI1STATbits.SPITBF);<br />
trong khi (DataRdySPI2 ());<br />
datard = ReadSPI2 ();<br />
if (datard
#define __dsPIC30F6014__<br />
#include<br />
#include<br />
/* Data received at SPI2 */<br />
unsigned int datard ;<br />
void __attribute__((__interrupt__)) _SPI1Interrupt(void)<br />
{<br />
IFS0bits.SPI1IF = 0;<br />
}<br />
void __attribute__((__interrupt__)) _SPI2Interrupt(void)<br />
{<br />
IFS1bits.SPI2IF = 0;<br />
SPI1STATbits.SPIROV = 0; /* Clear SPI1 receive overflow<br />
flag if set */<br />
}<br />
int main(void)<br />
{<br />
/* Holds the information about SPI configuartion */<br />
unsigned int SPICONValue;<br />
/* Holds the information about SPI Enable/Disable */<br />
unsigned int SPISTATValue;<br />
/*Timeout value during which timer1 is ON */<br />
int timeout;<br />
/* Turn off SPI modules */<br />
CloseSPI1();<br />
CloseSPI2();<br />
TMR1 = 0 ;<br />
timeout = 0;<br />
TRISDbits.TRISD0 = 0;<br />
/* Configure SPI2 interrupt */<br />
ConfigIntSPI2(SPI_INT_EN & SPI_INT_PRI_6);<br />
/* Configure SPI1 module totransmit 16 bit timer1 value<br />
in master mode */<br />
SPICONValue = FRAME_ENABLE_OFF & FRAME_SYNC_OUTPUT &<br />
ENABLE_SDO_PIN& SPI_MODE16_ON &<br />
SPI_SMP_ON & SPI_CKE_OFF &<br />
SLAVE_SELECT_ENABLE_OFF &<br />
CLK_POL_ACTIVE_HIGH &<br />
MASTER_ENABLE_ON &<br />
QEI_INT_DISABLE<br />
Ưu tiên QEI ngắt<br />
QEI_INT_PRI_0<br />
QEI_INT_PRI_1<br />
QEI_INT_PRI_2<br />
QEI_INT_PRI_3<br />
QEI_INT_PRI_4<br />
QEI_INT_PRI_5<br />
QEI_INT_PRI_6<br />
QEI_INT_PRI_7<br />
Trở lại giá trị Không<br />
Ghi chú: Chức năng này sẽ xóa sạch các bit Cờ ngắt, đặt ưu tiên ngắt và<br />
cho phép / vô hiệu hóa ngắt.<br />
Source File: ConfigIntQEI.c<br />
Mã số Ví dụ: ConfigIntQEI (QEI_INT_ENABLE & QEI_INT_PRI_1);<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 167<br />
OpenQEI<br />
Mô tả: Chức năng này cấu hình QEI.<br />
Bao gồm: qei.h<br />
Prototype: void OpenQEI (int config1, int<br />
config2);<br />
Đối số: config1 này chứa các thông số phải được cấu hình trong<br />
QEIxCON đăng ký theo quy định dưới đây:<br />
Chức vụ truy cập điều khiển hướng lựa chọn<br />
QEI_DIR_SEL_QEB<br />
QEI_DIR_SEL_CNTRL<br />
Hẹn giờ đồng hồ Nguồn Chọn bit<br />
QEI_EXT_CLK<br />
QEI_INT_CLK<br />
Chức vụ truy cập Thiết lập lại phép<br />
QEI_INDEX_RESET_ENABLE<br />
QEI_INDEX_RESET_DISABLE<br />
Đồng hồ đếm thời gian đầu vào prescale Chọn bit<br />
QEI_CLK_PRESCALE_1<br />
QEI_CLK_PRESCALE_8<br />
QEI_CLK_PRESCALE_64<br />
QEI_CLK_PRESCALE_256<br />
Thơi gian chung cổng Thời gian tích lũy Kích hoạt
SEC_PRESCAL_7_1 &<br />
PRI_PRESCAL_64_1;<br />
SPISTATValue = SPI_ENABLE & SPI_IDLE_CON &<br />
SPI_RX_OVFLOW_CLR;<br />
OpenSPI1(SPICONValue,SPISTATValue );<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 165<br />
/* Configure SPI2 module to receive 16 bit timer value in<br />
slave mode */<br />
SPICONValue = FRAME_ENABLE_OFF & FRAME_SYNC_OUTPUT &<br />
ENABLE_SDO_PIN & SPI_MODE16_ON &<br />
SPI_SMP_OFF & SPI_CKE_OFF &<br />
SLAVE_SELECT_ENABLE_OFF &<br />
CLK_POL_ACTIVE_HIGH &<br />
MASTER_ENABLE_OFF &<br />
SEC_PRESCAL_7_1 &<br />
PRI_PRESCAL_64_1;<br />
SPISTATValue = SPI_ENABLE & SPI_IDLE_CON &<br />
PI_RX_OVFLOW_CLR;<br />
OpenSPI2(SPICONValue,SPISTATValue );<br />
T1CON = 0X8000;<br />
while(timeout< 100 )<br />
{<br />
timeout = timeout+2 ;<br />
}<br />
T1CON = 0;<br />
WriteSPI1(TMR1);<br />
while(SPI1STATbits.SPITBF);<br />
while(!DataRdySPI2());<br />
datard = ReadSPI2();<br />
if(datard
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 166<br />
3.15 QEI FUNCTIONS<br />
2004 Microchip Technology Inc.<br />
This section contains a list of individualfunctions for QEI module and an<br />
example of<br />
use of the functions. Functions may be implemented as macros.<br />
3.15.1 Individual Functions<br />
CloseQEI<br />
Description: This function turns off the QEI module<br />
Include: qei.h<br />
Prototype: void closeQEI(void);<br />
Arguments: None<br />
Return Value None<br />
Remarks: This function disables the QEI module and clears the QEI Interrupt<br />
Enable and Flag bits.<br />
Source File: CloseQEI.c<br />
Code Example: CloseQEI();<br />
ConfigIntQEI<br />
Description: This function Configure the QEI Interrupt.<br />
Include: qei.h<br />
Prototype: void ConfigIntQEI(unsigned int config);<br />
Arguments: config QEI interrupt priority and enable/disable information as<br />
defined below:<br />
QEI Interrupt enable/disable<br />
QEI_INT_ENABLE<br />
QEI_INT_DISABLE<br />
QEI Interrupt priority<br />
QEI_INT_PRI_0<br />
QEI_INT_PRI_1<br />
QEI_INT_PRI_2<br />
QEI_INT_PRI_3<br />
QEI_INT_PRI_4<br />
QEI_INT_PRI_5<br />
QEI_INT_PRI_6<br />
QEI_INT_PRI_7<br />
Return Value None<br />
Remarks: This function clears the Interrupt Flag bit, sets the interrupt priority<br />
and<br />
MATCH_INDEX_INPUT_PHASEB<br />
Giai đoạn trạng thái tín hiệu đầu vào cho phù hợp với chỉ số xung<br />
MATCH_INDEX_INPUT_HIGH<br />
MATCH_INDEX_INPUT_LOW<br />
Bật / Tắt gián đoạn do vị trí số sự kiện<br />
POS_CNT_ERR_INT_ENABLE<br />
POS_CNT_ERR_INT_DISABLE<br />
QEA / QEB lọc kỹ thuật số Đồng hồ Chia Chọn bit<br />
QEI_QE_CLK_DIVIDE_1_1<br />
QEI_QE_CLK_DIVIDE_1_2<br />
QEI_QE_CLK_DIVIDE_1_4<br />
QEI_QE_CLK_DIVIDE_1_16<br />
QEI_QE_CLK_DIVIDE_1_32<br />
QEI_QE_CLK_DIVIDE_1_64<br />
QEI_QE_CLK_DIVIDE_1_128<br />
QEI_QE_CLK_DIVIDE_1_256<br />
QEA / QEB lọc kỹ thuật số đầu ra Kích hoạt<br />
QEI_QE_OUT_ENABLE<br />
QEI_QE_OUT_DISABLE<br />
Trở lại giá trị Không<br />
Ghi chú: Chức năng này cấu hình QEICON và DFLTCON đăng ký của QEI<br />
mô-đun.<br />
Chức năng này cũng xóa QEICON bit.<br />
Source File: OpenQEI.c<br />
Mã số Ví dụ: OpenQEI (QEI_DIR_SEL_QEB & QEI_INT_CLK &<br />
QEI_INDEX_RESET_ENABLE &<br />
QEI_CLK_PRESCALE_1 & QEI_NORMAL_IO &<br />
QEI_MODE_TIMER & QEI_UP_COUNT, 0);<br />
ReadQEI<br />
Mô tả: Chức năng này đọc các giá trị số vị trí trong sổ đăng ký POSCNT.<br />
Bao gồm: qei.h<br />
Nguyên mẫu: int ReadQEI (void);<br />
Lập luận: Không<br />
Bình luận: Không có<br />
Trở lại giá trị chức năng này trả về các nội dung của đăng ký POSCNT.<br />
Source File: ReadQEI.c<br />
Mã số Ví dụ: int pos_count;<br />
pos_count = ReadQEI ();<br />
OpenQEI (Tiếp theo)
enables/disables the interrupt.<br />
Source File: ConfigIntQEI.c<br />
Code Example: ConfigIntQEI(QEI_INT_ENABLE & QEI_INT_PRI_1);<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 167<br />
OpenQEI<br />
Description: This function configure the QEI.<br />
Include: qei.h<br />
Prototype: void OpenQEI(unsigned int config1, unsigned int<br />
config2);<br />
Arguments: config1 This contains the parameters to be configured in the<br />
QEIxCON register as defined below:<br />
Position Counter Direction Selection Control<br />
QEI_DIR_SEL_QEB<br />
QEI_DIR_SEL_CNTRL<br />
Timer Clock Source Select bit<br />
QEI_EXT_CLK<br />
QEI_INT_CLK<br />
Position Counter Reset Enable<br />
QEI_INDEX_RESET_ENABLE<br />
QEI_INDEX_RESET_DISABLE<br />
Timer Input Clock Prescale Select bits<br />
QEI_CLK_PRESCALE_1<br />
QEI_CLK_PRESCALE_8<br />
QEI_CLK_PRESCALE_64<br />
QEI_CLK_PRESCALE_256<br />
Timer Gated Time Accumulation Enable<br />
QEI_GATED_ACC_ENABLE<br />
QEI_GATED_ACC_DISABLE<br />
Position Counter Direction State Output Enable<br />
QEI_LOGIC_CONTROL_IO<br />
QEI_NORMAL_IO<br />
Phase A and Phase B Input Swap Select bit<br />
QEI_INPUTS_SWAP<br />
QEI_INPUTS_NOSWAP<br />
QEI Mode of operation select<br />
QEI_MODE_x4_MATCH<br />
QEI_MODE_x4_PULSE<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 169<br />
3.15.2 Macros cá nhân<br />
WriteQEI<br />
Mô tả: Chức năng này đặt giá trị số tối đa cho QEI.<br />
Bao gồm: qei.h<br />
Prototype: void WriteQEI (vị trí int unsigned);<br />
Đối số:<br />
Vị trí này là giá trị được storedinto đăng ký MAXCNT.<br />
Trở lại giá trị Không<br />
Bình luận: Không có<br />
Source File: WriteQEI.c<br />
Mã số Ví dụ: vị trí int unsigned = 0x3FFF;<br />
WriteQEI (vị trí);<br />
EnableIntQEI<br />
Mô tả: vĩ mô này cho phép ngắt QEI.<br />
Bao gồm: qei.h<br />
Lập luận: Không<br />
Ghi chú: Phần này bộ QEI Interrupt Enable bit Interrupt Enable kiểm soát<br />
đăng ký.<br />
Mã số Ví dụ: EnableIntQEI;<br />
DisableIntQEI<br />
Mô tả: vĩ mô này vô hiệu hóa ngắt QEI.<br />
Bao gồm: qei.h<br />
Lập luận: Không<br />
Bình luận: vĩ mô này xóa QEI Enablebit ngắt của ngắt Kích hoạt tính năng kiểm<br />
soát<br />
đăng ký.<br />
Mã số Ví dụ: DisableIntQEI;<br />
SetPriorityIntQEI<br />
Mô tả: Đây ưu tiên bộ vĩ mô cho QEI bị gián đoạn.<br />
Bao gồm: qei.h<br />
Đối số: ưu tiên<br />
Bình luận: vĩ mô này đặt QEI ngắt bit ưu tiên của ngắt ưu tiên kiểm soát<br />
đăng ký.<br />
Mã số Ví dụ: SetPriorityIntQEI (7);<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
QEI_MODE_x2_MATCH<br />
DS51456B trang 170<br />
2004 Microchip Technology Inc
QEI_MODE_x2_PULSE<br />
QEI_MODE_TIMER<br />
QEI_MODE_OFF<br />
Position Counter Direction Status<br />
QEI_UP_COUNT<br />
QEI_DOWN_COUNT<br />
Idle Mode Operation<br />
QEI_IDLE_STOP<br />
QEI_IDLE_CON<br />
config2 This contains the parameters to be configured in the<br />
DFLTxCON register.<br />
In 4x Quadrature Count Mode:<br />
Required State of Phase A input signal<br />
for match on index pulse<br />
MATCH_INDEX_PHASEA_HIGH<br />
MATCH_INDEX_PHASEA_LOW<br />
Required State of Phase B input signal<br />
for match on index pulse<br />
MATCH_INDEX_PHASEB_HIGH<br />
MATCH_INDEX_PHASEB_LOW<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 168 2004 Microchip Technology Inc.<br />
In 2x Quadrature Count Mode:<br />
Phase input signal for index state match<br />
MATCH_INDEX_INPUT_PHASEA<br />
MATCH_INDEX_INPUT_PHASEB<br />
Phase input signal state for match on index pulse<br />
MATCH_INDEX_INPUT_HIGH<br />
MATCH_INDEX_INPUT_LOW<br />
Enable/Disable interrupt due to position count event<br />
POS_CNT_ERR_INT_ENABLE<br />
POS_CNT_ERR_INT_DISABLE<br />
QEA/QEB Digital Filter Clock Divide Select bits<br />
QEI_QE_CLK_DIVIDE_1_1<br />
QEI_QE_CLK_DIVIDE_1_2<br />
QEI_QE_CLK_DIVIDE_1_4<br />
QEI_QE_CLK_DIVIDE_1_16<br />
3.15.3 Ví dụ sử dụng<br />
# xác định __dsPIC30F6010__<br />
# include<br />
# include<br />
int pos_value;<br />
khoảng trống __attribute __ ((__ interrupt__)) _QEIInterrupt (void)<br />
{<br />
PORTDbits.RD1 = 1; / * Tắt đèn LED trên RD1 * /<br />
POSCNT = 0;<br />
IFS2bits.QEIIF = 0; / * Rõ ràng QEI gián đoạn cờ * /<br />
}<br />
int main (void)<br />
{<br />
int MAX_VALUE;<br />
TRISDbits.TRISD1 = 0;<br />
PORTDbits.RD1 = 1; / * Tắt đèn LED trên RD1 * /<br />
/ * Kích hoạt QEI ngắt và ưu tiên để "1" * /<br />
ConfigIntQEI (QEI_INT_PRI_1 & QEI_INT_ENABLE);<br />
POSCNT = 0;<br />
MAXCNT = 0xFFFF;<br />
OpenQEI (QEI_INT_CLK & QEI_INDEX_RESET_ENABLE &<br />
QEI_CLK_PRESCALE_256 &<br />
QEI_GATED_ACC_DISABLE & QEI_INPUTS_NOSWAP &<br />
QEI_MODE_TIMER & QEI_DIR_SEL_CNTRL &<br />
QEI_IDLE_CON, 0);<br />
QEICONbits.UPDN = 1;<br />
trong khi (1)<br />
{<br />
pos_value = ReadQEI ();<br />
if (pos_value> = 0x7FFF)<br />
{<br />
PORTDbits.RD1 = 0; / * Bật đèn LED trên RD1 * /<br />
}<br />
}<br />
CloseQEI ();<br />
}<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 171<br />
3.16 chức năng PWM<br />
Phần này bao gồm một danh sách các chức năng riêng biệt cho mô-đun PWM
QEI_QE_CLK_DIVIDE_1_32<br />
QEI_QE_CLK_DIVIDE_1_64<br />
QEI_QE_CLK_DIVIDE_1_128<br />
QEI_QE_CLK_DIVIDE_1_256<br />
QEA/QEB Digital Filter Output Enable<br />
QEI_QE_OUT_ENABLE<br />
QEI_QE_OUT_DISABLE<br />
Return Value None<br />
Remarks: This function configures the QEICON and DFLTCON registers of<br />
QEI<br />
module.<br />
This function also clears the QEICON bit.<br />
Source File: OpenQEI.c<br />
Code Example: OpenQEI(QEI_DIR_SEL_QEB & QEI_INT_CLK &<br />
QEI_INDEX_RESET_ENABLE &<br />
QEI_CLK_PRESCALE_1 & QEI_NORMAL_IO &<br />
QEI_MODE_TIMER & QEI_UP_COUNT,0);<br />
ReadQEI<br />
Description: This function read the position count value from the POSCNT<br />
register.<br />
Include: qei.h<br />
Prototype: unsigned int ReadQEI(void);<br />
Arguments: None<br />
Remarks: None<br />
Return Value This functions returns the contents of the POSCNT register.<br />
Source File: ReadQEI.c<br />
Code Example: unsigned int pos_count;<br />
pos_count = ReadQEI();<br />
OpenQEI (Continued)<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 169<br />
3.15.2 Individual Macros<br />
WriteQEI<br />
Description: This function sets the maximum count value for QEI.<br />
Include: qei.h<br />
Prototype: void WriteQEI(unsigned int position);<br />
Arguments:<br />
position This is the value to be storedinto the MAXCNT register.<br />
Return Value None<br />
Remarks: None<br />
và một ví dụ về<br />
sử dụng các chức năng. Chức năng có thể được thực hiện như các macro.<br />
3.16.1 Chức năng cá nhân<br />
CloseMCPWM<br />
Mô tả: Chức năng này sẽ tắt các mô-đun điều khiển động cơ PWM.<br />
Bao gồm: pwm.h<br />
Prototype: void closeMCPWM (void);<br />
Lập luận: Không<br />
Trở lại giá trị Không<br />
Bình luận: Chức năng này vô hiệu hóa các động cơ mô-đun điều khiển PWM v<br />
xóa<br />
PWM, lỗi A và B lỗi ngắt Enable và bit cờ.<br />
Chức năng này cũng xóa PTCON, PWMCON1 và PWMCON2<br />
đăng ký.<br />
Source File: CloseMCPWM.c<br />
Mã số Ví dụ: CloseMCPWM ();<br />
ConfigIntMCPWM<br />
Mô tả: Chức năng này cấu hình PWM ngắt.<br />
Bao gồm: pwm.h<br />
Prototype: void ConfigIntMCPWM (int config);<br />
Lập luận: config PWM ngắt ưu tiên và bật / tắt thông tin<br />
quy định dưới đây:<br />
PWM ngắt bật / tắt<br />
PWM_INT_EN<br />
PWM_INT_DIS<br />
Ưu tiên ngắt PWM<br />
PWM_INT_PR0<br />
PWM_INT_PR1<br />
PWM_INT_PR2<br />
PWM_INT_PR3<br />
PWM_INT_PR4<br />
PWM_INT_PR5<br />
PWM_INT_PR6<br />
PWM_INT_PR7<br />
Một lỗi ngắt bật / tắt<br />
PWM_FLTA_EN_INT<br />
PWM_FLTA_DIS_INT<br />
Lỗi Một ưu tiên ngắt<br />
PWM_FLTA_INT_PR0<br />
PWM_FLTA_INT_PR1
Source File: WriteQEI.c<br />
Code Example: unsigned int position = 0x3FFF;<br />
WriteQEI(position);<br />
EnableIntQEI<br />
Description: This macro enables the QEI interrupt.<br />
Include: qei.h<br />
Arguments: None<br />
Remarks: This macro sets QEI Interrupt Enable bit of Interrupt Enable Control<br />
register.<br />
Code Example: EnableIntQEI;<br />
DisableIntQEI<br />
Description: This macro disables the QEI interrupt.<br />
Include: qei.h<br />
Arguments: None<br />
Remarks: This macro clears QEI Interrupt Enablebit of Interrupt Enable Control<br />
register.<br />
Code Example: DisableIntQEI;<br />
SetPriorityIntQEI<br />
Description: This macro sets priority for QEI interrupt.<br />
Include: qei.h<br />
Arguments: priority<br />
Remarks: This macro sets QEI Interrupt Priority bits of Interrupt Priority<br />
Control<br />
register.<br />
Code Example: SetPriorityIntQEI(7);<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
PWM_FLTA_INT_PR2<br />
PWM_FLTA_INT_PR3<br />
PWM_FLTA_INT_PR4<br />
PWM_FLTA_INT_PR5<br />
PWM_FLTA_INT_PR6<br />
PWM_FLTA_INT_PR7<br />
Lỗi B ngắt cho phép / vô hiệu hóa<br />
PWM_FLTB_EN_INT<br />
PWM_FLTB_DIS_INT<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 172 2004 Microchip Technology Inc<br />
Lỗi ưu tiên B ngắt<br />
PWM_FLTB_INT_PR0<br />
PWM_FLTB_INT_PR1<br />
PWM_FLTB_INT_PR2<br />
PWM_FLTB_INT_PR3<br />
PWM_FLTB_INT_PR4<br />
PWM_FLTB_INT_PR5<br />
PWM_FLTB_INT_PR6<br />
PWM_FLTB_INT_PR7<br />
Trở lại giá trị Không<br />
Ghi chú: Chức năng này sẽ xóa sạch các bit Cờ ngắt, đặt ưu tiên ngắt và<br />
cho phép / vô hiệu hóa ngắt.<br />
Source File: ConfigIntMCPWM.c<br />
Mã số Ví dụ: ConfigIntMCPWM (PWM_INT_EN & PWM_INT_PR5 &<br />
PWM_FLTA_EN_INT &<br />
DS51456B-page 170<br />
3.15.3 Example of Use<br />
2004 Microchip Technology Inc.<br />
PWM_FLTA_INT_PR6 &<br />
PWM_FLTB_EN_INT &<br />
#define __dsPIC30F6010__<br />
#include <br />
#include<br />
unsigned int pos_value;<br />
void __attribute__((__interrupt__)) _QEIInterrupt(void)<br />
{<br />
PORTDbits.RD1 = 1; /* turn off LED on RD1 */<br />
POSCNT = 0;<br />
IFS2bits.QEIIF = 0; /* Clear QEI interrupt flag */<br />
PWM_FLTB_INT_PR7);<br />
OpenMCPWM<br />
Mô tả: Chức năng này cấu hình các mô-đun PWM điều khiển động cơ.<br />
Bao gồm: pwm.h<br />
Prototype: void OpenMCPWM (giai đoạn int unsigned,<br />
int sptime,<br />
int config1,<br />
int config2,<br />
int config3);<br />
Lập luận: Giai đoạn này bao gồm các giá trị thời gian PWM timebase được lưu
}<br />
int main(void)<br />
{<br />
unsigned int max_value;<br />
TRISDbits.TRISD1 = 0;<br />
PORTDbits.RD1 = 1; /* turn off LED on RD1 */<br />
/* Enable QEI Interrupt and Priority to "1" */<br />
ConfigIntQEI(QEI_INT_PRI_1 & QEI_INT_ENABLE);<br />
POSCNT = 0;<br />
MAXCNT = 0xFFFF;<br />
OpenQEI(QEI_INT_CLK & QEI_INDEX_RESET_ENABLE &<br />
QEI_CLK_PRESCALE_256 &<br />
QEI_GATED_ACC_DISABLE & QEI_INPUTS_NOSWAP &<br />
QEI_MODE_TIMER & QEI_DIR_SEL_CNTRL &<br />
QEI_IDLE_CON, 0);<br />
QEICONbits.UPDN = 1;<br />
while(1)<br />
{<br />
pos_value = ReadQEI();<br />
if(pos_value >= 0x7FFF)<br />
{<br />
PORTDbits.RD1 = 0; /* turn on LED on RD1 */<br />
}<br />
}<br />
CloseQEI();<br />
}<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 171<br />
3.16 PWM FUNCTIONS<br />
This section contains a list of individual functions for PWM module and an<br />
example of<br />
use of the functions. Functions may be implemented as macros.<br />
3.16.1 Individual Functions<br />
CloseMCPWM<br />
Description: This function turns off the Motor Control PWM module.<br />
Include: pwm.h<br />
Prototype: void closeMCPWM(void);<br />
Arguments: None<br />
Return Value None<br />
trữ<br />
trong PTPER đăng ký.<br />
sptime này bao gồm các sự kiện đặc biệt so sánh giá trị là<br />
lưu trữ trong SEVTCMP đăng ký.<br />
config1 này chứa các parametersto được cấu hình trong<br />
PTCON đăng ký theo quy định dưới đây:<br />
Mô-đun PWM cho phép / vô hiệu hóa<br />
PWM_EN<br />
PWM_DIS<br />
Nhàn rỗi chế độ bật / tắt<br />
PWM_IDLE_STOP<br />
PWM_IDLE_CON<br />
Sản lượng bài rỉ chọn<br />
PWM_OP_SCALE1<br />
PWM_OP_SCALE2<br />
.....<br />
PWM_OP_SCALE15<br />
PWM_OP_SCALE16<br />
Đầu vào prescaler chọn<br />
PWM_IPCLK_SCALE1<br />
PWM_IPCLK_SCALE4<br />
PWM_IPCLK_SCALE16<br />
PWM_IPCLK_SCALE64<br />
ConfigIntMCPWM (Tiếp theo)<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 173<br />
Chế độ PWM hoạt động<br />
PWM_MOD_FREE<br />
PWM_MOD_SING<br />
PWM_MOD_UPDN<br />
PWM_MOD_DBL<br />
config2 này chứa các thông số phải được cấu hình trong<br />
PWMCON1 đăng ký theo quy định dưới đây:<br />
PWM I / O pin cặp<br />
PWM_MOD4_COMP<br />
PWM_MOD3_COMP<br />
PWM_MOD2_COMP<br />
PWM_MOD1_COMP<br />
PWM_MOD4_IND
Remarks: This function disables the Motor control PWM module and clears the<br />
PWM, Fault A and Fault B Interrupt Enable and Flag bits.<br />
This function also clears the PTCON, PWMCON1 and PWMCON2<br />
registers.<br />
Source File: CloseMCPWM.c<br />
Code Example: CloseMCPWM();<br />
ConfigIntMCPWM<br />
Description: This function configures the PWM Interrupts.<br />
Include: pwm.h<br />
Prototype: void ConfigIntMCPWM(unsigned int config);<br />
Arguments: config PWM interrupt priority and enable/disable information as<br />
defined below:<br />
PWM Interrupt enable/disable<br />
PWM_INT_EN<br />
PWM_INT_DIS<br />
PWM Interrupt priority<br />
PWM_INT_PR0<br />
PWM_INT_PR1<br />
PWM_INT_PR2<br />
PWM_INT_PR3<br />
PWM_INT_PR4<br />
PWM_INT_PR5<br />
PWM_INT_PR6<br />
PWM_INT_PR7<br />
Fault A Interrupt enable/disable<br />
PWM_FLTA_EN_INT<br />
PWM_FLTA_DIS_INT<br />
Fault A Interrupt priority<br />
PWM_FLTA_INT_PR0<br />
PWM_FLTA_INT_PR1<br />
PWM_FLTA_INT_PR2<br />
PWM_FLTA_INT_PR3<br />
PWM_FLTA_INT_PR4<br />
PWM_FLTA_INT_PR5<br />
PWM_FLTA_INT_PR6<br />
PWM_FLTA_INT_PR7<br />
Fault B Interrupt enable/disable<br />
PWM_FLTB_EN_INT<br />
PWM_FLTB_DIS_INT<br />
PWM_MOD3_IND<br />
PWM_MOD2_IND<br />
PWM_MOD1_IND<br />
PWM H / LI / O cho phép / vô hiệu hóa chọn<br />
PWM_PEN4H<br />
PWM_PDIS4H<br />
PWM_PEN3H<br />
PWM_PDIS3H<br />
PWM_PEN2H<br />
PWM_PDIS2H<br />
PWM_PEN1H<br />
PWM_PDIS1H<br />
PWM_PEN4L<br />
PWM_PDIS4L<br />
PWM_PEN3L<br />
PWM_PDIS3L<br />
PWM_PEN2L<br />
PWM_PDIS2L<br />
PWM_PEN1L<br />
PWM_PDIS1L<br />
Bit xác định liên quan đến PWM4 chỉ có sẵn cho một số<br />
thiết bị và các bảng dữ liệu phù hợp nên được chuyển đến.<br />
config3 này chứa các thông số phải được cấu hình trong<br />
PWMCON2 đăng ký theo quy định dưới đây:<br />
Sự kiện đặc biệt bài rỉ<br />
PWM_SEVOPS1<br />
PWM_SEVOPS2<br />
.....<br />
PWM_SEVOPS15<br />
PWM_SEVOPS16<br />
Đầu ra đồng bộ hóa Override chọn<br />
PWM_OSYNC_PWM<br />
PWM_OSYNC_Tcy<br />
Cập nhật PWM cho phép / vô hiệu hóa<br />
PWM_UDIS<br />
PWM_UEN<br />
Trở lại giá trị Không<br />
Ghi chú: Chức năng này cấu hình PTPER, SEVTCMP, PTCON, PWMCON1<br />
và PWMCON2 đăng ký.
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 172<br />
Fault B Interrupt priority<br />
PWM_FLTB_INT_PR0<br />
PWM_FLTB_INT_PR1<br />
PWM_FLTB_INT_PR2<br />
PWM_FLTB_INT_PR3<br />
PWM_FLTB_INT_PR4<br />
PWM_FLTB_INT_PR5<br />
PWM_FLTB_INT_PR6<br />
PWM_FLTB_INT_PR7<br />
Return Value None<br />
2004 Microchip Technology Inc.<br />
Remarks: This function clears the Interrupt Flag bit, sets the interrupt priority<br />
and<br />
enables/disables the interrupt.<br />
Source File: ConfigIntMCPWM.c<br />
Code Example: ConfigIntMCPWM(PWM_INT_EN & PWM_INT_PR5 &<br />
PWM_FLTA_EN_INT &<br />
PWM_FLTA_INT_PR6 &<br />
PWM_FLTB_EN_INT &<br />
PWM_FLTB_INT_PR7);<br />
OpenMCPWM<br />
Description: This function configure the motor control PWM module.<br />
Include: pwm.h<br />
Prototype: void OpenMCPWM(unsigned int period,<br />
unsigned int sptime,<br />
unsigned int config1,<br />
unsigned int config2,<br />
unsigned int config3);<br />
Arguments: period This contains the PWM timebase period value to be stored<br />
in PTPER register.<br />
sptime This contains the special event compare value to be<br />
stored in SEVTCMP register.<br />
config1 This contains the parametersto be configured in the<br />
PTCON register as defined below:<br />
PWM module enable/disable<br />
PWM_EN<br />
OpenMCPWM (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 174 2004 Microchip Technology Inc<br />
Source File: OpenMCPWM.c<br />
Mã số Ví dụ: giai đoạn = 0x7fff;<br />
sptime = 0x0;<br />
config1 = PWM_EN & PWM_PTSIDL_DIS &<br />
PWM_OP_SCALE16 &<br />
PWM_IPCLK_SCALE16 &<br />
PWM_MOD_UPDN;<br />
config2 = PWM_MOD1_COMP & PWM_PDIS4H &<br />
PWM_PDIS3H & PWM_PDIS2H &<br />
PWM_PEN1H & PWM_PDIS4L &<br />
PWM_PDIS3L & PWM_PDIS2L &<br />
PWM_PEN1L;<br />
config3 = PWM_SEVOPS1 & PWM_OSYNC_PWM &<br />
PWM_UEN;<br />
OpenMCPWM (thời gian, sptime, config1,<br />
config2, config3);<br />
OverrideMCPWM<br />
Mô tả: Chức năng này cấu hình đăng ký OVDCON.<br />
Bao gồm: pwm.h<br />
Prototype: void OverrideMCPWM (int config);<br />
Đối số: cấu hình này chứa các parametersto được cấu hình trong<br />
OVDCON đăng ký theo quy định dưới đây:<br />
Đầu ra điều khiển bởi máy phát điện PWM<br />
PWM_GEN_4H<br />
PWM_GEN_3H<br />
PWM_GEN_2H<br />
PWM_GEN_1H<br />
PWM_GEN_4L<br />
PWM_GEN_3L<br />
PWM_GEN_2L<br />
PWM_GEN_1L<br />
Bit xác định liên quan đến PWM4 chỉ có sẵn cho một số<br />
thiết bị và các bảng dữ liệu phù hợp nên được chuyển đến.<br />
Đầu ra điều khiển bởi bit Pout
PWM_DIS<br />
Idle mode enable/disable<br />
PWM_IDLE_STOP<br />
PWM_IDLE_CON<br />
Output post scaler select<br />
PWM_OP_SCALE1<br />
PWM_OP_SCALE2<br />
.....<br />
PWM_OP_SCALE15<br />
PWM_OP_SCALE16<br />
Input prescaler select<br />
PWM_IPCLK_SCALE1<br />
PWM_IPCLK_SCALE4<br />
PWM_IPCLK_SCALE16<br />
PWM_IPCLK_SCALE64<br />
ConfigIntMCPWM (Continued)<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 173<br />
PWM mode of operation<br />
PWM_MOD_FREE<br />
PWM_MOD_SING<br />
PWM_MOD_UPDN<br />
PWM_MOD_DBL<br />
config2 This contains the parameters to be configured in the<br />
PWMCON1 register as defined below:<br />
PWM I/O pin pair<br />
PWM_MOD4_COMP<br />
PWM_MOD3_COMP<br />
PWM_MOD2_COMP<br />
PWM_MOD1_COMP<br />
PWM_MOD4_IND<br />
PWM_MOD3_IND<br />
PWM_MOD2_IND<br />
PWM_MOD1_IND<br />
PWM H/L I/O enable/disable select<br />
PWM_PEN4H<br />
PWM_PDIS4H<br />
PWM_PEN3H<br />
PWM_PDIS3H<br />
PWM_POUT_4H<br />
PWM_POUT_4L<br />
PWM_POUT_3H<br />
PWM_POUT_3L<br />
PWM_POUT_2H<br />
PWM_POUT_2L<br />
PWM_POUT_1H<br />
PWM_POUT_1L<br />
Bit xác định liên quan đến PWM4 chỉ có sẵn cho một số<br />
thiết bị và các bảng dữ liệu phù hợp nên được chuyển đến.<br />
OpenMCPWM (Tiếp theo)<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 175<br />
PWM bit tay ra<br />
PWM_POUT4H_ACT<br />
PWM_POUT4H_INACT<br />
PWM_POUT4L_ACT<br />
PWM_POUT4L_INACT<br />
PWM_POUT3H_ACT<br />
PWM_POUT3H_INACT<br />
PWM_POUT3L_ACT<br />
PWM_POUT3L_INACT<br />
PWM_POUT2H_ACT<br />
PWM_POUT2H_INACT<br />
PWM_POUT2L_ACT<br />
PWM_POUT2L_INACT<br />
PWM_POUT1H_ACT<br />
PWM_POUT1H_INACT<br />
PWM_POUT1L_ACT<br />
PWM_POUT1L_INACT<br />
Bit xác định liên quan đến PWM4 chỉ có sẵn cho một số<br />
thiết bị và các bảng dữ liệu phù hợp nên được chuyển đến.<br />
Trở lại giá trị Không<br />
Bình luận: chức năng này cấu hình Override PWM đầu ra và hướng dẫn sử dụn<br />
Bit kiểm soát đăng ký OVDCON.<br />
Source File: OverrideMCPWM.c<br />
Mã số Ví dụ: config = PWM_GEN_1L &<br />
PWM_GEN_1H &<br />
PWM_POUT1L_INACT &
PWM_PEN2H<br />
PWM_PDIS2H<br />
PWM_PEN1H<br />
PWM_PDIS1H<br />
PWM_PEN4L<br />
PWM_PDIS4L<br />
PWM_PEN3L<br />
PWM_PDIS3L<br />
PWM_PEN2L<br />
PWM_PDIS2L<br />
PWM_PEN1L<br />
PWM_PDIS1L<br />
Bit defines related to PWM4 is available only for certain<br />
devices and the suitable data sheet should be referred to.<br />
config3 This contains the parameters to be configured in the<br />
PWMCON2 register as defined below:<br />
Special event post scaler<br />
PWM_SEVOPS1<br />
PWM_SEVOPS2<br />
.....<br />
PWM_SEVOPS15<br />
PWM_SEVOPS16<br />
Output Override synchronization select<br />
PWM_OSYNC_PWM<br />
PWM_OSYNC_Tcy<br />
PWM update enable/disable<br />
PWM_UDIS<br />
PWM_UEN<br />
Return Value None<br />
Remarks: This function configures the PTPER, SEVTCMP, PTCON,<br />
PWMCON1<br />
and PWMCON2 registers.<br />
OpenMCPWM (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
PWM_POUT3L_INACT;<br />
OverrideMCPWM (config);<br />
SetDCMCPWM<br />
Mô tả: Chức năng này cấu hình đăng ký Chu kỳ và cập nhật của PWM<br />
Cập nhật Disable 'bit inthe PWMCON2 đăng ký.<br />
Bao gồm: pwm.h<br />
Prototype: void SetDCMCPWM (<br />
int dutycyclereg,<br />
int dutycycle,<br />
char updatedisable);<br />
Đối số: dutycycleregThis là con trỏ đến đăng ký Chu kỳ.<br />
dutycycle Đây là giá trị được lưu trữ trong sổ đăng ký Chu kỳ.<br />
updatedisable Đây là giá trị được nạp vào 'Cập nhật<br />
Vô hiệu hoá 'bit của thanh ghi PWMCON2.<br />
Trở lại giá trị Không<br />
Bình luận: Không có<br />
Source File: SetDCMCPWM.c<br />
Mã số Ví dụ: dutycyclereg = 1;<br />
dutycycle = 0xFFF;<br />
updatedisable = 0;<br />
SetDCMCPWM (dutycyclereg, dutycycle, updatedisable);<br />
OverrideMCPWM (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 176 2004 Microchip Technology Inc<br />
SetMCPWMDeadTimeAssignment<br />
Mô tả: Chức năng này cấu hình giao các đơn vị thời gian chết để PWM<br />
cặp đầu ra.<br />
Bao gồm: pwm.h<br />
Prototype: void SetMCPWMDeadTimeAssignment (int<br />
config);<br />
Đối số: cấu hình này bao gồm các thông số phải được cấu hình trong<br />
DTCON2 đăng ký theo quy định dưới đây:<br />
Dead Thời gian Chọn bit cho tín hiệu PWM4<br />
PWM_DTS4A_UA<br />
DS51456B-page 174<br />
2004 Microchip Technology Inc.<br />
PWM_DTS4A_UB<br />
Source File: OpenMCPWM.c<br />
Code Example: period = 0x7fff;<br />
PWM_DTS4I_UA<br />
PWM_DTS4I_UB
sptime = 0x0;<br />
config1 = PWM_EN & PWM_PTSIDL_DIS &<br />
PWM_OP_SCALE16 &<br />
PWM_IPCLK_SCALE16 &<br />
PWM_MOD_UPDN;<br />
config2 = PWM_MOD1_COMP & PWM_PDIS4H &<br />
PWM_PDIS3H & PWM_PDIS2H &<br />
PWM_PEN1H & PWM_PDIS4L &<br />
PWM_PDIS3L & PWM_PDIS2L &<br />
PWM_PEN1L;<br />
config3 = PWM_SEVOPS1 & PWM_OSYNC_PWM &<br />
PWM_UEN;<br />
OpenMCPWM(period, sptime, config1,<br />
config2, config3);<br />
OverrideMCPWM<br />
Description: This function configures the OVDCON register.<br />
Include: pwm.h<br />
Prototype: void OverrideMCPWM(unsigned int config);<br />
Arguments: config This contains the parametersto be configured in the<br />
OVDCON register as defined below:<br />
Output controlled by PWM generator<br />
PWM_GEN_4H<br />
PWM_GEN_3H<br />
PWM_GEN_2H<br />
PWM_GEN_1H<br />
PWM_GEN_4L<br />
PWM_GEN_3L<br />
PWM_GEN_2L<br />
PWM_GEN_1L<br />
Bit defines related to PWM4 is available only for certain<br />
devices and the suitable data sheet should be referred to.<br />
Output controlled by POUT bits<br />
PWM_POUT_4H<br />
PWM_POUT_4L<br />
PWM_POUT_3H<br />
PWM_POUT_3L<br />
PWM_POUT_2H<br />
PWM_POUT_2L<br />
PWM_POUT_1H<br />
Bit xác định liên quan đến PWM4 chỉ có sẵn cho một số<br />
thiết bị và các bảng dữ liệu phù hợp nên được chuyển đến.<br />
Dead Thời gian Chọn bit cho tín hiệu PWM3<br />
PWM_DTS3A_UA<br />
PWM_DTS3A_UB<br />
PWM_DTS3I_UA<br />
PWM_DTS3I_UB<br />
Dead Thời gian Chọn bit cho tín hiệu PWM2<br />
PWM_DTS2A_UA<br />
PWM_DTS2A_UB<br />
PWM_DTS2I_UA<br />
PWM_DTS2I_UB<br />
Dead Thời gian Chọn bit cho tín hiệu pwm1<br />
PWM_DTS1A_UA<br />
PWM_DTS1A_UB<br />
PWM_DTS1I_UA<br />
PWM_DTS1I_UB<br />
Trở lại giá trị Không<br />
Bình luận: Không có<br />
Source File: SetMCPWMDeadTimeAssignment.c<br />
Mã số Ví dụ: SetMCPWMDeadTimeAssignment (PWM_DTS3A_UA &<br />
PWM_DTS2I_UA & PWM_DTS1I_UA);<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 177<br />
SetMCPWMDeadTimeGeneration<br />
Mô tả: Chức năng này cấu hình các giá trị thời gian chết và prescalers đồng hồ.<br />
Bao gồm: pwm.h<br />
Prototype: void SetMCPWMDeadTimeGeneration (<br />
int config);<br />
Đối số: cấu hình này bao gồm các thông số phải được cấu hình trong DTCON1<br />
đăng ký theo quy định dưới đây:<br />
Dead Thời gian Đơn vị B prescale Chọn bit<br />
PWM_DTBPS8<br />
PWM_DTBPS4<br />
PWM_DTBPS2<br />
PWM_DTBPS1<br />
Dead Thời gian Đơn vị A prescale Chọn hằng số<br />
PWM_DTA0<br />
PWM_DTA1
PWM_POUT_1L<br />
Bit defines related to PWM4 is available only for certain<br />
devices and the suitable data sheet should be referred to.<br />
OpenMCPWM (Continued)<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 175<br />
PWM Manual Output bits<br />
PWM_POUT4H_ACT<br />
PWM_POUT4H_INACT<br />
PWM_POUT4L_ACT<br />
PWM_POUT4L_INACT<br />
PWM_POUT3H_ACT<br />
PWM_POUT3H_INACT<br />
PWM_POUT3L_ACT<br />
PWM_POUT3L_INACT<br />
PWM_POUT2H_ACT<br />
PWM_POUT2H_INACT<br />
PWM_POUT2L_ACT<br />
PWM_POUT2L_INACT<br />
PWM_POUT1H_ACT<br />
PWM_POUT1H_INACT<br />
PWM_POUT1L_ACT<br />
PWM_POUT1L_INACT<br />
Bit defines related to PWM4 is available only for certain<br />
devices and the suitable data sheet should be referred to.<br />
Return Value None<br />
Remarks: This functions configures the PWM Output Override and Manual<br />
Control bits of the OVDCON register.<br />
Source File: OverrideMCPWM.c<br />
Code Example: config = PWM_GEN_1L &<br />
PWM_GEN_1H &<br />
PWM_POUT1L_INACT &<br />
PWM_POUT3L_INACT;<br />
OverrideMCPWM(config);<br />
SetDCMCPWM<br />
Description: This function configures the Duty Cycle register and updates the<br />
‘PWM<br />
Update Disable’ bit inthe PWMCON2 register.<br />
Include: pwm.h<br />
PWM_DTA2<br />
..........<br />
PWM_DTA62<br />
PWM_DTA63<br />
Dead Thời gian Đơn vị B prescale Chọn hằng số<br />
PWM_DTB0<br />
PWM_DTB1<br />
PWM_DTB2<br />
..........<br />
PWM_DTB62<br />
PWM_DTB63<br />
Dead Thời gian Đơn vị A prescale Chọn bit<br />
PWM_DTAPS8<br />
PWM_DTAPS4<br />
PWM_DTAPS2<br />
PWM_DTAPS1<br />
Trở lại giá trị Không<br />
Bình luận: Không có<br />
Source File: SetMCPWMDeadTimeGeneration.c<br />
Mã số Ví dụ: SetMCPWMDeadTimeGeneration (PWM_DTBPS16 &<br />
PWM_DT54 & PWM_DTAPS8);<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 178 2004 Microchip Technology Inc<br />
SetMCPWMFaultA<br />
Mô tả: Chức năng này cấu hình Lỗi Một bit Override, Lỗi Một chút Mode và<br />
Một lỗi đầu vào Enable bit PWM.<br />
Bao gồm: pwm.h<br />
Prototype: void SetMCPWMFaultA (int config);<br />
Đối số: cấu hình này bao gồm các thông số phải được cấu hình trong<br />
FLTACON đăng ký theo quy định dưới đây:<br />
Lỗi đầu vào PWM bit Override Giá trị<br />
PWM_OVA4H_ACTIVE<br />
PWM_OVA3H_ACTIVE<br />
PWM_OVA2H_ACTIVE<br />
PWM_OVA1H_ACTIVE<br />
PWM_OVA4L_ACTIVE<br />
PWM_OVA3L_ACTIVE
Prototype: void SetDCMCPWM(<br />
unsigned int dutycyclereg,<br />
unsigned int dutycycle,<br />
char updatedisable);<br />
Arguments: dutycycleregThis is the pointer to the Duty Cycle register.<br />
dutycycle This is the value to be stored in the Duty Cycle register.<br />
updatedisable This is the value to be loaded into the ‘Update<br />
Disable’ bit of the PWMCON2 register.<br />
Return Value None<br />
Remarks: None<br />
Source File: SetDCMCPWM.c<br />
Code Example: dutycyclereg = 1;<br />
dutycycle = 0xFFF;<br />
updatedisable = 0;<br />
SetDCMCPWM(dutycyclereg, dutycycle,updatedisable);<br />
OverrideMCPWM (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 176<br />
SetMCPWMDeadTimeAssignment<br />
2004 Microchip Technology Inc.<br />
Description: This function configures the assignment of dead time units to<br />
PWM<br />
output pairs.<br />
Include: pwm.h<br />
Prototype: void SetMCPWMDeadTimeAssignment (unsigned int<br />
config);<br />
Arguments: config This contains the parameters to be configured in the<br />
DTCON2 register as defined below:<br />
Dead Time Select bits for PWM4 signal<br />
PWM_DTS4A_UA<br />
PWM_DTS4A_UB<br />
PWM_DTS4I_UA<br />
PWM_DTS4I_UB<br />
Bit defines related to PWM4 is available only for certain<br />
devices and the suitable data sheet should be referred to.<br />
Dead Time Select bits for PWM3 signal<br />
PWM_DTS3A_UA<br />
PWM_DTS3A_UB<br />
PWM_OVA2L_ACTIVE<br />
PWM_OVA1L_ACTIVE<br />
PWM_OVA4H_INACTIVE<br />
PWM_OVA3H_INACTIVE<br />
PWM_OVA2H_INACTIVE<br />
PWM_OVA1H_INACTIVE<br />
PWM_OVA4L_INACTIVE<br />
PWM_OVA3L_INACTIVE<br />
PWM_OVA2L_INACTIVE<br />
PWM_OVA1L_INACTIVE<br />
Bit xác định liên quan đến PWM4 chỉ có sẵn cho một số<br />
thiết bị và các bảng dữ liệu phù hợp nên được chuyển đến.<br />
Lỗi Một chút chế độ<br />
PWM_FLTA_MODE_CYCLE<br />
PWM_FLTA_MODE_LATCH<br />
Một lỗi đầu vào Enable bit.<br />
PWM_FLTA4_EN<br />
PWM_FLTA4_DIS<br />
PWM_FLTA3_EN<br />
PWM_FLTA3_DIS<br />
PWM_FLTA2_EN<br />
PWM_FLTA2_DIS<br />
PWM_FLTA1_EN<br />
PWM_FLTA1_DIS<br />
Bit xác định liên quan đến PWM4 chỉ có sẵn cho một số<br />
thiết bị và các bảng dữ liệu phù hợp nên được chuyển đến.<br />
Trở lại giá trị Không<br />
Bình luận: Không có<br />
Source File: SetMCPWMFaultA.c<br />
Mã số Ví dụ: SetMCPWMFaultA (PWM_OVA3L_INACTIVE &<br />
PWM_FLTA_MODE_LATCH &<br />
PWM_FLTA1_DIS);<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 179<br />
SetMCPWMFaultB<br />
Mô tả: Chức năng này cấu hình bit Override lỗi B, chế độ lỗi bit và B<br />
Lỗi InputB Enable bit PWM.<br />
Bao gồm: pwm.h<br />
Prototype: void SetMCPWMFaultB (int config);
PWM_DTS3I_UA<br />
PWM_DTS3I_UB<br />
Dead Time Select bits for PWM2 signal<br />
PWM_DTS2A_UA<br />
PWM_DTS2A_UB<br />
PWM_DTS2I_UA<br />
PWM_DTS2I_UB<br />
Dead Time Select bits for PWM1 signal<br />
PWM_DTS1A_UA<br />
PWM_DTS1A_UB<br />
PWM_DTS1I_UA<br />
PWM_DTS1I_UB<br />
Return Value None<br />
Remarks: None<br />
Source File: SetMCPWMDeadTimeAssignment.c<br />
Code Example: SetMCPWMDeadTimeAssignment(PWM_DTS3A_UA &<br />
PWM_DTS2I_UA & PWM_DTS1I_UA);<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 177<br />
SetMCPWMDeadTimeGeneration<br />
Description: This function configures dead time values and clock prescalers.<br />
Include: pwm.h<br />
Prototype: void SetMCPWMDeadTimeGeneration(<br />
unsigned int config);<br />
Arguments: config This contains the parameters to be configured in the<br />
DTCON1<br />
register as defined below:<br />
Dead Time Unit B Prescale Select bits<br />
PWM_DTBPS8<br />
PWM_DTBPS4<br />
PWM_DTBPS2<br />
PWM_DTBPS1<br />
Dead Time Unit A Prescale Select constants<br />
PWM_DTA0<br />
PWM_DTA1<br />
PWM_DTA2<br />
..........<br />
PWM_DTA62<br />
PWM_DTA63<br />
Đối số: cấu hình này bao gồm các thông số phải được cấu hình trong<br />
FLTBCON đăng ký theo quy định dưới đây:<br />
FLTBCON đăng ký chỉ có sẵn cho các thiết bị nhất định và<br />
các bảng dữ liệu phù hợp nên được chuyển đến.<br />
Lỗi B PWM Override bit Giá trị đầu vào<br />
PWM_OVB4H_ACTIVE<br />
PWM_OVB3H_ACTIVE<br />
PWM_OVB2H_ACTIVE<br />
PWM_OVB1H_ACTIVE<br />
PWM_OVB4L_ACTIVE<br />
PWM_OVB3L_ACTIVE<br />
PWM_OVB2L_ACTIVE<br />
PWM_OVB1L_ACTIVE<br />
PWM_OVB4H_INACTIVE<br />
PWM_OVB3H_INACTIVE<br />
PWM_OVB2H_INACTIVE<br />
PWM_OVB1H_INACTIVE<br />
PWM_OVB4L_INACTIVE<br />
PWM_OVB3L_INACTIVE<br />
PWM_OVB2L_INACTIVE<br />
PWM_OVB1L_INACTIVE<br />
Lỗi B Chế độ bit<br />
PWM_FLTB_MODE_CYCLE<br />
PWM_FLTB_MODE_LATCH<br />
Lỗi đầu vào B Enable bit.<br />
PWM_FLTB4_EN<br />
PWM_FLTB4_DIS<br />
PWM_FLTB3_EN<br />
PWM_FLTB3_DIS<br />
PWM_FLTB2_EN<br />
PWM_FLTB2_DIS<br />
PWM_FLTB1_EN<br />
PWM_FLTB1_DIS<br />
Trở lại giá trị Không<br />
Bình luận: Không có<br />
Source File: SetMCPWMFaultB.c<br />
Mã số Ví dụ: SetMCPWMFaultB (PWM_OVB3L_INACTIVE &<br />
PWM_FLTB_MODE_LATCH &<br />
PWM_FLTB2_DIS);
Dead Time Unit B Prescale Select constants<br />
PWM_DTB0<br />
PWM_DTB1<br />
PWM_DTB2<br />
..........<br />
PWM_DTB62<br />
PWM_DTB63<br />
Dead Time Unit A Prescale Select bits<br />
PWM_DTAPS8<br />
PWM_DTAPS4<br />
PWM_DTAPS2<br />
PWM_DTAPS1<br />
Return Value None<br />
Remarks: None<br />
Source File: SetMCPWMDeadTimeGeneration.c<br />
Code Example: SetMCPWMDeadTimeGeneration(PWM_DTBPS16 &<br />
PWM_DT54 & PWM_DTAPS8);<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 178<br />
SetMCPWMFaultA<br />
2004 Microchip Technology Inc.<br />
Description: This function configures Fault A Override bits, Fault A Mode bit<br />
and<br />
Fault Input A Enable bits of PWM.<br />
Include: pwm.h<br />
Prototype: void SetMCPWMFaultA(unsigned int config);<br />
Arguments: config This contains the parameters to be configured in the<br />
FLTACON register as defined below:<br />
Fault Input A PWM Override Value bits<br />
PWM_OVA4H_ACTIVE<br />
PWM_OVA3H_ACTIVE<br />
PWM_OVA2H_ACTIVE<br />
PWM_OVA1H_ACTIVE<br />
PWM_OVA4L_ACTIVE<br />
PWM_OVA3L_ACTIVE<br />
PWM_OVA2L_ACTIVE<br />
PWM_OVA1L_ACTIVE<br />
PWM_OVA4H_INACTIVE<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 180<br />
3.16.2 Macros cá nhân<br />
EnableIntMCPWM<br />
2004 Microchip Technology Inc<br />
Mô tả: Phần này cho phép các PWM gián đoạn.<br />
Bao gồm: pwm.h<br />
Lập luận: Không<br />
Bình luận: Đây bộ vĩ mô PWM Enablebit ngắt của ngắt Kích hoạt tính năng<br />
kiểm soát<br />
đăng ký.<br />
Mã số Ví dụ: EnableIntMCPWM;<br />
DisableIntMCPWM<br />
Mô tả: vĩ mô này vô hiệu hóa các PWM gián đoạn.<br />
Bao gồm: pwm.h<br />
Lập luận: Không<br />
Bình luận: vĩ mô này sẽ xóa PWM Interrupt Enable bit Interrupt Enable kiểm<br />
soát<br />
đăng ký.<br />
Mã số Ví dụ: DisableIntMCPWM;<br />
SetPriorityIntMCPWM<br />
Mô tả: Điều này đặt ra ưu tiên vĩ mô cho PWM gián đoạn.<br />
Bao gồm: pwm.h<br />
Đối số: ưu tiên<br />
Bình luận: vĩ mô này đặt PWM ngắt bit ưu tiên của ngắt ưu tiên kiểm soát<br />
đăng ký.<br />
Mã số Ví dụ: SetPriorityIntMCPWM (7);<br />
EnableIntFLTA<br />
Mô tả: vĩ mô này cho phép ngắt FLTA.<br />
Bao gồm: pwm.h<br />
Lập luận: Không<br />
Bình luận: Đây bộ vĩ mô FLTA Interrupt Enable bit Interrupt Enable kiểm soát<br />
đăng ký.<br />
Mã số Ví dụ: EnableIntFLTA;<br />
DisableIntFLTA<br />
Mô tả: vĩ mô này vô hiệu hóa ngắt FLTA.<br />
Bao gồm: pwm.h<br />
Lập luận: Không<br />
Bình luận: vĩ mô này sẽ xóa FLTA Interrupt Enable bit Interrupt Enable kiểm<br />
soát
PWM_OVA3H_INACTIVE<br />
PWM_OVA2H_INACTIVE<br />
PWM_OVA1H_INACTIVE<br />
PWM_OVA4L_INACTIVE<br />
PWM_OVA3L_INACTIVE<br />
PWM_OVA2L_INACTIVE<br />
PWM_OVA1L_INACTIVE<br />
Bit defines related to PWM4 is available only for certain<br />
devices and the suitable data sheet should be referred to.<br />
Fault A Mode bit<br />
PWM_FLTA_MODE_CYCLE<br />
PWM_FLTA_MODE_LATCH<br />
Fault Input A Enable bits.<br />
PWM_FLTA4_EN<br />
PWM_FLTA4_DIS<br />
PWM_FLTA3_EN<br />
PWM_FLTA3_DIS<br />
PWM_FLTA2_EN<br />
PWM_FLTA2_DIS<br />
PWM_FLTA1_EN<br />
PWM_FLTA1_DIS<br />
Bit defines related to PWM4 is available only for certain<br />
devices and the suitable data sheet should be referred to.<br />
Return Value None<br />
Remarks: None<br />
Source File: SetMCPWMFaultA.c<br />
Code Example: SetMCPWMFaultA(PWM_OVA3L_INACTIVE &<br />
PWM_FLTA_MODE_LATCH &<br />
PWM_FLTA1_DIS);<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 179<br />
SetMCPWMFaultB<br />
Description: This function configures Fault B Override bits, Fault B Mode bit<br />
and<br />
Fault InputB Enable bits of PWM.<br />
Include: pwm.h<br />
đăng ký.<br />
Mã số Ví dụ: DisableIntFLTA;<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 181<br />
SetPriorityIntFLTA<br />
Mô tả: Đây ưu tiên bộ vĩ mô cho FLTA bị gián đoạn.<br />
Bao gồm: pwm.h<br />
Đối số: ưu tiên<br />
Bình luận: Đây bộ vĩ mô FLTA Prioritybits ngắt của ngắt ưu tiên kiểm soát<br />
đăng ký.<br />
Mã số Ví dụ: SetPriorityIntFLTA (7);<br />
EnableIntFLTB<br />
Mô tả: vĩ mô này cho phép ngắt FLTB.<br />
Bao gồm: pwm.h<br />
Lập luận: Không<br />
Bình luận: Đây bộ vĩ mô FLTB Enablebit ngắt của ngắt Kích hoạt tính năng<br />
kiểm soát<br />
đăng ký.<br />
Mã số Ví dụ: EnableIntFLTB;<br />
DisableIntFLTB<br />
Mô tả: vĩ mô này vô hiệu hóa ngắt FLTB.<br />
Bao gồm: pwm.h<br />
Lập luận: Không<br />
Bình luận: vĩ mô này sẽ xóa FLTB Interrupt Enable bit Interrupt Enable kiểm<br />
soát<br />
đăng ký.<br />
Mã số Ví dụ: DisableIntFLTB;<br />
SetPriorityIntFLTB<br />
Mô tả: Đây ưu tiên bộ vĩ mô cho FLTB bị gián đoạn.<br />
Bao gồm: pwm.h<br />
Đối số: ưu tiên<br />
Bình luận: Đây bộ vĩ mô FLTB Prioritybits ngắt của ngắt ưu tiên kiểm soát<br />
đăng ký.<br />
Mã số Ví dụ: SetPriorityIntFLTB (1);<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
Prototype: void SetMCPWMFaultB(unsigned int config);<br />
Arguments: config This contains the parameters to be configured in the<br />
DS51456B trang 182<br />
3.16.3 Ví dụ sử dụng<br />
2004 Microchip Technology Inc<br />
FLTBCON register as defined below:<br />
# xác định __dsPIC30F6010__
FLTBCON register is available only for certain devices and<br />
the suitable data sheet should be referred to.<br />
Fault Input B PWM Override Value bits<br />
PWM_OVB4H_ACTIVE<br />
PWM_OVB3H_ACTIVE<br />
PWM_OVB2H_ACTIVE<br />
PWM_OVB1H_ACTIVE<br />
PWM_OVB4L_ACTIVE<br />
PWM_OVB3L_ACTIVE<br />
PWM_OVB2L_ACTIVE<br />
PWM_OVB1L_ACTIVE<br />
PWM_OVB4H_INACTIVE<br />
PWM_OVB3H_INACTIVE<br />
PWM_OVB2H_INACTIVE<br />
PWM_OVB1H_INACTIVE<br />
PWM_OVB4L_INACTIVE<br />
PWM_OVB3L_INACTIVE<br />
PWM_OVB2L_INACTIVE<br />
PWM_OVB1L_INACTIVE<br />
Fault B Mode bit<br />
PWM_FLTB_MODE_CYCLE<br />
PWM_FLTB_MODE_LATCH<br />
Fault Input B Enable bits.<br />
PWM_FLTB4_EN<br />
PWM_FLTB4_DIS<br />
PWM_FLTB3_EN<br />
PWM_FLTB3_DIS<br />
PWM_FLTB2_EN<br />
PWM_FLTB2_DIS<br />
PWM_FLTB1_EN<br />
PWM_FLTB1_DIS<br />
Return Value None<br />
Remarks: None<br />
Source File: SetMCPWMFaultB.c<br />
Code Example: SetMCPWMFaultB(PWM_OVB3L_INACTIVE &<br />
PWM_FLTB_MODE_LATCH &<br />
PWM_FLTB2_DIS);<br />
dsPIC<br />
®<br />
# include<br />
# include<br />
khoảng trống __attribute __ ((__ interrupt__)) _PWMInterrupt (void)<br />
{<br />
IFS2bits.PWMIF = 0;<br />
}<br />
int main ()<br />
{<br />
/ * Giữ PWM giá trị cấu hình ngắt * /<br />
int cấu hình;<br />
/ * Giữ giá trị beloaded vào dutycycle đăng ký * /<br />
giai đoạn int unsigned;<br />
/ * Giữ giá trị được nạp vào sự kiện đặc biệt so sánh đăng ký * /<br />
int sptime;<br />
/ * Giữ giá trị cấu hình PWM * /<br />
int config1;<br />
/ * Giữ giá trị được nạp vào PWMCON1 đăng ký * /<br />
int config2;<br />
/ * Giữ giá trị cấu hình kích hoạt specialevent<br />
postscale và dutycycle * /<br />
int config3;<br />
/ * Giá trị của 'dutycyclereg' xác định chu kỳ nhiệm vụ<br />
register (PDCx) được viết * /<br />
int dutycyclereg;<br />
int dutycycle;<br />
unsigned char updatedisable;<br />
/ * Cấu hình PWM gián đoạn cho phép / vô hiệu hóa và thiết lập ngắt<br />
priorties * /<br />
config = (PWM_INT_EN & PWM_FLTA_DIS_INT & PWM_INT_PR1<br />
& PWM_FLTA_INT_PR0<br />
& PWM_FLTB_DIS_INT & PWM_FLTB_INT_PR0);<br />
ConfigIntMCPWM (config);<br />
/ * Cấu hình PWM để tạo ra sóng vuông of50% chu kỳ * /<br />
dutycyclereg = 1;<br />
dutycycle = 0x3FFF;<br />
updatedisable = 0;<br />
SetDCMCPWM (dutycyclereg, dutycycle, updatedisable);<br />
thời gian = 0x7fff;<br />
sptime = 0x0;
Language Tools Libraries<br />
DS51456B-page 180<br />
3.16.2 Individual Macros<br />
EnableIntMCPWM<br />
2004 Microchip Technology Inc.<br />
Description: This macro enables the PWM interrupt.<br />
Include: pwm.h<br />
Arguments: None<br />
Remarks: This macro sets PWM Interrupt Enablebit of Interrupt Enable Control<br />
register.<br />
Code Example: EnableIntMCPWM;<br />
DisableIntMCPWM<br />
Description: This macro disables the PWM interrupt.<br />
Include: pwm.h<br />
Arguments: None<br />
Remarks: This macro clears PWM Interrupt Enable bit of Interrupt Enable<br />
Control<br />
register.<br />
Code Example: DisableIntMCPWM;<br />
SetPriorityIntMCPWM<br />
Description: This macro sets priority for PWM interrupt.<br />
Include: pwm.h<br />
Arguments: priority<br />
Remarks: This macro sets PWM Interrupt Priority bits of Interrupt Priority<br />
Control<br />
register.<br />
Code Example: SetPriorityIntMCPWM(7);<br />
EnableIntFLTA<br />
Description: This macro enables the FLTA interrupt.<br />
Include: pwm.h<br />
Arguments: None<br />
Remarks: This macro sets FLTA Interrupt Enable bit of Interrupt Enable<br />
Control<br />
register.<br />
Code Example: EnableIntFLTA;<br />
DisableIntFLTA<br />
Description: This macro disables the FLTA interrupt.<br />
Include: pwm.h<br />
Arguments: None<br />
Remarks: This macro clears FLTA Interrupt Enable bit of Interrupt Enable<br />
Control<br />
register.<br />
config1 = (PWM_EN & PWM_PTSIDL_DIS & PWM_OP_SCALE16<br />
& PWM_IPCLK_SCALE16 &<br />
PWM_MOD_UPDN);<br />
config2 = (PWM_MOD1_COMP & PWM_PDIS4H & PWM_PDIS3H &<br />
PWM_PDIS2H & PWM_PEN1H & PWM_PDIS4L &<br />
PWM_PDIS3L & PWM_PDIS2L & PWM_PEN1L);<br />
config3 = (PWM_SEVOPS1 & PWM_OSYNC_PWM & PWM_UEN);<br />
OpenMCPWM (thời gian, sptime, config1, config2, config3);<br />
trong khi (1);<br />
}<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 183<br />
3.17 Tôi<br />
2<br />
C chức năng<br />
Phần này bao gồm một danh sách các chức năng cá nhân cho tôi<br />
2<br />
C module và một ví dụ về sử dụng<br />
các chức năng. Chức năng có thể được thực hiện như các macro.<br />
3.17.1 Chức năng cá nhân<br />
CloseI2C<br />
Mô tả: Chức năng này sẽ tắt thei<br />
2<br />
Cmodule<br />
Bao gồm: i2c.h<br />
Prototype: void CloseI2C (void);<br />
Lập luận: Không<br />
Trở lại giá trị Không<br />
Bình luận: Chức năng này vô hiệu hóa tôi<br />
2<br />
Cmodule và xóa Master và Slave<br />
Ngắt Enable và bit cờ.<br />
Source File: CloseI2C.c<br />
Mã số Ví dụ: CloseI2C ();<br />
ConfigIntI2C<br />
Mô tả: Chức năng này Cấu hình tôi<br />
2<br />
CInterrupt.<br />
Bao gồm: i2c.h
Code Example: DisableIntFLTA;<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 181<br />
SetPriorityIntFLTA<br />
Description: This macro sets priority for FLTA interrupt.<br />
Include: pwm.h<br />
Arguments: priority<br />
Remarks: This macro sets FLTA Interrupt Prioritybits of Interrupt Priority<br />
Control<br />
register.<br />
Code Example: SetPriorityIntFLTA(7);<br />
EnableIntFLTB<br />
Description: This macro enables the FLTB interrupt.<br />
Include: pwm.h<br />
Arguments: None<br />
Remarks: This macro sets FLTB Interrupt Enablebit of Interrupt Enable Control<br />
register.<br />
Code Example: EnableIntFLTB;<br />
DisableIntFLTB<br />
Description: This macro disables the FLTB interrupt.<br />
Include: pwm.h<br />
Arguments: None<br />
Remarks: This macro clears FLTB Interrupt Enable bit of Interrupt Enable<br />
Control<br />
register.<br />
Code Example: DisableIntFLTB;<br />
SetPriorityIntFLTB<br />
Description: This macro sets priority for FLTB interrupt.<br />
Include: pwm.h<br />
Arguments: priority<br />
Remarks: This macro sets FLTB Interrupt Prioritybits of Interrupt Priority<br />
Control<br />
register.<br />
Code Example: SetPriorityIntFLTB(1);<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 182<br />
3.16.3 Example of Use<br />
#define __dsPIC30F6010__<br />
2004 Microchip Technology Inc.<br />
Prototype: void ConfigIntI2C (int config);<br />
Lập luận: config tôi<br />
2<br />
Ưu tiên Cinterrupt và bật / tắt thông tin<br />
quy định dưới đây:<br />
Tôi<br />
2<br />
Cmaster ngắt bật / tắt<br />
MI2C_INT_ON<br />
MI2C_INT_OFF<br />
I2C nô lệ ngắt bật / tắt<br />
SI2C_INT_ON<br />
SI2C_INT_OFF<br />
Tôi<br />
2<br />
Ưu tiên Cmaster ngắt<br />
MI2C_INT_PRI_7<br />
MI2C_INT_PRI_6<br />
MI2C_INT_PRI_5<br />
MI2C_INT_PRI_4<br />
MI2C_INT_PRI_3<br />
MI2C_INT_PRI_2<br />
MI2C_INT_PRI_1<br />
MI2C_INT_PRI_0<br />
Tôi<br />
2<br />
Ưu tiên Cslave ngắt<br />
SI2C_INT_PRI_7<br />
SI2C_INT_PRI_6<br />
SI2C_INT_PRI_5<br />
SI2C_INT_PRI_4<br />
SI2C_INT_PRI_3<br />
SI2C_INT_PRI_2<br />
SI2C_INT_PRI_1<br />
SI2C_INT_PRI_0<br />
Trở lại giá trị Không<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ
#include <br />
#include<br />
void __attribute__((__interrupt__)) _PWMInterrupt(void)<br />
{<br />
IFS2bits.PWMIF = 0;<br />
}<br />
int main()<br />
{<br />
/* Holds the PWM interrupt configuration value*/<br />
unsigned int config;<br />
/* Holds the value to beloaded into dutycycle register */<br />
unsigned int period;<br />
/* Holds the value to be loaded into special event compare register */<br />
unsigned int sptime;<br />
/* Holds PWM configuration value */<br />
unsigned int config1;<br />
/* Holds the value be loaded into PWMCON1 register */<br />
unsigned int config2;<br />
/* Holds the value to configure the specialevent trigger<br />
postscale and dutycycle */<br />
unsigned int config3;<br />
/* The value of ‘dutycyclereg’ determines the duty cycle<br />
register(PDCx)to be written */<br />
unsigned int dutycyclereg;<br />
unsigned int dutycycle;<br />
unsigned char updatedisable;<br />
/* Configure pwm interrupt enable/disable and set interrupt<br />
priorties */<br />
config = (PWM_INT_EN & PWM_FLTA_DIS_INT & PWM_INT_PR1<br />
& PWM_FLTA_INT_PR0<br />
& PWM_FLTB_DIS_INT & PWM_FLTB_INT_PR0);<br />
ConfigIntMCPWM( config );<br />
/* Configure PWM to generate square wave of50% duty cycle */<br />
dutycyclereg = 1;<br />
dutycycle = 0x3FFF;<br />
updatedisable = 0;<br />
SetDCMCPWM(dutycyclereg,dutycycle,updatedisable);<br />
period = 0x7fff;<br />
sptime = 0x0;<br />
DS51456B trang 184<br />
2004 Microchip Technology Inc<br />
Bình luận: chức năng này sẽ xóa các bit Cờ ngắt, thiết lập các ưu tiên của ngắt<br />
chủ và nô lệ và cho phép / vô hiệu hóa ngắt.<br />
Source File: ConfigIntI2C.c<br />
Mã số Ví dụ: ConfigIntI2C (MI2C_INT_ON & MI2C_INT_PRI_3<br />
& SI2C_INT_ON & SI2C_INT_PRI_5);<br />
AckI2C<br />
Mô tả: Tạo ra tôi<br />
2<br />
Cbus Thừa nhận điều kiện.<br />
Bao gồm: i2c.h<br />
Prototype: void AckI2C (void);<br />
Lập luận: Không<br />
Trở lại giá trị Không<br />
Bình luận: Chức năng này tạo ra một tôi<br />
2<br />
Cbus Thừa nhận điều kiện.<br />
Source File: AckI2C.c<br />
Mã số Ví dụ: AckI2C ();<br />
DataRdyI2C<br />
Mô tả: Chức năng này cung cấp cho tình trạng trở lại cho người dùng nếu<br />
I2CRCV register chứa<br />
dữ liệu.<br />
Bao gồm: i2c.h<br />
Prototype: unsigned char DataRdyI2C (void);<br />
Lập luận: Không<br />
Giá trị trả lại chức năng này trả về "1" nếu có dữ liệu trong I2CRCV đăng<br />
ký; khác trở về<br />
"0" mà chỉ có dữ liệu trong I2CRCV đăng ký.<br />
Bình luận: Chức năng này xác định xem liệu có bất kỳ byte để đọc từ I2CRCV<br />
đăng ký.<br />
Source File: DataRdyI2C.c<br />
Mã số Ví dụ: if (DataRdyI2C ());<br />
IdleI2C<br />
Mô tả: Đây tình trạng chức năng generatesWait cho đến khi tôi<br />
2<br />
Cbus là nhàn rỗi<br />
Bao gồm: i2c.h<br />
Prototype: void IdleI2C (void);<br />
Lập luận: Không
config1 = (PWM_EN & PWM_PTSIDL_DIS & PWM_OP_SCALE16<br />
& PWM_IPCLK_SCALE16 &<br />
PWM_MOD_UPDN);<br />
config2 = (PWM_MOD1_COMP & PWM_PDIS4H & PWM_PDIS3H &<br />
PWM_PDIS2H & PWM_PEN1H& PWM_PDIS4L &<br />
PWM_PDIS3L & PWM_PDIS2L & PWM_PEN1L);<br />
config3 = (PWM_SEVOPS1& PWM_OSYNC_PWM & PWM_UEN);<br />
OpenMCPWM(period,sptime,config1,config2,config3);<br />
while(1);<br />
}<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 183<br />
3.17 I<br />
2<br />
C FUNCTIONS<br />
This section contains a list of individual functions for I<br />
2<br />
C module and an example of use<br />
of the functions. Functions may be implemented as macros.<br />
3.17.1 Individual Functions<br />
CloseI2C<br />
Description: This function turns off theI<br />
2<br />
Cmodule<br />
Include: i2c.h<br />
Prototype: void CloseI2C(void);<br />
Arguments: None<br />
Return Value None<br />
Remarks: This function disables the I<br />
2<br />
Cmodule and clears the Master and Slave<br />
Interrupt Enable and Flag bits.<br />
Source File: CloseI2C.c<br />
Code Example: CloseI2C();<br />
ConfigIntI2C<br />
Description: This function Configure the I<br />
2<br />
CInterrupt.<br />
Include: i2c.h<br />
Trở lại giá trị Không<br />
Ghi chú: Chức năng này sẽ ở trong trạng thái chờ đợi cho đến khi bắt đầu Điều<br />
kiện Kích hoạt bit, Stop<br />
Điều kiện Enable bit, Nhận Kích hoạt bit, Thừa nhận trình tự<br />
Bit cho phép của tôi<br />
2<br />
CControl đăng ký và Truyền Tình trạng bit tôi<br />
2<br />
CStatus<br />
đăng ký rõ ràng. Chức năng IdleI2C được yêu cầu kể từ khi phần cứng<br />
Tôi<br />
2<br />
Cperipheral không cho phép spooling của dãy xe buýt. I<br />
2<br />
C<br />
thiết bị ngoại vi phải ở trạng thái nhàn rỗi trước khi tôi<br />
2<br />
Coperation có thể được bắt đầu<br />
hoặc viết va chạm sẽ được tạo ra.<br />
Source File: IdleI2C.c<br />
Mã số Ví dụ: IdleI2C ();<br />
ConfigIntI2C (Tiếp theo)<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 185<br />
MastergetsI2C<br />
Mô tả: Chức năng này lần đọc dữ liệu định trước chuỗi dài từ tôi<br />
2<br />
Cbus.<br />
Bao gồm: i2c.h<br />
Prototype: unsigned int MastergetsI2C (unsigned int dài,<br />
unsigned char * rdptr, int i2c_data_wait);<br />
Đối số: chiều dài Số byte để đọc từ tôi<br />
2<br />
Cdevice.<br />
rdptr loại nhân vật con trỏ tới dsPIC ram cho lưu trữ dữ liệu<br />
đọc từ tôi<br />
2<br />
Cdevice<br />
i2c_data_wait Đây là số thời gian chờ cho các mô-đun có<br />
chờ đợi trước khi trở về.
Prototype: void ConfigIntI2C(unsigned int config);<br />
Arguments: config I<br />
2<br />
Cinterrupt priority and enable/disable information as<br />
defined below:<br />
I<br />
2<br />
Cmaster Interrupt enable/disable<br />
MI2C_INT_ON<br />
MI2C_INT_OFF<br />
I2C slave Interrupt enable/disable<br />
SI2C_INT_ON<br />
SI2C_INT_OFF<br />
I<br />
2<br />
Cmaster Interrupt priority<br />
MI2C_INT_PRI_7<br />
MI2C_INT_PRI_6<br />
MI2C_INT_PRI_5<br />
MI2C_INT_PRI_4<br />
MI2C_INT_PRI_3<br />
MI2C_INT_PRI_2<br />
MI2C_INT_PRI_1<br />
MI2C_INT_PRI_0<br />
I<br />
2<br />
Cslave Interrupt priority<br />
SI2C_INT_PRI_7<br />
SI2C_INT_PRI_6<br />
SI2C_INT_PRI_5<br />
SI2C_INT_PRI_4<br />
SI2C_INT_PRI_3<br />
SI2C_INT_PRI_2<br />
SI2C_INT_PRI_1<br />
SI2C_INT_PRI_0<br />
Return Value None<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
Nếu tính thời gian chờ là 'N', thời gian chờ thực tế sẽ<br />
khoảng (20 * N - 1) chu kỳ hướng dẫn.<br />
Giá trị trả lại chức năng này trả về "0" nếu tất cả các byte đã được gửi hoặc số<br />
byte<br />
đọc từ tôi<br />
2<br />
Cbus nếu nó không thể đọc được dữ liệu có trong các quy định<br />
i2c_data_waittime ra giá trị<br />
Bình luận: thói quen này đọc một chuỗi dữ liệu được xác định trước từ I<br />
2<br />
Cbus.<br />
Source File: MastergetsI2C.c<br />
Mã số Ví dụ: unsigned char string [10];<br />
unsigned char * rdptr;<br />
chiều dài int unsigned, i2c_data_wait;<br />
chiều dài = 9;<br />
rdptr = chuỗi;<br />
i2c_data_wait = 152;<br />
MastergetsI2C (chiều dài, rdptr, i2c_data_wait);<br />
MasterputsI2C<br />
Mô tả: Chức năng này được sử dụng để viết ra một chuỗi dữ liệu cho tôi<br />
2<br />
Cbus.<br />
Bao gồm: i2c.h<br />
Nguyên mẫu: int MasterputsI2C (unsigned char * wrptr);<br />
Đối số: wrptr loại nhân vật con trỏ đến các đối tượng dữ liệu trong dsPIC<br />
Ram. Các<br />
đối tượng dữ liệu được ghi vào tôi<br />
2<br />
Cdevice.<br />
Trở lại giá trị chức năng này trả về -3 nếu viết va chạm occurred.This trở về<br />
chức năng<br />
"0" nếu các ký tự null đã đạt được trong chuỗi dữ liệu.<br />
Bình luận: Chức năng này ghi một chuỗi các tôi<br />
2<br />
Cbus cho đến khi một nhân vật null<br />
đạt được. Mỗi byte được viết thông qua một cuộc gọi đến MasterputcI2C<br />
chức năng. Cơ thể calledfunction thực tế được gọi là MasterWriteI2C.<br />
MasterWriteI2Cand MasterputcI2Crefer để cùng chức năng thông qua<br />
một #definestatement trong i2c.h<br />
Source File: MasterputsI2C.c
DS51456B-page 184<br />
2004 Microchip Technology Inc.<br />
Remarks: This function clears the Interrupt Flag bits, sets the interrupt priorities<br />
of<br />
master and slave and enables/disables the interrupt.<br />
Source File: ConfigIntI2C.c<br />
Code Example: ConfigIntI2C(MI2C_INT_ON& MI2C_INT_PRI_3<br />
& SI2C_INT_ON & SI2C_INT_PRI_5);<br />
Mã số Ví dụ: unsigned char string [] = "vi mạch";<br />
unsigned char * wrptr;<br />
wrptr = chuỗi;<br />
MasterputsI2C (wrptr);<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
AckI2C<br />
Description: Generates I<br />
DS51456B trang 186<br />
MasterReadI2C<br />
2004 Microchip Technology Inc<br />
2<br />
Cbus Acknowledge condition.<br />
Include: i2c.h<br />
Prototype: void AckI2C(void);<br />
Arguments: None<br />
Return Value None<br />
Remarks: This function generates an I<br />
2<br />
Cbus Acknowledge condition.<br />
Source File: AckI2C.c<br />
Code Example: AckI2C();<br />
DataRdyI2C<br />
Description: This function provides status back to user if I2CRCV register<br />
contain<br />
data.<br />
Include: i2c.h<br />
Prototype: unsigned char DataRdyI2C(void);<br />
Arguments: None<br />
Return Value This function returns ‘1’ if there is data in I2CRCV register; else<br />
return<br />
‘0’ which indicates no data in I2CRCV register.<br />
Remarks: This function Determines if there is any byte to read from I2CRCV<br />
register.<br />
Source File: DataRdyI2C.c<br />
Code Example: if(DataRdyI2C());<br />
IdleI2C<br />
Description: This function generatesWait condition until I<br />
2<br />
Cbus is Idle<br />
Include: i2c.h<br />
Prototype: void IdleI2C(void);<br />
Mô tả: Chức năng này được sử dụng để đọc một byte duy nhất từ tôi<br />
2<br />
Cbus<br />
Bao gồm: i2c.h<br />
Prototype: unsigned char MasterReadI2C (void);<br />
Lập luận: Không<br />
Quay trở lại Giá trị Giá trị trả về là các byte dữ liệu đọc từ tôi<br />
2<br />
Cbus.<br />
Bình luận: Chức năng này lần đọc trong một byte duy nhất từ tôi<br />
2<br />
Cbus.<br />
Chức năng này thực hiện chức năng tương tự như MastergetcI2C.<br />
Source File: MasterReadI2C.c<br />
Mã số Ví dụ: giá trị unsigned char;<br />
giá trị = MasterReadI2C ();<br />
MasterWriteI2C<br />
Mô tả: Chức năng này được sử dụng để viết ra một byte dữ liệu duy nhất cho tô<br />
2<br />
Cdevice.<br />
Bao gồm: i2c.h<br />
Prototype: unsigned char MasterWriteI2C (unsigned char<br />
data_out);<br />
Đối số: data_out Một byte dữ liệu duy nhất để được ghi vào tôi<br />
2<br />
Thiết bị Cbus.<br />
Giá trị trả lại chức năng này trả về -1 nếu có một vụ va chạm khác viết nó trả về<br />
0.<br />
Ghi chú: Chức năng này viết ra một byte dữ liệu duy nhất cho tôi<br />
2<br />
Thiết bị Cbus. Điều này
Arguments: None<br />
Return Value None<br />
Remarks: This function will be in a wait state until Start Condition Enable bit,<br />
Stop<br />
Condition Enable bit, Receive Enable bit, Acknowledge Sequence<br />
Enable bit of I<br />
2<br />
CControl register and Transmit Status bit I<br />
2<br />
CStatus<br />
register are clear. The IdleI2C function is required since the hardware<br />
I<br />
2<br />
Cperipheral does not allow for spooling of bus sequence. The I<br />
2<br />
C<br />
peripheral must be in Idle state before an I<br />
2<br />
Coperation can be initiated<br />
or write collision will be generated.<br />
Source File: IdleI2C.c<br />
Code Example: IdleI2C();<br />
ConfigIntI2C (Continued)<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 185<br />
MastergetsI2C<br />
Description: This function reads predetermined data string length from the I<br />
2<br />
Cbus.<br />
Include: i2c.h<br />
Prototype: unsigned int MastergetsI2C(unsigned int length,<br />
unsigned char *rdptr, unsigned int i2c_data_wait);<br />
Arguments: length Number of bytes to read from I<br />
2<br />
Cdevice.<br />
rdptr Character type pointer to dsPIC ram for storage of data<br />
read from I<br />
2<br />
Cdevice<br />
chức năng thực hiện các chức năng tương tự như MasterputcI2C.<br />
Source File: MasterWriteI2C.c<br />
Mã số Ví dụ: MasterWriteI2C ('a');<br />
NotAckI2C<br />
Mô tả: Tạo ra tôi<br />
2<br />
Cbus Không Thừa nhận điều kiện.<br />
Bao gồm: i2c.h<br />
Prototype: void NotAckI2C (void);<br />
Lập luận: Không<br />
Trở lại giá trị Không<br />
Bình luận: Chức năng này tạo ra một tôi<br />
2<br />
Cbus Không Thừa nhận điều kiện.<br />
Source File: NotAckI2C.c<br />
Mã số Ví dụ: NotAckI2C ();<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 187<br />
OpenI2C<br />
Mô tả: Cấu hình tôi<br />
2<br />
Cmodule.<br />
Bao gồm: i2c.h<br />
Prototype: void OpenI2C (int config1, int<br />
config2);<br />
Đối số: config1 này chứa các tham số cấu hình I2CCON<br />
đăng ký<br />
Tôi<br />
2<br />
Bit CEnable<br />
I2C_ON<br />
I2C_OFF<br />
Tôi<br />
2<br />
CStop trong chế độ nhàn rỗi bit<br />
I2C_IDLE_STOP<br />
I2C_IDLE_CON<br />
SCL phát hành kiểm soát bit<br />
I2C_CLK_REL
i2c_data_wait This is the timeout count for which the module has<br />
to wait before return.<br />
If the timeout count is ‘N’, the actual timeout would<br />
be about (20*N - 1) instruction cycles.<br />
Return Value This function returns ‘0’ if all bytes have been sent or number of<br />
bytes<br />
read from I<br />
2<br />
Cbus if its not able to read the data with in the specified<br />
i2c_data_waittime out value<br />
Remarks: This routine reads a predefined data string from the I<br />
2<br />
Cbus.<br />
Source File: MastergetsI2C.c<br />
Code Example: unsigned char string[10];<br />
unsigned char *rdptr;<br />
unsigned int length,i2c_data_wait;<br />
length = 9;<br />
rdptr = string;<br />
i2c_data_wait = 152;<br />
MastergetsI2C(length, rdptr, i2c_data_wait);<br />
MasterputsI2C<br />
Description: This function is used to write out a data string to the I<br />
2<br />
Cbus.<br />
Include: i2c.h<br />
Prototype: unsigned int MasterputsI2C(unsigned char *wrptr);<br />
Arguments: wrptr Character type pointer to data objects in dsPIC Ram. The<br />
data objects are written to the I<br />
2<br />
Cdevice.<br />
Return Value This function returns -3 if a write collision occurred.This function<br />
returns<br />
‘0’ if the null character was reached in data string.<br />
Remarks: This function writes a string to the I<br />
2<br />
Cbus until a null character is<br />
reached. Each byte is written via a call to the MasterputcI2C<br />
function. The actual calledfunction body is termed MasterWriteI2C.<br />
MasterWriteI2Cand MasterputcI2Crefer to the same function via<br />
I2C_CLK_HLD<br />
Giao diện quản lý thông minh ngoại vi Enable bit<br />
I2C_IPMI_EN<br />
I2C_IPMI_DIS<br />
10-bit Slave Địa chỉ bit<br />
I2C_10BIT_ADD<br />
I2C_7BIT_ADD<br />
Vô hiệu hóa xoay Tỷ lệ kiểm soát bit<br />
I2C_SLW_DIS<br />
I2C_SLW_EN<br />
SMBus bit Cấp độ đầu vào<br />
I2C_SM_EN<br />
I2C_SM_DIS<br />
Gọi chung Enable bit<br />
I2C_GCALL_EN<br />
I2C_GCALL_DIS<br />
SCL đồng hồ căng Enable bit<br />
I2C_STR_EN<br />
I2C_STR_DIS<br />
Thừa nhận bit dữ liệu<br />
I2C_ACK<br />
I2C_NACK<br />
Thừa nhận trình tự Enable bit<br />
I2C_ACK_EN<br />
I2C_ACK_DIS<br />
Nhận Kích hoạt bit<br />
I2C_RCV_EN<br />
I2C_RCV_DIS<br />
Dừng Điều kiện Enable bit<br />
I2C_STOP_EN<br />
I2C_STOP_DIS<br />
Bắt đầu lặp đi lặp lại Điều kiện Enable bit<br />
I2C_RESTART_EN<br />
I2C_RESTART_DIS<br />
Điều kiện bắt đầu Enable bit<br />
I2C_START_EN<br />
I2C_START_DIS<br />
config2 trị giá tính toán cho máy phát điện tốc độ truyền<br />
dsPIC
a #definestatement in the i2c.h<br />
Source File: MasterputsI2C.c<br />
Code Example: unsigned char string[] = “ MICROCHIP ”;<br />
unsigned char *wrptr;<br />
wrptr = string;<br />
MasterputsI2C( wrptr);<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 186<br />
MasterReadI2C<br />
2004 Microchip Technology Inc.<br />
Description: This function is used to read a single byte from I<br />
2<br />
Cbus<br />
Include: i2c.h<br />
Prototype: unsigned char MasterReadI2C(void);<br />
Arguments: None<br />
Return Value The return value is the data byte read from the I<br />
2<br />
Cbus.<br />
Remarks: This function reads in a single byte from the I<br />
2<br />
Cbus.<br />
This function performs the same function as MastergetcI2C.<br />
Source File: MasterReadI2C.c<br />
Code Example: unsigned char value;<br />
value = MasterReadI2C();<br />
MasterWriteI2C<br />
Description: This function is used to write out a single data byte to the I<br />
2<br />
Cdevice.<br />
Include: i2c.h<br />
Prototype: unsigned char MasterWriteI2C(unsigned char<br />
data_out);<br />
Arguments: data_out A single data byte to be written to the I<br />
2<br />
Cbus device.<br />
Return Value This function returns -1 if there was a write collision else it<br />
returns a 0.<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 188 2004 Microchip Technology Inc<br />
Trở lại giá trị Không<br />
Bình luận: Chức năng này cấu hình tôi<br />
2<br />
CControl đăng ký và tôi<br />
2<br />
CBaud Rate<br />
Máy phát điện đăng ký.<br />
Source File: OpenI2C.c<br />
Mã số Ví dụ: OpenI2C ();<br />
RestartI2C<br />
Mô tả: Tạo ra tôi<br />
2<br />
CBUs Khởi động lại điều kiện.<br />
Bao gồm: i2c.h<br />
Prototype: void RestartI2C (void);<br />
Lập luận: Không<br />
Trở lại giá trị Không<br />
Bình luận: Chức năng này tạo ra một tôi<br />
2<br />
CBUs Khởi động lại điều kiện.<br />
Source File: RestartI2C.c<br />
Mã số Ví dụ: RestartI2C ();<br />
SlavegetsI2C<br />
Mô tả: Chức năng này lần đọc chuỗi dài trước determineddata từ I<br />
2<br />
Cbus.<br />
Bao gồm: i2c.h<br />
Nguyên mẫu: int SlavegetsI2C (unsigned char * rdptr,<br />
int i2c_data_wait);<br />
Đối số: rdptr loại nhân vật con trỏ tới dsPIC ram cho lưu trữ dữ liệu đọc<br />
từ I<br />
2<br />
Cdevice<br />
i2c_data_wait Đây là số thời gian chờ cho các mô-đun có<br />
chờ đợi trước khi trở về.<br />
Nếu tính thời gian chờ là 'N', thời gian chờ thực tế sẽ
Remarks: This function writes out a single data byte to the I<br />
2<br />
Cbus device. This<br />
function performs the same function as MasterputcI2C.<br />
Source File: MasterWriteI2C.c<br />
Code Example: MasterWriteI2C(‘a’);<br />
NotAckI2C<br />
Description: Generates I<br />
2<br />
Cbus Not Acknowledge condition.<br />
Include: i2c.h<br />
Prototype: void NotAckI2C(void);<br />
Arguments: None<br />
Return Value None<br />
Remarks: This function generates an I<br />
2<br />
Cbus Not Acknowledge condition.<br />
Source File: NotAckI2C.c<br />
Code Example: NotAckI2C();<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 187<br />
OpenI2C<br />
Description: Configures the I<br />
2<br />
Cmodule.<br />
Include: i2c.h<br />
Prototype: void OpenI2C(unsigned int config1, unsigned int<br />
config2);<br />
Arguments: config1 This contains the parameter to configure the I2CCON<br />
register<br />
I<br />
2<br />
CEnable bit<br />
I2C_ON<br />
I2C_OFF<br />
I<br />
2<br />
CStop in Idle Mode bit<br />
I2C_IDLE_STOP<br />
khoảng (20 * N - 1) chu kỳ hướng dẫn.<br />
Trở lại giá trị Trả về số byte nhận được từ tôi<br />
2<br />
Cbus.<br />
Bình luận: thói quen này đọc một chuỗi dữ liệu được xác định trước từ I<br />
2<br />
Cbus.<br />
Source File: SlavegetsI2C.c<br />
Mã số Ví dụ: unsigned char string [12];<br />
unsigned char * rdptr;<br />
rdptr = chuỗi;<br />
i2c_data_out = 0x11;<br />
SlavegetsI2C (rdptr, i2c_data_wait);<br />
OpenI2C (Tiếp theo)<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 189<br />
SlaveputsI2C<br />
Mô tả: Chức năng này được sử dụng để viết ra một chuỗi dữ liệu cho tôi<br />
2<br />
Cbus.<br />
Bao gồm: i2c.h<br />
Nguyên mẫu: int SlaveputsI2C (unsigned char * wrptr);<br />
Đối số: wrptr loại nhân vật con trỏ đến các đối tượng dữ liệu trong dsPIC<br />
ram. Các<br />
đối tượng dữ liệu được ghi vào tôi<br />
2<br />
Cdevice.<br />
Giá trị trả lại chức năng này trả về "0" nếu nullcharacter đã đạt được trong các<br />
dữ liệu<br />
chuỗi.<br />
Bình luận: thói quen này ghi một chuỗi dữ liệu ra cho tôi<br />
2<br />
Cbus cho đến khi một ký tự null<br />
đạt được.<br />
Source File: SlaveputsI2C.c<br />
Mã số Ví dụ: unsigned char string [] = "vi mạch";<br />
unsigned char * rdptr;<br />
rdptr = chuỗi;<br />
SlaveputsI2C (rdptr);<br />
SlaveReadI2C
I2C_IDLE_CON<br />
SCL Release Control bit<br />
I2C_CLK_REL<br />
I2C_CLK_HLD<br />
Intelligent Peripheral Management Interface Enable bit<br />
I2C_IPMI_EN<br />
I2C_IPMI_DIS<br />
10-bit Slave Address bit<br />
I2C_10BIT_ADD<br />
I2C_7BIT_ADD<br />
Disable Slew Rate Control bit<br />
I2C_SLW_DIS<br />
I2C_SLW_EN<br />
SMBus Input Level bits<br />
I2C_SM_EN<br />
I2C_SM_DIS<br />
General Call Enable bit<br />
I2C_GCALL_EN<br />
I2C_GCALL_DIS<br />
SCL Clock Stretch Enable bit<br />
I2C_STR_EN<br />
I2C_STR_DIS<br />
Acknowledge Data bit<br />
I2C_ACK<br />
I2C_NACK<br />
Acknowledge Sequence Enable bit<br />
I2C_ACK_EN<br />
I2C_ACK_DIS<br />
Receive Enable bit<br />
I2C_RCV_EN<br />
I2C_RCV_DIS<br />
Stop Condition Enable bit<br />
I2C_STOP_EN<br />
I2C_STOP_DIS<br />
Repeated Start Condition Enable bit<br />
I2C_RESTART_EN<br />
I2C_RESTART_DIS<br />
Start Condition Enable bit<br />
I2C_START_EN<br />
Mô tả: Chức năng này được sử dụng để đọc một byte duy nhất từ tôi<br />
2<br />
Cbus.<br />
Bao gồm: i2c.h<br />
Prototype: unsigned char SlaveReadI2C (void);<br />
Lập luận: Không<br />
Quay trở lại Giá trị Giá trị trả về là các byte dữ liệu đọc từ tôi<br />
2<br />
Cbus.<br />
Bình luận: Chức năng này lần đọc trong một byte duy nhất từ tôi<br />
2<br />
Cbus. Chức năng này<br />
thực hiện chức năng tương tự như SlavegetcI2C.<br />
Source File: SlaveReadI2C.c<br />
Mã số Ví dụ: giá trị unsigned char;<br />
giá trị = SlaveReadI2C ();<br />
SlaveWriteI2C<br />
Mô tả: Chức năng này được sử dụng để viết ra một byte duy nhất để tôi<br />
2<br />
Cbus.<br />
Bao gồm: i2c.h<br />
Prototype: void SlaveWriteI2C (unsigned char data_out);<br />
Đối số: data_out Một byte dữ liệu duy nhất để được ghi vào tôi<br />
2<br />
Thiết bị Cbus.<br />
Trở lại giá trị Không<br />
Ghi chú: Chức năng này viết ra một byte dữ liệu duy nhất cho tôi<br />
2<br />
Thiết bị Cbus. Điều này<br />
chức năng thực hiện các chức năng tương tự như SlaveputcI2C.<br />
Source File: SlaveWriteI2C.c<br />
Mã số Ví dụ: SlaveWriteI2C ('a');<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 190 2004 Microchip Technology Inc<br />
3.17.2 Macros cá nhân<br />
StartI2C<br />
Mô tả: Tạo ra tôi
I2C_START_DIS<br />
config2 computed value for the baud rate generator<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 188 2004 Microchip Technology Inc.<br />
Return Value None<br />
Remarks: This function configures the I<br />
2<br />
CControl register and I<br />
2<br />
CBaud Rate<br />
Generator register.<br />
Source File: OpenI2C.c<br />
Code Example: OpenI2C();<br />
RestartI2C<br />
Description: Generates I<br />
2<br />
CBus Restart condition.<br />
Include: i2c.h<br />
Prototype: void RestartI2C(void);<br />
Arguments: None<br />
Return Value None<br />
Remarks: This function generates an I<br />
2<br />
CBus Restart condition.<br />
Source File: RestartI2C.c<br />
Code Example: RestartI2C();<br />
SlavegetsI2C<br />
Description: This function reads pre-determineddata string length from the I<br />
2<br />
Cbus.<br />
Include: i2c.h<br />
Prototype: unsigned int SlavegetsI2C(unsigned char *rdptr,<br />
unsigned int i2c_data_wait);<br />
Arguments: rdptr Character type pointer to dsPIC ram for storage of data read<br />
from I<br />
2<br />
Cdevice<br />
2<br />
CBUs Bắt đầu điều kiện.<br />
Bao gồm: i2c.h<br />
Prototype: void StartI2C (void);<br />
Lập luận: Không<br />
Trở lại giá trị Không<br />
Bình luận: Chức năng này tạo ra một tôi<br />
2<br />
CBUs Bắt đầu điều kiện.<br />
Source File: StartI2C.c<br />
Mã số Ví dụ: StartI2C ();<br />
StopI2C<br />
Mô tả: Tạo ra tôi<br />
2<br />
CBUs Dừng điều kiện.<br />
Bao gồm: i2c.h<br />
Prototype: void StopI2C (void);<br />
Lập luận: Không<br />
Trở lại giá trị Không<br />
Bình luận: Chức năng này tạo ra một tôi<br />
2<br />
CBUs Dừng điều kiện.<br />
Source File: StopI2C.c<br />
Mã số Ví dụ: StopI2C ();<br />
EnableIntMI2C<br />
Mô tả: vĩ mô này cho phép chủ tôi<br />
2<br />
Cinterrupt.<br />
Bao gồm: i2c.h<br />
Lập luận: Không<br />
Bình luận: vĩ mô này đặt Thầy tôi<br />
2<br />
Bit CEnable của Interrupt Enable kiểm soát<br />
đăng ký.<br />
Mã số Ví dụ: EnableIntMI2C;<br />
DisableIntMI2C<br />
Mô tả: vĩ mô này vô hiệu hóa các chủ tôi<br />
2<br />
Cinterrupt.
i2c_data_wait This is the timeout count for which the module has<br />
to wait before return.<br />
If the timeout count is ‘N’, the actual timeout would<br />
be about (20*N - 1) instruction cycles.<br />
Return Value Returns the number of bytes received from the I<br />
2<br />
Cbus.<br />
Remarks: This routine reads a predefined data string from the I<br />
2<br />
Cbus.<br />
Source File: SlavegetsI2C.c<br />
Code Example: unsigned char string[12];<br />
unsigned char *rdptr;<br />
rdptr = string;<br />
i2c_data_out = 0x11;<br />
SlavegetsI2C(rdptr, i2c_data_wait);<br />
OpenI2C (Continued)<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 189<br />
SlaveputsI2C<br />
Description: This function is used to write out a data string to the I<br />
2<br />
Cbus.<br />
Include: i2c.h<br />
Prototype: unsigned int SlaveputsI2C(unsigned char *wrptr);<br />
Arguments: wrptr Character type pointer to data objects in dsPIC ram. The<br />
data objects are written to the I<br />
2<br />
Cdevice.<br />
Return Value This function returns ‘0’ if the nullcharacter was reached in the<br />
data<br />
string.<br />
Remarks: This routine writes a data string out to the I<br />
2<br />
Cbus until a null character<br />
is reached.<br />
Source File: SlaveputsI2C.c<br />
Code Example: unsigned char string[] =”MICROCHIP”;<br />
unsigned char *rdptr;<br />
Bao gồm: i2c.h<br />
Lập luận: Không<br />
Bình luận: vĩ mô này xóa Thầy tôi<br />
2<br />
CInterrupt Enable chút ngắt Kích hoạt<br />
Kiểm soát đăng ký.<br />
Mã số Ví dụ: DisableIntMI2C;<br />
dsPIC Thư viện ngoại vi<br />
2004 Microchip Technology Inc DS51456B trang 191<br />
SetPriorityIntMI2C<br />
Mô tả: Điều này đặt ra ưu tiên vĩ mô cho chủ tôi<br />
2<br />
Cinterrupt.<br />
Bao gồm: i2c.h<br />
Đối số: ưu tiên<br />
Bình luận: vĩ mô này đặt Thầy tôi<br />
2<br />
CInterrupt bit ưu tiên của ưu tiên ngắt<br />
Kiểm soát đăng ký.<br />
Mã số Ví dụ: SetPriorityIntMI2C (1);<br />
EnableIntSI2C<br />
Mô tả: vĩ mô Điều này cho phép các nô lệ tôi<br />
2<br />
Cinterrupt.<br />
Bao gồm: i2c.h<br />
Lập luận: Không<br />
Bình luận: vĩ mô này đặt Slave tôi<br />
2<br />
Bit CEnable của Interrupt Enable kiểm soát<br />
đăng ký.<br />
Mã số Ví dụ: EnableIntSI2C;<br />
DisableIntSI2C<br />
Mô tả: vĩ mô này vô hiệu hóa các nô lệ tôi<br />
2<br />
Cinterrupt.<br />
Bao gồm: i2c.h<br />
Lập luận: Không<br />
Bình luận: vĩ mô này xóa Slave tôi<br />
2
dptr = string;<br />
SlaveputsI2C(rdptr);<br />
SlaveReadI2C<br />
Description: This function is used to read a single byte from the I<br />
2<br />
Cbus.<br />
Include: i2c.h<br />
Prototype: unsigned char SlaveReadI2C(void);<br />
Arguments: None<br />
Return Value The return value is the data byte read from the I<br />
2<br />
Cbus.<br />
Remarks: This function reads in a single byte from the I<br />
2<br />
Cbus. This function<br />
performs the same function as SlavegetcI2C.<br />
Source File: SlaveReadI2C.c<br />
Code Example: unsigned char value;<br />
value = SlaveReadI2C();<br />
SlaveWriteI2C<br />
Description: This function is used to write out a single byte to the I<br />
2<br />
Cbus.<br />
Include: i2c.h<br />
Prototype: void SlaveWriteI2C(unsigned char data_out);<br />
Arguments: data_out A single data byte to be written to the I<br />
2<br />
Cbus device.<br />
Return Value None<br />
Remarks: This function writes out a single data byte to the I<br />
2<br />
Cbus device. This<br />
function performs the same function as SlaveputcI2C.<br />
Source File: SlaveWriteI2C.c<br />
Code Example: SlaveWriteI2C(‘a’);<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 190 2004 Microchip Technology Inc.<br />
CInterrupt Enable chút ngắt Kích hoạt<br />
Kiểm soát đăng ký.<br />
Mã số Ví dụ: DisableIntSI2C;<br />
SetPriorityIntSI2C<br />
Mô tả: Điều này đặt ra ưu tiên vĩ mô cho chủ tôi<br />
2<br />
Cinterrupt.<br />
Bao gồm: i2c.h<br />
Đối số: ưu tiên<br />
Bình luận: vĩ mô này đặt Thầy tôi<br />
2<br />
CInterrupt bit ưu tiên của ưu tiên ngắt<br />
Kiểm soát đăng ký.<br />
Mã số Ví dụ: SetPriorityIntSI2C (4);<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 192 2004 Microchip Technology Inc<br />
3.17.3 Ví dụ sử dụng<br />
# xác định __dsPIC30F6014__<br />
# include<br />
# include<br />
void main (void)<br />
{<br />
int config2, config1;<br />
unsigned char * wrptr;<br />
unsigned char tx_data [] =<br />
{'M', 'tôi', 'C', 'R', 'O', 'C', 'H', 'tôi', 'P', '\ 0'};<br />
wrptr = tx_data;<br />
/ * Tốc độ truyền được thiết lập cho 100 Khz * /<br />
config2 = 0x11;<br />
/ * Cấu hình I2C cho chế độ địa chỉ 7 bit * /<br />
config1 = (I2C_ON & I2C_IDLE_CON & I2C_CLK_HLD<br />
& I2C_IPMI_DIS & I2C_7BIT_ADD<br />
& I2C_SLW_DIS & I2C_SM_DIS &<br />
I2C_GCALL_DIS & I2C_STR_DIS &<br />
I2C_NACK & I2C_ACK_DIS & I2C_RCV_DIS &<br />
I2C_STOP_DIS & I2C_RESTART_DIS<br />
& I2C_START_DIS);
3.17.2 Individual Macros<br />
StartI2C<br />
Description: Generates I<br />
2<br />
CBus Start condition.<br />
Include: i2c.h<br />
Prototype: void StartI2C(void);<br />
Arguments: None<br />
Return Value None<br />
Remarks: This function generates a I<br />
2<br />
CBus Start condition.<br />
Source File: StartI2C.c<br />
Code Example: StartI2C();<br />
StopI2C<br />
Description: Generates I<br />
2<br />
CBus Stop condition.<br />
Include: i2c.h<br />
Prototype: void StopI2C(void);<br />
Arguments: None<br />
Return Value None<br />
Remarks: This function generates a I<br />
2<br />
CBus Stop condition.<br />
Source File: StopI2C.c<br />
Code Example: StopI2C();<br />
EnableIntMI2C<br />
Description: This macro enables the master I<br />
2<br />
Cinterrupt.<br />
Include: i2c.h<br />
Arguments: None<br />
Remarks: This macro sets Master I<br />
2<br />
CEnable bit of Interrupt Enable Control<br />
register.<br />
Code Example: EnableIntMI2C;<br />
DisableIntMI2C<br />
OpenI2C (config1, config2);<br />
IdleI2C ();<br />
StartI2C ();<br />
/ * Chờ cho đến khi bắt đầu trình tự hoàn thành * /<br />
trong khi (I2CCONbits.SEN);<br />
/ * Viết Slave địa chỉ và thiết lập tổng thể cho truyền * /<br />
MasterWriteI2C (0xE);<br />
/ * Chờ cho đến khi địa chỉ được truyền * /<br />
trong khi (I2CSTATbits.TBF);<br />
trong khi (I2CSTATbits.ACKSTAT);<br />
/ * Chuỗi Truyền dữ liệu * /<br />
MasterputsI2C (wrptr);<br />
StopI2C ();<br />
/ * Chờ cho đến khi dừng lại trình tự hoàn thành * /<br />
trong khi (I2CCONbits.PEN);<br />
CloseI2C ();<br />
}<br />
dsPIC<br />
®LANGUAGE CÔNG CỤ<br />
THƯ VIỆN<br />
2004 Microchip Technology Inc DS51456B trang 193<br />
Chương 4 Thư viện chuẩn C với các hàm toán<br />
4.1 GIỚI THIỆU<br />
Chức năng thư viện chuẩn ANSI C được chứa trong các thư viện libc-omf.aand<br />
libm-omf.a (chức năng toán học), trong đó có omfwill coffor elfdepending trên<br />
lựa chọn đối tượng định dạng mô-đun.<br />
Ngoài ra, một số tiêu chuẩn dsPIC chức năng trợ giúp thư viện C, và các chức<br />
năng tiêu chuẩn<br />
đó phải được sửa đổi để sử dụng với các thiết bị dsPIC, đang ở trong thư viện<br />
libpic30-omf.a.<br />
4.1.1 ứng dụng Mã hội<br />
Một phiên bản miễn phí của các hàm toán học thư viện và phần đầu tập tin có<br />
sẵn từ các trang web của Microchip. Không có mã nguồn có sẵn với phiên bản<br />
miễn phí này.<br />
4.1.2 ứng dụng C Mã<br />
Trình biên dịch MPLAB C30 C thư mục cài đặt (C: \ pic30_tools) chứa các<br />
thư mục con với các tập tin thư viện liên quan sau đây:<br />
• Tiêu chuẩn lib- tập tin thư viện C<br />
• src \ libm- mã nguồn cho các chức năng thư viện toán học, tập tin thực thi để<br />
xây dựng lại thư viện<br />
• tập tin tiêu đề hỗ trợ \ h- cho các thư viện<br />
4.1.3 Tổ chức Chương
Description: This macro disables the master I<br />
2<br />
Cinterrupt.<br />
Include: i2c.h<br />
Arguments: None<br />
Remarks: This macro clears Master I<br />
2<br />
CInterrupt Enable bit of Interrupt Enable<br />
Control register.<br />
Code Example: DisableIntMI2C;<br />
dsPIC Peripheral Libraries<br />
2004 Microchip Technology Inc. DS51456B-page 191<br />
SetPriorityIntMI2C<br />
Description: This macro sets priority for master I<br />
2<br />
Cinterrupt.<br />
Include: i2c.h<br />
Arguments: priority<br />
Remarks: This macro sets Master I<br />
2<br />
CInterrupt Priority bits of Interrupt Priority<br />
Control register.<br />
Code Example: SetPriorityIntMI2C(1);<br />
EnableIntSI2C<br />
Description: This macro enables the slave I<br />
2<br />
Cinterrupt.<br />
Include: i2c.h<br />
Arguments: None<br />
Remarks: This macro sets Slave I<br />
2<br />
CEnable bit of Interrupt Enable Control<br />
register.<br />
Code Example: EnableIntSI2C;<br />
DisableIntSI2C<br />
Description: This macro disables the slave I<br />
2<br />
Cinterrupt.<br />
Include: i2c.h<br />
Chương này được tổ chức như sau:<br />
• Sử dụng thư viện chuẩn C<br />
libc-omf.a<br />
• chẩn đoán<br />
• xử lý nhân vật<br />
• lỗi<br />
• đặc điểm nổi<br />
• giới hạn thực hiện xác định<br />
• nội địa hóa<br />
• nhảy không địa phương<br />
• xử lý tín hiệu<br />
• danh sách đối số biến<br />
• định nghĩa chung<br />
• đầu vào và đầu ra<br />
• chức năng tiện ích<br />
• chức năng chuỗi<br />
• ngày và thời gian chức năng<br />
libm-omf.a<br />
• chức năng toán học<br />
libpic30-omf.a<br />
• pic30-libs<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 194<br />
2004 Microchip Technology Inc<br />
4.2 SỬ DỤNG THƯ VIỆN TIÊU CHUẨN C<br />
Xây dựng một ứng dụng mà sử dụng các tiêu chuẩn thư viện C yêu cầu hai loại<br />
tập tin:<br />
tập tin tiêu đề và các tập tin thư viện.<br />
4.2.1 Tiêu đề tin<br />
Tất cả các tổ chức tiêu chuẩn thư viện C được khai báo hoặc quy định tại một<br />
hoặc nhiều tiêu đề tiêu chuẩn<br />
(Xem danh sách tại mục 4.1.3 "Chương Tổ chức".) Để sử dụng một thực thể<br />
trong thư viện<br />
một chương trình, viết một chỉ thị bao gồm có tên tiêu đề tiêu chuẩn có liên<br />
quan.<br />
Nội dung của một tiêu đề tiêu chuẩn được bao gồm bằng cách đặt tên nó trong<br />
một chỉ thị bao gồm, như trong:<br />
# include / * Bao gồm I / O cơ sở * /<br />
Các tiêu đề tiêu chuẩn có thể được bao gồm trong bất kỳ thứ tự. Không bao gồm<br />
tiêu đề chuẩn<br />
trong một tuyên bố. Không định nghĩa macro có cùng tên với từ khóa
Arguments: None<br />
Remarks: This macro clears Slave I<br />
2<br />
CInterrupt Enable bit of Interrupt Enable<br />
Control register.<br />
Code Example: DisableIntSI2C;<br />
SetPriorityIntSI2C<br />
Description: This macro sets priority for master I<br />
2<br />
Cinterrupt.<br />
Include: i2c.h<br />
Arguments: priority<br />
Remarks: This macro sets Master I<br />
2<br />
CInterrupt Priority bits of Interrupt Priority<br />
Control register.<br />
Code Example: SetPriorityIntSI2C(4);<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
trước khi bao gồm một tiêu đề chuẩn.<br />
Một tiêu đề tiêu chuẩn không bao giờ bao gồm một tiêu đề chuẩn.<br />
4.2.2 Thư viện tập tin<br />
Các tập tin thư viện lưu trữ chứa tất cả các đối tượng tập tin cá nhân cho mỗi<br />
chức năng thư viện.<br />
Khi kết nối một ứng dụng, tập tin thư viện phải được cung cấp như một đầu vào<br />
để mối liên kết<br />
(Bằng cách sử dụng tùy chọn -llinker --libraryor) như vậy mà các chức năng<br />
được sử dụng bởi<br />
ứng dụng có thể được kết nối vào ứng dụng.<br />
Một ứng dụng điển hình C sẽ yêu cầu ba tập tin thư viện: libc-omf.a, libmomf.a,<br />
và<br />
libpic30-omf.a. (Xem phần 1.2 "OMF-cụ thể thư viện / khởi động mô-đun"<br />
để biết thêm về thư viện OMF cụ thể.) Các thư viện này sẽ được bao gồm tự<br />
động nếu<br />
liên kết được thực hiện bằng cách sử dụng trình biên dịch MPLAB C30.<br />
Lưu ý: Một số chức năng thư viện chuẩn đòi hỏi một đống. Chúng bao gồm các<br />
tiêu chuẩn<br />
I / O chức năng mở các tập tin và các chức năng cấp phát bộ nhớ. Xem<br />
MPLAB ASM30, MPLAB LINK30 và Guideand MPLAB tiện ích của người sử<br />
dụng<br />
C30 C Compiler của người sử dụng Guidefor thêm thông tin về đống.<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 195<br />
DS51456B-page 192<br />
2004 Microchip Technology Inc.<br />
4.3 DIAGNOSTICS<br />
3.17.3 Example of Use<br />
#define __dsPIC30F6014__<br />
#include <br />
#include<br />
void main(void )<br />
{<br />
unsigned int config2, config1;<br />
unsigned char *wrptr;<br />
unsigned char tx_data[] =<br />
{'M','I','C','R','O',’C’,'H','I','P','\0'};<br />
wrptr = tx_data;<br />
/* Baud rate is set for 100 Khz */<br />
config2 = 0x11;<br />
/* Configure I2C for 7 bit address mode */<br />
config1 = (I2C_ON & I2C_IDLE_CON & I2C_CLK_HLD<br />
& I2C_IPMI_DIS & I2C_7BIT_ADD<br />
& I2C_SLW_DIS & I2C_SM_DIS &<br />
I2C_GCALL_DIS & I2C_STR_DIS &<br />
Các assert.hconsists tập tin tiêu đề của một vĩ mô duy nhất đó là hữu ích để gỡ<br />
lỗi lôgic<br />
sai sót trong chương trình. Bằng cách sử dụng các tuyên bố khẳng định tại các<br />
địa điểm quan trọng, nơi nhất định<br />
điều kiện phải được sự thật, logic của chương trình có thể được kiểm tra.<br />
Kiểm tra khẳng định có thể được tắt mà không loại bỏ các mã bằng cách định<br />
nghĩa NDEBUG<br />
trước khi bao gồm . Nếu NDEBUGis vĩ mô được xác định, khẳng định () bị bỏ<br />
qua<br />
và không có mã số được tạo ra.<br />
khẳng định<br />
Mô tả: Nếu biểu thức là sai, một thông báo khẳng định được in vào thiết bị lỗi<br />
chuẩn và<br />
chương trình được hủy bỏ.<br />
Bao gồm:<br />
Prototype: void khẳng định (int biểu thức);<br />
Đối số: biểu Các biểu hiện để kiểm tra.<br />
Ghi chú: Các biểu thức ước lượng không ornon-không. Nếu không, sự khẳng<br />
định<br />
không thành công, và một tin nhắn được in tostderr. Thông điệp bao gồm các<br />
tên tập tin nguồn (__FILE__), số dòng mã nguồn (__LINE__), các
I2C_NACK & I2C_ACK_DIS& I2C_RCV_DIS &<br />
I2C_STOP_DIS & I2C_RESTART_DIS<br />
& I2C_START_DIS);<br />
OpenI2C(config1,config2);<br />
IdleI2C();<br />
StartI2C();<br />
/* Wait till Start sequence is completed */<br />
while(I2CCONbits.SEN );<br />
/* Write Slave address and set master for transmission */<br />
MasterWriteI2C(0xE);<br />
/* Wait till address is transmitted */<br />
while(I2CSTATbits.TBF);<br />
while(I2CSTATbits.ACKSTAT);<br />
/* Transmit string of data */<br />
MasterputsI2C(wrptr);<br />
StopI2C();<br />
/* Wait till stop sequence is completed */<br />
while(I2CCONbits.PEN);<br />
CloseI2C();<br />
}<br />
dsPIC<br />
®LANGUAGE TOOLS<br />
biểu hiện được đánh giá và tin nhắn. Vĩ mô sau đó gọi<br />
chức năng hủy bỏ (). Nếu _VERBOSE_DEBUGGINGis vĩ mô được xác định,<br />
một<br />
thông báo sẽ được in để thiết bị lỗi chuẩn mỗi lần khẳng định () được gọi.<br />
Ví dụ: # include / * Để khẳng định * /<br />
int main (void)<br />
{<br />
int a;<br />
a = 2 * 2;<br />
khẳng định (a == 4); / * Nếu bản in thật không có gì * /<br />
khẳng định (a == 6); / * Nếu tin nhắn giả in * /<br />
/ * Và hủy bỏ * /<br />
}<br />
Đầu ra:<br />
sampassert.c: 9 a == 6 --assertion thất bại<br />
ABRT<br />
với _VERBOSE_DEBUGGINGdefined:<br />
sampassert.c: 8 a == 4 - OK<br />
sampassert.c: 9 a == 6 --assertion thất bại<br />
ABRT<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
LIBRARIES<br />
2004 Microchip Technology Inc. DS51456B-page 193<br />
DS51456B trang 196<br />
4.4 NHÂN XỬ LÝ<br />
2004 Microchip Technology Inc<br />
Chapter 4. Standard C Libraries with Math Functions<br />
4.1 INTRODUCTION<br />
Standard ANSI C library functions are contained in the libraries libc-omf.aand<br />
libm-omf.a(math functions), where omfwill be coffor elfdepending upon the<br />
selected object module format.<br />
Additionally, some dsPIC standard C library helper functions, and standard<br />
functions<br />
that must be modified for use with dsPIC devices, are in the library libpic30-<br />
omf.a.<br />
4.1.1 Assembly Code Applications<br />
A free version of the math functions library and header file is available from the<br />
Microchip web site. No source code is available with this free version.<br />
4.1.2 C Code Applications<br />
The MPLAB C30 C compiler install directory (c:\pic30_tools) contains the<br />
following subdirectories with library-related files:<br />
• lib– standard C library files<br />
Các ctype.hconsists tập tin tiêu đề của các chức năng hữu ích cho việc phân loạ<br />
và<br />
lập bản đồ ký tự. Nhân vật được giải thích theo quy định của địa phương chuẩn<br />
C.<br />
isalnum<br />
Mô tả: Kiểm tra cho một nhân vật tự chữ và số.<br />
Bao gồm:<br />
Nguyên mẫu: int isalnum (int c);<br />
Đối số: c Các nhân vật để kiểm tra.<br />
Quay trở lại giá trị: Trả về một số nguyên nhân vật khác không có giá trị ifthe là<br />
chữ số;<br />
nếu không, trả về một số không.<br />
Ghi chú: chữ và số ký tự được bao gồm trong phạm vi AZ, az hoặc 0-9.<br />
Ví dụ: # include / * Cho isalnum * /<br />
# include / * Cho printf * /<br />
int main (void)
• src\libm– source code for math library functions, batch file to rebuild the<br />
library<br />
• support\h– header files for libraries<br />
4.1.3 Chapter Organization<br />
This chapter is organized as follows:<br />
• Using the Standard C Libraries<br />
libc-omf.a<br />
• diagnostics<br />
• character handling<br />
• errors<br />
• floating-point characteristics<br />
• implementation-defined limits<br />
• localization<br />
• non-local jumps<br />
• signal handling<br />
• variable argument lists<br />
• common definitions<br />
• input and output<br />
• utility functions<br />
• string functions<br />
• date and time functions<br />
libm-omf.a<br />
• mathematical functions<br />
libpic30-omf.a<br />
• pic30-libs<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 194<br />
2004 Microchip Technology Inc.<br />
4.2 USING THE STANDARD C LIBRARIES<br />
Building an application which utilizes the standard C libraries requires two<br />
types of files:<br />
header files and library files.<br />
4.2.1 Header Files<br />
All standard C library entities are declared or defined in one or more standard<br />
headers<br />
(See list in Section 4.1.3 “Chapter Organization”.) To make use of a library<br />
entity in<br />
a program, write an include directive that names the relevant standard header.<br />
The contents of a standard header is included by naming it in an include<br />
directive, as in:<br />
{<br />
int ch;<br />
ch = '3';<br />
if (isalnum (ch))<br />
printf ("3 là một chữ \ n");<br />
khác<br />
printf ("3 là chữ số NOTan \ n");<br />
ch = '#';<br />
if (isalnum (ch))<br />
printf ("# là một chữ \ n");<br />
khác<br />
printf ("# là chữ số NOTan \ n");<br />
}<br />
Đầu ra:<br />
3 là một chữ số<br />
# Là không một chữ số<br />
isalpha<br />
Mô tả: Kiểm tra cho một ký tự chữ cái.<br />
Bao gồm:<br />
Nguyên mẫu: int isalpha (int c);<br />
Đối số: c Các nhân vật để kiểm tra.<br />
Quay trở lại giá trị: Trả về một số nguyên nhân vật khác không có giá trị ifthe là<br />
chữ cái;<br />
nếu không, trả về số không.<br />
Ghi chú: ký tự chữ cái được bao gồm trong phạm vi AZ hoặc az.<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 197<br />
Ví dụ: # include / * Cho isalpha * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
int ch;<br />
ch = 'B';<br />
if (isalpha (ch))<br />
printf ("B là chữ cái \ n");<br />
khác<br />
printf ("B isnot chữ cái \ n");<br />
ch = '#';<br />
if (isalpha (ch))<br />
printf ("# là chữ cái \ n");
#include /* include I/O facilities */<br />
The standard headers can be included in any order. Do not include a standard<br />
header<br />
within a declaration. Do not define macros that have the same names as<br />
keywords<br />
before including a standard header.<br />
A standard header never includes another standard header.<br />
4.2.2 Library Files<br />
The archived library files contain all the individual object files for each library<br />
function.<br />
When linking an application, the library file must be provided as an input to the<br />
linker<br />
(using the --libraryor -llinker option) such that the functions used by the<br />
application may be linked into the application.<br />
A typical C application will require three library files: libc-omf.a, libm-omf.a,<br />
and<br />
libpic30-omf.a. (See Section 1.2 “OMF-Specific Libraries/StarTup Modules”<br />
for more on OMF-specific libraries.) These libraries will be included<br />
automatically if<br />
linking is performed using the MPLAB C30 compiler.<br />
Note: Some standard library functions require a heap. These include the<br />
standard<br />
I/O functions that open files and the memory allocation functions. See the<br />
MPLAB ASM30, MPLAB LINK30 and Utilities User’s Guideand MPLAB<br />
C30 C Compiler User’s Guidefor more information on the heap.<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 195<br />
4.3 DIAGNOSTICS<br />
The header file assert.hconsists of a single macro that is useful for debugging<br />
logic<br />
errors in programs. By using the assert statement in critical locations where<br />
certain<br />
conditions should be true, the logic of the program may be tested.<br />
Assertion testing may be turned off without removing the code by defining<br />
NDEBUG<br />
before including . If the macro NDEBUGis defined, assert()is ignored<br />
and no code is generated.<br />
assert<br />
Description: If the expression is false, an assertion message is printed to stderr<br />
and<br />
the program is aborted.<br />
Include: <br />
Prototype: void assert(int expression);<br />
Argument: expression The expression to test.<br />
khác<br />
printf ("# isnot chữ cái \ n");<br />
}<br />
Đầu ra:<br />
B là chữ cái<br />
# Là không chữ cái<br />
iscntrl<br />
Mô tả: Kiểm tra cho một nhân vật điều khiển.<br />
Bao gồm:<br />
Nguyên mẫu: int iscntrl (int c);<br />
Đối số: nhân vật c để kiểm tra.<br />
Quay trở lại giá trị: Trả về một giá trị khác không số nguyên nếu nhân vật là<br />
một nhân vật kiểm soát;<br />
nếu không, trả về số không.<br />
Bình luận: Một nhân vật được coi là một nhân vật kiểm soát nếu giá trị ASCII<br />
của nó là<br />
trong phạm vi 0x00 đến 0x1f bao gồm, hoặc 0x7F.<br />
Ví dụ: # include / * Cho iscntrl * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
char ch;<br />
ch = 'B';<br />
if (iscntrl (ch))<br />
printf ("B là một điều khiển nhân vật \ n");<br />
khác<br />
printf ("B là Nota kiểm soát ký tự \ n");<br />
ch = '\ t';<br />
if (iscntrl (ch))<br />
printf ("Một tab isa ký tự điều khiển \ n");<br />
khác<br />
printf ("Một thẻ là không một nhân vật điều khiển \ n");<br />
}<br />
Đầu ra:<br />
B là không một nhân vật điều khiển<br />
Một thẻ là một nhân vật kiểm soát<br />
isalpha (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ
Remarks: The expression evaluates to zero ornon-zero. If zero, the assertion<br />
fails, and a message is printed tostderr. The message includes the<br />
source file name (__FILE__), the source line number (__LINE__), the<br />
expression being evaluated and the message. The macro then calls the<br />
function abort(). If the macro _VERBOSE_DEBUGGINGis defined, a<br />
message will be printed to stderr each time assert()is called.<br />
Example: #include /* for assert */<br />
int main(void)<br />
{<br />
int a;<br />
a = 2 * 2;<br />
assert(a == 4); /* if true-nothing prints */<br />
assert(a == 6); /*if false-print message */<br />
/* and abort */<br />
}<br />
Output:<br />
sampassert.c:9 a == 6 --assertion failed<br />
ABRT<br />
with _VERBOSE_DEBUGGINGdefined:<br />
sampassert.c:8 a == 4 -- OK<br />
sampassert.c:9 a == 6 --assertion failed<br />
ABRT<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 196<br />
2004 Microchip Technology Inc.<br />
4.4 CHARACTER HANDLING<br />
The header file ctype.hconsists of functions that are useful for classifying and<br />
mapping characters. Characters are interpreted according to the Standard C<br />
locale.<br />
isalnum<br />
Description: Test for an alphanumeric character.<br />
Include: <br />
Prototype: int isalnum(int c);<br />
Argument: c The character to test.<br />
Return Value: Returns a non-zero integer value ifthe character is alphanumeric;<br />
otherwise, returns a zero.<br />
Remarks: Alphanumeric characters are included within the ranges A-Z, a-z or 0-<br />
9.<br />
Example: #include /*for isalnum */<br />
DS51456B trang 198<br />
isdigit<br />
2004 Microchip Technology Inc<br />
Mô tả: Kiểm tra trong một chữ số thập phân.<br />
Bao gồm:<br />
Nguyên mẫu: int isdigit (int c);<br />
Đối số: nhân vật c để kiểm tra.<br />
Quay trở lại giá trị: Trả về một giá trị khác không số nguyên nếu nhân vật này l<br />
một chữ số; nếu không,<br />
lợi nhuận bằng không.<br />
Bình luận: Một nhân vật được coi là một nhân vật nếu nó là chữ số trong phạm<br />
vi<br />
"0" - "9".<br />
Ví dụ: # include / * Cho isdigit * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
int ch;<br />
ch = '3';<br />
if (isdigit (ch))<br />
printf ("3 là một chữ số \ n");<br />
khác<br />
printf ("3 là không một chữ số \ n");<br />
ch = '#';<br />
if (isdigit (ch))<br />
printf ("# là một chữ số \ n");<br />
khác<br />
printf ("# là không một chữ số \ n");<br />
}<br />
Đầu ra:<br />
3 là một chữ số<br />
# Là không một chữ số<br />
isgraph<br />
Mô tả: Kiểm tra cho một nhân vật đồ họa.<br />
Bao gồm:<br />
Nguyên mẫu: int isgraph (int c);<br />
Đối số: nhân vật c để kiểm tra<br />
Quay trở lại giá trị: Trả về một số nguyên nhân vật khác không có giá trị ifthe là<br />
một đồ họa<br />
nhân vật; nếu không, trả về số không.<br />
Bình luận: Một nhân vật được coi là một nhân vật đồ họa nếu nó là bất kỳ<br />
nhân vật có thể in được, ngoại trừ một không gian.
#include /* for printf */<br />
int main(void)<br />
{<br />
int ch;<br />
ch = '3';<br />
if (isalnum(ch))<br />
printf("3 is an alphanumeric\n");<br />
else<br />
printf("3 is NOTan alphanumeric\n");<br />
ch = '#';<br />
if (isalnum(ch))<br />
printf("# is an alphanumeric\n");<br />
else<br />
printf("# is NOTan alphanumeric\n");<br />
}<br />
Output:<br />
3 is an alphanumeric<br />
# is NOT an alphanumeric<br />
isalpha<br />
Description: Test for an alphabetic character.<br />
Include: <br />
Prototype: int isalpha(int c);<br />
Argument: c The character to test.<br />
Return Value: Returns a non-zero integer value ifthe character is alphabetic;<br />
otherwise, returns zero.<br />
Remarks: Alphabetic characters are included within the ranges A-Z or a-z.<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 197<br />
Example: #include /*for isalpha */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
int ch;<br />
ch = 'B';<br />
if (isalpha(ch))<br />
printf("B is alphabetic\n");<br />
else<br />
printf("B isNOT alphabetic\n");<br />
ch = '#';<br />
Ví dụ: # include / * Cho isgraph * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
int ch;<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 199<br />
ch = '3';<br />
if (isgraph (ch))<br />
printf ("3 là một nhân vật đồ họa \ n");<br />
khác<br />
printf ("3 là Nota đồ họa nhân vật \ n");<br />
ch = '#';<br />
if (isgraph (ch))<br />
printf ("# là một nhân vật đồ họa \ n");<br />
khác<br />
printf ("# là Nota nhân vật đồ họa \ n");<br />
ch = '';<br />
if (isgraph (ch))<br />
printf ("một không gian là một nhân vật đồ họa \ n");<br />
khác<br />
printf ("một không gian là không một nhân vật đồ họa \ n");<br />
}<br />
Đầu ra:<br />
3 là một nhân vật đồ họa<br />
# Là một nhân vật đồ họa<br />
một không gian là không một nhân vật đồ họa<br />
islower<br />
Mô tả: Kiểm tra trong một trường hợp thấp hơn ký tự chữ cái.<br />
Bao gồm:<br />
Nguyên mẫu: int islower (int c);<br />
Đối số: nhân vật c để kiểm tra<br />
Quay trở lại giá trị: Trả về một giá trị khác không số nguyên nếu nhân vật này l<br />
một trường hợp thấp hơn<br />
ký tự chữ cái; nếu không, trả về số không.<br />
Bình luận: Một nhân vật được coi là một trường hợp ký tự chữ cái thấp hơn nếu<br />
nó là<br />
trong phạm vi của 'a' - 'z'.<br />
Ví dụ: # include / * Cho islower * /<br />
# include / * Cho printf * /
if (isalpha(ch))<br />
printf("# is alphabetic\n");<br />
else<br />
printf("# isNOT alphabetic\n");<br />
}<br />
Output:<br />
B is alphabetic<br />
# is NOT alphabetic<br />
iscntrl<br />
Description: Test for a control character.<br />
Include: <br />
Prototype: int iscntrl(int c);<br />
Argument: c character to test.<br />
Return Value: Returns a non-zero integer value if the character is a control<br />
character;<br />
otherwise, returns zero.<br />
Remarks: A character is considered to be a control character if its ASCII value<br />
is<br />
in the range 0x00 to 0x1F inclusive, or 0x7F.<br />
Example: #include /*for iscntrl */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
char ch;<br />
ch = 'B';<br />
if (iscntrl(ch))<br />
printf("B is a control character\n");<br />
else<br />
printf("B is NOTa control character\n");<br />
ch = '\t';<br />
if (iscntrl(ch))<br />
printf("A tab isa control character\n");<br />
else<br />
printf("A tab is NOT a control character\n");<br />
}<br />
Output:<br />
B is NOT a control character<br />
A tab is a control character<br />
isalpha (Continued)<br />
dsPIC<br />
int main (void)<br />
{<br />
int ch;<br />
ch = 'B';<br />
if (islower (ch))<br />
printf ("B là trường hợp thấp hơn \ n");<br />
khác<br />
printf ("B isnot thấp hơn trường hợp \ n");<br />
ch = 'b';<br />
if (islower (ch))<br />
printf ("b là trường hợp thấp hơn \ n");<br />
khác<br />
printf ("b isnot thấp hơn trường hợp \ n");<br />
}<br />
Đầu ra:<br />
B là không thấp hơn trường hợp<br />
b là trường hợp thấp hơn<br />
isgraph (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 200<br />
isprint<br />
2004 Microchip Technology Inc<br />
Mô tả: Kiểm tra cho một ký tự in (bao gồm một không gian).<br />
Bao gồm:<br />
Nguyên mẫu: int isprint (int c);<br />
Đối số: nhân vật c để kiểm tra<br />
Quay trở lại giá trị: Trả về một số nguyên nhân vật khác không có giá trị ifthe là<br />
in;<br />
nếu không, trả về số không.<br />
Bình luận: Một nhân vật được coi là một nhân vật có thể in nếu nó đang trong<br />
phạm vi<br />
0x20 để 0x7e toàn diện.<br />
Ví dụ: # include / * Cho isprint * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
int ch;<br />
ch = "&";<br />
if (isprint (ch))
®<br />
Language Tools Libraries<br />
DS51456B-page 198<br />
isdigit<br />
Description: Test for a decimal digit.<br />
Include: <br />
Prototype: int isdigit(int c);<br />
Argument: c character to test.<br />
2004 Microchip Technology Inc.<br />
Return Value: Returns a non-zero integer value if the character is a digit;<br />
otherwise,<br />
returns zero.<br />
Remarks: A character is considered to be a digit character if it is in the range of<br />
'0'-'9'.<br />
Example: #include /*for isdigit */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
int ch;<br />
ch = '3';<br />
if (isdigit(ch))<br />
printf("3 is a digit\n");<br />
else<br />
printf("3 is NOT a digit\n");<br />
ch = '#';<br />
if (isdigit(ch))<br />
printf("# is a digit\n");<br />
else<br />
printf("# is NOT a digit\n");<br />
}<br />
Output:<br />
3 is a digit<br />
# is NOT a digit<br />
isgraph<br />
Description: Test for a graphical character.<br />
Include: <br />
Prototype: int isgraph (int c);<br />
Argument: c character to test<br />
Return Value: Returns a non-zero integer value ifthe character is a graphical<br />
character; otherwise, returns zero.<br />
printf ("& là một nhân vật có thể in \ n");<br />
khác<br />
printf ("& KHÔNG phải là một nhân vật có thể in \ n");<br />
ch = '\ t';<br />
if (isprint (ch))<br />
printf ("một tab là một nhân vật có thể in \ n");<br />
khác<br />
printf ("một tab là không một nhân vật có thể in \ n");<br />
}<br />
Đầu ra:<br />
Và là một nhân vật có thể in<br />
một tab là không một nhân vật có thể in<br />
ispunct<br />
Mô tả: Kiểm tra trong một ký tự chấm câu.<br />
Bao gồm:<br />
Nguyên mẫu: int ispunct (int c);<br />
Đối số: nhân vật c để kiểm tra<br />
Quay trở lại giá trị: Trả về một số nguyên nhân vật khác không có giá trị ifthe là<br />
một dấu chấm câu<br />
nhân vật; nếu không, trả về số không.<br />
Bình luận: Một nhân vật được coi là một nhân vật dấu chấm câu nếu nó là một<br />
nhân vật có thể in mà không phải là một không gian cũng không phải là chữ số<br />
nhân vật. Ký tự chấm câu bao gồm những điều sau đây:<br />
! "# $% & '(); @ [\] * +, - /:. ^ _ {|} ~<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 201<br />
Ví dụ: # include / * Cho ispunct * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
int ch;<br />
ch = "&";<br />
if (ispunct (ch))<br />
printf ("& là một nhân vật dấu chấm câu \ n");<br />
khác<br />
printf ("& là ký tự chấm câu Nota \ n");<br />
ch = '\ t';<br />
if (ispunct (ch))<br />
printf ("một tab isa dấu chấm câu ký tự \ n");<br />
khác
Remarks: A character is considered to be a graphical character if it is any<br />
printable character except a space.<br />
Example: #include /*for isgraph */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
int ch;<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 199<br />
ch = '3';<br />
if (isgraph(ch))<br />
printf("3 is a graphical character\n");<br />
else<br />
printf("3 is NOTa graphical character\n");<br />
ch = '#';<br />
if (isgraph(ch))<br />
printf("# is a graphical character\n");<br />
else<br />
printf("# is NOTa graphical character\n");<br />
ch = ' ';<br />
if (isgraph(ch))<br />
printf("a space is a graphical character\n");<br />
else<br />
printf("a space is NOT a graphical character\n");<br />
}<br />
Output:<br />
3 is a graphical character<br />
# is a graphical character<br />
a space is NOT a graphical character<br />
islower<br />
Description: Test for a lower case alphabetic character.<br />
Include: <br />
Prototype: int islower (int c);<br />
Argument: c character to test<br />
Return Value: Returns a non-zero integer value if the character is a lower case<br />
alphabetic character; otherwise, returns zero.<br />
Remarks: A character is considered to be a lower case alphabetic character if it<br />
is<br />
in the range of 'a'-'z'.<br />
printf ("một tab là không một ký tự chấm câu \ n");<br />
}<br />
Đầu ra:<br />
Và là một nhân vật dấu chấm câu<br />
một tab là không một ký tự chấm câu<br />
isspace<br />
Mô tả: Kiểm tra cho một nhân vật không gian trắng.<br />
Bao gồm:<br />
Nguyên mẫu: int isspace (int c);<br />
Đối số: nhân vật c để kiểm tra<br />
Quay trở lại giá trị: Trả về một giá trị khác không số nguyên nếu nhân vật này l<br />
một không gian màu trắng<br />
nhân vật; nếu không, trả về số không.<br />
Bình luận: Một nhân vật được coi là một nhân vật không gian trắng nếu nó là<br />
một trong những<br />
như sau: không gian (''), thức ăn dạng ('\ f'), xuống dòng ('\ n'), vận chuyển trở<br />
lại<br />
('\ R'), tab ngang ('\ t'), hoặc tab theo chiều dọc ('\ v').<br />
Ví dụ: # include / * Cho isspace * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
int ch;<br />
ch = "&";<br />
if (isspace (ch))<br />
printf ("& là một không gian trắng ký tự \ n");<br />
khác<br />
printf ("& là Nota trắng không gian ký tự \ n");<br />
ch = '\ t';<br />
if (isspace (ch))<br />
printf ("một tab isa trắng không gian ký tự \ n");<br />
khác<br />
printf ("một tab là không một không gian trắng ký tự \ n");<br />
}<br />
Đầu ra:<br />
Và là không một nhân vật không gian trắng<br />
một tab là một nhân vật không gian trắng<br />
ispunct (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ
Example: #include /*for islower */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
int ch;<br />
ch = 'B';<br />
if (islower(ch))<br />
printf("B is lower case\n");<br />
else<br />
printf("B isNOT lower case\n");<br />
ch = 'b';<br />
if (islower(ch))<br />
printf("b is lower case\n");<br />
else<br />
printf("b isNOT lower case\n");<br />
}<br />
Output:<br />
B is NOT lower case<br />
b is lower case<br />
isgraph (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B trang 202<br />
isupper<br />
2004 Microchip Technology Inc<br />
Mô tả: Kiểm tra cho một thư trường hợp trên.<br />
Bao gồm:<br />
Nguyên mẫu: int isupper (int c);<br />
Đối số: nhân vật c để kiểm tra<br />
Quay trở lại giá trị: Trả về một số nguyên giá trị ifthe nhân vật khác không Isan<br />
trường hợp trên<br />
ký tự chữ cái; nếu không, trả về số không.<br />
Bình luận: Một nhân vật được coi là một trường hợp trên ký tự chữ cái nếu nó<br />
là trong phạm vi của 'A' - 'Z'.<br />
Ví dụ: # include / * Cho isupper * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
int ch;<br />
ch = 'B';<br />
if (isupper (ch))<br />
printf ("B là chữ hoa \ n");<br />
khác<br />
printf ("B là không chữ hoa \ n");<br />
ch = 'b';<br />
if (isupper (ch))<br />
printf ("b là chữ hoa \ n");<br />
DS51456B-page 200<br />
isprint<br />
2004 Microchip Technology Inc.<br />
khác<br />
printf ("b là không chữ hoa \ n");<br />
Description: Test for a printable character (includes a space).<br />
Include: <br />
Prototype: int isprint (int c);<br />
Argument: c character to test<br />
Return Value: Returns a non-zero integer value ifthe character is printable;<br />
otherwise, returns zero.<br />
Remarks: A character is considered to be a printable character if it is in the<br />
range<br />
0x20 to 0x7e inclusive.<br />
Example: #include /*for isprint */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
int ch;<br />
}<br />
Đầu ra:<br />
B là trường hợp trên<br />
b là không trường hợp trên<br />
isxdigit<br />
Mô tả: Kiểm tra trong một chữ số thập lục phân.<br />
Bao gồm:<br />
Nguyên mẫu: int isxdigit (int c);<br />
Đối số: nhân vật c để kiểm tra<br />
Quay trở lại giá trị: Trả về một giá trị khác không số nguyên nếu nhân vật này l<br />
một chữ số thập lục phân;<br />
nếu không, trả về số không.<br />
Bình luận: Một nhân vật được coi là một nhân vật chữ số thập lục phân nếu nó<br />
đang trong<br />
phạm vi của "0" - "9 ',' A '-' F 'or' a '-' f'.Note: Danh sách này không bao gồm
ch = '&';<br />
if (isprint(ch))<br />
printf("& is a printable character\n");<br />
else<br />
printf("& is NOT a printable character\n");<br />
ch = '\t';<br />
if (isprint(ch))<br />
printf("a tab is a printable character\n");<br />
else<br />
printf("a tab is NOT a printable character\n");<br />
}<br />
Output:<br />
& is a printable character<br />
a tab is NOT a printable character<br />
ispunct<br />
Description: Test for a punctuation character.<br />
Include: <br />
Prototype: int ispunct (int c);<br />
Argument: c character to test<br />
Return Value: Returns a non-zero integer value ifthe character is a punctuation<br />
character; otherwise, returns zero.<br />
Remarks: A character is considered to be a punctuation character if it is a<br />
printable character which is neither a space nor an alphanumeric<br />
character. Punctuation characters consist of the following:<br />
! " # $ % & ' ( ) ; < = > ? @ [ \ ] * + , - . / : ^ _ { | } ~<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 201<br />
Example: #include /*for ispunct */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
int ch;<br />
ch = '&';<br />
if (ispunct(ch))<br />
printf("& is a punctuation character\n");<br />
else<br />
printf("& is NOTa punctuation character\n");<br />
ch = '\t';<br />
if (ispunct(ch))<br />
các<br />
0x hàng đầu vì 0x là tiền tố cho một số thập lục phân, nhưng không phải là<br />
một chữ số thập lục phân thực tế.<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 203<br />
Ví dụ: # include / * Cho isxdigit * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
int ch;<br />
ch = 'B';<br />
if (isxdigit (ch))<br />
printf ("B là một chữ số thập lục phân \ n");<br />
khác<br />
printf ("B là chữ số thập lục phân Nota \ n");<br />
ch = 't';<br />
if (isxdigit (ch))<br />
printf ("t là một chữ số thập lục phân \ n");<br />
khác<br />
printf ("t là chữ số thập lục phân Nota \ n");<br />
}<br />
Đầu ra:<br />
B là một chữ số thập lục phân<br />
t là không một chữ số thập lục phân<br />
ToLower<br />
Mô tả: Chuyển đổi một nhân vật đến một trường hợp thấp hơn chữ cái.<br />
Bao gồm:<br />
Nguyên mẫu: int ToLower (int c);<br />
Đối số: c Nhân vật chuyển đổi sang chữ thường.<br />
Quay trở lại giá trị: Trả về trường hợp thấp hơn tương ứng với chữ cái nếu<br />
lập luận là trường hợp ban đầu trên; nếu không, trả về ban đầu<br />
nhân vật.<br />
Ghi chú: Chỉ có trường hợp trên ký tự chữ cái có thể được chuyển đổi để giảm<br />
trường hợp.<br />
Ví dụ: # include / * Cho ToLower * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
int ch;
printf("a tab isa punctuation character\n");<br />
else<br />
printf("a tab is NOT a punctuation character\n");<br />
}<br />
Output:<br />
& is a punctuation character<br />
a tab is NOT a punctuation character<br />
isspace<br />
Description: Test for a white-space character.<br />
Include: <br />
Prototype: int isspace (int c);<br />
Argument: c character to test<br />
Return Value: Returns a non-zero integer value if the character is a white-space<br />
character; otherwise, returns zero.<br />
Remarks: A character is considered to be a white-space character if it is one of<br />
the following: space (' '), form feed ('\f'), newline ('\n'), carriage return<br />
('\r'), horizontal tab ('\t'), or vertical tab ('\v').<br />
Example: #include /*for isspace */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
int ch;<br />
ch = '&';<br />
if (isspace(ch))<br />
printf("& is a white-space character\n");<br />
else<br />
printf("& is NOTa white-space character\n");<br />
ch = '\t';<br />
if (isspace(ch))<br />
printf("a tab isa white-space character\n");<br />
else<br />
printf("a tab is NOT a white-space character\n");<br />
}<br />
Output:<br />
& is NOT a white-space character<br />
a tab is a white-space character<br />
ispunct (Continued)<br />
dsPIC<br />
®<br />
ch = 'B';<br />
printf ("thay đổi B trường hợp thấp hơn% c \ n",<br />
ToLower (ch));<br />
ch = 'b';<br />
printf ("b vẫn còn trường hợp thấp hơn% c \ n",<br />
ToLower (ch));<br />
ch = '@';<br />
printf ("@ không có trường hợp thấp hơn,");<br />
printf ("% c để được trả lại \ n", ToLower (ch));<br />
}<br />
Đầu ra:<br />
B để thay đổi trường hợp thấp hơn b<br />
b vẫn còn trường hợp thấp hơn b<br />
@ Không có trường hợp thấp hơn, vì vậy @ được trả lại<br />
isxdigit (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 204<br />
toupper<br />
2004 Microchip Technology Inc<br />
Mô tả: Chuyển đổi một nhân vật với một chữ hoa chữ cái.<br />
Bao gồm:<br />
Nguyên mẫu: int toupper (int c);<br />
Đối số: c Nhân vật chuyển đổi sang trường hợp trên.<br />
Quay trở lại giá trị: Trả về trường hợp trên tương ứng với chữ cái nếu<br />
lập luận là trường hợp ban đầu thấp hơn; nếu không, trả về ban đầu<br />
nhân vật.<br />
Ghi chú: Chỉ có trường hợp thấp hơn các ký tự chữ cái có thể được chuyển đổi<br />
sang trên<br />
trường hợp.<br />
Ví dụ: # include / * Cho toupper * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
int ch;<br />
ch = 'b';<br />
printf ("b thay đổi chữ hoa% c \ n",<br />
toupper (ch));<br />
ch = 'B';<br />
printf ("B vẫn còn trường hợp trên% c \ n",
Language Tools Libraries<br />
DS51456B-page 202<br />
isupper<br />
2004 Microchip Technology Inc.<br />
Description: Test for an upper case letter.<br />
Include: <br />
Prototype: int isupper (int c);<br />
Argument: c character to test<br />
Return Value: Returns a non-zero integer value ifthe character isan upper case<br />
alphabetic character; otherwise, returns zero.<br />
Remarks: A character is considered to be an upper case alphabetic character if it<br />
is in the range of 'A'-'Z'.<br />
Example: #include /*for isupper */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
int ch;<br />
ch = 'B';<br />
if (isupper(ch))<br />
printf("B is upper case\n");<br />
else<br />
printf("B is NOT upper case\n");<br />
ch = 'b';<br />
if (isupper(ch))<br />
printf("b is upper case\n");<br />
else<br />
printf("b is NOT upper case\n");<br />
}<br />
Output:<br />
B is upper case<br />
b is NOT upper case<br />
isxdigit<br />
Description: Test for a hexadecimal digit.<br />
Include: <br />
Prototype: int isxdigit (int c);<br />
Argument: c character to test<br />
Return Value: Returns a non-zero integer value if the character is a hexadecimal<br />
digit;<br />
otherwise, returns zero.<br />
Remarks: A character is considered to be a hexadecimal digit character if it is in<br />
toupper (ch));<br />
ch = '@';<br />
printf ("@ có trường hợp noupper,");<br />
printf ("% c để được trả lại \ n", toupper (ch));<br />
}<br />
Đầu ra:<br />
b thay đổi đối với trường hợp trên B<br />
B vẫn còn trường hợp trên B<br />
@ Không có trường hợp trên, vì vậy @ được trả lại<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 205<br />
4.5 LỖI<br />
Các errno.hconsists tập tin tiêu đề của các macro cung cấp mã lỗi được báo cáo<br />
bởi chức năng thư viện nhất định (xem chức năng riêng biệt.) Sự trở lại<br />
errnomay biến<br />
bất kỳ giá trị lớn hơn không. Để kiểm tra xem một chức năng thư viện gặp một<br />
lỗi, chương trình sẽ lưu trữ các giá trị số không trong errnoimmediately trước<br />
khi gọi hàm thư viện. Giá trị cần được kiểm tra trước khi một cuộc gọi chức<br />
năng có thể thay đổi giá trị.<br />
Khi khởi động chương trình, errnois không. Chức năng thư viện sẽ không bao<br />
giờ đặt errnoto không.<br />
EDOM<br />
Mô tả: Đại diện cho một lỗi tên miền.<br />
Bao gồm:<br />
Bình luận: EDOMrepresents một lỗi miền, xảy ra khi một đối số đầu vào<br />
là bên ngoài lĩnh vực chức năng whichthe được xác định.<br />
ERANGE<br />
Mô tả: Đại diện một tràn hoặc lỗi Van cân bằng.<br />
Bao gồm:<br />
Bình luận: ERANGErepresents một tràn hoặc lỗi Van cân bằng, xảy ra khi<br />
Kết quả là quá lớn hoặc quá nhỏ để có thể lưu trữ.<br />
errno<br />
Mô tả: Chứa các giá trị của một lỗi whenan lỗi xảy ra trong một hàm.<br />
Bao gồm:<br />
Chú ý: errnois biến thiết lập một khác không giá trị số nguyên của một thư viện<br />
hoạt động khi xảy ra lỗi. Khi khởi động chương trình, errnois thiết lập để<br />
không. Errnoshould được thiết lập lại bằng không trước khi gọi một chức năng<br />
mà bộ<br />
nó.<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ
the range of '0'-'9', 'A'-'F' or 'a'-'f'.Note: The list does not include the<br />
leading 0x because 0x is the prefix for a hexadecimal number but is not<br />
an actual hexadecimal digit.<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 203<br />
Example: #include /*for isxdigit */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
int ch;<br />
ch = 'B';<br />
if (isxdigit(ch))<br />
printf("B is a hexadecimal digit\n");<br />
else<br />
printf("B is NOTa hexadecimal digit\n");<br />
ch = 't';<br />
if (isxdigit(ch))<br />
printf("t is a hexadecimal digit\n");<br />
else<br />
printf("t is NOTa hexadecimal digit\n");<br />
}<br />
Output:<br />
B is a hexadecimal digit<br />
t is NOT a hexadecimal digit<br />
tolower<br />
Description: Convert a character to a lower case alphabetical character.<br />
Include: <br />
Prototype: int tolower (int c);<br />
Argument: c The character to convert to lower case.<br />
Return Value: Returns the corresponding lower case alphabetical character if<br />
the<br />
argument was originally upper case; otherwise, returns the original<br />
character.<br />
Remarks: Only upper case alphabetical characters may be converted to lower<br />
case.<br />
Example: #include /*for tolower */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
DS51456B trang 206<br />
4.6 ĐẶC ĐIỂM NỔI<br />
2004 Microchip Technology Inc<br />
Các float.hconsists tập tin tiêu đề của các macro mà chỉ định thuộc tính khác<br />
nhau nổi<br />
loại điểm. Các tính chất này bao gồm số con số đáng kể, giới hạn kích thước, và<br />
những gì<br />
chế độ làm tròn được sử dụng.<br />
DBL_DIG<br />
Mô tả: Số chữ số thập phân có độ chính xác trong một độ chính xác kép nổi<br />
giá trị điểm<br />
Bao gồm:<br />
Giá trị: 6 theo mặc định, 15 công tắc -fno-ngắn doubleis sử dụng<br />
Ghi chú: Theo mặc định, một loại tăng gấp đôi là samesize như một kiểu float<br />
(32-bit<br />
đại diện). Các -fno-ngắn doubleswitch cho phép IEEE<br />
Đại diện 64-bit được sử dụng cho một điểm chính xác đôi nổi<br />
giá trị.<br />
DBL_EPSILON<br />
Mô tả: Sự khác biệt giữa 1.0 và biểu diễn tiếp theo lớn hơn gấp đôi<br />
chính xác giá trị dấu chấm động<br />
Bao gồm:<br />
Giá trị: 1.192093e-07 theo mặc định, 2.220446e-16 nếu chuyển đổi<br />
-fno-ngắn doubleis sử dụng<br />
Ghi chú: Theo mặc định, một loại tăng gấp đôi là samesize như một kiểu float<br />
(32-bit<br />
đại diện). Các -fno-ngắn doubleswitch cho phép IEEE<br />
Đại diện 64-bit được sử dụng cho một điểm chính xác đôi nổi<br />
giá trị.<br />
DBL_MANT_DIG<br />
Mô tả: Số cơ sở-FLT_RADIXdigits trong một độ chính xác gấp đôi điểm nổi<br />
significand<br />
Bao gồm:<br />
Giá trị: 24 theo mặc định, 53 công tắc -fno-ngắn doubleis sử dụng<br />
Ghi chú: Theo mặc định, một loại tăng gấp đôi là samesize như một kiểu float<br />
(32-bit<br />
đại diện). The-fno-ngắn doubleswitch cho phép IEEE<br />
Đại diện 64-bit được sử dụng cho một điểm chính xác đôi nổi<br />
giá trị.<br />
DBL_MAX<br />
Mô tả: hữu hạn gấp đôi giá trị điểm tối đa độ chính xác nổi<br />
Bao gồm:<br />
Giá trị: 3.402823e + 38 theo mặc định, 1.797693e + 308 nếu chuyển đổi
int ch;<br />
ch = 'B';<br />
printf("B changes to lower case %c\n",<br />
tolower(ch));<br />
ch = 'b';<br />
printf("b remains lower case %c\n",<br />
tolower(ch));<br />
ch = '@';<br />
printf("@ has no lower case, ");<br />
printf("so %c is returned\n", tolower(ch));<br />
}<br />
Output:<br />
B changes to lower case b<br />
b remains lower case b<br />
@ has no lower case,so @ is returned<br />
isxdigit (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 204<br />
toupper<br />
2004 Microchip Technology Inc.<br />
Description: Convert a character to an upper case alphabetical character.<br />
Include: <br />
Prototype: int toupper (int c);<br />
Argument: c The character to convert to upper case.<br />
Return Value: Returns the corresponding upper case alphabetical character if<br />
the<br />
argument was originally lower case; otherwise, returns the original<br />
character.<br />
Remarks: Only lower case alphabetical characters may be converted to upper<br />
case.<br />
Example: #include /*for toupper */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
int ch;<br />
ch = 'b';<br />
printf("b changes to upper case %c\n",<br />
toupper(ch));<br />
-fno-ngắn doubleis sử dụng<br />
Ghi chú: Theo mặc định, một loại tăng gấp đôi là samesize như một kiểu float<br />
(32-bit<br />
đại diện). Các -fno-ngắn doubleswitch cho phép IEEE<br />
Đại diện 64-bit được sử dụng cho một điểm chính xác đôi nổi<br />
giá trị.<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 207<br />
DBL_MAX_10_EXP<br />
Mô tả: giá trị số nguyên tối đa cho một số mũ điểm chính xác gấp đôi nổi trong<br />
10 cơ sở<br />
Bao gồm:<br />
Giá trị: 38 theo mặc định, 308 nếu chuyển đổi -fno-ngắn doubleis sử dụng<br />
Ghi chú: Theo mặc định, một loại tăng gấp đôi là samesize như một kiểu float<br />
(32-bit<br />
đại diện). Các -fno-ngắn doubleswitch cho phép IEEE<br />
Đại diện 64-bit được sử dụng cho một điểm chính xác đôi nổi<br />
giá trị.<br />
DBL_MAX_EXP<br />
Mô tả: giá trị số nguyên tối đa cho một số mũ điểm chính xác gấp đôi nổi trong<br />
cơ sở FLT_RADIX<br />
Bao gồm:<br />
Giá trị: 128 theo mặc định, 1024 nếu chuyển đổi -fno-ngắn doubleis sử dụng<br />
Ghi chú: Theo mặc định, một loại tăng gấp đôi là samesize như một kiểu float<br />
(32-bit<br />
đại diện). Các -fno-ngắn doubleswitch cho phép IEEE<br />
Đại diện 64-bit được sử dụng cho một điểm chính xác đôi nổi<br />
giá trị.<br />
DBL_MIN<br />
Mô tả: tối thiểu giá trị chính xác điểm nổi đôi<br />
Bao gồm:<br />
Giá trị: 1.175494e-38 theo mặc định, 2.225074e-308 nếu chuyển đổi<br />
-fno-ngắn doubleis sử dụng<br />
Ghi chú: Theo mặc định, một loại tăng gấp đôi là samesize như một kiểu float<br />
(32-bit<br />
đại diện). Các -fno-ngắn doubleswitch cho phép IEEE<br />
Đại diện 64-bit được sử dụng cho một điểm chính xác đôi nổi<br />
giá trị.<br />
DBL_MIN_10_EXP<br />
Mô tả: Giá trị số nguyên âm tối thiểu cho một điểm chính xác đôi nổi<br />
số mũ cơ số 10
ch = 'B';<br />
printf("B remains upper case %c\n",<br />
toupper(ch));<br />
ch = '@';<br />
printf("@ has noupper case, ");<br />
printf("so %c is returned\n", toupper(ch));<br />
}<br />
Output:<br />
b changes to upper case B<br />
Bao gồm:<br />
Giá trị: -37 theo mặc định, nếu chuyển đổi -307 -fno-ngắn doubleis sử dụng<br />
Ghi chú: Theo mặc định, một loại tăng gấp đôi là samesize như một kiểu float<br />
(32-bit<br />
đại diện). Các -fno-ngắn doubleswitch cho phép IEEE<br />
Đại diện 64-bit được sử dụng cho một điểm chính xác đôi nổi<br />
giá trị.<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
B remains upper case B<br />
@ has no upper case, so @ is returned<br />
DS51456B trang 208<br />
DBL_MIN_EXP<br />
2004 Microchip Technology Inc<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 205<br />
4.5 ERRORS<br />
The header file errno.hconsists of macros that provide error codes that are<br />
reported<br />
by certain library functions (see individual functions.) The variable errnomay<br />
return<br />
any value greater than zero. To test if a library function encounters an error, the<br />
program should store the value zero in errnoimmediately before calling the<br />
library function. The value should be checked before another function call could<br />
change the value.<br />
At program startup, errnois zero. Library functions will never set errnoto zero.<br />
EDOM<br />
Description: Represents a domain error.<br />
Include: <br />
Remarks: EDOMrepresents a domain error, which occurs when an input<br />
argument<br />
is outside the domain in whichthe function is defined.<br />
ERANGE<br />
Description: Represents an overflow or underflow error.<br />
Include: <br />
Remarks: ERANGErepresents an overflow or underflow error, which occurs<br />
when<br />
a result is too large or too small to be stored.<br />
errno<br />
Description: Contains the value of an error whenan error occurs in a function.<br />
Include: <br />
Remarks: The variable errnois set to a non-zero integer value by a library<br />
function when an error occurs. At program startup, errnois set to<br />
zero. Errnoshould be reset to zero prior to calling a function that sets<br />
it.<br />
Mô tả: Giá trị số nguyên âm tối thiểu cho một điểm chính xác đôi nổi<br />
mũ trong FLT_RADIX cơ sở<br />
Bao gồm:<br />
Giá trị: -125 theo mặc định, nếu chuyển đổi -1021 -fno-ngắn doubleis sử dụng<br />
Ghi chú: Theo mặc định, một loại tăng gấp đôi là samesize như một kiểu float<br />
(32-bit<br />
đại diện). Các -fno-ngắn doubleswitch cho phép IEEE<br />
Đại diện 64-bit được sử dụng cho một điểm chính xác đôi nổi<br />
giá trị.<br />
FLT_DIG<br />
Mô tả: Số chữ số thập phân chính xác tại một điểm duy nhất chính xác nổi<br />
giá trị<br />
Bao gồm:<br />
Giá trị: 6<br />
FLT_EPSILON<br />
Mô tả: Sự khác biệt giữa 1.0 và duy nhất biểu diễn lớn hơn tiếp theo<br />
chính xác giá trị dấu chấm động<br />
Bao gồm:<br />
Giá trị: 1.192093e-07<br />
FLT_MANT_DIG<br />
Mô tả: Số cơ sở-FLT_RADIXdigits trong một đơn chính xác dấu chấm động<br />
significand<br />
Bao gồm:<br />
Giá trị: 24<br />
FLT_MAX<br />
Mô tả: hữu hạn đơn giá trị điểm tối đa độ chính xác nổi<br />
Bao gồm:<br />
Giá trị: 3.402823e + 38
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 206<br />
2004 Microchip Technology Inc.<br />
4.6 FLOATING-POINT CHARACTERISTICS<br />
The header file float.hconsists of macros that specify various properties of<br />
floating<br />
point types. These properties include number of significant figures, size limits,<br />
and what<br />
rounding mode is used.<br />
DBL_DIG<br />
Description: Number of decimal digits of precision in a double precision<br />
floating<br />
point value<br />
Include: <br />
Value: 6 by default, 15 if the switch -fno-short-doubleis used<br />
Remarks: By default, a double type is the samesize as a float type (32-bit<br />
representation). The -fno-short-doubleswitch allows the IEEE<br />
64-bit representation to be used for a double precision floating point<br />
value.<br />
DBL_EPSILON<br />
Description: The difference between 1.0 and the next larger representable<br />
double<br />
precision floating point value<br />
Include: <br />
Value: 1.192093e-07 by default, 2.220446e-16 if the switch<br />
-fno-short-doubleis used<br />
Remarks: By default, a double type is the samesize as a float type (32-bit<br />
representation). The -fno-short-doubleswitch allows the IEEE<br />
64-bit representation to be used for a double precision floating point<br />
value.<br />
DBL_MANT_DIG<br />
Description: Number of base-FLT_RADIXdigits in a double precision floatingpoint<br />
significand<br />
Include: <br />
Value: 24 by default, 53 if the switch -fno-short-doubleis used<br />
Remarks: By default, a double type is the samesize as a float type (32-bit<br />
representation). The-fno-short-doubleswitch allows the IEEE<br />
64-bit representation to be used for a double precision floating point<br />
value.<br />
FLT_MAX_10_EXP<br />
Mô tả: giá trị số nguyên tối đa cho một số mũ điểm chính xác đơn trôi nổi trong<br />
10 cơ sở<br />
Bao gồm:<br />
Giá trị: 38<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 209<br />
FLT_MAX_EXP<br />
Mô tả: giá trị số nguyên tối đa cho một số mũ điểm chính xác đơn trôi nổi trong<br />
cơ sở FLT_RADIX<br />
Bao gồm:<br />
Giá trị: 128<br />
FLT_MIN<br />
Mô tả: đơn giá trị điểm nổi chính xác tối thiểu<br />
Bao gồm:<br />
Giá trị: 1.175494e-38<br />
FLT_MIN_10_EXP<br />
Mô tả: Giá trị số nguyên âm tối thiểu cho một điểm duy nhất chính xác nổi<br />
số mũ cơ số 10<br />
Bao gồm:<br />
Giá trị: -37<br />
FLT_MIN_EXP<br />
Mô tả: Giá trị số nguyên âm tối thiểu cho một điểm duy nhất chính xác nổi<br />
mũ trong FLT_RADIX cơ sở<br />
Bao gồm:<br />
Giá trị: -125<br />
FLT_RADIX<br />
Mô tả: Radix đại diện mũ<br />
Bao gồm:<br />
Giá trị: 2<br />
Ghi chú: Các đại diện cơ sở của số mũ là cơ sở-2 hoặc nhị phân.<br />
FLT_ROUNDS<br />
Mô tả: Đại diện cho chế độ làm tròn cho các hoạt động nổi điểm<br />
Bao gồm:<br />
Giá trị: 1<br />
Bình luận: Rounds với giá trị biểu diễn gần<br />
LDBL_DIG<br />
Mô tả: Số chữ số thập phân có độ chính xác trong một độ chính xác kép dài<br />
điểm nổi giá trị
DBL_MAX<br />
Description: Maximum finite double precision floating point value<br />
Include: <br />
Value: 3.402823e+38 by default, 1.797693e+308 if the switch<br />
-fno-short-doubleis used<br />
Remarks: By default, a double type is the samesize as a float type (32-bit<br />
representation). The -fno-short-doubleswitch allows the IEEE<br />
64-bit representation to be used for a double precision floating point<br />
value.<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 207<br />
DBL_MAX_10_EXP<br />
Description: Maximum integer value for a double precision floating point<br />
exponent in<br />
base 10<br />
Include: <br />
Value: 38 by default, 308 if the switch -fno-short-doubleis used<br />
Remarks: By default, a double type is the samesize as a float type (32-bit<br />
representation). The -fno-short-doubleswitch allows the IEEE<br />
64-bit representation to be used for a double precision floating point<br />
value.<br />
DBL_MAX_EXP<br />
Description: Maximum integer value for a double precision floating point<br />
exponent in<br />
base FLT_RADIX<br />
Include: <br />
Value: 128 by default, 1024 if the switch -fno-short-doubleis used<br />
Remarks: By default, a double type is the samesize as a float type (32-bit<br />
representation). The -fno-short-doubleswitch allows the IEEE<br />
64-bit representation to be used for a double precision floating point<br />
value.<br />
DBL_MIN<br />
Description: Minimum double precision floating point value<br />
Include: <br />
Value: 1.175494e-38 by default, 2.225074e-308 if the switch<br />
-fno-short-doubleis used<br />
Remarks: By default, a double type is the samesize as a float type (32-bit<br />
representation). The -fno-short-doubleswitch allows the IEEE<br />
64-bit representation to be used for a double precision floating point<br />
value.<br />
Bao gồm:<br />
Giá trị: 15<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 210 2004 Microchip Technology Inc<br />
LDBL_EPSILON<br />
Mô tả: Sự khác biệt giữa 1.0 và dài biểu diễn lớn hơn tiếp theo<br />
độ chính xác gấp đôi giá trị dấu chấm động<br />
Bao gồm:<br />
Giá trị: 2.220446e-16<br />
LDBL_MANT_DIG<br />
Mô tả: Số chữ số cơ sở-FLT_RADIX trong một độ chính xác kép dài<br />
điểm nổi significand<br />
Bao gồm:<br />
Giá trị: 53<br />
LDBL_MAX<br />
Mô tả: hữu hạn dài gấp đôi độ chính xác giá trị nổi điểm tối đa<br />
Bao gồm:<br />
Giá trị: 1.797693e + 308<br />
LDBL_MAX_10_EXP<br />
Mô tả: giá trị số nguyên tối đa cho một độ chính xác kép dài dấu chấm động<br />
số mũ cơ số 10<br />
Bao gồm:<br />
Giá trị: 308<br />
LDBL_MAX_EXP<br />
Mô tả: giá trị số nguyên tối đa cho một độ chính xác kép dài dấu chấm động<br />
mũ trong FLT_RADIX cơ sở<br />
Bao gồm:<br />
Giá trị: 1024<br />
LDBL_MIN<br />
Mô tả: độ chính xác kép dài giá trị nổi-điểm tối thiểu<br />
Bao gồm:<br />
Giá trị: 2.225074e-308<br />
LDBL_MIN_10_EXP<br />
Mô tả: Giá trị số nguyên âm tối thiểu cho một độ chính xác kép dài<br />
điểm nổi số mũ cơ số 10<br />
Bao gồm:<br />
Giá trị: -307
DBL_MIN_10_EXP<br />
Description: Minimum negative integer value for a double precision floating<br />
point<br />
exponent in base 10<br />
Include: <br />
Value: -37 by default, -307 if the switch -fno-short-doubleis used<br />
Remarks: By default, a double type is the samesize as a float type (32-bit<br />
representation). The -fno-short-doubleswitch allows the IEEE<br />
64-bit representation to be used for a double precision floating point<br />
value.<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 208<br />
DBL_MIN_EXP<br />
2004 Microchip Technology Inc.<br />
Description: Minimum negative integer value for a double precision floating<br />
point<br />
exponent in base FLT_RADIX<br />
Include: <br />
Value: -125 by default, -1021 if the switch -fno-short-doubleis used<br />
Remarks: By default, a double type is the samesize as a float type (32-bit<br />
representation). The -fno-short-doubleswitch allows the IEEE<br />
64-bit representation to be used for a double precision floating point<br />
value.<br />
FLT_DIG<br />
Description: Number of decimal digits of precision in a single precision floating<br />
point<br />
value<br />
Include: <br />
Value: 6<br />
FLT_EPSILON<br />
Description: The difference between 1.0 and the next larger representable single<br />
precision floating point value<br />
Include: <br />
Value: 1.192093e-07<br />
FLT_MANT_DIG<br />
Description: Number of base-FLT_RADIXdigits in a single precision floatingpoint<br />
significand<br />
Include: <br />
Value: 24<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 211<br />
4.7 GIỚI HẠN THỰC HIỆN-ĐỊNH NGHĨA<br />
Các limits.hconsists tập tin tiêu đề của các macro để xác định tối thiểu và tối đa<br />
giá trị của các loại nguyên. Mỗi một macro có thể được sử dụng trong<br />
#ifpreprocessing<br />
chỉ thị.<br />
LDBL_MIN_EXP<br />
Mô tả: Giá trị số nguyên âm tối thiểu cho một độ chính xác kép dài<br />
điểm nổi mũ trong FLT_RADIX cơ sở<br />
Bao gồm:<br />
Giá trị: -1021<br />
CHAR_BIT<br />
Mô tả: Số bit để đại diện cho kiểu char<br />
Bao gồm:<br />
Giá trị: 8<br />
CHAR_MAX<br />
Mô tả: Giá trị tối đa của một char<br />
Bao gồm:<br />
Giá trị: 127<br />
CHAR_MIN<br />
Mô tả: Giá trị tối thiểu của một char<br />
Bao gồm:<br />
Giá trị: -128<br />
INT_MAX<br />
Mô tả: Giá trị tối đa của một int<br />
Bao gồm:<br />
Giá trị: 32767<br />
INT_MIN<br />
Mô tả: Giá trị tối thiểu của một int<br />
Bao gồm:<br />
Giá trị: -32768<br />
LLONG_MAX<br />
Mô tả: Giá trị tối đa của một int dài dài<br />
Bao gồm:<br />
Giá trị: 9223372036854775807<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 212<br />
2004 Microchip Technology Inc
FLT_MAX<br />
Description: Maximum finite single precision floating point value<br />
Include: <br />
Value: 3.402823e+38<br />
FLT_MAX_10_EXP<br />
Description: Maximum integer value for a single precision floating point<br />
exponent in<br />
base 10<br />
Include: <br />
Value: 38<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 209<br />
FLT_MAX_EXP<br />
Description: Maximum integer value for a single precision floating point<br />
exponent in<br />
base FLT_RADIX<br />
Include: <br />
Value: 128<br />
FLT_MIN<br />
Description: Minimum single precision floating point value<br />
Include: <br />
Value: 1.175494e-38<br />
FLT_MIN_10_EXP<br />
Description: Minimum negative integer value for a single precision floating<br />
point<br />
exponent in base 10<br />
Include: <br />
Value: -37<br />
FLT_MIN_EXP<br />
Description: Minimum negative integer value for a single precision floating<br />
point<br />
exponent in base FLT_RADIX<br />
Include: <br />
Value: -125<br />
FLT_RADIX<br />
Description: Radix of exponent representation<br />
Include: <br />
Value: 2<br />
Remarks: The base representation of the exponent is base-2 or binary.<br />
FLT_ROUNDS<br />
Description: Represents the rounding mode for floating-point operations<br />
LLONG_MIN<br />
Mô tả: Giá trị tối thiểu của một int dài dài<br />
Bao gồm:<br />
Giá trị: -9223372036854775808<br />
LONG_MAX<br />
Mô tả: Giá trị tối đa của một int dài<br />
Bao gồm:<br />
Giá trị: 2147483647<br />
LONG_MIN<br />
Mô tả: Giá trị tối thiểu của một int dài<br />
Bao gồm:<br />
Giá trị: -2147483648<br />
MB_LEN_MAX<br />
Mô tả: Tối đa số byte trong một nhân vật nhiều byte<br />
Bao gồm:<br />
Giá trị: 1<br />
SCHAR_MAX<br />
Mô tả: Giá trị tối đa của một char ký<br />
Bao gồm:<br />
Giá trị: 127<br />
SCHAR_MIN<br />
Mô tả: Giá trị tối thiểu của một char ký<br />
Bao gồm:<br />
Giá trị: -128<br />
SHRT_MAX<br />
Mô tả: Giá trị tối đa của một int ngắn<br />
Bao gồm:<br />
Giá trị: 32767<br />
SHRT_MIN<br />
Mô tả: Giá trị tối thiểu của một int ngắn<br />
Bao gồm:<br />
Giá trị: -32768<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 213<br />
4.8 Nội địa hoá<br />
Trình biên dịch này mặc định là miền địa phương C và không hỗ trợ bất kỳ<br />
ngôn ngữ khác; Do đó,<br />
nó không hỗ trợ các tập tin tiêu đề locale.h. Sau đây thường được tìm thấy<br />
trong tập tin này:<br />
• cấu trúc lconv
Include: <br />
Value: 1<br />
Remarks: Rounds to the nearest representable value<br />
LDBL_DIG<br />
Description: Number of decimal digits of precision in a long double precision<br />
floating-point value<br />
Include: <br />
Value: 15<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 210 2004 Microchip Technology Inc.<br />
LDBL_EPSILON<br />
Description: The difference between 1.0 and the next larger representable long<br />
double precision floating-point value<br />
Include: <br />
Value: 2.220446e-16<br />
LDBL_MANT_DIG<br />
Description: Number of base-FLT_RADIX digits in a long double precision<br />
floating-point significand<br />
Include: <br />
Value: 53<br />
LDBL_MAX<br />
Description: Maximum finite long double precision floating-point value<br />
Include: <br />
Value: 1.797693e+308<br />
LDBL_MAX_10_EXP<br />
Description: Maximum integer value for a long double precision floating-point<br />
exponent in base 10<br />
Include: <br />
Value: 308<br />
LDBL_MAX_EXP<br />
Description: Maximum integer value for a long double precision floating-point<br />
exponent in base FLT_RADIX<br />
Include: <br />
Value: 1024<br />
LDBL_MIN<br />
Description: Minimum long double precision floating-point value<br />
Include: <br />
• NULL<br />
• LC_ALL<br />
• LC_COLLATE<br />
• LC_CTYPE<br />
• LC_MONETARY<br />
• LC_NUMERIC<br />
• LC_TIME<br />
• localeconv<br />
• setlocale<br />
UCHAR_MAX<br />
Mô tả: Giá trị tối đa của một unsigned char<br />
Bao gồm:<br />
Giá trị: 255<br />
UINT_MAX<br />
Mô tả: Giá trị tối đa của một int unsigned<br />
Bao gồm:<br />
Giá trị: 65535<br />
ULLONG_MAX<br />
Mô tả: Giá trị tối đa của một lâu dài int<br />
Bao gồm:<br />
Giá trị: 18446744073709551615<br />
ULONG_MAX<br />
Mô tả: Giá trị tối đa của một int dài<br />
Bao gồm:<br />
Giá trị: 4294967295<br />
USHRT_MAX<br />
Mô tả: Giá trị tối đa của một ngắn unsigned int<br />
Bao gồm:<br />
Giá trị: 65535<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 214<br />
4.9 Nhảy KHÔNG ĐỊA PHƯƠNG<br />
2004 Microchip Technology Inc<br />
Các setjmp.hconsists tập tin tiêu đề của một loại, một chức năng Anda vĩ mô<br />
cho phép kiểm soát<br />
chuyển giao xảy ra bỏ qua các cuộc gọi chức năng bình thường và quá trình trở<br />
lại.<br />
jmp_buf<br />
Mô tả: Một loại đó là một mảng được sử dụng bởi setjmpand longjmpto lưu và
Value: 2.225074e-308<br />
LDBL_MIN_10_EXP<br />
Description: Minimum negative integer value for a long double precision<br />
floating-point exponent in base 10<br />
Include: <br />
Value: -307<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 211<br />
4.7 IMPLEMENTATION-DEFINED LIMITS<br />
The header file limits.hconsists of macros that define the minimum and<br />
maximum<br />
values of integer types. Each of these macros can be used in #ifpreprocessing<br />
directives.<br />
LDBL_MIN_EXP<br />
Description: Minimum negative integer value for a long double precision<br />
floating-point exponent in base FLT_RADIX<br />
Include: <br />
Value: -1021<br />
CHAR_BIT<br />
Description: Number of bits to represent type char<br />
Include: <br />
Value: 8<br />
CHAR_MAX<br />
Description: Maximum value of a char<br />
Include: <br />
Value: 127<br />
CHAR_MIN<br />
Description: Minimum value of a char<br />
Include: <br />
Value: -128<br />
INT_MAX<br />
Description: Maximum value of an int<br />
Include: <br />
Value: 32767<br />
INT_MIN<br />
Description: Minimum value of an int<br />
Include: <br />
Value: -32768<br />
LLONG_MAX<br />
phục hồi môi trường chương trình.<br />
Bao gồm:<br />
Prototype: typedef int jmp_buf [_NSETJMP];<br />
Bình luận: _NSETJMPis định nghĩa là 16 + 2 đại diện cho 16 đăng ký và<br />
Địa chỉ trả lại 32-bit.<br />
setjmp<br />
Mô tả: Một vĩ mô mà lưu trạng thái hiện tại của chương trình để sử dụng sau<br />
này bằng cách<br />
longjmp.<br />
Bao gồm:<br />
Prototype: setjmp # define (jmp_buf env)<br />
Đối số: env biến nơi môi trường được lưu trữ<br />
Quay trở lại giá trị: Nếu sự trở lại là từ một cuộc gọi trực tiếp, setjmpreturns<br />
không. Nếu sự trở lại là<br />
từ một cuộc gọi đến longjmp, setjmpreturns một giá trị khác không.<br />
Lưu ý: Nếu valfrom luận longjmpis 0, setjmpreturns 1.<br />
Ví dụ: Xem longjmp.<br />
longjmp<br />
Mô tả: Chức năng này sẽ phục hồi môi trường lưu bởi setjmp.<br />
Bao gồm:<br />
Prototype: void longjmp (jmp_buf env, int val);<br />
Đối số: biến môi nơi môi trường được lưu trữ<br />
val giá trị được trả lại cho setjmp gọi.<br />
Ghi chú: Các giá trị tham số valshould có khác không. Nếu longjmpis gọi<br />
từ xử lý tín hiệu lồng nhau (có nghĩa là, gọi là kết quả của một tín hiệu<br />
đưa ra trong việc xử lý các tín hiệu khác), hành vi này là không xác định.<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 215<br />
4.10 XỬ LÝ TÍN HIỆU<br />
Các signal.hconsists tập tin tiêu đề của một loại, một số macro và hai chức năng<br />
định rõ các chương trình xử lý tín hiệu trong khi nó được thực hiện. Một tín<br />
hiệu là một điều kiện<br />
có thể được báo cáo trong quá trình thực hiện chương trình. Tín hiệu đồng bộ,<br />
xảy ra dưới sự kiểm soát phần mềm thông qua các raisefunction.<br />
Một tín hiệu có thể được xử lý bởi:<br />
• xử lý (SIG_DFL) Mặc định; tín hiệu được coi là một lỗi nghiêm trọng và thực<br />
hiện<br />
điểm dừng<br />
• Bỏ qua các tín hiệu (SIG_IGN); tín hiệu được bỏ qua và kiểm soát được trả lạ<br />
cho<br />
các ứng dụng người dùng<br />
• Xử lý tín hiệu với một chức năng được thông qua tín hiệu.<br />
Theo mặc định, tất cả các tín hiệu được xử lý bởi bộ xử lý mặc định, được xác
Description: Maximum value of a long long int<br />
Include: <br />
Value: 9223372036854775807<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 212 2004 Microchip Technology Inc.<br />
LLONG_MIN<br />
Description: Minimum value of a long long int<br />
Include: <br />
Value: -9223372036854775808<br />
LONG_MAX<br />
Description: Maximum value of a long int<br />
Include: <br />
Value: 2147483647<br />
LONG_MIN<br />
Description: Minimum value of a long int<br />
Include: <br />
Value: -2147483648<br />
MB_LEN_MAX<br />
Description: Maximum number of bytes in a multibyte character<br />
Include: <br />
Value: 1<br />
SCHAR_MAX<br />
Description: Maximum value of a signed char<br />
định bởi<br />
SIG_DFL.<br />
Các loại sig_atomic_tis một loại nguyên do việc tiếp cận chương trình nguyên<br />
tử. Khi<br />
loại này được sử dụng với các từ khóa dễ bay hơi, xử lý tín hiệu có thể chia sẻ<br />
dữ liệu<br />
các đối tượng với phần còn lại của chương trình.<br />
sig_atomic_t<br />
Mô tả: Một loại được sử dụng bởi một bộ xử lý tín hiệu<br />
Bao gồm:<br />
Prototype: typedef int sig_atomic_t;<br />
SIG_DFL<br />
Mô tả: Sử dụng như đối số thứ hai và / hoặc giá trị trả về cho signalto<br />
xác định rằng việc xử lý mặc định sẽ được sử dụng cho một tín hiệu cụ thể.<br />
Bao gồm:<br />
SIG_ERR<br />
Mô tả: Được sử dụng như giá trị trả về cho signalwhen nó không thể hoàn thành<br />
một<br />
yêu cầu do một lỗi.<br />
Bao gồm:<br />
SIG_IGN<br />
Mô tả: Sử dụng như đối số thứ hai và / hoặc giá trị trả về cho signalto<br />
xác định rằng các signalshould bị bỏ qua.<br />
Bao gồm:<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
Include: <br />
Value: 127<br />
DS51456B trang 216<br />
SIGABRT<br />
2004 Microchip Technology Inc<br />
SCHAR_MIN<br />
Description: Minimum value of a signed char<br />
Include: <br />
Value: -128<br />
SHRT_MAX<br />
Description: Maximum value of a short int<br />
Include: <br />
Value: 32767<br />
SHRT_MIN<br />
Description: Minimum value of a short int<br />
Include: <br />
Value: -32768<br />
Mô tả: Đặt tên cho các tín hiệu chấm dứt bất thường.<br />
Bao gồm:<br />
Prototype: # define SIGABRT<br />
Bình luận: SIGABRTrepresents một tín hiệu chấm dứt bất thường và được sử<br />
dụng trong<br />
kết hợp với tín hiệu raiseor. Các raisebehavior mặc định<br />
(Hành động xác định bởi SIG_DFL) là đầu ra cho dòng sai số chuẩn:<br />
hủy bỏ - chấm dứt<br />
Xem ví dụ đi kèm signalto thấy sử dụng chung của<br />
tên tín hiệu và xử lý tín hiệu.<br />
Ví dụ: # include / * Cho tăng lương, SIGABRT * /<br />
# include / * Cho printf * /
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 213<br />
4.8 LOCALIZATION<br />
This compiler defaults to the C locale and does not support any other locales;<br />
therefore<br />
it does not support the header file locale.h. The following would normally be<br />
found<br />
in this file:<br />
• struct lconv<br />
• NULL<br />
•LC_ALL<br />
• LC_COLLATE<br />
• LC_CTYPE<br />
• LC_MONETARY<br />
• LC_NUMERIC<br />
• LC_TIME<br />
• localeconv<br />
• setlocale<br />
UCHAR_MAX<br />
Description: Maximum value of an unsigned char<br />
Include: <br />
Value: 255<br />
UINT_MAX<br />
Description: Maximum value of an unsigned int<br />
Include: <br />
Value: 65535<br />
ULLONG_MAX<br />
Description: Maximum value of a long long unsigned int<br />
Include: <br />
Value: 18446744073709551615<br />
ULONG_MAX<br />
Description: Maximum value of a long unsigned int<br />
Include: <br />
Value: 4294967295<br />
USHRT_MAX<br />
Description: Maximum value of an unsigned short int<br />
Include: <br />
Value: 65535<br />
dsPIC<br />
®<br />
int main (void)<br />
{<br />
nâng cao (SIGABRT);<br />
printf ("Chương trình không bao giờ đạt ở đây.");<br />
}<br />
Đầu ra:<br />
ABRT<br />
Giải thích:<br />
ABRT viết tắt của "hủy bỏ".<br />
SIGFPE<br />
Mô tả: Tín hiệu báo lỗi dấu chấm động như phân chia cho số không hoặc kết<br />
quả của<br />
phạm vi.<br />
Bao gồm:<br />
Prototype: # define SIGFPE<br />
Bình luận: SIGFPEis sử dụng như một tham số cho raiseand / hoặc tín hiệu. Kh<br />
được sử dụng, hành vi mặc định là in một thông báo lỗi số học và<br />
chấm dứt chương trình gọi điện thoại. Điều này có thể được ghi đè bởi một<br />
người dùng<br />
chức năng xác định các hành động xử lý tín hiệu. Xem signalfor một<br />
ví dụ về một người dùng xác định chức năng.<br />
Ví dụ: # include / * Cho tăng lương, SIGFPE * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
nâng cao (SIGFPE);<br />
printf ("Chương trình không bao giờ đạt ở đây");<br />
}<br />
Đầu ra:<br />
FPE<br />
Giải thích:<br />
FPE là viết tắt của "dấu chấm động lỗi".<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 217<br />
SIGILL<br />
Mô tả: Tín hiệu lệnh bất hợp pháp.<br />
Bao gồm:<br />
Prototype: # define SIGILL<br />
Bình luận: SIGILLis sử dụng như một tham số cho raiseand / hoặc tín hiệu. Khi<br />
được sử dụng, hành vi mặc định là in một mã thực thi không hợp lệ<br />
thông báo và chấm dứt chương trình gọi điện thoại. Điều này có thể được ghi đ
Language Tools Libraries<br />
DS51456B-page 214<br />
2004 Microchip Technology Inc.<br />
4.9 NON-LOCAL JUMPS<br />
The header file setjmp.hconsists of a type, a macro anda function that allow<br />
control<br />
transfers to occur that bypass the normal function call and return process.<br />
jmp_buf<br />
Description: A type that is an array used by setjmpand longjmpto save and<br />
restore the program environment.<br />
Include: <br />
Prototype: typedef int jmp_buf[_NSETJMP];<br />
Remarks: _NSETJMPis defined as 16 + 2 that represents 16 registers and a<br />
32-bit return address.<br />
setjmp<br />
Description: A macro that saves the current state of the program for later use by<br />
longjmp.<br />
Include: <br />
Prototype: #define setjmp(jmp_buf env)<br />
Argument: env variable where environment is stored<br />
Return Value: If the return is from a direct call, setjmpreturns zero. If the return<br />
is<br />
from a call to longjmp, setjmpreturns a non-zero value.<br />
Note:If the argument valfrom longjmpis 0, setjmpreturns 1.<br />
Example: See longjmp.<br />
longjmp<br />
Description: A function that restores the environment saved by setjmp.<br />
Include: <br />
Prototype: void longjmp(jmp_buf env, int val);<br />
Arguments: env variable where environment is stored<br />
val value to be returned to setjmp call.<br />
Remarks: The value parameter valshould be non-zero. If longjmpis invoked<br />
from a nested signal handler (that is, invoked as a result of a signal<br />
raised during the handling of another signal), the behavior is undefined.<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 215<br />
4.10 SIGNAL HANDLING<br />
The header file signal.hconsists of a type, several macros and two functions that<br />
specify how the program handles signals while it is executing. A signal is a<br />
condition<br />
that may be reported during the program execution. Signals are synchronous,<br />
occurring under software control via the raisefunction.<br />
bởi<br />
một chức năng người dùng định nghĩa các hành động xử lý tín hiệu. Xem<br />
signalfor<br />
một ví dụ về một người dùng xác định chức năng.<br />
Ví dụ: # include / * Forraise, SIGILL * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
nâng cao (SIGILL);<br />
printf ("Chương trình không bao giờ đạt ở đây");<br />
}<br />
Đầu ra:<br />
ILL<br />
Giải thích:<br />
ILL là viết tắt của "hướng dẫn bất hợp pháp".<br />
SIGINT<br />
Mô tả: tín hiệu ngắt.<br />
Bao gồm:<br />
Prototype: # define SIGINT<br />
Bình luận: SIGINTis sử dụng như một tham số cho raiseand / hoặc tín hiệu. Kh<br />
được sử dụng, hành vi mặc định là in một thông bị gián đoạn và<br />
chấm dứt chương trình gọi điện thoại. Thismay được ghi đè bởi một người dùng<br />
chức năng xác định các hành động xử lý tín hiệu. Xem signalfor một<br />
ví dụ về một người dùng xác định chức năng.<br />
Ví dụ: # include / * Forraise, SIGINT * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
nâng cao (SIGINT);<br />
printf ("Chương trình không bao giờ đạt ở đây.");<br />
}<br />
Đầu ra:<br />
INT<br />
Giải thích:<br />
INT là viết tắt của "gián đoạn".<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 218<br />
SIGSEGV<br />
2004 Microchip Technology Inc
A signal may be handled by:<br />
• Default handling (SIG_DFL); the signal is treated as a fatal error and<br />
execution<br />
stops<br />
• Ignoring the signal (SIG_IGN); the signal is ignored and control is returned to<br />
the user application<br />
• Handling the signal with a function designated via signal.<br />
By default all signals are handled by the default handler, which is identified by<br />
SIG_DFL.<br />
The type sig_atomic_tis an integer type that the program access atomically.<br />
When<br />
this type is used with the keyword volatile, the signal handler can share the data<br />
objects with the rest of the program.<br />
sig_atomic_t<br />
Description: A type used by a signal handler<br />
Include: <br />
Prototype: typedef int sig_atomic_t;<br />
SIG_DFL<br />
Description: Used as the second argument and/or the return value for signalto<br />
specify that the default handler should be used for a specific signal.<br />
Include: <br />
SIG_ERR<br />
Description: Used as the return value for signalwhen it cannot complete a<br />
request due to an error.<br />
Include: <br />
SIG_IGN<br />
Description: Used as the second argument and/or the return value for signalto<br />
specify that the signalshould be ignored.<br />
Include: <br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
Mô tả: Tín hiệu truy cập không hợp lệ để lưu trữ.<br />
Bao gồm:<br />
Prototype: # define SIGSEGV<br />
Bình luận: SIGSEGVis sử dụng như một tham số cho raiseand / hoặc tín<br />
hiệu. Khi<br />
được sử dụng, hành vi mặc định là in một yêu cầu lưu trữ không hợp lệ<br />
thông báo và chấm dứt chương trình gọi điện thoại. Điều này có thể được ghi đ<br />
bởi<br />
một chức năng người dùng định nghĩa các hành động xử lý tín hiệu. Xem<br />
signalfor<br />
một ví dụ về một người dùng xác định chức năng.<br />
Ví dụ: # include / * Cho tăng lương, SIGSEGV * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
nâng cao (SIGSEGV);<br />
printf ("Chương trình không bao giờ đạt ở đây.");<br />
}<br />
Đầu ra:<br />
SEGV<br />
Giải thích:<br />
SEGV viết tắt của "truy cập lưu trữ không hợp lệ".<br />
SIGTERM<br />
Mô tả: Tín hiệu yêu cầu chấm dứt<br />
Bao gồm:<br />
Prototype: # define SIGTERM<br />
Bình luận: SIGTERMis sử dụng như một tham số cho raiseand / hoặc tín<br />
hiệu. Khi<br />
được sử dụng, hành vi mặc định là in một thông báo yêu cầu chấm dứt<br />
và chấm dứt chương trình gọi điện thoại. Điều này có thể được ghi đè bởi một<br />
người dùng<br />
chức năng xác định các hành động xử lý tín hiệu. Xem signalfor một<br />
ví dụ về một người dùng xác định chức năng.<br />
Ví dụ: # include / * Cho tăng lương, SIGTERM * /<br />
DS51456B-page 216<br />
SIGABRT<br />
2004 Microchip Technology Inc.<br />
# include / * Cho printf * /<br />
int main (void)<br />
Description: Name for the abnormal termination signal.<br />
Include: <br />
Prototype: #define SIGABRT<br />
Remarks: SIGABRTrepresents an abnormal termination signal and is used in<br />
conjunction with raiseor signal. The default raisebehavior<br />
(action identified by SIG_DFL) is to output to the standard error stream:<br />
{<br />
nâng cao (SIGTERM);<br />
printf ("Chương trình không bao giờ đạt ở đây.");<br />
}<br />
Đầu ra:<br />
HẠN
abort - terminating<br />
See the example accompanying signalto see general usage of<br />
signal names and signal handling.<br />
Example: #include /* for raise, SIGABRT */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
raise(SIGABRT);<br />
printf("Program never reaches here.");<br />
}<br />
Output:<br />
ABRT<br />
Explanation:<br />
ABRT stands for “abort”.<br />
SIGFPE<br />
Description: Signals floating-point error such as for division by zero or result<br />
out of<br />
range.<br />
Include: <br />
Prototype: #define SIGFPE<br />
Remarks: SIGFPEis used as an argument for raiseand/or signal. When<br />
used, the default behavior is to print an arithmetic error message and<br />
terminate the calling program. This may be overridden by a user<br />
function that defines the signal handler actions. See signalfor an<br />
example of a user defined function.<br />
Example: #include /* for raise, SIGFPE */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
raise(SIGFPE);<br />
printf("Program never reaches here");<br />
}<br />
Output:<br />
FPE<br />
Explanation:<br />
FPE stands for “floating-point error”.<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 217<br />
SIGILL<br />
Giải thích:<br />
HẠN viết tắt của "yêu cầu chấm dứt".<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 219<br />
nâng cao<br />
Mô tả: Báo cáo một tín hiệu đồng bộ.<br />
Bao gồm:<br />
Nguyên mẫu: int tăng (int sig);<br />
Đối số: sig tên tín hiệu<br />
Quay trở lại giá trị: Trả về 0 nếu thành công; nếu không, trả về giá trị khác<br />
không.<br />
Bình luận: raisesends tín hiệu xác định bysig cho chương trình thực hiện.<br />
Ví dụ: # include / * Cho tăng, tín hiệu, * /<br />
/ * SIGILL, SIG_DFL * /<br />
# include / * Cho div, div_t * /<br />
# include / * Cho printf * /<br />
# include / * Cho INTCON1bits * /<br />
khoảng trống __attribute __ ((__ interrupt__))<br />
_MathError (Void)<br />
{<br />
nâng cao (SIGILL);<br />
INTCON1bits.MATHERR = 0;<br />
}<br />
khoảng trống illegalinsn (int idsig)<br />
{<br />
printf ("bất hợp pháp hướng dẫn thực hiện \ n");<br />
exit (1);<br />
}<br />
int main (void)<br />
{<br />
int x, y;<br />
z div_t;<br />
tín hiệu (SIGILL, illegalinsn);<br />
x = 7;<br />
y = 0;<br />
z = div (x, y);<br />
printf ("Chương trình không bao giờ đạt ở đây");<br />
}<br />
Đầu ra:<br />
Hướng dẫn thực hiện bất hợp pháp
Description: Signals illegal instruction.<br />
Include: <br />
Prototype: #define SIGILL<br />
Remarks: SIGILLis used as an argument for raiseand/or signal. When<br />
used, the default behavior is to print an invalid executable code<br />
message and terminate the calling program. This may be overridden by<br />
a user function that defines the signal handler actions. See signalfor<br />
an example of a user defined function.<br />
Example: #include /* forraise, SIGILL */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
raise(SIGILL);<br />
printf("Program never reaches here");<br />
}<br />
Output:<br />
ILL<br />
Explanation:<br />
ILL stands for “illegal instruction”.<br />
SIGINT<br />
Description: Interrupt signal.<br />
Include: <br />
Prototype: #define SIGINT<br />
Remarks: SIGINTis used as an argument for raiseand/or signal. When<br />
used, the default behavior is to print an interruption message and<br />
terminate the calling program. Thismay be overridden by a user<br />
function that defines the signal handler actions. See signalfor an<br />
example of a user defined function.<br />
Example: #include /* forraise, SIGINT */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
raise(SIGINT);<br />
printf("Program never reaches here.");<br />
}<br />
Output:<br />
INT<br />
Explanation:<br />
INT stands for “interruption”.<br />
Giải thích:<br />
Ví dụ này đòi hỏi các mối liên kết p30f6014.gld kịch bản. Có ba<br />
các bộ phận để ví dụ này.<br />
Đầu tiên, một xử lý ngắt được viết cho các vector ngắt<br />
_MathErrorto Xử lý một lỗi toán học bằng cách gửi một lệnh bất hợp pháp<br />
tín hiệu (SIGILL) để chương trình thực hiện. Tuyên bố cuối cùng trong<br />
gián đoạn xử lý xóa cờ ngoại lệ.<br />
Thứ hai, các chức năng illegalinsnwill in một thông báo lỗi và<br />
thoát cuộc gọi.<br />
Thứ ba, chính, tín hiệu (SIGILL, illegalinsn) bộ xử lý<br />
cho SIGILLto chức năng illegalinsn.<br />
Khi một lỗi toán học xảy ra, do một chia cho số không, các _MathError<br />
vector ngắt được gọi, mà lần lượt sẽ nâng cao một tín hiệu rằng sẽ gọi<br />
chức năng xử lý cho SIGILL, đó là chức năng illegalinsn.<br />
Vì vậy, các thông báo lỗi được in và chương trình được chấm dứt.<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 220 2004 Microchip Technology Inc<br />
tín hiệu<br />
Mô tả: Điều khiển gián đoạn xử lý tín hiệu.<br />
Bao gồm:<br />
Nguyên mẫu: void (* tín hiệu (int sig, void (* func) (int))) (int);<br />
Đối số: sig tên tín hiệu<br />
chức năng Func được thực hiện<br />
Quay trở lại giá trị: Trả về giá trị trước đó của Func.<br />
Ví dụ: # include / * Cho tín hiệu, nâng cao, * /<br />
/ * SIGINT, SIGILL, * /<br />
/ * SIG_IGN, và SIGFPE * /<br />
# include / * Cho printf * /<br />
/ * Chức năng xử lý tín hiệu * /<br />
khoảng trống mysigint (int id)<br />
{<br />
printf ("SIGINT nhận \ n");<br />
}<br />
int main (void)<br />
{<br />
/ * Ghi đè mặc định với người dùng xác định chức năng * /<br />
tín hiệu (SIGINT, mysigint);
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 218 2004 Microchip Technology Inc.<br />
SIGSEGV<br />
Description: Signals invalid access to storage.<br />
Include: <br />
Prototype: #define SIGSEGV<br />
Remarks: SIGSEGVis used as an argument for raiseand/or signal. When<br />
used, the default behavior is to print an invalid storage request<br />
message and terminate the calling program. This may be overridden by<br />
a user function that defines the signal handler actions. See signalfor<br />
an example of a user defined function.<br />
Example: #include /* for raise, SIGSEGV */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
raise(SIGSEGV);<br />
printf("Program never reaches here.");<br />
}<br />
Output:<br />
SEGV<br />
Explanation:<br />
SEGV stands for “invalid storage access”.<br />
SIGTERM<br />
Description: Signals a termination request<br />
Include: <br />
Prototype: #define SIGTERM<br />
Remarks: SIGTERMis used as an argument for raiseand/or signal. When<br />
used, the default behavior is to print a termination request message<br />
and terminate the calling program. This may be overridden by a user<br />
function that defines the signal handler actions. See signalfor an<br />
example of a user defined function.<br />
Example: #include /* for raise, SIGTERM */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
raise(SIGTERM);<br />
printf("Program never reaches here.");<br />
nâng cao (SIGINT);<br />
/ * Bỏ qua xử lý tín hiệu * /<br />
tín hiệu (SIGILL, SIG_IGN);<br />
nâng cao (SIGILL);<br />
printf ("SIGILL đã bị bỏ qua \ n");<br />
/ * Sử dụng tín hiệu mặc định xử lý * /<br />
nâng cao (SIGFPE);<br />
printf ("Chương trình không bao giờ đạt ở đây.");<br />
}<br />
Đầu ra:<br />
SIGINT nhận<br />
SIGILL đã bị bỏ qua<br />
FPE<br />
Giải thích:<br />
Các chức năng xử lý tín hiệu mysigintis người dùng định nghĩa cho SIGINT.<br />
Bên trong chương trình chính, chức năng signalis gọi thành lập<br />
xử lý tín hiệu (mysigint) cho SIGINTthat tín hiệu sẽ ghi đè lên<br />
hành động mặc định. Chức năng raiseis gọi đến báo tín hiệu<br />
SIGINT. Điều này làm cho xử lý tín hiệu cho SIGINTto sử dụng<br />
người dùng định nghĩa chức năng (mysigint) như là xử lý tín hiệu để nó in<br />
"SIGINT nhận được" tin nhắn.<br />
Tiếp theo, chức năng signalis kêu gọi thiết lập xử lý tín hiệu<br />
SIG_IGNfor các SIGILL tín hiệu. Các SIG_IGNis liên tục được sử dụng để<br />
chỉ ra shouldbe tín hiệu bỏ qua. Chức năng raiseis kêu gọi<br />
báo cáo SIGILLthat tín hiệu được bỏ qua.<br />
Chức năng raiseis gọi một lần nữa để báo cáo SIGFPE tín hiệu. Kể từ<br />
không có người sử dụng được xác định chức năng cho SIGFPE, xử lý tín hiệu<br />
mặc định<br />
được sử dụng để thông báo "FPE" được in (viết tắt của<br />
"Lỗi số học - chấm dứt") Sau đó, chương trình gọi là.<br />
chấm dứt. Các printfstatement không bao giờ đạt được.<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 221<br />
4.11 DANH MỤC LUẬN BIẾN<br />
Các tập tin tiêu đề stdarg.hsupports chức năng với danh sách đối số biến. Điều<br />
này cho phép<br />
chức năng để có những lập luận mà không cần khai báo tham số tương ứng. Có<br />
phải có ít nhất một đối số được đặt tên. Các đối số biến được biểu diễn bằng<br />
bầu dục (...). Một đối tượng của loại va_listmust được khai báo trong các chức<br />
năng để giữ<br />
các đối số. va_startwill khởi tạo biến một danh sách đối số, va_argwill
}<br />
Output:<br />
TERM<br />
Explanation:<br />
TERM stands for “termination request”.<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 219<br />
raise<br />
Description: Reports a synchronous signal.<br />
Include: <br />
Prototype: int raise(int sig);<br />
Argument: sig signal name<br />
Return Value: Returns a 0 if successful; otherwise, returns a nonzero value.<br />
Remarks: raisesends the signal identified bysig to the executing program.<br />
Example: #include /*for raise, signal, */<br />
/* SIGILL, SIG_DFL */<br />
#include /* for div, div_t */<br />
#include /* for printf */<br />
#include /*for INTCON1bits */<br />
void __attribute__((__interrupt__))<br />
_MathError(void)<br />
{<br />
raise(SIGILL);<br />
INTCON1bits.MATHERR = 0;<br />
}<br />
void illegalinsn(int idsig)<br />
{<br />
printf("Illegal instruction executed\n");<br />
truy cập vào danh sách đối số, và va_endwill chấm dứt việc sử dụng của các đố<br />
số.<br />
va_list<br />
Mô tả: Các loại va_listdeclares một biến mà sẽ đề cập đến từng đối số<br />
trong một danh sách đối số chiều dài thay đổi.<br />
Bao gồm:<br />
Ví dụ: Xem va_arg.<br />
va_arg<br />
Mô tả: Được tranh luận hiện nay<br />
Bao gồm:<br />
Prototype: va_arg # define (va_list ap, Ty)<br />
Đối số: ap con trỏ đến danh sách các đối số<br />
Ty loại đối số được lấy ra<br />
Quay trở lại giá trị: Trả về đối số hiện nay<br />
Bình luận: va_startmust được gọi trước khi va_arg.<br />
Ví dụ: # include / * Cho printf * /<br />
# include / * Cho va_arg, va_start,<br />
va_list, va_end * /<br />
khoảng trống tprint (const char * fmt, ...)<br />
{<br />
va_list ap;<br />
va_start (ap, fmt);<br />
trong khi (* fmt)<br />
{<br />
chuyển đổi (* fmt)<br />
{<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
exit(1);<br />
}<br />
int main(void)<br />
{<br />
int x, y;<br />
div_t z;<br />
DS51456B trang 222<br />
trường hợp '%':<br />
fmt ++;<br />
if (* fmt == 'd')<br />
{<br />
int d = va_arg (ap, int);<br />
2004 Microchip Technology Inc<br />
signal(SIGILL, illegalinsn);<br />
x = 7;<br />
y = 0;<br />
z = div(x, y);<br />
printf("Program never reaches here");<br />
printf (" là một số nguyên \ n", d);<br />
}<br />
else if (* == fmt 's')<br />
{<br />
char * s = va_arg (ap, char *);
}<br />
Output:<br />
Illegal instruction executed<br />
Explanation:<br />
This example requires the linker script p30f6014.gld. There are three<br />
parts to this example.<br />
First, an interrupt handler is written for the interrupt vector<br />
_MathErrorto handle a math error by sending an illegal instruction<br />
signal (SIGILL)to the executing program. The last statement in<br />
the interrupt handler clears the exception flag.<br />
Second, the function illegalinsnwill print an error message and<br />
call exit.<br />
Third, in main, signal (SIGILL, illegalinsn)sets the handler<br />
for SIGILLto the function illegalinsn.<br />
When a math error occurs, due to a divide by zero, the _MathError<br />
interrupt vector is called, which in turn will raise a signal that will call the<br />
handler function for SIGILL, which is the function illegalinsn.<br />
Thus error messages are printed and the program is terminated.<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 220 2004 Microchip Technology Inc.<br />
signal<br />
Description: Controls interrupt signal handling.<br />
Include: <br />
Prototype: void (*signal(int sig, void(*func)(int)))(int);<br />
Arguments: sig signal name<br />
func function to be executed<br />
Return Value: Returns the previous value of func.<br />
Example: #include /* for signal, raise, */<br />
/* SIGINT, SIGILL, */<br />
/* SIG_IGN, and SIGFPE */<br />
#include /* for printf */<br />
/* Signal handler function */<br />
void mysigint(int id)<br />
{<br />
printf("SIGINT received\n");<br />
}<br />
int main(void)<br />
printf (" là một chuỗi \ n", s);<br />
}<br />
khác<br />
{<br />
printf ("%%% c là một định dạng không rõ \ n",<br />
* Fmt);<br />
}<br />
fmt ++;<br />
phá vỡ;<br />
mặc định:<br />
printf ("% c là không rõ \ n", * fmt);<br />
fmt ++;<br />
phá vỡ;<br />
}<br />
}<br />
va_end (ap);<br />
}<br />
int main (void)<br />
{<br />
tprint (".% d% s% c", 83, "Đây là văn bản.", 'a');<br />
}<br />
Đầu ra:<br />
là một số nguyên<br />
là một chuỗi<br />
. không biết<br />
% C là một định dạng chưa biết<br />
va_arg (Tiếp theo)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 223<br />
4.12 ĐỊNH NGHĨA CHUNG<br />
Các stddef.hconsists tập tin tiêu đề của một số loại và macro có công dụng<br />
chung<br />
trong các chương trình.<br />
va_end<br />
Mô tả: Kết thúc việc sử dụng ap.<br />
Bao gồm:<br />
Prototype: va_end # define (va_list ap)<br />
Đối số: ap con trỏ đến danh sách các đối số<br />
Ghi chú: Sau khi một cuộc gọi đến va_end, các apis con trỏ danh sách đối số<br />
được coi là<br />
không hợp lệ. Cuộc gọi hơn nữa để va_argshould không được thực hiện cho đến
{<br />
/* Override default with user defined function */<br />
signal(SIGINT, mysigint);<br />
raise(SIGINT);<br />
/* Ignore signal handler */<br />
signal(SIGILL, SIG_IGN);<br />
raise(SIGILL);<br />
printf("SIGILL was ignored\n");<br />
/* Use default signal handler */<br />
raise(SIGFPE);<br />
printf("Program never reaches here.");<br />
}<br />
Output:<br />
SIGINT received<br />
SIGILL was ignored<br />
FPE<br />
Explanation:<br />
The function mysigintis the user-defined signal handler for SIGINT.<br />
Inside the main program, the function signalis called to set up the<br />
signal handler (mysigint) for the signal SIGINTthat will override the<br />
default actions. The function raiseis called to report the signal<br />
SIGINT. This causes the signal handler for SIGINTto use the<br />
user-defined function (mysigint) as the signal handler so it prints the<br />
"SIGINT received" message.<br />
Next, the function signalis called to set up the signal handler<br />
SIG_IGNfor the signal SIGILL. The constant SIG_IGNis used to<br />
indicate the signal shouldbe ignored. The function raiseis called to<br />
report the signal SIGILLthat is ignored.<br />
The function raiseis called again to report the signal SIGFPE. Since<br />
there is no user defined function for SIGFPE, the default signal handler<br />
is used so the message "FPE" is printed (which stands for<br />
"arithmetic error - terminating”.) Then the calling program is<br />
terminated. The printfstatement is never reached.<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 221<br />
4.11 VARIABLE ARGUMENT LISTS<br />
The header file stdarg.hsupports functions with variable argument lists. This<br />
allows<br />
functions to have arguments without corresponding parameter declarations.<br />
There<br />
khi tới<br />
va_start. Trong MPLAB C30, va_enddoes gì, vì vậy cuộc gọi này không phải là<br />
cần thiết, nhưng nên được sử dụng để có thể đọc và tính di động.<br />
Ví dụ: Xem va_arg.<br />
va_start<br />
Mô tả: Thiết lập con trỏ luận APTO đối số tùy chọn đầu tiên trong<br />
danh sách đối số chiều dài thay đổi<br />
Bao gồm:<br />
Prototype: va_start # define (va_list ap, last_arg)<br />
Đối số: ap con trỏ đến danh sách các đối số<br />
last_arg tên đối số cuối cùng trước khi các đối số tùy chọn<br />
Ví dụ: Xem va_arg.<br />
ptrdiff_t<br />
Mô tả: Các loại kết quả ofsubtracting hai con trỏ.<br />
Bao gồm:<br />
size_t<br />
Mô tả: Các loại kết quả của sizeofoperator.<br />
Bao gồm:<br />
wchar_t<br />
Mô tả: Một loại chứa một giá trị nhân vật rộng.<br />
Bao gồm:<br />
NULL<br />
Mô tả: Giá trị của một con trỏ hằng null.<br />
Bao gồm:<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 224<br />
offsetof<br />
2004 Microchip Technology Inc<br />
Mô tả: Cung cấp cho bù đắp của một thành viên cơ cấu từ đầu<br />
cấu trúc.<br />
Bao gồm:<br />
Prototype: # define offsetof (T, MBR)<br />
Đối số: tname cấu trúc<br />
MBR tên của thành viên trong cấu trúc T<br />
Quay trở lại giá trị: Trả về bù đắp bằng byte của các thành viên được chỉ định<br />
(MBR) từ<br />
bắt đầu của cấu trúc.<br />
Chú ý: offsetofis vĩ mô không xác định cho bitfields. Một thông báo lỗi sẽ<br />
xảy ra nếu bitfields được sử dụng.
must be at least one named argument. The variable arguments are represented<br />
by<br />
ellipses (...). An object of type va_listmust be declared inside the function to<br />
hold<br />
the arguments. va_startwill initialize the variable to an argument list, va_argwill<br />
access the argument list, and va_endwill end the use of the argument.<br />
va_list<br />
Description: The type va_listdeclares a variable that will refer to each argument<br />
in a variable-length argument list.<br />
Include: <br />
Example: See va_arg.<br />
va_arg<br />
Description: Gets the current argument<br />
Include: <br />
Prototype: #define va_arg(va_list ap, Ty)<br />
Argument: ap pointer to list of arguments<br />
Ty type of argument to be retrieved<br />
Return Value: Returns the current argument<br />
Remarks: va_startmust be called before va_arg.<br />
Example: #include /* for printf */<br />
#include /*for va_arg, va_start,<br />
va_list, va_end */<br />
void tprint(const char *fmt, ...)<br />
{<br />
va_list ap;<br />
va_start(ap, fmt);<br />
while (*fmt)<br />
{<br />
switch (*fmt)<br />
{<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
Ví dụ: # include / * Cho offsetof * /<br />
# include / * Cho printf * /<br />
thông tin cấu trúc {<br />
char item1 [5];<br />
int Item2;<br />
char Item3;<br />
nổi item4;<br />
};<br />
int main (void)<br />
{<br />
printf ("Offset của item1 =% d \ n",<br />
offsetof (thông tin cấu trúc, item1));<br />
printf ("Offset của Item2 =% d \ n",<br />
offsetof (thông tin cấu trúc, Item2));<br />
printf ("Offset của Item3 =% d \ n",<br />
offsetof (thông tin cấu trúc, Item3));<br />
printf ("Offset của item4 =% d \ n",<br />
offsetof (thông tin cấu trúc, item4));<br />
}<br />
Đầu ra:<br />
Offset của item1 = 0<br />
Offset của Item2 = 6<br />
Offset của Item3 = 8<br />
Offset của item4 = 10<br />
Giải thích:<br />
Chương trình này cho thấy sự bù đắp bằng byte của mỗi thành viên trong cấu<br />
trúc từ<br />
bắt đầu của cấu trúc. Mặc dù item1is chỉ 5 byte (char<br />
item1 [5]), đệm được thêm vào để địa chỉ của item2falls trên<br />
thậm chí ranh giới. Điều tương tự cũng xảy ra với Item3; nó là 1 byte (char<br />
Item3) với 1 byte padding.<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 225<br />
DS51456B-page 222<br />
case '%':<br />
fmt++;<br />
if (*fmt == 'd')<br />
2004 Microchip Technology Inc.<br />
4.13 Vào và đầu ra<br />
Các stdio.hconsists tập tin tiêu đề của các loại, macro và các chức năng cung<br />
cấp hỗ trợ<br />
để thực hiện các hoạt động đầu vào và đầu ra trên các tập tin và suối. Khi một<br />
tập tin được mở ra nó là<br />
{<br />
int d = va_arg(ap, int);<br />
printf(" is an integer\n",d);<br />
kết hợp với một dòng suối. Một dòng là một đường ống dẫn cho các luồng dữ<br />
liệu vào và ra khỏi các tập tin.<br />
Bởi vì hệ thống khác nhau sử dụng các thuộc tính khác nhau, dòng cung cấp<br />
đồng đều hơn
}<br />
else if (*fmt == 's')<br />
{<br />
char *s = va_arg(ap, char*);<br />
printf(" is a string\n", s);<br />
}<br />
else<br />
{<br />
printf("%%%c is an unknown format\n",<br />
*fmt);<br />
}<br />
fmt++;<br />
break;<br />
default:<br />
printf("%c is unknown\n", *fmt);<br />
fmt++;<br />
break;<br />
}<br />
}<br />
va_end(ap);<br />
}<br />
int main(void)<br />
{<br />
tprint("%d%s.%c", 83, "This is text.", 'a');<br />
}<br />
Output:<br />
is an integer<br />
is a string<br />
. is unknown<br />
%c is an unknown format<br />
va_arg (Continued)<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 223<br />
4.12 COMMON DEFINITIONS<br />
The header file stddef.hconsists of several types and macros that are of general<br />
use<br />
in programs.<br />
va_end<br />
Description: Ends the use of ap.<br />
bất động sản để cho phép đọc và viết các tập tin.<br />
Streams có thể dòng văn bản hoặc dòng nhị phân. Dòng văn bản bao gồm một<br />
chuỗi các<br />
nhân vật chia thành dòng. Mỗi dòng được kết thúc bằng một dòng mới ('\ n')<br />
nhân vật.<br />
Các nhân vật có thể được thay đổi trong internalrepresentation của họ, đặc biệt<br />
là liên quan đến<br />
kết thúc dòng. Dòng nhị phân bao gồm chuỗi các byte thông tin. Các byte<br />
chuyển đến các dòng nhị phân không altered.There có khái niệm về dòng, tập<br />
tin là<br />
chỉ là một loạt các byte.<br />
Khi khởi động ba dòng sẽ được tự động mở ra: stdin, stdout, và stderr.<br />
stdinprovides một dòng cho đầu vào tiêu chuẩn, stdoutis đầu ra tiêu chuẩn và<br />
thiết bị lỗi chuẩn<br />
là sai số chuẩn. Dòng bổ sung có thể được tạo ra với fopenfunction. Xem<br />
fopenfor các loại khác nhau của tập tin truy cập được phép. Những loại truy cập<br />
được<br />
được sử dụng bởi fopenand freopen.<br />
Các FILEis loại được sử dụng để lưu trữ thông tin về mỗi dòng mở tập tin. Nó<br />
bao gồm<br />
những thứ như chỉ số lỗi, cuối cùng các chỉ số tập tin, thị vị trí của tập tin, và<br />
các<br />
tình trạng thông tin nội bộ cần thiết để kiểm soát một dòng suối. Nhiều chức<br />
năng trong stdio<br />
sử dụng FILEas một cuộc tranh cãi.<br />
Có ba loại đệm: bộ đệm, dòng đệm và đệm đầy đủ. Unbuffered có nghĩa là một<br />
nhân vật hay byte được chuyển giao tại một thời điểm. Dòng đệm và thu thập<br />
những<br />
chuyển toàn bộ một dòng một lúc (ví dụ, các ký tự xuống dòng cho biết kết thú<br />
của một dòng.)<br />
Đệm đầy đủ cho phép các khối kích thước tùy ý được truyền đi. Các chức năng<br />
setbufand tập setvbufcontrol đệm.<br />
Các stdio.hfile cũng chứa các chức năng sử dụng các định dạng đầu vào và đầu<br />
ra. Các đầu vào<br />
định dạng, hoặc các định dạng quét, được sử dụng để đọc dữ liệu. Mô tả của họ<br />
có thể được tìm thấy<br />
dưới scanf, nhưng họ cũng được sử dụng bởi sscanf fscanfand. Các định dạng<br />
đầu ra, hoặc<br />
định dạng in ấn, được sử dụng để ghi dữ liệu. Mô tả của họ có thể được tìm thấy<br />
dưới printf.<br />
Các định dạng in ấn cũng được sử dụng bởi fprintf, sprintf, vfprintf, vprintfand<br />
vsprintf.<br />
Một số tùy chọn trình biên dịch có thể ảnh hưởng đến cách tiêu chuẩn I / O thực<br />
hiện. Trong một nỗ lực để cung cấp<br />
một phiên bản phù hợp hơn của thói quen định dạng I / O, dây chuyền công cụ<br />
có thể chuyển đổi một cuộc gọi<br />
đến một chức năng scanfstyle printfor một cuộc gọi khác nhau. Các tùy chọn<br />
được tóm tắt<br />
dưới đây:
Include: <br />
Prototype: #define va_end(va_list ap)<br />
Argument: ap pointer to list of arguments<br />
Remarks: After a call to va_end, the argument list pointer apis considered to be<br />
invalid. Further calls to va_argshould not be made until the next<br />
va_start. In MPLAB C30, va_enddoes nothing, so this call is not<br />
necessary but should be used for readability and portability.<br />
Example: See va_arg.<br />
va_start<br />
Description: Sets the argument pointer apto first optional argument in the<br />
variable-length argument list<br />
Include: <br />
Prototype: #define va_start(va_list ap, last_arg)<br />
Argument: ap pointer to list of arguments<br />
last_arg last named argument before the optional arguments<br />
Example: See va_arg.<br />
ptrdiff_t<br />
Description: The type of the result ofsubtracting two pointers.<br />
Include: <br />
size_t<br />
Description: The type of the result of the sizeofoperator.<br />
Include: <br />
wchar_t<br />
Description: A type that holds a wide character value.<br />
Include: <br />
NULL<br />
Description: The value of a null pointer constant.<br />
Include: <br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 224 2004 Microchip Technology Inc.<br />
offsetof<br />
Description: Gives the offset of a structure member from the beginning of the<br />
structure.<br />
Include: <br />
Prototype: #define offsetof(T, mbr)<br />
Arguments: Tname of structure<br />
mbr name of member in structure T<br />
• Các -msmart-iooption, khi được kích hoạt, sẽ cố gắng để chuyển đổi printf,<br />
scanfand chức năng khác sử dụng các định dạng đầu ra đầu vào cho một số<br />
nguyên chỉ<br />
biến thể. Các chức năng tương tự như các hình thức tiêu chuẩn C, trừ đi<br />
hỗ trợ cho đầu ra nổi điểm. -msmart-io = 0disables tính năng này và không có<br />
chuyển đổi sẽ diễn ra. -msmart-io = 1or -msmart-io (mặc định) sẽ<br />
chuyển đổi một cuộc gọi chức năng nếu có thể chứng minh rằng một chức năng<br />
I / O sẽ không bao giờ được trình bày với một chuyển đổi dấu chấm động. -<br />
msmart-io = 2is lạc quan hơn<br />
mặc định và sẽ cho rằng chuỗi định dạng không đổi hoặc<br />
chuỗi định dạng không biết sẽ không có một định dạng dấu chấm động. Trong<br />
trường hợp<br />
-msmart-io = 2is sử dụng với một định dạng dấu chấm động, bức thư định dạng<br />
sẽ xuất hiện<br />
như văn bản đen và số tương ứng của nó sẽ không được tiêu thụ.<br />
• -fno-ngắn doublewill gây ra trình biên dịch để tạo ra các cuộc gọi đến định<br />
dạng I / O<br />
thói quen hỗ trợ doubleas thể nó là một doubletype dài.<br />
Module trộn biên dịch với các tùy chọn này có thể dẫn đến một kích thước thực<br />
thi lớn hơn, hoặc<br />
thực hiện không đúng nếu lớn và nhỏ dữ liệu tăng gấp đôi kích thước được chia<br />
sẻ trên các mô-đun.<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 226<br />
FILE<br />
2004 Microchip Technology Inc<br />
Mô tả: Cửa hàng thông tin về một dòng tập tin.<br />
Bao gồm:<br />
fpos_t<br />
Mô tả: Loại một biến được sử dụng để lưu trữ một vị trí tập tin.<br />
Bao gồm:<br />
size_t<br />
Mô tả: Các loại kết quả của sizeofoperator.<br />
Bao gồm:<br />
_IOFBF<br />
Mô tả: Cho biết đầy đủ đệm.<br />
Bao gồm:<br />
Ghi chú: Được sử dụng bởi các chức năng setvbuf.<br />
_IOLBF<br />
Mô tả: Cho dòng đệm.<br />
Bao gồm:<br />
Ghi chú: Được sử dụng bởi các chức năng setvbuf.
Return Value: Returns the offset in bytes of the specified member (mbr) from<br />
the<br />
beginning of the structure.<br />
Remarks: The macro offsetofis undefined for bitfields. An error message will<br />
occur if bitfields are used.<br />
Example: #include /* for offsetof */<br />
#include /* for printf */<br />
struct info {<br />
char item1[5];<br />
int item2;<br />
char item3;<br />
float item4;<br />
};<br />
int main(void)<br />
{<br />
printf("Offset of item1 = %d\n",<br />
offsetof(struct info,item1));<br />
printf("Offset of item2 = %d\n",<br />
offsetof(struct info,item2));<br />
printf("Offset of item3 = %d\n",<br />
offsetof(struct info,item3));<br />
printf("Offset of item4 = %d\n",<br />
offsetof(struct info,item4));<br />
}<br />
Output:<br />
Offset of item1 = 0<br />
Offset of item2 = 6<br />
Offset of item3 = 8<br />
Offset of item4 = 10<br />
Explanation:<br />
This program shows the offset in bytes of each structure member from<br />
the start of the structure. Although item1is only 5 bytes (char<br />
item1[5]), padding is added so the address of item2falls on an<br />
even boundary. The same occurs with item3; it is 1 byte (char<br />
item3) with 1 byte of padding.<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 225<br />
4.13 INPUT AND OUTPUT<br />
The header file stdio.hconsists of types, macros and functions that provide<br />
support<br />
_IONBF<br />
Mô tả: Cho biết không có đệm.<br />
Bao gồm:<br />
Ghi chú: Được sử dụng bởi các chức năng setvbuf.<br />
BUFSIZ<br />
Mô tả: Xác định kích thước của bộ đệm được sử dụng bởi các chức năng setbuf<br />
Bao gồm:<br />
Giá trị: 512<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 227<br />
EOF<br />
Mô tả: Một số âm cho thấy các tập tin end-of-đã đạt tới hoặc<br />
báo cáo một điều kiện lỗi.<br />
Bao gồm:<br />
Ghi chú: Nếu một tập tin end-of-là gặp phải, chỉ số cuối cùng của tập tin được<br />
thiết lập. Nếu một<br />
tình trạng lỗi gặp phải, chỉ số lỗi được thiết lập. Lỗi<br />
điều kiện bao gồm ghi errorsand đầu vào hoặc đọc lỗi.<br />
FILENAME_MAX<br />
Mô tả: Tối đa số ký tự trong một tên tập tin bao gồm cả null<br />
terminator.<br />
Bao gồm:<br />
Giá trị: 260<br />
FOPEN_MAX<br />
Mô tả: Xác định số lượng tối đa của tập tin có thể được mở cùng một lúc<br />
Bao gồm:<br />
Giá trị: 8<br />
Bình luận: stderr, stdinand stdoutare bao gồm trong FOPEN_MAXcount.<br />
L_tmpnam<br />
Mô tả: Xác định số lượng ký tự cho tên tập tin tạm thời dài nhất<br />
tạo ra bởi các chức năng tmpnam.<br />
Bao gồm:<br />
Giá trị: 16<br />
Bình luận: L_tmpnamis sử dụng để xác định kích thước của mảng được sử dụng<br />
bởi tmpnam.<br />
NULL<br />
Mô tả: Giá trị của một con trỏ hằng rỗng<br />
Bao gồm:<br />
SEEK_CUR<br />
Mô tả: Chỉ ra rằng fseekshould tìm kiếm từ vị trí hiện tại của tập tin
to perform input and output operations on files and streams. When a file is<br />
opened it is<br />
associated with a stream. A stream is a pipeline for the flow of data into and out<br />
of files.<br />
Because different systems use different properties, the stream provides more<br />
uniform<br />
properties to allow reading and writing of the files.<br />
Streams can be text streams or binary streams. Text streams consist of a<br />
sequence of<br />
characters divided into lines. Each line is terminated with a newline ('\n')<br />
character.<br />
The characters may be altered in their internalrepresentation, particularly in<br />
regards to<br />
line endings. Binary streams consist of sequences of bytes of information. The<br />
bytes<br />
transmitted to the binary stream are not altered.There is no concept of lines, the<br />
file is<br />
just a series of bytes.<br />
At startup three streams are automatically opened: stdin, stdout, and stderr.<br />
stdinprovides a stream for standard input, stdoutis standard output and stderr<br />
is the standard error. Additional streams may be created with the fopenfunction.<br />
See<br />
fopenfor the different types of file access that are permitted. These access types<br />
are<br />
used by fopenand freopen.<br />
The type FILEis used to store information about each opened file stream. It<br />
includes<br />
such things as error indicators, end of file indicators, file position indicators, and<br />
other<br />
internal status information needed to control a stream. Many functions in the<br />
stdio<br />
use FILEas an argument.<br />
There are three types of buffering: unbuffered, line buffered and fully buffered.<br />
Unbuffered means a character or byte is transferred one at a time. Line buffered<br />
collects and<br />
transfers an entire line at a time (i.e., the newline character indicates the end of a<br />
line.)<br />
Fully buffered allows blocks of an arbitrary size to be transmitted. The functions<br />
setbufand setvbufcontrol file buffering.<br />
The stdio.hfile also contains functions that use input and output formats. The<br />
input<br />
formats, or scan formats, are used for reading data. Their descriptions can be<br />
found<br />
under scanf, but they are also used by fscanfand sscanf. The output formats, or<br />
print formats, are used for writing data. Their descriptions can be found under<br />
printf.<br />
These print formats are also used by fprintf, sprintf, vfprintf, vprintfand<br />
con trỏ<br />
Bao gồm:<br />
Ví dụ: Xem ví dụ cho fseek.<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 228 2004 Microchip Technology Inc<br />
SEEK_END<br />
Mô tả: Chỉ ra rằng fseekshould tìm kiếm từ khi kết thúc tập tin.<br />
Bao gồm:<br />
Ví dụ: Xem ví dụ cho fseek.<br />
SEEK_SET<br />
Mô tả: Chỉ ra rằng fseekshould tìm kiếm từ đầu của tập tin.<br />
Bao gồm:<br />
Ví dụ: Xem ví dụ cho fseek.<br />
stderr<br />
Mô tả: File con trỏ đến dòng lỗi chuẩn.<br />
Bao gồm:<br />
stdin<br />
Mô tả: File con trỏ đến dòng đầu vào tiêu chuẩn.<br />
Bao gồm:<br />
thiết bị xuất chuẩn<br />
Mô tả: File con trỏ đến dòng đầu ra tiêu chuẩn.<br />
Bao gồm:<br />
TMP_MAX<br />
Mô tả: Số lượng tối đa của tên tập tin duy nhất chức năng tmpnamcan<br />
tạo ra.<br />
Bao gồm:<br />
Giá trị: 32<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 229<br />
clearerr<br />
Mô tả: Cấu hình lại các indictor lỗi cho các dòng<br />
Bao gồm:<br />
Prototype: void clearerr (FILE * stream);<br />
Đối số: streamstream để thiết lập lại các chỉ số lỗi<br />
Ghi chú: Các chức năng xóa các chỉ số cuối cùng của tập tin và báo lỗi cho cho<br />
dòng (ví dụ, feofand ferrorwill return false sau khi chức năng<br />
clearerris gọi.)
vsprintf.<br />
Certain compiler options may affect how standard I/O performs. In an effort to<br />
provide<br />
a more tailored version of the formatted I/O routines, the tool chain may convert<br />
a call<br />
to a printfor scanfstyle function to a different call. The options are summarized<br />
below:<br />
•The -msmart-iooption, when enabled, will attempt to convert printf,<br />
scanfand other functions that use the input output formats to an integer only<br />
variant. The functionality is the same as that of the C standard forms, minus the<br />
support for floating point output. -msmart-io=0disables this feature and no<br />
conversion will take place. -msmart-io=1or -msmart-io(the default) will<br />
convert a function call if it can be proven that an I/O function will never be<br />
presented with a floating point conversion. -msmart-io=2is more optimistic than<br />
the default and will assume that non-constant format strings or otherwise<br />
unknown format strings will not contain a floating-point format. In the event<br />
that<br />
-msmart-io=2is used with a floating-point format, the format letter will appear<br />
as literal text and its corresponding argument will not be consumed.<br />
• -fno-short-doublewill cause the compiler to generate calls to formatted I/O<br />
routines that support doubleas if it were a long doubletype.<br />
Mixing modules compiled with these options may result in a larger executable<br />
size, or<br />
incorrect execution if large and small double-sized data is shared across<br />
modules.<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
Ví dụ: / * Chương trình này sẽ cố gắng để viết một tập tin đó là * /<br />
/ * Chỉ đọc. Điều này làm cho chỉ số lỗi để * /<br />
/ * Được thiết lập. Chức năng ferror được sử dụng để kiểm tra * /<br />
/ * Chỉ số lỗi. Chức năng clearerr là * /<br />
/ * Sử dụng để thiết lập lại các errorindicator vì vậy tiếp theo * /<br />
/ * Thời gian ferror được gọi là nó sẽ không báo cáo * /<br />
/ * Lỗi. * /<br />
# include / * Cho ferror, clearerr, * /<br />
/ * Printf, fprintf, fopen, * /<br />
/ * Fclose, FILE, NULL * /<br />
int main (void)<br />
{<br />
FILE * myfile;<br />
if ((myfile = fopen ("sampclearerr.c", "r")) ==<br />
NULL)<br />
printf ("Không thể mở tập tin \ n");<br />
khác<br />
{<br />
fprintf (myfile, "dòng Writethis đến"<br />
"Tập tin. \ N");<br />
if (ferror (myfile))<br />
printf ("Lỗi \ n");<br />
khác<br />
printf ("Không có lỗi \ n");<br />
clearerr (myfile);<br />
if (ferror (myfile))<br />
DS51456B-page 226<br />
FILE<br />
2004 Microchip Technology Inc.<br />
printf ("Vẫn có lỗi \ n");<br />
khác<br />
Description: Stores information for a file stream.<br />
Include: <br />
fpos_t<br />
Description: Type of a variable used to store a file position.<br />
Include: <br />
size_t<br />
Description: The result type of the sizeofoperator.<br />
Include: <br />
_IOFBF<br />
Description: Indicates full buffering.<br />
printf ("Lỗi chỉ thiết lập lại \ n");<br />
fclose (myfile);<br />
}<br />
}<br />
Đầu ra:<br />
Lỗi<br />
Lỗi chỉ thiết lập lại<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
Include: <br />
Remarks: Used by the function setvbuf.<br />
DS51456B trang 230<br />
2004 Microchip Technology Inc
_IOLBF<br />
Description: Indicates line buffering.<br />
Include: <br />
Remarks: Used by the function setvbuf.<br />
_IONBF<br />
Description: Indicates no buffering.<br />
Include: <br />
Remarks: Used by the function setvbuf.<br />
BUFSIZ<br />
Description: Defines the size of the buffer used by the function setbuf.<br />
Include: <br />
Value: 512<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 227<br />
EOF<br />
Description: A negative number indicating the end-of-file has been reached or<br />
to<br />
report an error condition.<br />
Include: <br />
Remarks: If an end-of-file is encountered, the end-of-file indicator is set. If an<br />
error condition is encountered, the error indicator is set. Error<br />
conditions include write errorsand input or read errors.<br />
FILENAME_MAX<br />
Description: Maximum number of characters in a filename including the null<br />
terminator.<br />
Include: <br />
Value: 260<br />
FOPEN_MAX<br />
Description: Defines the maximum number of files that can be simultaneously<br />
open<br />
Include: <br />
Value: 8<br />
Remarks: stderr, stdinand stdoutare included in the FOPEN_MAXcount.<br />
L_tmpnam<br />
Description: Defines the number of characters for the longest temporary<br />
filename<br />
created by the function tmpnam.<br />
Include: <br />
Value: 16<br />
Remarks: L_tmpnamis used to define the size of the array used by tmpnam.<br />
fclose<br />
Mô tả: Đóng một dòng suối.<br />
Bao gồm:<br />
Nguyên mẫu: int fclose (FILE * stream);<br />
Đối số: dòng con trỏ đến dòng đóng cửa<br />
Quay trở lại giá trị: Trả về 0 nếu thành công; nếu không, trả về EOF nếu có sai<br />
sót là<br />
phát hiện.<br />
Bình luận: fclosewrites bất kỳ sản lượng đệm vào tập tin.<br />
Ví dụ: # include / * Cho fopen, fclose, * /<br />
/ * Printf, FILE, NULL, kết thúc tập tin * /<br />
int main (void)<br />
{<br />
FILE * myfile1, * myfile2;<br />
int y;<br />
if ((myfile1 = fopen ("afile1", "w +")) == NULL)<br />
printf ("Không thể mở afile1 \ n");<br />
khác<br />
{<br />
printf ("afile1 được mở \ n");<br />
y = fclose (myfile1);<br />
if (y == EOF)<br />
printf ("afile1 đã không đóng cửa \ n");<br />
khác<br />
printf ("afile1 đã được đóng cửa \ n");<br />
}<br />
}<br />
Đầu ra:<br />
afile1 đã được mở<br />
afile1 đã bị đóng cửa<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 231<br />
feof<br />
Mô tả: Các thử nghiệm về kết thúc của file<br />
Bao gồm:<br />
Nguyên mẫu: int feof (FILE * stream);<br />
Đối số: dòng dòng để kiểm tra kết thúc của file<br />
Quay trở lại giá trị: Trả về giá trị khác không nếu dòng là ở phần cuối của tập<br />
tin; nếu không, trả về số không.<br />
Ví dụ: # include / * Cho feof, fgetc, fputc, * /
NULL<br />
Description: The value of a null pointer constant<br />
Include: <br />
SEEK_CUR<br />
Description: Indicates that fseekshould seek from the current position of the file<br />
pointer<br />
Include: <br />
Example: See example for fseek.<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 228<br />
SEEK_END<br />
2004 Microchip Technology Inc.<br />
Description: Indicates that fseekshould seek from the end of the file.<br />
Include: <br />
Example: See example for fseek.<br />
SEEK_SET<br />
Description: Indicates that fseekshould seek from the beginning of the file.<br />
Include: <br />
Example: See example for fseek.<br />
stderr<br />
Description: File pointer to the standard error stream.<br />
Include: <br />
stdin<br />
Description: File pointer to the standard input stream.<br />
Include: <br />
stdout<br />
Description: File pointer to the standard output stream.<br />
Include: <br />
TMP_MAX<br />
Description: The maximum number of unique filenames the function<br />
tmpnamcan<br />
generate.<br />
Include: <br />
Value: 32<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 229<br />
clearerr<br />
Description: Resets the error indictor for the stream<br />
/ * Fopen, fclose, FILE, * /<br />
/ * NULL * /<br />
int main (void)<br />
{<br />
FILE * myfile;<br />
int y = 0;<br />
if ((myfile = fopen ("afile.txt", "rb")) == NULL)<br />
printf ("Không thể mở tập tin \ n");<br />
khác<br />
{<br />
cho (;;)<br />
{<br />
y = fgetc (myfile);<br />
if (feof (myfile))<br />
phá vỡ;<br />
fputc (y, thiết bị xuất chuẩn);<br />
}<br />
fclose (myfile);<br />
}<br />
}<br />
Đầu vào:<br />
Nội dung afile.txt (được sử dụng như đầu vào):<br />
Đây là một câu.<br />
Đầu ra:<br />
Đây là một câu.<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 232<br />
ferror<br />
2004 Microchip Technology Inc<br />
Mô tả: Kiểm tra xem chỉ số lỗi được thiết lập.<br />
Bao gồm:<br />
Nguyên mẫu: int ferror (FILE * stream);<br />
Đối số: dòng con trỏ đến FILEstructure<br />
Quay trở lại giá trị: Trả về một giá trị khác không hàm IFERROR chỉ số được<br />
thiết lập; nếu không, trả về một<br />
không.<br />
Ví dụ: / * Chương trình này sẽ cố gắng để viết một tập tin đó là * /<br />
/ * Chỉ đọc. Điều này làm cho chỉ số lỗi để * /<br />
/ * Được thiết lập. Các functionferror được sử dụng để kiểm tra * /
Include: <br />
Prototype: void clearerr(FILE *stream);<br />
Argument: streamstream to reset error indicators<br />
Remarks: The function clears the end-of-file and error indicators for the given<br />
stream (i.e., feofand ferrorwill return false after the function<br />
clearerris called.)<br />
Example: /* This program tries to write to a file that is */<br />
/* readonly. This causes the error indicator to */<br />
/* be set. The function ferror is used to check */<br />
/* the error indicator. The function clearerr is */<br />
/* used to reset the errorindicator so the next */<br />
/* time ferror is called it will not report an */<br />
/* error. */<br />
#include /* for ferror, clearerr, */<br />
/* printf, fprintf, fopen,*/<br />
/* fclose, FILE, NULL */<br />
int main(void)<br />
{<br />
FILE *myfile;<br />
if ((myfile = fopen("sampclearerr.c", "r")) ==<br />
NULL)<br />
printf("Cannot open file\n");<br />
else<br />
{<br />
fprintf(myfile, "Writethis line to the "<br />
"file.\n");<br />
if (ferror(myfile))<br />
printf("Error\n");<br />
else<br />
printf("No error\n");<br />
clearerr(myfile);<br />
if (ferror(myfile))<br />
printf("Still has Error\n");<br />
else<br />
printf("Error indicator reset\n");<br />
fclose(myfile);<br />
}<br />
}<br />
Output:<br />
/ * Chỉ số lỗi và tìm ra lỗi. Các * /<br />
/ * Chức năng clearerr được sử dụng để thiết lập lại các lỗi * /<br />
/ * Chỉ nên thời gian ferror tiếp theo được gọi là * /<br />
/ * Nó sẽ không báo lỗi. * /<br />
# include / * Cho ferror, clearerr, * /<br />
/ * Printf, fprintf, * /<br />
/ * Fopen, fclose, * /<br />
/ * FILE, NULL * /<br />
int main (void)<br />
{<br />
FILE * myfile;<br />
if ((myfile = fopen ("sampclearerr.c", "r")) ==<br />
NULL)<br />
printf ("Không thể mở tập tin \ n");<br />
khác<br />
{<br />
fprintf (myfile, "Viết dòng này cho"<br />
"Tập tin. \ N");<br />
if (ferror (myfile))<br />
printf ("Lỗi \ n");<br />
khác<br />
printf ("Không có lỗi \ n");<br />
clearerr (myfile);<br />
if (ferror (myfile))<br />
printf ("Vẫn có lỗi \ n");<br />
khác<br />
printf ("Lỗi chỉ thiết lập lại \ n");<br />
fclose (myfile);<br />
}<br />
}<br />
Đầu ra:<br />
Lỗi<br />
Lỗi chỉ thiết lập lại<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 233<br />
fflush<br />
Mô tả: bừng bộ đệm trong dòng quy định.<br />
Bao gồm:<br />
Nguyên mẫu: int fflush (FILE * stream);
Error<br />
Error indicator reset<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
Đối số: dòng con trỏ tới dòng để tuôn ra.<br />
Quay trở lại giá trị: Trả về EOF nếu gặp lỗi ghi; nếu không, trả về số không cho<br />
thành công.<br />
Ghi chú: Nếu dòng là một con trỏ null, tất cả các bộ đệm đầu ra được ghi vào<br />
tập tin. fflush<br />
không có tác dụng trên một dòng không có bộ đệm.<br />
DS51456B-page 230<br />
fclose<br />
2004 Microchip Technology Inc.<br />
fgetc<br />
Mô tả: Có được một nhân vật từ một dòng suối<br />
Description: Close a stream.<br />
Include: <br />
Prototype: int fclose(FILE *stream);<br />
Argument: stream pointer to the stream to close<br />
Return Value: Returns 0 if successful; otherwise, returns EOF if any errors were<br />
detected.<br />
Remarks: fclosewrites any buffered output to the file.<br />
Example: #include /* for fopen, fclose, */<br />
/* printf,FILE, NULL, EOF */<br />
int main(void)<br />
{<br />
FILE *myfile1, *myfile2;<br />
int y;<br />
if ((myfile1 = fopen("afile1", "w+")) == NULL)<br />
printf("Cannot open afile1\n");<br />
else<br />
{<br />
printf("afile1 was opened\n");<br />
y = fclose(myfile1);<br />
if (y == EOF)<br />
printf("afile1 was not closed\n");<br />
else<br />
printf("afile1 was closed\n");<br />
}<br />
}<br />
Output:<br />
afile1 was opened<br />
afile1 was closed<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 231<br />
feof<br />
Description: Tests for end of file<br />
Bao gồm:<br />
Nguyên mẫu: int fgetc (FILE * stream);<br />
Đối số: dòng con trỏ đến dòng mở<br />
Quay trở lại giá trị: Trả về nhân vật đọc hoặc EOF nếu một lỗi đọc xảy ra hoặc<br />
kết thúc của tập tin<br />
đạt được.<br />
Bình luận: Chức năng đọc ký tự tiếp theo từ dòng đầu vào, tiến bộ<br />
chỉ số tập tin vị trí và trả về ký tự như là một unsigned<br />
charconverted đến một int.<br />
Ví dụ: # include / * Cho fgetc, printf, * /<br />
/ * Fclose, FILE, * /<br />
/ * NULL, kết thúc tập tin * /<br />
int main (void)<br />
{<br />
FILE * buf;<br />
char y;<br />
if ((buf = fopen ("afile.txt", "r")) == NULL)<br />
printf ("Không thể mở afile.txt \ n");<br />
khác<br />
{<br />
y = fgetc (buf);<br />
trong khi (y! = EOF)<br />
{<br />
printf ("% c |", y);<br />
y = fgetc (buf);<br />
}<br />
fclose (buf);<br />
}<br />
}<br />
Đầu vào:<br />
Nội dung afile.txt (được sử dụng như đầu vào):<br />
Ngắn
Include: <br />
Prototype: int feof(FILE *stream);<br />
Argument: stream stream to check for end of file<br />
Return Value: Returns nonzero if stream is at the end of file; otherwise, returns<br />
zero.<br />
Example: #include /* for feof, fgetc, fputc, */<br />
/* fopen, fclose, FILE, */<br />
/* NULL */<br />
Chuỗi dài hơn<br />
Đầu ra:<br />
S | h | o | r | t |<br />
| L | o | n | g | e | r | | s | t | r | i | n | g |<br />
|<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
int main(void)<br />
{<br />
DS51456B trang 234<br />
fgetpos<br />
2004 Microchip Technology Inc<br />
FILE *myfile;<br />
int y = 0;<br />
if( (myfile = fopen( "afile.txt", "rb" )) == NULL )<br />
printf( "Cannot open file\n" );<br />
else<br />
{<br />
for (;;)<br />
{<br />
y = fgetc(myfile);<br />
if (feof(myfile))<br />
break;<br />
fputc(y, stdout);<br />
}<br />
fclose( myfile );<br />
}<br />
}<br />
Input:<br />
Contents of afile.txt(used as input):<br />
This is a sentence.<br />
Output:<br />
This is a sentence.<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
Mô tả: Được vị trí hồ sơ của dòng suối.<br />
Bao gồm:<br />
Nguyên mẫu: int fgetpos (FILE * stream, fpos_t * pos);<br />
Đối số: dòng mục tiêu dòng<br />
pos lưu trữ vị trí, chỉ số<br />
Quay trở lại giá trị: Trả về 0 nếu thành công; nếu không, trả về một giá trị khác<br />
không.<br />
Ghi chú: Các chức năng lưu trữ các tập tin chỉ số vị trí cho các dòng được đưa<br />
ra trong<br />
* Posif thành công, nếu không, fgetpossets errno.<br />
Ví dụ: / * Chương trình này sẽ mở ra một tập tin và đọc byte tại * /<br />
/ * Địa điểm khác nhau. Các fgetpos * /<br />
/ * Chức năng ghi nhận các byte 8. 21 byte * /<br />
/ * Đọc sau đó 18 byte được đọc. Tiếp theo * /<br />
/ * Chức năng fsetpos được thiết lập dựa trên * /<br />
/ * Vị trí fgetpos và theprevious 21 byte * /<br />
/ * Đang đọc lại. * /<br />
# include / * Cho fgetpos, fread, * /<br />
/ * Printf, fopen, fclose, * /<br />
/ * FILE, NULL, perror, * /<br />
/ * Fpos_t, sizeof * /<br />
int main (void)<br />
{<br />
FILE * myfile;<br />
pos fpos_t;<br />
DS51456B-page 232<br />
ferror<br />
2004 Microchip Technology Inc.<br />
char buf [25];<br />
if ((myfile = fopen ("sampfgetpos.c", "rb")) ==<br />
Description: Tests if error indicator is set.<br />
Include: <br />
Prototype: int ferror(FILE *stream);<br />
NULL)<br />
printf ("Không thể mở tập tin \ n");<br />
khác
Argument: stream pointer to FILEstructure<br />
Return Value: Returns a nonzero value iferror indicator is set; otherwise, returns<br />
a<br />
zero.<br />
Example: /* This program tries to write to a file that is */<br />
/* readonly. This causes the error indicator to */<br />
/* be set. The functionferror is used to check */<br />
/* the error indicator and find the error. The */<br />
/* function clearerr is used to reset the error */<br />
/* indicator so the next time ferror is called */<br />
/* it will not report an error. */<br />
#include /* for ferror, clearerr, */<br />
/* printf, fprintf, */<br />
/* fopen, fclose, */<br />
/* FILE, NULL */<br />
int main(void)<br />
{<br />
FILE *myfile;<br />
if ((myfile = fopen("sampclearerr.c", "r")) ==<br />
NULL)<br />
printf("Cannot open file\n");<br />
else<br />
{<br />
fprintf(myfile, "Write this line to the "<br />
"file.\n");<br />
if (ferror(myfile))<br />
printf("Error\n");<br />
else<br />
printf("No error\n");<br />
clearerr(myfile);<br />
if (ferror(myfile))<br />
printf("Still has Error\n");<br />
else<br />
printf("Error indicator reset\n");<br />
fclose(myfile);<br />
}<br />
}<br />
Output:<br />
Error<br />
{<br />
fread (buf, sizeof (char), 8, myfile);<br />
if (fgetpos (myfile, và pos) = 0)<br />
perror ("fgetpos lỗi");<br />
khác<br />
{<br />
fread (buf, sizeof (char), 21 tuổi, myfile);<br />
printf ("Bytes đọc:% .21s \ n", buf);<br />
fread (buf, sizeof (char), 18 tuổi, myfile);<br />
printf ("Bytes đọc:% .18s \ n", buf);<br />
}<br />
if (fsetpos (myfile, và pos) = 0)<br />
perror ("fsetpos lỗi");<br />
fread (buf, sizeof (char), 21 tuổi, myfile);<br />
printf ("Bytes đọc:% .21s \ n", buf);<br />
fclose (myfile);<br />
}<br />
}<br />
Đầu ra:<br />
Byte đọc: chương trình sẽ mở ra một tập tin<br />
Byte đọc: và đọc byte tại<br />
Byte đọc: chương trình sẽ mở ra một tập tin<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 235<br />
fgets<br />
Mô tả: Có được một chuỗi từ một dòng suối<br />
Bao gồm:<br />
Prototype: char * fgets (char * s, int n, FILE * stream);<br />
Đối số: s con trỏ đến chuỗi lưu trữ<br />
n số lượng tối đa của các nhân vật để đọc<br />
dòng con trỏ đến dòng mở.<br />
Quay trở lại giá trị: Trả về một con trỏ đến chuỗi SIF thành công; nếu không, tr<br />
về một null<br />
con trỏ<br />
Bình luận: Chức năng đọc ký tự từ dòng đầu vào và lưu trữ chúng<br />
vào chuỗi trỏ đến bởi suntil nó đã đọc n-1 ký tự, lưu trữ một<br />
xuống dòng nhân vật hoặc thiết lập cuối cùng của tập tin hoặc các chỉ số<br />
lỗi. Nếu bất kỳ<br />
ký tự được lưu trữ, một ký tự null được lưu trữ ngay lập tức sau khi<br />
cuối cùng đọc ký tự trong phần tử tiếp theo của mảng. Nếu các fgetssets
Error indicator reset<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 233<br />
fflush<br />
Description: Flushes the buffer in the specified stream.<br />
Include: <br />
Prototype: int fflush(FILE *stream);<br />
Argument: stream pointer to the stream to flush.<br />
Return Value: Returns EOF if a write error occurs; otherwise, returns zero for<br />
success.<br />
Remarks: If stream is a null pointer, all output buffers are written to files. fflush<br />
has no effect on an unbuffered stream.<br />
fgetc<br />
Description: Get a character from a stream<br />
Include: <br />
Prototype: int fgetc(FILE *stream);<br />
Argument: stream pointer to the open stream<br />
Return Value: Returns the character read or EOF if a read error occurs or end of<br />
file is<br />
reached.<br />
Remarks: The function reads the next character from the input stream, advances<br />
the file-position indicator and returns the character as an unsigned<br />
charconverted to an int.<br />
Example: #include /* for fgetc, printf, */<br />
/* fclose, FILE, */<br />
/* NULL, EOF */<br />
int main(void)<br />
{<br />
FILE *buf;<br />
char y;<br />
if ((buf = fopen("afile.txt", "r")) == NULL)<br />
chỉ số lỗi, nội dung mảng là không xác định.<br />
Ví dụ: # include / * Cho fgets, printf, * /<br />
/ * Fopen, fclose, * /<br />
/ * FILE, NULL * /<br />
# define MAX 50<br />
int main (void)<br />
{<br />
FILE * buf;<br />
char s [MAX];<br />
if ((buf = fopen ("afile.txt", "r")) == NULL)<br />
printf ("Không thể mở afile.txt \ n");<br />
khác<br />
{<br />
trong khi (fgets (s, MAX, buf) = NULL)<br />
{<br />
printf ("% s |", s);<br />
}<br />
fclose (buf);<br />
}<br />
}<br />
Đầu vào:<br />
Nội dung afile.txt (được sử dụng như đầu vào):<br />
Ngắn<br />
Chuỗi dài hơn<br />
Đầu ra:<br />
Ngắn<br />
| Chuỗi dài hơn<br />
|<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
printf("Cannot open afile.txt\n");<br />
else<br />
{<br />
y = fgetc(buf);<br />
DS51456B trang 236<br />
fopen<br />
Mô tả: Mở một tập tin.<br />
Bao gồm:<br />
2004 Microchip Technology Inc<br />
while (y != EOF)<br />
{<br />
printf("%c|", y);<br />
y = fgetc(buf);<br />
Prototype: FILE * fopen (const char * filename, const char * mode);<br />
Tên tên tập tin của tập tin: đối số<br />
loại phương thức truy cập được phép<br />
Quay trở lại giá trị: Trả về một con trỏ đến dòng mở. Nếu chức năng không mộ<br />
con trỏ null
}<br />
fclose(buf);<br />
}<br />
}<br />
Input:<br />
Contents of afile.txt(used as input):<br />
Short<br />
Longer string<br />
Output:<br />
S|h|o|r|t|<br />
|L|o|n|g|e|r| |s|t|r|i|n|g|<br />
|<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 234 2004 Microchip Technology Inc.<br />
fgetpos<br />
Description: Gets the stream's file position.<br />
Include: <br />
Prototype: int fgetpos(FILE *stream, fpos_t *pos);<br />
Arguments: stream target stream<br />
pos position-indicator storage<br />
Return Value: Returns 0 if successful; otherwise, returns a non-zero value.<br />
Remarks: The function stores the file-position indicator for the given stream in<br />
*posif successful, otherwise, fgetpossets errno.<br />
Example: /* This program opens a file and reads bytes at */<br />
/* several different locations. The fgetpos */<br />
/* function notes the 8th byte. 21 bytes are */<br />
/* read then 18 bytes are read. Next the */<br />
/* fsetpos function is set based on the */<br />
/* fgetpos position and theprevious 21 bytes */<br />
/* are reread. */<br />
#include /* for fgetpos, fread, */<br />
/* printf, fopen, fclose, */<br />
/* FILE, NULL, perror, */<br />
/* fpos_t, sizeof */<br />
int main(void)<br />
{<br />
FILE *myfile;<br />
được trả về.<br />
Bình luận: Sau đây là các loại hình truy cập file:<br />
r- mở một tập tin văn bản hiện hành để đọc<br />
w- mở một tập tin văn bản trống cho văn bản. (Một tập tin hiện có sẽ<br />
được ghi đè.)<br />
a-mở một tập tin văn bản để phụ thêm. (Một tập tin được tạo ra nếu nó<br />
không tồn tại.)<br />
rb- mở một tập tin nhị phân hiện có để đọc.<br />
wb- mở một tập tin nhị phân có sản phẩm nào cho văn bản. (Một tập tin hiện có<br />
sẽ được ghi đè.)<br />
ab- mở một tập tin nhị phân để phụ thêm. (Một tập tin được tạo ra nếu nó<br />
không tồn tại.)<br />
r + - mở một tập tin văn bản hiện hành để đọc và viết.<br />
w + - mở một tập tin văn bản trống để đọc và viết. (An<br />
tập tin hiện tại sẽ được ghi đè.)<br />
a + - mở một tập tin văn bản để đọc và phụ thêm. (Một tập tin là<br />
tạo ra nếu nó không tồn tại.)<br />
r + bor rb + - mở một tập tin nhị phân hiện có để đọc và viết.<br />
w + bor wb + - mở một tập tin nhị phân có sản phẩm nào để đọc và viết. (An<br />
tập tin hiện tại sẽ được ghi đè.)<br />
a + ab + bor - mở một tập tin nhị phân để đọc và phụ thêm. (Một tập tin là<br />
tạo ra nếu nó không tồn tại.)<br />
Ví dụ: # include / * Cho fopen, fclose, * /<br />
/ * Printf, FILE, * /<br />
/ * NULL, kết thúc tập tin * /<br />
int main (void)<br />
{<br />
FILE * myfile1, * myfile2;<br />
int y;<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 237<br />
if ((myfile1 = fopen ("afile1", "r")) == NULL)<br />
printf ("Không thể mở afile1 \ n");<br />
khác<br />
{<br />
printf ("afile1 được mở \ n");<br />
y = fclose (myfile1);<br />
if (y == EOF)<br />
printf ("afile1was không đóng cửa \ n");
fpos_t pos;<br />
char buf[25];<br />
if ((myfile = fopen("sampfgetpos.c", "rb")) ==<br />
NULL)<br />
printf("Cannot open file\n");<br />
else<br />
{<br />
fread(buf, sizeof(char), 8, myfile);<br />
if (fgetpos(myfile, &pos) != 0)<br />
perror("fgetpos error");<br />
else<br />
{<br />
fread(buf, sizeof(char), 21, myfile);<br />
printf("Bytes read: %.21s\n", buf);<br />
fread(buf, sizeof(char), 18, myfile);<br />
printf("Bytes read: %.18s\n", buf);<br />
}<br />
if (fsetpos(myfile, &pos) != 0)<br />
perror("fsetpos error");<br />
fread(buf, sizeof(char), 21, myfile);<br />
printf("Bytes read: %.21s\n", buf);<br />
fclose(myfile);<br />
}<br />
}<br />
Output:<br />
Bytes read: program opens a file<br />
Bytes read: and reads bytes at<br />
Bytes read: program opens a file<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 235<br />
fgets<br />
Description: Get a string from a stream<br />
Include: <br />
Prototype: char *fgets(char *s, int n, FILE *stream);<br />
Arguments: s pointer to the storage string<br />
n maximum number of characters to read<br />
stream pointer to the open stream.<br />
Return Value: Returns a pointer to the string sif successful; otherwise, returns a<br />
null<br />
khác<br />
printf ("afile1 đã được đóng cửa \ n");<br />
}<br />
if ((myfile1 = fopen ("afile1", "w +")) == NULL)<br />
printf ("Thứ hai cố gắng, không thể mở afile1 \ n");<br />
khác<br />
{<br />
printf ("Thứ hai cố gắng, afile1 được mở \ n");<br />
y = fclose (myfile1);<br />
if (y == EOF)<br />
printf ("afile1was không đóng cửa \ n");<br />
khác<br />
printf ("afile1 đã được đóng cửa \ n");<br />
}<br />
if ((myfile2 = fopen ("afile2", "w +")) == NULL)<br />
printf ("Không thể mở afile2 \ n");<br />
khác<br />
{<br />
printf ("afile2 được mở \ n");<br />
y = fclose (myfile2);<br />
if (y == EOF)<br />
printf ("afile2was không đóng cửa \ n");<br />
khác<br />
printf ("afile2 đã được đóng cửa \ n");<br />
}<br />
}<br />
Đầu ra:<br />
Không thể mở afile1<br />
Thứ hai cố gắng, afile1 đã được mở<br />
afile1 đã bị đóng cửa<br />
afile2 đã được mở<br />
afile2 đã bị đóng cửa<br />
Giải thích:<br />
afile1must tồn tại trước khi nó có thể được mở ra để đọc (r) hoặc<br />
fopenfunction sẽ thất bại. Nếu fopenfunction mở một tập tin để viết<br />
(W +) nó không phải đã tồn tại. Nếu nó không tồn tại, nó sẽ được tạo ra<br />
và sau đó mở ra.<br />
fopen (Tiếp theo)<br />
dsPIC
pointer<br />
Remarks: The function reads characters from the input stream and stores them<br />
into the string pointed to by suntil it has read n-1 characters, stores a<br />
newline character or sets the end-of-file or error indicators. If any<br />
characters were stored, a null character is stored immediately after the<br />
last read character in the next element of the array. If fgetssets the<br />
error indicator, the array contents are indeterminate.<br />
Example: #include /* for fgets, printf, */<br />
/* fopen, fclose, */<br />
/* FILE, NULL */<br />
#define MAX 50<br />
int main(void)<br />
{<br />
FILE *buf;<br />
char s[MAX];<br />
if ((buf = fopen("afile.txt", "r")) == NULL)<br />
printf("Cannot open afile.txt\n");<br />
else<br />
{<br />
while (fgets(s, MAX, buf) != NULL)<br />
{<br />
printf("%s|", s);<br />
}<br />
fclose(buf);<br />
}<br />
}<br />
Input:<br />
Contents of afile.txt(used as input):<br />
Short<br />
Longer string<br />
Output:<br />
Short<br />
|Longer string<br />
|<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 236 2004 Microchip Technology Inc.<br />
fopen<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 238 2004 Microchip Technology Inc<br />
fprintf<br />
Mô tả: In định dạng dữ liệu vào một dòng.<br />
Bao gồm:<br />
Nguyên mẫu: int fprintf (FILE * stream, const char * format, ...);<br />
Đối số: dòng con trỏ vào dòng, trong đó để dữ liệu đầu ra<br />
định dạng kiểm soát chuỗi định dạng<br />
Đối số tùy chọn ...<br />
Quay trở lại giá trị: Trả về số ký tự được tạo ra hoặc một số âm nếu một<br />
lỗi xảy ra.<br />
Ghi chú: Đối số định dạng có cú pháp tương tự và sử dụng nó có trong<br />
in.<br />
Ví dụ: # include / * Cho fopen, fclose, * /<br />
/ * Fprintf, printf, * /<br />
/ * FILE, NULL * /<br />
int main (void)<br />
{<br />
FILE * myfile;<br />
int y;<br />
char s [] = "chuỗi Printthis";<br />
int x = 1;<br />
char '\ n' a =;<br />
if ((myfile = fopen ("afile", "w")) == NULL)<br />
printf ("Không thể mở afile \ n");<br />
khác<br />
{<br />
y = fprintf (myfile, "% s% d% thời gian c", s, x, a);<br />
printf ("ofcharacters Số in"<br />
"Nộp =% d", y);<br />
fclose (myfile);<br />
}<br />
}<br />
Đầu ra:<br />
Số ký tự được in để nộp = 25<br />
Nội dung afile:<br />
In chuỗi này 1 lần<br />
Thư viện chuẩn C với hàm toán học
Description: Opens a file.<br />
Include: <br />
Prototype: FILE *fopen(const char *filename, const char *mode);<br />
Arguments: filename name of the file<br />
mode type of access permitted<br />
Return Value: Returns a pointer to the open stream. If the function fails a null<br />
pointer<br />
is returned.<br />
Remarks: Following are the types of file access:<br />
r- opens an existing text file for reading<br />
w- opens an empty text file for writing. (An existing file will<br />
be overwritten.)<br />
a- opens a text file for appending. (A file is created if it<br />
doesn't exist.)<br />
rb- opens an existing binary file for reading.<br />
wb- opens an empty binary file for writing. (An existing file<br />
will be overwritten.)<br />
ab- opens a binary file for appending. (A file is created if it<br />
doesn't exist.)<br />
r+- opens an existing text file for reading and writing.<br />
w+- opens an empty text file for reading and writing. (An<br />
existing file will be overwritten.)<br />
a+- opens a text file for reading and appending. (A file is<br />
created if it doesn't exist.)<br />
r+bor rb+- opens an existing binary file for reading and writing.<br />
w+bor wb+- opens an empty binary file for reading and writing. (An<br />
existing file will be overwritten.)<br />
a+bor ab+- opens a binary file for reading and appending. (A file is<br />
created if it doesn't exist.)<br />
Example: #include /* for fopen, fclose, */<br />
/* printf, FILE, */<br />
/* NULL, EOF */<br />
int main(void)<br />
{<br />
FILE *myfile1, *myfile2;<br />
int y;<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 237<br />
if ((myfile1 = fopen("afile1", "r")) == NULL)<br />
2004 Microchip Technology Inc DS51456B trang 239<br />
fputc<br />
Mô tả: Đặt một ký tự dòng.<br />
Bao gồm:<br />
Nguyên mẫu: int fputc (int c, FILE * stream);<br />
Đối số: ký tự c được viết<br />
dòng con trỏ đến dòng mở<br />
Quay trở lại giá trị: Trả về nhân vật được viết orEOF nếu không gặp lỗi ghi.<br />
Ghi chú: Các chức năng ghi các ký tự dòng đầu ra, tiến bộ<br />
chỉ số tập tin vị trí và trả về ký tự như một unsigned char<br />
chuyển đổi sang một int.<br />
Ví dụ: # include / * Cho fputc, kết thúc tập tin, thiết bị xuất chuẩn * /<br />
int main (void)<br />
{<br />
char * y;<br />
char buf [] = "Đây là văn bản \ n";<br />
int x;<br />
x = 0;<br />
cho (y = buf; (x = EOF) && (* y = '\ 0');! y ++!)<br />
{<br />
x = fputc (* y, thiết bị xuất chuẩn);<br />
fputc ('|', thiết bị xuất chuẩn);<br />
}<br />
}<br />
Đầu ra:<br />
T | h | i | s | | i | s | | t | e | x | t |<br />
|<br />
fputs<br />
Mô tả: Đặt một chuỗi các dòng.<br />
Bao gồm:<br />
Nguyên mẫu: int fputs (const char * s, FILE * stream);<br />
Đối số: chuỗi s được viết<br />
dòng con trỏ đến dòng mở<br />
Quay trở lại giá trị: Trả về một giá trị không âm nếu thành công; nếu không, trả<br />
về EOF.<br />
Chú ý: chức năng viết ký tự tothe sản lượng dòng lên đến nhưng không<br />
bao gồm các ký tự null.<br />
Ví dụ: # include / * Cho fputs, thiết bị xuất chuẩn * /<br />
int main (void)<br />
{
printf("Cannot open afile1\n");<br />
else<br />
{<br />
printf("afile1 was opened\n");<br />
y = fclose(myfile1);<br />
if (y == EOF)<br />
printf("afile1was not closed\n");<br />
else<br />
printf("afile1 was closed\n");<br />
}<br />
if ((myfile1 = fopen("afile1", "w+")) == NULL)<br />
printf("Second try,cannot open afile1\n");<br />
else<br />
{<br />
printf("Second try,afile1 was opened\n");<br />
y = fclose(myfile1);<br />
if (y == EOF)<br />
printf("afile1was not closed\n");<br />
else<br />
printf("afile1 was closed\n");<br />
}<br />
if ((myfile2 = fopen("afile2", "w+")) == NULL)<br />
printf("Cannot open afile2\n");<br />
else<br />
{<br />
printf("afile2 was opened\n");<br />
y = fclose(myfile2);<br />
if (y == EOF)<br />
printf("afile2was not closed\n");<br />
else<br />
printf("afile2 was closed\n");<br />
}<br />
}<br />
Output:<br />
Cannot open afile1<br />
Second try, afile1 was opened<br />
afile1 was closed<br />
afile2 was opened<br />
afile2 was closed<br />
char buf [] = "Đây là văn bản \ n";<br />
fputs (buf, thiết bị xuất chuẩn);<br />
fputs ("|", thiết bị xuất chuẩn);<br />
}<br />
Đầu ra:<br />
Đây là văn bản<br />
|<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 240<br />
fread<br />
Mô tả: Đọc dữ liệu từ các dòng suối.<br />
Bao gồm:<br />
2004 Microchip Technology Inc<br />
Prototype: size_t fread (void * ptr, size_t size, nelem size_t,<br />
FILE * stream);<br />
Đối số: ptr con trỏ đến bộ đệm lưu trữ<br />
kích thước kích thước của sản phẩm<br />
số nelem tối đa các mặt hàng được đọc<br />
dòng con trỏ đến dòng<br />
Quay trở lại giá trị: Trả về số yếu tố hoàn toàn đọc lên đến nelemwhose<br />
kích thước được xác định bởi kích thước.<br />
Bình luận: Chức năng đọc ký tự FROMA dòng cho vào bộ đệm<br />
trỏ đến bởi ptruntil các cửa hàng chức năng kích thước * nelemcharacters<br />
hoặc thiết lập cuối cùng của tập tin hoặc chỉ số lỗi. freadreturns n / size trong đó<br />
n là<br />
số ký tự nó đọc. Nếu n không phải là một bội số của kích thước, giá trị<br />
của phần tử cuối cùng là không xác định. Nếu chức năng đặt ra các lỗi<br />
chỉ số, chỉ số tập tin vị trí là không xác định.<br />
Ví dụ: # include / * Cho fread, fwrite, * /<br />
/ * Printf, fopen, fclose, * /<br />
/ * Sizeof, FILE, NULL * /<br />
int main (void)<br />
{<br />
FILE * buf;<br />
int x, numwrote, numread;<br />
nums đôi [10], readnums [10];<br />
if ((buf = fopen ("afile.out", "w +")) = NULL)<br />
{<br />
for (x = 0; x
Explanation:<br />
afile1must exist before it can be opened for reading (r) or the<br />
fopenfunction will fail. If the fopenfunction opens a file for writing<br />
(w+) it does not have to already exist. If it doesn't exist, it will be created<br />
and then opened.<br />
fopen (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 238<br />
fprintf<br />
2004 Microchip Technology Inc.<br />
Description: Prints formatted data to a stream.<br />
Include: <br />
Prototype: int fprintf(FILE *stream, const char *format, ...);<br />
Arguments: stream pointer to the stream in which to output data<br />
format format control string<br />
... optional arguments<br />
Return Value: Returns number of characters generated or a negative number if<br />
an<br />
error occurs.<br />
Remarks: The format argument has the same syntax and use that it has in<br />
print.<br />
Example: #include /* for fopen, fclose, */<br />
/* fprintf, printf, */<br />
/* FILE, NULL */<br />
int main(void)<br />
{<br />
FILE *myfile;<br />
int y;<br />
char s[]="Printthis string";<br />
int x = 1;<br />
char a = '\n';<br />
if ((myfile = fopen("afile", "w")) == NULL)<br />
printf("Cannot open afile\n");<br />
else<br />
{<br />
y = fprintf(myfile, "%s %d time%c", s, x, a);<br />
printf("Number ofcharacters printed "<br />
"to file = %d",y);<br />
{<br />
nums [x] = 10,0 / (x + 1);<br />
printf ("10,0 /% d =% f \ n", x + 1, nums [x]);<br />
}<br />
numwrote = fwrite (nums, sizeof (double),<br />
10, buf);<br />
printf ("đã viết% dnumbers \ n \ n", numwrote);<br />
fclose (buf);<br />
}<br />
khác<br />
printf ("Không thể mở afile.out \ n");<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 241<br />
if ((buf = fopen ("afile.out", "r +")) = NULL)<br />
{<br />
numread = fread (readnums, sizeof (double),<br />
10, buf);<br />
printf ("Đọc% số d \ n", numread);<br />
for (x = 0; x
fclose(myfile);<br />
}<br />
}<br />
Output:<br />
Number of characters printed to file = 25<br />
Contents of afile:<br />
Print this string 1 time<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 239<br />
fputc<br />
Description: Puts a character to the stream.<br />
Include: <br />
Prototype: int fputc(int c, FILE *stream);<br />
Arguments: c character to be written<br />
stream pointer to the open stream<br />
Return Value: Returns the character written orEOF if a write error occurs.<br />
Remarks: The function writes the character to the output stream, advances the<br />
file-position indicator and returns the character as an unsigned char<br />
converted to an int.<br />
Example: #include /* for fputc, EOF, stdout */<br />
int main(void)<br />
{<br />
char *y;<br />
char buf[] = "This is text\n";<br />
int x;<br />
x = 0;<br />
Đã viết 10 số<br />
Đọc số 10<br />
1 * 10,000000 = 10,000000<br />
2 * 5,000000 = 10,000000<br />
3 * 3,333333 = 10,000000<br />
4 * 2,500000 = 10,000000<br />
5 * 2,000000 = 10,000000<br />
6 * 1,666667 = 10,000000<br />
7 * 1,428571 = 10,000000<br />
8 * 1,250000 = 10,000000<br />
9 * 1,111111 = 10,000000<br />
10 * 1,000000 = 10,000000<br />
Giải thích:<br />
Chương trình này sử dụng fwriteto tiết kiệm 10 số vào một tập tin dưới dạng nh<br />
phân.<br />
Điều này cho phép các con số để được lưu inthe cùng một khuôn mẫu của các<br />
bit là<br />
chương trình nào đang sử dụng cung cấp thêm độ chính xác và nhất quán. Sử<br />
dụng<br />
fprintfwould lưu các số là chuỗi văn bản mà có thể gây ra<br />
những con số được rút ngắn. Eachnumber được chia thành 10<br />
sản xuất một loạt các con số. Lấy các con số với một freadto<br />
mảng mới và nhân chúng bằng của số ban đầu cho thấy<br />
số không được cắt ngắn trong quá trình tiết kiệm.<br />
fread (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
for (y = buf; (x != EOF)&& (*y != '\0'); y++)<br />
{<br />
DS51456B trang 242<br />
freopen<br />
2004 Microchip Technology Inc<br />
x = fputc(*y, stdout);<br />
fputc('|', stdout);<br />
}<br />
}<br />
Output:<br />
T|h|i|s| |i|s| |t|e|x|t|<br />
|<br />
fputs<br />
Description: Puts a string to the stream.<br />
Include: <br />
Prototype: int fputs(const char *s, FILE *stream);<br />
Mô tả: reassigns một dòng hiện có vào một tập tin mới.<br />
Bao gồm:<br />
Prototype: FILE * freopen (const char * filename, const char<br />
* Chế độ, FILE * stream);<br />
Tên tên tập tin của các tập tin mới: đối số<br />
loại phương thức truy cập được phép<br />
dòng con trỏ đến dòng hiện đang mở<br />
Quay trở lại giá trị: Trả về một con trỏ đến các tập tin mở mới. Nếu chức năng<br />
không một con trỏ null<br />
được trả về.<br />
Bình luận: Chức năng đóng cửa các tập tin liên quan đến dòng như
Arguments: s string to be written<br />
stream pointer to the open stream<br />
Return Value: Returns a non-negative value if successful; otherwise, returns<br />
EOF.<br />
Remarks: The function writes characters tothe output stream up to but not<br />
including the null character.<br />
Example: #include /* for fputs, stdout */<br />
int main(void)<br />
{<br />
char buf[] = "This is text\n";<br />
fputs(buf,stdout);<br />
fputs("|",stdout);<br />
}<br />
Output:<br />
This is text<br />
|<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
fclosewas gọi. Sau đó, nó sẽ mở ra các tập tin mới như fopenwas<br />
gọi. freopenwill thất bại nếu dòng quy định không mở cửa. Xem fopen<br />
cho các loại có thể truy cập tập tin.<br />
Ví dụ: # include / * Cho fopen, freopen, * /<br />
/ * Printf, fclose, * /<br />
/ * FILE, NULL * /<br />
int main (void)<br />
{<br />
FILE * myfile1, * myfile2;<br />
int y;<br />
if ((myfile1 = fopen ("afile1", "w +")) == NULL)<br />
printf ("Không thể mở afile1 \ n");<br />
khác<br />
{<br />
printf ("afile1 được mở \ n");<br />
if ((myfile2 = freopen ("afile2", "w +",<br />
myfile1)) == NULL)<br />
{<br />
printf ("Không thể mở afile2 \ n");<br />
DS51456B-page 240<br />
fread<br />
2004 Microchip Technology Inc.<br />
fclose (myfile1);<br />
}<br />
Description: Reads data from the stream.<br />
Include: <br />
Prototype: size_t fread(void *ptr, size_t size, size_t nelem,<br />
FILE *stream);<br />
Arguments: ptr pointer to the storage buffer<br />
size size of item<br />
nelem maximum number of items to be read<br />
stream pointer to the stream<br />
Return Value: Returns the number of complete elements read up to nelemwhose<br />
size is specified by size.<br />
Remarks: The function reads characters froma given stream into the buffer<br />
pointed to by ptruntil the function stores size* nelemcharacters<br />
or sets the end-of-file or error indicator. freadreturns n/size where n is<br />
the number of characters it read. If n is not a multiple of size, the value<br />
of the last element is indeterminate. If the function sets the error<br />
indicator, the file-position indicator is indeterminate.<br />
Example: #include /* for fread, fwrite, */<br />
/* printf, fopen, fclose, */<br />
khác<br />
{<br />
printf ("afile2 được mở \ n");<br />
fclose (myfile2);<br />
}<br />
}<br />
}<br />
Đầu ra:<br />
afile1 đã được mở<br />
afile2 đã được mở<br />
Giải thích:<br />
Chương trình này sử dụng điểm myfile2to vào dòng khi freopenis<br />
gọi là như vậy nếu một lỗi xảy ra, vẫn myfile1will trỏ đến dòng và<br />
có thể được đóng đúng cách. Nếu freopencall thành công, myfile2can<br />
được sử dụng để đóng dòng đúng cách.<br />
fscanf<br />
Mô tả: Quét định dạng văn bản từ một dòng suối.<br />
Bao gồm:
* sizeof, FILE, NULL */<br />
int main(void)<br />
{<br />
FILE *buf;<br />
int x, numwrote, numread;<br />
double nums[10], readnums[10];<br />
if ((buf = fopen("afile.out", "w+")) != NULL)<br />
{<br />
for (x = 0; x < 10; x++)<br />
{<br />
nums[x] = 10.0/(x + 1);<br />
printf("10.0/%d = %f\n", x+1, nums[x]);<br />
}<br />
numwrote = fwrite(nums, sizeof(double),<br />
10, buf);<br />
printf("Wrote %dnumbers\n\n", numwrote);<br />
fclose(buf);<br />
}<br />
else<br />
printf("Cannot open afile.out\n");<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 241<br />
if ((buf = fopen("afile.out", "r+")) != NULL)<br />
{<br />
numread = fread(readnums, sizeof(double),<br />
10, buf);<br />
printf("Read %d numbers\n", numread);<br />
for (x = 0; x < 10; x++)<br />
{<br />
printf("%d * %f= %f\n", x+1, readnums[x],<br />
(x + 1) * readnums[x]);<br />
}<br />
fclose(buf);<br />
}<br />
else<br />
printf("Cannot open afile.out\n");<br />
}<br />
Output:<br />
10.0/1 = 10.000000<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 243<br />
Nguyên mẫu: int fscanf (FILE * stream, const char * format, ...);<br />
Đối số: dòng con trỏ đến dòng mở cửa từ để đọc dữ liệu<br />
định dạng kiểm soát chuỗi định dạng<br />
Đối số tùy chọn ...<br />
Quay trở lại giá trị: Trả về số lượng các mục chuyển đổi thành công và được<br />
giao. Nếu<br />
Không có sản phẩm được giao, một 0 được trả về. Kết thúc tập tin được trả về<br />
nếu kết thúc tập tin<br />
gặp phải trước khi chuyển đổi đầu tiên hoặc nếu có lỗi xảy ra.<br />
Ghi chú: Đối số định dạng có cú pháp tương tự và sử dụng nó có trong<br />
scanf.<br />
Ví dụ: # include / * Cho fopen, fscanf, * /<br />
/ * Fclose, fprintf, * /<br />
/ * Fseek, printf, FILE, * /<br />
/ * NULL, SEEK_SET * /<br />
int main (void)<br />
{<br />
FILE * myfile;<br />
char s [30];<br />
int x;<br />
char a;<br />
if ((myfile = fopen ("afile", "w +")) == NULL)<br />
printf ("Không thể mở afile \ n");<br />
khác<br />
{<br />
fprintf (myfile, "% s% d lần% c",<br />
"In chuỗi này", 100, '\ n');<br />
fseek (myfile, 0l, SEEK_SET);<br />
fscanf (myfile, "% s", s);<br />
printf ("% s \ n", s);<br />
fscanf (myfile, "% s", s);<br />
printf ("% s \ n", s);<br />
fscanf (myfile, "% s", s);<br />
printf ("% s \ n", s);<br />
fscanf (myfile, "% d", & x);<br />
printf ("% d \ n", x);<br />
fscanf (myfile, "% s", s);<br />
printf ("% s \ n", s);
10.0/2 = 5.000000<br />
10.0/3 = 3.333333<br />
10.0/4 = 2.500000<br />
10.0/5 = 2.000000<br />
10.0/6 = 1.666667<br />
10.0/7 = 1.428571<br />
10.0/8 = 1.250000<br />
10.0/9 = 1.111111<br />
10.0/10 = 1.000000<br />
Wrote 10 numbers<br />
Read 10 numbers<br />
1 * 10.000000 = 10.000000<br />
2 * 5.000000 = 10.000000<br />
3 * 3.333333 = 10.000000<br />
4 * 2.500000 = 10.000000<br />
5 * 2.000000 = 10.000000<br />
6 * 1.666667 = 10.000000<br />
7 * 1.428571 = 10.000000<br />
8 * 1.250000 = 10.000000<br />
9 * 1.111111 = 10.000000<br />
10 * 1.000000 = 10.000000<br />
Explanation:<br />
This program uses fwriteto save 10 numbers to a file in binary form.<br />
This allows the numbers to be saved inthe same pattern of bits as the<br />
program is using which provides more accuracy and consistency. Using<br />
fprintfwould save the numbers as text strings which could cause<br />
the numbers to be truncated. Eachnumber is divided into 10 to<br />
produce a variety of numbers. Retrieving the numbers with freadto a<br />
new array and multiplying them by the original number shows the<br />
numbers were not truncated in the save process.<br />
fread (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
fscanf (myfile, "% c", a);<br />
printf ("% c \ n", a);<br />
fclose (myfile);<br />
}<br />
}<br />
Đầu vào:<br />
Nội dung afile:<br />
In chuỗi này 100 lần<br />
Đầu ra:<br />
In<br />
này<br />
chuỗi<br />
100<br />
lần<br />
fscanf (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 244<br />
fseek<br />
2004 Microchip Technology Inc<br />
Mô tả: Di chuyển con trỏ tập tin đến một địa điểm cụ thể.<br />
Bao gồm:<br />
Nguyên mẫu: int fseek (FILE * stream, dài bù đắp, int mode);<br />
Đối số: dòng dòng, trong đó để di chuyển con trỏ tập tin.<br />
giá trị bù đắp thêm vào vị trí hiện tại<br />
loại phương thức tìm kiếm để thực hiện<br />
Quay trở lại giá trị: Trả về 0 nếu thành công; nếu không, trả về một giá trị khác<br />
không và thiết lập<br />
errno.<br />
Bình luận: chế độ có thể là một trong các cách sau:<br />
SEEK_SET- tìm kiếm từ đầu của tập tin<br />
SEEK_CUR- tìm từ vị trí hiện tại của con trỏ tập tin<br />
SEEK_END- tìm kiếm từ khi kết thúc tập tin<br />
Ví dụ: # include / * Cho fseek, fgets, * /<br />
/ * Printf, fopen, fclose, * /<br />
DS51456B-page 242<br />
freopen<br />
2004 Microchip Technology Inc.<br />
/ * FILE, NULL, perror, * /<br />
/ * SEEK_SET, SEEK_CUR, * /<br />
Description: Reassigns an existing stream to a new file.<br />
Include: <br />
Prototype: FILE *freopen(const char *filename, const char<br />
/ * SEEK_END * /<br />
int main (void)<br />
{
*mode, FILE *stream);<br />
Arguments: filename name of the new file<br />
mode type of access permitted<br />
stream pointer to the currently open stream<br />
Return Value: Returns a pointer to the new open file. If the function fails a null<br />
pointer<br />
is returned.<br />
Remarks: The function closes the file associated with the stream as though<br />
fclosewas called. Then it opens the new file as though fopenwas<br />
called. freopenwill fail if the specified stream is not open. See fopen<br />
for the possible types of file access.<br />
Example: #include /* for fopen, freopen, */<br />
/* printf, fclose, */<br />
/* FILE, NULL */<br />
int main(void)<br />
{<br />
FILE *myfile1, *myfile2;<br />
int y;<br />
if ((myfile1 = fopen("afile1", "w+")) == NULL)<br />
printf("Cannot open afile1\n");<br />
else<br />
{<br />
printf("afile1 was opened\n");<br />
if ((myfile2 = freopen("afile2", "w+",<br />
myfile1)) == NULL)<br />
{<br />
printf("Cannot open afile2\n");<br />
fclose(myfile1);<br />
}<br />
else<br />
{<br />
printf("afile2 was opened\n");<br />
fclose(myfile2);<br />
}<br />
}<br />
}<br />
Output:<br />
afile1 was opened<br />
afile2 was opened<br />
FILE * myfile;<br />
char s [70];<br />
int y;<br />
myfile = fopen ("afile.out", "w +");<br />
if (myfile == NULL)<br />
printf ("Không thể mở afile.out \ n");<br />
khác<br />
{<br />
fprintf (myfile, "Đây là sự khởi đầu"<br />
"Đây là trung bình và"<br />
"Đây là kết thúc.");<br />
y = fseek (myfile, 0l, SEEK_SET);<br />
if (y)<br />
perror ("fseek thất bại");<br />
khác<br />
{<br />
fgets (s, 22, myfile);<br />
printf ("\"% s \ "\ n \ n", s);<br />
}<br />
y = fseek (myfile, 2L, SEEK_CUR);<br />
if (y)<br />
perror ("fseek thất bại");<br />
khác<br />
{<br />
fgets (s, 70, myfile);<br />
printf ("\"% s \ "\ n \ n", s);<br />
}<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 245<br />
y = fseek (myfile, -16L, SEEK_END);<br />
if (y)<br />
perror ("fseek thất bại");<br />
khác<br />
{<br />
fgets (s, 70, myfile);<br />
printf ("\"% s \ "\ n", s);<br />
}<br />
fclose (myfile);<br />
}
Explanation:<br />
This program uses myfile2to point to the stream when freopenis<br />
called so if an error occurs, myfile1will still point to the stream and<br />
can be closed properly. If the freopencall is successful, myfile2can<br />
be used to close the stream properly.<br />
fscanf<br />
Description: Scans formatted text from a stream.<br />
Include: <br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 243<br />
Prototype: int fscanf(FILE *stream, const char *format, ...);<br />
Arguments: stream pointer to the open stream from which to read data<br />
format format control string<br />
... optional arguments<br />
Return Value: Returns the number of items successfully converted and assigned.<br />
If<br />
no items are assigned, a 0 is returned. EOF is returned if end of file is<br />
encountered before the first conversion or if an error occurs.<br />
Remarks: The format argument has the same syntax and use that it has in<br />
scanf.<br />
Example: #include /* for fopen, fscanf, */<br />
/* fclose, fprintf, */<br />
/* fseek, printf, FILE, */<br />
/* NULL, SEEK_SET */<br />
int main(void)<br />
{<br />
FILE *myfile;<br />
char s[30];<br />
int x;<br />
char a;<br />
if ((myfile = fopen("afile", "w+")) == NULL)<br />
printf("Cannot open afile\n");<br />
else<br />
{<br />
fprintf(myfile, "%s %d times%c",<br />
"Print this string", 100, '\n');<br />
fseek(myfile, 0L, SEEK_SET);<br />
fscanf(myfile, "%s", s);<br />
printf("%s\n", s);<br />
}<br />
Đầu ra:<br />
"Đây là sự khởi đầu"<br />
"Đây là andthis giữa là kết thúc."<br />
"Đây là kết thúc."<br />
Giải thích:<br />
Các tập tin afile.outis tạo ra với các văn bản, "Đây là sự khởi đầu, điều này<br />
là giữa và đây là kết thúc ".<br />
Chức năng fseekuses một bù đắp bằng không và SEEK_SETto thiết lập các tập<br />
tin<br />
con trỏ đến đầu của tập tin. fgetsthen đọc 22 ký tự<br />
mà là "Đây là sự khởi đầu", và cho biết thêm một ký tự null đến<br />
chuỗi.<br />
Tiếp theo, fseekuses một bù đắp của hai SEEK_CURRENTto và thiết lập các<br />
tập tin<br />
con trỏ đến vị trí hiện tại cộng với hai (bỏ qua các dấu phẩy và<br />
không gian.) fgetsthen đọc đến 70characters tiếp theo. Đầu tiên 39<br />
nhân vật "này là giữa và đây là kết thúc." Nó dừng lại khi nó<br />
đọc kết thúc tập tin và cho biết thêm một ký tự null vào chuỗi.<br />
Cuối cùng, fseekuses bù đắp âm 16 ký tự và SEEK_END<br />
thiết lập các tập tin con trỏ đến 16 ký tự từ cuối của tập tin. fgets<br />
sau đó đọc lên đến 70 ký tự. Nó dừng lại ở kết thúc tập tin sau khi đọc 16<br />
nhân vật "này là kết thúc." và cho biết thêm một ký tự null vào chuỗi.<br />
fsetpos<br />
Mô tả: Thiết lập vị trí tập tin của dòng.<br />
Bao gồm:<br />
Prototype: fsetpos int (FILE * stream, fpos_t const * pos);<br />
Đối số: dòng streamtarget<br />
pos lưu trữ vị trí, chỉ số như trả về bởi một cuộc gọi trước đó để<br />
fgetpos<br />
Quay trở lại giá trị: Trả về 0 nếu thành công; nếu không, trả về một giá trị khác<br />
không.<br />
Chú ý: chức năng đặt chỉ số tập tin vị trí cho các dòng được đưa ra trong * pos<br />
nếu thành công; nếu không, fsetpossets errno.<br />
fseek (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 246<br />
2004 Microchip Technology Inc<br />
Ví dụ: / * Chương trình này sẽ mở ra một tập tin và đọc byte tại * /<br />
/ * Địa điểm khác nhau. Các fgetpos * /
fscanf(myfile, "%s", s);<br />
printf("%s\n", s);<br />
fscanf(myfile, "%s", s);<br />
printf("%s\n", s);<br />
fscanf(myfile, "%d", &x);<br />
printf("%d\n", x);<br />
fscanf(myfile, "%s", s);<br />
printf("%s\n", s);<br />
fscanf(myfile, "%c", a);<br />
printf("%c\n", a);<br />
fclose(myfile);<br />
}<br />
}<br />
Input:<br />
Contents of afile:<br />
Print this string 100 times<br />
Output:<br />
Print<br />
this<br />
string<br />
100<br />
times<br />
fscanf (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 244<br />
fseek<br />
2004 Microchip Technology Inc.<br />
Description: Moves file pointer to a specific location.<br />
Include: <br />
Prototype: int fseek(FILE *stream, long offset, int mode);<br />
Arguments: stream stream in which to move the file pointer.<br />
offset value to add to the current position<br />
mode type of seek to perform<br />
Return Value: Returns 0 if successful; otherwise, returns a non-zero value and<br />
set<br />
errno.<br />
Remarks: mode can be one of the following:<br />
SEEK_SET– seeks from the beginning of the file<br />
/ * Chức năng ghi nhận các byte 8. 21 byte * /<br />
/ * Đọc sau đó 18 byte được đọc. Tiếp theo * /<br />
/ * Chức năng fsetpos được thiết lập dựa trên * /<br />
/ * Vị trí fgetpos và theprevious 21 byte * /<br />
/ * Đang đọc lại. * /<br />
# include / * Cho fgetpos, fread, * /<br />
/ * Printf, fopen, fclose, * /<br />
/ * FILE, NULL, perror, * /<br />
/ * Fpos_t, sizeof * /<br />
int main (void)<br />
{<br />
FILE * myfile;<br />
pos fpos_t;<br />
char buf [25];<br />
if ((myfile = fopen ("sampfgetpos.c", "rb")) ==<br />
NULL)<br />
printf ("Không thể mở tập tin \ n");<br />
khác<br />
{<br />
fread (buf, sizeof (char), 8, myfile);<br />
if (fgetpos (myfile, và pos) = 0)<br />
perror ("fgetpos lỗi");<br />
khác<br />
{<br />
fread (buf, sizeof (char), 21 tuổi, myfile);<br />
printf ("Bytes đọc:% .21s \ n", buf);<br />
fread (buf, sizeof (char), 18 tuổi, myfile);<br />
printf ("Bytes đọc:% .18s \ n", buf);<br />
}<br />
if (fsetpos (myfile, và pos) = 0)<br />
perror ("fsetpos lỗi");<br />
fread (buf, sizeof (char), 21 tuổi, myfile);<br />
printf ("Bytes đọc:% .21s \ n", buf);<br />
fclose (myfile);<br />
}<br />
}<br />
Đầu ra:<br />
Byte đọc: chương trình sẽ mở ra một tập tin<br />
Byte đọc: và đọc byte tại
SEEK_CUR– seeks from the current position of the file pointer<br />
SEEK_END– seeks from the end of the file<br />
Example: #include /* for fseek, fgets, */<br />
/* printf, fopen, fclose, */<br />
/* FILE, NULL, perror, */<br />
/* SEEK_SET, SEEK_CUR, */<br />
/*SEEK_END */<br />
int main(void)<br />
{<br />
FILE *myfile;<br />
char s[70];<br />
int y;<br />
myfile = fopen("afile.out", "w+");<br />
if (myfile == NULL)<br />
printf("Cannot open afile.out\n");<br />
else<br />
{<br />
fprintf(myfile, "This is the beginning, "<br />
"this is the middle and "<br />
"this is the end.");<br />
y = fseek(myfile, 0L, SEEK_SET);<br />
if (y)<br />
perror("Fseek failed");<br />
else<br />
{<br />
fgets(s, 22, myfile);<br />
printf("\"%s\"\n\n", s);<br />
}<br />
y = fseek(myfile, 2L, SEEK_CUR);<br />
if (y)<br />
perror("Fseek failed");<br />
else<br />
{<br />
fgets(s, 70, myfile);<br />
printf("\"%s\"\n\n", s);<br />
}<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 245<br />
y = fseek(myfile, -16L, SEEK_END);<br />
Byte đọc: chương trình sẽ mở ra một tập tin<br />
fsetpos (Tiếp theo)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 247<br />
ftell<br />
Mô tả: Được vị trí hiện tại của con trỏ tập tin.<br />
Bao gồm:<br />
Prototype: dài ftell (FILE * stream);<br />
Đối số: dòng dòng, trong đó để có được vị trí tập tin hiện hành<br />
Quay trở lại giá trị: Trả về vị trí của con trỏ tập tin nếu thành công; nếu không,<br />
trả về<br />
-1.<br />
Ví dụ: # include / * Cho ftell, fread, * /<br />
/ * Fprintf, printf, * /<br />
/ * Fopen, fclose, sizeof, * /<br />
/ * FILE, NULL * /<br />
int main (void)<br />
{<br />
FILE * myfile;<br />
char s [75];<br />
y dài;<br />
myfile = fopen ("afile.out", "w +");<br />
if (myfile == NULL)<br />
printf ("Không thể mở afile.out \ n");<br />
khác<br />
{<br />
fprintf (myfile, "isa này câu rất dài"<br />
"Để đưa vào các tập tin có tên"<br />
"Afile.out để thử nghiệm.");<br />
fclose (myfile);<br />
if ((myfile = fopen ("afile.out", "rb")) = NULL)<br />
{<br />
printf ("Đọc một số ký tự: \ n");<br />
fread (s, sizeof (char), 29 tuổi, myfile);<br />
printf ("\ t \"% s \ "\ n", s);<br />
y = ftell (myfile);<br />
printf ("vị trí hiện tại của"<br />
"Con trỏ tập tin là% ld \ n", y);<br />
fclose (myfile);<br />
}
if (y)<br />
perror("Fseek failed");<br />
else<br />
{<br />
fgets(s, 70, myfile);<br />
printf("\"%s\"\n", s);<br />
}<br />
fclose(myfile);<br />
}<br />
}<br />
Output:<br />
"This is the beginning"<br />
"this is the middle andthis is the end."<br />
"this is the end."<br />
Explanation:<br />
The file afile.outis created with the text, "This is the beginning, this<br />
is the middle and this is the end".<br />
The function fseekuses an offset of zero and SEEK_SETto set the file<br />
pointer to the beginning of the file. fgetsthen reads 22 characters<br />
which are "This is the beginning, " and adds a null character to the<br />
string.<br />
Next, fseekuses an offset of two and SEEK_CURRENTto set the file<br />
pointer to the current position plus two (skipping the comma and<br />
space.) fgetsthen reads up to the next 70characters. The first 39<br />
characters are "this is the middle and this is the end." It stops when it<br />
reads EOF and adds a null character to the string.<br />
FInally, fseekuses an offset of negative 16 characters and SEEK_END<br />
to set the file pointer to 16 characters from the end of the file. fgets<br />
then reads up to 70 characters. It stops at the EOF after reading 16<br />
characters "this is the end." and adds a null character to the string.<br />
fsetpos<br />
Description: Sets the stream's file position.<br />
Include: <br />
Prototype: int fsetpos(FILE *stream, const fpos_t *pos);<br />
Arguments: streamtarget stream<br />
pos position-indicator storage as returned by an earlier call to<br />
fgetpos<br />
Return Value: Returns 0 if successful; otherwise, returns a non-zero value.<br />
Remarks: The function sets the file-position indicator for the given stream in<br />
}<br />
}<br />
Đầu ra:<br />
Đọc một số ký tự:<br />
"Câu isa này rất dài"<br />
Vị trí hiện tại của con trỏ tập tin là 29<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 248<br />
fwrite<br />
Mô tả: Ghi dữ liệu vào dòng.<br />
Bao gồm:<br />
2004 Microchip Technology Inc<br />
Prototype: size_t fwrite (const void * ptr, size_t size,<br />
nelem size_t, FILE * stream);<br />
Đối số: ptr con trỏ đến bộ đệm lưu trữ<br />
kích thước kích thước của sản phẩm<br />
số nelem tối đa các mặt hàng được đọc<br />
dòng con trỏ đến dòng mở<br />
Quay trở lại giá trị: Trả về số phần tử hoàn chỉnh văn bản thành công, mà<br />
sẽ ít hơn nelemonly nếu một lỗi ghi là gặp phải.<br />
Ghi chú: Các chức năng viết chữ vào một dòng nhất định từ một bộ đệm chỉ<br />
để bằng ptrup để nelemelements có kích thước được xác định bởi kích<br />
thước. Các<br />
chỉ báo vị trí tập tin được đưa lên bằng số lượng ký tự<br />
viết thành công. Nếu functionsets chỉ số lỗi,<br />
chỉ số tập tin vị trí là không xác định.<br />
Ví dụ: # include / * Cho fread, fwrite, * /<br />
/ * Printf, fopen, fclose, * /<br />
/ * Sizeof, FILE, NULL * /<br />
int main (void)<br />
{<br />
FILE * buf;<br />
int x, numwrote, numread;<br />
nums đôi [10], readnums [10];<br />
if ((buf = fopen ("afile.out", "w +")) = NULL)<br />
{<br />
for (x = 0; x
*pos<br />
if successful; otherwise, fsetpossets errno.<br />
fseek (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
printf ("10,0 /% d =% f \ n", x + 1, nums [x]);<br />
}<br />
numwrote = fwrite (nums, sizeof (double),<br />
10, buf);<br />
printf ("đã viết% dnumbers \ n \ n", numwrote);<br />
fclose (buf);<br />
DS51456B-page 246<br />
2004 Microchip Technology Inc.<br />
}<br />
Example: /* This program opens a file and reads bytes at */<br />
/* several different locations. The fgetpos */<br />
/* function notes the 8th byte. 21 bytes are */<br />
/* read then 18 bytes are read. Next the */<br />
/* fsetpos function is set based on the */<br />
/* fgetpos position and theprevious 21 bytes */<br />
/* are reread. */<br />
#include /* for fgetpos, fread, */<br />
/* printf, fopen, fclose, */<br />
/* FILE, NULL, perror, */<br />
/* fpos_t, sizeof */<br />
int main(void)<br />
{<br />
FILE *myfile;<br />
fpos_t pos;<br />
char buf[25];<br />
if ((myfile = fopen("sampfgetpos.c", "rb")) ==<br />
NULL)<br />
printf("Cannot open file\n");<br />
else<br />
{<br />
fread(buf, sizeof(char), 8, myfile);<br />
if (fgetpos(myfile, &pos) != 0)<br />
perror("fgetpos error");<br />
else<br />
{<br />
fread(buf, sizeof(char), 21, myfile);<br />
printf("Bytes read: %.21s\n", buf);<br />
fread(buf, sizeof(char), 18, myfile);<br />
printf("Bytes read: %.18s\n", buf);<br />
}<br />
if (fsetpos(myfile, &pos) != 0)<br />
khác<br />
printf ("Không thể mở afile.out \ n");<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 249<br />
if ((buf = fopen ("afile.out", "r +")) = NULL)<br />
{<br />
numread = fread (readnums, sizeof (double),<br />
10, buf);<br />
printf ("Đọc% số d \ n", numread);<br />
for (x = 0; x
perror("fsetpos error");<br />
fread(buf, sizeof(char), 21, myfile);<br />
printf("Bytes read: %.21s\n", buf);<br />
fclose(myfile);<br />
}<br />
}<br />
Output:<br />
Bytes read: program opens a file<br />
Bytes read: and reads bytes at<br />
Bytes read: program opens a file<br />
fsetpos (Continued)<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 247<br />
ftell<br />
Description: Gets the current position of a file pointer.<br />
Include: <br />
Prototype: long ftell(FILE *stream);<br />
Argument: stream stream in which to get the current file position<br />
Return Value: Returns the position of the file pointer if successful; otherwise,<br />
returns<br />
-1.<br />
Example: #include /* for ftell, fread, */<br />
/* fprintf, printf, */<br />
/* fopen, fclose, sizeof, */<br />
/* FILE, NULL */<br />
int main(void)<br />
{<br />
FILE *myfile;<br />
char s[75];<br />
long y;<br />
myfile = fopen("afile.out", "w+");<br />
if (myfile == NULL)<br />
printf("Cannot open afile.out\n");<br />
else<br />
{<br />
fprintf(myfile,"This isa very long sentence "<br />
"for input into the file named "<br />
"afile.out for testing.");<br />
fclose(myfile);<br />
1 * 10,000000 = 10,000000<br />
2 * 5,000000 = 10,000000<br />
3 * 3,333333 = 10,000000<br />
4 * 2,500000 = 10,000000<br />
5 * 2,000000 = 10,000000<br />
6 * 1,666667 = 10,000000<br />
7 * 1,428571 = 10,000000<br />
8 * 1,250000 = 10,000000<br />
9 * 1,111111 = 10,000000<br />
10 * 1,000000 = 10,000000<br />
Giải thích:<br />
Chương trình này sử dụng fwriteto tiết kiệm 10 số vào một tập tin dưới dạng nh<br />
phân.<br />
Điều này cho phép các con số để được lưu inthe cùng một khuôn mẫu của các<br />
bit là<br />
chương trình nào đang sử dụng cung cấp thêm độ chính xác và nhất quán. Sử<br />
dụng<br />
fprintfwould lưu các số như textstrings, mà có thể gây ra<br />
những con số được rút ngắn. Eachnumber được chia thành 10<br />
sản xuất một loạt các con số. Lấy các con số với một freadto<br />
mảng mới và nhân chúng bằng của số ban đầu cho thấy<br />
số không được cắt ngắn trong quá trình tiết kiệm.<br />
fwrite (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 250<br />
getc<br />
2004 Microchip Technology Inc<br />
Mô tả: Có được một nhân vật từ các dòng.<br />
Bao gồm:<br />
Nguyên mẫu: int getc (FILE * stream);<br />
Đối số: dòng con trỏ đến dòng mở<br />
Quay trở lại giá trị: Trả về nhân vật đọc hoặc EOF nếu một lỗi đọc xảy ra hoặc<br />
kết thúc của tập tin<br />
đạt được.<br />
Bình luận: getcis giống như chức năng fgetc.<br />
Ví dụ: # include / * Cho getc, printf, * /<br />
/ * Fopen, fclose, * /<br />
/ * FILE, NULL, kết thúc tập tin * /<br />
int main (void)<br />
{
if ((myfile = fopen("afile.out", "rb")) != NULL)<br />
{<br />
printf("Read some characters:\n");<br />
fread(s, sizeof(char), 29, myfile);<br />
printf("\t\"%s\"\n", s);<br />
y = ftell(myfile);<br />
printf("The current position of the "<br />
"file pointer is %ld\n", y);<br />
fclose(myfile);<br />
}<br />
}<br />
}<br />
Output:<br />
Read some characters:<br />
"This isa very long sentence "<br />
The current position of the file pointer is 29<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 248<br />
fwrite<br />
Description: Writes data to the stream.<br />
Include: <br />
2004 Microchip Technology Inc.<br />
Prototype: size_t fwrite(const void *ptr, size_t size,<br />
size_t nelem, FILE *stream);<br />
Arguments: ptr pointer to the storage buffer<br />
size size of item<br />
nelem maximum number of items to be read<br />
stream pointer to the open stream<br />
Return Value: Returns the number of complete elements successfully written,<br />
which<br />
will be less than nelemonly if a write error is encountered.<br />
Remarks: The function writes characters to a given stream from a buffer pointed<br />
to by ptrup to nelemelements whose size is specified by size. The<br />
file position indicator is advanced by the number of characters<br />
successfully written. If the functionsets the error indicator, the<br />
file-position indicator is indeterminate.<br />
Example: #include /* for fread, fwrite, */<br />
/* printf, fopen, fclose, */<br />
FILE * buf;<br />
char y;<br />
if ((buf = fopen ("afile.txt", "r")) == NULL)<br />
printf ("Không thể mở afile.txt \ n");<br />
khác<br />
{<br />
y = getc (buf);<br />
trong khi (y! = EOF)<br />
{<br />
printf ("% c |", y);<br />
y = getc (buf);<br />
}<br />
fclose (buf);<br />
}<br />
}<br />
Đầu vào:<br />
Nội dung afile.txt (được sử dụng như đầu vào):<br />
Ngắn<br />
Chuỗi dài hơn<br />
Đầu ra:<br />
S | h | o | r | t |<br />
| L | o | n | g | e | r | | s | t | r | i | n | g |<br />
|<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 251<br />
getchar<br />
Mô tả: Có được một nhân vật từ thiết bị nhập chuẩn.<br />
Bao gồm:<br />
Nguyên mẫu: int getchar (void);<br />
Quay trở lại giá trị: Trả về nhân vật đọc hoặc EOF nếu một lỗi đọc xảy ra hoặc<br />
kết thúc của tập tin<br />
đạt được.<br />
Bình luận: cùng tác dụng như fgetcwith các thiết bị nhập chuẩn đối số.<br />
Ví dụ: # include / * Cho getchar, printf * /<br />
int main (void)<br />
{<br />
char y;<br />
y = getchar ();<br />
printf ("% c |", y);<br />
y = getchar ();
* sizeof, FILE, NULL */<br />
int main(void)<br />
{<br />
FILE *buf;<br />
int x, numwrote, numread;<br />
double nums[10], readnums[10];<br />
if ((buf = fopen("afile.out", "w+")) != NULL)<br />
{<br />
for (x = 0; x < 10; x++)<br />
{<br />
nums[x] = 10.0/(x + 1);<br />
printf("10.0/%d = %f\n", x+1, nums[x]);<br />
}<br />
numwrote = fwrite(nums, sizeof(double),<br />
10, buf);<br />
printf("Wrote %dnumbers\n\n", numwrote);<br />
fclose(buf);<br />
}<br />
else<br />
printf("Cannot open afile.out\n");<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 249<br />
if ((buf = fopen("afile.out", "r+")) != NULL)<br />
{<br />
numread = fread(readnums, sizeof(double),<br />
10, buf);<br />
printf("Read %d numbers\n", numread);<br />
for (x = 0; x < 10; x++)<br />
{<br />
printf("%d * %f= %f\n", x+1, readnums[x],<br />
(x + 1) * readnums[x]);<br />
printf ("% c |", y);<br />
y = getchar ();<br />
printf ("% c |", y);<br />
y = getchar ();<br />
printf ("% c |", y);<br />
y = getchar ();<br />
printf ("% c |", y);<br />
}<br />
Đầu vào:<br />
Nội dung UartIn.txt (được sử dụng như là đầu vào thiết bị nhập chuẩn cho mô<br />
phỏng):<br />
Ngắn<br />
Chuỗi dài hơn<br />
Đầu ra:<br />
S | h | o | r | t |<br />
được<br />
Mô tả: Có được một chuỗi từ thiết bị nhập chuẩn.<br />
Bao gồm:<br />
Prototype: char * được (char * s);<br />
Đối số: s con trỏ đến chuỗi lưu trữ<br />
Quay trở lại giá trị: Trả về một con trỏ đến chuỗi SIF thành công; nếu không, tr<br />
về một null<br />
con trỏ<br />
Chú ý: chức năng đọc ký tự từ các cửa hàng dòng stdinand chúng<br />
vào chuỗi trỏ đến bởi suntil nó đọc một ký tự xuống dòng (đó là<br />
không được lưu trữ) hoặc thiết lập cuối cùng của tập tin orerror chỉ số. Nếu bất<br />
kỳ ký tự<br />
đã đọc, một ký tự null được lưu trữ ngay lập tức sau khi đọc cuối cùng<br />
nhân vật trong phần tiếp theo của mảng. Nếu getssets lỗi<br />
chỉ số, các mảng nội dung là không xác định.<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
}<br />
DS51456B trang 252<br />
2004 Microchip Technology Inc<br />
fclose(buf);<br />
}<br />
else<br />
printf("Cannot open afile.out\n");<br />
}<br />
Output:<br />
10.0/1 = 10.000000<br />
Ví dụ: # include / * Cho được, printf * /<br />
int main (void)<br />
{<br />
char y [50];<br />
được (y);<br />
printf ("Text:% s \ n", y);<br />
}
10.0/2 = 5.000000<br />
10.0/3 = 3.333333<br />
10.0/4 = 2.500000<br />
10.0/5 = 2.000000<br />
10.0/6 = 1.666667<br />
10.0/7 = 1.428571<br />
10.0/8 = 1.250000<br />
10.0/9 = 1.111111<br />
10.0/10 = 1.000000<br />
Wrote 10 numbers<br />
Read 10 numbers<br />
1 * 10.000000 = 10.000000<br />
2 * 5.000000 = 10.000000<br />
3 * 3.333333 = 10.000000<br />
4 * 2.500000 = 10.000000<br />
5 * 2.000000 = 10.000000<br />
6 * 1.666667 = 10.000000<br />
7 * 1.428571 = 10.000000<br />
8 * 1.250000 = 10.000000<br />
9 * 1.111111 = 10.000000<br />
10 * 1.000000 = 10.000000<br />
Explanation:<br />
This program uses fwriteto save 10 numbers to a file in binary form.<br />
This allows the numbers to be saved inthe same pattern of bits as the<br />
program is using which provides more accuracy and consistency. Using<br />
fprintfwould save the numbers as textstrings, which could cause<br />
the numbers to be truncated. Eachnumber is divided into 10 to<br />
produce a variety of numbers. Retrieving the numbers with freadto a<br />
new array and multiplying them by the original number shows the<br />
numbers were not truncated in the save process.<br />
fwrite (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 250 2004 Microchip Technology Inc.<br />
getc<br />
Description: Get a character from the stream.<br />
Include: <br />
Prototype: int getc(FILE *stream);<br />
Đầu vào:<br />
Nội dung UartIn.txt (được sử dụng như là đầu vào thiết bị nhập chuẩn cho mô<br />
phỏng):<br />
Ngắn<br />
Chuỗi dài hơn<br />
Đầu ra:<br />
Tiêu đề: Ngắn<br />
perror<br />
Mô tả: In một thông báo lỗi để thiết bị lỗi chuẩn.<br />
Bao gồm:<br />
Prototype: void perror (const char * s);<br />
Đối số: s chuỗi in<br />
Quay trở lại giá trị: Không có.<br />
Ghi chú: Các chuỗi s được in theo sau dấu hai chấm và một không gian. Sau đó<br />
một lỗi<br />
tin dựa trên errnois được in theo sau là một dòng mới<br />
Ví dụ: # include / * Cho perror, fopen, * /<br />
/ * Fclose, printf, * /<br />
/ * FILE, NULL * /<br />
int main (void)<br />
{<br />
FILE * myfile;<br />
if ((myfile = fopen ("samp.fil", "r +")) == NULL)<br />
perror ("Không thể mở samp.fil");<br />
khác<br />
printf ("Thành công mở samp.fil \ n");<br />
fclose (myfile);<br />
}<br />
Đầu ra:<br />
Không thể mở samp.fil: tập tin lỗi mở<br />
được (Tiếp theo)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 253<br />
printf<br />
Mô tả: In định dạng văn bản để thiết bị xuất chuẩn.<br />
Bao gồm:<br />
Nguyên mẫu: int printf (const char * format, ...);<br />
Đối số: chuỗi định dạng kiểm soát định dạng<br />
Đối số tùy chọn ...<br />
Quay trở lại giá trị: Trả về số ký tự được tạo ra hoặc một số âm nếu một
Argument: stream pointer to the open stream<br />
Return Value: Returns the character read or EOF if a read error occurs or end of<br />
file is<br />
reached.<br />
Remarks: getcis the same as the function fgetc.<br />
Example: #include /* for getc, printf, */<br />
/* fopen, fclose, */<br />
/* FILE, NULL, EOF */<br />
int main(void)<br />
{<br />
FILE *buf;<br />
char y;<br />
if ((buf = fopen("afile.txt", "r")) == NULL)<br />
printf("Cannot open afile.txt\n");<br />
else<br />
{<br />
y = getc(buf);<br />
while (y != EOF)<br />
{<br />
printf("%c|", y);<br />
y = getc(buf);<br />
}<br />
fclose(buf);<br />
}<br />
}<br />
Input:<br />
Contents of afile.txt(used as input):<br />
Short<br />
Longer string<br />
Output:<br />
S|h|o|r|t|<br />
|L|o|n|g|e|r| |s|t|r|i|n|g|<br />
|<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 251<br />
getchar<br />
Description: Get a character from stdin.<br />
Include: <br />
Prototype: int getchar(void);<br />
lỗi xảy ra.<br />
Bình luận: Phải có chính xác cùng một số đối số là có<br />
định dạng specifiers. Nếu là đối số ít hơn phù hợp với định dạng<br />
specifiers, đầu ra là không xác định. Nếu có tranh luận hơn<br />
phù hợp với các đặc tả định dạng, các đối số còn lại sẽ bị loại bỏ.<br />
Mỗi đặc tả định dạng bắt đầu với một dấu phần trăm tiếp theo tùy chọn<br />
lĩnh vực và một loại yêu cầu như ở đây:<br />
[Chính xác.] [Size]% [cờ] [chiều rộng] loại<br />
cờ<br />
- Trái biện minh cho giá trị trong một lĩnh vực nhất định chiều rộng<br />
0 0 sử dụng cho nhân vật pad thay vì không gian (đó là<br />
mặc định)<br />
+ Tạo ra một dấu cộng cho các giá trị ký kết tích cực<br />
không gian tạo ra một không gian hoặc giá trị ký kết có không phải là một cộng<br />
cũng không phải là dấu trừ<br />
# Để tiền tố 0 trên một chuyển đổi bát phân, tiền tố 0x hoặc 0X trên<br />
chuyển đổi hệ thập lục phân, hoặc để tạo ra một dấu thập phân<br />
và chữ số thập phân được nếu không bị đàn áp trên<br />
chuyển đổi dấu chấm động<br />
chiều rộng<br />
xác định số ký tự để tạo ra cho việc chuyển đổi. Nếu<br />
dấu sao (*) được sử dụng thay vì một số thập phân, tiếp theo<br />
tranh luận (mà cần phải có kiểu int) sẽ được sử dụng cho lĩnh vực này<br />
chiều rộng. Nếu kết quả là ít hơn so với chiều rộng lĩnh vực, nhân vật pad sẽ<br />
sử dụng ở bên trái để điền vào lĩnh vực này. Nếu kết quả là lớn hơn lĩnh vực nà<br />
chiều rộng, lĩnh vực này được mở rộng toaccommodate giá trị mà không<br />
padding.<br />
độ chính xác<br />
Chiều rộng lĩnh vực có thể được theo sau với dấu chấm (.) Và một số nguyên<br />
thập phân<br />
đại diện cho sự chính xác mà xác định một trong những điều sau đây:<br />
- Số lượng tối thiểu của các chữ số để tạo ra trên một chuyển đổi số nguyên<br />
- Số chữ số phần để tạo ra một địa chỉ e, E, hoặc f chuyển đổi<br />
- Số lượng tối đa đáng kể chữ số để tạo ra trên ag hoặc G<br />
chuyển đổi<br />
- Số lượng tối đa của nhân vật để tạo ra từ một chuỗi C trên<br />
s chuyển đổi<br />
Nếu giai đoạn này xuất hiện mà không có số nguyên số nguyên được giả định<br />
là số không. Nếu các dấu sao (*) được sử dụng thay vì một số thập phân,<br />
Đối số tiếp theo (trong đó phải có kiểu int) sẽ được sử dụng cho
Return Value: Returns the character read or EOF if a read error occurs or end of<br />
file is<br />
reached.<br />
Remarks: Same effect as fgetcwith the argument stdin.<br />
chính xác.<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
Example: #include /* for getchar, printf */<br />
int main(void)<br />
DS51456B trang 254<br />
kích thước<br />
2004 Microchip Technology Inc<br />
{<br />
char y;<br />
y = getchar();<br />
printf("%c|", y);<br />
y = getchar();<br />
printf("%c|", y);<br />
y = getchar();<br />
printf("%c|", y);<br />
y = getchar();<br />
printf("%c|", y);<br />
y = getchar();<br />
printf("%c|", y);<br />
}<br />
Input:<br />
Contents of UartIn.txt(used as stdin input for simulator):<br />
Short<br />
Longer string<br />
Output:<br />
S|h|o|r|t|<br />
gets<br />
Description: Get a string from stdin.<br />
Include: <br />
Prototype: char *gets(char *s);<br />
Argument: s pointer to the storage string<br />
Return Value: Returns a pointer to the string sif successful; otherwise, returns a<br />
null<br />
pointer<br />
Remarks: The function reads characters from the stream stdinand stores them<br />
into the string pointed to by suntil it reads a newline character (which is<br />
not stored) or sets the end-of-file orerror indicators. If any characters<br />
were read, a null character is stored immediately after the last read<br />
character in the next element of the array. If getssets the error<br />
indicator, the array contents are indeterminate.<br />
dsPIC<br />
h sửa đổi - sử dụng với các loại d, i, o, u, x, X; chuyển đổi các giá trị cho một<br />
intor ngắn unsigned short int<br />
h sửa đổi - sử dụng với n; xác định rằng con trỏ trỏ đến một<br />
ngắn int<br />
l sửa đổi - sử dụng với các loại d, i, o, u, x, X; chuyển đổi các giá trị cho một<br />
intor dài unsigned long int<br />
l sửa đổi - sử dụng với n; xác định rằng con trỏ trỏ đến một<br />
long int<br />
l sửa đổi - sử dụng với c; quy định cụ thể một nhân vật rộng<br />
l sửa đổi - sử dụng với các loại điện tử, E, F, F, g, G; chuyển đổi các giá trị cho<br />
một<br />
đôi<br />
ll sửa đổi - sử dụng với các loại d, i, o, u, x, X; chuyển đổi các giá trị cho một<br />
intor lâu dài unsigned long long int<br />
ll sửa đổi - sử dụng với n; xác định rằng con trỏ trỏ đến một<br />
lâu dài int<br />
L sửa đổi - sử dụng với điện tử, E, e, g, G; chuyển đổi các giá trị cho một thời<br />
gian dài<br />
đôi<br />
loại<br />
d, tôi đã ký int<br />
o unsigned intin bát phân<br />
u thập phân intin unsigned<br />
x unsigned intin hệ thập lục phân chữ thường<br />
X unsigned intin hệ thập lục phân hoa<br />
điện tử, E doublein ký hiệu khoa học<br />
f doubledecimal ký hiệu<br />
g, G đôi (có dạng điện tử, E hoặc e nếu thích hợp)<br />
c char- một nhân vật duy nhất<br />
của chuỗi<br />
giá trị p của một con trỏ<br />
n tranh luận liên quan sẽ là một con trỏ số nguyên vào<br />
được đặt số lượng ký tự được viết cho đến nay. Không có<br />
ký tự được in.
®<br />
Language Tools Libraries<br />
DS51456B-page 252 2004 Microchip Technology Inc.<br />
Example: #include /* for gets, printf */<br />
int main(void)<br />
{<br />
char y[50];<br />
gets(y) ;<br />
printf("Text: %s\n", y);<br />
}<br />
Input:<br />
Contents of UartIn.txt(used as stdin input for simulator):<br />
Short<br />
Longer string<br />
Output:<br />
Text: Short<br />
perror<br />
Description: Prints an error message to stderr.<br />
Include: <br />
Prototype: void perror(const char *s);<br />
Argument: s string to print<br />
Return Value: None.<br />
Remarks: The string s is printed followed by a colon and a space. Then an error<br />
message based on errnois printed followed by an newline<br />
Example: #include /* for perror, fopen, */<br />
/* fclose, printf, */<br />
/* FILE, NULL */<br />
int main(void)<br />
{<br />
FILE *myfile;<br />
if ((myfile = fopen("samp.fil", "r+")) == NULL)<br />
perror("Cannot open samp.fil");<br />
else<br />
printf("Success opening samp.fil\n");<br />
fclose(myfile);<br />
}<br />
Output:<br />
Cannot open samp.fil: file open error<br />
gets (Continued)<br />
%% Một nhân vật được in<br />
Ví dụ: # include / * Cho printf * /<br />
int main (void)<br />
{<br />
/ * In quyền nhân vật lý trong 3 * /<br />
/ * Không gian nhân vật. * /<br />
printf ("% 3c \ n", 'a');<br />
/ * In một số nguyên, trái lý (như * /<br />
/ * Xác định bởi các dấu trừ ở định dạng * /<br />
/ * String) trong một không gian 4 ký tự. In một * /<br />
/ * Số nguyên thứ hai như vậy là hợp lý trong * /<br />
/ * Một không gian 4 nhân vật bằng cách sử dụng ống (|) như * /<br />
/ * Một dấu phân cách giữa các số nguyên. * /<br />
printf ("% - 4d |% 4d \ n", -4, 4);<br />
/ * In một số chuyển đổi sang bát phân trong 4 * /<br />
/ * Chữ số. * /<br />
printf ("% 4o. \ n", 10);<br />
printf (Tiếp theo)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 255<br />
/ * In một số chuyển đổi sang hệ thập lục phân * /<br />
/ * Định dạng với một tiền tố 0x. * /<br />
printf ("% # x \ n", 28);<br />
/ * In một phao trong ký hiệu khoa học * /<br />
printf ("% E \ n", 1.1e20);<br />
/ * In nổi với 2 chữ số thập phân * /<br />
printf (".% 2f \ n", -3,346);<br />
/ * In một phao dài với E%,% e hoặc% f * /<br />
/ * Nào là phiên bản ngắn nhất * /<br />
printf ("% Lg \ n", .02L);<br />
}<br />
Đầu ra:<br />
một<br />
-4 | 4<br />
0012<br />
0x1c<br />
1.100000E + 20<br />
-3.35<br />
0.02
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 253<br />
printf<br />
Description: Prints formatted text to stdout.<br />
Include: <br />
Prototype: int printf(const char *format, ...);<br />
Arguments: format format control string<br />
... optional arguments<br />
Return Value: Returns number of characters generated or a negative number if<br />
an<br />
error occurs.<br />
Remarks: There must be exactly the same number of arguments as there are<br />
format specifiers. If the are less arguments than match the format<br />
specifiers, the output is undefined. If there are more arguments than<br />
match the format specifiers, the remaining arguments are discarded.<br />
Each format specifier begins with a percent sign followed by optional<br />
fields and a required type as shown here:<br />
%[flags][width][.precision][size]type<br />
flags<br />
- left-justify the value within a given field width<br />
0 Use 0 for the pad character instead of space (which is the<br />
default)<br />
+ generate a plus sign for positive signed values<br />
space generate a space or signed values that have neither a plus<br />
nor a minus sign<br />
# to prefix 0 on an octal conversion, to prefix 0x or 0X on a<br />
hexadecimal conversion, or to generate a decimal point<br />
and fraction digits that are otherwise suppressed on a<br />
floating-point conversion<br />
width<br />
specify the number of characters to generate for the conversion. If<br />
the asterisk (*) is used instead of a decimal number, the next<br />
argument (which must be of type int) will be used for the field<br />
width. If the result is less than the field width, pad characters will be<br />
used on the left to fill the field. If the result is greater than the field<br />
width, the field is expanded toaccommodate the value without<br />
padding.<br />
precision<br />
The field width can be followed with dot (.) and a decimal integer<br />
putc<br />
Mô tả: Đặt một ký tự dòng.<br />
Bao gồm:<br />
Nguyên mẫu: int putc (int c, FILE * stream);<br />
Đối số: ký tự c được viết<br />
dòng con trỏ đến cấu trúc FILE<br />
Quay trở lại giá trị: Trả về nhân vật hoặc EOF nếu lỗi xảy ra hoặc kết thúc của<br />
tập tin<br />
đạt được.<br />
Bình luận: putcis giống như chức năng fputc.<br />
Ví dụ: # include / * Cho putc, kết thúc tập tin, thiết bị xuất chuẩn * /<br />
int main (void)<br />
{<br />
char * y;<br />
char buf [] = "Đây là văn bản \ n";<br />
int x;<br />
x = 0;<br />
cho (y = buf; (x = EOF) && (* y = '\ 0');! y ++!)<br />
{<br />
x = putc (* y, thiết bị xuất chuẩn);<br />
putc ('|', thiết bị xuất chuẩn);<br />
}<br />
}<br />
Đầu ra:<br />
T | h | i | s | | i | s | | t | e | x | t |<br />
|<br />
printf (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 256<br />
putchar<br />
2004 Microchip Technology Inc<br />
Mô tả: Đặt một nhân vật để thiết bị xuất chuẩn.<br />
Bao gồm:<br />
Nguyên mẫu: int putchar (int c);<br />
Đối số: ký tự c được viết<br />
Quay trở lại giá trị: Trả về nhân vật hoặc EOF nếu lỗi xảy ra hoặc kết thúc của<br />
tập tin<br />
đạt được.<br />
Bình luận: cùng tác dụng như fputcwith stdoutas một cuộc tranh cãi.
epresenting the precision that specifies one of the following:<br />
- minimum number of digits to generate on an integer conversion<br />
- number of fraction digits to generate on an e, E, or f conversion<br />
- maximum number of significant digits to generate on a g or G<br />
conversion<br />
- maximum number of characters to generate from a C string on an<br />
s conversion<br />
If the period appears without the integer the integer is assumed to<br />
be zero. If the asterisk (*) is used instead of a decimal number, the<br />
next argument (which must be of type int) will be used for the<br />
precision.<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 254 2004 Microchip Technology Inc.<br />
size<br />
h modifier - used with type d, i, o,u, x, X; converts the value to a<br />
short intor unsigned short int<br />
h modifier - used with n; specifies that the pointer points to a<br />
short int<br />
l modifier - used with type d, i, o,u, x, X; converts the value to a<br />
long intor unsigned long int<br />
l modifier - used with n; specifies that the pointer points to a<br />
long int<br />
l modifier - used with c; specifies a wide character<br />
l modifier - used with type e, E, f, F, g, G; converts the value to a<br />
double<br />
ll modifier - used with type d, i, o,u, x, X; converts the value to a<br />
long long intor unsigned long long int<br />
ll modifier - used with n; specifies that the pointer points to a<br />
long long int<br />
L modifier - used with e, E, f, g, G; converts the value to a long<br />
double<br />
type<br />
d, i signed int<br />
o unsigned intin octal<br />
u unsigned intin decimal<br />
x unsigned intin lowercase hexadecimal<br />
X unsigned intin uppercase hexadecimal<br />
Ví dụ: # include / * Cho putchar, printf, * /<br />
/ * Kết thúc tập tin, thiết bị xuất chuẩn * /<br />
int main (void)<br />
{<br />
char * y;<br />
char buf [] = "Đây là văn bản \ n";<br />
int x;<br />
x = 0;<br />
cho (y = buf; (x = EOF) && (* y = '\ 0');! y ++!)<br />
x = putchar (* y);<br />
}<br />
Đầu ra:<br />
Đây là văn bản<br />
puts<br />
Mô tả: Đặt một chuỗi thiết bị xuất chuẩn.<br />
Bao gồm:<br />
Nguyên mẫu: int puts (const char * s);<br />
Đối số: s chuỗi được viết<br />
Quay trở lại giá trị: Trả về một giá trị không âm nếu thành công; nếu không, trả<br />
về EOF.<br />
Ghi chú: Các chức năng ghi ký tự đến thiết bị xuất chuẩn dòng. Một dòng mới<br />
nhân vật được nối. Các ký tự null chấm dứt được không được ghi vào<br />
dòng.<br />
Ví dụ: # include / * Cho puts * /<br />
int main (void)<br />
{<br />
char buf [] = "Đây là văn bản \ n";<br />
đặt (buf);<br />
đặt ("|");<br />
}<br />
Đầu ra:<br />
Đây là văn bản<br />
|<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 257<br />
loại bỏ<br />
Mô tả: Xóa các tập tin được chỉ định.<br />
Bao gồm:<br />
Nguyên mẫu: int remove (const char * filename);<br />
Đối số: tên tên tập tin của tập tin bị xóa.
e, E doublein scientific notation<br />
f doubledecimal notation<br />
g, G double(takes the form of e, E or f as appropriate)<br />
c char- a single character<br />
s string<br />
p value of a pointer<br />
n the associated argument shall be an integer pointer into<br />
which is placed the number of characters written so far. No<br />
characters are printed.<br />
% A % character is printed<br />
Example: #include /* for printf */<br />
int main(void)<br />
{<br />
/* print a character right justified in a 3 */<br />
/* character space. */<br />
printf("%3c\n", 'a');<br />
/* print an integer, left justified (as */<br />
/* specified by the minus sign in the format */<br />
/* string) in a 4 character space. Print a */<br />
/* second integer that is right justified in */<br />
/* a 4 character space using the pipe (|) as */<br />
/* a separator between the integers. */<br />
printf("%-4d|%4d\n", -4, 4);<br />
/* print a number converted to octal in 4 */<br />
/* digits. */<br />
printf("%.4o\n", 10);<br />
printf (Continued)<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 255<br />
/* print a number converted to hexadecimal */<br />
/* format with a 0x prefix. */<br />
printf("%#x\n", 28);<br />
/* print a float in scientific notation */<br />
printf("%E\n", 1.1e20);<br />
/* print a float with 2 fraction digits */<br />
printf("%.2f\n", -3.346);<br />
/* print a long float with %E, %e, or %f */<br />
/* whichever is the shortest version */<br />
printf("%Lg\n", .02L);<br />
Quay trở lại giá trị: Trả về 0 nếu thành công, -1 nếu không.<br />
Ghi chú: Nếu tên tập tin không tồn tại hoặc là mở, removewill thất bại.<br />
Ví dụ: # include / * Cho loại bỏ, printf * /<br />
int main (void)<br />
{<br />
if (loại bỏ ("myfile.txt") = 0)<br />
printf ("Không thể loại bỏ tập tin");<br />
khác<br />
printf ("File gỡ bỏ");<br />
}<br />
Đầu ra:<br />
Tập tin bị loại bỏ<br />
đổi tên<br />
Mô tả: Đổi tên các tập tin được chỉ định.<br />
Bao gồm:<br />
Nguyên mẫu: int đổi tên (const char * cũ, const char * mới);<br />
Đối số: con trỏ cũ sang tên cũ<br />
con trỏ mới sang tên mới.<br />
Quay trở lại giá trị: Trở về 0 nếu thành công, khác không nếu không.<br />
Chú ý: tên mới phải không tồn tại trong thư mục làm việc hiện tại,<br />
tên cũ phải tồn tại trong thư mục làm việc hiện tại.<br />
Ví dụ: # include / * Để đổi tên, printf * /<br />
int main (void)<br />
{<br />
if (đổi tên ("myfile.txt", "newfile.txt") = 0)<br />
printf ("Không thể đổi tên tập tin");<br />
khác<br />
printf ("File đổi tên thành");<br />
}<br />
Đầu ra:<br />
Tập tin đổi tên<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 258 2004 Microchip Technology Inc<br />
quay lại<br />
Mô tả: Cấu hình lại các tập tin con trỏ đến đầu của tập tin.<br />
Bao gồm:<br />
Prototype: void rewind (FILE * stream);
}<br />
Output:<br />
a<br />
-4 | 4<br />
0012<br />
0x1c<br />
1.100000E+20<br />
-3.35<br />
0.02<br />
putc<br />
Description: Puts a character to the stream.<br />
Include: <br />
Prototype: int putc(int c, FILE *stream);<br />
Arguments: c character to be written<br />
stream pointer to FILE structure<br />
Return Value: Returns the character or EOF if an error occurs or end of file is<br />
reached.<br />
Remarks: putcis the same as the function fputc.<br />
Example: #include /* for putc, EOF, stdout */<br />
int main(void)<br />
{<br />
char *y;<br />
char buf[] = "This is text\n";<br />
int x;<br />
x = 0;<br />
for (y = buf; (x != EOF) && (*y != '\0'); y++)<br />
{<br />
x = putc(*y, stdout);<br />
putc('|', stdout);<br />
}<br />
}<br />
Output:<br />
T|h|i|s| |i|s| |t|e|x|t|<br />
|<br />
printf (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 256 2004 Microchip Technology Inc.<br />
Đối số: dòng suối để thiết lập lại con trỏ tập tin<br />
Chú ý: chức năng cuộc gọi fseek (stream, 0L, SEEK_SET) và sau đó Clears<br />
chỉ số lỗi cho các dòng nhất định.<br />
Ví dụ: # include / * Để quay lại, fopen, * /<br />
/ * Fscanf, fclose, * /<br />
/ * Fprintf, printf, * /<br />
/ * FILE, NULL * /<br />
int main (void)<br />
{<br />
FILE * myfile;<br />
char s [] = "cookies";<br />
int x = 10;<br />
if ((myfile = fopen ("afile", "w +")) == NULL)<br />
printf ("Không thể mở afile \ n");<br />
khác<br />
{<br />
fprintf (myfile, "% d% s", x, s);<br />
printf ("Tôi có% d% s. \ n", x, s);<br />
/ * Thiết lập con trỏ tobeginning của tập tin * /<br />
tua lại (myfile);<br />
fscanf (myfile, "% d% s", & x, & s);<br />
printf ("tôi đã ăn% d% s. \ n", x, s);<br />
fclose (myfile);<br />
}<br />
}<br />
Đầu ra:<br />
Tôi có 10 bánh.<br />
Tôi đã ăn 10 bánh.<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 259<br />
scanf<br />
Mô tả: Quét định dạng văn bản từ thiết bị nhập chuẩn.<br />
Bao gồm:<br />
Nguyên mẫu: int scanf (const char * format, ...);<br />
Đối số: định dạng chuỗi kiểm soát định dạng<br />
Đối số tùy chọn ...<br />
Quay trở lại giá trị: Trả về số lượng các mục chuyển đổi thành công và được<br />
giao. Nếu<br />
Không có sản phẩm được giao, một 0 được trả về. Kết thúc tập tin được trả lại<br />
nếu một đầu vào
putchar<br />
Description: Put a character to stdout.<br />
Include: <br />
Prototype: int putchar(int c);<br />
Argument: c character to be written<br />
Return Value: Returns the character or EOF if an error occurs or end of file is<br />
reached.<br />
Remarks: Same effect as fputcwith stdoutas an argument.<br />
Example: #include /* for putchar, printf, */<br />
/* EOF, stdout */<br />
int main(void)<br />
{<br />
char *y;<br />
char buf[] = "This is text\n";<br />
int x;<br />
x = 0;<br />
for (y = buf; (x !=EOF) && (*y != '\0'); y++)<br />
x = putchar(*y);<br />
}<br />
Output:<br />
This is text<br />
puts<br />
Description: Put a string to stdout.<br />
Include: <br />
Prototype: int puts(const char *s);<br />
Argument: s string to be written<br />
Return Value: Returns a non-negative value if successful; otherwise, returns<br />
EOF.<br />
Remarks: The function writes characters to the stream stdout. A newline<br />
character is appended. The terminating null character is not written to<br />
the stream.<br />
Example: #include /* for puts */<br />
thất bại là gặp phải trước khi là người đầu tiên.<br />
Ghi chú: Mỗi đặc tả định dạng bắt đầu với một dấu phần trăm tiếp theo tùy chọ<br />
lĩnh vực và một loại yêu cầu như ở đây:<br />
% [*] [Chiều rộng] [sửa đổi] loại<br />
*<br />
chỉ ra nhiệm vụ đàn áp. Điều này sẽ gây ra các lĩnh vực đầu vào<br />
bị bỏ qua và không có chuyển nhượng được thực hiện.<br />
chiều rộng<br />
xác định số ký tự tối đa đầu vào để phù hợp cho<br />
chuyển đổi không bao gồm khoảng trắng có thể được bỏ qua.<br />
sửa đổi<br />
h sửa đổi - sử dụng với các loại d, i, o, u, x, X; chuyển đổi các giá trị cho một<br />
intor ngắn unsigned short int.<br />
h sửa đổi - sử dụng với n; xác định rằng con trỏ trỏ đến một<br />
ngắn int<br />
l sửa đổi - sử dụng với các loại d, i, o, u, x, X; chuyển đổi các giá trị cho một<br />
intor dài unsigned long int<br />
l sửa đổi - sử dụng với n; xác định rằng con trỏ trỏ đến một<br />
long int<br />
l sửa đổi - sử dụng với c; quy định cụ thể một nhân vật rộng<br />
l sửa đổi - sử dụng với các loại điện tử, E, F, F, g, G; chuyển đổi các giá trị cho<br />
một<br />
đôi<br />
ll sửa đổi - sử dụng với các loại d, i, o, u, x, X; chuyển đổi các giá trị cho một<br />
intor lâu dài unsigned long long int<br />
ll sửa đổi - sử dụng với n; xác định rằng con trỏ trỏ đến một<br />
lâu dài int<br />
L sửa đổi - sử dụng với điện tử, E, e, g, G; chuyển đổi các giá trị cho một thời<br />
gian dài<br />
đôi<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
int main(void)<br />
{<br />
char buf[] = "This is text\n";<br />
DS51456B trang 260<br />
loại<br />
d, tôi đã ký int<br />
2004 Microchip Technology Inc<br />
puts(buf);<br />
puts("|");<br />
}<br />
Output:<br />
o unsigned intin bát phân<br />
u thập phân intin unsigned<br />
x unsigned intin hệ thập lục phân chữ thường<br />
X unsigned intin hệ thập lục phân hoa
This is text<br />
|<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 257<br />
remove<br />
Description: Deletes the specified file.<br />
Include: <br />
Prototype: int remove(const char *filename);<br />
Argument: filename name of file to be deleted.<br />
Return Value: Returns 0 if successful, -1 if not.<br />
Remarks: If filename does not exist or is open, removewill fail.<br />
Example: #include /* for remove, printf */<br />
int main(void)<br />
{<br />
if (remove("myfile.txt") != 0)<br />
printf("Cannot remove file");<br />
else<br />
printf("File removed");<br />
}<br />
Output:<br />
File removed<br />
rename<br />
Description: Renames the specified file.<br />
Include: <br />
Prototype: int rename(const char *old, const char *new);<br />
Arguments: old pointer to the old name<br />
new pointer to the new name.<br />
Return Value: Return 0 if successful, non-zero if not.<br />
Remarks: The new name must not already exist in the current working<br />
directory,<br />
the old name must exist in the current working directory.<br />
Example: #include /* for rename, printf */<br />
int main(void)<br />
{<br />
if (rename("myfile.txt","newfile.txt") != 0)<br />
printf("Cannot rename file");<br />
else<br />
printf("File renamed");<br />
}<br />
điện tử, E doublein ký hiệu khoa học<br />
f doubledecimal ký hiệu<br />
g, G đôi (có dạng điện tử, E hoặc e nếu thích hợp)<br />
c char- một nhân vật duy nhất<br />
sstring giá trị p của một con trỏ<br />
n tranh luận liên quan sẽ là một con trỏ số nguyên vào,<br />
được đặt số ký tự đọc cho đến nay. Không có<br />
nhân vật được quét.<br />
[...] Nhân vật mảng. Cho phép tìm kiếm một tập hợp các ký tự. Một<br />
dấu mũ (^) ngay sau khi khung bên trái ([) đảo ngược<br />
scanset và cho phép bất kỳ ký tự ASCII, ngoại trừ những<br />
quy định giữa các dấu ngoặc đơn. Một nhân vật có dấu gạch ngang (-) có thể<br />
dùng để xác định một phạm vi đầu với nhân vật trước<br />
dấu gạch ngang và kết thúc các nhân vật sau dấu gạch ngang. Một rỗng<br />
nhân vật không thể là một phần của scanset.<br />
%% Một nhân vật được quét<br />
Ví dụ: # include / * Cho scanf, printf * /<br />
int main (void)<br />
{<br />
int số lượng, mặt hàng;<br />
thư char;<br />
char màu [30], string [30];<br />
nổi tiền lương;<br />
printf ("Nhập số yourfavorite"<br />
"Thư yêu thích,");<br />
printf ("yêu thích màu sắc mong muốn mức lương"<br />
"Và SSN: \ n");<br />
mục = scanf ("% d% c% [A-Za-z]% f% s", & số,<br />
& Thư, và màu sắc, và tiền lương, và string);<br />
printf ("Số scan =% d \ n", các mục);<br />
printf ("số yêu thích =% d", số lượng);<br />
printf ("thư yêu thích =% c \ n", thư);<br />
printf ("Màu sắc ưa thích =% s", màu sắc);<br />
printf ("lương Desired = $% 2f. \ n", tiền lương);<br />
printf ("Số An Sinh Xã Hội =% s", string);<br />
}<br />
Đầu vào:<br />
Nội dung UartIn.txt (được sử dụng như là đầu vào thiết bị nhập chuẩn cho mô<br />
phỏng):<br />
5 T xanh 300000 123-45-6789
Output:<br />
File renamed<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 258 2004 Microchip Technology Inc.<br />
rewind<br />
Description: Resets the file pointer to the beginning of the file.<br />
Include: <br />
Prototype: void rewind(FILE *stream);<br />
Argument: stream stream to reset the file pointer<br />
Remarks: The function calls fseek(stream, 0L, SEEK_SET)and then clears<br />
the error indicator for the given stream.<br />
Example: #include /* for rewind, fopen, */<br />
/* fscanf, fclose, */<br />
/* fprintf, printf, */<br />
/* FILE, NULL */<br />
int main(void)<br />
{<br />
FILE *myfile;<br />
char s[] = "cookies";<br />
int x = 10;<br />
if ((myfile = fopen("afile", "w+")) == NULL)<br />
printf("Cannot open afile\n");<br />
else<br />
{<br />
fprintf(myfile, "%d %s", x, s);<br />
printf("I have %d %s.\n", x, s);<br />
/* set pointer tobeginning of file */<br />
rewind(myfile);<br />
fscanf(myfile, "%d %s", &x, &s);<br />
printf("I ate %d %s.\n", x, s);<br />
fclose(myfile);<br />
}<br />
}<br />
Output:<br />
I have 10 cookies.<br />
I ate 10 cookies.<br />
Standard C Libraries with Math Functions<br />
Đầu ra:<br />
Nhập số yêu thích của bạn, thư yêu thích,<br />
Màu sắc yêu thích, lương mong muốn và SSN:<br />
Số mục quét = 5<br />
Số yêu thích = 5, thư yêu thích = T<br />
Màu sắc ưa thích = Green, lương mong muốn = $ 300.000,00<br />
Số An Sinh Xã Hội = 123-45-6789<br />
scanf (Tiếp theo)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 261<br />
setbuf<br />
Mô tả: Xác định như thế nào một dòng là đệm.<br />
Bao gồm:<br />
Prototype: void setbuf (FILE * stream, char * buf);<br />
Đối số: dòng con trỏ đến dòng mở<br />
buf sử dụng cấp phát bộ đệm<br />
Bình luận: setbufmust được gọi sau khi fopenbut trước khi gọi chức năng khác<br />
hoạt động trên dòng suối. Nếu bufis một con trỏ null, setbufcalls các<br />
chức năng setvbuf (dòng, 0, _IONBF, BUFSIZ) không có đệm;<br />
nếu không setbufcalls setvbuf (dòng, buf, _IOFBF,<br />
BUFSIZ) để đệm đầy đủ với một bộ đệm có kích thước BUFSIZ. Xem setvbuf.<br />
Ví dụ: # include / * Cho setbuf, printf, * /<br />
/ * Fopen, fclose, * /<br />
/ * FILE, NULL, BUFSIZ * /<br />
int main (void)<br />
{<br />
FILE * myfile1, * myfile2;<br />
char buf [BUFSIZ];<br />
if ((myfile1 = fopen ("afile1", "w +")) = NULL)<br />
{<br />
setbuf (myfile1, NULL);<br />
printf ("myfile1 không có đệm \ n");<br />
fclose (myfile1);<br />
}<br />
if ((myfile2 = fopen ("afile2", "w +")) = NULL)<br />
{<br />
setbuf (myfile2, buf);<br />
printf ("myfile2 có đầy đủ đệm");<br />
fclose (myfile2);
2004 Microchip Technology Inc. DS51456B-page 259<br />
scanf<br />
Description: Scans formatted text from stdin.<br />
Include: <br />
Prototype: int scanf(const char *format, ...);<br />
Argument: format format control string<br />
... optional arguments<br />
Return Value: Returns the number of items successfully converted and assigned.<br />
If<br />
no items are assigned, a 0 is returned. EOF is returned if an input<br />
failure is encountered before the first.<br />
Remarks: Each format specifier begins with a percent sign followed by optional<br />
fields and a required type as shown here:<br />
%[*][width][modifier]type<br />
*<br />
indicates assignment suppression. This will cause the input field to<br />
be skipped and no assignment made.<br />
width<br />
specify the maximum number of input characters to match for the<br />
conversion not including white space that can be skipped.<br />
modifier<br />
h modifier - used with type d, i, o,u, x, X; converts the value to a<br />
short intor unsigned short int.<br />
h modifier - used with n; specifies that the pointer points to a<br />
short int<br />
l modifier - used with type d, i, o,u, x, X; converts the value to a<br />
long intor unsigned long int<br />
l modifier - used with n; specifies that the pointer points to a<br />
long int<br />
l modifier - used with c; specifies a wide character<br />
l modifier - used with type e, E, f, F, g, G; converts the value to a<br />
double<br />
ll modifier - used with type d, i, o, u, x, X; converts the value to a<br />
long long intor unsigned long long int<br />
ll modifier - used with n; specifies that the pointer points to a<br />
long long int<br />
L modifier - used with e, E, f, g, G; converts the value to a long<br />
double<br />
dsPIC<br />
}<br />
}<br />
Đầu ra:<br />
myfile1 không có đệm<br />
myfile2 có đầy đủ đệm<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 262<br />
setvbuf<br />
2004 Microchip Technology Inc<br />
Mô tả: Xác định dòng để được đệm và kích thước bộ đệm.<br />
Bao gồm:<br />
Nguyên mẫu: int setvbuf (FILE * stream, char * buf, int mode,<br />
size_t size);<br />
Đối số: dòng con trỏ đến dòng mở<br />
buf sử dụng cấp phát bộ đệm<br />
loại chế độ đệm<br />
kích thước kích thước của bộ đệm<br />
Quay trở lại giá trị: Trả về 0 nếu thành công<br />
Bình luận: setvbufmust được gọi sau khi fopenbut trước khi bất kỳ chức năng<br />
khác<br />
các cuộc gọi hoạt động trên dòng suối. Đối với chế độ sử dụng một trong các<br />
cách sau:<br />
_IOFBF- Đủ đệm<br />
_IOLBF- Cho dòng đệm<br />
_IONBF- Không có đệm<br />
Ví dụ: # include / * Cho setvbuf, fopen, * /<br />
/ * Printf, FILE, NULL, * /<br />
/ * _IONBF, _IOFBF * /<br />
int main (void)<br />
{<br />
FILE * myfile1, * myfile2;<br />
char buf [256];<br />
if ((myfile1 = fopen ("afile1", "w +")) = NULL)<br />
{<br />
if (setvbuf (myfile1, NULL, _IONBF, 0) == 0)<br />
printf ("myfile1 không có đệm \ n");<br />
khác<br />
printf ("Không thể xác định dòng đệm"<br />
"Và / hoặc kích thước \ n");
®<br />
Language Tools Libraries<br />
DS51456B-page 260 2004 Microchip Technology Inc.<br />
type<br />
d,i signed int<br />
o unsigned intin octal<br />
u unsigned intin decimal<br />
x unsigned intin lowercase hexadecimal<br />
X unsigned intin uppercase hexadecimal<br />
e,E doublein scientific notation<br />
f doubledecimal notation<br />
g,G double(takes the form of e, E or f as appropriate)<br />
c char- a single character<br />
sstring p value of a pointer<br />
n the associated argument shall be an integer pointer into,<br />
which is placed the number of characters read so far. No<br />
characters are scanned.<br />
[...] character array. Allows a search of a set of characters. A<br />
caret (^) immediately after the left bracket ( [ ) inverts the<br />
scanset and allows any ASCII character except those<br />
specified between the brackets. A dash character (-) may be<br />
used to specify a range beginning with the character before<br />
the dash and ending the character after the dash. A null<br />
character can not be part of the scanset.<br />
% A % character is scanned<br />
Example: #include /*for scanf, printf */<br />
int main(void)<br />
{<br />
int number, items;<br />
char letter;<br />
char color[30], string[30];<br />
float salary;<br />
printf("Enter yourfavorite number, "<br />
"favorite letter, ");<br />
printf("favorite color desired salary "<br />
"and SSN:\n");<br />
items = scanf("%d %c %[A-Za-z] %f %s", &number,<br />
&letter, &color, &salary, &string);<br />
printf("Number of items scanned = %d\n", items);<br />
}<br />
fclose (myfile1);<br />
if ((myfile2 = fopen ("afile2", "w +")) = NULL)<br />
{<br />
if (setvbuf (myfile2, buf, _IOFBF, sizeof (buf)) ==<br />
0)<br />
printf ("myfile2 có một bộ đệm của% d"<br />
"Ký tự \ n", sizeof (buf));<br />
khác<br />
printf ("Không thể xác định dòng đệm"<br />
"Và / hoặc kích thước \ n");<br />
}<br />
fclose (myfile2);<br />
}<br />
Đầu ra:<br />
myfile1 không có đệm<br />
myfile2 có bufferof 256 ký tự<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 263<br />
sprintf<br />
Mô tả: In định dạng văn bản cho một chuỗi<br />
Bao gồm:<br />
Nguyên mẫu: int sprintf (char * s, char * format, ...);<br />
Đối số: s chuỗi lưu trữ cho định dạng đầu ra kiểm soát chuỗi định dạng<br />
Đối số tùy chọn ...<br />
Quay trở lại giá trị: Trả về số ký tự được lưu trữ trong sexcluding việc chấm dứ<br />
ký tự null.<br />
Ghi chú: Đối số định dạng có cú pháp tương tự và sử dụng nó có trong<br />
printf.<br />
Ví dụ: # include / * Cho sprintf, printf * /<br />
int main (void)<br />
{<br />
SBUF char [100], s [] = "In chuỗi này";<br />
int x = 1, y;<br />
char '\ n' a =;<br />
y = sprintf (SBUF, "% s% d% thời gian c", s, x, a);<br />
printf ("Số ký tự được in để"<br />
"Chuỗi đệm =% d \ n", y);<br />
printf ("String =% s \ n", SBUF);
printf("Favorite number = %d, ", number);<br />
printf("Favorite letter = %c\n", letter);<br />
printf("Favorite color= %s, ", color);<br />
printf("Desired salary = $%.2f\n", salary);<br />
printf("Social Security Number = %s, ", string);<br />
}<br />
Input:<br />
Contents of UartIn.txt(used as stdin input for simulator):<br />
5 T Green 300000 123-45-6789<br />
Output:<br />
Enter your favorite number, favorite letter,<br />
favorite color, desired salary and SSN:<br />
Number of items scanned = 5<br />
Favorite number = 5,Favorite letter = T<br />
Favorite color = Green, Desired salary = $300000.00<br />
Social Security Number = 123-45-6789<br />
scanf (Continued)<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 261<br />
setbuf<br />
Description: Defines how a stream is buffered.<br />
Include: <br />
Prototype: void setbuf(FILE *stream, char *buf);<br />
Arguments: stream pointer to the open stream<br />
buf user allocated buffer<br />
Remarks: setbufmust be called after fopenbut before any other function calls<br />
that operate on the stream. If bufis a null pointer, setbufcalls the<br />
function setvbuf(stream, 0, _IONBF, BUFSIZ)for no buffering;<br />
otherwise setbufcalls setvbuf(stream, buf, _IOFBF,<br />
BUFSIZ)for full buffering with a buffer of size BUFSIZ. See setvbuf.<br />
Example: #include /* for setbuf, printf, */<br />
/* fopen, fclose, */<br />
/* FILE, NULL, BUFSIZ */<br />
int main(void)<br />
{<br />
FILE *myfile1, *myfile2;<br />
char buf[BUFSIZ];<br />
if ((myfile1 = fopen("afile1", "w+")) != NULL)<br />
{<br />
}<br />
Đầu ra:<br />
Số ký tự được in chuỗi đệm = 25<br />
String = In trang nay chuỗi 1 lần<br />
sscanf<br />
Mô tả: Quét định dạng văn bản từ một chuỗi<br />
Bao gồm:<br />
Nguyên mẫu: int sscanf (const char * s, char * format, ...);<br />
Đối số: s chuỗi lưu trữ cho các định dạng đầu vào chuỗi kiểm soát định dạng<br />
Đối số tùy chọn ...<br />
Quay trở lại giá trị: Trả về số lượng các mục chuyển đổi thành công và được<br />
giao. Nếu<br />
Không có sản phẩm được giao, một 0 được trả về. Kết thúc tập tin được trả lại<br />
nếu một lỗi đầu vào<br />
đang gặp phải trước khi chuyển đổi đầu tiên.<br />
Ghi chú: Đối số định dạng có cú pháp tương tự và sử dụng nó có trong<br />
scanf.<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 264<br />
2004 Microchip Technology Inc<br />
Ví dụ: # include / * Cho sscanf, printf * /<br />
int main (void)<br />
{<br />
char s [] = "5 T 3.000.000,00 xanh";<br />
int số lượng, mặt hàng;<br />
thư char;<br />
char màu [10];<br />
nổi tiền lương;<br />
mục = sscanf (s, "% d% c% s% f", & số, và lá thư,<br />
Và màu sắc, và tiền lương);<br />
printf ("Số scan =% d \ n", các mục);<br />
printf ("yêu thích số =% d \ n", số lượng);<br />
printf ("thư yêu thích =% c \ n", thư);<br />
printf ("Màu sắc ưa thích =% s \ n", màu sắc);<br />
printf ("lương Desired = $% 2f. \ n", tiền lương);<br />
}<br />
Đầu ra:<br />
Số mục quét = 4<br />
Số yêu thích = 5
setbuf(myfile1, NULL);<br />
printf("myfile1 has no buffering\n");<br />
fclose(myfile1);<br />
}<br />
if ((myfile2 = fopen("afile2", "w+")) != NULL)<br />
{<br />
setbuf(myfile2, buf);<br />
printf("myfile2 has full buffering");<br />
fclose(myfile2);<br />
}<br />
}<br />
Output:<br />
myfile1 has no buffering<br />
myfile2 has full buffering<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 262 2004 Microchip Technology Inc.<br />
setvbuf<br />
Description: Defines the stream to be buffered and the buffer size.<br />
Include: <br />
Prototype: int setvbuf(FILE *stream, char *buf, int mode,<br />
size_t size);<br />
Arguments: stream pointer to the open stream<br />
buf user allocated buffer<br />
mode type of buffering<br />
size size of buffer<br />
Return Value: Returns 0 if successful<br />
Remarks: setvbufmust be called after fopenbut before any other function<br />
calls that operate on the stream. For mode use one of the following:<br />
_IOFBF– for full buffering<br />
_IOLBF– for line buffering<br />
_IONBF– for no buffering<br />
Example: #include /* for setvbuf, fopen, */<br />
/* printf, FILE, NULL, */<br />
/* _IONBF, _IOFBF */<br />
int main(void)<br />
{<br />
FILE *myfile1, *myfile2;<br />
Thư yêu thích = T<br />
Màu sắc yêu thích màu xanh lá cây =<br />
Mức lương mong muốn = $ 3.000.000,00<br />
tmpfile<br />
Mô tả: Tạo ra một tập tin tạm thời<br />
Bao gồm:<br />
Prototype: FILE * tmpfile (void)<br />
Quay trở lại giá trị: Trả về một con trỏ dòng nếu thành công; nếu không, trả về<br />
một NULL<br />
con trỏ.<br />
Bình luận: tmpfilecreates một tập tin với một tên tập tin duy nhất. Các tập tin<br />
tạm thời là<br />
mở trong w + b (nhị phân đọc / ghi) chế độ. Nó sẽ tự động được<br />
loại bỏ khi exitis gọi; nếu không thì tập tin sẽ ở lại<br />
thư mục.<br />
Ví dụ: # include / * Cho tmpfile, printf, * /<br />
/ * FILE, NULL * /<br />
int main (void)<br />
{<br />
FILE * mytempfile;<br />
if ((mytempfile = tmpfile ()) == NULL)<br />
printf ("Không thể tạo tập tin tạm thời");<br />
khác<br />
printf ("tập tin tạm thời được tạo ra");<br />
}<br />
Đầu ra:<br />
Tập tin tạm thời được tạo ra<br />
sscanf (Tiếp theo)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 265<br />
tmpnam<br />
Mô tả: Tạo ra một tên tập tin tạm thời độc đáo<br />
Bao gồm:<br />
Prototype: char * tmpnam (char * s);<br />
Đối số: s con trỏ đến tên tạm thời<br />
Quay trở lại giá trị: Trả về một con trỏ đến tên tập tin được tạo ra và lưu trữ các<br />
tên tập tin trong<br />
s. Nếu nó không thể tạo ra một tên tập tin, con trỏ NULL được trả về.<br />
Chú ý: tên tập tin được tạo ra sẽ không mâu thuẫn với một tên tập tin hiện<br />
có. Sử dụng<br />
L_tmpnamto xác định kích thước của mảng đối số của tmpnampoints
char buf[256];<br />
if ((myfile1 = fopen("afile1", "w+")) != NULL)<br />
{<br />
if (setvbuf(myfile1, NULL, _IONBF, 0) == 0)<br />
printf("myfile1 has no buffering\n");<br />
else<br />
printf("Unable to define buffer stream "<br />
"and/or size\n");<br />
}<br />
fclose(myfile1);<br />
if ((myfile2 = fopen("afile2", "w+")) != NULL)<br />
{<br />
if (setvbuf(myfile2, buf, _IOFBF, sizeof(buf)) ==<br />
0)<br />
printf("myfile2 has a buffer of %d "<br />
"characters\n", sizeof(buf));<br />
else<br />
printf("Unable to define buffer stream "<br />
"and/or size\n");<br />
}<br />
fclose(myfile2);<br />
}<br />
Output:<br />
myfile1 has no buffering<br />
myfile2 has a bufferof 256 characters<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 263<br />
sprintf<br />
Description: Prints formatted text to a string<br />
Include: <br />
Prototype: int sprintf(char *s, const char *format, ...);<br />
Arguments: s storage string for output format format control string<br />
... optional arguments<br />
Return Value: Returns the number of characters stored in sexcluding the<br />
terminating<br />
null character.<br />
Remarks: The format argument has the same syntax and use that it has in<br />
printf.<br />
Example: #include /* for sprintf, printf */<br />
để.<br />
Ví dụ: # include / * Cho tmpnam, L_tmpnam, * /<br />
/ * Printf, NULL * /<br />
int main (void)<br />
{<br />
char * mYfiLEname;<br />
char mybuf [L_tmpnam];<br />
char * myptr = (char *) & mybuf;<br />
if ((mYfiLEname = tmpnam (myptr)) == NULL)<br />
printf ("Không thể tạo tên tập tin tạm thời");<br />
khác<br />
printf ("tạm thời tập tin% s đã được tạo ra",<br />
mYfiLEname);<br />
}<br />
Đầu ra:<br />
Tập tin tạm thời được tạo ra ctm00001.tmp<br />
ungetc<br />
Mô tả: Đẩy nhân vật trở lại vào dòng.<br />
Bao gồm:<br />
Nguyên mẫu: int ungetc (int c, FILE * stream);<br />
Đối số: ký tự c được đẩy lùi<br />
dòng con trỏ đến dòng mở<br />
Quay trở lại giá trị: Trả về nhân vật đẩy nếu thành công; nếu không, trả về EOF<br />
Ghi chú: Các nhân vật bị đẩy trở lại sẽ được trả về bởi sau đó đọc trên<br />
dòng. Nếu có nhiều hơn một nhân vật được đẩy trở lại, họ sẽ có<br />
trở lại theo thứ tự ngược lại đẩy họ. Một cuộc gọi thành công vào một tập tin<br />
chức năng định vị (fseek, fsetposor quay lại) hủy bỏ bất kỳ đẩy<br />
ký tự trở lại. Chỉ có một nhân vật của pushback được đảm bảo.<br />
Nhiều cuộc gọi đến ungetcwithout một vị trí can thiệp đọc hoặc tập tin<br />
hoạt động có thể gây ra một sự thất bại.<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 266 2004 Microchip Technology Inc<br />
Ví dụ: # include / * Cho ungetc, fgetc, * /<br />
/ * Printf, fopen, fclose, * /<br />
/ * FILE, NULL, kết thúc tập tin * /<br />
int main (void)<br />
{
int main(void)<br />
{<br />
char sbuf[100], s[]="Print this string";<br />
int x = 1, y;<br />
char a = '\n';<br />
y = sprintf(sbuf, "%s%d time%c", s, x, a);<br />
printf("Number of characters printed to "<br />
"string buffer = %d\n", y);<br />
printf("String= %s\n", sbuf);<br />
}<br />
Output:<br />
Number of characters printed to string buffer = 25<br />
String = Print this string 1 time<br />
sscanf<br />
Description: Scans formatted text from a string<br />
Include: <br />
Prototype: int sscanf(const char *s, const char *format, ...);<br />
Arguments: s storage string for input format format control string<br />
... optional arguments<br />
Return Value: Returns the number of items successfully converted and assigned.<br />
If<br />
no items are assigned, a 0 is returned. EOF is returned if an input error<br />
is encountered before the first conversion.<br />
Remarks: The format argument has the same syntax and use that it has in<br />
scanf.<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
FILE * buf;<br />
char y, c;<br />
if ((buf = fopen ("afile.txt", "r")) == NULL)<br />
printf ("Không thể mở afile.txt \ n");<br />
khác<br />
{<br />
y = fgetc (buf);<br />
trong khi (y! = EOF)<br />
{<br />
if (y == 'r')<br />
{<br />
c = ungetc (y, buf);<br />
if (c! = EOF)<br />
{<br />
printf ("2");<br />
y = fgetc (buf);<br />
}<br />
}<br />
printf ("% c", y);<br />
y = fgetc (buf);<br />
}<br />
fclose (buf);<br />
}<br />
}<br />
Đầu vào:<br />
Nội dung afile.txt (được sử dụng như đầu vào):<br />
Ngắn<br />
Chuỗi dài hơn<br />
DS51456B-page 264<br />
2004 Microchip Technology Inc.<br />
Đầu ra:<br />
Example: #include /* for sscanf, printf */<br />
int main(void)<br />
{<br />
char s[] = "5 T green 3000000.00";<br />
int number, items;<br />
char letter;<br />
char color[10];<br />
float salary;<br />
items = sscanf(s, "%d %c %s %f", &number, &letter,<br />
&color, &salary);<br />
Sho2rt<br />
Longe2r st2ring<br />
ungetc (Tiếp theo)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 267<br />
vfprintf<br />
Mô tả: In định dạng dữ liệu cho một dòng bằng cách sử dụng một danh sách đố<br />
số chiều dài biến.<br />
Bao gồm:<br />
Nguyên mẫu: int vfprintf (FILE * stream, const char * format,<br />
va_list ap);
printf("Number of items scanned = %d\n", items);<br />
printf("Favorite number = %d\n", number);<br />
printf("Favorite letter = %c\n", letter);<br />
printf("Favorite color = %s\n", color);<br />
printf("Desired salary = $%.2f\n", salary);<br />
}<br />
Output:<br />
Number of items scanned = 4<br />
Favorite number = 5<br />
Favorite letter = T<br />
Favorite color = green<br />
Desired salary = $3000000.00<br />
tmpfile<br />
Description: Creates a temporary file<br />
Include: <br />
Prototype: FILE *tmpfile(void)<br />
Return Value: Returns a stream pointer if successful; otherwise, returns a NULL<br />
pointer.<br />
Remarks: tmpfilecreates a file with a unique filename. The temporary file is<br />
opened in w+b(binary read/write) mode. It will automatically be<br />
removed when exitis called; otherwise the file will remain in the<br />
directory.<br />
Example: #include /* for tmpfile, printf, */<br />
/* FILE, NULL */<br />
int main(void)<br />
{<br />
FILE *mytempfile;<br />
if ((mytempfile = tmpfile()) == NULL)<br />
printf("Cannot create temporary file");<br />
else<br />
printf("Temporary file was created");<br />
}<br />
Output:<br />
Temporary file was created<br />
sscanf (Continued)<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 265<br />
tmpnam<br />
Description: Creates a unique temporary filename<br />
Đối số: dòng con trỏ đến dòng mở<br />
định dạng kiểm soát chuỗi định dạng<br />
ap con trỏ đến một danh sách các đối số<br />
Quay trở lại giá trị: Trả về số ký tự được tạo ra hoặc một số âm nếu một<br />
lỗi xảy ra.<br />
Ghi chú: Đối số định dạng có cú pháp tương tự và sử dụng nó có trong<br />
printf.<br />
Để truy cập vào danh sách đối số chiều dài biến, apvariable phải<br />
khởi tạo bởi các va_startand vĩ mô có thể được khởi tạo lại bởi<br />
cuộc gọi bổ sung cho va_arg. Điều này phải được thực hiện trước khi vfprintf<br />
hàm được gọi. Gọi va_endafter trở về chức năng. Để biết thêm<br />
chi tiết xem stdarg.h.<br />
Ví dụ: # include / * Forvfprintf, fopen, * /<br />
/ * Fclose, printf, * /<br />
/ * FILE, NULL * /<br />
# include / * Cho va_start, * /<br />
/ * Va_list, va_end * /<br />
FILE * myfile;<br />
khoảng trống errmsg (const char * fmt, ...)<br />
{<br />
va_list ap;<br />
va_start (ap, fmt);<br />
vfprintf (myfile, fmt, ap);<br />
va_end (ap);<br />
}<br />
int main (void)<br />
{<br />
int num = 3;<br />
if ((myfile = fopen ("afile.txt", "w")) == NULL)<br />
printf ("Không thể mở afile.txt \ n");<br />
khác<br />
{<br />
errmsg ("Lỗi: Ký tự"% c 'không phải là% s \ n ",' a ',<br />
"Một số nguyên.");<br />
errmsg ("Lỗi: Yêu cầu% d% s% c", num,<br />
"Hoặc nhiều ký tự.", '\ N');<br />
}<br />
fclose (myfile);<br />
}
Include: <br />
Prototype: char *tmpnam(char *s);<br />
Argument: s pointer to the temporary name<br />
Return Value: Returns a pointer to the filename generated and stores the<br />
filename in<br />
s. If it can not generate a filename, the NULL pointer is returned.<br />
Remarks: The created filename will not conflict with an existing file name. Use<br />
Đầu ra:<br />
Nội dung afile.txt<br />
Lỗi: chữ 'a' isnot một số nguyên.<br />
Lỗi: Yêu cầu 3 ormore ký tự.<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
L_tmpnamto define the size of array the argument of tmpnampoints<br />
to.<br />
DS51456B trang 268<br />
vprintf<br />
2004 Microchip Technology Inc<br />
Example: #include /* for tmpnam, L_tmpnam, */<br />
/* printf, NULL */<br />
int main(void)<br />
{<br />
char *myfilename;<br />
char mybuf[L_tmpnam];<br />
char *myptr = (char *) &mybuf;<br />
if ((myfilename = tmpnam(myptr)) == NULL)<br />
printf("Cannot create temporary file name");<br />
else<br />
printf("Temporary file %s was created",<br />
myfilename);<br />
}<br />
Output:<br />
Temporary file ctm00001.tmp was created<br />
ungetc<br />
Description: Pushes character back onto stream.<br />
Include: <br />
Prototype: int ungetc(int c, FILE *stream);<br />
Argument: c character to be pushed back<br />
stream pointer to the open stream<br />
Return Value: Returns the pushed character if successful; otherwise, returns<br />
EOF<br />
Remarks: The pushed back character will be returned by a subsequent read on<br />
the stream. If more than one character is pushed back, they will be<br />
returned in the reverse order of their pushing. A successful call to a file<br />
positioning function (fseek, fsetposor rewind) cancels any pushed<br />
back characters. Only one character of pushback is guaranteed.<br />
Multiple calls to ungetcwithout an intervening read or file positioning<br />
operation may cause a failure.<br />
dsPIC<br />
Mô tả: In định dạng văn bản để stdoutusing một danh sách đối số chiều dài biến<br />
Bao gồm:<br />
Nguyên mẫu: int vprintf (const char * format, va_list ap);<br />
Đối số: chuỗi định dạng kiểm soát định dạng<br />
ap con trỏ đến một danh sách các đối số trở lại giá trị: Trả về số ký tự được tạo<br />
ra hoặc một số âm nếu một<br />
lỗi xảy ra.<br />
Ghi chú: Đối số định dạng có cú pháp tương tự và sử dụng nó có trong<br />
printf.<br />
Để truy cập vào danh sách đối số chiều dài biến, apvariable phải<br />
khởi tạo bởi các va_startand vĩ mô có thể được khởi tạo lại bởi<br />
cuộc gọi bổ sung cho va_arg. Điều này phải được thực hiện trước khi vprintf<br />
hàm được gọi. Gọi va_endafter trở về chức năng. Để biết thêm<br />
chi tiết xem stdarg.h<br />
Ví dụ: # include / * Cho vprintf, printf * /<br />
# include / * Cho va_start, * /<br />
/ * Va_list, va_end * /<br />
khoảng trống errmsg (const char * fmt, ...)<br />
{<br />
va_list ap;<br />
va_start (ap, fmt);<br />
printf ("Lỗi:");<br />
vprintf (fmt, ap);<br />
va_end (ap);<br />
}<br />
int main (void)<br />
{<br />
int num = 3;<br />
errmsg ("Bức thư '% c' không phải là% s \ n", 'a',<br />
"Một số nguyên.");<br />
errmsg ("Yêu cầu% d% s \ n", num,
®<br />
Language Tools Libraries<br />
DS51456B-page 266 2004 Microchip Technology Inc.<br />
Example: #include /* for ungetc, fgetc, */<br />
/* printf, fopen, fclose, */<br />
/* FILE, NULL, EOF */<br />
int main(void)<br />
{<br />
FILE *buf;<br />
char y, c;<br />
if ((buf = fopen("afile.txt", "r")) == NULL)<br />
printf("Cannot open afile.txt\n");<br />
else<br />
{<br />
y = fgetc(buf);<br />
while (y != EOF)<br />
{<br />
if (y == 'r')<br />
{<br />
c = ungetc(y, buf);<br />
if (c != EOF)<br />
{<br />
printf("2");<br />
y = fgetc(buf);<br />
}<br />
}<br />
printf("%c", y);<br />
y = fgetc(buf);<br />
}<br />
fclose(buf);<br />
}<br />
}<br />
Input:<br />
Contents of afile.txt(used as input):<br />
Short<br />
Longer string<br />
Output:<br />
Sho2rt<br />
Longe2r st2ring<br />
"Hoặc nhiều ký tự. \ N");<br />
}<br />
Đầu ra:<br />
Lỗi: chữ 'a' isnot một số nguyên.<br />
Lỗi: Yêu cầu 3 ormore ký tự.<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 269<br />
vsprintf<br />
Mô tả: In định dạng văn bản cho một chuỗi bằng cách sử dụng một danh sách<br />
đối số chiều dài biến<br />
Bao gồm:<br />
Nguyên mẫu: int vsprintf (char * s, char * format, va_list<br />
ap);<br />
Đối số: s chuỗi lưu trữ cho đầu ra<br />
định dạng kiểm soát chuỗi định dạng<br />
ap con trỏ đến một danh sách các đối số trở lại giá trị: Trả về số ký tự được lưu<br />
trữ trong sexcluding việc chấm dứt vô<br />
nhân vật.<br />
Ghi chú: Đối số định dạng có cú pháp tương tự và sử dụng nó có trong<br />
printf.<br />
Để truy cập vào danh sách đối số chiều dài biến, apvariable phải<br />
khởi tạo bởi các va_startand vĩ mô có thể được khởi tạo lại bởi<br />
cuộc gọi bổ sung cho va_arg. Điều này phải được thực hiện trước khi vsprintf<br />
hàm được gọi. Gọi va_endafter trở về chức năng. Để biết thêm<br />
chi tiết xem stdarg.h<br />
Ví dụ: # include / * Cho vsprintf, printf * /<br />
# include / * Cho va_start, * /<br />
/ * Va_list, va_end * /<br />
khoảng trống errmsg (const char * fmt, ...)<br />
{<br />
va_list ap;<br />
char buf [100];<br />
va_start (ap, fmt);<br />
vsprintf (buf, fmt, ap);<br />
va_end (ap);<br />
printf ("Lỗi:% s", buf);<br />
}<br />
int main (void)<br />
{<br />
int num = 3;
ungetc (Continued)<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 267<br />
vfprintf<br />
Description: Prints formatted data to a stream using a variable length argument<br />
list.<br />
Include: <br />
<br />
Prototype: int vfprintf(FILE *stream, const char *format,<br />
va_list ap);<br />
Arguments: stream pointer to the open stream<br />
errmsg ("Bức thư '% c' không phải là% s \ n", 'a',<br />
"Một số nguyên.");<br />
errmsg ("Yêu cầu% d% s \ n", num,<br />
"Hoặc nhiều ký tự. \ N");<br />
}<br />
Đầu ra:<br />
Lỗi: chữ 'a' isnot một số nguyên.<br />
Lỗi: Yêu cầu 3 ormore ký tự.<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
format format control string<br />
DS51456B trang 270<br />
2004 Microchip Technology Inc<br />
ap pointer to a list of arguments<br />
Return Value: Returns number of characters generated or a negative number if<br />
an<br />
error occurs.<br />
Remarks: The format argument has the same syntax and use that it has in<br />
printf.<br />
To access the variable length argument list, the apvariable must be<br />
initialized by the macro va_startand may be reinitialized by<br />
additional calls to va_arg. This must be done before the vfprintf<br />
function is called. Invoke va_endafter the function returns. For more<br />
details see stdarg.h.<br />
Example: #include /* forvfprintf, fopen, */<br />
/* fclose, printf, */<br />
/* FILE, NULL */<br />
#include /* for va_start, */<br />
/* va_list, va_end */<br />
FILE *myfile;<br />
void errmsg(const char *fmt, ...)<br />
{<br />
va_list ap;<br />
va_start(ap, fmt);<br />
vfprintf(myfile, fmt, ap);<br />
va_end(ap);<br />
}<br />
int main(void)<br />
{<br />
int num = 3;<br />
if ((myfile = fopen("afile.txt", "w")) == NULL)<br />
4.14 CHỨC NĂNG TIỆN ÍCH<br />
Các stdlib.hconsists tập tin tiêu đề của các loại, macro và các chức năng cung<br />
cấp các văn bản<br />
chuyển đổi, quản lý bộ nhớ, tìm kiếm và phân loại khả năng, và các chung<br />
tiện ích.<br />
div_t<br />
Mô tả: Một loại chứa một thương và phần còn lại của một bộ phận nguyên ký<br />
với toán hạng kiểu int.<br />
Bao gồm:<br />
Nguyên mẫu: struct {intquot, rem; } Div_t;<br />
Ghi chú: Đây là loại cấu trúc hàm trả về div.<br />
ldiv_t<br />
Mô tả: Một loại chứa một thương và phần còn lại của một bộ phận nguyên ký<br />
với toán hạng của loại dài.<br />
Bao gồm:<br />
Nguyên mẫu: struct {quot dài, rem; } Ldiv_t;<br />
Ghi chú: Đây là loại cấu trúc hàm trả về ldiv.<br />
size_t<br />
Mô tả: Các loại kết quả của sizeofoperator.<br />
Bao gồm:<br />
wchar_t<br />
Mô tả: Một loại chứa một giá trị nhân vật rộng.<br />
Bao gồm:<br />
EXIT_FAILURE<br />
Mô tả: Báo cáo kết thúc không thành công.<br />
Bao gồm:<br />
Bình luận: EXIT_FAILUREis một giá trị cho các chức năng thoát để trở về mộ<br />
chấm dứt tình trạng không thành công
printf("Cannot open afile.txt\n");<br />
else<br />
{<br />
errmsg("Error: The letter '%c' is not %s\n", 'a',<br />
"an integer value.");<br />
errmsg("Error: Requires %d%s%c", num,<br />
" or more characters.", '\n');<br />
}<br />
fclose(myfile);<br />
}<br />
Output:<br />
Contents of afile.txt<br />
Error: The letter 'a' isnot an integer value.<br />
Error: Requires 3 ormore characters.<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
Ví dụ: Xem exitfor ví dụ về sử dụng.<br />
EXIT_SUCCESS<br />
Mô tả: Báo cáo kết thúc thành công<br />
Bao gồm:<br />
Bình luận: EXIT_SUCCESSis một giá trị cho các chức năng thoát để trở về mộ<br />
thành công<br />
trạng thái chấm dứt.<br />
Ví dụ: Xem exitfor ví dụ về sử dụng.<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 271<br />
MB_CUR_MAX<br />
Mô tả: Tối đa số charactersin một nhân vật nhiều byte<br />
Bao gồm:<br />
Giá trị: 1<br />
NULL<br />
Mô tả: Giá trị của một con trỏ hằng rỗng<br />
Bao gồm:<br />
RAND_MAX<br />
DS51456B-page 268<br />
vprintf<br />
2004 Microchip Technology Inc.<br />
Mô tả: Giá trị tối đa khả năng được trả về bởi randfunction<br />
Bao gồm:<br />
Description: Prints formatted text to stdoutusing a variable length argument list<br />
Include: <br />
<br />
Prototype: int vprintf(const char *format, va_list ap);<br />
Arguments: format format control string<br />
ap pointer to a list of arguments Return Value: Returns number of characters<br />
generated or a negative number if an<br />
error occurs.<br />
Remarks: The format argument has the same syntax and use that it has in<br />
printf.<br />
To access the variable length argument list, the apvariable must be<br />
initialized by the macro va_startand may be reinitialized by<br />
additional calls to va_arg. This must be done before the vprintf<br />
function is called. Invoke va_endafter the function returns. For more<br />
details see stdarg.h<br />
Example: #include /* for vprintf, printf */<br />
#include /* for va_start, */<br />
/* va_list, va_end */<br />
void errmsg(const char *fmt, ...)<br />
{<br />
Giá trị: 32767<br />
hủy bỏ<br />
Mô tả: hủy bỏ quá trình hiện tại.<br />
Bao gồm:<br />
Prototype: void abort (void);<br />
Bình luận: abortwill gây ra bộ vi xử lý để thiết lập lại.<br />
Ví dụ: # include / * Cho fopen, fclose, * /<br />
/ * Printf, FILE, NULL * /<br />
# include / * Cho hủy bỏ * /<br />
int main (void)<br />
{<br />
FILE * myfile;<br />
if ((myfile = fopen ("samp.fil", "r")) == NULL)<br />
{<br />
printf ("Không thể mở samp.fil \ n");<br />
hủy bỏ ();<br />
}<br />
khác<br />
printf ("Thành công mở samp.fil \ n");<br />
fclose (myfile);
va_list ap;<br />
va_start(ap, fmt);<br />
printf("Error: ");<br />
vprintf(fmt, ap);<br />
va_end(ap);<br />
}<br />
int main(void)<br />
{<br />
int num = 3;<br />
errmsg("The letter '%c' is not %s\n", 'a',<br />
"an integer value.");<br />
errmsg("Requires %d%s\n", num,<br />
" or more characters.\n");<br />
}<br />
Output:<br />
Error: The letter 'a' isnot an integer value.<br />
Error: Requires 3 ormore characters.<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 269<br />
vsprintf<br />
Description: Prints formatted text to a string using a variable length argument<br />
list<br />
Include: <br />
<br />
Prototype: int vsprintf(char *s, const char *format, va_list<br />
ap);<br />
Arguments: s storage string for output<br />
format format control string<br />
ap pointer to a list of arguments Return Value: Returns number of characters<br />
stored in sexcluding the terminating null<br />
character.<br />
Remarks: The format argument has the same syntax and use that it has in<br />
printf.<br />
To access the variable length argument list, the apvariable must be<br />
initialized by the macro va_startand may be reinitialized by<br />
additional calls to va_arg. This must be done before the vsprintf<br />
function is called. Invoke va_endafter the function returns. For more<br />
details see stdarg.h<br />
Example: #include /* for vsprintf, printf */<br />
#include /* for va_start, */<br />
}<br />
Đầu ra:<br />
Không thể mở samp.fil<br />
ABRT<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 272 2004 Microchip Technology Inc<br />
abs<br />
Mô tả: Tính giá trị tuyệt đối.<br />
Bao gồm:<br />
Nguyên mẫu: int abs (int i);<br />
Đối số: i số nguyên giá trị<br />
Quay trở lại giá trị: Trả về giá trị tuyệt đối của tôi.<br />
Bình luận: Một số âm được trả về là tích cực; một số dương là<br />
không thay đổi.<br />
Ví dụ: # include / * Cho printf * /<br />
# include / * Cho abs * /<br />
int main (void)<br />
{<br />
int i;<br />
i = 12;<br />
printf ("Giá trị tuyệt đối của% d% d \ n",<br />
i, abs (i));<br />
i = -2;<br />
printf ("Giá trị tuyệt đối của% d% d \ n",<br />
i, abs (i));<br />
i = 0;<br />
printf ("Giá trị tuyệt đối của% d% d \ n",<br />
i, abs (i));<br />
}<br />
Đầu ra:<br />
Giá trị tuyệt đối của 12 là 12<br />
Giá trị tuyệt đối của -2 là 2<br />
Giá trị tuyệt đối của 0 là 0<br />
atexit<br />
Mô tả: Thanh ghi chức năng xác định được gọi khi chương trình<br />
chấm dứt bình thường.<br />
Bao gồm:
* va_list, va_end */<br />
void errmsg(const char *fmt, ...)<br />
{<br />
va_list ap;<br />
char buf[100];<br />
va_start(ap, fmt);<br />
vsprintf(buf, fmt, ap);<br />
va_end(ap);<br />
printf("Error: %s", buf);<br />
}<br />
int main(void)<br />
{<br />
int num = 3;<br />
errmsg("The letter '%c' is not %s\n", 'a',<br />
"an integer value.");<br />
errmsg("Requires %d%s\n", num,<br />
" or more characters.\n");<br />
}<br />
Output:<br />
Error: The letter 'a' isnot an integer value.<br />
Error: Requires 3 ormore characters.<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 270<br />
2004 Microchip Technology Inc.<br />
4.14 UTILITY FUNCTIONS<br />
The header file stdlib.hconsists of types, macros and functions that provide text<br />
conversions, memory management, searching and sorting abilities, and other<br />
general<br />
utilities.<br />
div_t<br />
Description: A type that holds a quotient and remainder of a signed integer<br />
division<br />
with operands of type int.<br />
Include: <br />
Prototype: typedef struct { intquot, rem; } div_t;<br />
Remarks: This is the structure type returned by the function div.<br />
ldiv_t<br />
Description: A type that holds a quotient and remainder of a signed integer<br />
division<br />
Nguyên mẫu: int atexit (void (* func) (void));<br />
Đối số: chức năng Func được gọi là<br />
Quay trở lại giá trị: Trả về một số không nếu thành công; nếu không, trả về một<br />
giá trị khác không.<br />
Ghi chú: Đối với các chức năng đăng ký để được gọi là, chương trình phải chấm<br />
dứt<br />
với các cuộc gọi exitfunction.<br />
Ví dụ: # include / * Cho scanf, printf * /<br />
# include / * Cho atexit, xuất cảnh * /<br />
good_msg trống (void);<br />
bad_msg trống (void);<br />
end_msg trống (void);<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 273<br />
int main (void)<br />
{<br />
int số;<br />
atexit (end_msg);<br />
printf ("Nhập số yêu thích của bạn:");<br />
scanf ("% d", & số lượng);<br />
printf ("% d \ n", số lượng);<br />
if (số == 5)<br />
{<br />
printf ("Good Choice \ n");<br />
atexit (good_msg);<br />
exit (0);<br />
}<br />
khác<br />
{<br />
("?% d \ n", số lượng) printf;<br />
atexit (bad_msg);<br />
exit (0);<br />
}<br />
}<br />
good_msg trống (void)<br />
{<br />
printf ("Đó là một số lượng \ n tuyệt vời");<br />
}<br />
bad_msg trống (void)<br />
{
with operands of type long.<br />
Include: <br />
Prototype: typedef struct { long quot, rem; } ldiv_t;<br />
Remarks: This is the structure type returned by the function ldiv.<br />
size_t<br />
Description: The type of the result of the sizeofoperator.<br />
Include: <br />
wchar_t<br />
Description: A type that holds a wide character value.<br />
Include: <br />
EXIT_FAILURE<br />
Description: Reports unsuccessful termination.<br />
Include: <br />
Remarks: EXIT_FAILUREis a value for the exit function to return an<br />
unsuccessful termination status<br />
Example: See exitfor example of use.<br />
EXIT_SUCCESS<br />
Description: Reports successful termination<br />
Include: <br />
Remarks: EXIT_SUCCESSis a value for the exit function to return a successful<br />
termination status.<br />
Example: See exitfor example of use.<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 271<br />
MB_CUR_MAX<br />
Description: Maximum number of charactersin a multibyte character<br />
Include: <br />
Value: 1<br />
NULL<br />
Description: The value of a null pointer constant<br />
Include: <br />
RAND_MAX<br />
Description: Maximum value capable of being returned by the randfunction<br />
Include: <br />
Value: 32767<br />
abort<br />
Description: Aborts the current process.<br />
Include: <br />
Prototype: void abort(void);<br />
printf ("Đó là một con số khủng khiếp \ n");<br />
}<br />
end_msg trống (void)<br />
{<br />
printf ("Bây giờ gocount một cái gì đó \ n");<br />
}<br />
Đầu vào:<br />
Với nội dung của UartIn.txt (sử dụng như stdininput cho giả lập):<br />
5<br />
Đầu ra:<br />
Nhập số yêu thích của bạn: 5<br />
Good Choice<br />
Đó là một con số tuyệt vời<br />
Bây giờ đi đếm một cái gì đó<br />
Đầu vào:<br />
Với nội dung của UartIn.txt (sử dụng như stdininput cho giả lập):<br />
42<br />
Đầu ra:<br />
Nhập số yêu thích của bạn: 42<br />
42 !?<br />
Đó là một con số khủng khiếp<br />
Bây giờ đi đếm một cái gì đó<br />
atexit (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 274<br />
atof<br />
2004 Microchip Technology Inc<br />
Mô tả: Chuyển đổi một chuỗi đến một độ chính xác gấp đôi giá trị dấu chấm<br />
động.<br />
Bao gồm:<br />
Prototype: atof đôi (const char * s);<br />
Đối số: s con trỏ đến chuỗi được chuyển đổi<br />
Quay trở lại giá trị: Trả về giá trị chuyển đổi nếu thành công; nếu không, trả về<br />
0.<br />
Ghi chú: Số lượng có thể bao gồm những điều sau đây:<br />
[Khoảng trắng] [dấu hiệu] chữ số [.digits]<br />
[{E | E} [dấu hiệu] chữ số]<br />
khoảng trắng tùy chọn, theo sau là một signthen tùy chọn một chuỗi<br />
của một hoặc nhiều digitswith một điểm thập phân tùy chọn, theo sau là một
Remarks: abortwill cause the processor to reset.<br />
Example: #include /* for fopen, fclose, */<br />
/* printf, FILE, NULL */<br />
#include /* for abort */<br />
int main(void)<br />
{<br />
FILE *myfile;<br />
if ((myfile = fopen("samp.fil", "r")) == NULL)<br />
{<br />
printf("Cannot open samp.fil\n");<br />
abort();<br />
}<br />
else<br />
printf("Success opening samp.fil\n");<br />
fclose(myfile);<br />
}<br />
Output:<br />
Cannot open samp.fil<br />
ABRT<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 272 2004 Microchip Technology Inc.<br />
abs<br />
Description: Calculates the absolute value.<br />
Include: <br />
Prototype: int abs(int i);<br />
Argument: i integer value<br />
Return Value: Returns the absolute value of i.<br />
Remarks: A negative number is returned as positive; a positive number is<br />
unchanged.<br />
Example: #include /* for printf */<br />
#include /* for abs */<br />
int main(void)<br />
{<br />
int i;<br />
i = 12;<br />
printf("The absolute value of %d is %d\n",<br />
i, abs(i));<br />
hoặc tùy chọn hơn digitsand một EOR tùy chọn Efollowed bởi một tùy chọn<br />
mũ đã ký kết. Việc chuyển đổi dừng lại khi lần đầu tiên được công nhận<br />
nhân vật đạt được. Việc chuyển đổi cũng giống như strtod (s, 0,0)<br />
ngoại trừ nó không có kiểm tra lỗi để errnowill không được thiết lập.<br />
Ví dụ: # include / * Cho printf * /<br />
# include / * Cho atof * /<br />
int main (void)<br />
{<br />
char a [] = "1,28";<br />
char b [] = "27.835e2";<br />
char c [] = "Number1";<br />
x đôi;<br />
x = atof (a);<br />
printf ("String = \"% s \ "float =% f \ n", a, x);<br />
x = atof (b);<br />
printf ("String = \"% s \ "float =% f \ n", b, x);<br />
x = atof (c);<br />
printf ("String = \"% s \ "float =% f \ n", c, x);<br />
}<br />
Đầu ra:<br />
String = "1.28" float = 1,280000<br />
String = "27,835: e2" float = 2783,500000<br />
String = "Number1" float = 0.000000<br />
Thư viện chuẩn C với hàm toán học<br />
atoi<br />
2004 Microchip Technology Inc DS51456B trang 275<br />
Mô tả: Chuyển đổi một chuỗi số nguyên.<br />
Bao gồm:<br />
Nguyên mẫu: int atoi (const char * s);<br />
Đối số: s chuỗi được chuyển đổi<br />
Quay trở lại giá trị: Trả về số nguyên chuyển đổi nếu thành công; nếu không, tr<br />
về 0.<br />
Ghi chú: Số lượng có thể bao gồm những điều sau đây:<br />
[Khoảng trắng] [dấu hiệu] chữ số<br />
khoảng trắng tùy chọn, theo sau là một signthen tùy chọn một chuỗi<br />
của một hoặc nhiều chữ số. Việc chuyển đổi dừng lại khi lần đầu tiên<br />
nhân vật không được công nhận là đạt. Việc chuyển đổi tương đương với<br />
(Int) strtol (s, 0,10), ngoại trừ nó không có kiểm tra lỗi để errno<br />
sẽ không được thiết lập.<br />
Ví dụ: # include / * Cho printf * /
i = -2;<br />
printf("The absolute value of %d is %d\n",<br />
i, abs(i));<br />
i = 0;<br />
printf("The absolute value of %d is %d\n",<br />
i, abs(i));<br />
}<br />
Output:<br />
The absolute value of 12 is 12<br />
The absolute value of -2 is 2<br />
The absolute value of 0 is 0<br />
atexit<br />
Description: Registers the specified function to be called when the program<br />
terminates normally.<br />
Include: <br />
Prototype: int atexit(void(*func)(void));<br />
Argument: func function to be called<br />
Return Value: Returns a zero if successful; otherwise, returns a non-zero value.<br />
Remarks: For the registered functions to be called, the program must terminate<br />
with the exitfunction call.<br />
Example: #include /* for scanf, printf */<br />
#include /* for atexit, exit */<br />
void good_msg(void);<br />
void bad_msg(void);<br />
void end_msg(void);<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 273<br />
int main(void)<br />
{<br />
int number;<br />
# include / * Cho atoi * /<br />
int main (void)<br />
{<br />
char a [] = "-127";<br />
char b [] = "Number1";<br />
int x;<br />
x = atoi (a);<br />
printf ("String = \"% s \ "\ màu =% d \ n", a, x);<br />
x = atoi (b);<br />
printf ("String = \"% s \ "\ màu =% d \ n", b, x);<br />
}<br />
Đầu ra:<br />
String = "-127" int = -127<br />
String = "Number1" int = 0<br />
atol<br />
Mô tả: Chuyển đổi một chuỗi thành một số nguyên dài.<br />
Bao gồm:<br />
Prototype: atol dài (const char * s);<br />
Đối số: s chuỗi được chuyển đổi<br />
Quay trở lại giá trị: Trả về longinteger chuyển đổi nếu thành công; nếu không,<br />
trả về 0<br />
Ghi chú: Số lượng có thể bao gồm những điều sau đây:<br />
[Khoảng trắng] [dấu hiệu] chữ số<br />
khoảng trắng tùy chọn, theo sau là một signthen tùy chọn một chuỗi<br />
của một hoặc nhiều chữ số. Việc chuyển đổi dừng lại khi lần đầu tiên<br />
nhân vật không được công nhận là đạt. Việc chuyển đổi tương đương với<br />
(Int) strtol (s, 0,10), ngoại trừ nó không có kiểm tra lỗi để errno<br />
sẽ không được thiết lập.<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
atexit(end_msg);<br />
DS51456B trang 276<br />
2004 Microchip Technology Inc<br />
printf("Enter your favorite number:");<br />
scanf("%d", &number);<br />
printf(" %d\n", number);<br />
if (number == 5)<br />
{<br />
printf("Good Choice\n");<br />
atexit(good_msg);<br />
exit(0);<br />
Ví dụ: # include / * Cho printf * /<br />
# include / * Cho atol * /<br />
int main (void)<br />
{<br />
char a [] = "-123.456";<br />
char b [] = "2Number";<br />
x dài;<br />
x = atol (a);
}<br />
else<br />
{<br />
printf("%d!?\n", number);<br />
atexit(bad_msg);<br />
exit(0);<br />
}<br />
}<br />
void good_msg(void)<br />
{<br />
printf("That's an excellent number\n");<br />
}<br />
void bad_msg(void)<br />
{<br />
printf("That's an awful number\n");<br />
}<br />
void end_msg(void)<br />
{<br />
printf("Now gocount something\n");<br />
}<br />
Input:<br />
With contents of UartIn.txt(used as stdininput for simulator):<br />
5<br />
Output:<br />
Enter your favorite number: 5<br />
Good Choice<br />
That's an excellent number<br />
Now go count something<br />
Input:<br />
With contents of UartIn.txt(used as stdininput for simulator):<br />
42<br />
Output:<br />
Enter your favorite number: 42<br />
42!?<br />
That's an awful number<br />
Now go count something<br />
atexit (Continued)<br />
dsPIC<br />
®<br />
printf ("String = \"% s \ "int =% ld \ n", a, x);<br />
x = atol (b);<br />
printf ("String = \"% s \ "int =% ld \ n", b, x);<br />
}<br />
Đầu ra:<br />
String = "-123.456" int = -123.456<br />
String = "2Number" int = 2<br />
bsearch<br />
Mô tả: Thực hiện tìm kiếm nhị phân<br />
Bao gồm:<br />
Nguyên mẫu: void * bsearch (const void * quan trọng, const void * cơ sở,<br />
nelem size_t, size_t size,<br />
int (* CMP) (const void * ck, const void * ce));<br />
Đối số: đối tượng quan trọng để tìm kiếm<br />
con trỏ cơ sở để bắt đầu tìm kiếm dữ liệu<br />
số nelem của các yếu tố<br />
kích thước kích thước của các yếu tố<br />
CMP con trỏ đến chức năng so sánh<br />
ck con trỏ đến chìa khóa cho việc tìm kiếm<br />
ce con trỏ đến phần tử được so sánh với phím.<br />
Quay trở lại giá trị: Trả về một con trỏ đến các đối tượng được tìm kiếm nếu tìm<br />
thấy; nếu không,<br />
trở về NULL.<br />
Bình luận: Giá trị trả về của hàm so sánh là 0 nếu ckis lớn hơn ce.<br />
Trong ví dụ sau, qsortis sử dụng để sắp xếp danh sách trước khi bsearch<br />
được gọi. bsearchrequires danh sách được sắp xếp theo<br />
chức năng so sánh. Đây compuses thứ tự tăng dần.<br />
atol (Tiếp theo)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 277<br />
Ví dụ: # include / * Cho bsearch, qsort * /<br />
# include / * Cho printf, sizeof * /<br />
# xác định NUM 7<br />
int comp (const void * e1, const void * e2);<br />
int main (void)<br />
{<br />
int danh sách [NUM] = {35, 47,63, 25, 93, 16, 52};<br />
int x, y;<br />
int * r;
Language Tools Libraries<br />
DS51456B-page 274 2004 Microchip Technology Inc.<br />
atof<br />
Description: Converts a string to a double precision floating-point value.<br />
Include: <br />
Prototype: double atof(const char *s);<br />
Argument: s pointer to the string to be converted<br />
Return Value: Returns the converted value if successful; otherwise, returns 0.<br />
Remarks: The number may consist of the following:<br />
[whitespace] [sign] digits [.digits]<br />
[ { e | E }[sign]digits]<br />
optional whitespace, followed by an optional signthen a sequence<br />
of one or more digitswith an optional decimal point, followed by one<br />
or more optional digitsand an optional eor Efollowed by an optional<br />
signed exponent. The conversion stops when the first unrecognized<br />
character is reached. The conversion is the same as strtod(s,0,0)<br />
except it does no error checking so errnowill not be set.<br />
Example: #include /* for printf */<br />
#include /* for atof */<br />
int main(void)<br />
{<br />
char a[] = " 1.28";<br />
char b[] = "27.835e2";<br />
char c[] = "Number1";<br />
double x;<br />
x = atof(a);<br />
printf("String = \"%s\" float = %f\n", a, x);<br />
x = atof(b);<br />
printf("String = \"%s\" float = %f\n", b, x);<br />
x = atof(c);<br />
printf("String = \"%s\" float = %f\n", c, x);<br />
}<br />
Output:<br />
String = "1.28" float = 1.280000<br />
String = "27.835:e2"float = 2783.500000<br />
String = "Number1" float = 0.000000<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 275<br />
atoi<br />
qsort (danh sách, NUM, sizeof (int), comp);<br />
printf ("Sắp xếp liệt kê:");<br />
for (x = 0; x
Description: Converts a string to an integer.<br />
Include: <br />
Prototype: int atoi(const char *s);<br />
Argument: s string to be converted<br />
Return Value: Returns the converted integer if successful; otherwise, returns 0.<br />
Remarks: The number may consist of the following:<br />
[whitespace] [sign] digits<br />
optional whitespace, followed by an optional signthen a sequence<br />
of one or more digits. The conversion stops when the first<br />
unrecognized character is reached. The conversion is equivalent to<br />
(int) strtol(s,0,10)except it does no error checking so errno<br />
will not be set.<br />
Example: #include /* for printf */<br />
#include /* for atoi */<br />
int main(void)<br />
{<br />
char a[] = " -127";<br />
char b[] = "Number1";<br />
int x;<br />
x = atoi(a);<br />
printf("String = \"%s\"\tint = %d\n", a, x);<br />
x = atoi(b);<br />
printf("String = \"%s\"\tint = %d\n", b, x);<br />
}<br />
Output:<br />
String = " -127" int = -127<br />
String = "Number1" int = 0<br />
atol<br />
Description: Converts a string to a long integer.<br />
Include: <br />
Prototype: long atol(const char *s);<br />
Argument: s string to be converted<br />
Return Value: Returns the converted longinteger if successful; otherwise,<br />
returns 0<br />
Remarks: The number may consist of the following:<br />
[whitespace] [sign] digits<br />
optional whitespace, followed by an optional signthen a sequence<br />
of one or more digits. The conversion stops when the first<br />
unrecognized character is reached. The conversion is equivalent to<br />
Bao gồm:<br />
Nguyên mẫu: void * calloc (size_t nelem, size_t size);<br />
Đối số: số nelem của các yếu tố<br />
chiều dài kích thước của mỗi phần tử<br />
Quay trở lại giá trị: Trả về một con trỏ đến không gian được phân bổ nếu thành<br />
công; nếu không,<br />
trả về một con trỏ null.<br />
Ghi chú: Bộ nhớ được trả về bởi callocis liên kết chính xác cho bất kỳ dữ liệu<br />
kích thước<br />
phần tử và được khởi tạo bằng không.<br />
Ví dụ: / * Chương trình này cấp phát bộ nhớ cho * /<br />
/ * Mảng 'i' của longintegers và khởi tạo * /<br />
/ * Chúng bằng không. * /<br />
# include / * Cho printf, NULL * /<br />
# include / * Cho calloc, * miễn phí /<br />
int main (void)<br />
{<br />
int x;<br />
dài * i;<br />
i = (long *) calloc (5, sizeof (long));<br />
if (i! = NULL)<br />
{<br />
for (x = 0; x
(int) strtol(s,0,10)except it does no error checking so errno<br />
will not be set.<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 276<br />
2004 Microchip Technology Inc.<br />
Example: #include /* for printf */<br />
#include /* for atol */<br />
int main(void)<br />
{<br />
char a[] = " -123456";<br />
char b[] = "2Number";<br />
long x;<br />
x = atol(a);<br />
printf("String = \"%s\" int = %ld\n", a, x);<br />
x = atol(b);<br />
printf("String = \"%s\" int = %ld\n", b, x);<br />
}<br />
Output:<br />
String = " -123456" int = -123456<br />
String = "2Number" int = 2<br />
bsearch<br />
Description: Performs a binary search<br />
Include: <br />
Prototype: void *bsearch(const void *key, const void *base,<br />
size_t nelem, size_t size,<br />
int (*cmp)(const void *ck, const void *ce));<br />
Arguments: key object to search for<br />
base pointer to the start of the search data<br />
nelem number of elements<br />
size size of elements<br />
cmp pointer to the comparison function<br />
ck pointer to the key for the search<br />
ce pointer to the element being compared with the key.<br />
Return Value: Returns a pointer to the object being searched for if found;<br />
otherwise,<br />
returns NULL.<br />
Remarks: The value returned by the compare function is 0 if ckis greater than ce.<br />
denom mẫu<br />
Quay trở lại giá trị: Trả về thương và phần còn lại.<br />
Ghi chú: Các thương trở lại sẽ có những dấu hiệu tương tự như tử số chia<br />
với mẫu số. Các dấu hiệu cho phần còn lại sẽ được như vậy mà các<br />
thương lần mẫu số cộng với phần còn lại sẽ tương đương với<br />
tử số (* quot denom + rem = numer). Chia cho không sẽ gọi<br />
các lỗi ngoại lệ toán học, mà theo mặc định, sẽ gây ra một thiết lập lại. Viết<br />
xử lý lỗi toán học cần làm cái gì khác.<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 279<br />
Ví dụ: # include / * Cho div, div_t * /<br />
# include / * Forprintf * /<br />
khoảng trống __attribute __ ((__ interrupt__))<br />
_MathError (Void)<br />
{<br />
printf ("bất hợp pháp hướng dẫn thực hiện \ n");<br />
hủy bỏ ();<br />
}<br />
int main (void)<br />
{<br />
int x, y;<br />
z div_t;<br />
x = 7;<br />
y = 3;<br />
printf ("Đối với div (% d,% d) \ n", x, y);<br />
z = div (x, y);<br />
printf ("thương là% d và"<br />
"Còn lại là% d \ n \ n", z.quot, z.rem);<br />
x = 7;<br />
y = -3;<br />
printf ("Đối với div (% d,% d) \ n", x, y);<br />
z = div (x, y);<br />
printf ("thương là% d và"<br />
"Còn lại là% d \ n \ n", z.quot, z.rem);<br />
x = -5;<br />
y = 3;<br />
printf ("Đối với div (% d,% d) \ n", x, y);<br />
z = div (x, y);<br />
printf ("thương là% d và"
In the following example, qsortis used to sort the list before bsearch<br />
is called. bsearchrequires the list to be sorted according to the<br />
comparison function. This compuses ascending order.<br />
atol (Continued)<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 277<br />
Example: #include /* for bsearch, qsort */<br />
#include /* for printf, sizeof */<br />
#define NUM 7<br />
int comp(const void *e1, const void *e2);<br />
int main(void)<br />
{<br />
int list[NUM] = {35, 47,63, 25, 93, 16, 52};<br />
int x, y;<br />
int *r;<br />
qsort(list, NUM, sizeof(int), comp);<br />
printf("Sorted List: ");<br />
for (x = 0; x < NUM; x++)<br />
printf("%d ", list[x]);<br />
y = 25;<br />
r = bsearch(&y, list,NUM, sizeof(int), comp);<br />
if (r)<br />
printf("\nThe value%d was found\n", y);<br />
else<br />
printf("\nThe value %d was not found\n", y);<br />
y = 75;<br />
r = bsearch(&y, list,NUM, sizeof(int), comp);<br />
if (r)<br />
printf("\nThe value%d was found\n", y);<br />
else<br />
printf("\nThe value %d was not found\n", y);<br />
}<br />
int comp(const void *e1, const void *e2)<br />
{<br />
const int * a1 = e1;<br />
const int * a2 = e2;<br />
if (*a1 < *a2)<br />
return -1;<br />
else if (*a1 == *a2)<br />
"Còn lại là% d \ n \ n", z.quot, z.rem);<br />
x = 7;<br />
y = 7;<br />
printf ("Đối với div (% d,% d) \ n", x, y);<br />
z = div (x, y);<br />
printf ("thương là% d và"<br />
"Còn lại là% d \ n \ n", z.quot, z.rem);<br />
x = 7;<br />
y = 0;<br />
printf ("Đối với div (% d,% d) \ n", x, y);<br />
z = div (x, y);<br />
printf ("thương là% d và"<br />
"Còn lại là% d \ n \ n", z.quot, z.rem);<br />
}<br />
div (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 280 2004 Microchip Technology Inc<br />
Đầu ra:<br />
Đối với div (7, 3)<br />
Các thương là 2 và phần còn lại là 1<br />
Đối với div (7, -3)<br />
Thương số là -2 và phần còn lại là 1<br />
Đối với div (-5, 3)<br />
Thương số là -1 và phần còn lại là -2<br />
Đối với div (7, 7)<br />
Các thương là 1 và phần còn lại là 0<br />
Đối với div (7, 0)<br />
Hướng dẫn thực hiện bất hợp pháp<br />
ABRT<br />
thoát<br />
Mô tả: Kết thúc chương trình sau khi làm sạch.<br />
Bao gồm:<br />
Nguyên mẫu: void exit (int trạng thái);<br />
Lập luận: tình trạng statusexit<br />
Bình luận: exitcalls bất kỳ chức năng đăng ký atexitin theo chiều ngược<br />
đăng ký, bừng bộ đệm, closesstream, đóng cửa bất kỳ tập tin tạm thời<br />
tạo ra với tmpfile, và thiết lập lại bộ vi xử lý. Chức năng này
eturn 0;<br />
else<br />
return 1;<br />
}<br />
Output:<br />
Sorted List: 16 25 35 47 52 63 93<br />
The value 25 was found<br />
The value 75 was not found<br />
bsearch (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 278 2004 Microchip Technology Inc.<br />
calloc<br />
Description: Allocates an array in memory and initializes the elements to 0.<br />
Include: <br />
Prototype: void *calloc(size_t nelem, size_t size);<br />
Arguments: nelem number of elements<br />
size length of each element<br />
Return Value: Returns a pointer to the allocated space if successful; otherwise,<br />
returns a null pointer.<br />
Remarks: Memory returned by callocis aligned correctly for any size data<br />
element and is initialized to zero.<br />
Example: /* This program allocates memory for the */<br />
/* array 'i' of longintegers and initializes */<br />
/* them to zero. */<br />
#include /* for printf, NULL */<br />
#include /* for calloc, free */<br />
int main(void)<br />
{<br />
int x;<br />
long *i;<br />
i = (long *)calloc(5, sizeof(long));<br />
if (i != NULL)<br />
{<br />
for (x = 0; x < 5; x++)<br />
printf("i[%d] = %ld\n", x, i[x]);<br />
free(i);<br />
}<br />
tùy biến. Xem pic30-libs.<br />
Ví dụ: # include / * Cho fopen, printf, * /<br />
/ * FILE, NULL * /<br />
# include / * Để xuất cảnh * /<br />
int main (void)<br />
{<br />
FILE * myfile;<br />
if ((myfile = fopen ("samp.fil", "r")) == NULL)<br />
{<br />
printf ("Không thể mở samp.fil \ n");<br />
xuất cảnh (EXIT_FAILURE);<br />
}<br />
khác<br />
{<br />
printf ("Thành công mở samp.fil \ n");<br />
xuất cảnh (EXIT_SUCCESS);<br />
}<br />
printf ("Điều này sẽ không được in");<br />
}<br />
Đầu ra:<br />
Không thể mở samp.fil<br />
div (Tiếp theo)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 281<br />
miễn phí<br />
Mô tả: Giải phóng bộ nhớ.<br />
Bao gồm:<br />
Prototype: void free (void * ptr);<br />
Đối số: điểm ptr vào bộ nhớ được giải phóng<br />
Bình luận: giải phóng bộ nhớ trước đây giao calloc, malloc, hoặc<br />
realloc. Nếu freeis sử dụng trên không gian đã được deallocated<br />
(Bằng một cuộc gọi trước để freeor bởi realloc) hoặc trên không gian không<br />
được phân bổ<br />
với calloc, malloc, hoặc realloc, hành vi này là không xác định.<br />
Ví dụ: # include / * Forprintf, sizeof, * /<br />
/ * NULL * /<br />
# include / * Cho malloc, * miễn phí /<br />
int main (void)<br />
{<br />
dài * i;
else<br />
printf("Cannot allocate memory\n");<br />
}<br />
Output:<br />
i[0] = 0<br />
i[1] = 0<br />
i[2] = 0<br />
i[3] = 0<br />
i[4] = 0<br />
div<br />
Description: Calculates the quotient and remainder of two numbers<br />
Include: <br />
Prototype: div_t div(int numer, int denom);<br />
Arguments: numer numerator<br />
denom denominator<br />
Return Value: Returns the quotient and the remainder.<br />
Remarks: The returned quotient will have the same sign as the numerator<br />
divided<br />
by the denominator. The sign for the remainder will be such that the<br />
quotient times the denominator plus the remainder will equal the<br />
numerator (quot * denom + rem = numer). Division by zero will invoke<br />
the math exception error, which by default, will cause a reset. Write a<br />
math error handler todo something else.<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 279<br />
Example: #include /* for div, div_t */<br />
#include /* forprintf */<br />
void __attribute__((__interrupt__))<br />
_MathError(void)<br />
{<br />
printf("Illegal instruction executed\n");<br />
abort();<br />
}<br />
int main(void)<br />
{<br />
int x, y;<br />
div_t z;<br />
x = 7;<br />
y = 3;<br />
if ((i = (long *) malloc (50 * sizeof (long))) ==<br />
NULL)<br />
printf ("Không thể cấp phát bộ nhớ \ n");<br />
khác<br />
{<br />
printf ("bộ nhớ phân bổ \ n");<br />
miễn phí (i);<br />
printf ("giải phóng bộ nhớ \ n");<br />
}<br />
}<br />
Đầu ra:<br />
Cấp phát bộ nhớ<br />
Bộ nhớ giải phóng<br />
getenv<br />
Mô tả: Lấy một giá trị cho một biến môi trường.<br />
Bao gồm:<br />
Prototype: char * getenv (const char * name);<br />
Tên tên của biến môi trường: Đối số<br />
Quay trở lại giá trị: Trả về một con trỏ đến giá trị của biến môi trường nếu thàn<br />
công;<br />
nếu không, trả về một con trỏ null.<br />
Bình luận: Chức năng này phải được tùy chỉnh để được sử dụng như mô tả (xem<br />
pic30-libs). Theo mặc định không có mục trong danh sách môi trường<br />
cho getenvto tìm.<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 282<br />
2004 Microchip Technology Inc<br />
Ví dụ: # include / * Cho printf, NULL * /<br />
# include / * Cho getenv * /<br />
int main (void)<br />
{<br />
char * incvar;<br />
incvar = getenv ("BAO GỒM");<br />
if (incvar! = NULL)<br />
printf ("BAO GỒM biến môi trường =% s \ n",<br />
incvar);<br />
khác<br />
printf ("Không thể tìm thấy biến môi trường"<br />
"BAO GỒM");
printf("For div(%d, %d)\n", x, y);<br />
z = div(x, y);<br />
printf("The quotient is %d and the "<br />
"remainder is %d\n\n", z.quot, z.rem);<br />
x = 7;<br />
y = -3;<br />
printf("For div(%d, %d)\n", x, y);<br />
z = div(x, y);<br />
printf("The quotient is %d and the "<br />
"remainder is %d\n\n", z.quot, z.rem);<br />
x = -5;<br />
y = 3;<br />
printf("For div(%d, %d)\n", x, y);<br />
z = div(x, y);<br />
printf("The quotient is %d and the "<br />
"remainder is %d\n\n", z.quot, z.rem);<br />
x = 7;<br />
y = 7;<br />
printf("For div(%d, %d)\n", x, y);<br />
z = div(x, y);<br />
printf("The quotient is %d and the "<br />
"remainder is %d\n\n", z.quot, z.rem);<br />
x = 7;<br />
y = 0;<br />
printf("For div(%d, %d)\n", x, y);<br />
z = div(x, y);<br />
printf("The quotient is %d and the "<br />
"remainder is %d\n\n", z.quot, z.rem);<br />
}<br />
div (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 280 2004 Microchip Technology Inc.<br />
Output:<br />
For div(7, 3)<br />
The quotient is 2 and the remainder is 1<br />
For div(7, -3)<br />
The quotient is -2 and the remainder is 1<br />
}<br />
Đầu ra:<br />
Không thể tìm thấy biến môi trường BAO GỒM<br />
các phòng thí nghiệm<br />
Mô tả: Tính giá trị tuyệt đối của một số nguyên dài.<br />
Bao gồm:<br />
Prototype: phòng thí nghiệm dài (i dài);<br />
Đối số: i giá trị số nguyên dài<br />
Quay trở lại giá trị: Trả về giá trị tuyệt đối của tôi.<br />
Bình luận: Một số âm được trả về là tích cực; một số dương là<br />
không thay đổi.<br />
Ví dụ: # include / * Cho printf * /<br />
# include / * Cho các phòng thí nghiệm * /<br />
int main (void)<br />
{<br />
i dài;<br />
i = 123456;<br />
printf ("Giá trị tuyệt đối của% 7ld là 6LD% \ n",<br />
i, các phòng thí nghiệm (i));<br />
i = -246.834;<br />
printf ("Giá trị tuyệt đối của% 7ld là 6LD% \ n",<br />
i, các phòng thí nghiệm (i));<br />
i = 0;<br />
printf ("Giá trị tuyệt đối của% 7ld là 6LD% \ n",<br />
i, các phòng thí nghiệm (i));<br />
}<br />
Đầu ra:<br />
Các of123456 giá trị tuyệt đối là 123.456<br />
Giá trị tuyệt đối là 246.834 -246.834<br />
Giá trị tuyệt đối của 0 là 0<br />
getenv (Tiếp theo)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 283<br />
ldiv<br />
Mô tả: Tính thương và phần còn lại của hai số nguyên dài.<br />
Bao gồm:<br />
Prototype: ldiv_t ldiv (numer dài, denom dài);<br />
Đối số: numer tử số<br />
denomdenominator
For div(-5, 3)<br />
The quotient is -1 and the remainder is -2<br />
For div(7, 7)<br />
The quotient is 1 and the remainder is 0<br />
For div(7, 0)<br />
Illegal instruction executed<br />
ABRT<br />
exit<br />
Description: Terminates program after clean up.<br />
Include: <br />
Prototype: void exit(int status);<br />
Argument: statusexit status<br />
Remarks: exitcalls any functions registered by atexitin reverse order of<br />
registration, flushes buffers, closesstream, closes any temporary files<br />
created with tmpfile, and resets the processor. This function is<br />
customizable. See pic30-libs.<br />
Example: #include /* for fopen, printf, */<br />
/* FILE, NULL */<br />
#include /* for exit */<br />
int main(void)<br />
{<br />
FILE *myfile;<br />
if ((myfile = fopen("samp.fil", "r" )) == NULL)<br />
{<br />
printf("Cannot open samp.fil\n");<br />
exit(EXIT_FAILURE);<br />
}<br />
else<br />
{<br />
printf("Success opening samp.fil\n");<br />
exit(EXIT_SUCCESS);<br />
}<br />
printf("This will not be printed");<br />
}<br />
Output:<br />
Cannot open samp.fil<br />
div (Continued)<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 281<br />
Quay trở lại giá trị: Trả về quotientand phần còn lại.<br />
Ghi chú: Các thương trở lại sẽ có những dấu hiệu tương tự như tử số chia<br />
với mẫu số. Các dấu hiệu cho phần còn lại sẽ được như vậy mà các<br />
thương lần mẫu số cộng với phần còn lại sẽ tương đương với<br />
tử số (* quot denom + rem = numer). Nếu mẫu số là số không,<br />
hành vi này là không xác định.<br />
Ví dụ: # include / * Cho ldiv, ldiv_t * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
dài x, y;<br />
ldiv_t z;<br />
x = 7;<br />
y = 3;<br />
printf ("Đối với ldiv (% ld,% ld) \ n", x, y);<br />
z = ldiv (x, y);<br />
printf ("thương là% ld và"<br />
"Còn lại là% ld \ n \ n", z.quot, z.rem);<br />
x = 7;<br />
y = -3;<br />
printf ("Đối với ldiv (% ld,% ld) \ n", x, y);<br />
z = ldiv (x, y);<br />
printf ("thương là% ld và"<br />
"Còn lại là% ld \ n \ n", z.quot, z.rem);<br />
x = -5;<br />
y = 3;<br />
printf ("Đối với ldiv (% ld,% ld) \ n", x, y);<br />
z = ldiv (x, y);<br />
printf ("thương là% ld và"<br />
"Còn lại là% ld \ n \ n", z.quot, z.rem);<br />
x = 7;<br />
y = 7;<br />
printf ("Đối với ldiv (% ld,% ld) \ n", x, y);<br />
z = ldiv (x, y);<br />
printf ("thương là% ld và"<br />
"Còn lại là% ld \ n \ n", z.quot, z.rem);<br />
x = 7;<br />
y = 0;<br />
printf ("Đối với ldiv (% ld,% ld) \ n", x, y);
free<br />
Description: Frees memory.<br />
Include: <br />
Prototype: void free(void *ptr);<br />
Argument: ptr points to memory to be freed<br />
Remarks: Frees memory previously allocated with calloc, malloc, or<br />
realloc. If freeis used on space that has already been deallocated<br />
(by a previous call to freeor by realloc) or on space not allocated<br />
with calloc, malloc, or realloc, the behavior is undefined.<br />
Example: #include /* forprintf, sizeof, */<br />
/* NULL */<br />
#include /* for malloc, free */<br />
int main(void)<br />
{<br />
long *i;<br />
if ((i = (long *)malloc(50 * sizeof(long))) ==<br />
NULL)<br />
printf("Cannot allocate memory\n");<br />
else<br />
{<br />
printf("Memory allocated\n");<br />
free(i);<br />
printf("Memory freed\n");<br />
}<br />
}<br />
Output:<br />
Memory allocated<br />
Memory freed<br />
getenv<br />
Description: Get a value for an environment variable.<br />
Include: <br />
Prototype: char *getenv(const char *name);<br />
Argument: name name of environment variable<br />
Return Value: Returns a pointer to the value of the environment variable if<br />
successful;<br />
otherwise, returns a null pointer.<br />
Remarks: This function must be customized to be used as described (see<br />
pic30-libs). By default there are no entries in the environment list<br />
for getenvto find.<br />
z = ldiv (x, y);<br />
printf ("thương là% ld và"<br />
"Còn lại là% ld \ n \ n",<br />
z.quot, z.rem);<br />
}<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 284<br />
Đầu ra:<br />
Đối với ldiv (7, 3)<br />
Các thương là 2 và phần còn lại là 1<br />
Đối với ldiv (7, -3)<br />
Thương số là -2 và phần còn lại là 1<br />
Đối với ldiv (-5, 3)<br />
Thương số là -1 và phần còn lại là -2<br />
Đối với ldiv (7, 7)<br />
Các thương là 1 và phần còn lại là 0<br />
Đối với ldiv (7, 0)<br />
Thương số là -1 và phần còn lại là 7<br />
Giải thích:<br />
2004 Microchip Technology Inc<br />
Trong ví dụ cuối (ldiv (7,0)) mẫu số là số không, hành vi<br />
là không xác định.<br />
malloc<br />
Mô tả: Phân bổ bộ nhớ.<br />
Bao gồm:<br />
Nguyên mẫu: void * malloc (size_t size);<br />
Đối số: số kích thước của ký tự để phân bổ<br />
Quay trở lại giá trị: Trả về một con trỏ đến không gian được phân bổ nếu thành<br />
công; nếu không,<br />
trả về một con trỏ null.<br />
Bình luận: mallocdoes không khởi tạo bộ nhớ nó sẽ trả về.<br />
Ví dụ: # include / * Cho printf, sizeof, * /<br />
/ * NULL * /<br />
# include / * Cho malloc, * miễn phí /<br />
int main (void)<br />
{<br />
dài * i;<br />
if ((i = (long *) malloc (50 * sizeof (long))) ==<br />
NULL)
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 282 2004 Microchip Technology Inc.<br />
Example: #include /* for printf, NULL */<br />
#include /* for getenv */<br />
int main(void)<br />
{<br />
char *incvar;<br />
incvar = getenv("INCLUDE");<br />
if (incvar != NULL)<br />
printf("INCLUDE environment variable = %s\n",<br />
incvar);<br />
else<br />
printf("Cannot find environment variable "<br />
"INCLUDE ");<br />
}<br />
Output:<br />
Cannot find environment variable INCLUDE<br />
labs<br />
Description: Calculates the absolute value of a long integer.<br />
Include: <br />
Prototype: long labs(long i);<br />
Argument: i long integer value<br />
Return Value: Returns the absolute value of i.<br />
Remarks: A negative number is returned as positive; a positive number is<br />
unchanged.<br />
Example: #include /* for printf */<br />
#include /* for labs */<br />
int main(void)<br />
{<br />
long i;<br />
i = 123456;<br />
printf("The absolute value of %7ld is %6ld\n",<br />
i, labs(i));<br />
i = -246834;<br />
printf("The absolute value of %7ld is %6ld\n",<br />
i, labs(i));<br />
i = 0;<br />
printf ("Không thể cấp phát bộ nhớ \ n");<br />
khác<br />
{<br />
printf ("bộ nhớ phân bổ \ n");<br />
miễn phí (i);<br />
printf ("giải phóng bộ nhớ \ n");<br />
}<br />
}<br />
Đầu ra:<br />
Cấp phát bộ nhớ<br />
Bộ nhớ giải phóng<br />
ldiv (Tiếp theo)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 285<br />
mblen<br />
Mô tả: Được chiều dài của một nhân vật nhiều byte. (Xem chú thích.)<br />
Bao gồm:<br />
Nguyên mẫu: int mblen (const char * s, size_t n);<br />
Đối số: s điểm cho nhân vật nhiều byte<br />
số n byte để kiểm tra<br />
Quay trở lại giá trị: Trả về số không nếu s điểm cho một nhân vật null; nếu<br />
không, trả về 1.<br />
Bình luận: MPLAB C30 không hỗ trợ các ký tự nhiều byte có độ dài lớn<br />
hơn 1 byte.<br />
mbstowcs<br />
Mô tả: Chuyển đổi một chuỗi đa byte cho một chuỗi ký tự rộng. (Xem chú<br />
thích.)<br />
Bao gồm:<br />
Mbstowcs size_t (wchar_t * WCS, const char * s,: nguyên mẫu<br />
size_t n);<br />
Đối số: WCS điểm đến chuỗi ký tự rộng<br />
s điểm cho chuỗi đa byte<br />
n số lượng ký tự rộng để chuyển đổi.<br />
Quay trở lại giá trị: Trả về số ký tự rộng lưu trữ bao gồm các null<br />
nhân vật.<br />
Bình luận: mbstowcsconverts nSố ký tự rộng trừ khi nó gặp<br />
một nhân vật rộng null đầu tiên. MPLAB C30 không hỗ trợ nhiều byte<br />
nhân vật có chiều dài lớn hơn 1 byte.<br />
mbtowc<br />
Mô tả: Chuyển đổi một nhân vật nhiều byte cho một nhân vật rộng. (Xem chú<br />
thích.)
printf("The absolute value of %7ld is %6ld\n",<br />
i, labs(i));<br />
}<br />
Output:<br />
The absolute value of123456 is 123456<br />
The absolute value of -246834 is 246834<br />
The absolute value of 0 is 0<br />
getenv (Continued)<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 283<br />
ldiv<br />
Bao gồm:<br />
Nguyên mẫu: int mbtowc (wchar_t * PwC, const char * s, size_t n);<br />
Đối số: điểm PwC cho nhiều nhân vật<br />
s điểm cho nhân vật nhiều byte<br />
số n byte để kiểm tra<br />
Quay trở lại giá trị: Trả về số không nếu spoints cho một nhân vật null; nếu<br />
không, trả về 1<br />
Ghi chú: Các ký tự rộng kết quả sẽ được lưu trữ tại PwC. MPLAB C30 không<br />
không hỗ trợ các ký tự nhiều byte có chiều dài lớn hơn 1 byte.<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
Description: Calculates the quotient and remainder of two long integers.<br />
Include: <br />
DS51456B trang 286<br />
qsort<br />
2004 Microchip Technology Inc<br />
Prototype: ldiv_t ldiv(long numer, long denom);<br />
Arguments: numer numerator<br />
denomdenominator<br />
Return Value: Returns the quotientand the remainder.<br />
Remarks: The returned quotient will have the same sign as the numerator<br />
divided<br />
by the denominator. The sign for the remainder will be such that the<br />
quotient times the denominator plus the remainder will equal the<br />
numerator (quot * denom + rem = numer). If the denominator is zero,<br />
the behavior is undefined.<br />
Example: #include /* for ldiv, ldiv_t */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
long x,y;<br />
ldiv_t z;<br />
x = 7;<br />
y = 3;<br />
printf("For ldiv(%ld, %ld)\n", x, y);<br />
z = ldiv(x, y);<br />
printf("The quotient is %ld and the "<br />
"remainder is %ld\n\n", z.quot, z.rem);<br />
x = 7;<br />
y = -3;<br />
printf("For ldiv(%ld, %ld)\n", x, y);<br />
z = ldiv(x, y);<br />
Mô tả: Thực hiện sắp xếp nhanh chóng.<br />
Bao gồm:<br />
Prototype: void qsort (void * cơ sở, nelem size_t, size_t size,<br />
int (* CMP) (const void * e1, const void * e2));<br />
Con trỏ cơ sở để bắt đầu của mảng: đối số<br />
số nelem của các yếu tố<br />
kích thước kích thước của các yếu tố<br />
CMP con trỏ đến chức năng so sánh<br />
e1 con trỏ đến chìa khóa cho các con trỏ tìm kiếm e2 cho các phần tử được so<br />
sánh với phím<br />
Bình luận: qsortoverwrites mảng với mảng được sắp xếp. Việc so sánh<br />
chức năng được cung cấp bởi người sử dụng. Inthe ví dụ sau đây, trong danh<br />
sách là<br />
sắp xếp theo chức năng so sánh. Đây compuses<br />
thứ tự tăng dần.<br />
Ví dụ: # include / * Cho qsort * /<br />
# include / * Cho printf * /<br />
# xác định NUM 7<br />
int comp (const void * e1, const void * e2);<br />
int main (void)<br />
{<br />
int danh sách [NUM] = {35, 47, 63, 25, 93, 16, 52};<br />
int x;<br />
printf ("Danh sách Unsorted:");<br />
for (x = 0; x
printf("The quotient is %ld and the "<br />
"remainder is %ld\n\n", z.quot, z.rem);<br />
x = -5;<br />
y = 3;<br />
printf("For ldiv(%ld, %ld)\n", x, y);<br />
z = ldiv(x, y);<br />
printf("The quotient is %ld and the "<br />
"remainder is %ld\n\n", z.quot, z.rem);<br />
x = 7;<br />
y = 7;<br />
printf("For ldiv(%ld, %ld)\n", x, y);<br />
z = ldiv(x, y);<br />
printf("The quotient is %ld and the "<br />
"remainder is %ld\n\n", z.quot, z.rem);<br />
x = 7;<br />
y = 0;<br />
printf("For ldiv(%ld, %ld)\n", x, y);<br />
z = ldiv(x, y);<br />
printf("The quotient is %ld and the "<br />
"remainder is %ld\n\n",<br />
z.quot, z.rem);<br />
}<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 284 2004 Microchip Technology Inc.<br />
Output:<br />
For ldiv(7, 3)<br />
The quotient is 2 and the remainder is 1<br />
For ldiv(7, -3)<br />
The quotient is -2 and the remainder is 1<br />
For ldiv(-5, 3)<br />
The quotient is -1 and the remainder is -2<br />
For ldiv(7, 7)<br />
The quotient is 1 and the remainder is 0<br />
For ldiv(7, 0)<br />
The quotient is -1 and the remainder is 7<br />
Explanation:<br />
In the last example (ldiv(7,0)) the denominator is zero, the behavior<br />
printf ("\ n");<br />
printf ("Sắp xếp liệt kê:");<br />
for (x = 0; x
is undefined.<br />
malloc<br />
Description: Allocates memory.<br />
Include: <br />
Prototype: void *malloc(size_t size);<br />
Argument: size number of characters to allocate<br />
Return Value: Returns a pointer to the allocated space if successful; otherwise,<br />
returns a null pointer.<br />
Remarks: mallocdoes not initialize memory it returns.<br />
Example: #include /* for printf, sizeof, */<br />
/* NULL */<br />
#include /* for malloc, free */<br />
int main(void)<br />
{<br />
long *i;<br />
if ((i = (long *)malloc(50 * sizeof(long))) ==<br />
NULL)<br />
printf("Cannot allocate memory\n");<br />
else<br />
{<br />
printf("Memory allocated\n");<br />
free(i);<br />
printf("Memory freed\n");<br />
}<br />
}<br />
Output:<br />
Memory allocated<br />
Memory freed<br />
ldiv (Continued)<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 285<br />
mblen<br />
Description: Gets the length of a multibyte character. (See Remarks.)<br />
Include: <br />
Prototype: int mblen(const char *s, size_t n);<br />
Arguments: s points to the multibyte character<br />
n number of bytes to check<br />
Return Value: Returns zero if s points to a null character; otherwise, returns 1.<br />
Remarks: MPLAB C30 does not support multibyte characters with length<br />
for (x = 0; x
greater<br />
than 1 byte.<br />
mbstowcs<br />
Description: Converts a multibyte string to a wide character string. (See<br />
Remarks.)<br />
Include: <br />
Prototype: size_t mbstowcs(wchar_t *wcs, const char *s,<br />
size_t n);<br />
Arguments: wcs points to the wide character string<br />
s points to the multibyte string<br />
n the number of wide characters to convert.<br />
Return Value: Returns the number of wide characters stored excluding the null<br />
character.<br />
Remarks: mbstowcsconverts nnumber of wide characters unless it encounters<br />
a null wide character first. MPLAB C30 does not support multibyte<br />
characters with length greater than 1 byte.<br />
mbtowc<br />
Description: Converts a multibyte character to a wide character. (See Remarks.)<br />
Include: <br />
Prototype: int mbtowc(wchar_t *pwc, const char *s, size_t n);<br />
Arguments: pwc points to the wide character<br />
s points to the multibyte character<br />
n number of bytes to check<br />
Return Value: Returns zero if spoints to a null character; otherwise, returns 1<br />
Remarks: The resulting wide character will be stored at pwc. MPLAB C30 does<br />
not support multibyte characters with length greater than 1 byte.<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 286<br />
qsort<br />
Description: Performs a quick sort.<br />
Include: <br />
2004 Microchip Technology Inc.<br />
Prototype: void qsort(void *base, size_t nelem, size_t size,<br />
int (*cmp)(const void *e1, const void *e2));<br />
Arguments: base pointer to the start of the array<br />
nelem number of elements<br />
size size of the elements<br />
cmp pointer to the comparison function<br />
e1 pointer to the key for the search e2 pointer to the element being compared<br />
== NULL)<br />
printf ("Không thể cấp phát bộ nhớ \ n");<br />
khác<br />
{<br />
printf ("bộ nhớ phân bổ \ n");<br />
/ * Nhiệt độ con trỏ trong trường hợp realloc () không thành công * /<br />
j = i;<br />
if ((i = (long *) realloc (i, 25 * sizeof (long)))<br />
== NULL)<br />
{<br />
printf ("Không thể tái phân bổ bộ nhớ \ n");<br />
/ * J chỉ để cấp phát bộ nhớ * /<br />
miễn phí (j);<br />
}<br />
khác<br />
{<br />
printf ("bộ nhớ phân bổ lại \ n");<br />
miễn phí (i);<br />
}<br />
}<br />
}<br />
Đầu ra:<br />
Cấp phát bộ nhớ<br />
Bộ nhớ phân bổ lại<br />
realloc (Tiếp theo)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 289<br />
srand<br />
Mô tả: Đặt hạt giống khởi đầu cho chuỗi số giả ngẫu nhiên.<br />
Bao gồm:<br />
Prototype: void srand (unsigned int hạt giống);<br />
Giá trị bắt đầu hạt giống cho dãy số giả ngẫu nhiên: Đối số<br />
Trở lại giá trị: Không<br />
Bình luận: Chức năng này đặt hạt giống khởi đầu cho các số giả ngẫu nhiên<br />
tự tạo ra bởi các randfunction. Các randfunction sẽ<br />
luôn luôn trở về cùng một chuỗi các số nguyên hạt giống khi giống hệt nhau<br />
giá trị được sử dụng. Nếu randis gọi với một giá trị hạt giống số 1, trình tự<br />
số được tạo ra sẽ được giống như nếu randhad được gọi là<br />
mà không srandhaving được gọi là đầu tiên.
with the key<br />
Remarks: qsortoverwrites the array with the sorted array. The comparison<br />
function is supplied by the user. Inthe following example, the list is<br />
sorted according to the comparison function. This compuses<br />
ascending order.<br />
Example: #include /* for qsort */<br />
#include /* for printf */<br />
#define NUM 7<br />
int comp(const void *e1,const void *e2);<br />
int main(void)<br />
{<br />
int list[NUM] = {35, 47, 63, 25, 93, 16, 52};<br />
int x;<br />
printf("Unsorted List: ");<br />
for (x = 0; x < NUM; x++)<br />
printf("%d ", list[x]);<br />
qsort(list, NUM, sizeof(int), comp);<br />
printf("\n");<br />
printf("Sorted List: ");<br />
for (x = 0; x < NUM; x++)<br />
printf("%d ", list[x]);<br />
}<br />
int comp(const void *e1,const void *e2)<br />
{<br />
const int * a1 = e1;<br />
const int * a2 = e2;<br />
if (*a1 < *a2)<br />
return -1;<br />
else if (*a1 == *a2)<br />
return 0;<br />
else<br />
return 1;<br />
}<br />
Output:<br />
Unsorted List: 35 47 63 25 93 16 52<br />
Sorted List: 16 25 35 47 52 63 93<br />
Ví dụ: # include / * Forprintf * /<br />
# include / * Cho rand, srand * /<br />
int main (void)<br />
{<br />
int x;<br />
srand (7);<br />
for (x = 0; x
Description: Generates a pseudo-random integer.<br />
Include: <br />
Prototype: int rand(void);<br />
Return Value: Returns an integer between 0 and RAND_MAX.<br />
Remarks: Calls to this function return pseudo-random integer values in the<br />
range<br />
[0,RAND_MAX]. To use this function effectively, you must seed the<br />
random number generator using the srandfunction. This function will<br />
always return the same sequence ofintegers when no seeds are used<br />
(as in the example below) or whenidentical seed values are used. (See<br />
srandfor seed example.)<br />
Example: #include /* for printf */<br />
#include /* for rand */<br />
int main(void)<br />
{<br />
int x;<br />
for (x = 0; x < 5; x++)<br />
printf("Number = %d\n", rand());<br />
}<br />
Output:<br />
Number = 21422<br />
Number = 2061<br />
Number = 16443<br />
Number = 11617<br />
Number = 9125<br />
Notice if the program is run a second time, the numbers are the same.<br />
See the example for srandto seed the random number generator.<br />
realloc<br />
Description: Reallocates memory to allow a size change.<br />
Include: <br />
Prototype: void *realloc(void *ptr, size_t size);<br />
Arguments: ptr points to previously allocated memory<br />
size new size to allocate to<br />
Return Value: Returns a pointer to the allocated space if successful; otherwise,<br />
returns a null pointer.<br />
Remarks: If the existing object is smaller than the new object, the entire existing<br />
object is copied to the new object and the remainder of the new object<br />
is indeterminate. If the existing object is larger than the new object, the<br />
function copies as much of the existing object as will fit in the new<br />
int main (void)<br />
{<br />
char * kết thúc;<br />
char a [] = "1.28 inch";<br />
char b [] = "27.835e2i";<br />
char c [] = "Number1";<br />
x đôi;<br />
x = strtod (a, và kết thúc);<br />
printf ("String = \"% s \ "float =% f \ n", a, x);<br />
printf ("Ngưng tại:% s \ n \ n", kết thúc);<br />
x = strtod (b, và kết thúc);<br />
printf ("String = \"% s \ "float =% f \ n", b, x);<br />
printf ("Ngưng tại:% s \ n \ n", kết thúc);<br />
x = strtod (c, và kết thúc);<br />
printf ("String = \"% s \ "float =% f \ n", c, x);<br />
printf ("Ngưng tại:% s \ n \ n", kết thúc);<br />
}<br />
Đầu ra:<br />
String = "1.28 inch" float = 1,280000<br />
Dừng lại ở: inch<br />
String = "27.835e2i" float = 2783,500000<br />
Dừng lại ở: i<br />
String = "Number1" float = 0.000000<br />
Dừng lại ở: Number1<br />
strtod (Tiếp theo)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 291<br />
strtol<br />
Mô tả: Chuyển đổi một chuỗi một phần một số nguyên dài.<br />
Bao gồm:<br />
Prototype: strtol dài (const char * s, char ** endptr, int cơ sở);<br />
Đối số: chuỗi s được chuyển đổi<br />
endptr con trỏ đến các nhân vật atwhich chuyển đổi dừng lại<br />
cơ sở số lượng cơ sở để sử dụng trong chuyển đổi<br />
Quay trở lại giá trị: Trả về số chuyển đổi nếu thành công; nếu không, trả về 0.<br />
Ghi chú: Nếu baseis số không, strtolattempts để xác định các cơ sở tự động.<br />
Nó có thể là bát phân, xác định bởi một số không hàng đầu, hệ thập lục phân,<br />
xác định<br />
bởi một hàng đầu 0x hoặc 0X, hoặc thập phân trong các trường hợp khác. Nếu<br />
cơ sở được quy định
object. If reallocsucceeds in allocating a new object, the existing<br />
object will be deallocated; otherwise, the existing object is left<br />
unchanged. Keep a temporary pointerto the existing object since<br />
reallocwill return a null pointer on failure.<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 288 2004 Microchip Technology Inc.<br />
Example: #include /* for printf, sizeof, NULL */<br />
#include /* for realloc, malloc, free */<br />
int main(void)<br />
{<br />
long *i, *j;<br />
if ((i = (long *)malloc(50 * sizeof(long)))<br />
== NULL)<br />
printf("Cannot allocate memory\n");<br />
else<br />
{<br />
printf("Memory allocated\n");<br />
/* Temp pointer in case realloc() fails */<br />
j = i;<br />
if ((i = (long *)realloc(i, 25 * sizeof(long)))<br />
== NULL)<br />
{<br />
printf("Cannot reallocate memory\n");<br />
/* j pointed to allocated memory */<br />
free(j);<br />
}<br />
else<br />
{<br />
printf("Memory reallocated\n");<br />
free(i);<br />
}<br />
}<br />
}<br />
Output:<br />
Memory allocated<br />
Memory reallocated<br />
realloc (Continued)<br />
strtolconverts một chuỗi số và chữ cái az (trường hợp<br />
không nhạy cảm), nơi az đại diện cho số 10-36. Chuyển đổi<br />
dừng lại khi một trong số basenumber là gặp phải. điểm để endptrwill<br />
phần còn lại của chuỗi bắt đầu với nhân vật không thể đảo ngược đầu tiên.<br />
Nếu một lỗi xảy ra nhiều, errnowill được thiết lập.<br />
Ví dụ: # include / * Cho printf * /<br />
# include / * Cho strtol * /<br />
int main (void)<br />
{<br />
char * kết thúc;<br />
char a [] = "-12BGEE";<br />
char b [] = "1234Number";<br />
x dài;<br />
x = strtol (a, và kết thúc, 16);<br />
printf ("String = \"% s \ "dài =% ld \ n", a, x);<br />
printf ("Ngưng tại:% s \ n \ n", kết thúc);<br />
x = strtol (b, và kết thúc, 4);<br />
printf ("String = \"% s \ "dài =% ld \ n", b, x);<br />
printf ("Ngưng tại:% s \ n \ n", kết thúc);<br />
}<br />
Đầu ra:<br />
String = "-12BGEE" dài = -299<br />
Dừng lại ở: GEE<br />
String = "1234Number" dài = 27<br />
Dừng lại ở: 4Number<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 292 2004 Microchip Technology Inc<br />
strtoul<br />
Mô tả: Chuyển đổi một chuỗi một phần một số nguyên dài không dấu.<br />
Bao gồm:<br />
Prototype: strtoul unsigned dài (const char * s, char ** endptr,<br />
int cơ sở);<br />
Đối số: chuỗi s được chuyển đổi<br />
con trỏ endptr với nhân vật mà tại đó việc chuyển đổi dừng lại<br />
cơ sở số lượng cơ sở để sử dụng trong chuyển đổi<br />
Quay trở lại giá trị: Trả về số chuyển đổi nếu thành công; nếu không, trả về 0.<br />
Ghi chú: Nếu baseis số không, strtolattempts để xác định các cơ sở tự động.<br />
Nó có thể là bát phân, xác định bởi một số không hàng đầu, hệ thập lục phân,
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 289<br />
srand<br />
Description: Set the starting seed for the pseudo-random number sequence.<br />
Include: <br />
Prototype: void srand(unsigned int seed);<br />
Argument: seed starting value for the pseudo-random number sequence<br />
Return Value: None<br />
Remarks: This function sets the starting seed for the pseudo-random number<br />
sequence generated by the randfunction. The randfunction will<br />
always return the same sequence of integers when identical seed<br />
values are used. If randis called with a seed value of 1, the sequence<br />
of numbers generated will be the same as if randhad been called<br />
without srandhaving been called first.<br />
Example: #include /* forprintf */<br />
#include /* for rand, srand */<br />
int main(void)<br />
{<br />
int x;<br />
srand(7);<br />
for (x = 0; x < 5; x++)<br />
printf("Number = %d\n", rand());<br />
}<br />
Output:<br />
Number = 16327<br />
Number = 5931<br />
Number = 23117<br />
Number = 30985<br />
Number = 29612<br />
strtod<br />
Description: Converts a partial string to a floating-point number of type double.<br />
Include: <br />
Prototype: double strtod(const char *s, char **endptr);<br />
Arguments: s string to be converted endptr pointer to the character at which the<br />
conversion stopped<br />
Return Value: Returns the converted number if successful; otherwise, returns 0.<br />
Remarks: The number may consist of the following:<br />
[whitespace] [sign] digits [.digits]<br />
[ { e | E }[sign]digits]<br />
xác định<br />
bởi một hàng đầu 0x hoặc 0X, hoặc thập phân trong các trường hợp khác. Nếu<br />
cơ sở được quy định<br />
strtolconverts một chuỗi số và chữ cái az (trường hợp<br />
không nhạy cảm), nơi az đại diện cho số 10-36. Chuyển đổi<br />
dừng lại khi một trong số cơ số là gặp phải. điểm để endptrwill<br />
phần còn lại của chuỗi bắt đầu với nhân vật không thể đảo ngược đầu tiên.<br />
Nếu một lỗi xảy ra nhiều, errnowill được thiết lập.<br />
Ví dụ: # include / * Cho printf * /<br />
# include / * Cho strtoul * /<br />
int main (void)<br />
{<br />
char * kết thúc;<br />
char a [] = "12BGET3";<br />
char b [] = "0x1234Number";<br />
char c [] = "-123abc";<br />
x unsigned dài;<br />
x = strtoul (a, và kết thúc, 25);<br />
printf ("String = \"% s \ "dài =% lu \ n", a, x);<br />
printf ("Ngưng tại:% s \ n \ n", kết thúc);<br />
x = strtoul (b, và kết thúc, 0);<br />
printf ("String = \"% s \ "dài =% lu \ n", b, x);<br />
printf ("Ngưng tại:% s \ n \ n", kết thúc);<br />
x = strtoul (c, và kết thúc, 0);<br />
printf ("String = \"% s \ "dài =% lu \ n", c, x);<br />
printf ("Ngưng tại:% s \ n \ n", kết thúc);<br />
}<br />
Đầu ra:<br />
String = "12BGET3" dài = 429.164<br />
Dừng lại ở: T3<br />
String = "0x1234Number" dài = 4660<br />
Dừng lại ở: Số<br />
String = "-123abc" dài = 4294967173<br />
Dừng lại ở: abc<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 293<br />
hệ thống<br />
Mô tả: Thực hiện một lệnh.<br />
Bao gồm:<br />
Nguyên mẫu: int hệ thống (const char * s);
optional whitespace, followed by an optional sign,then a sequence<br />
of one or more digitswith an optional decimal point, followed by one<br />
or more optional digitsand an optional eor Efollowed by an optional<br />
signed exponent.<br />
strtodconverts the string until it reaches a character that cannot be<br />
converted to a number. endptrwill point to the remainder of the string<br />
starting with the first unconverted character.<br />
If a range error occurs, errnowill be set.<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 290 2004 Microchip Technology Inc.<br />
Example: #include /* for printf */<br />
#include /* for strtod */<br />
int main(void)<br />
{<br />
char *end;<br />
char a[] = "1.28 inches";<br />
char b[] = "27.835e2i";<br />
char c[] = "Number1";<br />
double x;<br />
x = strtod(a, &end);<br />
printf("String = \"%s\" float = %f\n", a, x );<br />
printf("Stopped at: %s\n\n", end );<br />
x = strtod(b, &end);<br />
printf("String = \"%s\" float = %f\n", b, x );<br />
printf("Stopped at: %s\n\n", end );<br />
x = strtod(c, &end);<br />
printf("String = \"%s\" float = %f\n", c, x );<br />
printf("Stopped at: %s\n\n", end );<br />
}<br />
Output:<br />
String = "1.28 inches" float = 1.280000<br />
Stopped at: inches<br />
String = "27.835e2i"float = 2783.500000<br />
Stopped at: i<br />
String = "Number1" float = 0.000000<br />
Stopped at: Number1<br />
Đối số: s lệnh được thực thi<br />
Bình luận: Chức năng này phải được tùy chỉnh để được sử dụng như mô tả (xem<br />
pic30-libs). Theo mặc định systemwill gây ra một thiết lập lại nếu được gọi với<br />
bất cứ điều gì khác hơn là NULL. hệ thống (NULL) sẽ không làm gì cả.<br />
Ví dụ: / * Chương trình này sử dụng hệ thống * /<br />
/ * Để TYPE tập tin nguồn của nó. * /<br />
# include / * Cho hệ thống * /<br />
int main (void)<br />
{<br />
hệ thống ("loại sampsystem.c");<br />
}<br />
Đầu ra:<br />
Hệ thống (loại sampsystem.c) được gọi là: hủy bỏ<br />
wctomb<br />
Mô tả: Chuyển đổi một nhân vật rộng để một nhân vật nhiều byte. (Xem chú<br />
thích.)<br />
Bao gồm:<br />
Nguyên mẫu: int wctomb (char * s, WCHAR wchar_t);<br />
Đối số: s điểm cho nhân vật nhiều byte<br />
WCHAR nhân vật rộng được chuyển đổi<br />
Quay trở lại giá trị: Trả về số không nếu s điểm cho một nhân vật null; nếu<br />
không, trả về 1.<br />
Bình luận: Kết quả là nhân vật nhiều byte được lưu trữ tại s. MPLAB C30<br />
không<br />
hỗ trợ các ký tự nhiều byte có chiều dài lớn hơn 1 nhân vật.<br />
wcstombs<br />
Mô tả: Chuyển đổi một chuỗi ký tự rộng để một chuỗi đa byte. (Xem chú thích.<br />
Bao gồm:<br />
Wcstombs size_t (char * s, const wchar_t * WCS,: nguyên mẫu<br />
size_t n);<br />
Đối số: s điểm cho chuỗi đa byte<br />
WCS chỉ vào chuỗi ký tự rộng<br />
n số ký tự để chuyển đổi<br />
Quay trở lại giá trị: Trả về số ký tự được lưu trữ bao gồm các ký tự null.<br />
Bình luận: wcstombsconverts nSố ký tự nhiều byte trừ khi nó<br />
gặp một ký tự null đầu tiên. MPLAB C30 không hỗ trợ<br />
ký tự nhiều byte có chiều dài lớn hơn 1 nhân vật.<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
strtod (Continued)<br />
DS51456B trang 294<br />
2004 Microchip Technology Inc
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 291<br />
strtol<br />
Description: Converts a partial string to a long integer.<br />
Include: <br />
Prototype: long strtol(const char *s, char **endptr, int base);<br />
Arguments: s string to be converted<br />
endptr pointer to the character atwhich the conversion stopped<br />
base number base to use in conversion<br />
Return Value: Returns the converted number if successful; otherwise, returns 0.<br />
Remarks: If baseis zero, strtolattempts to determine the base automatically.<br />
It can be octal, determined by a leading zero, hexadecimal, determined<br />
by a leading 0x or 0X, or decimal in any other case. If base is specified<br />
strtolconverts a sequence of digits and letters a-z (case<br />
insensitive), where a-z represents the numbers 10-36. Conversion<br />
stops when an out of basenumber is encountered. endptrwill point to<br />
the remainder of the string starting with the first unconverted character.<br />
If a range error occurs, errnowill be set.<br />
Example: #include /* for printf */<br />
#include /* for strtol */<br />
int main(void)<br />
{<br />
char *end;<br />
char a[] = "-12BGEE";<br />
char b[] = "1234Number";<br />
long x;<br />
x = strtol(a, &end, 16);<br />
printf("String = \"%s\" long = %ld\n", a, x );<br />
printf("Stopped at: %s\n\n", end );<br />
x = strtol(b, &end, 4);<br />
printf("String = \"%s\" long = %ld\n", b, x );<br />
printf("Stopped at: %s\n\n", end );<br />
}<br />
Output:<br />
String = "-12BGEE" long = -299<br />
Stopped at: GEE<br />
String = "1234Number" long = 27<br />
Stopped at: 4Number<br />
dsPIC<br />
4.15 CHỨC NĂNG STRING<br />
Các string.hconsists tập tin tiêu đề của các loại, macro và các chức năng cung<br />
cấp các công cụ<br />
để thao tác chuỗi.<br />
size_t<br />
Mô tả: Các loại kết quả của sizeofoperator.<br />
Bao gồm:<br />
NULL<br />
Mô tả: Giá trị của một con trỏ hằng null.<br />
Bao gồm:<br />
memchr<br />
Mô tả: Tọa lạc một nhân vật trong một bộ đệm.<br />
Bao gồm:<br />
Nguyên mẫu: void * memchr (const void * s, int c, size_t n);<br />
Đối số: s con trỏ vào bộ đệm<br />
c nhân vật để tìm kiếm<br />
số n của các nhân vật để kiểm tra<br />
Quay trở lại giá trị: Trả về một con trỏ đến vị trí của trận đấu nếu thành<br />
công; nếu không,<br />
trả về null.<br />
Bình luận: memchrstops khi nó tìm thấy sự xuất hiện đầu tiên của cor sau khi<br />
tìm kiếm<br />
nSố ký tự.<br />
Ví dụ: # include / * Cho memchr, NULL * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
char buf1 [50] = "Bây giờ là mấy?";<br />
char ch1 = 'i', CH2 = 'y';<br />
char * ptr;<br />
res int;<br />
printf ("buf1:% s \ n \ n", buf1);<br />
ptr = memchr (buf1, ch1, 50);<br />
if (ptr! = NULL)<br />
{<br />
res = ptr - buf1 1;<br />
printf ("% c tìm thấy ở vị trí% d \ n", ch1, độ phân giải);<br />
}<br />
khác<br />
printf ("% c không tìm thấy \ n", ch1);<br />
Thư viện chuẩn C với hàm toán học
®<br />
Language Tools Libraries<br />
DS51456B-page 292 2004 Microchip Technology Inc.<br />
strtoul<br />
Description: Converts a partial string to an unsigned long integer.<br />
Include: <br />
Prototype: unsigned long strtoul(const char *s, char **endptr,<br />
int base);<br />
Arguments: s string to be converted<br />
endptr pointer to the character at which the conversion stopped<br />
base number base to use in conversion<br />
Return Value: Returns the converted number if successful; otherwise, returns 0.<br />
Remarks: If baseis zero, strtolattempts to determine the base automatically.<br />
It can be octal, determined by a leading zero, hexadecimal, determined<br />
by a leading 0x or 0X, or decimal in any other case. If base is specified<br />
strtolconverts a sequence of digits and letters a-z (case<br />
insensitive), where a-z represents the numbers 10-36. Conversion<br />
stops when an out of base number is encountered. endptrwill point to<br />
the remainder of the string starting with the first unconverted character.<br />
If a range error occurs, errnowill be set.<br />
Example: #include /* for printf */<br />
#include /* for strtoul */<br />
int main(void)<br />
{<br />
char *end;<br />
char a[] = "12BGET3";<br />
char b[] = "0x1234Number";<br />
char c[] = "-123abc";<br />
unsigned long x;<br />
x = strtoul(a, &end, 25);<br />
printf("String = \"%s\" long = %lu\n", a, x );<br />
printf("Stopped at: %s\n\n", end );<br />
x = strtoul(b, &end, 0);<br />
printf("String = \"%s\" long = %lu\n", b, x );<br />
printf("Stopped at: %s\n\n", end );<br />
x = strtoul(c, &end, 0);<br />
printf("String = \"%s\" long = %lu\n", c, x );<br />
printf("Stopped at: %s\n\n", end );<br />
}<br />
2004 Microchip Technology Inc DS51456B trang 295<br />
printf ("\ n");<br />
ptr = memchr (buf1, CH2, 50);<br />
if (ptr! = NULL)<br />
{<br />
res = ptr - buf1 1;<br />
printf ("% c tìm thấy atposition% d \ n", CH2, độ phân giải);<br />
}<br />
khác<br />
printf ("% c không tìm thấy \ n", CH2);<br />
}<br />
Đầu ra:<br />
buf1: Bây giờ là mấy?<br />
tôi tìm thấy ở vị trí 7<br />
y không tìm thấy<br />
memcmp<br />
Mô tả: So sánh nội dung của hai bộ đệm.<br />
Bao gồm:<br />
Nguyên mẫu: int memcmp (const void * s1, const void * s2, size_t n);<br />
Đối số: s1 đệm đầu tiên<br />
s2 đệm thứ hai<br />
số n ký tự để so sánh<br />
Quay trở lại giá trị: Trả về một số dương nếu s1is lớn hơn s2, bằng không nếu<br />
s1is bằng<br />
s2, hoặc một số âm nếu s1is ít hơn s2.<br />
Ghi chú: Chức năng này so sánh ncharacters đầu tiên trong s1to n đầu tiên<br />
nhân vật trong s2and trả về một giá trị cho biết liệu bộ đệm<br />
ít hơn, bằng hoặc lớn hơn so với nhau.<br />
Ví dụ: # include / * Memcmp * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
char buf1 [50] = "đâu là thời điểm";<br />
char buf2 [50] = "Họ đã đi đâu?";<br />
char buf3 [50] = "Tại sao?";<br />
res int;<br />
printf ("buf1:% s \ n", buf1);<br />
printf ("buf2:% s \ n", buf2);<br />
printf ("buf3:% s \ n \ n", buf3);<br />
res = memcmp (buf1, buf2, 6);
Output:<br />
String = "12BGET3" long = 429164<br />
Stopped at: T3<br />
String = "0x1234Number" long = 4660<br />
Stopped at: Number<br />
String = "-123abc" long = 4294967173<br />
Stopped at: abc<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 293<br />
system<br />
Description: Execute a command.<br />
Include: <br />
Prototype: int system(const char *s);<br />
Argument: s command to be executed<br />
Remarks: This function must be customized to be used as described (see<br />
pic30-libs). By default systemwill cause a reset if called with<br />
anything other than NULL. system(NULL)will do nothing.<br />
Example: /* This program uses system */<br />
/* to TYPE its source file. */<br />
#include /* for system */<br />
int main(void)<br />
{<br />
system("type sampsystem.c");<br />
}<br />
Output:<br />
System(type sampsystem.c) called: Aborting<br />
wctomb<br />
Description: Converts a wide character to a multibyte character. (See Remarks.)<br />
Include: <br />
Prototype: int wctomb(char *s, wchar_t wchar);<br />
Arguments: s points to the multibyte character<br />
wchar the wide character to be converted<br />
Return Value: Returns zero if s points to a null character; otherwise, returns 1.<br />
Remarks: The resulting multibyte character is stored at s. MPLAB C30 does not<br />
support multibyte characters with length greater than 1 character.<br />
wcstombs<br />
Description: Converts a wide character string to a multibyte string. (See<br />
Remarks.)<br />
Include: <br />
if (res
Prototype: size_t wcstombs(char *s, const wchar_t *wcs,<br />
size_t n);<br />
Arguments: s points to the multibyte string<br />
wcs points to the wide character string<br />
n the number of characters to convert<br />
Return Value: Returns the number of characters stored excluding the null<br />
character.<br />
Remarks: wcstombsconverts nnumber of multibyte characters unless it<br />
encounters a null character first. MPLAB C30 does not support<br />
multibyte characters with length greater than 1 character.<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 297<br />
memcpy<br />
Mô tả: Bản sao các ký tự từ một bộ đệm khác.<br />
Bao gồm:<br />
Nguyên mẫu: void * memcpy (void * dst, const void * src, size_t n);<br />
Đối số: đệm dst để sao chép nhân vật<br />
src đệm để sao chép các nhân vật từ<br />
số n ký tự sao chép<br />
Quay trở lại giá trị: Trả dst.<br />
Bình luận: memcpycopies ncharacters từ bộ đệm các nguồn srcto<br />
điểm đến dst đệm. Nếu bộ đệm chồng lên nhau, hành vi này là không xác định.<br />
Ví dụ: # include / * Memcpy * /<br />
DS51456B-page 294<br />
2004 Microchip Technology Inc.<br />
# include / * Cho printf * /<br />
4.15 STRING FUNCTIONS<br />
The header file string.hconsists of types, macros and functions that provide tools<br />
to manipulate strings.<br />
size_t<br />
Description: The type of the result of the sizeofoperator.<br />
Include: <br />
NULL<br />
Description: The value of a null pointer constant.<br />
Include: <br />
memchr<br />
Description: Locates a character in a buffer.<br />
Include: <br />
Prototype: void *memchr(const void *s, int c, size_t n);<br />
Arguments: s pointer to the buffer<br />
c character to search for<br />
n number of characters to check<br />
Return Value: Returns a pointer to the location of the match if successful;<br />
otherwise,<br />
returns null.<br />
Remarks: memchrstops when it finds the first occurrence of cor after searching<br />
nnumber of characters.<br />
Example: #include /* for memchr, NULL */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
char buf1[50] = "What time is it?";<br />
int main (void)<br />
{<br />
char buf1 [50] = "";<br />
char buf2 [50] = "đâu là thời điểm";<br />
char buf3 [50] = "Tại sao?";<br />
printf ("buf1:% s \ n", buf1);<br />
printf ("buf2:% s \ n", buf2);<br />
printf ("buf3:% s \ n \ n", buf3);<br />
memcpy (buf1, buf2, 6);<br />
printf ("buf1 sau memcpy 6 ký tự của"<br />
"Buf2: \ n \ t% s \ n", buf1);<br />
printf ("\ n");<br />
memcpy (buf1, buf3, 5);<br />
printf ("buf1 sau memcpy 5 ký tự của"<br />
"Buf3: \ n \ t% s \ n", buf1);<br />
}<br />
Đầu ra:<br />
buf1:<br />
buf2: đâu là thời gian?<br />
buf3: Tại sao?<br />
buf1 sau memcpy of6 ký tự của buf2:<br />
Ở đâu<br />
buf1 sau memcpy of5 ký tự của buf3:<br />
Tại sao?<br />
dsPIC
char ch1 = 'i', ch2 = 'y';<br />
char *ptr;<br />
int res;<br />
printf("buf1 : %s\n\n", buf1);<br />
ptr = memchr(buf1, ch1, 50);<br />
if (ptr != NULL)<br />
{<br />
res = ptr - buf1 + 1;<br />
printf("%c found at position %d\n", ch1, res);<br />
}<br />
else<br />
printf("%c not found\n", ch1);<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 295<br />
printf("\n");<br />
ptr = memchr(buf1, ch2, 50);<br />
if (ptr != NULL)<br />
{<br />
res = ptr - buf1 + 1;<br />
printf("%c found atposition %d\n", ch2, res);<br />
}<br />
else<br />
printf("%c not found\n", ch2);<br />
}<br />
Output:<br />
buf1 : What time is it?<br />
i found at position 7<br />
y not found<br />
memcmp<br />
Description: Compare the contents of two buffers.<br />
Include: <br />
Prototype: int memcmp(const void *s1, const void *s2, size_t n);<br />
Arguments: s1 first buffer<br />
s2 second buffer<br />
n number of characters to compare<br />
Return Value: Returns a positive number if s1is greater than s2, zero if s1is<br />
equal to<br />
s2, or a negative number if s1is less than s2.<br />
Remarks: This function compares the first ncharacters in s1to the first n<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 298<br />
memmove<br />
2004 Microchip Technology Inc<br />
Mô tả: Bản sao n ký tự của sourcebuffer vào bộ đệm đích,<br />
ngay cả khi các khu vực chồng chéo lên nhau.<br />
Bao gồm:<br />
Nguyên mẫu: void * memmove (void * s1, const void * s2, size_t n);<br />
Đối số: s1 đệm để sao chép nhân vật (đích)<br />
s2 đệm để sao chép các nhân vật từ (source)<br />
số n ký tự sao chép từ s2to s1<br />
Quay trở lại giá trị: Trả về một con trỏ đến bộ đệm điểm đến<br />
Ghi chú: Nếu bộ đệm chồng chéo, hiệu quả là asif các nhân vật được đọc đầu<br />
tiên<br />
s2then bằng văn bản cho s1so bộ đệm không bị hỏng.<br />
Ví dụ: # include / * Cho memmove * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
char buf1 [50] = "Khi thời gian cuộc tuần hành trên";<br />
char buf2 [50] = "đâu là thời điểm";<br />
char buf3 [50] = "Tại sao?";<br />
printf ("buf1:% s \ n", buf1);<br />
printf ("buf2:% s \ n", buf2);<br />
printf ("buf3:% s \ n \ n", buf3);<br />
memmove (buf1, buf2, 6);<br />
printf ("buf1 sau memmove 6 ký tự của"<br />
"Buf2: \ n \ t% s \ n", buf1);<br />
printf ("\ n");<br />
memmove (buf1, buf3, 5);<br />
printf ("buf1 sau memmove 5 ký tự của"<br />
"Buf3: \ n \ t% s \ n", buf1);<br />
}<br />
Đầu ra:<br />
buf1: Khi thời gian cuộc tuần hành trên<br />
buf2: đâu là thời gian?<br />
buf3: Tại sao?<br />
buf1 sau memmove 6 ký tự của buf2:<br />
Trường hợp ime cuộc tuần hành trên<br />
buf1 sau memmove 5 ký tự của buf3:
characters in s2and returns a value indicating whether the buffers are<br />
less than, equal to or greater than each other.<br />
Example: #include /* memcmp */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
char buf1[50] = "Where is the time?";<br />
char buf2[50] = "Where did they go?";<br />
char buf3[50] = "Why?";<br />
int res;<br />
printf("buf1 : %s\n", buf1);<br />
printf("buf2 : %s\n", buf2);<br />
printf("buf3 : %s\n\n", buf3);<br />
res = memcmp(buf1, buf2, 6);<br />
if (res < 0)<br />
printf("buf1 comes before buf2\n");<br />
else if (res == 0)<br />
printf("6 characters of buf1 and buf2 "<br />
"are equal\n");<br />
else<br />
printf("buf2 comes before buf1\n");<br />
memchr (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 296 2004 Microchip Technology Inc.<br />
printf("\n");<br />
res = memcmp(buf1, buf2, 20);<br />
if (res < 0)<br />
printf("buf1 comes before buf2\n");<br />
else if (res == 0)<br />
printf("20 characters of buf1 and buf2 "<br />
"are equal\n");<br />
else<br />
printf("buf2 comes before buf1\n");<br />
printf("\n");<br />
res = memcmp(buf1, buf3, 20);<br />
if (res < 0)<br />
printf("buf1 comes before buf3\n");<br />
Tại sao?<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 299<br />
memset<br />
Mô tả: Bản sao các nhân vật được chỉ định vào bộ đệm đích.<br />
Bao gồm:<br />
Nguyên mẫu: void * memset (void * s, int c, size_t n);<br />
Đối số: s đệm<br />
c nhân vật để đưa vào bộ đệm<br />
số n lần<br />
Quay trở lại giá trị: Trả về đệm với các nhân vật bằng văn bản cho nó.<br />
Ghi chú: Các ký tự cis bằng văn bản cho ntimes đệm.<br />
Ví dụ: # include / * Cho memset * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
char buf1 [20] = "Bây giờ là mấy?";<br />
char buf2 [20] = "";<br />
char ch1 =, = CH2 'y' '?';<br />
char * ptr;<br />
res int;<br />
printf ("memset (\"% s \ ", \ '% c \', 4); \ n", buf1, ch1);<br />
memset (buf1, ch1, 4);<br />
printf ("buf1 aftermemset:% s \ n", buf1);<br />
printf ("\ n");<br />
printf ("memset (\"% s \ ", \ '% c \', 10); \ n", buf2, CH2);<br />
memset (buf2, CH2, 10);<br />
printf ("buf2 aftermemset:% s \ n", buf2);<br />
}<br />
Đầu ra:<br />
memset ("thời gian gì isit?", 4 '?');<br />
buf1 sau khi memset: ???? thời gian là nó?<br />
memset ("", 'y', 10);<br />
buf2 sau khi memset: yyyyyyyyyy<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 300 2004 Microchip Technology Inc<br />
strcat
else if (res == 0)<br />
printf("20 characters of buf1 and buf3 "<br />
"are equal\n");<br />
else<br />
printf("buf3 comes before buf1\n");<br />
}<br />
Output:<br />
buf1 : Where is the time?<br />
buf2 : Where did they go?<br />
buf3 : Why?<br />
6 characters of buf1and buf2 are equal<br />
buf2 comes before buf1<br />
buf1 comes before buf3<br />
memcmp (Continued)<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 297<br />
memcpy<br />
Description: Copies characters from one buffer to another.<br />
Include: <br />
Prototype: void *memcpy(void *dst, const void *src, size_t n);<br />
Arguments: dst buffer to copy characters to<br />
src buffer to copy characters from<br />
n number of characters to copy<br />
Return Value: Returns dst.<br />
Remarks: memcpycopies ncharacters from the source buffer srcto the<br />
destination buffer dst. If the buffers overlap, the behavior is undefined.<br />
Example: #include /* memcpy */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
char buf1[50] = "";<br />
char buf2[50] = "Where is the time?";<br />
char buf3[50] = "Why?";<br />
printf("buf1 : %s\n", buf1);<br />
printf("buf2 : %s\n", buf2);<br />
printf("buf3 : %s\n\n", buf3);<br />
memcpy(buf1, buf2, 6);<br />
printf("buf1 after memcpy of 6 chars of "<br />
"buf2: \n\t%s\n", buf1);<br />
Mô tả: Gắn thêm một bản sao của mã nguồn stringto cuối của chuỗi đích.<br />
Bao gồm:<br />
Prototype: char * strcat (char * s1, const char * s2);<br />
Đối số: s1 null chấm dứt chuỗi đích để sao chép vào<br />
s2 null chấm dứt chuỗi nguồn được sao chép<br />
Quay trở lại giá trị: Trả về một con trỏ đến chuỗi đích.<br />
Ghi chú: Chức năng này gắn thêm chuỗi nguồn (bao gồm cả việc chấm dứt vô<br />
nhân vật) vào cuối của chuỗi đích. Các nhân vật ban đầu của<br />
chuỗi nguồn sẽ ghi đè lên các ký tự null ở cuối của<br />
chuỗi đích. Nếu bộ đệm chồng lên nhau, hành vi này là không xác định.<br />
Ví dụ: # include / * Cho strcat, strlen * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
char buf1 [50] = "Chúng tôi ở đây";<br />
char buf2 [50] = "đâu là thời điểm";<br />
printf ("buf1:% s \ n", buf1);<br />
printf ("\ t (% d ký tự) \ n \ n", strlen (buf1));<br />
printf ("buf2:% s \ n", buf2);<br />
printf ("\ t (% d ký tự) \ n \ n", strlen (buf2));<br />
strcat (buf1, buf2);<br />
printf ("buf1 sau strcat của buf2: \ n \ t% s \ n",<br />
buf1);<br />
printf ("\ t (% d ký tự) \ n", strlen (buf1));<br />
printf ("\ n");<br />
strcat (buf1, "Tại sao?");<br />
printf ("buf1 sau strcatof \" Tại sao \? ": \ n \ t% s \ n",<br />
buf1);<br />
printf ("\ t (% d ký tự) \ n", strlen (buf1));<br />
}<br />
Đầu ra:<br />
buf1: Chúng tôi ở đây<br />
(10 ký tự)<br />
buf2: đâu là thời gian?<br />
(18 ký tự)<br />
buf1 sau strcat của buf2:<br />
Chúng tôi hereWhere là thời gian?<br />
(28 ký tự)<br />
buf1 sau strcat của "Tại sao?":
printf("\n");<br />
memcpy(buf1, buf3, 5);<br />
printf("buf1 after memcpy of 5 chars of "<br />
"buf3: \n\t%s\n", buf1);<br />
}<br />
Output:<br />
buf1 :<br />
buf2 : Where is the time?<br />
buf3 : Why?<br />
buf1 after memcpy of6 chars of buf2:<br />
Where<br />
buf1 after memcpy of5 chars of buf3:<br />
Why?<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 298<br />
memmove<br />
2004 Microchip Technology Inc.<br />
Description: Copies n characters of the sourcebuffer into the destination buffer,<br />
even if the regions overlap.<br />
Include: <br />
Prototype: void *memmove(void *s1, const void *s2, size_t n);<br />
Arguments: s1 buffer to copy characters to (destination)<br />
s2 buffer to copy characters from (source)<br />
n number of characters to copy from s2to s1<br />
Return Value: Returns a pointer to the destination buffer<br />
Remarks: If the buffers overlap, the effect is asif the characters are read first<br />
from<br />
s2then written to s1so the buffer is not corrupted.<br />
Example: #include /* for memmove */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
char buf1[50] = "When time marches on";<br />
char buf2[50] = "Where is the time?";<br />
char buf3[50] = "Why?";<br />
printf("buf1 : %s\n", buf1);<br />
printf("buf2 : %s\n", buf2);<br />
printf("buf3 : %s\n\n", buf3);<br />
Chúng tôi hereWhere là thời gian? Tại sao?<br />
(32 ký tự)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 301<br />
strchr<br />
Mô tả: Tọa lạc xuất hiện đầu tiên của một nhân vật được quy định trong một<br />
chuỗi.<br />
Bao gồm:<br />
Prototype: char * strchr (const char * s, int c);<br />
Đối số: s con trỏ đến chuỗi<br />
c nhân vật để tìm kiếm<br />
Quay trở lại giá trị: Trả về một con trỏ đến vị trí của trận đấu nếu thành<br />
công; nếu không,<br />
trả về một con trỏ null.<br />
Bình luận: chức năng này tìm kiếm chuỗi sto tìm sự xuất hiện đầu tiên của<br />
nhân vật c.<br />
Ví dụ: # include / * Forstrchr, NULL * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
char buf1 [50] = "Bây giờ là mấy?";<br />
char ch1 = 'm', CH2 = 'y';<br />
char * ptr;<br />
res int;<br />
printf ("buf1:% s \ n \ n", buf1);<br />
ptr = strchr (buf1, ch1);<br />
if (ptr! = NULL)<br />
{<br />
res = ptr - buf1 1;<br />
printf ("% c tìm thấy atposition% d \ n", ch1, độ phân giải);<br />
}<br />
khác<br />
printf ("% c không tìm thấy \ n", ch1);<br />
printf ("\ n");<br />
ptr = strchr (buf1, CH2);<br />
if (ptr! = NULL)<br />
{<br />
res = ptr - buf1 1;<br />
printf ("% c tìm thấy atposition% d \ n", CH2, độ phân giải);<br />
}
memmove(buf1, buf2, 6);<br />
printf("buf1 after memmove of 6 chars of "<br />
"buf2: \n\t%s\n", buf1);<br />
printf("\n");<br />
memmove(buf1, buf3, 5);<br />
printf("buf1 after memmove of 5 chars of "<br />
"buf3: \n\t%s\n", buf1);<br />
}<br />
Output:<br />
buf1 : When time marches on<br />
buf2 : Where is the time?<br />
buf3 : Why?<br />
buf1 after memmove of 6 chars of buf2:<br />
Where ime marches on<br />
buf1 after memmove of 5 chars of buf3:<br />
Why?<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 299<br />
memset<br />
Description: Copies the specified character into the destination buffer.<br />
Include: <br />
Prototype: void *memset(void *s, int c, size_t n);<br />
Arguments: s buffer<br />
c character to put in buffer<br />
n number of times<br />
Return Value: Returns the buffer with characters written to it.<br />
Remarks: The character cis written to the buffer ntimes.<br />
Example: #include /* for memset */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
char buf1[20] = "What time is it?";<br />
char buf2[20] = "";<br />
char ch1 = '?', ch2 = 'y';<br />
char *ptr;<br />
int res;<br />
printf("memset(\"%s\", \'%c\',4);\n", buf1, ch1);<br />
memset(buf1, ch1, 4);<br />
printf("buf1 aftermemset: %s\n", buf1);<br />
khác<br />
printf ("% c không tìm thấy \ n", CH2);<br />
}<br />
Đầu ra:<br />
buf1: Bây giờ là mấy?<br />
m tìm thấy ở vị trí 8<br />
y không tìm thấy<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 302<br />
strcmp<br />
Mô tả: So sánh hai chuỗi.<br />
Bao gồm:<br />
2004 Microchip Technology Inc<br />
Nguyên mẫu: int strcmp (const char * s1, const char * s2);<br />
Đối số: s1 chuỗi đầu tiên<br />
chuỗi s2second<br />
Quay trở lại giá trị: Trả về một số dương nếu s1is lớn hơn s2, bằng không nếu<br />
s1is bằng<br />
s2, hoặc một số âm nếu s1is ít hơn s2.<br />
Ghi chú: Chức năng này so sánh nhân vật tiếp từ s1and s2until<br />
chúng không bằng nhau hoặc terminator null được đạt tới.<br />
Ví dụ: # include / * Cho strcmp * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
char buf1 [50] = "đâu là thời điểm";<br />
char buf2 [50] = "Họ đã đi đâu?";<br />
char buf3 [50] = "Tại sao?";<br />
res int;<br />
printf ("buf1:% s \ n", buf1);<br />
printf ("buf2:% s \ n", buf2);<br />
printf ("buf3:% s \ n \ n", buf3);<br />
res = strcmp (buf1, buf2);<br />
if (res
printf("\n");<br />
printf("memset(\"%s\", \'%c\',10);\n", buf2, ch2);<br />
memset(buf2, ch2, 10);<br />
printf("buf2 aftermemset: %s\n", buf2);<br />
}<br />
Output:<br />
memset("What time isit?", '?',4);<br />
buf1 after memset: ???? time is it?<br />
memset("", 'y',10);<br />
buf2 after memset: yyyyyyyyyy<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 300<br />
strcat<br />
2004 Microchip Technology Inc.<br />
Description: Appends a copy of the source stringto the end of the destination<br />
string.<br />
Include: <br />
Prototype: char *strcat(char *s1, const char *s2);<br />
Arguments: s1 null terminated destination string to copy to<br />
s2 null terminated source string to be copied<br />
Return Value: Returns a pointer to the destination string.<br />
Remarks: This function appends the source string (including the terminating<br />
null<br />
character) to the end of the destination string. The initial character of<br />
the source string overwrites the null character at the end of the<br />
destination string. If the buffers overlap, the behavior is undefined.<br />
Example: #include /* for strcat, strlen */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
char buf1[50] = "We're here";<br />
char buf2[50] = "Where is the time?";<br />
printf("buf1 : %s\n", buf1);<br />
printf("\t(%d characters)\n\n", strlen(buf1));<br />
printf("buf2 : %s\n", buf2);<br />
printf("\t(%d characters)\n\n", strlen(buf2));<br />
strcat(buf1, buf2);<br />
printf("buf1 after strcat of buf2: \n\t%s\n",<br />
buf1);<br />
printf ("\ n");<br />
res = strcmp (buf1, buf3);<br />
if (res
printf("\t(%d characters)\n", strlen(buf1));<br />
printf("\n");<br />
strcat(buf1, "Why?");<br />
printf("buf1 after strcatof \"Why?\": \n\t%s\n",<br />
buf1);<br />
printf("\t(%d characters)\n", strlen(buf1));<br />
}<br />
Output:<br />
buf1 : We're here<br />
(10 characters)<br />
buf2 : Where is the time?<br />
(18 characters)<br />
buf1 after strcat of buf2:<br />
We're hereWhere is the time?<br />
(28 characters)<br />
buf1 after strcat of "Why?":<br />
We're hereWhere is the time?Why?<br />
(32 characters)<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 301<br />
strchr<br />
Description: Locates the first occurrence of a specified character in a string.<br />
Include: <br />
Prototype: char *strchr(const char *s, int c);<br />
Arguments: s pointer to the string<br />
c character to search for<br />
Return Value: Returns a pointer to the location of the match if successful;<br />
otherwise,<br />
returns a null pointer.<br />
Remarks: This function searches the string sto find the first occurrence of the<br />
character c.<br />
Example: #include /* forstrchr, NULL */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
char buf1[50] = "What time is it?";<br />
char ch1 = 'm', ch2 = 'y';<br />
char *ptr;<br />
int res;<br />
Mô tả: Sao chép chuỗi nguồn vào chuỗi đích.<br />
Bao gồm:<br />
Prototype: char * strcpy (char * s1, const char * s2);<br />
Đối số: s1 chuỗi đích để sao chép vào<br />
chuỗi nguồn s2 sao chép từ<br />
Quay trở lại giá trị: Trả về một con trỏ đến chuỗi đích.<br />
Bình luận: Tất cả các nhân vật của s2are sao chép, bao gồm ký tự chấm dứt nul<br />
Nếu chuỗi chồng chéo lên nhau, hành vi này là không xác định.<br />
Ví dụ: # include / * Forstrcpy, strlen * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
char buf1 [50] = "Chúng tôi ở đây";<br />
char buf2 [50] = "đâu là thời điểm";<br />
char buf3 [50] = "Tại sao?";<br />
printf ("buf1:% s \ n", buf1);<br />
printf ("buf2:% s \ n", buf2);<br />
printf ("buf3:% s \ n \ n", buf3);<br />
strcpy (buf1, buf2);<br />
printf ("buf1 sau strcpy của buf2: \ n \ t% s \ n \ n",<br />
buf1);<br />
strcmp (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 304 2004 Microchip Technology Inc<br />
strcpy (buf1, buf3);<br />
printf ("buf1 sau strcpy của buf3: \ n \ t% s \ n",<br />
buf1);<br />
}<br />
Đầu ra:<br />
buf1: Chúng tôi ở đây<br />
buf2: đâu là thời gian?<br />
buf3: Tại sao?<br />
buf1 sau strcpy của buf2:<br />
Ở đâu thời gian?<br />
buf1 sau strcpy của buf3:<br />
Tại sao?<br />
strcspn
printf("buf1 : %s\n\n", buf1);<br />
ptr = strchr(buf1, ch1);<br />
if (ptr != NULL)<br />
{<br />
res = ptr - buf1 + 1;<br />
printf("%c found atposition %d\n", ch1, res);<br />
}<br />
else<br />
printf("%c not found\n", ch1);<br />
printf("\n");<br />
ptr = strchr(buf1, ch2);<br />
if (ptr != NULL)<br />
{<br />
res = ptr - buf1 + 1;<br />
printf("%c found atposition %d\n", ch2, res);<br />
}<br />
else<br />
printf("%c not found\n", ch2);<br />
}<br />
Output:<br />
buf1 : What time is it?<br />
m found at position 8<br />
y not found<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 302<br />
strcmp<br />
Description: Compares two strings.<br />
Include: <br />
2004 Microchip Technology Inc.<br />
Prototype: int strcmp(const char *s1, const char *s2);<br />
Arguments: s1 first string<br />
s2second string<br />
Return Value: Returns a positive number if s1is greater than s2, zero if s1is<br />
equal to<br />
s2, or a negative number if s1is less than s2.<br />
Remarks: This function compares successive characters from s1and s2until<br />
they are not equal or the null terminator is reached.<br />
Example: #include /* for strcmp */<br />
Mô tả: Tính toán số lượng các ký tự liên tiếp vào đầu của một<br />
chuỗi không được containedin một tập hợp các ký tự.<br />
Bao gồm:<br />
Prototype: strcspn size_t (const char * s1, const char * s2);<br />
Đối số: con trỏ s1 vào chuỗi cần tìm kiếm<br />
s2 con trỏ đến ký tự để tìm kiếm<br />
Quay trở lại giá trị: Trả về độ dài của phân khúc này trong s1not chứa các ký tự<br />
được tìm thấy trong s2.<br />
Bình luận: chức năng này sẽ xác định các ký tự liên tiếp từ numberof<br />
đầu s1that không có trong s2.<br />
Ví dụ: # include / * Cho strcspn * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
char str1 [20] = "hello";<br />
char str2 [20] = "aeiou";<br />
char str3 [20] = "động vật";<br />
char str4 [20] = "xyz";<br />
res int;<br />
res = strcspn (str1, str2);<br />
printf ("strcspn (\"% s \ ", \"% s \ ") =% d \ n",<br />
str1, str2, độ phân giải);<br />
res = strcspn (str3, str2);<br />
printf ("strcspn (\"% s \ ", \"% s \ ") =% d \ n",<br />
str3, str2, độ phân giải);<br />
res = strcspn (str3, str4);<br />
printf ("strcspn (\"% s \ ", \"% s \ ") =% d \ n",<br />
str3, str4, độ phân giải);<br />
}<br />
Đầu ra:<br />
strcspn ("hello", "aeiou") = 1<br />
strcspn ("động vật", "aeiou") = 0<br />
strcspn ("động vật", "xyz") = 6<br />
strcpy (Tiếp theo)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 305<br />
Giải thích:<br />
Trong kết quả đầu tiên, eis trong s2so nó ngừng đếm sau khi h.<br />
Trong kết quả thứ hai, ais trong s2.
#include /* for printf */<br />
int main(void)<br />
{<br />
char buf1[50] = "Where is the time?";<br />
char buf2[50] = "Where did they go?";<br />
char buf3[50] = "Why?";<br />
int res;<br />
printf("buf1 : %s\n", buf1);<br />
printf("buf2 : %s\n", buf2);<br />
printf("buf3 : %s\n\n", buf3);<br />
res = strcmp(buf1, buf2);<br />
if (res < 0)<br />
printf("buf1 comes before buf2\n");<br />
else if (res == 0)<br />
printf("buf1 andbuf2 are equal\n");<br />
else<br />
printf("buf2 comes before buf1\n");<br />
printf("\n");<br />
res = strcmp(buf1, buf3);<br />
if (res < 0)<br />
printf("buf1 comes before buf3\n");<br />
else if (res == 0)<br />
printf("buf1 andbuf3 are equal\n");<br />
else<br />
printf("buf3 comes before buf1\n");<br />
printf("\n");<br />
res = strcmp("Why?", buf3);<br />
if (res < 0)<br />
printf("\"Why?\"comes before buf3\n");<br />
else if (res == 0)<br />
printf("\"Why?\" and buf3 are equal\n");<br />
else<br />
printf("buf3 comes before \"Why?\"\n");<br />
}<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 303<br />
Output:<br />
buf1 : Where is the time?<br />
buf2 : Where did they go?<br />
Trong kết quả thứ ba, không ai trong số các nhân vật của s1are trong s2so tất cả<br />
nhân vật được tính.<br />
dột<br />
Mô tả: Được một thông báo lỗi nội bộ.<br />
Bao gồm:<br />
Prototype: char * dột (int errcode);<br />
Errcode số của mã lỗi: Đối số<br />
Quay trở lại giá trị: Trả về một con trỏ đến một thông báo lỗi nội bộ để<br />
stringcorresponding<br />
mã lỗi errcode quy định.<br />
Ghi chú: Các mảng trỏ đến bởi strerrormay được ghi đè bởi một<br />
cuộc gọi tiếp theo để chức năng này.<br />
Ví dụ: # include / * Cho fopen, fclose, * /<br />
/ * Printf, FILE, NULL * /<br />
# include / * Cho dột * /<br />
# include / * Cho errno * /<br />
int main (void)<br />
{<br />
FILE * myfile;<br />
if ((myfile = fopen ("samp.fil", "r +")) == NULL)<br />
printf ("Không thể mở samp.fil:% s \ n",<br />
dột (errno));<br />
khác<br />
printf ("Thành công mở samp.fil \ n");<br />
fclose (myfile);<br />
}<br />
Đầu ra:<br />
Không thể mở samp.fil: tập tin lỗi mở<br />
strlen<br />
Mô tả: Tìm chiều dài của một chuỗi.<br />
Bao gồm:<br />
Prototype: size_t strlen (const char * s);<br />
Đối số: s chuỗi<br />
Quay trở lại giá trị: Trả về độ dài của một chuỗi.<br />
Bình luận: Chức năng này quyết định độ dài của chuỗi, không bao gồm<br />
chấm dứt ký tự null.<br />
strcspn (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ
uf3 : Why?<br />
buf2 comes before buf1<br />
buf1 comes before buf3<br />
"Why?" and buf3 are equal<br />
strcoll<br />
Description: Compares one string to another. (See Remarks.)<br />
Include: <br />
Prototype: int strcoll(const char *s1, const char *s2);<br />
Arguments: s1 first string<br />
s2 second string<br />
Return Value: Using the locale-dependent rules, itreturns a positive number if<br />
s1is<br />
greater than s2, zero if s1is equal to s2, or a negative number if s1is<br />
less than s2.<br />
Remarks: Since MPLAB C30 does not support alternate locales, this function is<br />
equivalent to strcmp.<br />
strcpy<br />
Description: Copy the source string into the destination string.<br />
Include: <br />
Prototype: char *strcpy(char *s1, const char *s2);<br />
Arguments: s1 destination string to copy to<br />
s2 source string to copy from<br />
Return Value: Returns a pointer to the destination string.<br />
Remarks: All characters of s2are copied, including the null terminating<br />
character.<br />
If the strings overlap, the behavior is undefined.<br />
Example: #include /* forstrcpy, strlen */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
char buf1[50] = "We're here";<br />
char buf2[50] = "Where is the time?";<br />
char buf3[50] = "Why?";<br />
printf("buf1 : %s\n", buf1);<br />
printf("buf2 : %s\n", buf2);<br />
printf("buf3 : %s\n\n", buf3);<br />
strcpy(buf1, buf2);<br />
printf("buf1 after strcpy of buf2: \n\t%s\n\n",<br />
buf1);<br />
strcmp (Continued)<br />
DS51456B trang 306<br />
Ví dụ: # include / * Cho strlen * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
2004 Microchip Technology Inc<br />
char str1 [20] = "Chúng tôi đang ở đây";<br />
char str2 [20] = "";<br />
char str3 [20] = "Sao lại là tôi?";<br />
printf ("str1:% s \ n", str1);<br />
printf ("\ t (string chiều dài =% d ký tự) \ n \ n",<br />
strlen (str1));<br />
printf ("str2:% s \ n", str2);<br />
printf ("\ t (string chiều dài =% d ký tự) \ n \ n",<br />
strlen (str2));<br />
printf ("str3:% s \ n", str3);<br />
printf ("\ t (string chiều dài =% d ký tự) \ n \ n \ n",<br />
strlen (str3));<br />
}<br />
Đầu ra:<br />
str1: Chúng tôi đang ở đây<br />
(Chiều dài chuỗi = 11 ký tự)<br />
str2:<br />
(Chiều dài chuỗi = 0 ký tự)<br />
str3: Tại sao tôi không?<br />
(Chiều dài chuỗi = 7 ký tự)<br />
strncat<br />
Mô tả: Thêm một số quy định của ký tự từ chuỗi nguồn đến<br />
chuỗi đích.<br />
Bao gồm:<br />
Prototype: char * strncat (char * s1, const char * s2, size_t n);<br />
Đối số: s1 chuỗi đích để sao chép vào<br />
chuỗi nguồn s2 sao chép từ<br />
số n của các nhân vật để phụ thêm<br />
Quay trở lại giá trị: Trả về một con trỏ đến chuỗi đích.<br />
Ghi chú: Chức năng này gắn thêm lên đến ncharacters (một nhân vật vô giá trị<br />
và<br />
nhân vật mà theo nó không nối) từ chuỗi nguồn đến<br />
kết thúc của chuỗi đích. Nếu một ký tự null không gặp, sau đó<br />
một ký tự null chấm dứt được gắn vào kết quả. Nếu dây<br />
chồng chéo lên nhau, hành vi này là không xác định.
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 304<br />
strcpy(buf1, buf3);<br />
2004 Microchip Technology Inc.<br />
printf("buf1 after strcpy of buf3: \n\t%s\n",<br />
buf1);<br />
}<br />
Output:<br />
buf1 : We're here<br />
buf2 : Where is the time?<br />
buf3 : Why?<br />
buf1 after strcpy of buf2:<br />
Where is the time?<br />
buf1 after strcpy of buf3:<br />
Why?<br />
strcspn<br />
Description: Calculate the number of consecutive characters at the beginning of<br />
a<br />
string that are not containedin a set of characters.<br />
Include: <br />
Prototype: size_t strcspn(const char *s1, const char *s2);<br />
Arguments: s1 pointer to the string to be searched<br />
s2 pointer to characters to search for<br />
Return Value: Returns the length of the segment in s1not containing characters<br />
found in s2.<br />
Remarks: This function will determine the numberof consecutive characters<br />
from<br />
the beginning of s1that are not contained in s2.<br />
Example: #include /* for strcspn */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
char str1[20] = "hello";<br />
char str2[20] = "aeiou";<br />
char str3[20] = "animal";<br />
char str4[20] = "xyz";<br />
int res;<br />
res = strcspn(str1, str2);<br />
printf("strcspn(\"%s\", \"%s\") = %d\n",<br />
Ví dụ: # include / * Cho strncat, strlen * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
char buf1 [50] = "Chúng tôi ở đây";<br />
char buf2 [50] = "đâu là thời điểm";<br />
char buf3 [50] = "Tại sao?";<br />
strlen (Tiếp theo)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 307<br />
printf ("buf1:% s \ n", buf1);<br />
printf ("\ t (% d ký tự) \ n \ n", strlen (buf1));<br />
printf ("buf2:% s \ n", buf2);<br />
printf ("\ t (% d ký tự) \ n \ n", strlen (buf2));<br />
printf ("buf3:% s \ n", buf3);<br />
printf ("\ t (% d ký tự) \ n \ n \ n", strlen (buf3));<br />
strncat (buf1, buf2, 6);<br />
printf ("buf1 sau strncat 6 ký tự"<br />
"Của buf2: \ n \ t% s \ n", buf1);<br />
printf ("\ t (% d ký tự) \ n", strlen (buf1));<br />
printf ("\ n");<br />
strncat (buf1, buf2, 25);<br />
printf ("buf1 sau strncat 25 ký tự"<br />
"Của buf2: \ n \ t% s \ n", buf1);<br />
printf ("\ t (% d ký tự) \ n", strlen (buf1));<br />
printf ("\ n");<br />
strncat (buf1, buf3, 4);<br />
printf ("buf1 sau strncat của 4 nhân vật"<br />
"Của buf3: \ n \ t% s \ n", buf1);<br />
printf ("\ t (% d ký tự) \ n", strlen (buf1));<br />
}<br />
Đầu ra:<br />
buf1: Chúng tôi ở đây<br />
(10 ký tự)<br />
buf2: đâu là thời gian?<br />
(18 ký tự)<br />
buf3: Tại sao?<br />
(4 ký tự)<br />
buf1 sau strncat 6 ký tự của buf2:
str1, str2, res);<br />
res = strcspn(str3, str2);<br />
printf("strcspn(\"%s\", \"%s\") = %d\n",<br />
str3, str2, res);<br />
res = strcspn(str3, str4);<br />
printf("strcspn(\"%s\", \"%s\") = %d\n",<br />
str3, str4, res);<br />
}<br />
Output:<br />
strcspn("hello", "aeiou") = 1<br />
strcspn("animal", "aeiou") = 0<br />
strcspn("animal", "xyz") = 6<br />
strcpy (Continued)<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 305<br />
Explanation:<br />
In the first result, eis in s2so it stops counting after h.<br />
In the second result, ais in s2.<br />
In the third result, none of the characters of s1are in s2so all<br />
characters are counted.<br />
strerror<br />
Description: Gets an internal error message.<br />
Include: <br />
Prototype: char *strerror(int errcode);<br />
Argument: errcode number of the error code<br />
Return Value: Returns a pointer to an internal error message<br />
stringcorresponding to<br />
the specified error code errcode.<br />
Remarks: The array pointed to by strerrormay be overwritten by a<br />
subsequent call to this function.<br />
Example: #include /* for fopen, fclose, */<br />
/* printf, FILE, NULL */<br />
#include /* for strerror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
FILE *myfile;<br />
if ((myfile = fopen("samp.fil", "r+")) == NULL)<br />
printf("Cannot open samp.fil: %s\n",<br />
Chúng tôi hereWhere<br />
(16 ký tự)<br />
buf1 sau strncat 25 ký tự của buf2:<br />
Chúng tôi hereWhere ở đâu thời gian?<br />
(34 ký tự)<br />
buf1 sau strncat của 4 nhân vật của buf3:<br />
Chúng tôi hereWhere ở đâu thời gian? Tại sao?<br />
(38 ký tự)<br />
strncat (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 308<br />
strncmp<br />
2004 Microchip Technology Inc<br />
Mô tả: So sánh hai chuỗi, cho đến một số quy định của ký tự.<br />
Bao gồm:<br />
Nguyên mẫu: int strncmp (const char * s1, const char * s2,<br />
size_t n);<br />
Đối số: s1 chuỗi đầu tiên<br />
s2 chuỗi thứ hai<br />
số n ký tự để so sánh<br />
Quay trở lại giá trị: Trả về một số dương nếu s1is lớn hơn s2, bằng không nếu<br />
s1is bằng<br />
s2, hoặc một số âm nếu s1is ít hơn s2.<br />
Bình luận: strncmpreturns một giá trị dựa trên các nhân vật đầu tiên mà khác<br />
giữa s1and s2. Nhân vật tiếp theo một ký tự null không<br />
so sánh.<br />
Ví dụ: # include / * Cho strncmp * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
char buf1 [50] = "đâu là thời điểm";<br />
char buf2 [50] = "Họ đã đi đâu?";<br />
char buf3 [50] = "Tại sao?";<br />
res int;<br />
printf ("buf1:% s \ n", buf1);<br />
printf ("buf2:% s \ n", buf2);<br />
printf ("buf3:% s \ n \ n", buf3);<br />
res = strncmp (buf1, buf2, 6);<br />
if (res
strerror(errno));<br />
else<br />
printf("Success opening samp.fil\n");<br />
fclose(myfile);<br />
}<br />
Output:<br />
Cannot open samp.fil: file open error<br />
strlen<br />
Description: Finds the length of a string.<br />
Include: <br />
Prototype: size_t strlen(const char *s);<br />
Argument: s the string<br />
Return Value: Returns the length of a string.<br />
Remarks: This function determines the length of the string, not including the<br />
terminating null character.<br />
strcspn (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 306 2004 Microchip Technology Inc.<br />
Example: #include /* for strlen */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
char str1[20] = "We are here";<br />
char str2[20] = "";<br />
char str3[20] = "Why me?";<br />
printf("str1 : %s\n", str1);<br />
printf("\t(string length = %d characters)\n\n",<br />
strlen(str1));<br />
printf("str2 : %s\n", str2);<br />
printf("\t(string length = %d characters)\n\n",<br />
strlen(str2));<br />
printf("str3 : %s\n", str3);<br />
printf("\t(string length = %d characters)\n\n\n",<br />
strlen(str3));<br />
}<br />
Output:<br />
str1 : We are here<br />
printf ("buf1 đến trước buf2 \ n");<br />
if (res == 0)<br />
printf ("6 charactersof buf1 và buf2"<br />
"Bằng nhau \ n");<br />
khác<br />
printf ("buf2 đến trước buf1 \ n");<br />
printf ("\ n");<br />
res = strncmp (buf1, buf2, 20);<br />
if (res
(string length = 11 characters)<br />
str2 :<br />
(string length = 0 characters)<br />
str3 : Why me?<br />
(string length = 7 characters)<br />
strncat<br />
Description: Append a specified number of characters from the source string to<br />
the<br />
destination string.<br />
Include: <br />
Prototype: char *strncat(char *s1, const char *s2, size_t n);<br />
Arguments: s1 destination string to copy to<br />
s2 source string to copy from<br />
n number of characters to append<br />
Return Value: Returns a pointer to the destination string.<br />
Remarks: This function appends up to ncharacters (a null character and<br />
characters that follow it are not appended) from the source string to the<br />
end of the destination string. If a null character is not encountered, then<br />
a terminating null character is appended to the result. If the strings<br />
overlap, the behavior is undefined.<br />
Example: #include /* for strncat, strlen */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
char buf1[50] = "We're here";<br />
Đối số: s1 chuỗi đích để sao chép vào<br />
chuỗi nguồn s2 sao chép từ<br />
số n ký tự sao chép<br />
Quay trở lại giá trị: Trả về một con trỏ đến chuỗi đích.<br />
Bình luận: Bản sao ncharacters từ chuỗi nguồn vào chuỗi đích. Nếu<br />
chuỗi nguồn ít hơn ncharacters, điểm đến đầy<br />
ký tự null tổng ncharacters. Nếu ncharacters đã được sao chép và không có<br />
ký tự rỗng được tìm thấy sau đó các chuỗi điểm đến sẽ không được<br />
null-chấm dứt. Nếu chuỗi chồng chéo lên nhau, hành vi này là không xác định.<br />
Ví dụ: # include / * Forstrncpy, strlen * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
char buf1 [50] = "Chúng tôi ở đây";<br />
char buf2 [50] = "đâu là thời điểm";<br />
char buf3 [50] = "Tại sao?";<br />
buf4 char [7] = "Ở đâu?";<br />
printf ("buf1:% s \ n", buf1);<br />
printf ("buf2:% s \ n", buf2);<br />
printf ("buf3:% s \ n", buf3);<br />
printf ("buf4:% s \ n", buf4);<br />
strncmp (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
char buf2[50] = "Where is the time?";<br />
char buf3[50] = "Why?";<br />
DS51456B trang 310<br />
strncpy (buf1, buf2, 6);<br />
2004 Microchip Technology Inc<br />
strlen (Continued)<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 307<br />
printf("buf1 : %s\n", buf1);<br />
printf("\t(%d characters)\n\n", strlen(buf1));<br />
printf("buf2 : %s\n", buf2);<br />
printf("\t(%d characters)\n\n", strlen(buf2));<br />
printf("buf3 : %s\n", buf3);<br />
printf("\t(%d characters)\n\n\n", strlen(buf3));<br />
strncat(buf1, buf2, 6);<br />
printf("buf1 after strncat of 6 characters "<br />
"of buf2: \n\t%s\n", buf1);<br />
printf ("buf1 sau strncpy 6 ký tự"<br />
"Của buf2: \ n \ t% s \ n", buf1);<br />
printf ("\ t (% d ký tự) \ n", strlen (buf1));<br />
printf ("\ n");<br />
strncpy (buf1, buf2, 18);<br />
printf ("buf1 sau strncpy của 18 nhân vật"<br />
"Của buf2: \ n \ t% s \ n", buf1);<br />
printf ("\ t (% d ký tự) \ n", strlen (buf1));<br />
printf ("\ n");<br />
strncpy (buf1, buf3, 5);<br />
printf ("buf1 sau strncpy 5 ký tự"<br />
"Của buf3: \ n \ t% s \ n", buf1);
printf("\t(%d characters)\n", strlen(buf1));<br />
printf("\n");<br />
strncat(buf1, buf2, 25);<br />
printf("buf1 after strncat of 25 characters "<br />
"of buf2: \n\t%s\n", buf1);<br />
printf("\t(%d characters)\n", strlen(buf1));<br />
printf("\n");<br />
strncat(buf1, buf3, 4);<br />
printf("buf1 after strncat of 4 characters "<br />
"of buf3: \n\t%s\n", buf1);<br />
printf("\t(%d characters)\n", strlen(buf1));<br />
}<br />
Output:<br />
buf1 : We're here<br />
(10 characters)<br />
buf2 : Where is the time?<br />
(18 characters)<br />
buf3 : Why?<br />
(4 characters)<br />
buf1 after strncat of 6 characters of buf2:<br />
We're hereWhere<br />
(16 characters)<br />
buf1 after strncat of 25 characters of buf2:<br />
We're hereWhere Where is the time?<br />
(34 characters)<br />
buf1 after strncat of 4 characters of buf3:<br />
We're hereWhere Where is the time?Why?<br />
(38 characters)<br />
strncat (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
printf ("\ t (% d ký tự) \ n", strlen (buf1));<br />
printf ("\ n");<br />
strncpy (buf1, buf4, 9);<br />
printf ("buf1 sau strncpy của 9 nhân vật"<br />
"Của buf4: \ n \ t% s \ n", buf1);<br />
printf ("\ t (% d ký tự) \ n", strlen (buf1));<br />
}<br />
Đầu ra:<br />
buf1: Chúng tôi ở đây<br />
buf2: đâu là thời gian?<br />
buf3: Tại sao?<br />
buf4: ở đâu?<br />
buf1 sau strncpy 6 ký tự của buf2:<br />
Trường hợp ở đây<br />
(10 ký tự)<br />
buf1 sau strncpy của 18characters của buf2:<br />
Ở đâu thời gian?<br />
(18 ký tự)<br />
buf1 sau strncpy 5 ký tự của buf3:<br />
Tại sao?<br />
(4 ký tự)<br />
buf1 sau strncpy của 9 nhân vật của buf4:<br />
Ở đâu?<br />
(6 ký tự)<br />
strncpy (Tiếp theo)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 311<br />
Giải thích:<br />
Mỗi bộ đệm chứa chuỗi thể hiện, tiếp theo là ký tự null cho một<br />
chiều dài của 50 dùng strlenwill tìm thấy chiều dài của chuỗi lên đến nhưng<br />
không<br />
bao gồm các ký tự null đầu tiên.<br />
Trong ví dụ đầu tiên, 6 ký tự của buf2 ("ở đâu") thay thế 6 tháng đầu năm<br />
DS51456B-page 308<br />
strncmp<br />
2004 Microchip Technology Inc.<br />
nhân vật của buf1 ("Chúng tôi") và phần còn lại của buf1remains cùng<br />
("Ở đây" cộng với ký tự null).<br />
Description: Compare two strings, up to a specified number of characters.<br />
Include: <br />
Prototype: int strncmp(const char *s1, const char *s2,<br />
size_t n);<br />
Arguments: s1 first string<br />
Trong ví dụ thứ hai, 18 ký tự thay thế 18 ký tự đầu tiên của<br />
buf1and phần còn lại vẫn còn ký tự null.<br />
Trong ví dụ thứ ba, 5 nhân vật của buf3 ("Tại sao?" Cộng với một null<br />
chấm dứt ký tự) thay thế 5 ký tự đầu tiên của buf1. buf1now<br />
thực sự có ("Tại sao?", 1 nhân vật vô giá trị, "được thời gian?", 32 rỗng
s2 second string<br />
n number of characters to compare<br />
Return Value: Returns a positive number if s1is greater than s2, zero if s1is<br />
equal to<br />
s2, or a negative number if s1is less than s2.<br />
Remarks: strncmpreturns a value based on the first character that differs<br />
between s1and s2. Characters that follow a null character are not<br />
compared.<br />
Example: #include /* for strncmp */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
char buf1[50] = "Where is the time?";<br />
char buf2[50] = "Where did they go?";<br />
char buf3[50] = "Why?";<br />
int res;<br />
printf("buf1 : %s\n", buf1);<br />
printf("buf2 : %s\n", buf2);<br />
printf("buf3 : %s\n\n", buf3);<br />
res = strncmp(buf1, buf2, 6);<br />
if (res < 0)<br />
printf("buf1 comes before buf2\n");<br />
else if (res == 0)<br />
printf("6 charactersof buf1 and buf2 "<br />
"are equal\n");<br />
else<br />
printf("buf2 comes before buf1\n");<br />
printf("\n");<br />
res = strncmp(buf1, buf2, 20);<br />
if (res < 0)<br />
printf("buf1 comes before buf2\n");<br />
else if (res == 0)<br />
printf("20 characters of buf1 and buf2 "<br />
"are equal\n");<br />
else<br />
printf("buf2 comes before buf1\n");<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 309<br />
printf("\n");<br />
ký tự). strlenshows 4 nhân vật vì nó dừng lại khi nó<br />
đạt các ký tự null đầu tiên.<br />
Trong ví dụ thứ tư, kể từ khi buf4is chỉ có 7 nhân vật strncpyuses 2<br />
ký tự null bổ sung thay thế 9 ký tự đầu tiên của buf1. Các<br />
kết quả của buf1is 6 ký tự ("Ở đâu?") tiếp theo là 3 ký tự null,<br />
tiếp theo là 9 ký tự ("thời gian?"), tiếp theo là 32 ký tự null.<br />
strpbrk<br />
Mô tả: Tìm kiếm một chuỗi cho sự xuất hiện đầu tiên của một nhân vật từ một<br />
quy định<br />
tập hợp các ký tự.<br />
Bao gồm:<br />
Prototype: char * strpbrk (const char * s1, const char * s2);<br />
Đối số: con trỏ s1 vào chuỗi cần tìm kiếm<br />
s2 con trỏ đến ký tự để tìm kiếm<br />
Quay trở lại giá trị: Trả về một con trỏ đến các nhân vật xuất hiện trong s1if tìm<br />
thấy; nếu không,<br />
trả về một con trỏ null.<br />
Bình luận: Chức năng này sẽ tìm kiếm s1for sự xuất hiện đầu tiên của một nhân<br />
vật<br />
chứa trong s2.<br />
Ví dụ: # include / * Cho strpbrk, NULL * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
char str1 [20] = "Bây giờ là mấy?";<br />
char str2 [20] = "xyz";<br />
char str3 [20] = "EOU?";<br />
char * ptr;<br />
res int;<br />
printf ("strpbrk (\"% s \ ", \"% s \ ") \ n", str1, str2);<br />
ptr = strpbrk (str1, str2);<br />
if (ptr! = NULL)<br />
{<br />
res = ptr - str1 + 1;<br />
printf ("phù hợp với vị trí foundat% d \ n", độ phân giải);<br />
}<br />
khác<br />
printf ("phù hợp không tìm thấy \ n");<br />
strncpy (Tiếp theo)<br />
dsPIC<br />
®
es = strncmp(buf1, buf3, 20);<br />
if (res < 0)<br />
printf("buf1 comes before buf3\n");<br />
else if (res == 0)<br />
printf("20 characters of buf1 and buf3 "<br />
"are equal\n");<br />
else<br />
printf("buf3 comes before buf1\n");<br />
}<br />
Output:<br />
buf1 : Where is the time?<br />
buf2 : Where did they go?<br />
buf3 : Why?<br />
6 characters of buf1 and buf2 are equal<br />
buf2 comes before buf1<br />
buf1 comes before buf3<br />
strncpy<br />
Description: Copy characters from the source string into the destination string,<br />
up to<br />
the specified number of characters.<br />
Include: <br />
Prototype: char *strncpy(char *s1, const char *s2, size_t n);<br />
Arguments: s1 destination string to copy to<br />
s2 source string to copy from<br />
n number of characters to copy<br />
Return Value: Returns a pointer to the destination string.<br />
Remarks: Copies ncharacters from the source string to the destination string. If<br />
the source string is less than ncharacters, the destination is filled with<br />
null characters to total ncharacters. If ncharacters were copied and no<br />
null character was found then the destination string will not be<br />
null-terminated. If the strings overlap, the behavior is undefined.<br />
Example: #include /* forstrncpy, strlen */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
char buf1[50] = "We're here";<br />
char buf2[50] = "Where is the time?";<br />
char buf3[50] = "Why?";<br />
char buf4[7] = "Where?";<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 312<br />
printf ("\ n");<br />
2004 Microchip Technology Inc<br />
printf ("strpbrk (\"% s \ ", \"% s \ ") \ n", str1, str3);<br />
ptr = strpbrk (str1, str3);<br />
if (ptr! = NULL)<br />
{<br />
res = ptr - str1 + 1;<br />
printf ("phù hợp với tìm thấy ở vị trí% d \ n", độ phân giải);<br />
}<br />
khác<br />
printf ("matchnot tìm thấy \ n");<br />
}<br />
Đầu ra:<br />
strpbrk ("thời gian gì isit?", "xyz")<br />
phù hợp không tìm thấy<br />
strpbrk ("thời gian gì isit?", "EOU?")<br />
phù hợp với tìm thấy ở vị trí 9<br />
strrchr<br />
Mô tả: Tìm kiếm sự xuất hiện cuối cùng của một nhân vật được quy định trong<br />
một chuỗi.<br />
Bao gồm:<br />
Prototype: char * strrchr (const char * s, int c);<br />
Đối số: s con trỏ đến chuỗi cần tìm kiếm<br />
c nhân vật để tìm kiếm<br />
Quay trở lại giá trị: Trả về một con trỏ tới các nhân vật nếu tìm thấy; nếu không<br />
trả về một null<br />
con trỏ.<br />
Ghi chú: Chức năng tìm kiếm chuỗi, bao gồm cả việc chấm dứt vô<br />
nhân vật, để tìm sự xuất hiện cuối cùng của nhân vật c.<br />
Ví dụ: # include / * Cho strrchr, NULL * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
char buf1 [50] = "Bây giờ là mấy?";<br />
char ch1 = 'm', CH2 = 'y';<br />
char * ptr;<br />
res int;<br />
printf ("buf1:% s \ n \ n", buf1);<br />
ptr = strrchr (buf1, ch1);
printf("buf1 : %s\n", buf1);<br />
printf("buf2 : %s\n", buf2);<br />
printf("buf3 : %s\n", buf3);<br />
printf("buf4 : %s\n", buf4);<br />
strncmp (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 310 2004 Microchip Technology Inc.<br />
strncpy(buf1, buf2, 6);<br />
printf("buf1 after strncpy of 6 characters "<br />
"of buf2: \n\t%s\n", buf1);<br />
printf("\t( %d characters)\n", strlen(buf1));<br />
printf("\n");<br />
strncpy(buf1, buf2, 18);<br />
printf("buf1 after strncpy of 18 characters "<br />
"of buf2: \n\t%s\n", buf1);<br />
printf("\t( %d characters)\n", strlen(buf1));<br />
printf("\n");<br />
strncpy(buf1, buf3, 5);<br />
printf("buf1 after strncpy of 5 characters "<br />
"of buf3: \n\t%s\n", buf1);<br />
printf("\t( %d characters)\n", strlen(buf1));<br />
printf("\n");<br />
strncpy(buf1, buf4, 9);<br />
printf("buf1 after strncpy of 9 characters "<br />
"of buf4: \n\t%s\n", buf1);<br />
printf("\t( %d characters)\n", strlen(buf1));<br />
}<br />
Output:<br />
buf1 : We're here<br />
buf2 : Where is the time?<br />
buf3 : Why?<br />
buf4 : Where?<br />
buf1 after strncpy of 6 characters of buf2:<br />
Where here<br />
( 10 characters)<br />
buf1 after strncpy of 18characters of buf2:<br />
Where is the time?<br />
if (ptr! = NULL)<br />
{<br />
res = ptr - buf1 1;<br />
printf ("% c tìm thấy ở vị trí% d \ n", ch1, độ phân giải);<br />
}<br />
khác<br />
printf ("% c không tìm thấy \ n", ch1);<br />
strpbrk (Tiếp theo)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 313<br />
printf ("\ n");<br />
ptr = strrchr (buf1, CH2);<br />
if (ptr! = NULL)<br />
{<br />
res = ptr - buf1 1;<br />
printf ("% c tìm thấy atposition% d \ n", CH2, độ phân giải);<br />
}<br />
khác<br />
printf ("% c không tìm thấy \ n", CH2);<br />
}<br />
Đầu ra:<br />
buf1: Bây giờ là mấy?<br />
m tìm thấy ở vị trí 8<br />
y không tìm thấy<br />
strspn<br />
Mô tả: Tính toán số lượng các ký tự liên tiếp vào đầu của một<br />
chuỗi được chứa trong một tập hợp các ký tự.<br />
Bao gồm:<br />
Prototype: strspn size_t (const char * s1, const char * s2);<br />
Đối số: con trỏ s1 vào chuỗi cần tìm kiếm<br />
s2 con trỏ đến ký tự để tìm kiếm<br />
Quay trở lại giá trị: Trả về số ký tự liên tiếp từ đầu s1<br />
được chứa trong s2.<br />
Ghi chú: Chức năng này ngừng tìm kiếm khi một nhân vật s1is không s2.<br />
Ví dụ: # include / * Cho strspn * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
char str1 [20] = "động vật";
( 18 characters)<br />
buf1 after strncpy of 5 characters of buf3:<br />
Why?<br />
( 4 characters)<br />
buf1 after strncpy of 9 characters of buf4:<br />
Where?<br />
( 6 characters)<br />
strncpy (Continued)<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 311<br />
Explanation:<br />
Each buffer contains the string shown,followed by null characters for a<br />
length of 50. Using strlenwill find the length of the string up to but not<br />
including the first null character.<br />
In the first example, 6 characters of buf2(“Where “) replace the first 6<br />
characters of buf1("We're ") and the rest of buf1remains the same<br />
("here" plus null characters).<br />
In the second example, 18 characters replace the first 18 characters of<br />
buf1and the rest remain null characters.<br />
In the third example, 5 characters of buf3("Why?" plus a null<br />
terminating character) replace the first 5 characters of buf1. buf1now<br />
actually contains ("Why?", 1 null character, " is the time?", 32 null<br />
characters). strlenshows 4 characters because it stops when it<br />
reaches the first null character.<br />
In the fourth example, since buf4is only 7 characters strncpyuses 2<br />
additional null characters to replace the first 9 characters of buf1. The<br />
result of buf1is 6 characters ("Where?") followed by 3 null characters,<br />
followed by 9 characters ("the time?"), followed by 32 null characters.<br />
strpbrk<br />
Description: Search a string for the first occurrence of a character from a<br />
specified<br />
set of characters.<br />
Include: <br />
Prototype: char *strpbrk(const char *s1, const char *s2);<br />
Arguments: s1 pointer to the string to be searched<br />
s2 pointer to characters to search for<br />
Return Value: Returns a pointer to the matched character in s1if found;<br />
otherwise,<br />
returns a null pointer.<br />
Remarks: This function will search s1for the first occurrence of a character<br />
char str2 [20] = "aeiounm";<br />
char str3 [20] = "aimnl";<br />
char str4 [20] = "xyz";<br />
res int;<br />
res = strspn (str1, str2);<br />
printf ("strspn (\"% s \ ", \"% s \ ") =% d \ n",<br />
str1, str2, độ phân giải);<br />
res = strspn (str1, str3);<br />
printf ("strspn (\"% s \ ", \"% s \ ") =% d \ n",<br />
str1, str3, độ phân giải);<br />
res = strspn (str1, str4);<br />
printf ("strspn (\"% s \ ", \"% s \ ") =% d \ n",<br />
str1, str4, độ phân giải);<br />
}<br />
strrchr (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 314<br />
Đầu ra:<br />
strspn ("động vật", "aeiounm") = 5<br />
strspn ("động vật", "aimnl") = 6<br />
strspn ("động vật", "xyz") = 0<br />
Giải thích:<br />
Trong kết quả đầu tiên, lis không s2.<br />
2004 Microchip Technology Inc<br />
Trong kết quả thứ hai, chấm dứt rỗng không có trong s2.<br />
Trong kết quả thứ ba, ais không s2, vì vậy việc so sánh dừng lại.<br />
strstr<br />
Mô tả: Tìm kiếm chuỗi xảy ra ofa đầu tiên trong chuỗi khác.<br />
Bao gồm:<br />
Prototype: char * strstr (const char * s1, const char * s2);<br />
Đối số: con trỏ s1 vào chuỗi cần tìm kiếm<br />
s2 con trỏ đến chuỗi cần tìm kiếm<br />
Quay trở lại giá trị: Trả về địa chỉ của phần tử đầu tiên phù hợp với chuỗi nếu<br />
tìm thấy; nếu không, trả về một con trỏ null.<br />
Ghi chú: Chức năng này sẽ tìm thấy sự xuất hiện đầu tiên của chuỗi s2 (không<br />
bao gồm các<br />
vô terminator) trong chuỗi s1. Nếu s2points một chuỗi số không dài,<br />
s1is trả lại.<br />
Ví dụ: # include / * Cho strstr, NULL * /
contained in s2.<br />
Example: #include /* for strpbrk, NULL */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
char str1[20] = "What time is it?";<br />
char str2[20] = "xyz";<br />
char str3[20] = "eou?";<br />
char *ptr;<br />
int res;<br />
printf("strpbrk(\"%s\", \"%s\")\n", str1, str2);<br />
ptr = strpbrk(str1, str2);<br />
if (ptr != NULL)<br />
{<br />
res = ptr - str1 + 1;<br />
printf("match foundat position %d\n", res);<br />
}<br />
else<br />
printf("match not found\n");<br />
strncpy (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 312 2004 Microchip Technology Inc.<br />
printf("\n");<br />
printf("strpbrk(\"%s\", \"%s\")\n", str1, str3);<br />
ptr = strpbrk(str1, str3);<br />
if (ptr != NULL)<br />
{<br />
res = ptr - str1 + 1;<br />
printf("match found at position %d\n", res);<br />
}<br />
else<br />
printf("matchnot found\n");<br />
}<br />
Output:<br />
strpbrk("What time isit?", "xyz")<br />
match not found<br />
strpbrk("What time isit?", "eou?")<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
char str1 [20] = "Bây giờ là mấy?";<br />
char str2 [20] = "là";<br />
char str3 [20] = "xyz";<br />
char * ptr;<br />
res int;<br />
printf ("str1:% s \ n", str1);<br />
printf ("str2:% s \ n", str2);<br />
printf ("str3:% s \ n \ n", str3);<br />
ptr = strstr (str1, str2);<br />
if (ptr! = NULL)<br />
{<br />
res = ptr - str1 + 1;<br />
printf ("\"% s \ "được tìm thấy ở vị trí% d \ n",<br />
str2, độ phân giải);<br />
}<br />
khác<br />
printf ("\"% s \ "không tìm thấy \ n", str2);<br />
strspn (Tiếp theo)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 315<br />
printf ("\ n");<br />
ptr = strstr (str1, str3);<br />
if (ptr! = NULL)<br />
{<br />
res = ptr - str1 + 1;<br />
printf ("\"% s \ "được tìm thấy ở vị trí% d \ n",<br />
str3, độ phân giải);<br />
}<br />
khác<br />
printf ("\"% s \ "không tìm thấy \ n", str3);<br />
}<br />
Đầu ra:<br />
str1: Bây giờ là mấy?<br />
str2: là<br />
str3: xyz<br />
"Được" tìm thấy ở vị trí 11
match found at position 9<br />
strrchr<br />
Description: Search for the last occurrence of a specified character in a string.<br />
Include: <br />
Prototype: char *strrchr(const char *s, int c);<br />
Arguments: s pointer to the string to be searched<br />
c character to search for<br />
Return Value: Returns a pointer to the character if found; otherwise, returns a<br />
null<br />
pointer.<br />
Remarks: The function searches the string s, including the terminating null<br />
character, to find the last occurrence of character c.<br />
Example: #include /* for strrchr, NULL */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
char buf1[50] = "What time is it?";<br />
char ch1 = 'm', ch2 = 'y';<br />
char *ptr;<br />
int res;<br />
printf("buf1 : %s\n\n", buf1);<br />
ptr = strrchr(buf1, ch1);<br />
if (ptr != NULL)<br />
{<br />
res = ptr - buf1 + 1;<br />
printf("%c found at position %d\n", ch1, res);<br />
}<br />
else<br />
printf("%c not found\n", ch1);<br />
strpbrk (Continued)<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 313<br />
printf("\n");<br />
ptr = strrchr(buf1, ch2);<br />
if (ptr != NULL)<br />
{<br />
res = ptr - buf1 + 1;<br />
"Xyz" không tìm thấy<br />
strtok<br />
Mô tả: Phá vỡ một chuỗi thành chuỗi con, hoặc thẻ, bằng cách chèn các ký tự<br />
null ở<br />
nơi phân cách quy định.<br />
Bao gồm:<br />
Prototype: char * strtok (char * s1, const char * s2);<br />
Đối số: con trỏ s1 vào chuỗi kết thúc để được tìm kiếm<br />
s2 con trỏ tới ký tự cần tìm kiếm (sử dụng như là ký tự phân cách)<br />
Quay trở lại giá trị: Trả về một con trỏ đến ký tự đầu tiên của một mã thông báo<br />
(ký tự đầu tiên trong<br />
s1that không xuất hiện trong tập hợp các ký tự của s2). Nếu không có dấu hiệu<br />
là<br />
tìm thấy, con trỏ null được trả về.<br />
Bình luận: Một chuỗi các cuộc gọi đến các chức năng này có thể được sử dụng<br />
để tách một chuỗi thành<br />
chuỗi con (hoặc thẻ) bằng cách thay thế các ký tự quy định với null<br />
ký tự. Lần đầu tiên chức năng này được gọi vào một chuỗi ký tự,<br />
chuỗi cần được thông qua trong s1. Sau lần đầu tiên, chức năng này có thể<br />
tiếp tục phân tích các chuỗi từ dấu phân cách cuối cùng bằng cách gọi nó với<br />
một<br />
giá trị null được thông qua trong s1.<br />
Nó bỏ qua tất cả nhân vật chính xuất hiện trong chuỗi s2 (ký tự phân cách),<br />
sau đó bỏ qua tất cả các nhân vật không xuất hiện trong s2 (phân khúc này của<br />
nhân vật là các mã thông báo), và sau đó ghi đè các ký tự tiếp theo với một<br />
nhân vật vô giá trị, chấm dứt các mã thông báo hiện hành. Chức năng strtokthen<br />
tiết kiệm một con trỏ tới ký tự sau đó, từ đó tiếp theo<br />
tìm kiếm sẽ bắt đầu. Nếu strtokfinds sự kết thúc của chuỗi trước khi nó tìm thấy<br />
một<br />
dấu phân cách, các mã thông báo hiện tại kéo dài cuối tothe của chuỗi chỉ ra<br />
bởi s1. Nếu đây là cuộc gọi đầu tiên strtok, nó không sửa đổi các chuỗi (không<br />
ký tự null được ghi vào s1). Tập hợp các ký tự được thông qua<br />
trong s2need không phải là samefor mỗi cuộc gọi đến strtok.<br />
Nếu strtokis gọi với một tham số có giá trị cho s1after cuộc gọi ban đầu,<br />
chuỗi thành chuỗi tosearch mới. Chuỗi cũ trước đây<br />
tìm kiếm sẽ bị mất.<br />
strstr (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
printf("%c found atposition %d\n", ch2, res);<br />
DS51456B trang 316<br />
2004 Microchip Technology Inc<br />
}<br />
Ví dụ: # include / * Cho strtok, NULL * /
else<br />
printf("%c not found\n", ch2);<br />
}<br />
Output:<br />
buf1 : What time is it?<br />
m found at position 8<br />
y not found<br />
strspn<br />
Description: Calculate the number of consecutive characters at the beginning of<br />
a<br />
string that are contained in a set of characters.<br />
Include: <br />
Prototype: size_t strspn(const char *s1, const char *s2);<br />
Arguments: s1 pointer to the string to be searched<br />
s2 pointer to characters to search for<br />
Return Value: Returns the number of consecutive characters from the beginning<br />
of s1<br />
that are contained in s2.<br />
Remarks: This function stops searching when a character from s1is not in s2.<br />
Example: #include /* for strspn */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
char str1[20] = "animal";<br />
char str2[20] = "aeiounm";<br />
char str3[20] = "aimnl";<br />
char str4[20] = "xyz";<br />
int res;<br />
res = strspn(str1, str2);<br />
printf("strspn(\"%s\", \"%s\") = %d\n",<br />
str1, str2, res);<br />
res = strspn(str1, str3);<br />
printf("strspn(\"%s\", \"%s\") = %d\n",<br />
str1, str3, res);<br />
res = strspn(str1, str4);<br />
printf("strspn(\"%s\", \"%s\") = %d\n",<br />
str1, str4, res);<br />
}<br />
strrchr (Continued)<br />
dsPIC<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
char str1 [30] = "Ở đây, ontop của thế giới!";<br />
char DELIM làm phân cách [5] = ",.";<br />
char * từ;<br />
int x;<br />
printf ("str1:% s \ n", str1);<br />
x = 1;<br />
từ = strtok (str1, DELIM làm phân cách);<br />
trong khi (từ! = NULL)<br />
{<br />
printf ("từ% d:% s \ n", x ++, văn bản);<br />
từ = strtok (NULL, DELIM làm phân cách);<br />
}<br />
}<br />
Đầu ra:<br />
str1: Ở đây, trên đỉnh của thế giới!<br />
từ 1: Ở đây<br />
từ 2: trên<br />
từ 3: đầu<br />
từ 4: của<br />
từ 5:<br />
từ 6: thế giới!<br />
strxfrm<br />
Mô tả: Transforms một chuỗi bằng cách sử dụng quy tắc địa phương phụ thuộc<br />
vào. (Xem chú thích.)<br />
Bao gồm:<br />
Prototype: strxfrm size_t (char * s1, const char * s2, size_t n);<br />
Đối số: s1 chuỗi điểm đến<br />
chuỗi nguồn s2 được chuyển đổi<br />
số n ký tự để chuyển đổi<br />
Quay trở lại giá trị: Trả về chiều dài của chuỗi biến đổi không bao gồm<br />
chấm dứt ký tự null. Nếu nis hết, những chuỗi không được chuyển đổi (s1<br />
có thể là một điểm vô giá trị trong trường hợp này) và chiều dài của s2is trả lại.<br />
Ghi chú: Nếu giá trị trả về là lớn hơn hoặc bằng n, nội dung của s1is<br />
không xác định. Kể từ MPLAB C30 doesnot miền địa phương hỗ trợ thay thế,<br />
việc chuyển đổi tương đương với strcpy, ngoại trừ chiều dài của<br />
chuỗi điểm đến được giới hạn bởi n-1.<br />
strtok (Tiếp theo)
®<br />
Language Tools Libraries<br />
DS51456B-page 314<br />
Output:<br />
strspn("animal", "aeiounm") = 5<br />
strspn("animal", "aimnl") = 6<br />
strspn("animal", "xyz") = 0<br />
Explanation:<br />
In the first result, lis not in s2.<br />
2004 Microchip Technology Inc.<br />
In the second result, the terminating null is not in s2.<br />
In the third result, ais not in s2, so the comparison stops.<br />
strstr<br />
Description: Search for the first occurrence ofa string inside another string.<br />
Include: <br />
Prototype: char *strstr(const char *s1, const char *s2);<br />
Arguments: s1 pointer to the string to be searched<br />
s2 pointer to substring to be searched for<br />
Return Value: Returns the address of the first element that matches the substring<br />
if<br />
found; otherwise, returns a null pointer.<br />
Remarks: This function will find the first occurrence of the string s2(excluding<br />
the<br />
null terminator) within the string s1. If s2points to a zero length string,<br />
s1is returned.<br />
Example: #include /* for strstr, NULL */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
char str1[20] = "What time is it?";<br />
char str2[20] = "is";<br />
char str3[20] = "xyz";<br />
char *ptr;<br />
int res;<br />
printf("str1 : %s\n", str1);<br />
printf("str2 : %s\n", str2);<br />
printf("str3 : %s\n\n", str3);<br />
ptr = strstr(str1, str2);<br />
if (ptr != NULL)<br />
{<br />
res = ptr - str1 + 1;<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 317<br />
4.16 Ngày giờ CHỨC NĂNG<br />
Các time.hconsists tập tin tiêu đề của các loại, macro và chức năng điều khiển<br />
thời gian.<br />
clock_t<br />
Mô tả: Cửa hàng xử lý thời gian giá trị.<br />
Bao gồm:<br />
Prototype: typedef clock_t dài<br />
size_t<br />
Mô tả: Các loại kết quả của sizeofoperator.<br />
Bao gồm:<br />
struct tm<br />
Mô tả: Cơ cấu sử dụng để giữ thời gian và ngày (thời gian lịch).<br />
Bao gồm:<br />
Nguyên mẫu: struct tm {<br />
int tm_sec; / * Giây sau khi phút (0-61) * /<br />
/ * Cho phép đến hai giây nhuận * /<br />
int tm_min; / * Phút sau khi giờ (0-59) * /<br />
int tm_hour; / * Giờ kể từ nửa đêm (0-23) * /<br />
int tm_mday; / * Ngày trong tháng (1-31) * /<br />
int tm_mon; / * Tháng (0-11 tháng một nơi = 0) * /<br />
int tm_year; / * Năm kể từ năm 1900 * /<br />
int tm_wday; / * Ngày trong tuần (0-6 nơi chủ nhật = 0) * /<br />
int tm_yday; / * Ngày trong năm (0-365 nơi 01 tháng 1 = 0) * /<br />
int tm_isdst; / * Daylight Savings Time cờ * /<br />
}<br />
Ghi chú: Nếu tm_isdst isa giá trị tích cực, ánh sáng ban ngày tiết kiệm có hiệu<br />
lực. Nếu đó là<br />
thời gian không, tiết kiệm ánh sáng không có hiệu lực. Nếu đó là một giá trị âm<br />
tình trạng của Daylight Saving Time không được biết đến.<br />
time_t<br />
Mô tả: Đại diện cho các giá trị thời gian lịch.<br />
Bao gồm:<br />
Prototype: typedef time_t dài<br />
CLOCKS_PER_SEC<br />
Mô tả: Số đồng hồ xử lý mỗi giây.<br />
Bao gồm:<br />
Prototype: # define CLOCKS_PER_SEC<br />
Giá trị: 1<br />
Bình luận: MPLAB C30 trả về bọ ve đồng hồ (chu kỳ hướng dẫn) không phải
printf("\"%s\" found at position %d\n",<br />
str2, res);<br />
}<br />
else<br />
printf("\"%s\" not found\n", str2);<br />
strspn (Continued)<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 315<br />
printf("\n");<br />
ptr = strstr(str1, str3);<br />
if (ptr != NULL)<br />
{<br />
res = ptr - str1 + 1;<br />
printf("\"%s\" found at position %d\n",<br />
str3, res);<br />
}<br />
else<br />
printf("\"%s\" not found\n", str3);<br />
}<br />
Output:<br />
str1 : What time is it?<br />
str2 : is<br />
str3 : xyz<br />
"is" found at position 11<br />
"xyz" not found<br />
strtok<br />
Description: Break a string into substrings, or tokens, by inserting null<br />
characters in<br />
place of specified delimiters.<br />
Include: <br />
Prototype: char *strtok(char *s1, const char *s2);<br />
Arguments: s1 pointer to the null terminated string to be searched<br />
s2 pointer to characters to be searched for (used as delimiters)<br />
Return Value: Returns a pointer to the first character of a token (the first<br />
character in<br />
s1that does not appear in the set of characters of s2). If no token is<br />
found, the null pointer is returned.<br />
Remarks: A sequence of calls to this function can be used to split up a string<br />
into<br />
substrings (or tokens) by replacing specified characters with null<br />
thời gian thực tế.<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 318 2004 Microchip Technology Inc<br />
NULL<br />
Mô tả: Giá trị của một con trỏ hằng null.<br />
Bao gồm:<br />
asctime<br />
Mô tả: Chuyển đổi cơ cấu thời gian để một chuỗi ký tự.<br />
Bao gồm:<br />
Prototype: char * asctime (const struct tm * tptr);<br />
Đối số: tptr lần / ngày cấu trúc<br />
Quay trở lại giá trị: Trả về một con trỏ đến một chuỗi ký tự định dạng sau:<br />
DDD MMM dd hh: mm: ss YYYY<br />
DDDis ngày trong tuần<br />
MMMis tháng trong năm<br />
ddis ngày của tháng<br />
hhis giờ<br />
phút mmis<br />
SSIS thứ hai<br />
YYYYis năm<br />
Ví dụ: # include / * Cho asctime, tm * /<br />
# include / * Cho printf * /<br />
dễ bay hơi int i;<br />
int main (void)<br />
{<br />
struct tm khi;<br />
whattime time_t;<br />
when.tm_sec = 30;<br />
when.tm_min = 30;<br />
when.tm_hour = 2;<br />
when.tm_mday = 1;<br />
when.tm_mon = 1;<br />
when.tm_year = 103;<br />
whattime = mktime (và khi nào);<br />
printf ("Ngày và thời gian là% s \ n", asctime (và khi nào));<br />
}<br />
Đầu ra:
characters. The first time this function is invoked on a particular string,<br />
that string should be passed in s1. After the first time, this function can<br />
continue parsing the string from the last delimiter by invoking it with a<br />
null value passed in s1.<br />
It skips all leading characters that appear in the string s2(delimiters),<br />
then skips all characters not appearing in s2(this segment of<br />
characters is the token), and then overwrites the next character with a<br />
null character, terminating the current token. The function strtokthen<br />
saves a pointer to the character that follows,from which the next<br />
search will start. If strtokfinds the end of the string before it finds a<br />
delimiter, the current token extends tothe end of the string pointed to<br />
by s1. If this is the first call to strtok, it does not modify the string (no<br />
null characters are written to s1). The set of characters that is passed<br />
in s2need not be the samefor each call to strtok.<br />
If strtokis called with a non-null parameter for s1after the initial call,<br />
the string becomes the new string tosearch. The old string previously<br />
searched will be lost.<br />
strstr (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
Ngày và thời gian là Sat 01 tháng 2 năm 2003 02:30:30<br />
đồng hồ<br />
Mô tả: Tính toán thời gian xử lý.<br />
Bao gồm:<br />
Prototype: đồng hồ clock_t (void);<br />
Quay trở lại giá trị: Trả về số của đồng hồ bọ ve thời gian xử lý trôi qua.<br />
Ghi chú: Nếu môi trường mục tiêu không thể đo lường thời gian xử lý trôi qua,<br />
các<br />
chức năng trả về -1, vào vai một clock_t. (Tức là (clock_t) -1) Theo mặc định,<br />
MPLAB C30 trả về thời gian là chu kỳ hướng dẫn.<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 319<br />
Ví dụ: # include / * Cho đồng hồ * /<br />
# include / * Cho printf * /<br />
dễ bay hơi int i;<br />
int main (void)<br />
{<br />
clock_t bắt đầu, dừng lại;<br />
int ct;<br />
bắt đầu = đồng hồ ();<br />
for (i = 0; i
Output:<br />
str1 : Here, on top of the world!<br />
word 1: Here<br />
word 2: on<br />
word 3: top<br />
word 4: of<br />
word 5: the<br />
word 6: world!<br />
strxfrm<br />
Description: Transforms a string using the locale-dependent rules. (See<br />
Remarks.)<br />
Include: <br />
Prototype: size_t strxfrm(char *s1, const char *s2, size_t n);<br />
Arguments: s1 destination string<br />
s2 source string to be transformed<br />
n number of characters to transform<br />
Return Value: Returns the length of the transformed string not including the<br />
terminating null character. If nis zero, the string is not transformed (s1<br />
{<br />
whattime time_t;<br />
struct tm nowtime;<br />
nowtime.tm_sec = 30;<br />
nowtime.tm_min = 30;<br />
nowtime.tm_hour = 2;<br />
nowtime.tm_mday = 1;<br />
nowtime.tm_mon = 1;<br />
nowtime.tm_year = 103;<br />
whattime = mktime (& nowtime);<br />
printf ("Ngày và thời gian% s \ n", ctime (& whattime));<br />
}<br />
Đầu ra:<br />
Ngày và thời gian Sat Feb1 2003 02:30:30<br />
đồng hồ (tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
may be a point null in this case) and the length of s2is returned.<br />
Remarks: If the return value is greater than or equal to n, the content of s1is<br />
DS51456B trang 320<br />
difftime<br />
2004 Microchip Technology Inc<br />
indeterminate. Since MPLAB C30 doesnot support alternate locales,<br />
the transformation is equivalent to strcpy, except that the length of<br />
the destination string is bounded by n-1.<br />
strtok (Continued)<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 317<br />
4.16 DATE AND TIME FUNCTIONS<br />
The header file time.hconsists of types, macros and functions that manipulate<br />
time.<br />
clock_t<br />
Description: Stores processor time values.<br />
Include: <br />
Prototype: typedef long clock_t<br />
size_t<br />
Description: The type of the result of the sizeofoperator.<br />
Include: <br />
struct tm<br />
Description: Structure used to hold the time and date (calendar time).<br />
Include: <br />
Prototype: struct tm {<br />
Mô tả: Tìm sự khác biệt giữa hai lần.<br />
Bao gồm:<br />
Prototype: difftime đôi (time_t t1, t0 time_t);<br />
Đối số: t1 kết thúc thời gian<br />
t0 thời gian bắt đầu<br />
Quay trở lại giá trị: Trả về số giây giữa t1and t0.<br />
Ghi chú: Theo mặc định, MPLAB C30 trả về thời gian là chu kỳ hướng dẫn để<br />
difftimereturns số lượng bọ ve giữa t1and t0.<br />
Ví dụ: # include / * Cho đồng hồ, difftime * /<br />
# include / * Cho printf * /<br />
dễ bay hơi int i;<br />
int main (void)<br />
{<br />
clock_t bắt đầu, dừng lại;<br />
đôi trôi qua;<br />
bắt đầu = đồng hồ ();<br />
for (i = 0; i
int tm_sec; /*seconds after the minute ( 0 to 61 ) */<br />
/* allows for up to two leap seconds */<br />
int tm_min; /* minutes after the hour ( 0 to 59 ) */<br />
int tm_hour; /* hours since midnight ( 0 to 23 ) */<br />
int tm_mday; /* day of month ( 1 to 31 ) */<br />
int tm_mon; /* month ( 0 to 11 where January = 0 ) */<br />
int tm_year; /* years since 1900 */<br />
int tm_wday; /* day of week ( 0 to 6 where Sunday = 0 ) */<br />
int tm_yday; /* day of year ( 0 to 365 where January 1 = 0 ) */<br />
int tm_isdst; /* Daylight Savings Time flag */<br />
}<br />
Remarks: If tm_isdst isa positive value, Daylight Savings is in effect. If it is<br />
zero, Daylight Saving time is not in effect. If it is a negative value, the<br />
status of Daylight Saving Time is not known.<br />
time_t<br />
Description: Represents calendar time values.<br />
Include: <br />
Prototype: typedef long time_t<br />
CLOCKS_PER_SEC<br />
Description: Number of processor clocks per second.<br />
Include: <br />
Prototype: #define CLOCKS_PER_SEC<br />
Value: 1<br />
Remarks: MPLAB C30 returns clock ticks (instruction cycles) not actual time.<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
printf ("stop =% ld \ n", dừng lại);<br />
trôi qua = difftime (dừng lại, bắt đầu);<br />
printf ("Thời gian đã qua =% .0f \ n", trôi qua);<br />
}<br />
Đầu ra:<br />
bắt đầu = 0<br />
ngăn chặn = 317<br />
Thời gian đã qua = 317<br />
gmtime<br />
Mô tả: Chuyển đổi lịch thời gian để cấu trúc thời gian thể hiện như Universal<br />
Time<br />
Phối hợp (UTC) còn được gọi asGreenwich Mean Time (GMT).<br />
Bao gồm:<br />
Nguyên mẫu: struct tm * gmtime (time_t * const tod);<br />
Đối số: con trỏ tod gian lưu trữ<br />
Quay trở lại giá trị: Trả về địa chỉ của cấu trúc thời gian.<br />
Ghi chú: Chức năng này phá vỡ todvalue vào cấu trúc thời gian của loại<br />
tm. Theo mặc định, MPLAB C30 trả về thời gian là chu kỳ hướng dẫn. Với<br />
gmtimeand mặc định này localtimewill tương đương trừ gmtime<br />
sẽ returntm_isdst (Daylight Savings Time cờ) là không để cho biết<br />
mà Daylight Savings Time không có hiệu lực.<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 321<br />
Ví dụ: # include / * Cho gmtime, asctime, * /<br />
/ * Time_t, tm * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
DS51456B-page 318<br />
NULL<br />
2004 Microchip Technology Inc.<br />
giờ time_t;<br />
struct tm * Newtime;<br />
Description: The value of a null pointer constant.<br />
Include: <br />
asctime<br />
Description: Converts the time structure to a character string.<br />
Include: <br />
Prototype: char *asctime(const struct tm *tptr);<br />
Argument: tptr time/date structure<br />
Return Value: Returns a pointer to a character string of the following format:<br />
DDD MMM dd hh:mm:ss YYYY<br />
DDDis day of the week<br />
timer = 1066668182; / * Thứ 16:43:02 ngày 20 tháng 10 năm 2003 * /<br />
Newtime = gmtime (và thời gian);<br />
printf ("UTC thời gian =% s \ n", asctime (Newtime));<br />
}<br />
Đầu ra:<br />
UTC thời gian = Thứ hai ngày 20 tháng 10 năm 2003 16:43:02<br />
localtime<br />
Mô tả: Chuyển đổi một giá trị thời gian địa phương.<br />
Bao gồm:<br />
Nguyên mẫu: struct tm * localtime (const time_t * tod);
MMMis month of the year<br />
ddis day of the month<br />
hhis hour<br />
mmis minute<br />
ssis second<br />
YYYYis year<br />
Example: #include /*for asctime, tm */<br />
#include /* for printf */<br />
volatile int i;<br />
int main(void)<br />
{<br />
struct tm when;<br />
time_t whattime;<br />
when.tm_sec = 30;<br />
when.tm_min = 30;<br />
when.tm_hour = 2;<br />
when.tm_mday = 1;<br />
when.tm_mon = 1;<br />
when.tm_year = 103;<br />
whattime = mktime(&when);<br />
printf("Day and time is %s\n", asctime(&when));<br />
}<br />
Output:<br />
Đối số: con trỏ tod gian lưu trữ<br />
Quay trở lại giá trị: Trả về địa chỉ cơ cấu thời gian.<br />
Ghi chú: Theo mặc định, MPLAB C30 trả về chu kỳ hướng dẫn timeas. Với<br />
điều này<br />
localtimeand mặc định gmtimewill tương đương trừ localtime<br />
sẽ trở lại tm_isdst (Daylight Savings Time cờ) là -1 để chỉ ra rằng<br />
tình trạng của Daylight Savings Time không được biết đến.<br />
Ví dụ: # include / * Cho localtime, * /<br />
/ * Asctime, time_t, tm * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
giờ time_t;<br />
struct tm * Newtime;<br />
timer = 1066668182; / * Thứ 16:43:02 ngày 20 tháng 10 năm 2003 * /<br />
Newtime = localtime (và thời gian);<br />
printf ("Giờ địa phương =% s \ n", asctime (Newtime));<br />
}<br />
Đầu ra:<br />
Giờ địa phương = Thứ Oct20 2003 16:43:02<br />
gmtime (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
Day and time is Sat Feb 1 02:30:30 2003<br />
clock<br />
DS51456B trang 322<br />
mktime<br />
2004 Microchip Technology Inc<br />
Description: Calculates the processor time.<br />
Include: <br />
Prototype: clock_t clock(void);<br />
Return Value: Returns the number of clock ticks of elapsed processor time.<br />
Remarks: If the target environment cannot measure elapsed processor time, the<br />
function returns -1, cast as a clock_t. (i.e. (clock_t) -1) By default,<br />
MPLAB C30 returns the time as instruction cycles.<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 319<br />
Example: #include /* for clock */<br />
#include /* for printf */<br />
volatile int i;<br />
int main(void)<br />
{<br />
Mô tả: Chuyển đổi giờ địa phương đến một giá trị lịch.<br />
Bao gồm:<br />
Prototype: time_t mktime (struct tm * tptr);<br />
Đối số: tptr một con trỏ đến cấu trúc thời gian<br />
Quay trở lại giá trị: Trả lại thời gian lịch được mã hóa như là một giá trị time_t.<br />
Ghi chú: Nếu thời gian lịch không thể được đại diện, chức năng trả về -1, diễn<br />
viên<br />
như một time_t (tức là (time_t) -1).<br />
Ví dụ: # include / * Cho localtime, * /<br />
/ * Asctime, mktime, * /<br />
/ * Time_t, tm * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{
clock_t start, stop;<br />
int ct;<br />
start = clock();<br />
for (i = 0; i < 10; i++)<br />
stop = clock();<br />
printf("start = %ld\n", start);<br />
printf("stop = %ld\n", stop);<br />
}<br />
Output:<br />
start = 0<br />
stop = 317<br />
ctime<br />
Description: Converts calendar time to a string representation of local time.<br />
Include: <br />
Prototype: char *ctime(const time_t *tod);<br />
Argument: tod pointer to stored time<br />
Return Value: Returns the address of a string thatrepresents the local time of the<br />
parameter passed.<br />
Remarks: This function is equivalent to asctime(localtime(tod)).<br />
Example: #include /* for mktime, tm, ctime */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
time_t whattime;<br />
struct tm nowtime;<br />
nowtime.tm_sec = 30;<br />
nowtime.tm_min = 30;<br />
nowtime.tm_hour = 2;<br />
nowtime.tm_mday = 1;<br />
nowtime.tm_mon = 1;<br />
nowtime.tm_year = 103;<br />
whattime = mktime(&nowtime);<br />
printf("Day and time %s\n", ctime(&whattime));<br />
}<br />
Output:<br />
Day and time Sat Feb1 02:30:30 2003<br />
clock (Continued)<br />
dsPIC<br />
®<br />
giờ time_t, whattime;<br />
struct tm * Newtime;<br />
timer = 1066668182; / * Thứ 16:43:02 ngày 20 tháng 10 năm 2003 * /<br />
/ * Localtime phân bổ không gian cho struct tm * /<br />
Newtime = localtime (và thời gian);<br />
printf ("Giờ địa phương =% s", asctime (Newtime));<br />
whattime = mktime (Newtime);<br />
printf ("thời gian Lịch như time_t =% ld \ n",<br />
whattime);<br />
}<br />
Đầu ra:<br />
Giờ địa phương = Thứ hai ngày 20 Tháng 10 2003 16:43:02<br />
Lịch thời gian như time_t = 1066668182<br />
strftime<br />
Mô tả: Định dạng cấu trúc thời gian để một chuỗi dựa trên các thông số định<br />
dạng.<br />
Bao gồm:<br />
Prototype: size_t strftime (char * s, size_t n,<br />
const char * format, const struct tm * tptr);<br />
Đối số: chuỗi soutput<br />
n chiều dài tối đa của chuỗi<br />
định dạng định dạng kiểm soát chuỗi<br />
tptr con trỏ đến cấu trúc dữ liệu tm<br />
Quay trở lại giá trị: Trả về số ký tự được đặt trong mảng s nếu tổng số<br />
bao gồm cả việc chấm dứt null là không lớn hơn n. Nếu không,<br />
chức năng trả về 0 và các nội dung của mảng sare không xác định.<br />
Ghi chú: Các thông số định dạng theo:<br />
% Một tên các ngày trong tuần viết tắt<br />
% A tên các ngày trong tuần đầy đủ<br />
% B tên tháng viết tắt<br />
% Name tháng đầy đủ B<br />
% C ngày thích hợp và đại diện thời gian<br />
% D ngày của tháng (01-31)<br />
% H giờ trong ngày (00-23)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 323<br />
% I giờ trong ngày (01-12)<br />
% J ngày trong năm (001-366)<br />
% M tháng trong năm (01-12)<br />
% M phút của giờ (00-59)
Language Tools Libraries<br />
DS51456B-page 320<br />
difftime<br />
2004 Microchip Technology Inc.<br />
Description: Find the difference between two times.<br />
Include: <br />
Prototype: double difftime(time_t t1, time_t t0);<br />
Arguments: t1 ending time<br />
t0 beginning time<br />
Return Value: Returns the number of seconds between t1and t0.<br />
Remarks: By default, MPLAB C30 returns the time as instruction cycles so<br />
difftimereturns the number of ticks between t1and t0.<br />
Example: #include /*for clock, difftime */<br />
#include /* for printf */<br />
volatile int i;<br />
int main(void)<br />
{<br />
clock_t start, stop;<br />
double elapsed;<br />
start = clock();<br />
for (i = 0; i < 10; i++)<br />
stop = clock();<br />
printf("start = %ld\n", start);<br />
printf("stop = %ld\n", stop);<br />
elapsed = difftime(stop, start);<br />
printf("Elapsed time = %.0f\n", elapsed);<br />
}<br />
Output:<br />
start = 0<br />
stop = 317<br />
Elapsed time = 317<br />
gmtime<br />
Description: Converts calendar time to time structure expressed as Universal<br />
Time<br />
Coordinated (UTC) also known asGreenwich Mean Time (GMT).<br />
Include: <br />
Prototype: struct tm *gmtime(const time_t *tod);<br />
Argument: tod pointer to stored time<br />
Return Value: Returns the address of the time structure.<br />
Remarks: This function breaks down the todvalue into the time structure of type<br />
% P AM / PM vấn thiết kế<br />
% S thứ hai của phút (00-61)<br />
cho phép đến hai giây nhuận<br />
% U số tuần của năm mà Chủ nhật là ngày đầu tiên của tuần 1<br />
(00-53)<br />
% W ngày trong tuần, nơi Chủ nhật là ngày 0 (0-6)<br />
% W số tuần trong năm, nơi thứ hai là ngày đầu tiên của tuần 1<br />
(00-53)<br />
% X đại diện ngày thích hợp<br />
% X đại diện thời điểm thích hợp<br />
% Năm y mà không cần thế kỷ (00-99)<br />
% Y năm với thế kỷ<br />
Khu% Z thời gian (có thể viết tắt) hoặc không có ký tự nếu múi giờ là<br />
không có sẵn<br />
%% Tính phần trăm%<br />
Ví dụ: # include / * Cho strftime, * /<br />
/ * Localtime, * /<br />
/ * Time_t, tm * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
giờ time_t, whattime;<br />
struct tm * Newtime;<br />
char buf [128];<br />
timer = 1066668182; / * Thứ 16:43:02 ngày 20 tháng 10 năm 2003 * /<br />
/ * Localtime phân bổ không gian cho cấu trúc * /<br />
Newtime = localtime (và thời gian);<br />
strftime (buf, 128, "Đó là một% A,% d ngày vào"<br />
". Tháng% B trong năm% Y \ n", Newtime);<br />
printf (buf);<br />
strftime (buf, 128, "Đó là tuần W% vào năm"<br />
"Hoặc jdays% vào năm \ n.", Newtime);<br />
printf (buf);<br />
}<br />
Đầu ra:<br />
Đó là một thứ hai, 20 ngày vào tháng Mười năm<br />
năm 2003.<br />
Đó là 42 tuần vào năm hoặc 293 ngày vào<br />
năm.
tm. By default, MPLAB C30 returns the time as instruction cycles. With<br />
this default gmtimeand localtimewill be equivalent except gmtime<br />
will returntm_isdst(Daylight Savings Time flag) as zero to indicate<br />
that Daylight Savings Time is not in effect.<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 321<br />
Example: #include /* for gmtime, asctime, */<br />
/* time_t, tm */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
time_t timer;<br />
struct tm *newtime;<br />
timer = 1066668182; /* Mon Oct 20 16:43:02 2003 */<br />
newtime = gmtime(&timer);<br />
printf("UTC time = %s\n", asctime(newtime));<br />
}<br />
Output:<br />
UTC time = Mon Oct 20 16:43:02 2003<br />
localtime<br />
Description: Converts a value to the local time.<br />
Include: <br />
Prototype: struct tm *localtime(const time_t *tod);<br />
Argument: tod pointer to stored time<br />
Return Value: Returns the address ofthe time structure.<br />
Remarks: By default, MPLAB C30 returns the timeas instruction cycles. With<br />
this<br />
default localtimeand gmtimewill be equivalent except localtime<br />
will return tm_isdst(Daylight Savings Time flag) as -1 to indicate that<br />
the status of Daylight Savings Time is not known.<br />
Example: #include /* for localtime, */<br />
/* asctime, time_t, tm */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
time_t timer;<br />
struct tm *newtime;<br />
timer = 1066668182; /* Mon Oct 20 16:43:02 2003 */<br />
newtime = localtime(&timer);<br />
strftime (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 324<br />
thời gian<br />
Mô tả: Tính thời gian lịch hiện tại.<br />
Bao gồm:<br />
2004 Microchip Technology Inc<br />
Nguyên mẫu: thời gian time_t (time_t * tod);<br />
Đối số: con trỏ tod để vị trí lưu trữ cho thời gian<br />
Quay trở lại giá trị: Trả lại thời gian lịch được mã hóa như là một giá trị time_t.<br />
Ghi chú: Nếu môi trường mục tiêu không thể xác định thời gian, chức năng<br />
trả về -1, vào vai một time_t. Theo mặc định, MPLAB C30 trả về thời gian<br />
như chu kỳ hướng dẫn. Chức năng này là tùy chỉnh. Xem pic30-libs.<br />
Ví dụ: # include / * Thời gian * /<br />
# include / * Cho printf * /<br />
dễ bay hơi int i;<br />
int main (void)<br />
{<br />
time_t ve;<br />
thời gian (0); / * Thời gian bắt đầu * /<br />
for (i = 0; i
printf("Local time = %s\n", asctime(newtime));<br />
}<br />
Output:<br />
Local time = Mon Oct20 16:43:02 2003<br />
gmtime (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
nếu<br />
Kết quả underflowed (giá trị trả về là quá nhỏ).<br />
Phản ứng với giá trị đặc biệt, chẳng hạn như Nans, số không, và infinities, có<br />
thể thay đổi tùy thuộc<br />
theo chức năng. Mỗi mô tả chức năng bao gồm một định nghĩa của các chức<br />
năng của<br />
đáp ứng với giá trị đó.<br />
HUGE_VAL<br />
Mô tả: HUGE_VALis trả về bởi một chức năng trên một loạt lỗi (ví dụ, chức<br />
năng<br />
DS51456B-page 322<br />
mktime<br />
2004 Microchip Technology Inc.<br />
cố gắng để trả lại một giá trị quá lớn để được đại diện trong các mục tiêu<br />
chính xác).<br />
Description: Converts local time to a calendar value.<br />
Include: <br />
Prototype: time_t mktime(struct tm *tptr);<br />
Argument: tptr a pointer to the time structure<br />
Return Value: Returns the calendar time encoded as a value of time_t.<br />
Remarks: If the calendar time cannot be represented, the function returns -1,<br />
cast<br />
as a time_t(i.e. (time_t) -1).<br />
Example: #include /*for localtime, */<br />
/* asctime, mktime, */<br />
/* time_t, tm */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
time_t timer, whattime;<br />
struct tm *newtime;<br />
timer = 1066668182; /* Mon Oct 20 16:43:02 2003 */<br />
/* localtime allocates space for struct tm */<br />
newtime = localtime(&timer);<br />
printf("Local time = %s", asctime(newtime));<br />
whattime = mktime(newtime);<br />
printf("Calendar time as time_t = %ld\n",<br />
whattime);<br />
}<br />
Output:<br />
Local time = Mon Oct 20 16:43:02 2003<br />
Calendar time as time_t = 1066668182<br />
strftime<br />
Bao gồm:<br />
Bình luận: -HUGE_VALis trả lại nếu kết quả chức năng là tiêu cực và quá lớn<br />
(Độ lớn) được đại diện trên cả chặng đường mục tiêu chính xác. Khi<br />
kết quả in được +/- HUGE_VAL, nó sẽ được đại diện bởi +/- inf.<br />
acos<br />
Mô tả: Tính hàm hồ quang cosin lượng giác của một độ chính xác kép<br />
giá trị dấu chấm động.<br />
Bao gồm:<br />
Prototype: acos đôi (double x);<br />
Đối số: giá trị x giữa -1 và 1 mà trả lại cosin hồ quang<br />
Quay trở lại giá trị: Trả về cosin hồ quang trong radian trong khoảng từ 0 đến p<br />
(bao gồm).<br />
Bình luận: Một lỗi xảy ra nếu miền XIS ít hơn 1 hoặc lớn hơn 1.<br />
Ví dụ: # include / * Cho acos * /<br />
# include / * Cho printf, perror * /<br />
# include / * Cho errno * /<br />
int main (void)<br />
{<br />
double x, y;<br />
errno = 0;<br />
x = -2,0;<br />
y = acos (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("arccosine của% f% f \ n \ n", x, y);<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
Description: Formats the time structure to a string based on the format<br />
parameter.<br />
DS51456B trang 326<br />
2004 Microchip Technology Inc
Include: <br />
Prototype: size_t strftime(char *s, size_t n,<br />
const char *format, const struct tm *tptr);<br />
Arguments: soutput string<br />
n maximum length of string<br />
format format-control string<br />
tptr pointer to tm data structure<br />
Return Value: Returns the number of characters placed in the array s if the total<br />
including the terminating null is not greater than n. Otherwise, the<br />
function returns 0 and the contents of array sare indeterminate.<br />
Remarks: The format parameters follow:<br />
%a abbreviated weekday name<br />
%A full weekday name<br />
%b abbreviated month name<br />
%B full month name<br />
%c appropriate date and time representation<br />
%d day of the month (01-31)<br />
%H hour of the day (00-23)<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 323<br />
%I hour of the day (01-12)<br />
%j day of the year (001-366)<br />
%m month of the year (01-12)<br />
%M minute of the hour (00-59)<br />
%p AM/PM designator<br />
%S second of the minute (00-61)<br />
allowing for up to two leap seconds<br />
%U week number of the year where Sunday is the first day of week 1<br />
(00-53)<br />
%w weekday where Sunday is day 0 (0-6)<br />
%W week number of the year where Monday is the first day of week 1<br />
(00-53)<br />
%x appropriate date representation<br />
%X appropriate time representation<br />
%y year without century (00-99)<br />
%Y year with century<br />
%Z time zone (possibly abbreviated) or no characters if time zone is<br />
unavailable<br />
%% percent character %<br />
errno = 0;<br />
x = 0,10;<br />
y = acos (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("arccosine của% f% f \ n \ n", x, y);<br />
}<br />
Đầu ra:<br />
Lỗi: lỗi miền<br />
Các arccosine của -2,000000 là nan<br />
Các arccosine của 0.100000 là 1.470629<br />
acosf<br />
Mô tả: Tính hàm hồ quang cosin lượng giác của một độ chính xác đơn<br />
giá trị dấu chấm động.<br />
Bao gồm:<br />
Prototype: acosf nổi (float x);<br />
Giá trị x giữa -1 và 1: Đối số<br />
Quay trở lại giá trị: Trả về cosin hồ quang trong radian trong khoảng of0 đến pi<br />
(bao gồm).<br />
Bình luận: Một lỗi xảy ra nếu miền XIS ít hơn 1 hoặc lớn hơn 1.<br />
Ví dụ: # include / * Cho acosf * /<br />
# include / * Cho printf, perror * /<br />
# include / * Cho errno * /<br />
int main (void)<br />
{<br />
float x, y;<br />
errno = 0;<br />
x = 2.0F;<br />
y = acosf (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("arccosine của% f% f \ n \ n", x, y);<br />
errno = 0;<br />
x = 0.0f;<br />
y = acosf (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("arccosine của% f% f \ n", x, y);<br />
}<br />
Đầu ra:
Example: #include /* for strftime, */<br />
/* localtime, */<br />
/* time_t, tm */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
time_t timer, whattime;<br />
struct tm *newtime;<br />
char buf[128];<br />
timer = 1066668182; /* Mon Oct 20 16:43:02 2003 */<br />
/* localtime allocates space for structure */<br />
newtime = localtime(&timer);<br />
strftime(buf, 128, "It was a %A, %d days into the "<br />
"month of %B in the year %Y.\n", newtime);<br />
printf(buf);<br />
strftime(buf, 128, "It was %W weeks into the year "<br />
"or %jdays into the year.\n", newtime);<br />
printf(buf);<br />
}<br />
Output:<br />
It was a Monday, 20 days into the month of October in<br />
the year 2003.<br />
It was 42 weeks into the year or 293 days into the<br />
year.<br />
strftime (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
Lỗi: lỗi miền<br />
Các arccosine của 2.000000 là nan<br />
Các arccosine của 0.000000 là 1.570796<br />
acos (Tiếp theo)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 327<br />
asin<br />
Mô tả: Tính hàm sin cung lượng giác của một độ chính xác kép<br />
giá trị dấu chấm động.<br />
Bao gồm:<br />
Prototype: asin đôi (double x);<br />
Đối số: giá trị x giữa -1 và 1 mà trả lại arc sine<br />
Quay trở lại giá trị: Trả về sin hồ quang trong radian trong khoảng -pi / 2 đến +<br />
pi / 2 (bao gồm).<br />
Bình luận: Một lỗi xảy ra nếu miền XIS ít hơn 1 hoặc lớn hơn 1.<br />
Ví dụ: # include / * Cho asin * /<br />
# include / * Cho printf, perror * /<br />
# include / * Cho errno * /<br />
int main (void)<br />
{<br />
double x, y;<br />
errno = 0;<br />
x = 2,0;<br />
y = asin (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("arcsine của% f% f \ n \ n", x, y);<br />
errno = 0;<br />
x = 0,0;<br />
DS51456B-page 324<br />
time<br />
2004 Microchip Technology Inc.<br />
y = asin (x);<br />
if (errno)<br />
Description: Calculates the current calendar time.<br />
Include: <br />
Prototype: time_t time(time_t *tod);<br />
Argument: tod pointer to storage location for time<br />
Return Value: Returns the calendar time encoded as a value of time_t.<br />
Remarks: If the target environment cannot determine the time, the function<br />
returns -1, cast as a time_t. By default, MPLAB C30 returns the time<br />
as instruction cycles. This function is customizable. See pic30-libs.<br />
Example: #include /*for time */<br />
perror ("Lỗi");<br />
printf ("arcsine của% f% f \ n \ n", x, y);<br />
}<br />
Đầu ra:<br />
Lỗi: lỗi miền<br />
Các arcsine của 2.000000 là nan<br />
Các arcsine của 0.000000 là 0.000000<br />
asinf<br />
Mô tả: Tính hàm sin cung lượng giác của một độ chính xác đơn
#include /* for printf */<br />
volatile int i;<br />
int main(void)<br />
{<br />
time_t ticks;<br />
time(0); /* start time */<br />
for (i = 0; i < 10; i++) /* waste time */<br />
time(&ticks); /* get time */<br />
printf("Time = %ld\n", ticks);<br />
}<br />
Output:<br />
Time = 256<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 325<br />
4.17 MATHEMATICAL FUNCTIONS<br />
giá trị dấu chấm động.<br />
Bao gồm:<br />
Prototype: asinf nổi (float x);<br />
Giá trị x giữa -1 và 1: Đối số<br />
Quay trở lại giá trị: Trả về sin hồ quang trong radian trong khoảng -pi / 2 đến +<br />
pi / 2 (bao gồm).<br />
Bình luận: Một lỗi xảy ra nếu miền XIS ít hơn 1 hoặc lớn hơn 1.<br />
Ví dụ: # include / * Cho asinf * /<br />
# include / * Cho printf, perror * /<br />
# include / * Cho errno * /<br />
int main (void)<br />
{<br />
float x, y;<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
The header file math.hconsists of a macro and various functions that calculate<br />
common mathematical operations. Error conditions may be handled with a<br />
domain error or<br />
range error (see errno.h).<br />
DS51456B trang 328<br />
errno = 0;<br />
x = 2.0F;<br />
2004 Microchip Technology Inc<br />
A domain error occurs when the input argument is outside the domain over<br />
which the<br />
function is defined. The error is reported by storing the value of EDOMin<br />
errnoand<br />
returning a particular value defined for each function.<br />
A range error occurs when the result is too large or too small to be represented<br />
in the<br />
target precision. The error is reported by storing the value of ERANGEin<br />
errnoand<br />
returning HUGE_VALif the result overflowed (return value was too large) or a<br />
zero if the<br />
result underflowed (return value is too small).<br />
Responses to special values, such as NaNs, zeros, and infinities, may vary<br />
depending<br />
upon the function. Each function description includes a definition of the<br />
function's<br />
response to such values.<br />
HUGE_VAL<br />
Description: HUGE_VALis returned by a function on a range error (e. g., the<br />
function<br />
tries to return a value too large to be represented in the target<br />
precision).<br />
Include: <br />
Remarks: -HUGE_VALis returned if a function result is negative and is too<br />
large<br />
y = asinf (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("arcsine của% f% f \ n \ n", x, y);<br />
errno = 0;<br />
x = 0.0f;<br />
y = asinf (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("arcsine của% f% f \ n \ n", x, y);<br />
}<br />
Đầu ra:<br />
Lỗi: lỗi miền<br />
Các arcsine của 2.000000 là nan<br />
Các arcsine của 0.000000 là 0.000000<br />
atan<br />
Mô tả: Tính hàm hồ quang tang lượng giác của một độ chính xác kép<br />
giá trị dấu chấm động.<br />
Bao gồm:<br />
Prototype: atan đôi (double x);<br />
Đối số: x giá trị mà trả lại tang cung
(in magnitude) to be represented inthe target precision. When the<br />
printed result is +/- HUGE_VAL, it will be represented by +/- inf.<br />
acos<br />
Description: Calculates the trigonometric arc cosine function of a double<br />
precision<br />
floating-point value.<br />
Include: <br />
Prototype: double acos (double x);<br />
Argument: x value between -1 and 1 for which to return the arc cosine<br />
Return Value: Returns the arc cosine in radians in the range of 0 to pi<br />
(inclusive).<br />
Remarks: A domain error occurs if xis less than -1 or greater than 1.<br />
Example: #include /* for acos */<br />
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
double x,y;<br />
errno = 0;<br />
x = -2.0;<br />
y = acos (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The arccosine of %f is %f\n\n", x, y);<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
Quay trở lại giá trị: Trả về tang cung trong radian trong khoảng -pi / 2 đến + pi<br />
2<br />
(Bao gồm).<br />
Bình luận: Không có tên miền hoặc phạm vi lỗi sẽ xảy ra.<br />
Ví dụ: # include / * Cho atan * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
double x, y;<br />
x = 2,0;<br />
y = atan (x);<br />
printf ("arctangent của% f% f \ n \ n", x, y);<br />
x = -1,0;<br />
y = atan (x);<br />
printf ("arctangent của% f% f \ n \ n", x, y);<br />
}<br />
Đầu ra:<br />
Các arctangent của 2.000000 là 1.107149<br />
Các arctangent của -1,000000 là -,785398<br />
asinf (Tiếp theo)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 329<br />
atanf<br />
Mô tả: Tính hàm hồ quang tang lượng giác của một độ chính xác đơn<br />
giá trị dấu chấm động.<br />
Bao gồm:<br />
Prototype: atanf nổi (float x);<br />
DS51456B-page 326<br />
2004 Microchip Technology Inc.<br />
Đối số: x giá trị mà trả lại tang cung<br />
errno = 0;<br />
x = 0.10;<br />
y = acos (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The arccosine of %f is %f\n\n", x, y);<br />
}<br />
Output:<br />
Error: domain error<br />
The arccosine of -2.000000 is nan<br />
The arccosine of 0.100000 is 1.470629<br />
acosf<br />
Quay trở lại giá trị: Trả về tang cung trong radian trong khoảng -pi / 2 đến + pi<br />
2<br />
(Bao gồm).<br />
Bình luận: Không có tên miền hoặc rangeerror sẽ xảy ra.<br />
Ví dụ: # include / * Cho atanf * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
float x, y;<br />
x = 2.0F;<br />
y = atanf (x);<br />
printf ("arctangent của% f% f \ n \ n", x, y);
Description: Calculates the trigonometric arc cosine function of a single<br />
precision<br />
floating-point value.<br />
Include: <br />
Prototype: float acosf (float x);<br />
Argument: x value between -1 and 1<br />
Return Value: Returns the arc cosine in radians in the range of0 to pi<br />
(inclusive).<br />
Remarks: A domain error occurs if xis less than -1 or greater than 1.<br />
Example: #include /* for acosf */<br />
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
float x, y;<br />
errno = 0;<br />
x = 2.0F;<br />
y = acosf (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The arccosine of %f is %f\n\n", x, y);<br />
errno = 0;<br />
x = 0.0F;<br />
y = acosf (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The arccosine of %f is %f\n", x, y);<br />
}<br />
Output:<br />
Error: domain error<br />
The arccosine of 2.000000 is nan<br />
The arccosine of 0.000000 is 1.570796<br />
acos (Continued)<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 327<br />
asin<br />
Description: Calculates the trigonometric arc sine function of a double precision<br />
floating-point value.<br />
Include: <br />
Prototype: double asin (double x);<br />
x = -1.0F;<br />
y = atanf (x);<br />
printf ("arctangent của% f% f \ n \ n", x, y);<br />
}<br />
Đầu ra:<br />
Các arctangent của 2.000000 là 1.107149<br />
Các arctangent của -1,000000 là -,785398<br />
atan2<br />
Mô tả: Tính hàm lượng giác cung tiếp tuyến của y / x.<br />
Bao gồm:<br />
Prototype: atan2 đôi (double y, double x);<br />
Đối số: giá trị yy mà trả lại tang cung<br />
giá trị xx mà trả lại tang cung<br />
Quay trở lại giá trị: Trả về inradians hồ quang tiếp xúc trong khoảng từ-pi pi<br />
(bao gồm)<br />
với góc tọa độ được xác định bởi các dấu hiệu của cả hai tham số.<br />
Bình luận: Một lỗi xảy ra nếu cả hai miền xand Yare không hoặc cả hai xand<br />
Yare<br />
+/- Vô cùng.<br />
Ví dụ: # include / * Cho atan2 * /<br />
# include / * Cho printf, perror * /<br />
# include / * Cho errno * /<br />
int main (void)<br />
{<br />
double x, y, z;<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 330<br />
errno = 0;<br />
x = 0,0;<br />
y = 2,0;<br />
z = atan2 (x, y);<br />
if (errno)<br />
perror ("Lỗi");<br />
2004 Microchip Technology Inc<br />
printf ("arctangent của% f / f% là% f \ n \ n",<br />
x, y, z);<br />
errno = 0;<br />
x = -1,0;<br />
y = 0.0;
Argument: x value between -1 and 1 for which to return the arc sine<br />
Return Value: Returns the arc sine in radians in the range of -pi/2 to +pi/2<br />
(inclusive).<br />
Remarks: A domain error occurs if xis less than -1 or greater than 1.<br />
Example: #include /* for asin */<br />
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
double x, y;<br />
errno = 0;<br />
x = 2.0;<br />
y = asin (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The arcsine of %f is %f\n\n", x, y);<br />
errno = 0;<br />
x = 0.0;<br />
y = asin (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The arcsine of %f is %f\n\n", x, y);<br />
}<br />
Output:<br />
Error: domain error<br />
The arcsine of 2.000000 is nan<br />
The arcsine of 0.000000 is 0.000000<br />
asinf<br />
Description: Calculates the trigonometric arc sine function of a single precision<br />
floating-point value.<br />
Include: <br />
Prototype: float asinf (float x);<br />
Argument: x value between -1 and 1<br />
Return Value: Returns the arc sine in radians in the range of -pi/2 to +pi/2<br />
(inclusive).<br />
Remarks: A domain error occurs if xis less than -1 or greater than 1.<br />
Example: #include /* for asinf */<br />
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
z = atan2 (x, y);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("arctangent của% f / f% là% f \ n \ n",<br />
x, y, z);<br />
errno = 0;<br />
x = 0,0;<br />
y = 0.0;<br />
z = atan2 (x, y);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("arctangent của% f / f% là% f \ n \ n",<br />
x, y, z);<br />
}<br />
Đầu ra:<br />
Các arctangent của 2.000000 / 0.000000 là 1.570796<br />
Các arctangent của 0.000000 / -1,000000 là 3,141593<br />
Lỗi: lỗi miền<br />
Các arctangent của 0.000000 / 0.000000 là nan<br />
atan2 (Tiếp theo)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 331<br />
atan2f<br />
Mô tả: Tính hàm lượng giác cung tiếp tuyến của y / x.<br />
Bao gồm:<br />
Prototype: atan2f nổi (float y, float x);<br />
Đối số: giá trị yy mà trả lại tang cung<br />
giá trị xx mà trả lại tang cung<br />
Quay trở lại giá trị: Trả về inradians hồ quang tiếp xúc trong khoảng từ-pi pi vớ<br />
góc phần tư được xác định bởi các dấu hiệu của cả hai tham số.<br />
Bình luận: Một lỗi xảy ra nếu cả hai miền xand Yare không hoặc cả hai xand<br />
Yare<br />
+/- Vô cùng.<br />
Ví dụ: # include / * Cho atan2f * /<br />
# include / * Cho printf, perror * /<br />
# include / * Cho errno * /<br />
int main (void)<br />
{<br />
nổi x, y, z;<br />
errno = 0;
{<br />
float x, y;<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 328<br />
errno = 0;<br />
x = 2.0F;<br />
y = asinf(x);<br />
if (errno)<br />
perror("Error");<br />
2004 Microchip Technology Inc.<br />
printf("The arcsine of%f is %f\n\n", x, y);<br />
errno = 0;<br />
x = 0.0F;<br />
y = asinf(x);<br />
if (errno)<br />
perror("Error");<br />
printf("The arcsine of%f is %f\n\n", x, y);<br />
}<br />
Output:<br />
Error: domain error<br />
The arcsine of 2.000000 is nan<br />
The arcsine of 0.000000 is 0.000000<br />
atan<br />
Description: Calculates the trigonometric arc tangent function of a double<br />
precision<br />
floating-point value.<br />
Include: <br />
Prototype: double atan (double x);<br />
Argument: x value for which to return the arc tangent<br />
Return Value: Returns the arc tangent in radians in the range of -pi/2 to +pi/2<br />
(inclusive).<br />
x = 2.0F;<br />
y = 0.0f;<br />
z = atan2f (y, x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("arctangent của% f / f% là% f \ n \ n",<br />
x, y, z);<br />
errno = 0;<br />
x = 0.0f;<br />
y = -1.0F;<br />
z = atan2f (y, x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("arctangent của% f / f% là% f \ n \ n",<br />
x, y, z);<br />
errno = 0;<br />
x = 0.0f;<br />
y = 0.0f;<br />
z = atan2f (y, x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("arctangent của% f / f% là% f \ n \ n",<br />
x, y, z);<br />
}<br />
Đầu ra:<br />
Các arctangent của 2.000000 / 0.000000 là 1.570796<br />
Các arctangent của 0.000000 / -1,000000 là 3,141593<br />
Lỗi: lỗi miền<br />
Các arctangent của 0.000000 / 0.000000 là nan<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
Remarks: No domain or range error will occur.<br />
Example: #include /*for atan */<br />
DS51456B trang 332<br />
ceil<br />
2004 Microchip Technology Inc<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
double x, y;<br />
x = 2.0;<br />
Mô tả: Tính trần của một giá trị.<br />
Bao gồm:<br />
Prototype: ceil đôi (double x);<br />
Đối số: xa giá trị dấu chấm động mà trở về trần.<br />
Quay trở lại giá trị: Trả về giá trị nguyên nhỏ nhất lớn hơn hoặc bằng x.
y = atan (x);<br />
printf("The arctangent of%f is %f\n\n", x, y);<br />
x = -1.0;<br />
y = atan (x);<br />
printf("The arctangent of%f is %f\n\n", x, y);<br />
}<br />
Output:<br />
The arctangent of 2.000000 is 1.107149<br />
The arctangent of -1.000000 is -0.785398<br />
asinf (Continued)<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 329<br />
atanf<br />
Description: Calculates the trigonometric arc tangent function of a single<br />
precision<br />
floating-point value.<br />
Include: <br />
Prototype: float atanf (float x);<br />
Argument: x value for which to return the arc tangent<br />
Return Value: Returns the arc tangent in radians in the range of -pi/2 to +pi/2<br />
(inclusive).<br />
Remarks: No domain or rangeerror will occur.<br />
Example: #include /* for atanf */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
float x, y;<br />
x = 2.0F;<br />
y = atanf (x);<br />
printf("The arctangent of%f is %f\n\n", x, y);<br />
x = -1.0F;<br />
y = atanf (x);<br />
printf("The arctangent of%f is %f\n\n", x, y);<br />
}<br />
Output:<br />
The arctangent of 2.000000 is 1.107149<br />
The arctangent of -1.000000 is -0.785398<br />
atan2<br />
Description: Calculates the trigonometric arc tangent function of y/x.<br />
Bình luận: Không có tên miền hoặc phạm vi lỗi sẽ xảy ra. Xem sàn.<br />
Ví dụ: # include / * Cho trần nhà * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
double x [8] = {2.0, 1.75, 1.5, 1.25, -2.0,<br />
-1.75, -1.5, -1.25};<br />
y kép;<br />
int i;<br />
for (i = 0; i
Include: <br />
Prototype: double atan2 (double y, double x);<br />
Arguments: y y value for which to return the arc tangent<br />
x x value for which to return the arc tangent<br />
Return Value: Returns the arc tangent inradians in the range of-pi to pi<br />
(inclusive)<br />
with the quadrant determined by the signs of both parameters.<br />
Remarks: A domain error occurs if both xand yare zero or both xand yare<br />
+/- infinity.<br />
Example: #include /* for atan2 */<br />
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
double x, y, z;<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
nổi y;<br />
int i;<br />
for (i = 0; i
if (errno)<br />
perror("Error");<br />
printf("The arctangent of %f/%f is %f\n\n",<br />
y, x, z);<br />
}<br />
Output:<br />
The arctangent of 2.000000/0.000000 is 1.570796<br />
The arctangent of 0.000000/-1.000000 is 3.141593<br />
Error: domain error<br />
The arctangent of 0.000000/0.000000 is nan<br />
atan2 (Continued)<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 331<br />
atan2f<br />
Description: Calculates the trigonometric arc tangent function of y/x.<br />
Include: <br />
Prototype: float atan2f (float y, float x);<br />
Arguments: y y value for which to return the arc tangent<br />
x x value for which to return the arc tangent<br />
Return Value: Returns the arc tangent inradians in the range of-pi to pi with the<br />
quadrant determined by the signs of both parameters.<br />
Remarks: A domain error occurs if both xand yare zero or both xand yare<br />
+/- infinity.<br />
Example: #include /* for atan2f */<br />
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
float x, y, z;<br />
errno = 0;<br />
x = 2.0F;<br />
y = 0.0F;<br />
z = atan2f (y, x);<br />
if (errno)<br />
perror("Error");<br />
printf("The arctangent of %f/%f is %f\n\n",<br />
y, x, z);<br />
errno = 0;<br />
x = 0.0F;<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 334<br />
errno = 0;<br />
x = 0,0;<br />
y = cos (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("cô sin của% f% f \ n \ n", x, y);<br />
}<br />
Đầu ra:<br />
Các cô sin của -1,000000 là 0,540302<br />
Các cô sin của 0.000000 là 1.000000<br />
cosf<br />
2004 Microchip Technology Inc<br />
Mô tả: Tính hàm cosin lượng giác của một độ chính xác đơn<br />
nổi giá trị điểm.<br />
Bao gồm:<br />
Prototype: cosf nổi (float x);<br />
Đối số: x giá trị mà toreturn cô sin<br />
Quay trở lại giá trị: Trả về cosin của xin radian trong phạm vi của -1 đến 1 bao<br />
gồm.<br />
Bình luận: Một lỗi miền sẽ xảy ra nếu XIS một NaN hoặc vô cùng.<br />
Ví dụ: # include / * Cho cosf * /<br />
# include / * Cho printf, perror * /<br />
# include / * Cho errno * /<br />
int main (void)<br />
{<br />
float x, y;<br />
errno = 0;<br />
x = -1.0F;<br />
y = cosf (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("cô sin của% f% f \ n \ n", x, y);<br />
errno = 0;<br />
x = 0.0f;<br />
y = cosf (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("cô sin của% f% f \ n \ n", x, y);<br />
}
y = -1.0F;<br />
z = atan2f (y, x);<br />
if (errno)<br />
perror("Error");<br />
printf("The arctangent of %f/%f is %f\n\n",<br />
y, x, z);<br />
errno = 0;<br />
x = 0.0F;<br />
y = 0.0F;<br />
z = atan2f (y, x);<br />
if (errno)<br />
perror("Error");<br />
printf("The arctangent of %f/%f is %f\n\n",<br />
y, x, z);<br />
}<br />
Output:<br />
The arctangent of 2.000000/0.000000 is 1.570796<br />
The arctangent of 0.000000/-1.000000 is 3.141593<br />
Error: domain error<br />
The arctangent of 0.000000/0.000000 is nan<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 332 2004 Microchip Technology Inc.<br />
ceil<br />
Description: Calculates the ceiling of a value.<br />
Include: <br />
Prototype: double ceil(double x);<br />
Argument: x a floating-point value for which to return the ceiling.<br />
Return Value: Returns the smallest integer value greater than or equal to x.<br />
Remarks: No domain or range error will occur. See floor.<br />
Example: #include /*for ceil */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
double x[8] = {2.0, 1.75, 1.5, 1.25, -2.0,<br />
-1.75, -1.5, -1.25};<br />
double y;<br />
int i;<br />
Đầu ra:<br />
Các cô sin của -1,000000 là 0,540302<br />
Các cô sin của 0.000000 là 1.000000<br />
cos (Tiếp theo)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 335<br />
cosh<br />
Mô tả: Tính hàm cosin hyperbol của một độ chính xác gấp đôi nổi<br />
giá trị điểm.<br />
Bao gồm:<br />
Prototype: cosh đôi (double x);<br />
Đối số: x giá trị mà trả lại cosin hyperbol<br />
Quay trở lại giá trị: Trả về cosin hyperbol của x<br />
Bình luận: Một loạt lỗi sẽ xảy ra nếu độ lớn của XIS quá lớn.<br />
Ví dụ: # include / * Cho cosh * /<br />
# include / * Cho printf, perror * /<br />
# include / * Cho errno * /<br />
int main (void)<br />
{<br />
double x, y;<br />
errno = 0;<br />
x = -1,5;<br />
y = cosh (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("cosin hyperbol của% f% f \ n \ n",<br />
x, y);<br />
errno = 0;<br />
x = 0,0;<br />
y = cosh (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("cosin hyperbol của% f% f \ n \ n",<br />
x, y);<br />
errno = 0;<br />
x = 720,0;<br />
y = cosh (x);<br />
if (errno)<br />
perror ("Lỗi");
for (i=0; i
The ceiling for 2.000000 is 2.000000<br />
The ceiling for 1.750000 is 2.000000<br />
The ceiling for 1.500000 is 2.000000<br />
The ceiling for 1.250000 is 2.000000<br />
The ceiling for -2.000000 is -2.000000<br />
The ceiling for -1.750000 is -1.000000<br />
The ceiling for -1.500000 is -1.000000<br />
The ceiling for -1.250000 is -1.000000<br />
cos<br />
Description: Calculates the trigonometric cosine function of a double precision<br />
floating point value.<br />
Include: <br />
Prototype: double cos (double x);<br />
Argument: x value for which toreturn the cosine<br />
Return Value: Returns the cosine of xin radians in the ranges of -1 to 1<br />
inclusive.<br />
Remarks: A domain error will occur if xis a NaN or infinity.<br />
Example: #include /* for cos*/<br />
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
double x,y;<br />
errno = 0;<br />
x = -1.0;<br />
y = cos (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The cosine of%f is %f\n\n", x, y);<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
x, y);<br />
errno = 0;<br />
x = 720.0F;<br />
y = coshf (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("cosin hyperbol của% f% f \ n \ n",<br />
x, y);<br />
}<br />
Đầu ra:<br />
Cosin hyperbol của-1.000000 là 1.543081<br />
Cosin hyperbol of0.000000 là 1,000000<br />
Lỗi: lỗi phạm vi<br />
Cosin hyperbol of720.000000 là inf<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 337<br />
exp<br />
Mô tả: Tính hàm OFX mũ (e lũy thừa x nơi<br />
x là độ chính xác gấp đôi giá trị nổi điểm).<br />
Bao gồm:<br />
Prototype: điểm kinh nghiệm gấp đôi (double x);<br />
Đối số: x giá trị mà để trả lại theo cấp số nhân<br />
Quay trở lại giá trị: Trả về số mũ của x. Trên một tràn, expreturns infand trên<br />
Van cân bằng một expreturns 0.<br />
Bình luận: Một loạt lỗi xảy ra nếu độ lớn của XIS quá lớn.<br />
Ví dụ: # include / * Cho điểm kinh nghiệm * /<br />
# include / * Cho printf, perror * /<br />
# include / * Cho errno * /<br />
int main (void)<br />
{<br />
double x, y;<br />
errno = 0;<br />
DS51456B-page 334<br />
errno = 0;<br />
x = 0.0;<br />
y = cos (x);<br />
if (errno)<br />
perror("Error");<br />
2004 Microchip Technology Inc.<br />
x = 1,0;<br />
y = exp (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("mũ của% f% f \ n \ n", x, y);<br />
errno = 0;<br />
printf("The cosine of %f is %f\n\n", x, y);<br />
x = 1E3;
}<br />
Output:<br />
The cosine of -1.000000 is 0.540302<br />
The cosine of 0.000000 is 1.000000<br />
cosf<br />
Description: Calculates the trigonometric cosine function of a single precision<br />
floating point value.<br />
Include: <br />
Prototype: float cosf (float x);<br />
Argument: x value for which toreturn the cosine<br />
Return Value: Returns the cosine of xin radians in the ranges of -1 to 1<br />
inclusive.<br />
Remarks: A domain error will occur if xis a NaN or infinity.<br />
Example: #include /* for cosf */<br />
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
float x, y;<br />
errno = 0;<br />
y = exp (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("mũ của% f% f \ n \ n", x, y);<br />
errno = 0;<br />
x = -1E3;<br />
y = exp (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("mũ của% f% f \ n \ n", x, y);<br />
}<br />
Đầu ra:<br />
Các mũ của 1.000000 là 2.718282<br />
Lỗi: lỗi phạm vi<br />
Các mũ của 1000.000000 là inf<br />
Lỗi: lỗi phạm vi<br />
Các mũ của -1000,000000 là 0.000000<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
x = -1.0F;<br />
y = cosf (x);<br />
DS51456B trang 338<br />
expf<br />
2004 Microchip Technology Inc<br />
if (errno)<br />
perror("Error");<br />
printf("The cosine of %f is %f\n\n", x, y);<br />
errno = 0;<br />
x = 0.0F;<br />
y = cosf (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The cosine of %f is %f\n\n", x, y);<br />
}<br />
Output:<br />
The cosine of -1.000000 is 0.540302<br />
The cosine of 0.000000 is 1.000000<br />
cos (Continued)<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 335<br />
cosh<br />
Mô tả: Tính hàm mũ của x (e lũy thừa x nơi<br />
x là độ chính xác đơn giá trị nổi điểm).<br />
Bao gồm:<br />
Prototype: expf nổi (float x);<br />
Đối số: x nổi giá trị điểm mà trả lại theo cấp số nhân<br />
Quay trở lại giá trị: Trả về số mũ của x. Trên một tràn, expfreturns infand trên<br />
một điểm kinh nghiệm Van cân bằng trả về 0.<br />
Bình luận: Một loạt lỗi xảy ra nếu độ lớn của XIS quá lớn.<br />
Ví dụ: # include / * Cho expf * /<br />
# include / * Cho printf, perror * /<br />
# include / * Cho errno * /<br />
int main (void)<br />
{<br />
float x, y;<br />
errno = 0;<br />
x = 1.0f;<br />
y = expf (x);
Description: Calculates the hyperbolic cosine function of a double precision<br />
floating<br />
point value.<br />
Include: <br />
Prototype: double cosh (double x);<br />
Argument: x value for which to return the hyperbolic cosine<br />
Return Value: Returns the hyperbolic cosine of x<br />
Remarks: A range error will occur if the magnitude of xis too large.<br />
Example: #include /* for cosh */<br />
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
double x, y;<br />
errno = 0;<br />
x = -1.5;<br />
y = cosh (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The hyperbolic cosine of %f is %f\n\n",<br />
x, y);<br />
errno = 0;<br />
x = 0.0;<br />
y = cosh (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The hyperbolic cosine of %f is %f\n\n",<br />
x, y);<br />
errno = 0;<br />
x = 720.0;<br />
y = cosh (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The hyperbolic cosine of %f is %f\n\n",<br />
x, y);<br />
}<br />
Output:<br />
The hyperbolic cosine of-1.500000 is 2.352410<br />
The hyperbolic cosine of0.000000 is 1.000000<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("mũ của% f% f \ n \ n", x, y);<br />
errno = 0;<br />
x = 1.0E3F;<br />
y = expf (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("mũ của% f% f \ n \ n", x, y);<br />
errno = 0;<br />
x = -1.0E3F;<br />
y = expf (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("mũ của% f% f \ n \ n", x, y);<br />
}<br />
Đầu ra:<br />
Các mũ của 1.000000 là 2.718282<br />
Lỗi: lỗi phạm vi<br />
Các mũ của 1000.000000 là inf<br />
Lỗi: lỗi phạm vi<br />
Các mũ của -1000,000000 là 0.000000<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 339<br />
fabs<br />
Mô tả: Tính giá trị tuyệt đối của một giá trị chính xác điểm nổi gấp đôi.<br />
Bao gồm:<br />
Prototype: fabs đôi (double x);<br />
Đối số: x nổi giá trị điểm mà toreturn giá trị tuyệt đối<br />
Quay trở lại giá trị: Trả về giá trị tuyệt đối của x. (Một số âm được trả về như<br />
tích cực, một số dương là không thay đổi.)<br />
Bình luận: Không có tên miền hoặc rangeerror sẽ xảy ra.<br />
Ví dụ: # include / * Cho fabs * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
double x, y;<br />
x = 1,75;<br />
y = fabs (x);
Error: range error<br />
The hyperbolic cosine of 720.000000 is inf<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 336<br />
coshf<br />
2004 Microchip Technology Inc.<br />
Description: Calculates the hyperbolic cosine function of a single precision<br />
floating<br />
point value.<br />
Include: <br />
Prototype: float coshf (float x);<br />
Argument: x value for which to return the hyperbolic cosine<br />
Return Value: Returns the hyperbolic cosine of x<br />
Remarks: A range error will occur if the magnitude of xis too large.<br />
Example: #include /* for coshf */<br />
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
float x, y;<br />
errno = 0;<br />
x = -1.0F;<br />
y = coshf (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The hyperbolic cosine of %f is %f\n\n",<br />
x, y);<br />
errno = 0;<br />
x = 0.0F;<br />
y = coshf (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The hyperbolic cosine of %f is %f\n\n",<br />
printf ("Giá trị tuyệt đối của% f% f \ n", x, y);<br />
x = -1,5;<br />
y = fabs (x);<br />
printf ("Giá trị tuyệt đối của% f% f \ n", x, y);<br />
}<br />
Đầu ra:<br />
Giá trị tuyệt đối là 1.750000 1.750000<br />
Giá trị tuyệt đối của -1,500000 là 1,500000<br />
fabsf<br />
Mô tả: Tính giá trị tuyệt đối của một giá trị điểm duy nhất chính xác nổi.<br />
Bao gồm:<br />
Prototype: fabsf nổi (float x);<br />
Đối số: x nổi giá trị điểm mà trở về giá trị tuyệt đối<br />
Quay trở lại giá trị: Trả về giá trị tuyệt đối của x. (Một số âm được trả về như<br />
tích cực, một số dương là không thay đổi.)<br />
Bình luận: Không có tên miền hoặc rangeerror sẽ xảy ra.<br />
Ví dụ: # include / * Cho fabsf * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
float x, y;<br />
x = 1.75F;<br />
y = fabsf (x);<br />
printf ("Giá trị tuyệt đối của% f% f \ n", x, y);<br />
x = -1.5F;<br />
y = fabsf (x);<br />
printf ("Giá trị tuyệt đối của% f% f \ n", x, y);<br />
}<br />
Đầu ra:<br />
Giá trị tuyệt đối là 1.750000 1.750000<br />
Giá trị tuyệt đối của -1,500000 là 1,500000<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
x, y);<br />
errno = 0;<br />
DS51456B trang 340<br />
sàn<br />
2004 Microchip Technology Inc<br />
x = 720.0F;<br />
y = coshf (x);<br />
if (errno)<br />
Mô tả: Tính toán sàn của một giá trị chính xác điểm nổi gấp đôi.<br />
Bao gồm:<br />
Prototype: Tầng đôi (double x);
perror("Error");<br />
printf("The hyperbolic cosine of %f is %f\n\n",<br />
x, y);<br />
}<br />
Output:<br />
The hyperbolic cosine of-1.000000 is 1.543081<br />
The hyperbolic cosine of0.000000 is 1.000000<br />
Error: range error<br />
The hyperbolic cosine of720.000000 is inf<br />
Standard C Libraries with Math Functions<br />
exp<br />
2004 Microchip Technology Inc. DS51456B-page 337<br />
Description: Calculates the exponential function ofx (e raised to the power x<br />
where<br />
x is a double precision floating point value).<br />
Include: <br />
Prototype: double exp (double x);<br />
Argument: x value for which to return the exponential<br />
Return Value: Returns the exponential of x. On an overflow, expreturns infand<br />
on<br />
an underflow expreturns 0.<br />
Remarks: A range error occurs if the magnitude of xis too large.<br />
Example: #include /* for exp*/<br />
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
double x, y;<br />
errno = 0;<br />
x = 1.0;<br />
y = exp (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The exponential of %f is %f\n\n", x, y);<br />
errno = 0;<br />
x = 1E3;<br />
y = exp (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The exponential of %f is %f\n\n", x, y);<br />
Đối số: x nổi giá trị điểm mà quay trở lại sàn.<br />
Quay trở lại giá trị: Trả về giá trị nguyên lớn nhất nhỏ hơn hoặc bằng x.<br />
Bình luận: Không có tên miền hoặc phạm vi lỗi sẽ xảy ra. Xem làm trần nhà.<br />
Ví dụ: # include / * Sàn * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
double x [8] = {2.0, 1.75, 1.5, 1.25, -2.0,<br />
-1.75, -1.5, -1.25};<br />
y kép;<br />
int i;<br />
for (i = 0; i
errno = 0;<br />
x = -1E3;<br />
y = exp (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The exponential of %f is %f\n\n", x, y);<br />
}<br />
Output:<br />
The exponential of 1.000000 is 2.718282<br />
Error: range error<br />
The exponential of 1000.000000 is inf<br />
Error: range error<br />
The exponential of -1000.000000 is 0.000000<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 338<br />
expf<br />
2004 Microchip Technology Inc.<br />
Description: Calculates the exponential function of x (e raised to the power x<br />
where<br />
x is a single precision floating point value).<br />
Include: <br />
Prototype: float expf (float x);<br />
Argument: x floating point value for which to return the exponential<br />
Return Value: Returns the exponential of x. On an overflow, expfreturns infand<br />
on<br />
an underflow exp returns 0.<br />
Remarks: A range error occurs if the magnitude of xis too large.<br />
Example: #include /* for expf */<br />
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
float x, y;<br />
errno = 0;<br />
x = 1.0F;<br />
y = expf (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The exponential of %f is %f\n\n", x, y);<br />
nổi x [8] = {2.0F, 1.75F, 1.5F, 1.25F,<br />
-2.0F, -1.75F, -1.5F, -1.25F};<br />
nổi y;<br />
int i;<br />
for (i = 0; i
errno = 0;<br />
x = 1.0E3F;<br />
y = expf (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The exponential of %f is %f\n\n", x, y);<br />
errno = 0;<br />
x = -1.0E3F;<br />
y = expf (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The exponential of %f is %f\n\n", x, y);<br />
}<br />
Output:<br />
The exponential of 1.000000 is 2.718282<br />
Error: range error<br />
The exponential of 1000.000000 is inf<br />
Error: range error<br />
The exponential of -1000.000000 is 0.000000<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 339<br />
fabs<br />
Description: Calculates the absolute value of a double precision floating point<br />
value.<br />
Include: <br />
Prototype: double fabs(double x);<br />
Argument: x floating point value for which toreturn the absolute value<br />
Return Value: Returns the absolute value of x. (A negative number is returned<br />
as<br />
positive, a positive number is unchanged.)<br />
Remarks: No domain or rangeerror will occur.<br />
Example: #include /*for fabs */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
double x, y;<br />
x = 1.75;<br />
y = fabs (x);<br />
printf("The absolute value of %f is %f\n", x, y);<br />
x = -1.5;<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("Đối với fmod (% f, f%) còn lại là% f \ n \ n",<br />
x, y, z);<br />
floorf (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 342 2004 Microchip Technology Inc<br />
errno = 0;<br />
x = 7,0;<br />
y = 7.0;<br />
z = fmod (x, y);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("Đối với fmod (% f, f%) còn lại là% f \ n \ n",<br />
x, y, z);<br />
errno = 0;<br />
x = -5,0;<br />
y = 3,0;<br />
z = fmod (x, y);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("Đối với fmod (% f, f%) còn lại là% f \ n \ n",<br />
x, y, z);<br />
errno = 0;<br />
x = 5,0;<br />
y = -3,0;<br />
z = fmod (x, y);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("Đối với fmod (% f, f%) còn lại là% f \ n \ n",<br />
x, y, z);<br />
errno = 0;<br />
x = -5,0;<br />
y = -5,0;<br />
z = fmod (x, y);<br />
if (errno)<br />
perror ("Lỗi");
y = fabs (x);<br />
printf("The absolute value of %f is %f\n", x, y);<br />
}<br />
Output:<br />
The absolute value of 1.750000 is 1.750000<br />
The absolute value of -1.500000 is 1.500000<br />
fabsf<br />
Description: Calculates the absolute value of a single precision floating point<br />
value.<br />
Include: <br />
Prototype: float fabsf(float x);<br />
Argument: x floating point value for which to return the absolute value<br />
Return Value: Returns the absolute value of x. (A negative number is returned<br />
as<br />
positive, a positive number is unchanged.)<br />
Remarks: No domain or rangeerror will occur.<br />
Example: #include /* for fabsf */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
float x,y;<br />
x = 1.75F;<br />
y = fabsf (x);<br />
printf("The absolute value of %f is %f\n", x, y);<br />
x = -1.5F;<br />
y = fabsf (x);<br />
printf("The absolute value of %f is %f\n", x, y);<br />
}<br />
Output:<br />
The absolute value of 1.750000 is 1.750000<br />
The absolute value of -1.500000 is 1.500000<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 340<br />
floor<br />
2004 Microchip Technology Inc.<br />
Description: Calculates the floor of a double precision floating point value.<br />
Include: <br />
Prototype: double floor (double x);<br />
Argument: x floating point value for which to return the floor.<br />
printf ("Đối với fmod (% f, f%) còn lại là% f \ n \ n",<br />
x, y, z);<br />
errno = 0;<br />
x = 7,0;<br />
y = 0.0;<br />
z = fmod (x, y);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("Đối với fmod (% f, f%) còn lại là% f \ n \ n",<br />
x, y, z);<br />
}<br />
Đầu ra:<br />
Đối với fmod (7.000000, 3.000000) còn lại là 1.000000<br />
Đối với fmod (7.000000, 7.000000) còn lại là 0.000000<br />
Đối với fmod (-5,000000, 3,000000) còn lại là -2,000000<br />
Đối với fmod (5.000000, -3,000000) còn lại là 2,000000<br />
Đối với fmod (-5,000000, -5,000000) còn lại là -,000000<br />
Lỗi: lỗi miền<br />
Đối với fmod (7.000000, 0.000000) còn lại là nan<br />
fmod (Tiếp theo)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 343<br />
fmodf<br />
Mô tả: Tính toán phần còn lại của x / y như một giá trị chính xác duy nhất.<br />
Bao gồm:<br />
Prototype: fmodf nổi (float x, float y);<br />
Đối số: xa đơn giá trị điểm chính xác nổi<br />
ya đơn chính xác nổi giá trị điểm<br />
Quay trở lại giá trị: Trả về phần còn lại của xdivided của y.<br />
Ghi chú: Nếu y = 0, một lỗi miền xảy ra. Nếu YIS khác không, kết quả sẽ có<br />
cùng dấu hiệu như xand tầm quan trọng của kết quả sẽ thấp hơn<br />
tầm quan trọng của y.<br />
Ví dụ: # include / * Cho fmodf * /<br />
# include / * Cho printf, perror * /<br />
# include / * Cho errno * /<br />
int main (void)<br />
{<br />
nổi x, y, z;<br />
errno = 0;
Return Value: Returns the largest integer value less than or equal to x.<br />
Remarks: No domain or range error will occur. See ceil.<br />
Example: #include /* for floor */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
double x[8] = {2.0, 1.75, 1.5, 1.25, -2.0,<br />
-1.75, -1.5, -1.25};<br />
double y;<br />
int i;<br />
for (i=0; i
-2.0F, -1.75F, -1.5F, -1.25F};<br />
float y;<br />
int i;<br />
for (i=0; i
perror("Error");<br />
printf("For fmod(%f, %f) the remainder is %f\n\n",<br />
x, y, z);<br />
floorf (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 342 2004 Microchip Technology Inc.<br />
errno = 0;<br />
x = 7.0;<br />
y = 7.0;<br />
z = fmod(x, y);<br />
if (errno)<br />
perror("Error");<br />
printf("For fmod(%f, %f) the remainder is %f\n\n",<br />
x, y, z);<br />
errno = 0;<br />
x = -5.0;<br />
y = 3.0;<br />
z = fmod(x, y);<br />
if (errno)<br />
perror("Error");<br />
printf("For fmod(%f, %f) the remainder is %f\n\n",<br />
x, y, z);<br />
errno = 0;<br />
x = 5.0;<br />
y = -3.0;<br />
z = fmod(x, y);<br />
if (errno)<br />
perror("Error");<br />
printf("For fmod(%f, %f) the remainder is %f\n\n",<br />
x, y, z);<br />
errno = 0;<br />
x = -5.0;<br />
y = -5.0;<br />
z = fmod(x, y);<br />
if (errno)<br />
perror("Error");<br />
printf("For fmod(%f, %f) the remainder is %f\n\n",<br />
fmodf (Tiếp theo)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 345<br />
x = 50.0;<br />
y = frexp (x, & n);<br />
printf ("Đối với frexp của% f \ n phần là% f \ n",<br />
x, y);<br />
printf ("và số mũ là% d \ n \ n", n);<br />
x = -2,5;<br />
y = frexp (x, & n);<br />
printf ("Đối với frexp của% f \ n phần là% f \ n",<br />
x, y);<br />
printf ("và số mũ là% d \ n \ n", n);<br />
x = 0,0;<br />
y = frexp (x, & n);<br />
printf ("Đối với frexp của% f \ n phần là% f \ n",<br />
x, y);<br />
printf ("và số mũ là% d \ n \ n", n);<br />
}<br />
Đầu ra:<br />
Đối với frexp của 50.000000<br />
phần là 0.781250<br />
và số mũ là 6<br />
Đối với frexp của -2,500000<br />
phần là -,625000<br />
và số mũ là 2<br />
Đối với frexp của 0.000000<br />
phần là 0.000000<br />
và số mũ là 0<br />
frexpf<br />
Mô tả: Được phần và số mũ của một điểm chính xác nổi duy nhất<br />
số.<br />
Bao gồm:<br />
Prototype: frexpf nổi (float x, int * exp);<br />
Đối số: x nổi giá trị điểm mà trả lại phần và<br />
số mũ<br />
* Exp con trỏ đến một số mũ nguyên lưu trữ<br />
Quay trở lại giá trị: Trả về phân số, exppoints với số mũ. Nếu XIS 0, chức năng<br />
trả về 0 cho cả hai phần và số mũ.<br />
Bình luận: Giá trị tuyệt đối của phần là trên cả chặng đường khoảng 1/2 (bao
x, y, z);<br />
errno = 0;<br />
x = 7.0;<br />
y = 0.0;<br />
z = fmod(x, y);<br />
if (errno)<br />
perror("Error");<br />
printf("For fmod(%f, %f) the remainder is %f\n\n",<br />
x, y, z);<br />
}<br />
Output:<br />
For fmod(7.000000, 3.000000) the remainder is 1.000000<br />
For fmod(7.000000, 7.000000) the remainder is 0.000000<br />
For fmod(-5.000000, 3.000000) the remainder is -2.000000<br />
For fmod(5.000000, -3.000000) the remainder is 2.000000<br />
For fmod(-5.000000, -5.000000) the remainder is -0.000000<br />
Error: domain error<br />
For fmod(7.000000, 0.000000) the remainder is nan<br />
fmod (Continued)<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 343<br />
fmodf<br />
Description: Calculates the remainder of x/y as a single precision value.<br />
Include: <br />
Prototype: float fmodf(float x, float y);<br />
Arguments: x a single precision floating point value<br />
y a single precision floating point value<br />
Return Value: Returns the remainder of xdivided by y.<br />
Remarks: If y= 0, a domain error occurs. If yis nonzero, the result will have the<br />
same sign as xand the magnitude of the result will be less than the<br />
magnitude of y.<br />
Example: #include /* for fmodf */<br />
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
float x,y,z;<br />
errno = 0;<br />
x = 7.0F;<br />
gồm) tới 1<br />
(Độc quyền). Không có lỗi miền orrange sẽ xảy ra.<br />
Ví dụ: # include / * Cho frexpf * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
float x, y;<br />
int n;<br />
frexp (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 346 2004 Microchip Technology Inc<br />
x = 0.15F;<br />
y = frexpf (x, & n);<br />
printf ("Đối với frexpf của% f \ n phần là% f \ n",<br />
x, y);<br />
printf ("và số mũ là% d \ n \ n", n);<br />
x = -2.5F;<br />
y = frexpf (x, & n);<br />
printf ("Đối với frexpf của% f \ n phần là% f \ n",<br />
x, y);<br />
printf ("và số mũ là% d \ n \ n", n);<br />
x = 0.0f;<br />
y = frexpf (x, & n);<br />
printf ("Đối với frexpf của% f \ n phần là% f \ n",<br />
x, y);<br />
printf ("và số mũ là% d \ n \ n", n);<br />
}<br />
Đầu ra:<br />
Đối với frexpf của 0.150000<br />
phần là 0.600000<br />
và số mũ là -2<br />
Đối với frexpf của -2,500000<br />
phần là -,625000<br />
và số mũ là 2<br />
Đối với frexpf của 0.000000<br />
phần là 0.000000<br />
và số mũ là 0
y = 3.0F;<br />
z = fmodf (x, y);<br />
if (errno)<br />
perror("Error");<br />
printf("For fmodf (%f, %f) the remainder is"<br />
" %f\n\n", x, y, z);<br />
errno = 0;<br />
x = -5.0F;<br />
y = 3.0F;<br />
z = fmodf (x, y);<br />
if (errno)<br />
perror("Error");<br />
printf("For fmodf (%f, %f)the remainder is"<br />
" %f\n\n", x, y, z);<br />
errno = 0;<br />
x = 5.0F;<br />
y = -3.0F;<br />
z = fmodf (x, y);<br />
if (errno)<br />
perror("Error");<br />
printf("For fmodf (%f, %f) the remainder is"<br />
" %f\n\n", x, y, z);<br />
errno = 0;<br />
x = 5.0F;<br />
y = -5.0F;<br />
z = fmodf (x, y);<br />
if (errno)<br />
perror("Error");<br />
printf("For fmodf (%f, %f) the remainder is"<br />
" %f\n\n", x, y, z);<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 344 2004 Microchip Technology Inc.<br />
errno = 0;<br />
x = 7.0F;<br />
y = 0.0F;<br />
z = fmodf (x, y);<br />
if (errno)<br />
ldexp<br />
Mô tả: Tính toán kết quả của một số điểm nổi doubleprecision<br />
nhân với số mũ của 2.<br />
Bao gồm:<br />
Prototype: ldexp đôi (double x, int cũ);<br />
Đối số: x nổi giá trị điểm<br />
số mũ nguyên cũ<br />
Quay trở lại giá trị: Trả về x * 2 ^ cũ. Trên một tràn, ldexpreturns infand trên<br />
Van cân bằng, ldexpreturns 0.<br />
Bình luận: Một lỗi xảy ra trên phạm vi sẽ tràn hoặc tràn dưới.<br />
Ví dụ: # include / * Cho ldexp * /<br />
# include / * Cho printf, perror * /<br />
# include / * Cho errno * /<br />
int main (void)<br />
{<br />
double x, y;<br />
int n;<br />
frexpf (Tiếp theo)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 347<br />
errno = 0;<br />
x = -0,625;<br />
n = 2;<br />
y = ldexp (x, n);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("Đối với một số =% fand một số mũ =% d \ n",<br />
x, n);<br />
printf ("ldexp (% f,% d) =% f \ n \ n",<br />
x, n, y);<br />
errno = 0;<br />
x = 2,5;<br />
n = 3;<br />
y = ldexp (x, n);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("Đối với một số =% fand một số mũ =% d \ n",<br />
x, n);<br />
printf ("ldexp (% f,% d) =% f \ n \ n",
perror("Error");<br />
printf("For fmodf (%f,%f) the remainder is"<br />
" %f\n\n", x, y, z);<br />
errno = 0;<br />
x = 7.0F;<br />
y = 7.0F;<br />
z = fmodf (x, y);<br />
if (errno)<br />
perror("Error");<br />
printf("For fmodf (%f,%f) the remainder is"<br />
" %f\n\n", x, y, z);<br />
}<br />
Output:<br />
For fmodf (7.000000,3.000000) the remainder is 1.000000<br />
For fmodf (-5.000000, 3.000000) the remainder is -2.000000<br />
For fmodf (5.000000, -3.000000) the remainder is 2.000000<br />
For fmodf (5.000000, -5.000000) the remainder is 0.000000<br />
Error: domain error<br />
For fmodf (7.000000,0.000000) the remainder is nan<br />
For fmodf (7.000000,7.000000) the remainder is 0.000000<br />
frexp<br />
Description: Gets the fraction and the exponent ofa double precision floating<br />
point<br />
number.<br />
Include: <br />
Prototype: double frexp (double x, int *exp);<br />
Arguments: x floating point value for which to return the fraction and<br />
exponent<br />
*exp pointer to a stored integer exponent<br />
Return Value: Returns the fraction, exppoints to the exponent. If xis 0, the<br />
function<br />
returns 0 for both the fraction and exponent.<br />
Remarks: The absolute value of the fraction is in the range of 1/2 (inclusive) to<br />
1<br />
(exclusive). No domain or range error will occur.<br />
Example: #include /* for frexp */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
double x,y;<br />
x, n, y);<br />
errno = 0;<br />
x = 15,0;<br />
n = 10000;<br />
y = ldexp (x, n);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("Đối với một số =% fand một số mũ =% d \ n",<br />
x, n);<br />
printf ("ldexp (% f,% d) =% f \ n \ n",<br />
x, n, y);<br />
}<br />
Đầu ra:<br />
Đối với một số = -,625000 và một số mũ = 2<br />
ldexp (-,625000, 2) = -2,500000<br />
Đối với một số = 2.500000 và một số mũ = 3<br />
ldexp (2.500000, 3) = 20,000000<br />
Lỗi: lỗi phạm vi<br />
Đối với một số = 15.000000 và một số mũ = 10000<br />
ldexp (15.000000, 10000) = inf<br />
ldexpf<br />
Mô tả: Tính toán kết quả của một số điểm chính xác đơn nổi<br />
nhân với số mũ của 2.<br />
Bao gồm:<br />
Prototype: ldexpf nổi (float x, int cũ);<br />
Đối số: x nổi giá trị điểm<br />
exinteger mũ<br />
Quay trở lại giá trị: Trả về x * 2 ^ cũ. Trên một tràn, ldexpreturns infand trên<br />
Van cân bằng, ldexpreturns 0.<br />
ldexp (Tiếp theo)<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 348 2004 Microchip Technology Inc<br />
Bình luận: Một lỗi xảy ra trên phạm vi sẽ tràn hoặc tràn dưới.<br />
Ví dụ: # include / * Cho ldexpf * /<br />
# include / * Cho printf, perror * /<br />
# include / * Cho errno * /<br />
int main (void)
int n;<br />
fmodf (Continued)<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 345<br />
x = 50.0;<br />
y = frexp (x, &n);<br />
printf("For frexp of %f\n the fraction is %f\n ",<br />
x, y);<br />
printf(" and the exponent is %d\n\n", n);<br />
x = -2.5;<br />
y = frexp (x, &n);<br />
printf("For frexp of %f\n the fraction is %f\n ",<br />
x, y);<br />
printf(" and the exponent is %d\n\n", n);<br />
x = 0.0;<br />
y = frexp (x, &n);<br />
printf("For frexp of %f\n the fraction is %f\n ",<br />
x, y);<br />
printf(" and the exponent is %d\n\n", n);<br />
}<br />
Output:<br />
For frexp of 50.000000<br />
the fraction is 0.781250<br />
and the exponent is 6<br />
For frexp of -2.500000<br />
the fraction is -0.625000<br />
and the exponent is 2<br />
For frexp of 0.000000<br />
the fraction is 0.000000<br />
and the exponent is 0<br />
frexpf<br />
Description: Gets the fraction and the exponent of a single precision floating<br />
point<br />
number.<br />
Include: <br />
Prototype: float frexpf (float x, int *exp);<br />
Arguments: x floating point value for which to return the fraction and<br />
exponent<br />
*exp pointer to a stored integer exponent<br />
{<br />
float x, y;<br />
int n;<br />
errno = 0;<br />
x = -0.625F;<br />
n = 2;<br />
y = ldexpf (x, n);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("Đối với một số =% fand một số mũ =% d \ n",<br />
x, n);<br />
printf ("ldexpf (% f,% d) =% f \ n \ n",<br />
x, n, y);<br />
errno = 0;<br />
x = 2.5F;<br />
n = 3;<br />
y = ldexpf (x, n);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("Đối với một số =% fand một số mũ =% d \ n",<br />
x, n);<br />
printf ("ldexpf (% f,% d) =% f \ n \ n",<br />
x, n, y);<br />
errno = 0;<br />
x = 15.0F;<br />
n = 10000;<br />
y = ldexpf (x, n);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("Đối với một số =% fand một số mũ =% d \ n",<br />
x, n);<br />
printf ("ldexpf (% f,% d) =% f \ n \ n",<br />
x, n, y);<br />
}<br />
Đầu ra:<br />
Đối với một số = -,625000 và một số mũ = 2<br />
ldexpf (-,625000, 2) = -2,500000<br />
Đối với một số = 2.500000 và một số mũ = 3<br />
ldexpf (2.500000, 3) = 20,000000
Return Value: Returns the fraction, exppoints to the exponent. If xis 0, the<br />
function<br />
returns 0 for both the fraction and exponent.<br />
Remarks: The absolute value of the fraction is inthe range of 1/2 (inclusive) to 1<br />
(exclusive). No domain orrange error will occur.<br />
Example: #include /* for frexpf */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
float x,y;<br />
int n;<br />
frexp (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
Lỗi: lỗi phạm vi<br />
Đối với một số = 15.000000 và một số mũ = 10000<br />
ldexpf (15.000000, 10000) = inf<br />
ldexpf (Tiếp theo)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 349<br />
đăng nhập<br />
Mô tả: Tính logarit tự nhiên của một điểm chính xác đôi nổi<br />
giá trị.<br />
Bao gồm:<br />
Nguyên mẫu: đăng nhập tăng gấp đôi (double x);<br />
Đối số: x bất kỳ giá trị tích cực mà trả lại đăng nhập<br />
Quay trở lại giá trị: Trả về logarit tự nhiên của x. -infis trả lại nếu XIS 0 và NaN<br />
trả lại nếu XIS một số âm.<br />
Bình luận: Một lỗi miền xảy ra nếu x ≤0.<br />
DS51456B-page 346<br />
x = 0.15F;<br />
y = frexpf (x, &n);<br />
2004 Microchip Technology Inc.<br />
Ví dụ: # include / * Để đăng nhập * /<br />
# include / * Cho printf, perror * /<br />
# include / * Cho errno * /<br />
printf("For frexpf of %f\n the fraction is %f\n ",<br />
x, y);<br />
printf(" and the exponent is %d\n\n", n);<br />
x = -2.5F;<br />
y = frexpf (x, &n);<br />
printf("For frexpf of %f\n the fraction is %f\n ",<br />
x, y);<br />
printf(" and the exponent is %d\n\n", n);<br />
x = 0.0F;<br />
y = frexpf (x, &n);<br />
printf("For frexpf of %f\n the fraction is %f\n ",<br />
x, y);<br />
printf(" and the exponent is %d\n\n", n);<br />
}<br />
Output:<br />
For frexpf of 0.150000<br />
the fraction is 0.600000<br />
and the exponent is -2<br />
For frexpf of -2.500000<br />
the fraction is -0.625000<br />
and the exponent is 2<br />
int main (void)<br />
{<br />
double x, y;<br />
errno = 0;<br />
x = 2,0;<br />
y = log (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("logarit tự nhiên của% f% f \ n \ n",<br />
x, y);<br />
errno = 0;<br />
x = 0,0;<br />
y = log (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("logarit tự nhiên của% f% f \ n \ n",<br />
x, y);<br />
errno = 0;<br />
x = -2,0;<br />
y = log (x);<br />
if (errno)
For frexpf of 0.000000<br />
the fraction is 0.000000<br />
and the exponent is 0<br />
ldexp<br />
Description: Calculates the result of a doubleprecision floating point number<br />
multiplied by an exponent of 2.<br />
Include: <br />
Prototype: double ldexp(double x, int ex);<br />
Arguments: x floating point value<br />
ex integer exponent<br />
Return Value: Returns x* 2^ex. On an overflow, ldexpreturns infand on an<br />
underflow, ldexpreturns 0.<br />
Remarks: A range error will occur on overflow or underflow.<br />
Example: #include /* for ldexp */<br />
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
double x,y;<br />
int n;<br />
frexpf (Continued)<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 347<br />
errno = 0;<br />
x = -0.625;<br />
n = 2;<br />
y = ldexp (x, n);<br />
if (errno)<br />
perror("Error");<br />
printf("For a number = %fand an exponent = %d\n",<br />
x, n);<br />
printf(" ldexp(%f, %d) = %f\n\n",<br />
x, n, y);<br />
errno = 0;<br />
x = 2.5;<br />
n = 3;<br />
y = ldexp (x, n);<br />
if (errno)<br />
perror("Error");<br />
perror ("Lỗi");<br />
printf ("logarit tự nhiên của% f% f \ n \ n",<br />
x, y);<br />
}<br />
Đầu ra:<br />
Các of2.000000 logarit tự nhiên là 0,693147<br />
Các of0.000000 logarit tự nhiên là -INF<br />
Lỗi: lỗi miền<br />
Logarit tự nhiên của -2,000000 là nan<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 350 2004 Microchip Technology Inc<br />
log10<br />
Mô tả: Tính logarit cơ số 10 của một điểm chính xác đôi nổi<br />
giá trị.<br />
Bao gồm:<br />
Prototype: log10 đôi (double x);<br />
Đối số: x bất kỳ độ chính xác kép nổi điểm số dương<br />
Quay trở lại giá trị: Trả về logarit cơ số 10 của x. -infis trả lại nếu XIS 0 và NaN<br />
được trả lại nếu XIS một số âm.<br />
Bình luận: Một lỗi miền xảy ra nếu x ≤0.<br />
Ví dụ: # include / * Cho log10 * /<br />
# include / * Cho printf, perror * /<br />
# include / * Cho errno * /<br />
int main (void)<br />
{<br />
double x, y;<br />
errno = 0;<br />
x = 2,0;<br />
y = log10 (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("Các cơ sở-10 logarit% f% f \ n \ n",<br />
x, y);<br />
errno = 0;<br />
x = 0,0;<br />
y = log10 (x);<br />
if (errno)
printf("For a number = %fand an exponent = %d\n",<br />
x, n);<br />
printf(" ldexp(%f, %d) = %f\n\n",<br />
x, n, y);<br />
errno = 0;<br />
x = 15.0;<br />
n = 10000;<br />
y = ldexp (x, n);<br />
if (errno)<br />
perror("Error");<br />
printf("For a number = %fand an exponent = %d\n",<br />
x, n);<br />
printf(" ldexp(%f, %d) = %f\n\n",<br />
x, n, y);<br />
}<br />
Output:<br />
For a number = -0.625000 and an exponent = 2<br />
ldexp(-0.625000, 2) = -2.500000<br />
For a number = 2.500000 and an exponent = 3<br />
ldexp(2.500000, 3) = 20.000000<br />
Error: range error<br />
For a number = 15.000000 and an exponent = 10000<br />
ldexp(15.000000, 10000) = inf<br />
ldexpf<br />
Description: Calculates the result of a single precision floating point number<br />
multiplied by an exponent of 2.<br />
Include: <br />
Prototype: float ldexpf(float x, int ex);<br />
Arguments: x floating point value<br />
exinteger exponent<br />
Return Value: Returns x* 2^ex. On an overflow, ldexpreturns infand on an<br />
underflow, ldexpreturns 0.<br />
ldexp (Continued)<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 348 2004 Microchip Technology Inc.<br />
Remarks: A range error will occur on overflow or underflow.<br />
Example: #include /* for ldexpf */<br />
perror ("Lỗi");<br />
printf ("Các cơ sở-10 logarit% f% f \ n \ n",<br />
x, y);<br />
errno = 0;<br />
x = -2,0;<br />
y = log10 (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("Các cơ sở-10 logarit% f% f \ n \ n",<br />
x, y);<br />
}<br />
Đầu ra:<br />
Các cơ sở of2.000000-10 logarit là 0,301030<br />
Các cơ sở-10 logarit 0.000000 là -INF<br />
Lỗi: lỗi miền<br />
Các cơ sở-10 logarit-2,000000 là nan<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 351<br />
log10f<br />
Mô tả: Tính điểm cơ số 10 logarit ofa độ chính xác đơn nổi<br />
giá trị.<br />
Bao gồm:<br />
Prototype: log10f nổi (float x);<br />
Đối số: x bất kỳ chính xác duy nhất nổi điểm số dương<br />
Quay trở lại giá trị: Trả về logarit cơ số 10 của x. -infis trả lại nếu XIS 0 và NaN<br />
được trả lại nếu XIS một số âm.<br />
Bình luận: Một lỗi miền xảy ra nếu x ≤0.<br />
Ví dụ: # include / * Cho log10f * /<br />
# include / * Cho printf, perror * /<br />
# include / * Cho errno * /<br />
int main (void)<br />
{<br />
float x, y;<br />
errno = 0;<br />
x = 2.0F;<br />
y = log10f (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("Các cơ sở-10 logarit% f% f \ n \ n",
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
float x,y;<br />
int n;<br />
errno = 0;<br />
x = -0.625F;<br />
n = 2;<br />
y = ldexpf (x, n);<br />
if (errno)<br />
perror("Error");<br />
printf("For a number = %fand an exponent = %d\n",<br />
x, n);<br />
printf(" ldexpf(%f, %d) = %f\n\n",<br />
x, n, y);<br />
errno = 0;<br />
x = 2.5F;<br />
n = 3;<br />
y = ldexpf (x, n);<br />
if (errno)<br />
perror("Error");<br />
printf("For a number = %fand an exponent = %d\n",<br />
x, n);<br />
printf(" ldexpf(%f, %d) = %f\n\n",<br />
x, n, y);<br />
errno = 0;<br />
x = 15.0F;<br />
n = 10000;<br />
y = ldexpf (x, n);<br />
if (errno)<br />
perror("Error");<br />
printf("For a number = %fand an exponent = %d\n",<br />
x, n);<br />
printf(" ldexpf(%f, %d) = %f\n\n",<br />
x, n, y);<br />
}<br />
Output:<br />
For a number = -0.625000 and an exponent = 2<br />
x, y);<br />
errno = 0;<br />
x = 0.0f;<br />
y = log10f (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("Các cơ sở-10 logarit% f% f \ n \ n",<br />
x, y);<br />
errno = 0;<br />
x = -2.0F;<br />
y = log10f (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("Các cơ sở-10 logarit% f% f \ n \ n",<br />
x, y);<br />
}<br />
Đầu ra:<br />
Các cơ sở of2.000000-10 logarit là 0,301030<br />
Lỗi: lỗi miền<br />
Các cơ sở-10 logarit of0.000000 là -INF<br />
Lỗi: lỗi miền<br />
Các cơ sở-10 logarit -2,000000 là nan<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 352 2004 Microchip Technology Inc<br />
logf<br />
Mô tả: Tính logarit tự nhiên của một điểm chính xác nổi duy nhất<br />
giá trị.<br />
Bao gồm:<br />
Prototype: logf nổi (float x);<br />
Đối số: x bất kỳ giá trị tích cực mà trả lại đăng nhập<br />
Quay trở lại giá trị: Trả về logarit tự nhiên của x. -infis trả lại nếu XIS 0 và NaN<br />
trả lại nếu XIS một số âm.<br />
Bình luận: Một lỗi miền xảy ra nếu x ≤0.<br />
Ví dụ: # include / * Cho logf * /<br />
# include / * Cho printf, perror * /<br />
# include / * Cho errno * /<br />
int main (void)
ldexpf(-0.625000, 2) = -2.500000<br />
For a number = 2.500000 and an exponent = 3<br />
ldexpf(2.500000, 3) = 20.000000<br />
Error: range error<br />
For a number = 15.000000 and an exponent = 10000<br />
ldexpf(15.000000, 10000) = inf<br />
ldexpf (Continued)<br />
Standard C Libraries with Math Functions<br />
log<br />
2004 Microchip Technology Inc. DS51456B-page 349<br />
Description: Calculates the natural logarithm of a double precision floating<br />
point<br />
value.<br />
Include: <br />
Prototype: double log(double x);<br />
Argument: x any positive value for which to return the log<br />
Return Value: Returns the natural logarithm of x. -infis returned if xis 0 and<br />
NaN is<br />
returned if xis a negative number.<br />
Remarks: A domain error occurs if x ≤0.<br />
Example: #include /* for log*/<br />
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
double x, y;<br />
errno = 0;<br />
x = 2.0;<br />
y = log (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The natural logarithm of %f is %f\n\n",<br />
x, y);<br />
errno = 0;<br />
x = 0.0;<br />
y = log (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The natural logarithm of %f is %f\n\n",<br />
x, y);<br />
{<br />
float x, y;<br />
errno = 0;<br />
x = 2.0F;<br />
y = logf (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("logarit tự nhiên của% f% f \ n \ n",<br />
x, y);<br />
errno = 0;<br />
x = 0.0f;<br />
y = logf (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("logarit tự nhiên của% f% f \ n \ n",<br />
x, y);<br />
errno = 0;<br />
x = -2.0F;<br />
y = logf (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("logarit tự nhiên của% f% f \ n \ n",<br />
x, y);<br />
}<br />
Đầu ra:<br />
Các of2.000000 logarit tự nhiên là 0,693147<br />
Logarit tự nhiên của 0.000000 là -INF<br />
Lỗi: lỗi miền<br />
Logarit tự nhiên của-2.000000 là nan<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 353<br />
modf<br />
Mô tả: Tách một độ chính xác kép nổi pointvalue vào phân đoạn và số nguyên<br />
các bộ phận.<br />
Bao gồm:<br />
Prototype: modf đôi (double x, double * pint);<br />
Đối số: x độ chính xác gấp đôi giá trị dấu chấm động<br />
pint con trỏ để lưu trữ một phần nguyên<br />
Quay trở lại giá trị: Trả về phần thập phân có chữ ký và pintpoints đến phần<br />
nguyên.
errno = 0;<br />
x = -2.0;<br />
y = log (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The natural logarithm of %f is %f\n\n",<br />
x, y);<br />
}<br />
Output:<br />
The natural logarithm of2.000000 is 0.693147<br />
The natural logarithm of0.000000 is -inf<br />
Error: domain error<br />
The natural logarithm of -2.000000 is nan<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
Bình luận: Giá trị tuyệt đối của các phần phân đoạn nằm trong khoảng từ 0 (bao<br />
gồm)<br />
1 (độc quyền). Không có lỗi nhiều domainor sẽ xảy ra.<br />
Ví dụ: # include / * Cho modf * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
double x, y, n;<br />
x = 0,707;<br />
y = modf (x, & n);<br />
printf ("% f Đối với phần là% f \ n", x, y);<br />
printf ("và các số nguyên là 0.f% \ n \ n", n);<br />
x = -15,2121;<br />
y = modf (x, & n);<br />
printf ("% f Đối với phần là% f \ n", x, y);<br />
printf ("và các số nguyên là 0.f% \ n \ n", n);<br />
}<br />
DS51456B-page 350<br />
log10<br />
2004 Microchip Technology Inc.<br />
Đầu ra:<br />
Đối với 0.707000 phần là 0.707000<br />
Description: Calculates the base-10 logarithm of a double precision floating<br />
point<br />
value.<br />
Include: <br />
Prototype: double log10(double x);<br />
Argument: x any double precision floating point positive number<br />
Return Value: Returns the base-10 logarithm of x. -infis returned if xis 0 and<br />
NaN<br />
is returned if xis a negative number.<br />
Remarks: A domain error occurs if x ≤0.<br />
Example: #include /* for log10 */<br />
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
double x, y;<br />
errno = 0;<br />
x = 2.0;<br />
y = log10 (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The base-10 logarithm of %f is %f\n\n",<br />
và các số nguyên là 0<br />
Đối với -15,212100 phần là -,212100<br />
và các số nguyên là -15<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 354<br />
modff<br />
2004 Microchip Technology Inc<br />
Mô tả: Tách một độ chính xác giá trị dấu chấm duy nhất vào phân đoạn và số<br />
nguyên<br />
các bộ phận.<br />
Bao gồm:<br />
Prototype: modff nổi (float x, float * pint);<br />
Đối số: x độ chính xác đơn giá trị dấu chấm<br />
con trỏ pint để phần nguyên lưu trữ<br />
Quay trở lại giá trị: Trả về phần thập phân có chữ ký và pintpoints đến phần<br />
nguyên.<br />
Bình luận: Giá trị tuyệt đối của các phần phân đoạn nằm trong khoảng từ 0 (bao<br />
gồm)<br />
1 (độc quyền). Không có lỗi nhiều domainor sẽ xảy ra.<br />
Ví dụ: # include / * Cho modff * /<br />
# include / * Cho printf * /
x, y);<br />
errno = 0;<br />
x = 0.0;<br />
y = log10 (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The base-10 logarithm of %f is %f\n\n",<br />
x, y);<br />
errno = 0;<br />
x = -2.0;<br />
y = log10 (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The base-10 logarithm of %f is %f\n\n",<br />
x, y);<br />
}<br />
Output:<br />
The base-10 logarithm of2.000000 is 0.301030<br />
The base-10 logarithm of 0.000000 is -inf<br />
Error: domain error<br />
The base-10 logarithm of-2.000000 is nan<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 351<br />
log10f<br />
Description: Calculates the base-10 logarithm ofa single precision floating point<br />
value.<br />
Include: <br />
Prototype: float log10f(float x);<br />
Argument: x any single precision floating point positive number<br />
Return Value: Returns the base-10 logarithm of x. -infis returned if xis 0 and<br />
NaN<br />
is returned if xis a negative number.<br />
Remarks: A domain error occurs if x ≤0.<br />
Example: #include /* for log10f */<br />
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
float x, y;<br />
int main (void)<br />
{<br />
float x, y, n;<br />
x = 0.707F;<br />
y = modff (x, & n);<br />
printf ("% f Đối với phần là% f \ n", x, y);<br />
printf ("và các số nguyên là 0.f% \ n \ n", n);<br />
x = -15.2121F;<br />
y = modff (x, & n);<br />
printf ("% f Đối với phần là% f \ n", x, y);<br />
printf ("và các số nguyên là 0.f% \ n \ n", n);<br />
}<br />
Đầu ra:<br />
Đối với 0.707000 phần là 0.707000<br />
và các số nguyên là 0<br />
Đối với -15,212100 phần là -,212100<br />
và các số nguyên là -15<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 355<br />
pow<br />
Mô tả: Tính x lũy thừa y.<br />
Bao gồm:<br />
Prototype: pow đôi (double x, double y);<br />
Đối số: x cơ sở<br />
mũ ythe<br />
Quay trở lại giá trị: Trả về xraised cho y sức mạnh (x ^ y).<br />
Ghi chú: Nếu YIS 0 powreturns 1 Nếu XIS 0.0 và YIS nhỏ hơn 0 powreturns in<br />
và một lỗi xảy ra miền. Nếu tràn kết quả hoặc underflows, một<br />
phạm vi lỗi xảy ra.<br />
Ví dụ: # include / * Cho pow * /<br />
# include / * Cho printf, perror * /<br />
# include / * Cho errno * /<br />
int main (void)<br />
{<br />
double x, y, z;<br />
errno = 0;<br />
x = -2,0;<br />
y = 3,0;<br />
z = pow (x, y);
errno = 0;<br />
x = 2.0F;<br />
y = log10f(x);<br />
if (errno)<br />
perror("Error");<br />
printf("The base-10 logarithm of %f is %f\n\n",<br />
x, y);<br />
errno = 0;<br />
x = 0.0F;<br />
y = log10f(x);<br />
if (errno)<br />
perror("Error");<br />
printf("The base-10 logarithm of %f is %f\n\n",<br />
x, y);<br />
errno = 0;<br />
x = -2.0F;<br />
y = log10f(x);<br />
if (errno)<br />
perror("Error");<br />
printf("The base-10 logarithm of %f is %f\n\n",<br />
x, y);<br />
}<br />
Output:<br />
The base-10 logarithm of2.000000 is 0.301030<br />
Error: domain error<br />
The base-10 logarithm of0.000000 is -inf<br />
Error: domain error<br />
The base-10 logarithm of -2.000000 is nan<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 352 2004 Microchip Technology Inc.<br />
logf<br />
Description: Calculates the natural logarithm of a single precision floating point<br />
value.<br />
Include: <br />
Prototype: float logf(float x);<br />
Argument: x any positive value for which to return the log<br />
Return Value: Returns the natural logarithm of x. -infis returned if xis 0 and<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("% f% f nâng lên là% f \ n \ n", x, y, z);<br />
errno = 0;<br />
x = 3,0;<br />
y = -0,5;<br />
z = pow (x, y);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("% f% f nâng lên là% f \ n \ n", x, y, z);<br />
errno = 0;<br />
x = 4,0;<br />
y = 0.0;<br />
z = pow (x, y);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("% f% f nâng lên là% f \ n \ n", x, y, z);<br />
errno = 0;<br />
x = 0,0;<br />
y = -3,0;<br />
z = pow (x, y);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("% f% f nâng lên là% f \ n \ n", x, y, z);<br />
}<br />
Đầu ra:<br />
-2,000000 Nâng lên 3,000000 là -8,000000<br />
3.000000 nâng lên -,500000 là 0,577350<br />
4.000000 nâng lên là 0.000000 1.000000<br />
Lỗi: lỗi miền<br />
0.000000 nâng lên -3,000000 là inf<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 356 2004 Microchip Technology Inc<br />
powf<br />
Mô tả: Tính x lũy thừa y.<br />
Bao gồm:<br />
Prototype: powf nổi (float x, float y);
NaN is<br />
returned if xis a negative number.<br />
Remarks: A domain error occurs if x ≤0.<br />
Example: #include /* for logf */<br />
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
float x, y;<br />
errno = 0;<br />
x = 2.0F;<br />
y = logf (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The natural logarithm of %f is %f\n\n",<br />
x, y);<br />
errno = 0;<br />
x = 0.0F;<br />
y = logf (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The natural logarithm of %f is %f\n\n",<br />
x, y);<br />
errno = 0;<br />
x = -2.0F;<br />
y = logf (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The natural logarithm of %f is %f\n\n",<br />
x, y);<br />
}<br />
Output:<br />
The natural logarithm of2.000000 is 0.693147<br />
The natural logarithm of 0.000000 is -inf<br />
Error: domain error<br />
The natural logarithm of-2.000000 is nan<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 353<br />
modf<br />
Đối số: Xbase<br />
yexponent<br />
Quay trở lại giá trị: Trả về xraised cho y sức mạnh (x ^ y).<br />
Ghi chú: Nếu YIS 0 powfreturns 1 Nếu XIS 0.0 và YIS nhỏ hơn 0 powfreturns<br />
infand một lỗi miền xảy ra. Nếu tràn kết quả hoặc underflows, một<br />
phạm vi lỗi xảy ra.<br />
Ví dụ: # include / * Cho powf * /<br />
# include / * Cho printf, perror * /<br />
# include / * Cho errno * /<br />
int main (void)<br />
{<br />
nổi x, y, z;<br />
errno = 0;<br />
x = -2.0F;<br />
y = 3.0F;<br />
z = powf (x, y);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("% f% f nâng lên là% f \ n \ n", x, y, z);<br />
errno = 0;<br />
x = 3.0F;<br />
y = -0.5F;<br />
z = powf (x, y);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("% f% f nâng lên là% f \ n \ n", x, y, z);<br />
errno = 0;<br />
x = 0.0f;<br />
y = -3.0F;<br />
z = powf (x, y);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("% f% f nâng lên là% f \ n \ n", x, y, z);<br />
}<br />
Đầu ra:<br />
-2,000000 Nâng lên 3,000000 là -8,000000<br />
3.000000 nâng lên -,500000 là 0,577350<br />
Lỗi: lỗi miền<br />
0.000000 nâng lên -3,000000 là inf
Description: Splits a double precision floating pointvalue into fractional and<br />
integer<br />
parts.<br />
Include: <br />
Prototype: double modf(double x, double *pint);<br />
Arguments: x double precision floating point value<br />
pint pointer to a stored the integer part<br />
Return Value: Returns the signed fractional part and pintpoints to the integer<br />
part.<br />
Remarks: The absolute value of the fractional part is in the range of 0<br />
(inclusive)<br />
to 1 (exclusive). No domainor range error will occur.<br />
Example: #include /*for modf */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
double x,y,n;<br />
x = 0.707;<br />
y = modf (x, &n);<br />
printf("For %f the fraction is %f\n ", x, y);<br />
printf(" and the integer is %0.f\n\n", n);<br />
x = -15.2121;<br />
y = modf (x, &n);<br />
printf("For %f the fraction is %f\n ", x, y);<br />
printf(" and the integer is %0.f\n\n", n);<br />
}<br />
Output:<br />
For 0.707000 the fraction is 0.707000<br />
and the integer is 0<br />
For -15.212100 the fraction is -0.212100<br />
and the integer is -15<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 354<br />
modff<br />
2004 Microchip Technology Inc.<br />
Description: Splits a single precision floating point value into fractional and<br />
integer<br />
parts.<br />
Include: <br />
Prototype: float modff(float x, float *pint);<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 357<br />
tội lỗi<br />
Mô tả: Tính hàm lượng giác sin của một độ chính xác kép nổi<br />
giá trị điểm.<br />
Bao gồm:<br />
Prototype: tội lỗi kép (double x);<br />
Đối số: x giá trị mà trả lại sin<br />
Quay trở lại giá trị: Trả về sin xin radian trong phạm vi của -1 đến 1 bao gồm.<br />
Bình luận: Một lỗi miền sẽ xảy ra nếu t XIS một NaN hoặc vô cùng.<br />
Ví dụ: # include / * Tội lỗi * /<br />
# include / * Cho printf, perror * /<br />
# include / * Cho errno * /<br />
int main (void)<br />
{<br />
double x, y;<br />
errno = 0;<br />
x = -1,0;<br />
y = sin (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("sin của FIS%% f \ n \ n", x, y);<br />
errno = 0;<br />
x = 0,0;<br />
y = sin (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("sin của FIS%% f \ n \ n", x, y);<br />
}<br />
Đầu ra:<br />
Sin của -1,000000 là -,841471<br />
Sin của 0.000000 là 0.000000<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 358 2004 Microchip Technology Inc<br />
sinf<br />
Mô tả: Tính hàm lượng giác sin của một độ chính xác đơn nổi<br />
giá trị điểm.
Arguments: x single precision floating point value<br />
pint pointer to stored integer part<br />
Return Value: Returns the signed fractional part and pintpoints to the integer<br />
part.<br />
Remarks: The absolute value of the fractional part is in the range of 0<br />
(inclusive)<br />
to 1 (exclusive). No domainor range error will occur.<br />
Example: #include /* for modff */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
float x,y,n;<br />
x = 0.707F;<br />
y = modff (x, &n);<br />
printf("For %f the fraction is %f\n ", x, y);<br />
printf(" and the integer is %0.f\n\n", n);<br />
x = -15.2121F;<br />
y = modff (x, &n);<br />
printf("For %f the fraction is %f\n ", x, y);<br />
printf(" and the integer is %0.f\n\n", n);<br />
}<br />
Output:<br />
For 0.707000 the fraction is 0.707000<br />
and the integer is 0<br />
For -15.212100 the fraction is -0.212100<br />
and the integer is -15<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 355<br />
pow<br />
Description: Calculates x raised to the power y.<br />
Include: <br />
Prototype: double pow(double x, double y);<br />
Arguments: x the base<br />
ythe exponent<br />
Return Value: Returns xraised to the power y(x^y).<br />
Remarks: If yis 0 powreturns 1. If xis 0.0 and yis less than 0 powreturns inf<br />
and a domain error occurs. If the result overflows or underflows, a<br />
range error occurs.<br />
Example: #include /* for pow*/<br />
#include /* for printf, perror */<br />
Bao gồm:<br />
Prototype: sinf nổi (float x);<br />
Đối số: x giá trị mà trả lại sin<br />
Quay trở lại giá trị: Trả về tội xin radian trong phạm vi của -1 đến 1 bao gồm.<br />
Bình luận: Một lỗi miền sẽ xảy ra nếu XIS một NaN hoặc vô cùng.<br />
Ví dụ: # include / * Cho sinf * /<br />
# include / * Cho printf, perror * /<br />
# include / * Cho errno * /<br />
int main (void)<br />
{<br />
float x, y;<br />
errno = 0;<br />
x = -1.0F;<br />
y = sinf (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("sin của% f% f \ n \ n", x, y);<br />
errno = 0;<br />
x = 0.0f;<br />
y = sinf (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("sin của% f% f \ n \ n", x, y);<br />
}<br />
Đầu ra:<br />
Sin của -1,000000 là -,841471<br />
Sin của 0.000000 là 0.000000<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 359<br />
sinh<br />
Mô tả: Tính hàm sin hyperbol của một độ chính xác gấp đôi nổi<br />
giá trị điểm.<br />
Bao gồm:<br />
Prototype: sinh đôi (double x);<br />
Đối số: x giá trị mà trả lại sin hyperbol<br />
Quay trở lại giá trị: Trả về sin hyperbol của x<br />
Bình luận: Một loạt lỗi sẽ xảy ra nếu độ lớn của XIS quá lớn.<br />
Ví dụ: # include / * Cho sinh * /<br />
# include / * Cho printf, perror * /
#include /* for errno */<br />
int main(void)<br />
{<br />
double x,y,z;<br />
errno = 0;<br />
x = -2.0;<br />
y = 3.0;<br />
z = pow (x, y);<br />
if (errno)<br />
perror("Error");<br />
printf("%f raised to %f is %f\n\n ", x, y, z);<br />
errno = 0;<br />
x = 3.0;<br />
y = -0.5;<br />
z = pow (x, y);<br />
if (errno)<br />
perror("Error");<br />
printf("%f raised to %f is %f\n\n ", x, y, z);<br />
errno = 0;<br />
x = 4.0;<br />
y = 0.0;<br />
z = pow (x, y);<br />
if (errno)<br />
perror("Error");<br />
printf("%f raised to %f is %f\n\n ", x, y, z);<br />
errno = 0;<br />
x = 0.0;<br />
y = -3.0;<br />
z = pow (x, y);<br />
if (errno)<br />
perror("Error");<br />
printf("%f raised to %f is %f\n\n ", x, y, z);<br />
}<br />
Output:<br />
-2.000000 raised to 3.000000 is -8.000000<br />
3.000000 raised to -0.500000 is 0.577350<br />
4.000000 raised to 0.000000 is 1.000000<br />
Error: domain error<br />
0.000000 raised to -3.000000 is inf<br />
# include / * Cho errno * /<br />
int main (void)<br />
{<br />
double x, y;<br />
errno = 0;<br />
x = -1,5;<br />
y = sinh (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("sin hyperbol của% f% f \ n \ n",<br />
x, y);<br />
errno = 0;<br />
x = 0,0;<br />
y = sinh (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("sin hyperbol của% f% f \ n \ n",<br />
x, y);<br />
errno = 0;<br />
x = 720,0;<br />
y = sinh (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("sin hyperbol của% f% f \ n \ n",<br />
x, y);<br />
}<br />
Đầu ra:<br />
Sin hyperbol của -1,500000 là -2,129279<br />
Sin hyperbol của 0.000000 là 0.000000<br />
Lỗi: lỗi phạm vi<br />
Sin hyperbol của 720.000000 là inf<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 360 2004 Microchip Technology Inc<br />
sinhf<br />
Mô tả: Tính hàm sin hyperbol của một độ chính xác đơn nổi<br />
giá trị điểm.<br />
Bao gồm:
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 356 2004 Microchip Technology Inc.<br />
powf<br />
Description: Calculates x raised to the power y.<br />
Include: <br />
Prototype: float powf(float x, float y);<br />
Arguments: xbase<br />
yexponent<br />
Return Value: Returns xraised to the power y(x^y).<br />
Remarks: If yis 0 powfreturns 1. If xis 0.0 and yis less than 0 powfreturns<br />
infand a domain error occurs. If the result overflows or underflows, a<br />
range error occurs.<br />
Example: #include /* for powf */<br />
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
float x,y,z;<br />
errno = 0;<br />
x = -2.0F;<br />
y = 3.0F;<br />
z = powf (x, y);<br />
if (errno)<br />
perror("Error");<br />
printf("%f raised to %f is%f\n\n ", x, y, z);<br />
errno = 0;<br />
x = 3.0F;<br />
y = -0.5F;<br />
z = powf (x, y);<br />
if (errno)<br />
perror("Error");<br />
printf("%f raised to %f is%f\n\n ", x, y, z);<br />
errno = 0;<br />
x = 0.0F;<br />
y = -3.0F;<br />
z = powf (x, y);<br />
if (errno)<br />
Prototype: sinhf nổi (float x);<br />
Đối số: x giá trị mà trả lại sin hyperbol<br />
Quay trở lại giá trị: Trả về sin hyperbol của x<br />
Bình luận: Một loạt lỗi sẽ xảy ra nếu độ lớn của XIS quá lớn.<br />
Ví dụ: # include / * Cho sinhf * /<br />
# include / * Cho printf, perror * /<br />
# include / * Cho errno * /<br />
int main (void)<br />
{<br />
float x, y;<br />
errno = 0;<br />
x = -1.0F;<br />
y = sinhf (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("sin hyperbol của% f% f \ n \ n",<br />
x, y);<br />
errno = 0;<br />
x = 0.0f;<br />
y = sinhf (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("sin hyperbol của% f% f \ n \ n",<br />
x, y);<br />
}<br />
Đầu ra:<br />
Sin hyperbol của -1,000000 là -1,175201<br />
Sin hyperbol của 0.000000 là 0.000000<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 361<br />
sqrt<br />
Mô tả: Tính căn bậc hai của một giá trị chính xác điểm nổi gấp đôi.<br />
Bao gồm:<br />
Prototype: sqrt đôi (double x);<br />
Đối số: xa không âm giá trị dấu chấm<br />
Quay trở lại giá trị: Trả về căn không negativesquare của x ..<br />
Ghi chú: Nếu XIS tiêu cực, một lỗi miền xảy ra.<br />
Ví dụ: # include / * Cho sqrt * /<br />
# include / * Cho printf, perror * /
perror("Error");<br />
printf("%f raised to %f is%f\n\n ", x, y, z);<br />
}<br />
Output:<br />
-2.000000 raised to 3.000000 is -8.000000<br />
3.000000 raised to -0.500000 is 0.577350<br />
Error: domain error<br />
0.000000 raised to -3.000000 is inf<br />
Standard C Libraries with Math Functions<br />
sin<br />
2004 Microchip Technology Inc. DS51456B-page 357<br />
Description: Calculates the trigonometric sine function of a double precision<br />
floating<br />
point value.<br />
Include: <br />
Prototype: double sin (double x);<br />
Argument: x value for which to return the sine<br />
Return Value: Returns the sine of xin radians in the ranges of -1 to 1 inclusive.<br />
Remarks: A domain error will occur if t xis a NaN or infinity.<br />
Example: #include /* for sin*/<br />
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
double x, y;<br />
errno = 0;<br />
x = -1.0;<br />
y = sin (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The sine of %fis %f\n\n", x, y);<br />
# include / * Cho errno * /<br />
int main (void)<br />
{<br />
double x, y;<br />
errno = 0;<br />
x = 0,0;<br />
y = sqrt (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("căn bậc hai của% f% f \ n \ n", x, y);<br />
errno = 0;<br />
x = 9,5;<br />
y = sqrt (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("căn bậc hai của% f% f \ n \ n", x, y);<br />
errno = 0;<br />
x = -25,0;<br />
y = sqrt (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("căn bậc hai của% f% f \ n \ n", x, y);<br />
}<br />
Đầu ra:<br />
Căn bậc hai của 0.000000 là 0.000000<br />
Căn bậc hai của 9.500000 là 3.082207<br />
Lỗi: lỗi miền<br />
Căn bậc hai của -25,000000 là nan<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
errno = 0;<br />
x = 0.0;<br />
DS51456B trang 362<br />
sqrtf<br />
2004 Microchip Technology Inc<br />
y = sin (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The sine of %fis %f\n\n", x, y);<br />
}<br />
Output:<br />
Mô tả: Tính căn bậc hai của một giá trị chính xác điểm nổi duy nhất.<br />
Bao gồm:<br />
Prototype: sqrtf nổi (float x);<br />
Đối số: x không âm giá trị dấu chấm<br />
Quay trở lại giá trị: Trả về căn bậc hai không âm của x.<br />
Ghi chú: Nếu XIS tiêu cực, một lỗi miền xảy ra.
The sine of -1.000000 is -0.841471<br />
The sine of 0.000000 is 0.000000<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 358<br />
sinf<br />
2004 Microchip Technology Inc.<br />
Description: Calculates the trigonometric sine function of a single precision<br />
floating<br />
point value.<br />
Include: <br />
Prototype: float sinf (float x);<br />
Argument: x value for which to return the sine<br />
Return Value: Returns the sin of xin radians in the ranges of -1 to 1 inclusive.<br />
Remarks: A domain error will occur if xis a NaN or infinity.<br />
Example: #include /* for sinf */<br />
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
float x, y;<br />
errno = 0;<br />
x = -1.0F;<br />
y = sinf (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The sine of %f is %f\n\n", x, y);<br />
errno = 0;<br />
x = 0.0F;<br />
y = sinf (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The sine of %f is %f\n\n", x, y);<br />
}<br />
Output:<br />
The sine of -1.000000 is -0.841471<br />
The sine of 0.000000 is 0.000000<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 359<br />
Ví dụ: # include / * Cho sqrtf * /<br />
# include / * Cho printf, perror * /<br />
# include / * Cho errno * /<br />
int main (void)<br />
{<br />
x đôi;<br />
errno = 0;<br />
x = sqrtf (0.0f);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("căn bậc hai của 0.0f là% f \ n \ n", x);<br />
errno = 0;<br />
x = sqrtf (9.5F);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("căn bậc hai của 9.5F là% f \ n \ n", x);<br />
errno = 0;<br />
x = sqrtf (-25.0F);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("căn bậc hai của -25F là% f \ n", x);<br />
}<br />
Đầu ra:<br />
Căn bậc hai của 0.0f là 0.000000<br />
Căn bậc hai của 9.5F là 3,082207<br />
Lỗi: lỗi miền<br />
Căn bậc hai của -25F là nan<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 363<br />
tan<br />
Mô tả: Tính hàm lượng giác tiếp xúc của một độ chính xác kép<br />
nổi giá trị điểm.<br />
Bao gồm:<br />
Prototype: đôi tan (double x);<br />
Đối số: x giá trị mà trả lại tang<br />
Quay trở lại giá trị: Trả về tang của xin radian.<br />
Bình luận: Một lỗi miền sẽ xảy ra nếu XIS một NaN hoặc vô cùng.<br />
Ví dụ: # include / * Cho tan * /<br />
# include / * Cho printf, perror * /
sinh<br />
Description: Calculates the hyperbolic sine function of a double precision<br />
floating<br />
point value.<br />
Include: <br />
Prototype: double sinh (double x);<br />
Argument: x value for which to return the hyperbolic sine<br />
Return Value: Returns the hyperbolic sine of x<br />
Remarks: A range error will occur if the magnitude of xis too large.<br />
Example: #include /* for sinh */<br />
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
double x, y;<br />
errno = 0;<br />
x = -1.5;<br />
y = sinh (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The hyperbolic sine of %f is %f\n\n",<br />
x, y);<br />
errno = 0;<br />
x = 0.0;<br />
y = sinh (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The hyperbolic sine of %f is %f\n\n",<br />
x, y);<br />
errno = 0;<br />
x = 720.0;<br />
y = sinh (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The hyperbolic sine of %f is %f\n\n",<br />
x, y);<br />
}<br />
# include / * Cho errno * /<br />
int main (void)<br />
{<br />
double x, y;<br />
errno = 0;<br />
x = -1,0;<br />
y = tan (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("tang của% f% f \ n \ n", x, y);<br />
errno = 0;<br />
x = 0,0;<br />
y = tan (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("tang của% f% f \ n \ n", x, y);<br />
}<br />
Đầu ra:<br />
Tang của -1,000000 là -1,557408<br />
Tang của 0.000000 là 0.000000<br />
TANF<br />
Mô tả: Tính tangentfunction lượng giác của một độ chính xác đơn<br />
nổi giá trị điểm.<br />
Bao gồm:<br />
Prototype: TANF nổi (float x);<br />
Đối số: x giá trị mà trả lại tang<br />
Quay trở lại giá trị: Trả về tang của x<br />
Bình luận: Một lỗi miền sẽ xảy ra nếu XIS một NaN hoặc vô cùng.<br />
Ví dụ: # include / * Cho TANF * /<br />
# include / * Cho printf, perror * /<br />
# include / * Cho errno * /<br />
int main (void)<br />
{<br />
float x, y;<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
Output:<br />
The hyperbolic sine of -1.500000 is -2.129279<br />
DS51456B trang 364<br />
errno = 0;<br />
2004 Microchip Technology Inc
The hyperbolic sine of 0.000000 is 0.000000<br />
Error: range error<br />
The hyperbolic sine of 720.000000 is inf<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 360<br />
sinhf<br />
2004 Microchip Technology Inc.<br />
Description: Calculates the hyperbolic sine function of a single precision<br />
floating<br />
point value.<br />
Include: <br />
Prototype: float sinhf (float x);<br />
Argument: x value for which to return the hyperbolic sine<br />
Return Value: Returns the hyperbolic sine of x<br />
Remarks: A range error will occur if the magnitude of xis too large.<br />
Example: #include /* for sinhf */<br />
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
float x, y;<br />
errno = 0;<br />
x = -1.0F;<br />
y = sinhf (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The hyperbolic sine of %f is %f\n\n",<br />
x, y);<br />
errno = 0;<br />
x = 0.0F;<br />
y = sinhf (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The hyperbolic sine of %f is %f\n\n",<br />
x, y);<br />
}<br />
Output:<br />
The hyperbolic sine of -1.000000 is -1.175201<br />
x = -1.0F;<br />
y = TANF (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("tang của% f% f \ n \ n", x, y);<br />
errno = 0;<br />
x = 0.0f;<br />
y = TANF (x);<br />
if (errno)<br />
perror ("Lỗi");<br />
printf ("tang của% f% f \ n", x, y);<br />
}<br />
Đầu ra:<br />
Tang của -1,000000 là -1,557408<br />
Tang của 0.000000 là 0.000000<br />
tanh<br />
Mô tả: Tính hàm tang hyperbol của một độ chính xác gấp đôi nổi<br />
giá trị điểm.<br />
Bao gồm:<br />
Prototype: tanh kép (double x);<br />
Đối số: x giá trị mà trả lại tang hyperbol<br />
Quay trở lại giá trị: Trả về tang hyperbol của xin các phạm vi của -1 đến 1 bao<br />
gồm.<br />
Bình luận: Không có tên miền hoặc phạm vi lỗi sẽ xảy ra.<br />
Ví dụ: # include / * Cho tanh * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
double x, y;<br />
x = -1,0;<br />
y = tanh (x);<br />
printf ("tang hyperbol của% f% f \ n \ n",<br />
x, y);<br />
x = 2,0;<br />
y = tanh (x);<br />
printf ("tang hyperbol của% f% f \ n \ n",<br />
x, y);<br />
}<br />
Đầu ra:<br />
Tang hyperbol của -1,000000 là -,761594
The hyperbolic sine of 0.000000 is 0.000000<br />
Standard C Libraries with Math Functions<br />
sqrt<br />
2004 Microchip Technology Inc. DS51456B-page 361<br />
Description: Calculates the square root of a double precision floating point<br />
value.<br />
Include: <br />
Prototype: double sqrt(double x);<br />
Argument: x a non-negative floating point value<br />
Return Value: Returns the non-negativesquare root of x..<br />
Remarks: If xis negative, a domain error occurs.<br />
Example: #include /* for sqrt */<br />
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
double x, y;<br />
errno = 0;<br />
x = 0.0;<br />
y = sqrt (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The square root of %f is %f\n\n", x, y);<br />
errno = 0;<br />
x = 9.5;<br />
y = sqrt (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The square root of %f is %f\n\n", x, y);<br />
errno = 0;<br />
x = -25.0;<br />
y = sqrt (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The square root of %f is %f\n\n", x, y);<br />
}<br />
Output:<br />
The square root of 0.000000 is 0.000000<br />
The square root of 9.500000 is 3.082207<br />
Tang of2.000000 hyperbol là 0,964028<br />
TANF (Tiếp theo)<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 365<br />
tanhf<br />
Mô tả: Tính hàm tang hyperbol của một độ chính xác đơn nổi<br />
giá trị điểm.<br />
Bao gồm:<br />
Prototype: tanhf nổi (float x);<br />
Đối số: x giá trị mà trả lại tang hyperbol<br />
Quay trở lại giá trị: Trả về tang hyperbol của xin các phạm vi của -1 đến 1 bao<br />
gồm.<br />
Bình luận: Không có tên miền hoặc rangeerror sẽ xảy ra.<br />
Ví dụ: # include / * Cho tanhf * /<br />
# include / * Cho printf * /<br />
int main (void)<br />
{<br />
float x, y;<br />
x = -1.0F;<br />
y = tanhf (x);<br />
printf ("tang hyperbol của% f% f \ n \ n",<br />
x, y);<br />
x = 0.0f;<br />
y = tanhf (x);<br />
printf ("tang hyperbol của% f% f \ n \ n",<br />
x, y);<br />
}<br />
Đầu ra:<br />
Tang hyperbol của -1,000000 là -,761594<br />
Tang hyperbol của 0.000000 là 0.000000<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 366<br />
4.18 PIC30-libs<br />
2004 Microchip Technology Inc<br />
Các chức năng sau đây là C chức năng trợ giúp thư viện chuẩn:<br />
• _exit chấm dứt thực hiện chương trình<br />
• brk thiết lập kết thúc của không gian dữ liệu của quá trình<br />
• gần đóng một tập tin<br />
• lseek di chuyển một con trỏ tập tin vào một vị trí quy định
Error: domain error<br />
The square root of -25.000000 is nan<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 362 2004 Microchip Technology Inc.<br />
sqrtf<br />
Description: Calculates the square root of a single precision floating point value.<br />
Include: <br />
Prototype: float sqrtf(float x);<br />
Argument: x non-negative floating point value<br />
Return Value: Returns the non-negative square root of x.<br />
Remarks: If xis negative, a domain error occurs.<br />
Example: #include /* for sqrtf */<br />
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
double x;<br />
errno = 0;<br />
x = sqrtf (0.0F);<br />
if (errno)<br />
perror("Error");<br />
printf("The square root of 0.0F is %f\n\n", x);<br />
errno = 0;<br />
x = sqrtf (9.5F);<br />
if (errno)<br />
perror("Error");<br />
printf("The square root of 9.5F is %f\n\n", x);<br />
errno = 0;<br />
x = sqrtf (-25.0F);<br />
if (errno)<br />
perror("Error");<br />
printf("The square root of -25F is %f\n", x);<br />
}<br />
Output:<br />
The square root of 0.0F is 0.000000<br />
The square root of 9.5F is 3.082207<br />
Error: domain error<br />
• mở mở một tập tin<br />
• đọc đọc dữ liệu từ một tập tin<br />
• sbrk mở rộng không gian dữ liệu của quá trình một tăng cho<br />
• ghi ghi dữ liệu vào một tập tin<br />
Các chức năng này được gọi là bởi các chức năng khác trong thư viện C chuẩn<br />
và phải được<br />
sửa đổi cho mục tiêu ứng dụng. Các mô-đun đối tượng tương ứng được phân<br />
phối tại<br />
các libpic30-omf.aarchive và mã nguồn (cho MPLAB C30) có sẵn trong<br />
src \ pic30folder.<br />
Ngoài ra, một số chức năng tiêu chuẩn thư viện C cũng phải được sửa đổi cho<br />
mục tiêu<br />
ứng dụng. Đó là:<br />
• getenv được một giá trị cho một biến môi trường<br />
• loại bỏ loại bỏ một tập tin<br />
• đổi tên đổi tên một tập tin hoặc thư mục<br />
• Hệ thống thực thi một lệnh<br />
• Thời gian có được thời gian hệ thống<br />
Mặc dù các chức năng này là một phần của thư viện C chuẩn, các mô-đun đối<br />
tượng là<br />
phân bố ở libpic30-omf.aarchive và mã nguồn (cho MPLAB C30) là<br />
có sẵn trong src \ pic30folder. Những module này không được phân phối như<br />
một phần của<br />
libc-omf.a.<br />
4.18.1 Xây dựng lại thư viện libpic30-omf.a<br />
Theo mặc định, chức năng trợ giúp được liệt kê trong chương này được viết để<br />
làm việc với<br />
sim30simulator. Các tập tin tiêu đề, simio.h, định nghĩa giao diện giữa các thư<br />
viện<br />
và giả lập. Nó được cung cấp để bạn có thể xây dựng lại các thư viện và tiếp tục<br />
sử dụng<br />
mô phỏng. Tuy nhiên, ứng dụng của bạn không nên sử dụng giao diện này kể từ<br />
khi mô phỏng<br />
sẽ không có sẵn cho một ứng dụng nhúng.<br />
Các chức năng trợ giúp phải được sửa đổi và xây dựng lại cho các ứng dụng<br />
mục tiêu của bạn. Các<br />
libpic30-omf.alibrary có thể được xây dựng lại với các tập tin thực thi có tên<br />
makelib.bat,<br />
đã được cung cấp với các nguồn trong src \ pic30. Thực hiện các tập tin thực th<br />
từ<br />
một cửa sổ lệnh. Hãy chắc chắn bạn đang ở trong src \ pic30directory. Sau đó<br />
sao chép các mới<br />
biên soạn tập tin (libpic30-omf.a) vào thư mục lib.<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 367<br />
4.18.2 Chức năng Mô tả
The square root of -25F is nan<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 363<br />
tan<br />
Description: Calculates the trigonometric tangent function of a double precision<br />
floating point value.<br />
Include: <br />
Prototype: double tan (double x);<br />
Argument: x value for which to return the tangent<br />
Return Value: Returns the tangent of xin radians.<br />
Remarks: A domain error will occur if xis a NaN or infinity.<br />
Example: #include /* for tan*/<br />
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
double x, y;<br />
errno = 0;<br />
x = -1.0;<br />
y = tan (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The tangent of %f is %f\n\n", x, y);<br />
errno = 0;<br />
x = 0.0;<br />
y = tan (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The tangent of %f is %f\n\n", x, y);<br />
}<br />
Output:<br />
The tangent of -1.000000 is -1.557408<br />
The tangent of 0.000000 is 0.000000<br />
tanf<br />
Description: Calculates the trigonometric tangentfunction of a single precision<br />
Phần này mô tả các chức năng mà phải được tùy biến cho hoạt động chính xác<br />
của<br />
Thư viện C chuẩn trong môi trường mục tiêu của bạn. Phần hành vi mặc định<br />
mô tả những gì các chức năng nào vì nó isdistributed. Mô tả và nhận xét<br />
mô tả những gì nó thường nên làm.<br />
_exit<br />
Mô tả: Chấm dứt thực hiện chương trình.<br />
Bao gồm: Không<br />
Prototype: void _exit (trạng thái int);<br />
Đối số: trạng thái thoát trạng thái<br />
Bình luận: Đây là một chức năng trợ giúp gọi bằng lối ra () Tiêu chuẩn Thư việ<br />
C<br />
chức năng.<br />
Hành vi mặc định: Khi phân phối, điều này bừng chức năng thiết bị xuất chuẩn<br />
và chấm dứt. Các<br />
tình trạng tham số là giống như được truyền cho xuất cảnh () tiêu chuẩn C<br />
chức năng thư viện.<br />
File: _exit.c<br />
brk<br />
Mô tả: Thiết lập kết thúc của không gian dữ liệu của quá trình.<br />
Bao gồm: Không<br />
Nguyên mẫu: int brk (void * endds)<br />
Đối số: endds con trỏ đến cuối đoạn dữ liệu<br />
Trở lại giá trị: Trả về "0" nếu thành công, '-1' nếu không.<br />
Bình luận: brk () được sử dụng để tự động thay đổi số lượng của không gian<br />
phân bổ cho<br />
đoạn dữ liệu quá trình kêu gọi của. Sự thay đổi này được thực hiện bằng cách<br />
đặt lại<br />
giá trị đột phá của quá trình và phân bổ số tiền thích hợp của<br />
không gian. Giá trị nghỉ là địa chỉ của địa điểm đầu tiên vượt ra ngoài<br />
kết thúc của đoạn dữ liệu. Số lượng phân bổ tăng không gian như<br />
tăng giá trị nghỉ.<br />
Gian được phân bổ mới chưa được định hình.<br />
Chức năng trợ giúp này được sử dụng bởi các chức năng thư viện chuẩn C<br />
malloc ().<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
floating point value.<br />
DS51456B trang 368<br />
2004 Microchip Technology Inc<br />
Include: <br />
Prototype: float tanf (float x);<br />
Argument: x value for which to return the tangent<br />
Hành vi mặc định: Nếu các đối số enddsis không, các chức năng thiết lập các<br />
biến toàn cầu<br />
__curbrkto địa chỉ của sự bắt đầu của heap, và trả về số không.
Return Value: Returns the tangent of x<br />
Remarks: A domain error will occur if xis a NaN or infinity.<br />
Example: #include /* for tanf */<br />
#include /* for printf, perror */<br />
#include /* for errno */<br />
int main(void)<br />
{<br />
float x, y;<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 364<br />
errno = 0;<br />
x = -1.0F;<br />
y = tanf (x);<br />
if (errno)<br />
perror("Error");<br />
2004 Microchip Technology Inc.<br />
printf("The tangent of%f is %f\n\n", x, y);<br />
errno = 0;<br />
x = 0.0F;<br />
y = tanf (x);<br />
if (errno)<br />
perror("Error");<br />
printf("The tangent of %f is %f\n", x, y);<br />
}<br />
Output:<br />
The tangent of -1.000000 is -1.557408<br />
The tangent of 0.000000 is 0.000000<br />
tanh<br />
Description: Calculates the hyperbolic tangent function of a double precision<br />
floating<br />
point value.<br />
Include: <br />
Prototype: double tanh (double x);<br />
Argument: x value for which to return the hyperbolic tangent<br />
Return Value: Returns the hyperbolic tangent of xin the ranges of -1 to 1<br />
inclusive.<br />
Remarks: No domain or range error will occur.<br />
Example: #include /*for tanh */<br />
#include /* for printf */<br />
Nếu các đối số enddsis khác không, và có giá trị ít hơn<br />
địa chỉ cuối của heap, các chức năng thiết lập các biến toàn cầu<br />
__curbrkto giá trị của enddsand trả về số không.<br />
Nếu không, các biến toàn cầu __curbrkis không thay đổi, và<br />
chức năng trả về -1.<br />
Đối số enddsmust nằm trong phạm vi đống (xem dữ liệu không gian<br />
bản đồ bộ nhớ dưới đây.)<br />
Chú ý rằng, kể từ khi chồng nằm ngay phía trên đống,<br />
sử dụng brk () hoặc sbrk () có ít ảnh hưởng đến kích thước của động<br />
bộ nhớ hồ bơi. Các brk () và sbrk () chức năng này được thiết kế chủ yếu<br />
để sử dụng trong môi trường thời gian chạy mà chồng phát triển và giảm<br />
đống phát triển đi lên.<br />
Các mối liên kết phân bổ một khối ofmemory cho đống nếu<br />
-Wl, - Đống = noption được xác định, nơi mà NIS kích thước heap mong muốn<br />
trong<br />
ký tự. Các bắt đầu và kết thúc địa chỉ của heap được báo cáo<br />
trong các biến _heapand _eheap, tương ứng.<br />
Đối với MPLAB C30, sử dụng tùy chọn kích thước heap của mối liên kết là<br />
cách tiêu chuẩn<br />
kiểm soát kích thước heap, hơn là dựa vào brk () và sbrk ().<br />
File: brk.c<br />
gần<br />
Mô tả: Đóng một tập tin.<br />
Bao gồm: Không<br />
Nguyên mẫu: int gần (int xử lý);<br />
Đối số: xử lý việc xử lý đề cập đến một tập tin mở<br />
Trở lại giá trị: Trả về "0" nếu các tập tin được đóng thành công. Một giá trị trở<br />
lại của '-1'<br />
cho biết một lỗi.<br />
Bình luận: chức năng trợ giúp này được gọi là bởi fclose () Tiêu chuẩn Thư việ<br />
C<br />
chức năng.<br />
Hành vi mặc định: Khi phân phối, chức năng tập tin passesthe này xử lý để mô<br />
phỏng,<br />
trong đó đưa ra một chặt chẽ trong hệ thống tập tin host.<br />
File: close.c<br />
brk (Tiếp theo)<br />
PSV<br />
Chồng<br />
Heap<br />
biến<br />
SFR
int main(void)<br />
{<br />
double x, y;<br />
x = -1.0;<br />
y = tanh (x);<br />
printf("The hyperbolic tangent of %f is %f\n\n",<br />
x, y);<br />
x = 2.0;<br />
y = tanh (x);<br />
printf("The hyperbolic tangent of %f is %f\n\n",<br />
x, y);<br />
}<br />
Output:<br />
The hyperbolic tangent of -1.000000 is -0.761594<br />
The hyperbolic tangent of2.000000 is 0.964028<br />
tanf (Continued)<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 365<br />
tanhf<br />
Description: Calculates the hyperbolic tangent function of a single precision<br />
floating<br />
point value.<br />
Include: <br />
Prototype: float tanhf (float x);<br />
Argument: x value for which to return the hyperbolic tangent<br />
Return Value: Returns the hyperbolic tangent of xin the ranges of -1 to 1<br />
inclusive.<br />
Remarks: No domain or rangeerror will occur.<br />
Example: #include /* for tanhf */<br />
#include /* for printf */<br />
int main(void)<br />
{<br />
float x, y;<br />
x = -1.0F;<br />
y = tanhf (x);<br />
printf("The hyperbolic tangent of %f is %f\n\n",<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 369<br />
getenv<br />
Mô tả: Lấy một giá trị cho một biến môi trường<br />
Bao gồm:<br />
Prototype: char * getenv (const char * s);<br />
Đối số: tên của biến môi trường<br />
Quay trở lại giá trị: Trả về một con trỏ đến giá trị của biến môi trường nếu thàn<br />
công;<br />
nếu không, trả về một con trỏ null.<br />
Hành vi mặc định: Khi phân phối, chức năng này trả về một con trỏ null. Không<br />
có hỗ trợ<br />
cho các biến môi trường.<br />
File: getenv.c<br />
lseek<br />
Mô tả: Di chuyển con trỏ tập tin vào một vị trí quy định.<br />
Bao gồm: Không<br />
Prototype: lseek dài (int xử lý, dài bù đắp, int nguồn gốc);<br />
Đối số: xử lý đề cập đến một tập tin mở<br />
bù đắp số ký tự từ gốc<br />
nguồn gốc vị trí mà từ đó để bắt đầu tìm kiếm. originmay được<br />
một trong các giá trị sau (theo quy định tại stdio.h):<br />
SEEK_SET - lúc bắt đầu của tập tin.<br />
SEEK_CUR - vị trí hiện tại của con trỏ tập tin.<br />
SEEK_END - Kết thúc tập tin.<br />
Quay trở lại giá trị: Trả về bù đắp, trong nhân vật, vị trí ofthe mới từ đầu<br />
của tập tin. Một giá trị trở lại của '-1L' chỉ ra một lỗi.<br />
Bình luận: chức năng trợ giúp này được gọi bởi các chức năng thư viện chuẩn C<br />
fgetpos (), ftell (), fseek (), fsetpos, và tua lại ().<br />
Hành vi mặc định: Khi phân phối, các thông số được truyền đến hệ thống máy<br />
chủ<br />
thông qua các mô phỏng. Giá trị trả về là giá trị được trả về bởi máy chủ<br />
hệ thống tập tin.<br />
File: lseek.c<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
x, y);<br />
x = 0.0F;<br />
y = tanhf (x);<br />
printf("The hyperbolic tangent of %f is %f\n\n",<br />
DS51456B trang 370<br />
mở<br />
Mô tả: Mở một tập tin.<br />
Bao gồm: Không<br />
2004 Microchip Technology Inc
x, y);<br />
}<br />
Output:<br />
The hyperbolic tangent of -1.000000 is -0.761594<br />
The hyperbolic tangent of 0.000000 is 0.000000<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 366<br />
4.18 PIC30-LIBS<br />
2004 Microchip Technology Inc.<br />
The following functions are standard C library helper functions:<br />
• _exit terminate program execution<br />
• brk set the end of the process's data space<br />
• close close a file<br />
• lseek move a file pointer to a specified location<br />
• open open a file<br />
• read read data from a file<br />
• sbrk extend the process's data space by a given increment<br />
• write write data to a file<br />
These functions are called by other functions in the standard C library and must<br />
be<br />
modified for the target application. The corresponding object modules are<br />
distributed in<br />
the libpic30-omf.aarchive and the source code (for MPLAB C30) is available in<br />
the src\pic30folder.<br />
Additionally, several standard C library functions must also be modified for the<br />
target<br />
application. They are:<br />
• getenv get a value for an environment variable<br />
• remove remove a file<br />
• rename rename a file or directory<br />
• system execute a command<br />
• time get the system time<br />
Although these functions are part of the standard C library, the object modules<br />
are<br />
distributed in the libpic30-omf.aarchive and the source code (for MPLAB C30)<br />
is<br />
available in the src\pic30folder. These modules are not distributed as part of<br />
libc-omf.a.<br />
4.18.1 Rebuilding the libpic30-omf.a library<br />
By default, the helper functions listed in this chapter were written to work with<br />
the<br />
Nguyên mẫu: int mở (const char * name, int truy cập, int mode);<br />
Đối số: tên tên của tập tin sẽ được mở<br />
phương pháp truy cập truy cập để mở tập tin<br />
loại phương thức truy cập được phép<br />
Quay trở lại giá trị: Nếu thành công, hàm trả về một tập tin xử lý, một số<br />
nguyên dương nhỏ.<br />
Xử lý này sau đó được sử dụng trên tiếp theo ở mức độ thấp tập tin I / O hoạt<br />
động. Một<br />
giá trị trả lại '-1' cho biết một lỗi.<br />
Bình luận: Việc tiếp cận lá cờ là một sự kết hợp của một ofthe phương pháp tru<br />
cập sau đây và<br />
không có hoặc có tiếp cận nhiều hơn vòng loại:<br />
0 - Mở một tập tin để đọc.<br />
1 - Mở một tập tin để viết.<br />
2 - Mở một tập tin cho cả đọc và viết.<br />
Vòng loại truy cập sau đây phải được hỗ trợ:<br />
0x0008 - Di chuyển con trỏ tập tin đến cuối tập tin trước khi tất cả các hoạt<br />
động viết.<br />
0x0100 - Tạo và mở một tập tin mới cho văn bản.<br />
0x0200 - Mở tập tin và cắt nó để không dài.<br />
0x4000 - Mở tập tin trong văn bản (dịch) chế độ.<br />
0x8000 - Mở tập tin trong hệ nhị phân (chưa dịch) chế độ.<br />
Tham số chế độ có thể beone những điều sau đây:<br />
0x0100 - Reading chỉ được cho phép.<br />
0x0080 - Viết được phép (ngụ ý reading cho phép).<br />
Chức năng trợ giúp này được gọi bởi các chức năng thư viện chuẩn C<br />
fopen () và freopen ().<br />
Hành vi mặc định: Khi phân phối, các thông số được truyền đến hệ thống máy<br />
chủ<br />
thông qua các mô phỏng. Giá trị trả về là giá trị được trả về bởi máy chủ<br />
hệ thống tập tin. Nếu hệ thống máy chủ trả về giá trị của '-1', biến toàn cầu<br />
errno được thiết lập để giá trị của biểu tượng liên tục trong EFOPENdefined<br />
.<br />
File: open.c<br />
Thư viện chuẩn C với hàm toán học<br />
đọc<br />
2004 Microchip Technology Inc DS51456B trang 371<br />
Mô tả: Đọc dữ liệu từ một tập tin.<br />
Bao gồm: Không<br />
Nguyên mẫu: int read (int xử lý, void * đệm,<br />
int len);<br />
Đối số: xử lý xử lý đề cập toan file đã mở
sim30simulator. The header file, simio.h, defines the interface between the<br />
library<br />
and the simulator. It is provided so you can rebuild the libraries and continue to<br />
use the<br />
simulator. However, your application should not use this interface since the<br />
simulator<br />
will not be available to an embedded application.<br />
The helper functions must be modified and rebuilt for your target application.<br />
The<br />
libpic30-omf.alibrary can be rebuild with the batch file named makelib.bat,<br />
which has been provided with the sources in src\pic30. Execute the batch file<br />
from<br />
a command window. Be sure you are in the src\pic30directory. Then copy the<br />
newly<br />
compiled file (libpic30-omf.a) into the lib directory.<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 367<br />
4.18.2 Function Descriptions<br />
This section describes the functions that must be customized for correct<br />
operation of<br />
the Standard C Library in your target environment. The default behavior section<br />
describes what the function does as it isdistributed. The description and remarks<br />
describe what it typically should do.<br />
_exit<br />
Description: Terminate program execution.<br />
Include: None<br />
Prototype: void _exit (int status);<br />
Argument: status exit status<br />
Remarks: This is a helper function called by the exit()Standard C Library<br />
function.<br />
Default Behavior: As distributed, this function flushes stdout and terminates.<br />
The<br />
parameter status is the same as that passed to the exit()standard C<br />
library function.<br />
File: _exit.c<br />
brk<br />
Description: Set the end of the process's data space.<br />
Include: None<br />
Prototype: int brk(void *endds)<br />
Argument: endds pointer to the end of the data segment<br />
Return Value: Returns ‘0’ if successful, ‘-1’ if not.<br />
Remarks: brk()is used to dynamically change the amount of space allocated for<br />
điểm đệm để vị trí lưu trữ để đọc dữ liệu<br />
len số lượng tối đa của các nhân vật để đọc<br />
Quay trở lại giá trị: Trả về số charactersread, mà có thể ít hơn lenif<br />
có ít hơn lencharacters còn lại trong các tập tin hoặc các tập tin được<br />
mở trong chế độ văn bản, trong trường hợp mỗi vận chuyển trở lại-linefeed mà<br />
Cặp (CR-LF) được thay thế bằng một nhân vật linefeed duy nhất. Chỉ có<br />
nhân vật linefeed duy nhất được tính vào giá trị trả về. Các<br />
thay thế không ảnh hưởng đến con trỏ tập tin. Nếu chức năng cố gắng đọc<br />
ở cuối của tập tin, nó sẽ trả về "0". Nếu xử lý không hợp lệ, hoặc các tập tin<br />
không mở cửa<br />
để đọc, hoặc các tập tin bị khóa, hàm trả về '-1'.<br />
Bình luận: chức năng trợ giúp này được gọi bởi các chức năng thư viện chuẩn C<br />
fgetc (), fgets (), fread (), và được ().<br />
Hành vi mặc định: Khi phân phối, các thông số được truyền đến hệ thống máy<br />
chủ<br />
thông qua các mô phỏng. Giá trị trả về là giá trị được trả về bởi máy chủ<br />
hệ thống tập tin.<br />
File: read.c<br />
loại bỏ<br />
Mô tả: Xóa một tập tin.<br />
Bao gồm:<br />
Nguyên mẫu: int remove (const char * filename);<br />
Đối số: file tên tập tin phải được loại bỏ<br />
Trở lại giá trị: Trả về "0" nếu thành công, "- 1 'nếu không thành công.<br />
Hành vi mặc định: Khi phân phối, các thông số được truyền đến hệ thống máy<br />
chủ<br />
thông qua các mô phỏng. Giá trị trả về là giá trị được trả về bởi máy chủ<br />
hệ thống tập tin.<br />
File: remove.c<br />
đổi tên<br />
Mô tả: Đổi tên một tập tin hoặc thư mục.<br />
Bao gồm:<br />
Nguyên mẫu: int đổi tên (const char * oldname, const char<br />
* Newname);<br />
Đối số: con trỏ oldname thành tên cũ<br />
newname con trỏ sang tên mới<br />
Trở lại giá trị: Trả về "0" nếu nó là thành công. Trên một lỗi, hàm trả về một giá<br />
trị khác không<br />
giá trị.<br />
Hành vi mặc định: Khi phân phối, các thông số được truyền đến hệ thống máy<br />
chủ<br />
thông qua các mô phỏng. Giá trị trả về là giá trị được trả về bởi máy chủ
the calling process's data segment. The change is made by resetting<br />
the process's break value and allocating the appropriate amount of<br />
space. The break value is the address of the first location beyond the<br />
end of the data segment. The amount of allocated space increases as<br />
the break value increases.<br />
Newly allocated space is uninitialized.<br />
This helper function is used by the Standard C Library function<br />
malloc().<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 368<br />
2004 Microchip Technology Inc.<br />
Default Behavior: If the argument enddsis zero, the function sets the global<br />
variable<br />
__curbrkto the address of the start of the heap, and returns zero.<br />
If the argument enddsis non-zero, and has a value less than the<br />
address of the end of the heap, the function sets the global variable<br />
__curbrkto the value of enddsand returns zero.<br />
Otherwise, the global variable __curbrkis unchanged, and the<br />
function returns -1.<br />
The argument enddsmust be within the heap range (see data space<br />
memory map below.)<br />
Notice that, since the stack is located immediately above the heap,<br />
using brk()or sbrk()has little effect on the size of the dynamic<br />
memory pool. The brk()and sbrk()functions are primarily intended<br />
for use in run-time environments where the stack grows downward and<br />
the heap grows upward.<br />
The linker allocates a block ofmemory for the heap if the<br />
-Wl,--heap=noption is specified, where nis the desired heap size in<br />
characters. The starting and ending addresses of the heap are reported<br />
in variables _heapand _eheap, respectively.<br />
For MPLAB C30, using the linker's heap size option is the standard way<br />
of controlling heap size, rather than relying on brk()and sbrk().<br />
File: brk.c<br />
close<br />
Description: Close a file.<br />
Include: None<br />
Prototype: int close(int handle);<br />
Argument: handle handle referring to an opened file<br />
hệ thống tập tin.<br />
File: rename.c<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 372<br />
sbrk<br />
2004 Microchip Technology Inc<br />
Mô tả: Mở rộng không gian dữ liệu của quá trình một tăng nhất định.<br />
Bao gồm: Không<br />
Nguyên mẫu: void * sbrk (int incr);<br />
Đối số: số incr của các nhân vật để tăng / giảm<br />
Quay trở lại giá trị gia tăng: Quay trở lại sự bắt đầu của không gian mới phân<br />
bổ, hoặc '-1' lỗi.<br />
Bình luận: sbrk () cho biết thêm incrcharacters với giá trị phá vỡ và thay đổi<br />
phân bổ không gian cho phù hợp. incrcan được tiêu cực, trong trường hợp đó<br />
số lượng không gian được phân bổ được giảm.<br />
sbrk () được sử dụng để tự động thay đổi số lượng của không gian phân bổ<br />
cho phân đoạn dữ liệu của quá trình gọi. Sự thay đổi này được thực hiện bởi<br />
đặt lại giá trị đột phá của quá trình và phân bổ thích hợp<br />
số lượng không gian. Giá trị nghỉ là địa chỉ của địa điểm đầu tiên<br />
vượt ra ngoài kết thúc của đoạn dữ liệu. Số lượng không gian được phân bổ<br />
tăng như tăng giá trị nghỉ.<br />
Đây là một chức năng trợ giúp gọi bythe Thư viện chuẩn C chức năng<br />
malloc ().<br />
Hành vi mặc định: Nếu biến toàn cầu __curbrkis không, chức năng gọi brk () để<br />
khởi tạo giá trị nghỉ. Nếu brk () trả về -1, do đó, hiện chức năng này.<br />
Nếu incris không, giá trị hiện tại của __curbrkis biến toàn cầu<br />
trả lại.<br />
Nếu incris không, chức năng kiểm tra rằng địa chỉ<br />
(__curbrk + Incr) ít hơn so với địa chỉ cuối cùng của đống. Nếu đó là<br />
ít hơn, các biến toàn cầu __curbrkis cập nhật giá trị đó, và<br />
chức năng trả về giá trị unsigned của __curbrk.<br />
Nếu không, chức năng trả về -1.<br />
Xem mô tả các brk ().<br />
File: sbrk.c<br />
hệ thống<br />
Mô tả: Thực hiện một lệnh.<br />
Bao gồm:<br />
Nguyên mẫu: int hệ thống (const char * s);<br />
Đối số: s lệnh được thực thi.
Return Value: Returns ‘0’ if the file is successfully closed. A return value of ‘-<br />
1’<br />
indicates an error.<br />
Remarks: This helper function is called by the fclose()Standard C Library<br />
function.<br />
Default Behavior: As distributed, this function passesthe file handle to the<br />
simulator,<br />
which issues a close in the host file system.<br />
File: close.c<br />
brk (Continued)<br />
PSV<br />
Stack<br />
Heap<br />
variables<br />
SFR<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 369<br />
getenv<br />
Description: Get a value for an environment variable<br />
Include: <br />
Prototype: char *getenv(const char *s);<br />
Argument: s name of environment variable<br />
Return Value: Returns a pointer to the value of the environment variable if<br />
successful;<br />
otherwise, returns a null pointer.<br />
Default Behavior: As distributed, this function returns a null pointer. There is no<br />
support<br />
for environment variables.<br />
File: getenv.c<br />
lseek<br />
Description: Move a file pointer to a specified location.<br />
Include: None<br />
Prototype: long lseek(int handle, long offset, int origin);<br />
Argument: handle refers to an opened file<br />
offset the number of characters from the origin<br />
origin the position from which to start the seek. originmay be<br />
one of the following values (as defined in stdio.h):<br />
SEEK_SET – Beginning of file.<br />
SEEK_CUR – Current position of file pointer.<br />
SEEK_END – End of file.<br />
Hành vi mặc định: Khi phân phối, chức năng này hoạt động như còn sơ khai<br />
hoặc giữ chỗ cho bạn<br />
chức năng. Nếu sis không phải là NULL, một thông báo lỗi được ghi vào thiết<br />
bị xuất chuẩn và<br />
chương trình sẽ thiết lập lại; cách khác, giá trị -1 được trả về.<br />
File: system.c<br />
Thư viện chuẩn C với hàm toán học<br />
2004 Microchip Technology Inc DS51456B trang 373<br />
thời gian<br />
Mô tả: Lấy thời gian hệ thống.<br />
Bao gồm:<br />
Nguyên mẫu: thời gian time_t (time_t * timer);<br />
Điểm hẹn giờ đến một địa điểm lưu trữ cho thời gian: Đối số<br />
Quay trở lại giá trị: Trả lại thời gian trôi qua trong vài giây. Không có lỗi lại.<br />
Hành vi mặc định: Khi phân phối, nếu Timer2 không được kích hoạt, nó được<br />
kích hoạt trong chế độ 32-bit. Các<br />
giá trị trả về là giá trị hiện tại của 32-bit Timer2 đăng ký. Ngoại trừ trong<br />
trường hợp rất hiếm, giá trị trả về đây không phải là thời gian trôi qua trong vài<br />
giây.<br />
File: time.c<br />
viết<br />
Mô tả: Viết dữ liệu vào một tập tin.<br />
Bao gồm: Không<br />
Nguyên mẫu: int write (int xử lý, void * đệm, int<br />
tính);<br />
Đối số: xử lý đề cập đến một tập tin mở<br />
điểm đệm đến vị trí lưu trữ dữ liệu được ghi<br />
đếm số lượng các ký tự để viết.<br />
Quay trở lại giá trị: Nếu thành công, viết trả về số ký tự thực sự bằng văn<br />
bản. Một<br />
trở về giá trị của '-1'indicates một lỗi.<br />
Ghi chú: Nếu không gian thực tế còn lại trên đĩa nhỏ hơn kích thước của<br />
đệm chức năng đang cố gắng để ghi vào đĩa cứng, viết không thành công và<br />
không<br />
tuôn ra bất kỳ các nội dung của bộ đệm vào đĩa. Nếu tập tin được mở ra trong<br />
văn bản<br />
chế độ, mỗi nhân vật linefeed được thay thế bằng một trở về vận chuyển -<br />
cặp linefeed ở đầu ra. Việc thay thế không ảnh hưởng đến sự trở lại<br />
giá trị.<br />
Đây là một chức năng trợ giúp gọi bằng chức năng thư viện chuẩn C<br />
fflush ().<br />
Hành vi mặc định: Khi phân phối, các thông số được truyền đến hệ thống máy<br />
chủ<br />
Return Value: Returns the offset, in characters, ofthe new position from the
eginning<br />
of the file. A return value of ‘-1L’ indicates an error.<br />
Remarks: This helper function is called by the Standard C Library functions<br />
fgetpos(), ftell(), fseek(), fsetpos, and rewind().<br />
Default Behavior: As distributed, the parameters are passed to the host file<br />
system<br />
through the simulator. The return value is the value returned by the host<br />
file system.<br />
File: lseek.c<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 370<br />
open<br />
Description: Open a file.<br />
Include: None<br />
2004 Microchip Technology Inc.<br />
Prototype: int open(const char *name, int access, int mode);<br />
Argument: name name of the file to be opened<br />
access access method to open file<br />
mode type of access permitted<br />
Return Value: If successful, the function returns a file handle, a small positive<br />
integer.<br />
This handle is then used on subsequent low-level file I/O operations. A<br />
return value of ‘-1’ indicates an error.<br />
Remarks: The access flag is a union of one ofthe following access methods and<br />
zero or more access qualifiers:<br />
0 – Open a file for reading.<br />
1 – Open a file for writing.<br />
2 – Open a file for both reading and writing.<br />
The following access qualifiers must be supported:<br />
0x0008 – Move file pointer to end of file before every write operation.<br />
0x0100 – Create and open a new file for writing.<br />
0x0200 – Open the file and truncate it to zero length.<br />
0x4000 – Open the file in text (translated) mode.<br />
0x8000 – Open the file in binary (untranslated) mode.<br />
The mode parameter may beone of the following:<br />
0x0100 – Reading only permitted.<br />
0x0080 – Writing permitted (implies reading permitted).<br />
This helper function is called by the Standard C Library functions<br />
fopen()and freopen().<br />
thông qua các mô phỏng. Giá trị trả về là giá trị được trả về bởi máy chủ<br />
hệ thống tập tin.<br />
File: write.c<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 374<br />
GHI CHÚ:<br />
dsPIC<br />
®LANGUAGE CÔNG CỤ<br />
THƯ VIỆN<br />
2004 Microchip Technology Inc<br />
2004 Microchip Technology Inc DS51456B trang 375<br />
Chương 5 MPLAB C30 Built-in chức năng<br />
5.1 GIỚI THIỆU<br />
Chương này mô tả MPLAB C30 tích infunctions được cụ thể cho dsPIC<br />
thiết bị.<br />
Chức năng được xây dựng trong cung cấp cho các lập trình viên C tiếp cận với<br />
các nhà khai thác lắp ráp hoặc máy<br />
hướng dẫn được hiện tại chỉ accessibleusing lắp ráp nội tuyến, nhưng là đủ<br />
hữu ích mà họ có thể áp dụng cho một loạt các ứng dụng. Chức năng được xây<br />
dựng trong là<br />
mã hóa trong các tập tin mã nguồn C cú pháp như các cuộc gọi chức năng,<br />
nhưng họ được biên dịch để<br />
mã lắp ráp trực tiếp thực hiện các chức năng, và không liên quan đến chức năng<br />
cuộc gọi<br />
hoặc thói quen thư viện.<br />
Có một số lý do tại sao cung cấp được xây dựng trong các chức năng được ưa<br />
chuộng hơn<br />
yêu cầu các lập trình viên sử dụng lắp ráp nội tuyến. Chúng bao gồm những<br />
điều sau đây:<br />
1 Cung cấp tích hợp chức năng cho các mục đích cụ thể đơn giản hóa mã hóa.<br />
2. Một số opitmizations bị vô hiệu hóa khi lắp ráp nội tuyến được sử dụng. Đây<br />
không phải là<br />
trường hợp cho xây dựng trong chức năng.<br />
3. Để được hướng dẫn đăng ký sử dụng máy chuyên dụng, mã hóa lắp ráp nội<br />
tuyến<br />
trong khi tránh lỗi giao đăng ký có thể yêu cầu chăm sóc đáng kể. Các<br />
tích hợp chức năng làm cho quá trình này đơn giản là bạn không cần phải được<br />
quan tâm<br />
với các yêu cầu đăng ký riêng cho từng hướng dẫn máy tính cá nhân.<br />
Chương này được tổ chức như sau:<br />
• Danh sách Chức năng Built-In<br />
• Được xây dựng trong chức năng thông báo lỗi<br />
dsPIC
Default Behavior: As distributed, the parameters are passed to the host file<br />
system<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
through the simulator. The return value is the value returned by the host<br />
DS51456B trang 376<br />
2004 Microchip Technology Inc<br />
file system. If the host system returns a value of ‘-1’, the global variable<br />
errno is set to the value of the symbolic constant EFOPENdefined in<br />
.<br />
File: open.c<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 371<br />
read<br />
Description: Read data from a file.<br />
Include: None<br />
Prototype: int read(int handle, void * buffer,<br />
unsigned int len);<br />
Argument: handle handle referring toan opened file<br />
buffer points to the storage location for read data<br />
len the maximum number of characters to read<br />
Return Value: Returns the number of charactersread, which may be less than<br />
lenif<br />
there are fewer than lencharacters left in the file or if the file was<br />
opened in text mode, in which case each carriage return-linefeed<br />
(CR-LF) pair is replaced with a single linefeed character. Only the<br />
single linefeed character is counted in the return value. The<br />
replacement does not affect the file pointer. If the function tries to read<br />
at end of file, it returns ‘0’. If the handle is invalid, or the file is not open<br />
for reading, or the file is locked, the function returns ‘-1’.<br />
Remarks: This helper function is called by the Standard C Library functions<br />
fgetc(), fgets(), fread(), and gets().<br />
Default Behavior: As distributed, the parameters are passed to the host file<br />
system<br />
through the simulator. The return value is the value returned by the host<br />
file system.<br />
File: read.c<br />
remove<br />
Description: Remove a file.<br />
Include: <br />
Prototype: int remove(const char *filename);<br />
Argument: filename file to be removed<br />
Return Value: Returns ‘0’ if successful,‘-1’ if unsuccessful.<br />
Default Behavior: As distributed, the parameters are passed to the host file<br />
system<br />
5.2 Xây-IN DANH SÁCH CHỨC NĂNG<br />
Phần này mô tả các giao diện lập trình để trình biên dịch MPLAB C30 C được<br />
xây dựng trong<br />
chức năng. Kể từ khi chức năng này được "xây dựng trong", không có tập tin<br />
tiêu đề liên quan<br />
chúng. Tương tự như vậy, không có thiết bị chuyển mạch dòng lệnh liên quan<br />
đến việc tích hợp<br />
chức năng - họ luôn có sẵn. Tên chức năng được xây dựng trong được lựa chọn<br />
như vậy mà<br />
họ thuộc về không gian tên của trình biên dịch (tất cả đều có __builtin_ tiền tố)<br />
do đó<br />
họ sẽ không xung đột với các chức năng hoặc tên biến trong không gian tên của<br />
lập trình viên.<br />
__builtin_divsd<br />
Mô tả: Chức năng tính toán thương num / den. Một ngoại lệ lỗi toán học<br />
xảy ra nếu denis không. Đối số chức năng được ký kết, như là chức năng<br />
kết quả. Các tùy chọn dòng lệnh -Wconversionscan được sử dụng để<br />
phát hiện chuyển đổi tín hiệu không mong muốn.<br />
Nguyên mẫu: int __builtin_divsd (num dài const, const int den);<br />
Đối số: num tử số<br />
mẫu den<br />
Quay trở lại giá trị: Trả về giá trị số nguyên có chữ ký của các thương num /<br />
den.<br />
Assembler<br />
Điều hành / Máy<br />
Hướng dẫn:<br />
div.sd<br />
__builtin_divud<br />
Mô tả: Chức năng tính toán thương num / den. Một ngoại lệ lỗi toán học<br />
xảy ra nếu denis không. Chức năng argumentsare unsigned, như là<br />
chức năng kết quả. Các tùy chọn dòng lệnh được -Wconversionscan<br />
được sử dụng để phát hiện các dấu hiệu chuyển đổi bất ngờ.<br />
Nguyên mẫu: int __builtin_divud (const unsigned<br />
num dài, const int den);<br />
Đối số: num tử số<br />
mẫu den<br />
Quay trở lại giá trị: Trả về integervalue unsigned của các thương num / den.<br />
Assembler<br />
Điều hành / Máy<br />
Hướng dẫn:
through the simulator. The return value is the value returned by the host<br />
file system.<br />
File: remove.c<br />
rename<br />
Description: Rename a file or directory.<br />
Include: <br />
Prototype: int rename(const char *oldname, const char<br />
*newname);<br />
Argument: oldname pointer to the old name<br />
newname pointer to the new name<br />
Return Value: Returns ‘0’ if it is successful. On an error, the function returns a<br />
nonzero<br />
value.<br />
Default Behavior: As distributed, the parameters are passed to the host file<br />
system<br />
through the simulator. The return value is the value returned by the host<br />
file system.<br />
File: rename.c<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 372<br />
sbrk<br />
2004 Microchip Technology Inc.<br />
Description: Extend the process's data space by a given increment.<br />
Include: None<br />
Prototype: void * sbrk(int incr);<br />
Argument: incr number of characters to increment/decrement<br />
Return Value: Return the start of the new space allocated, or ‘-1’ for errors.<br />
Remarks: sbrk()adds incrcharacters to the break value and changes the<br />
allocated space accordingly. incrcan be negative, in which case the<br />
amount of allocated space is decreased.<br />
sbrk()is used to dynamically change the amount of space allocated<br />
for the calling process's data segment. The change is made by<br />
resetting the process's break value and allocating the appropriate<br />
amount of space. The break value is the address of the first location<br />
beyond the end of the data segment. The amount of allocated space<br />
increases as the break value increases.<br />
This is a helper function called bythe Standard C Library function<br />
malloc().<br />
Default Behavior: If the global variable __curbrkis zero, the function calls<br />
div.ud<br />
__builtin_mulss<br />
Mô tả: Chức năng tính toán p1 p0x sản phẩm. Đối số chức năng là<br />
ký số nguyên, và kết quả chức năng là một số nguyên dài đã ký kết. Các<br />
tùy chọn-Wconversionscan dòng lệnh được sử dụng để phát hiện<br />
chuyển đổi tín hiệu không mong muốn.<br />
Prototype: ký __builtin_mulss dài (const int ký p0,<br />
const ký int p1);<br />
Đối số: p0 nhơn<br />
p1 nhân<br />
Quay trở lại giá trị: Trả về giá trị số nguyên dài ký của p1 p0x sản phẩm.<br />
Assembler<br />
Điều hành / Máy<br />
Hướng dẫn:<br />
mul.ss<br />
MPLAB C30 Built-in chức năng<br />
2004 Microchip Technology Inc DS51456B trang 377<br />
__builtin_mulsu<br />
Mô tả: Chức năng tính toán p1 p0x sản phẩm. Đối số chức năng là<br />
số nguyên có dấu hiệu hỗn hợp, và kết quả chức năng là một ký dài<br />
số nguyên. Các tùy chọn-Wconversionscan dòng lệnh được sử dụng để<br />
phát hiện chuyển đổi tín hiệu không mong muốn. Chức năng này hỗ trợ đầy đủ<br />
phạm vi giải quyết modesof hướng dẫn, bao gồm cả ngay lập tức<br />
chế độ cho toán hạng p1.<br />
Prototype: ký __builtin_mulsu dài (const int ký p0,<br />
const int p1);<br />
Đối số: p0 nhơn<br />
p1 nhân<br />
Quay trở lại giá trị: Trả về giá trị số nguyên dài ký của p1 p0x sản phẩm.<br />
Assembler<br />
Điều hành / Máy<br />
Hướng dẫn:<br />
mul.su<br />
__builtin_mulus<br />
Mô tả: Chức năng tính toán p1 p0x sản phẩm. Đối số chức năng là<br />
số nguyên có dấu hiệu hỗn hợp, và kết quả chức năng là một ký dài<br />
số nguyên. Các tùy chọn-Wconversionscan dòng lệnh được sử dụng để<br />
phát hiện chuyển đổi tín hiệu không mong muốn. Chức năng này hỗ trợ đầy đủ<br />
phạm vi giải quyết modesof hướng dẫn.
k()to<br />
initialize the break value. If brk()returns -1, so does this function.<br />
If the incris zero, the current value of the global variable __curbrkis<br />
returned.<br />
If the incris non-zero, the function checks that the address<br />
(__curbrk+ incr) is less than the end address of the heap. If it is<br />
less, the global variable __curbrkis updated to that value, and the<br />
function returns the unsigned value of __curbrk.<br />
Otherwise, the function returns -1.<br />
See the description of brk().<br />
File: sbrk.c<br />
system<br />
Description: Execute a command.<br />
Include: <br />
Prototype: int system(const char *s);<br />
Argument: s command to be executed.<br />
Default Behavior: As distributed, this function acts as a stub or placeholder for<br />
your<br />
function. If sis not NULL, an error message is written to stdout and the<br />
program will reset; otherwise, a value of -1 is returned.<br />
File: system.c<br />
Standard C Libraries with Math Functions<br />
2004 Microchip Technology Inc. DS51456B-page 373<br />
time<br />
Description: Get the system time.<br />
Include: <br />
Prototype: time_t time(time_t *timer);<br />
Argument: timer points to a storage location for time<br />
Return Value: Returns the elapse time in seconds. There is no error return.<br />
Default Behavior: As distributed, if timer2 is not enabled,it is enabled in 32-bit<br />
mode. The<br />
return value is the current value of the 32-bit timer2 register. Except in<br />
very rare cases, this return value is not the elapsed time in seconds.<br />
File: time.c<br />
write<br />
Description: Write data to a file.<br />
Include: None<br />
Prototype: int write(int handle, void *buffer, unsigned int<br />
count);<br />
Argument: handle refers to an opened file<br />
Prototype: ký __builtin_mulus dài (const int p0,<br />
const ký int p1);<br />
Đối số: p0 nhơn<br />
p1 nhân<br />
Quay trở lại giá trị: Trả về giá trị số nguyên dài ký của p1 p0x sản phẩm.<br />
Assembler<br />
Điều hành / Máy<br />
Hướng dẫn:<br />
mul.us<br />
__builtin_muluu<br />
Mô tả: Chức năng tính toán p1 p0x sản phẩm. Đối số chức năng là<br />
số nguyên unsigned, và kết quả chức năng là một số nguyên dài không dấu.<br />
Các tùy chọn-Wconversionscan dòng lệnh được sử dụng để phát hiện<br />
chuyển đổi tín hiệu không mong muốn. Chức năng này hỗ trợ đầy đủ các<br />
giải quyết các chế độ của các hướng dẫn, bao gồm cả chế độ ngay lập tức cho<br />
toán hạng p1.<br />
Prototype: unsigned __builtin_muluu dài (const int p0,<br />
const int p1);<br />
Đối số: p0 nhơn<br />
p1 nhân<br />
Quay trở lại giá trị: Trả về giá trị số nguyên dài ký của p1 p0x sản phẩm.<br />
Assembler<br />
Điều hành / Máy<br />
Hướng dẫn:<br />
mul.uu<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 378 2004 Microchip Technology Inc<br />
__builtin_tblpage<br />
Mô tả: Chức năng trả về số trang bảng của đối tượng mà<br />
địa chỉ được đưa ra như một tham số. Đối số pmust là địa chỉ<br />
của một đối tượng trong một dữ liệu EE, PSV hay không gian bộ nhớ thực thi;<br />
nếu không một thông báo lỗi được sản xuất và biên soạn không. Xem<br />
các spaceattribute trong MPLAB®<br />
Hướng dẫn C30 C Compiler của người dùng.<br />
Nguyên mẫu: int __builtin_tblpage (const void * p);<br />
Đối số: p địa chỉ đối tượng<br />
Quay trở lại giá trị: Trả về số trang bảng của đối tượng có địa chỉ được cho là
uffer points to the storage location of data to be written<br />
count the number of characters to write.<br />
Return Value: If successful, write returns the number of characters actually<br />
written. A<br />
return value of ‘-1’indicates an error.<br />
Remarks: If the actual space remaining on the disk is less than the size of the<br />
buffer the function is trying to write to the disk, write fails and does not<br />
flush any of the buffer's contents to the disk. If the file is opened in text<br />
mode, each linefeed character is replaced with a carriage return –<br />
linefeed pair in the output. The replacement does not affect the return<br />
value.<br />
This is a helper function called by the Standard C Library function<br />
fflush().<br />
Default Behavior: As distributed, the parameters are passed to the host file<br />
system<br />
through the simulator. The return value is the value returned by the host<br />
file system.<br />
File: write.c<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
một tham số.<br />
Assembler<br />
Điều hành / Máy<br />
Hướng dẫn:<br />
tblpage<br />
__builtin_tbloffset<br />
Mô tả: Chức năng trả về trang bảng bù đắp của các đối tượng có địa chỉ<br />
được đưa ra như một tham số. Đối số pmust là địa chỉ của một<br />
đối tượng trong một dữ liệu EE, PSV hay không gian bộ nhớ thực thi; nếu<br />
không một<br />
thông báo lỗi được sản xuất và biên soạn không. Xem không gian<br />
thuộc tính trong MPLAB®<br />
Hướng dẫn C30 C Compiler của người dùng.<br />
Nguyên mẫu: int __builtin_tbloffset (const void * p);<br />
Đối số: p địa chỉ đối tượng<br />
Quay trở lại giá trị: Trả về số trang bảng offsetof đối tượng có địa chỉ là<br />
được coi là một tham số.<br />
Assembler<br />
Điều hành / Máy<br />
Hướng dẫn:<br />
tbloffset<br />
DS51456B-page 374<br />
NOTES:<br />
dsPIC<br />
2004 Microchip Technology Inc.<br />
__builtin_psvpage<br />
Mô tả: Chức năng trả về số trang PSV của đối tượng có địa chỉ<br />
được đưa ra như một tham số. Đối số pmust là địa chỉ của một<br />
®LANGUAGE TOOLS<br />
LIBRARIES<br />
2004 Microchip Technology Inc. DS51456B-page 375<br />
Chapter 5. MPLAB C30 Built-in Functions<br />
5.1 INTRODUCTION<br />
This chapter describes the MPLAB C30 built-infunctions that are specific to<br />
dsPIC<br />
devices.<br />
Built-in functions give the C programmer access to assembler operators or<br />
machine<br />
instructions that are currently only accessibleusing inline assembly, but are<br />
sufficiently<br />
useful that they are applicable to a broad range of applications. Built-in<br />
functions are<br />
coded in C source files syntactically like function calls, but they are compiled to<br />
assembly code that directly implements the function, and do not involve<br />
function calls<br />
or library routines.<br />
đối tượng trong một dữ liệu EE, PSV hay không gian bộ nhớ thực thi; nếu<br />
không một<br />
thông báo lỗi được sản xuất và biên soạn không. Xem không gian<br />
thuộc tính trong MPLAB®<br />
Hướng dẫn C30 C Compiler của người dùng.<br />
Nguyên mẫu: int __builtin_psvpage (const void * p);<br />
Đối số: p địa chỉ đối tượng<br />
Quay trở lại giá trị: Trả về số trang PSV của đối tượng có địa chỉ được đưa ra<br />
như một<br />
tham số.<br />
Assembler<br />
Điều hành / Máy<br />
Hướng dẫn:<br />
psvpage<br />
MPLAB C30 Built-in chức năng<br />
2004 Microchip Technology Inc DS51456B trang 379<br />
5.3 CHỨC NĂNG THÔNG ĐIỆP LỖI Xây-IN
There are a number of reasons why providing built-in functions is preferable to<br />
requiring programmers to use inline assembly. They include the following:<br />
1. Providing built-in functions for specific purposes simplifies coding.<br />
2. Certain opitmizations are disabled when inline assembly is used. This is not<br />
the<br />
case for built-in functions.<br />
3. For machine instructions that use dedicated registers, coding inline assembly<br />
while avoiding register allocation errors can require considerable care. The<br />
built-in functions make this process simpler as you do not need to be concerned<br />
with the particular register requirements for each individual machine<br />
instruction.<br />
This chapter is organized as follows:<br />
• Built-In Function List<br />
• Built-In Function Error Messages<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 376<br />
5.2 BUILT-IN FUNCTION LIST<br />
2004 Microchip Technology Inc.<br />
This section describes the programmer interface to the MPLAB C30 C compiler<br />
built-in<br />
functions. Since the functions are “built in”, there are no header files associated<br />
with<br />
them. Similarly, there are no command-line switches associated with the built-in<br />
functions – they are always available. The built-in function names are chosen<br />
such that<br />
they belong to the compiler's namespace (they all have the prefix __builtin_), so<br />
they will not conflict with function or variable names in the programmer's<br />
namespace.<br />
__builtin_divsd<br />
Description: The function computes the quotient num/ den. A math error<br />
exception<br />
occurs if denis zero. Function arguments are signed, as is the function<br />
result. The command-line option -Wconversionscan be used to<br />
detect unexpected sign conversions.<br />
Prototype: int __builtin_divsd(const long num, const int den);<br />
Argument: num numerator<br />
den denominator<br />
Return Value: Returns the signed integer value of the quotient num/ den.<br />
Assembler<br />
Operator / Machine<br />
Instruction:<br />
Các thông báo lỗi sau đây được tạo ra khi các chức năng tích hợp được sử dụng<br />
không chính xác.<br />
Tham số để __builtin_function () không phải là địa chỉ của một đối tượng trong<br />
mã, PSV, hoặc phần EEDATA<br />
Đối số cho các chức năng tích hợp sau đây phải là một địa chỉ đối tượng rõ<br />
ràng:<br />
• __builtin_tblpage<br />
• __builtin_tbloffset<br />
• __builtin_psvpage<br />
• __builtin_psvoffset<br />
Ví dụ, nếu objis đối tượng trong một phần thực thi hoặc chỉ đọc, cú pháp sau<br />
có giá trị:<br />
unsigned trang = __builtin_function (& obj);<br />
__builtin_psvoffset<br />
Mô tả: Chức năng trả về trang PSV bù đắp của các đối tượng có địa chỉ là<br />
được coi là một tham số. Đối số pmust là địa chỉ của một<br />
đối tượng trong một dữ liệu EE, PSV hay không gian bộ nhớ thực thi; nếu<br />
không một<br />
thông báo lỗi được sản xuất và biên soạn không. Xem không gian<br />
thuộc tính trong MPLAB®<br />
Hướng dẫn C30 C Compiler của người dùng.<br />
Nguyên mẫu: int __builtin_psvoffset (const void * p);<br />
Đối số: p địa chỉ đối tượng<br />
Quay trở lại giá trị: Trả về số trang PSV offsetof đối tượng có địa chỉ là<br />
được coi là một tham số.<br />
Assembler<br />
Điều hành / Máy<br />
Hướng dẫn:<br />
psvoffset<br />
__builtin_return_address<br />
Mô tả: Chức năng này trả về địa chỉ trả về của hàm hiện tại, hoặc của<br />
một trong những người gọi của nó. Đối với levelargument một giá trị từ 0 sản<br />
lượng<br />
địa chỉ trả về của hàm hiện nay, giá trị sản lượng 1 sự trở lại<br />
địa chỉ của người gọi của chức năng hiện tại, và vv. Khi mức độ<br />
vượt quá chiều sâu ngăn xếp hiện tại, 0 sẽ được trả lại. Chức năng này<br />
chỉ nên được sử dụng với một đối số khác không cho mục đích gỡ lỗi.<br />
Nguyên mẫu: int __builtin_return_address (const mức int);<br />
Đối số: mức Số khung để quét lên gọi chồng.<br />
Quay trở lại giá trị: Trả về địa chỉ trả về của hàm hiện tại, hoặc của một trong<br />
của nó
div.sd<br />
__builtin_divud<br />
Description: The function computes the quotient num/ den. A math error<br />
exception<br />
occurs if denis zero. Function argumentsare unsigned, as is the<br />
function result. The command-line option -Wconversionscan be<br />
used to detect unexpected sign conversions.<br />
Prototype: unsigned int __builtin_divud(const unsigned<br />
người gọi.<br />
Assembler<br />
Điều hành / Máy<br />
Hướng dẫn:<br />
return_address<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
long num, const unsigned int den);<br />
Argument: num numerator<br />
den denominator<br />
DS51456B trang 380<br />
GHI CHÚ:<br />
dsPIC<br />
2004 Microchip Technology Inc<br />
Return Value: Returns the unsigned integervalue of the quotient num/ den.<br />
Assembler<br />
Operator / Machine<br />
Instruction:<br />
div.ud<br />
__builtin_mulss<br />
Description: The function computes the product p0x p1. Function arguments are<br />
signed integers, and the function result is a signed long integer. The<br />
command-line option-Wconversionscan be used to detect<br />
unexpected sign conversions.<br />
Prototype: signed long __builtin_mulss(const signed int p0,<br />
const signed int p1);<br />
Argument: p0 multiplicand<br />
p1 multiplier<br />
Return Value: Returns the signed long integer value of the product p0x p1.<br />
Assembler<br />
Operator / Machine<br />
Instruction:<br />
mul.ss<br />
MPLAB C30 Built-in Functions<br />
2004 Microchip Technology Inc. DS51456B-page 377<br />
__builtin_mulsu<br />
Description: The function computes the product p0x p1. Function arguments are<br />
integers with mixed signs, and the function result is a signed long<br />
integer. The command-line option-Wconversionscan be used to<br />
detect unexpected sign conversions. This function supports the full<br />
range of addressing modesof the instruction, including immediate<br />
®LANGUAGE CÔNG CỤ<br />
THƯ VIỆN<br />
2004 Microchip Technology Inc DS51456B trang 381<br />
Phụ lục A. ASCII Character Set<br />
BẢNG A-1: ASCII CHARACTER SET<br />
Hầu hết các nhân vật quan trọng<br />
Nhân vật quan trọng nhất<br />
Hex01234567<br />
0 NUL DLE Space 0 @ P 'p<br />
1 SOH DC1! 1 AQ aq<br />
2 STX DC2 "2 BR br<br />
3 ETX DC3 # 3 CS cs<br />
4 EOT DC4 $ 4 DT dt<br />
5 ENQ NAK 5% EU eu<br />
6ACKSYN & 6 FV FV<br />
7BellETB '7 GW GW<br />
8BSCAN (8 HX hx<br />
9HTEM) 9 IY iy<br />
ALFSUB *: JZ jz<br />
BVTESC +; K [k {<br />
CFFFS, N ^ n ~<br />
FSIUS / O_ Odel?<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
mode for operand p1.<br />
DS51456B trang 382<br />
2004 Microchip Technology Inc
Prototype: signed long __builtin_mulsu(const signed int p0,<br />
const unsigned int p1);<br />
Argument: p0 multiplicand<br />
p1 multiplier<br />
Return Value: Returns the signed long integer value of the product p0x p1.<br />
Assembler<br />
Operator / Machine<br />
Instruction:<br />
mul.su<br />
__builtin_mulus<br />
Description: The function computes the product p0x p1. Function arguments are<br />
integers with mixed signs, and the function result is a signed long<br />
integer. The command-line option-Wconversionscan be used to<br />
detect unexpected sign conversions. This function supports the full<br />
range of addressing modesof the instruction.<br />
Prototype: signed long __builtin_mulus(const unsigned int p0,<br />
const signed int p1);<br />
Argument: p0 multiplicand<br />
p1 multiplier<br />
Return Value: Returns the signed long integer value of the product p0x p1.<br />
Assembler<br />
Operator / Machine<br />
Instruction:<br />
mul.us<br />
__builtin_muluu<br />
Description: The function computes the product p0x p1. Function arguments are<br />
unsigned integers, and the function result is an unsigned long integer.<br />
The command-line option-Wconversionscan be used to detect<br />
unexpected sign conversions. This function supports the full range of<br />
addressing modes of the instruction, including immediate mode for<br />
operand p1.<br />
Prototype: unsigned long __builtin_muluu(const unsigned int p0,<br />
const unsigned int p1);<br />
Argument: p0 multiplicand<br />
p1 multiplier<br />
Return Value: Returns the signed long integer value of the product p0x p1.<br />
Assembler<br />
Operator / Machine<br />
Instruction:<br />
GHI CHÚ:<br />
dsPIC<br />
®LANGUAGE CÔNG CỤ<br />
THƯ VIỆN<br />
2004 Microchip Technology Inc DS51456B trang 383<br />
Chỉ số<br />
Biểu tượng<br />
# xác định ..................... 10, 74, 76, 99, 106, 147, 163, 185<br />
# nếu ................................................ ........................... 211<br />
# include ................................................ ....... 10, 74, 194<br />
%, Phần trăm ...................................... 254, 259, 260, 323<br />
-, Dash ............................................... .................... 260<br />
\ F, mẫu thức ăn ............................................. ............ 201<br />
\ N, dòng mới ............... 201, 225, 235, 240, 251, 252, 256<br />
\ R, vận chuyển trở lại ............................................. 201 ....<br />
\ T, ngang Tab ............................................. ....... 201<br />
\ V, dọc Tab ............................................. .......... 201<br />
^, Caret ............................................... .................... 260<br />
__builtin_divsd ................................................. ...... 376<br />
__builtin_divud ................................................. ...... 376<br />
__builtin_mulss ................................................. ..... 376<br />
__builtin_mulsu ................................................. ..... 377<br />
__builtin_mulus ................................................. ..... 377<br />
__builtin_muluu ................................................. ..... 377<br />
__builtin_psvoffset ................................................. 379<br />
__builtin_psvpage ................................................. . 378<br />
__builtin_return_address ....................................... 379<br />
__builtin_tbloffset ................................................. 378 ..<br />
__builtin_tblpage ................................................. 378 ...<br />
__FILE__ ................................................. .............. 195<br />
__LINE__ ................................................. .............. 195<br />
_exit ................................................. ...................... 367<br />
_IOFBF ................................................. ..226, 261, 262<br />
_IOLBF ................................................. ........... 226, 262<br />
_IONBF ................................................. ..226, 261, 262<br />
_MathError ................................................. ............ 219<br />
_NSETJMP ................................................. ........... 214<br />
Numerics<br />
0x ................................................. ... 202, 253, 291, 292
mul.uu<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 378<br />
__builtin_tblpage<br />
2004 Microchip Technology Inc.<br />
Description: The function returns the table page number of the object whose<br />
address is given as a parameter. The argument pmust be the address<br />
of an object in an EE data, PSV or executable memory space;<br />
otherwise an error message is produced and the compilation fails. See<br />
the spaceattribute in the MPLAB®<br />
C30 C Compiler User’s Guide.<br />
Prototype: unsigned int __builtin_tblpage(const void *p);<br />
Argument: p object address<br />
Return Value: Returns the table page number of the object whose address is<br />
given as<br />
a parameter.<br />
Assembler<br />
Operator / Machine<br />
Instruction:<br />
tblpage<br />
__builtin_tbloffset<br />
Description: The function returns the table page offset of the object whose<br />
address<br />
is given as a parameter. The argument pmust be the address of an<br />
object in an EE data, PSV or executable memory space; otherwise an<br />
error message is produced and the compilation fails. See the space<br />
attribute in the MPLAB®<br />
C30 C Compiler User’s Guide.<br />
Prototype: unsigned int __builtin_tbloffset(const void *p);<br />
Argument: p object address<br />
Return Value: Returns the table page number offsetof the object whose address<br />
is<br />
given as a parameter.<br />
Assembler<br />
Operator / Machine<br />
Instruction:<br />
tbloffset<br />
__builtin_psvpage<br />
Description: The function returns the psv page number of the object whose<br />
address<br />
Một<br />
Chấm dứt bất thường Tín hiệu ................................. 216<br />
hủy bỏ ................................................. ............... 195, 271<br />
abs ................................................. ........................ 272<br />
Giá trị tuyệt đối<br />
Đôi Floating Point ..................................... 339<br />
Integer ................................................. ............ 272<br />
Long Integer ................................................ 282 ....<br />
Độc Floating Point ....................................... 339<br />
Giá trị tuyệt đối Chức năng<br />
abs ................................................. ................. 272<br />
fabs ................................................. ................ 339<br />
fabsf ................................................. ............... 339<br />
phòng thí nghiệm ................................................. ................ 282<br />
Chế độ truy cập<br />
................................................. Nhị phân ............. 236<br />
Văn bản ................................................. ................ 236<br />
AckI2C ................................................. ................... 184<br />
acos ................................................. ....................... 325<br />
acosf ................................................. ...................... 326<br />
ADC, 10-Bit<br />
................................................. Bận rộn ............... 102<br />
Đóng ................................................. .............. 102<br />
Cấu hình ngắt .......................................... 102<br />
Vô hiệu hóa ngắt Macro ................................... 107<br />
Kích hoạt tính năng ngắt Macro ................................... 107<br />
Ví dụ sử dụng ............................................... 108<br />
Mở ................................................. .............. 103<br />
Đọc ................................................. .............. 106<br />
Thiết lập kênh ................................................ 106 ....<br />
Thiết lập ngắt PriorityMacro ............................. 107<br />
Bắt đầu chuyển đổi ............................................. 103<br />
Dừng lấy mẫu ................................................ . 106<br />
ADC, 12-Bit<br />
................................................. Bận rộn ................. 95<br />
Đóng ................................................. ................ 95<br />
Cấu hình ngắt ............................................ 95<br />
Vô hiệu hóa ngắt Macro ................................... 100<br />
Kích hoạt tính năng ngắt Macro ................................... 100
is given as a parameter. The argument pmust be the address of an<br />
object in an EE data, PSV or executable memory space; otherwise an<br />
error message is produced and the compilation fails. See the space<br />
attribute in the MPLAB®<br />
C30 C Compiler User’s Guide.<br />
Prototype: unsigned int __builtin_psvpage(const void *p);<br />
Argument: p object address<br />
Return Value: Returns the psv page number of the object whose address is given<br />
as a<br />
parameter.<br />
Assembler<br />
Operator / Machine<br />
Instruction:<br />
psvpage<br />
MPLAB C30 Built-in Functions<br />
2004 Microchip Technology Inc. DS51456B-page 379<br />
5.3 BUILT-IN FUNCTION ERROR MESSAGES<br />
The following error messages are produced when the built-in functions are used<br />
incorrectly.<br />
Argument to __builtin_function() is not the address of an object in<br />
code, psv, or eedata section<br />
The argument to the following built-in functions must be an explicit object<br />
address:<br />
• __builtin_tblpage<br />
• __builtin_tbloffset<br />
• __builtin_psvpage<br />
• __builtin_psvoffset<br />
For example, if objis object in an executable or read-only section, the following<br />
syntax<br />
is valid:<br />
unsigned page = __builtin_function(&obj);<br />
__builtin_psvoffset<br />
Description: The function returns the psv page offset of the object whose<br />
address is<br />
given as a parameter. The argument pmust be the address of an<br />
object in an EE data, PSV or executable memory space; otherwise an<br />
error message is produced and the compilation fails. See the space<br />
attribute in the MPLAB®<br />
C30 C Compiler User’s Guide.<br />
Prototype: unsigned int __builtin_psvoffset(const void *p);<br />
Argument: p object address<br />
Ví dụ sử dụng ............................................... 101<br />
Mở ................................................. ................ 96<br />
Đọc ................................................. ................ 99<br />
Thiết lập kênh ................................................ ...... 99<br />
Thiết lập ngắt PriorityMacro ............................. 100<br />
Bắt đầu chuyển đổi ............................................... 96<br />
Dừng lấy mẫu ................................................ 99 ...<br />
Cấp phát bộ nhớ ................................................ 284 ....<br />
calloc ................................................. .............. 278<br />
Miễn phí ................................................. ................ 281<br />
realloc ................................................. ............ 287<br />
Ký tự chữ cái<br />
Xác định ................................................. ........... 196<br />
Kiểm tra cho ................................................ ............ 196<br />
Kí tự<br />
Xác định ................................................. ........... 196<br />
Kiểm tra cho ................................................ ............ 196<br />
AM / PM ............................................... .................... 323<br />
Nối ................................................. .......... 300, 306<br />
arccosine<br />
Đôi Floating Point ...................................... 325<br />
Độc Floating Point ....................................... 326<br />
arcsine<br />
Đôi Floating Point ...................................... 327<br />
Độc Floating Point ....................................... 327<br />
arctangent<br />
Đôi Floating Point ...................................... 328<br />
Độc Floating Point ....................................... 329<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 384 2004 Microchip Technology Inc<br />
arctangent của y / x<br />
Đôi Floating Point ...................................... 329<br />
Độc Floating Point ....................................... 331<br />
Danh sách tham số .................................. 221, 267, 268, 269<br />
Thông báo lỗi số học ....................................... 216<br />
ASCII Character Set ............................................... 381<br />
asctime ................................................. .................. 318
Return Value: Returns the psv page number offsetof the object whose address is<br />
given as a parameter.<br />
Assembler<br />
Operator / Machine<br />
Instruction:<br />
psvoffset<br />
__builtin_return_address<br />
Description: This function returns the return address of the current function, or<br />
of<br />
one of its callers. For the levelargument, a value of 0 yields the<br />
return address of the current function, a value of 1 yields the return<br />
address of the caller of the current function, and so forth. When level<br />
exceeds the current stack depth, 0 will be returned. This function<br />
should only be used with a non-zero argument for debugging purposes.<br />
Prototype: int __builtin_return_address (const int level);<br />
Argument: level Number of frames to scan up the call stack.<br />
Return Value: Returns the the return address of the current function, or of one of<br />
its<br />
callers.<br />
Assembler<br />
Operator / Machine<br />
Instruction:<br />
return_address<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 380<br />
NOTES:<br />
dsPIC<br />
®LANGUAGE TOOLS<br />
LIBRARIES<br />
2004 Microchip Technology Inc.<br />
2004 Microchip Technology Inc. DS51456B-page 381<br />
Appendix A. ASCII Character Set<br />
TABLE A-1: ASCII CHARACTER SET<br />
Most Significant Character<br />
Least Significant Character<br />
Hex01234567<br />
0 NUL DLE Space 0 @ P ‘ p<br />
1 SOH DC1 ! 1 A Q a q<br />
2 STX DC2 " 2 B R b r<br />
asin ................................................. ........................ 327<br />
asinf ................................................. ....................... 327<br />
khẳng định ................................................. .................... 195<br />
assert.h ............................................... ................... 195<br />
Phân Ngăn chặn ........................................ 259<br />
Asterisk ................................................. ......... 253, 259<br />
atan ................................................. ....................... 328<br />
atan2 ................................................. ..................... 329<br />
atan2f ................................................. .................... 331<br />
atanf ................................................. ...................... 329<br />
atexit ................................................. .............. 272, 280<br />
atof ................................................. ........................ 274<br />
atoi ................................................. ........................ 275<br />
atol ................................................. ........................ 275<br />
B<br />
BartlettInit ................................................. ................ 26<br />
Cơ sở ................................................. .............. 291, 292<br />
10 ............................. 207, 208, 209, 210, 350, 351<br />
2 ................................................. ..................... 209<br />
e ................................................. ............. 349, 352<br />
FLT_RADIX .............. 206, 207, 208, 209, 210, 211<br />
Nhị phân<br />
Cơ sở ................................................. ............... 209<br />
Chế độ ................................................. ...... 236, 264<br />
Tìm kiếm ................................................. ............ 276<br />
Suối ................................................. .......... 225<br />
Bitfields ................................................. .................. 224<br />
BitReverseComplex ................................................. . 60<br />
BlackmanInit ................................................. ............ 27<br />
BORStatReset ................................................. ....... 119<br />
brk ................................................. ................. 367, 372<br />
bsearch ................................................. ................. 276<br />
Dung lượng bộ đệm ................................................ ...... 226, 262<br />
BufferEmptyDCI ................................................. 150 ....<br />
Chế độ đệm ................................................ ..... 262<br />
Đệm, Đệm SeeFile<br />
BUFSIZ ................................................. ......... 226, 261<br />
Được xây dựng trong chức năng<br />
__builtin_divsd ................................................ 376
3 ETX DC3 # 3 C S c s<br />
4 EOT DC4 $ 4 D T d t<br />
5 ENQ NAK % 5 E U e u<br />
6ACKSYN& 6 F V f v<br />
7BellETB’ 7 G W g w<br />
8BSCAN( 8 H X h x<br />
9HTEM) 9 I Y i y<br />
ALFSUB* : J Z j z<br />
BVTESC+ ; K [ k {<br />
CFFFS , < L \ l |<br />
DCRGS- =M]m}<br />
ESORS . > N ^ n ~<br />
FSIUS/ ?O_ oDEL<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 382 2004 Microchip Technology Inc.<br />
NOTES:<br />
dsPIC<br />
®LANGUAGE TOOLS<br />
LIBRARIES<br />
2004 Microchip Technology Inc. DS51456B-page 383<br />
Index<br />
Symbols<br />
#define .....................10, 74, 76, 99, 106, 147, 163, 185<br />
#if ........................................................................... 211<br />
#include.......................................................10, 74, 194<br />
%, Percent ...................................... 254, 259, 260, 323<br />
-, Dash ................................................................... 260<br />
\f, Form Feed ......................................................... 201<br />
\n, Newline ...............201, 225, 235, 240, 251, 252, 256<br />
\r, Carriage Return ................................................. 201<br />
\t, Horizontal Tab.................................................... 201<br />
\v, Vertical Tab ....................................................... 201<br />
^, Caret................................................................... 260<br />
__builtin_divsd ....................................................... 376<br />
__builtin_divud ....................................................... 376<br />
__builtin_mulss ...................................................... 376<br />
__builtin_mulsu ...................................................... 377<br />
__builtin_divud ................................................ 376<br />
__builtin_mulss ............................................... 376<br />
__builtin_mulsu ............................................... 377<br />
__builtin_mulus ............................................... 377<br />
__builtin_muluu ............................................... 377<br />
__builtin_psvoffset .......................................... 379<br />
__builtin_psvpage ........................................... 378<br />
__builtin_return_address ................................ 379<br />
__builtin_tbloffset ............................................ 378<br />
__builtin_tblpage ............................................. 378<br />
BusyADC10 ................................................. ........... 102<br />
BusyADC12 ................................................. ............. 95<br />
BusyUartx ................................................. .............. 141<br />
BusyXLCD ................................................. ............... 75<br />
C<br />
C Locale ................................................ ......... 196, 213<br />
Lịch Thời gian ......................... 317, 319, 320, 322, 324<br />
calloc ................................................. ............. 278, 281<br />
THỂ Ngắt<br />
Cấu hình ................................................. .......... 91<br />
Vô hiệu hóa Macro ................................................ 92 ...<br />
Kích hoạt tính năng Macro ................................................ 92 ....<br />
Đặt ưu tiên Macro .............................................. 92<br />
CAN, Ví dụ sử dụng ............................................. . 93<br />
CANxAbortAll ................................................. .......... 81<br />
CANxGetRXErrorCount ............................................ 81<br />
CANxGetTXErrorCount ............................................ 82<br />
CANxInitialize ................................................. .......... 90<br />
CANxIsBusOff ................................................. ......... 82<br />
CANxIsRXPassive ................................................. 83 ...<br />
CANxIsRXReady ................................................. ..... 82<br />
CANxIsTXPassive ................................................. 83 ...<br />
CANxIsTXReady ................................................. ..... 84<br />
CANxRecieveMessage ............................................ 84<br />
CANxSendMessage ................................................. 85<br />
CANxSetFilter ................................................. .......... 86<br />
CANxSetMask ................................................. ......... 86<br />
CANxSetOperationMode .......................................... 87<br />
CANxSetOperationModeNoWait .............................. 88
__builtin_mulus ...................................................... 377<br />
__builtin_muluu...................................................... 377<br />
__builtin_psvoffset ................................................. 379<br />
__builtin_psvpage .................................................. 378<br />
__builtin_return_address ....................................... 379<br />
__builtin_tbloffset ................................................... 378<br />
__builtin_tblpage.................................................... 378<br />
__FILE__ ............................................................... 195<br />
__LINE__ ............................................................... 195<br />
_exit ....................................................................... 367<br />
_IOFBF ...................................................226, 261, 262<br />
_IOLBF............................................................226, 262<br />
_IONBF ...................................................226, 261, 262<br />
_MathError ............................................................. 219<br />
_NSETJMP ............................................................ 214<br />
Numerics<br />
0x .................................................... 202, 253, 291, 292<br />
A<br />
Abnormal Termination Signal................................. 216<br />
abort................................................................195, 271<br />
abs ......................................................................... 272<br />
Absolute Value<br />
Double Floating Point ..................................... 339<br />
Integer............................................................. 272<br />
Long Integer.................................................... 282<br />
Single Floating Point....................................... 339<br />
Absolute Value Function<br />
abs .................................................................. 272<br />
fabs ................................................................. 339<br />
fabsf ................................................................ 339<br />
labs ................................................................. 282<br />
Access Mode<br />
Binary.............................................................. 236<br />
Text................................................................. 236<br />
AckI2C.................................................................... 184<br />
acos........................................................................ 325<br />
acosf....................................................................... 326<br />
ADC, 10-Bit<br />
Busy ................................................................ 102<br />
CANxSetRXMode ................................................. 88 ....<br />
CANxSetTXMode ................................................. 89 ....<br />
Caret (^) .............................................. .................... 260<br />
Vận chuyển trở lại ................................................ ...... 201<br />
ceil ................................................. ......................... 332<br />
ceilf ................................................. ........................ 333<br />
trần<br />
Đôi Floating Point ...................................... 332<br />
Độc Floating Point ....................................... 333<br />
char<br />
Giá trị tối đa .............................................. 211<br />
Giá trị tối thiểu ............................................... 211<br />
Số Bits ............................................... . 211<br />
CHAR_BIT ................................................. ............. 211<br />
CHAR_MAX ................................................. .......... 211<br />
CHAR_MIN ................................................. ............ 211<br />
Nhân vật mảng ................................................ ...... 260<br />
Trường hợp bản đồ nhân vật<br />
Trường hợp thấp hơn nhân vật chữ cái .................. 203<br />
Trường hợp chữ cái trên nhân vật .................. 204<br />
Trường hợp bản đồ nhân vật chức năng<br />
ToLower ................................................. ............ 203<br />
toupper ................................................. ........... 204<br />
Xử lý nhân vật, Seectype.h<br />
Character Input / Output Chức năng<br />
fgetc ................................................. ............... 233<br />
fgets ................................................. ............... 235<br />
fputc ................................................. ............... 239<br />
fputs ................................................. ............... 239<br />
getc ................................................. ................ 250<br />
getchar ................................................. ........... 251<br />
được ................................................. ................ 251<br />
putc ................................................. ................ 255<br />
putchar ................................................. ........... 256<br />
đặt ................................................. ................ 256<br />
ungetc ................................................. ............ 265<br />
Chỉ số<br />
2004 Microchip Technology Inc DS51456B trang 385<br />
Kiểm tra nhân vật
Close............................................................... 102<br />
Configure Interrupt.......................................... 102<br />
Disable Interrupt Macro................................... 107<br />
Enable Interrupt Macro ................................... 107<br />
Example of Use............................................... 108<br />
Open ............................................................... 103<br />
Read ............................................................... 106<br />
Set Channel .................................................... 106<br />
Set Interrupt PriorityMacro ............................. 107<br />
Start Conversion ............................................. 103<br />
Stop Sampling................................................. 106<br />
ADC, 12-Bit<br />
Busy .................................................................. 95<br />
Close................................................................. 95<br />
Configure Interrupt............................................ 95<br />
Disable Interrupt Macro................................... 100<br />
Enable Interrupt Macro ................................... 100<br />
Example of Use............................................... 101<br />
Open ................................................................. 96<br />
Read ................................................................. 99<br />
Set Channel ...................................................... 99<br />
Set Interrupt PriorityMacro ............................. 100<br />
Start Conversion ............................................... 96<br />
Stop Sampling................................................... 99<br />
Allocate Memory .................................................... 284<br />
calloc............................................................... 278<br />
Free................................................................. 281<br />
realloc ............................................................. 287<br />
Alphabetic Character<br />
Defined............................................................ 196<br />
Test for ............................................................ 196<br />
Alphanumeric Character<br />
Defined............................................................ 196<br />
Test for ............................................................ 196<br />
AM/PM ................................................................... 323<br />
Append........................................................... 300, 306<br />
arccosine<br />
Double Floating Point...................................... 325<br />
Single Floating Point ....................................... 326<br />
Ký tự chữ cái ...................................... 196<br />
Kí tự ................................. 196<br />
Điều khiển nhân vật ........................................... 197<br />
Chữ số thập phân ................................................ 198 ...<br />
Nhân vật đồ họa ........................................ 198<br />
Chữ số thập lục phân ........................................... 202<br />
Trường hợp thấp hơn nhân vật chữ cái .................. 199<br />
Nhân vật có thể in ......................................... 200<br />
Dấu phân cách nhân vật .................................... 200<br />
Trường hợp chữ cái trên nhân vật .................. 202<br />
Trắng không gian nhân vật .................................. 201<br />
Chức năng kiểm tra nhân vật<br />
isalnum ................................................. .......... 196<br />
isalpha ................................................. ........... 196<br />
iscntrl ................................................. ............. 197<br />
isdigit ................................................. .............. 198<br />
isgraph ................................................. ........... 198<br />
islower ................................................. ............ 199<br />
isprint ................................................. ............. 200<br />
ispunct ................................................. ........... 200<br />
isspace ................................................. ........... 201<br />
isupper ................................................. ........... 202<br />
isxdigit ................................................. ............ 202<br />
Nhân vật<br />
Chữ cái ................................................. ...... 196<br />
Chữ và số ................................................. . 196<br />
Kiểm soát ................................................. ........... 197<br />
Chuyển đổi sang Hạ Trường hợp chữ cái ................. 203<br />
Chuyển đổi sang Upper Case chữ cái ................. 204<br />
Chữ số thập phân ................................................ 198 ...<br />
................................................. Đồ họa ....... 198<br />
Chữ số thập lục phân ........................................... 202<br />
Thấp hơn trường hợp chữ cái ................................... 199<br />
................................................. Có thể in ......... 200<br />
Dấu chấm câu ................................................. 200 ....<br />
Trường hợp chữ cái trên ................................... 202<br />
Trắng-Space ............................................... 201 ....<br />
Nhân vật phân loại ........................................... 196<br />
clearerr ................................................. .................. 229
arcsine<br />
Double Floating Point...................................... 327<br />
Single Floating Point ....................................... 327<br />
arctangent<br />
Double Floating Point...................................... 328<br />
Single Floating Point ....................................... 329<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 384 2004 Microchip Technology Inc.<br />
arctangent of y/x<br />
Double Floating Point...................................... 329<br />
Single Floating Point ....................................... 331<br />
Argument List ..................................221, 267, 268, 269<br />
Arithmetic Error Message....................................... 216<br />
ASCII Character Set............................................... 381<br />
asctime ................................................................... 318<br />
asin......................................................................... 327<br />
asinf........................................................................ 327<br />
assert ..................................................................... 195<br />
assert.h .................................................................. 195<br />
Assignment Suppression........................................ 259<br />
Asterisk .......................................................... 253, 259<br />
atan ........................................................................ 328<br />
atan2 ...................................................................... 329<br />
atan2f ..................................................................... 331<br />
atanf ....................................................................... 329<br />
atexit............................................................... 272, 280<br />
atof ......................................................................... 274<br />
atoi ......................................................................... 275<br />
atol ......................................................................... 275<br />
B<br />
BartlettInit ................................................................. 26<br />
Base ............................................................... 291, 292<br />
10 ............................. 207, 208, 209, 210, 350, 351<br />
2 ...................................................................... 209<br />
e .............................................................. 349, 352<br />
FLT_RADIX.............. 206, 207, 208, 209, 210, 211<br />
Binary<br />
Lỗi thanh toán bù trừ chỉ số .......................................... 229<br />
đồng hồ ................................................. ...................... 318<br />
clock_t ................................................. ............ 317, 318<br />
CLOCKS_PER_SEC ............................................. 317<br />
gần ................................................. ...................... 368<br />
CloseADC10 ................................................. ......... 102<br />
CloseADC12 ................................................. ........... 95<br />
CloseCapturex ................................................. ...... 125<br />
CloseDCI ................................................. ............... 150<br />
CloseI2C ................................................. ............... 183<br />
CloseINTx ................................................. ............. 120<br />
CloseMCPWM ................................................. ....... 171<br />
CloseOCx ................................................. .............. 131<br />
CloseQEI ................................................. ............... 166<br />
CloseSPIx ................................................. ............. 158<br />
CloseTimerx ................................................. .......... 109<br />
CloseTimerxx ................................................. ........ 109<br />
CloseUARTx ................................................. ......... 141<br />
Định nghĩa phổ biến, Seestddef.h<br />
So sánh Strings ................................................ 302 ....<br />
So sánh chức năng ...................................... 276, 286<br />
Chức năng so sánh<br />
memcmp ................................................. ........ 295<br />
strcmp ................................................. ............ 302<br />
strcoll ................................................. .............. 303<br />
strncmp ................................................. .......... 308<br />
strxfrm ................................................. ............ 316<br />
Tùy chọn trình biên dịch<br />
-fno-ngắn đôi ............................................ . 225<br />
-msmart-io .............................................. ......... 225<br />
Chức năng nối<br />
strcat ................................................. .............. 300<br />
strncat ................................................. ............ 306<br />
ConfigCNPullups ................................................. 122 ...<br />
ConfigIntADC10 ................................................. 102 ....<br />
ConfigIntADC12 ................................................. ...... 95<br />
ConfigIntCANx ................................................. ........ 91<br />
ConfigIntCapturex ................................................. . 126<br />
ConfigIntCN ................................................. ........... 122
Base................................................................ 209<br />
Mode ....................................................... 236, 264<br />
Search............................................................. 276<br />
Streams........................................................... 225<br />
Bitfields................................................................... 224<br />
BitReverseComplex.................................................. 60<br />
BlackmanInit............................................................. 27<br />
BORStatReset........................................................ 119<br />
brk .................................................................. 367, 372<br />
bsearch .................................................................. 276<br />
Buffer Size...................................................... 226, 262<br />
BufferEmptyDCI ..................................................... 150<br />
Buffering Modes ..................................................... 262<br />
Buffering, SeeFile Buffering<br />
BUFSIZ .......................................................... 226, 261<br />
Built-In Functions<br />
__builtin_divsd ................................................ 376<br />
__builtin_divud ................................................ 376<br />
__builtin_mulss ............................................... 376<br />
__builtin_mulsu ............................................... 377<br />
__builtin_mulus ............................................... 377<br />
__builtin_muluu............................................... 377<br />
__builtin_psvoffset .......................................... 379<br />
__builtin_psvpage ........................................... 378<br />
__builtin_return_address ................................ 379<br />
__builtin_tbloffset ............................................ 378<br />
__builtin_tblpage............................................. 378<br />
BusyADC10............................................................ 102<br />
BusyADC12.............................................................. 95<br />
BusyUartx............................................................... 141<br />
BusyXLCD................................................................ 75<br />
C<br />
C Locale ......................................................... 196, 213<br />
Calendar Time.........................317, 319, 320, 322, 324<br />
calloc .............................................................. 278, 281<br />
CAN Interrupts<br />
Configure........................................................... 91<br />
Disable Macro ................................................... 92<br />
Enable Macro .................................................... 92<br />
ConfigIntDCI ................................................. .......... 151<br />
ConfigIntI2C ................................................. .......... 183<br />
ConfigIntlOCx ................................................. ........ 132<br />
ConfigIntMCPWM ................................................. . 171<br />
ConfigIntQEI ................................................. .......... 166<br />
ConfigIntSpIx ................................................. ......... 158<br />
ConfigIntTimerx ................................................. ..... 110<br />
ConfigIntTimerxx ................................................. 111 ...<br />
ConfigIntUARTx ................................................. 142 ....<br />
ConfigINTx ................................................. ............ 121<br />
Điều khiển nhân vật<br />
Xác định ................................................. ........... 197<br />
Kiểm tra cho ................................................ ............ 197<br />
Chuyển điều khiển ................................................ 214 ...<br />
Chuyển đổi .............................................. 253, 259 , 263<br />
Chuyển đổi<br />
Nhân vật để nhân vật multibyte .................... 293<br />
Ký tự nhiều byte Character rộng ........... 285<br />
Chuỗi nhiều byte để rộng chuỗi ký tự ....... 285<br />
String để đôi Floating Point ............... 274, 289<br />
String để Integer .............................................. 275<br />
Chuỗi Long Integer ............................. 275, 291<br />
String để Unsigned LongInteger ..................... 292<br />
Để Hạ Trường hợp chữ cái nhân vật ............. 203<br />
Để Upper Case chữ cái nhân vật ............. 204<br />
Character rộng chuỗi toMultibyte chuỗi ....... 293<br />
ConvertADC10 ................................................. ...... 103<br />
ConvertADC12 ................................................. ........ 96<br />
Chức năng sao chép<br />
memcpy ................................................. ......... 297<br />
memmove ................................................. ...... 298<br />
memset ................................................. .......... 299<br />
strcpy ................................................. ............. 303<br />
strncpy ................................................. ........... 309<br />
cos ................................................. ......................... 333<br />
cosf ................................................. ........................ 334<br />
CosFactorInit ................................................. ........... 61<br />
cosh ................................................. ....................... 335<br />
coshf ................................................. ...................... 336
Set Priority Macro.............................................. 92<br />
CAN, Example of Use .............................................. 93<br />
CANxAbortAll ........................................................... 81<br />
CANxGetRXErrorCount............................................ 81<br />
CANxGetTXErrorCount............................................ 82<br />
CANxInitialize ........................................................... 90<br />
CANxIsBusOff .......................................................... 82<br />
CANxIsRXPassive.................................................... 83<br />
CANxIsRXReady...................................................... 82<br />
CANxIsTXPassive .................................................... 83<br />
CANxIsTXReady ...................................................... 84<br />
CANxRecieveMessage............................................ 84<br />
CANxSendMessage ................................................. 85<br />
CANxSetFilter........................................................... 86<br />
CANxSetMask .......................................................... 86<br />
CANxSetOperationMode.......................................... 87<br />
CANxSetOperationModeNoWait .............................. 88<br />
CANxSetRXMode..................................................... 88<br />
CANxSetTXMode ..................................................... 89<br />
Caret (^).................................................................. 260<br />
Carriage Return...................................................... 201<br />
ceil .......................................................................... 332<br />
ceilf ......................................................................... 333<br />
ceiling<br />
Double Floating Point...................................... 332<br />
Single Floating Point....................................... 333<br />
char<br />
Maximum Value .............................................. 211<br />
Minimum Value ............................................... 211<br />
Number of Bits ................................................ 211<br />
CHAR_BIT.............................................................. 211<br />
CHAR_MAX ........................................................... 211<br />
CHAR_MIN............................................................. 211<br />
Character Array ...................................................... 260<br />
Character Case Mapping<br />
Lower Case Alphabetic Character .................. 203<br />
Upper Case Alphabetic Character .................. 204<br />
Character Case Mapping Functions<br />
tolower............................................................. 203<br />
cosin<br />
Đôi Floating Point ...................................... 333<br />
Độc Floating Point ....................................... 334<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 386 2004 Microchip Technology Inc<br />
crt0, crt1 ............................................... ...................... 8<br />
ctime ................................................. ...................... 319<br />
ctype.h ............................................... ..................... 196<br />
isalnum ................................................. ........... 196<br />
iscntrl ................................................. .............. 197<br />
isdigit ................................................. .............. 198<br />
isgraph ................................................. ........... 198<br />
islapha ................................................. ............ 196<br />
islower ................................................. ............ 199<br />
iSpring ................................................. ............ 200<br />
ispunct ................................................. ............ 200<br />
isspace ................................................. ........... 201<br />
isupper ................................................. ........... 202<br />
isxdigit ................................................. ............ 202<br />
ToLower ................................................. ........... 203<br />
toupper ................................................. ........... 204<br />
Đối số hiện tại ................................................ 221 ...<br />
Dịch vụ thông báo khách hàng .................................... 5<br />
Hỗ trợ khách hàng ................................................ ...... 6<br />
Chức năng tùy chỉnh .............................................. 281<br />
D<br />
Dấu gạch ngang (-) .............................................. .................... 260<br />
DataRdyDCI ................................................. .......... 151<br />
DataRdyI2C ................................................. ........... 184<br />
DataRdySPIx ................................................. ......... 159<br />
DataRdyUARTx ................................................. ..... 143<br />
Thời gian ............................................... ......... 322<br />
Thời gian chức năng, Seetime.h<br />
Ngày tháng ..................................... 317, 318, 322<br />
Ngày trong tuần ...................................... 317, 318, 322<br />
Ngày của năm .............................................. 317, 323<br />
Daylight Savings Time ............................. 317, 320, 321
toupper ............................................................ 204<br />
Character Handling, Seectype.h<br />
Character Input/Output Functions<br />
fgetc ................................................................ 233<br />
fgets ................................................................ 235<br />
fputc ................................................................ 239<br />
fputs ................................................................ 239<br />
getc ................................................................. 250<br />
getchar ............................................................ 251<br />
gets ................................................................. 251<br />
putc ................................................................. 255<br />
putchar ............................................................ 256<br />
puts ................................................................. 256<br />
ungetc ............................................................. 265<br />
Index<br />
2004 Microchip Technology Inc. DS51456B-page 385<br />
Character Testing<br />
Alphabetic Character...................................... 196<br />
Alphanumeric Character ................................. 196<br />
Control Character ........................................... 197<br />
Decimal Digit................................................... 198<br />
Graphical Character........................................ 198<br />
Hexadecimal Digit........................................... 202<br />
Lower Case Alphabetic Character .................. 199<br />
Printable Character ......................................... 200<br />
Punctuation Character .................................... 200<br />
Upper Case Alphabetic Character .................. 202<br />
White-Space Character .................................. 201<br />
Character Testing Functions<br />
isalnum ........................................................... 196<br />
isalpha ............................................................ 196<br />
iscntrl .............................................................. 197<br />
isdigit............................................................... 198<br />
isgraph ............................................................ 198<br />
islower............................................................. 199<br />
isprint .............................................................. 200<br />
ispunct ............................................................ 200<br />
isspace............................................................ 201<br />
isupper ............................................................ 202<br />
DBL_DIG ................................................. ............... 206<br />
DBL_EPSILON ................................................. ...... 206<br />
DBL_MANT_DIG ................................................. 206 ...<br />
DBL_MAX ................................................. ............. 206<br />
DBL_MAX_10_EXP ............................................... 207<br />
DBL_MAX_EXP ................................................. 207 ....<br />
DBL_MIN ................................................. ............... 207<br />
DBL_MIN_10_EXP ................................................ 207<br />
DBL_MIN_EXP ................................................. ..... 208<br />
DCI chức năng<br />
Đóng DCI ................................................ ........ 150<br />
Cấu hình DCI ................................................ . 151<br />
Cấu hình DCI ngắt ................................... 151<br />
DCI RX đệm trạng ...................................... 151<br />
DCI TX đệm trạng ...................................... 150<br />
Ví dụ sử dụng ............................................... 156<br />
Đọc DCI RX đệm ........................................ 154<br />
Viết DCI TX đệm ........................................ 154<br />
DCI Macros<br />
Vô hiệu hoá DCI ngắt ...................................... 155<br />
Kích hoạt tính năng ngắt DCI ....................................... 155<br />
Đặt ưu tiên DCI ngắt ................................. 155<br />
DCT ................................................. ......................... 61<br />
DCTIP ................................................. ..................... 63<br />
Deallocate bộ nhớ ........................................ 281, 287<br />
lỗi gỡ lỗi lôgic ............................................ 195<br />
Số thập phân ........................................... 254, 260, 291, 292<br />
Chữ số thập phân<br />
Xác định ................................................. ........... 198<br />
Số ....................................... 206, 208, 209<br />
Kiểm tra cho ................................................ ............ 198<br />
Điểm số thập phân ................................................ ......... 253<br />
Mặc định Handler ................................................ ...... 215<br />
Chẩn đoán, Seeassert.h<br />
difftime ................................................. ................... 320<br />
Chữ số, số thập phân, chữ số SeeDecimal<br />
Chữ số, thập lục phân, chữ số SeeHexadecimal<br />
Đầu vào trực tiếp / Chức năng đầu ra<br />
fread ................................................. ............... 240
isxdigit............................................................. 202<br />
Characters<br />
Alphabetic ....................................................... 196<br />
Alphanumeric .................................................. 196<br />
Control ............................................................ 197<br />
Convert to Lower Case Alphabetic ................. 203<br />
Convert to Upper Case Alphabetic ................. 204<br />
Decimal Digit................................................... 198<br />
Graphical ........................................................ 198<br />
Hexadecimal Digit........................................... 202<br />
Lower Case Alphabetic ................................... 199<br />
Printable.......................................................... 200<br />
Punctuation..................................................... 200<br />
Upper Case Alphabetic ................................... 202<br />
White-Space ................................................... 201<br />
Classifying Characters........................................... 196<br />
clearerr ................................................................... 229<br />
Clearing Error Indicator .......................................... 229<br />
clock ....................................................................... 318<br />
clock_t.............................................................317, 318<br />
CLOCKS_PER_SEC ............................................. 317<br />
close....................................................................... 368<br />
CloseADC10 .......................................................... 102<br />
CloseADC12 ............................................................ 95<br />
CloseCapturex ....................................................... 125<br />
CloseDCI................................................................ 150<br />
CloseI2C ................................................................ 183<br />
CloseINTx .............................................................. 120<br />
CloseMCPWM........................................................ 171<br />
CloseOCx............................................................... 131<br />
CloseQEI................................................................ 166<br />
CloseSPIx .............................................................. 158<br />
CloseTimerx ........................................................... 109<br />
CloseTimerxx ......................................................... 109<br />
CloseUARTx .......................................................... 141<br />
Common Definitions, Seestddef.h<br />
Compare Strings .................................................... 302<br />
Comparison Function......................................276, 286<br />
Comparison Functions<br />
fwrite ................................................. ............... 248<br />
DisableCNx ................................................. ........... 123<br />
DisableIntADC ................................................ 100 107<br />
DisableIntCANx ................................................. ....... 92<br />
DisableIntDCI ................................................. ........ 155<br />
DisableInterrupts ................................................. 119 ...<br />
DisableIntFLTA ................................................. ...... 180<br />
DisableIntFLTB ................................................. ...... 181<br />
DisableIntlC1 ................................................. ......... 129<br />
DisableIntlUxRX ................................................. 147 ....<br />
DisableIntMCPWM ................................................. 180<br />
DisableIntMI2C ................................................. ...... 190<br />
DisableIntOCx ................................................. ....... 139<br />
DisableIntQEI ................................................. ........ 169<br />
DisableIntSI2C ................................................. ...... 191<br />
DisableIntSPIx ................................................. ....... 163<br />
DisableIntTx ................................................. .......... 115<br />
DisableIntUxTX ................................................. ..... 148<br />
DisableINTx ................................................. ........... 124<br />
div ................................................. .................. 270, 278<br />
div_t ................................................. ....................... 270<br />
Chia<br />
Integer ................................................. ............ 278<br />
Long Integer ................................................ 283 ....<br />
Chia Zero ........................................ 216, 219, 278<br />
Tài liệu<br />
Giao diện ................................................. ................ 2<br />
Tài liệu<br />
Ước ................................................. ....... 3<br />
Lỗi miền .......................... 205, 325, 326, 327, 329,<br />
............................ 331, 333, 334, 341, 343, 349, 350,<br />
............................. 351, 352, 357, 358, 361, 362, 363<br />
dot ................................................. ......................... 253<br />
Đôi chính xác dấu chấm động<br />
Máy Epsilon .............................................. 206<br />
Exponent tối đa (10 cơ sở) ........................ 207<br />
Exponent tối đa (cơ sở 2) .......................... 207<br />
Giá trị tối đa .............................................. 206<br />
Tối thiểu Exponent (10 cơ sở) ......................... 207
memcmp ......................................................... 295<br />
strcmp ............................................................. 302<br />
strcoll............................................................... 303<br />
strncmp ........................................................... 308<br />
strxfrm ............................................................. 316<br />
Compiler Options<br />
-fno-short-double............................................. 225<br />
-msmart-io....................................................... 225<br />
Concatenation Functions<br />
strcat ............................................................... 300<br />
strncat ............................................................. 306<br />
ConfigCNPullups.................................................... 122<br />
ConfigIntADC10 ..................................................... 102<br />
ConfigIntADC12 ....................................................... 95<br />
ConfigIntCANx ......................................................... 91<br />
ConfigIntCapturex .................................................. 126<br />
ConfigIntCN............................................................ 122<br />
ConfigIntDCI........................................................... 151<br />
ConfigIntI2C ........................................................... 183<br />
ConfigIntlOCx......................................................... 132<br />
ConfigIntMCPWM .................................................. 171<br />
ConfigIntQEI........................................................... 166<br />
ConfigIntSpIx.......................................................... 158<br />
ConfigIntTimerx...................................................... 110<br />
ConfigIntTimerxx .................................................... 111<br />
ConfigIntUARTx ..................................................... 142<br />
ConfigINTx ............................................................. 121<br />
Control Character<br />
Defined............................................................ 197<br />
Test for ............................................................ 197<br />
Control Transfers ................................................... 214<br />
Conversion ..............................................253, 259, 263<br />
Convert<br />
Character to Multibyte Character .................... 293<br />
Multibyte Character to Wide Character ........... 285<br />
Multibyte String to Wide Character String....... 285<br />
String to Double Floating Point ............... 274, 289<br />
String to Integer .............................................. 275<br />
String to Long Integer ............................. 275, 291<br />
Tối thiểu Exponent (cơ sở 2) ........................... 208<br />
Giá trị tối thiểu ............................................... 207<br />
Số chữ số nhị phân .................................. 206<br />
Số thập phân chữ số ............................... 206<br />
đôi Loại ................................................ ............ 225<br />
Chức năng mơ ................................................ ...... 253<br />
Thư viện DSP ................................................ ............. 9<br />
dsPIC Thư viện ngoại vi ....................................... 73<br />
Chỉ số<br />
2004 Microchip Technology Inc DS51456B trang 387<br />
E<br />
EDOM ................................................. ................... 205<br />
đôm ................................................. ..................... 325<br />
Bầu dục (...) ............................................ ......... 221, 260<br />
File nhị phân rỗng ............................................... 236 ....<br />
Rỗng Text File ............................................... ....... 236<br />
EnableCNx ................................................. ............ 123<br />
EnableIntADC ................................................. 100, 107<br />
EnableIntCANx ................................................. ....... 92<br />
EnableIntDCI ................................................. ......... 155<br />
EnableIntFLTA ................................................. ...... 180<br />
EnableIntFLTB ................................................. ...... 181<br />
EnableIntlCx ................................................. .......... 129<br />
EnableIntlUxTX ................................................. ..... 147<br />
EnableIntMCPWM ................................................. 180<br />
EnableIntMI2C ................................................. ...... 190<br />
EnableIntOCx ................................................. ........ 139<br />
EnableIntQEI ................................................. ......... 169<br />
EnableIntSI2C ................................................. ....... 191<br />
EnableIntSPIx ................................................. ....... 163<br />
EnableIntTx ................................................. ........... 115<br />
EnableIntUxRX ................................................. ..... 147<br />
EnableINTx ................................................. ........... 123<br />
End Of tập tin ............................................... .............. 227<br />
Chỉ số ................................................. ......... 225<br />
Tìm kiếm ................................................. ............... 244<br />
Kiểm tra Đối với ................................................ .......... 231<br />
Chức năng môi trường<br />
getenv ................................................. ............ 281
String to Unsigned LongInteger ..................... 292<br />
To Lower Case Alphabetic Character ............. 203<br />
To Upper Case Alphabetic Character ............. 204<br />
Wide Character String toMultibyte String....... 293<br />
ConvertADC10 ....................................................... 103<br />
ConvertADC12 ......................................................... 96<br />
Copying Functions<br />
memcpy .......................................................... 297<br />
memmove ....................................................... 298<br />
memset ........................................................... 299<br />
strcpy .............................................................. 303<br />
strncpy ............................................................ 309<br />
cos.......................................................................... 333<br />
cosf......................................................................... 334<br />
CosFactorInit............................................................ 61<br />
cosh........................................................................ 335<br />
coshf....................................................................... 336<br />
cosine<br />
Double Floating Point...................................... 333<br />
Single Floating Point ....................................... 334<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 386 2004 Microchip Technology Inc.<br />
crt0, crt1 ..................................................................... 8<br />
ctime....................................................................... 319<br />
ctype.h.................................................................... 196<br />
isalnum............................................................ 196<br />
iscntrl............................................................... 197<br />
isdigit............................................................... 198<br />
isgraph ............................................................ 198<br />
islapha............................................................. 196<br />
islower ............................................................. 199<br />
ispring ............................................................. 200<br />
ispunct............................................................. 200<br />
isspace............................................................ 201<br />
isupper ............................................................ 202<br />
isxdigit ............................................................. 202<br />
tolower ............................................................ 203<br />
Biến môi trường ............................................. 369<br />
EOF ................................................. ....................... 227<br />
ERANGE ................................................. ............... 205<br />
erange ................................................. ................... 325<br />
errno ................................................. ............... 205, 325<br />
errno.h ............................................... ...... 205, 325, 370<br />
EDOM ................................................. ............ 205<br />
ERANGE ................................................. ........ 205<br />
errno ................................................. .............. 205<br />
Mã lỗi ................................................ ..... 205, 305<br />
Điều kiện lỗi ................................................ ..... 325<br />
Lỗi Handler ................................................ ......... 278<br />
Chức năng Xử lý lỗi<br />
clearerr ................................................. ........... 229<br />
feof ................................................. ................. 231<br />
ferror ................................................. .............. 232<br />
perror ................................................. ............. 252<br />
Lỗi Chỉ ................................................ ........ 225<br />
Các chỉ số lỗi<br />
Thanh toán bù trừ ................................................. ..229, 258<br />
End Of tập tin ............................................... 229, 235<br />
Lỗi ................................................. ........ 229, 235<br />
Kiểm tra Đối với ................................................ .......... 232<br />
Các thông báo lỗi, xây dựng trong chức năng ........................ 379<br />
Lỗi tín hiệu ................................................ ............ 215<br />
Lỗi, Seeerrno.h<br />
Lỗi, kiểm tra Đối với .............................................. 205 ...<br />
Ví dụ sử dụng<br />
ADC, 10-Bit ............................................. ........ 108<br />
ADC, 12-Bit ............................................. ........ 101<br />
CAN ................................................. ................. 93<br />
DCI ................................................. ................. 156<br />
I2C ................................................. ................. 192<br />
Input Capture ................................................ 130 ..<br />
So sánh sản lượng ............................................. 140<br />
PWM ................................................. .............. 182<br />
Chức năng QEI ................................................ . 170<br />
SPI ................................................. ................. 164<br />
Thời Gian ................................................. ............ 116
toupper ............................................................ 204<br />
Current Argument................................................... 221<br />
Customer Notification Service .................................... 5<br />
Customer Support ...................................................... 6<br />
Customized Function.............................................. 281<br />
D<br />
Dash (-) .................................................................. 260<br />
DataRdyDCI ........................................................... 151<br />
DataRdyI2C............................................................ 184<br />
DataRdySPIx.......................................................... 159<br />
DataRdyUARTx...................................................... 143<br />
Date and Time........................................................ 322<br />
Date and Time Functions, Seetime.h<br />
Day of the Month.....................................317, 318, 322<br />
Day of the Week......................................317, 318, 322<br />
Day of the Year .............................................. 317, 323<br />
Daylight Savings Time.............................317, 320, 321<br />
DBL_DIG................................................................ 206<br />
DBL_EPSILON....................................................... 206<br />
DBL_MANT_DIG.................................................... 206<br />
DBL_MAX .............................................................. 206<br />
DBL_MAX_10_EXP ............................................... 207<br />
DBL_MAX_EXP ..................................................... 207<br />
DBL_MIN................................................................ 207<br />
DBL_MIN_10_EXP ................................................ 207<br />
DBL_MIN_EXP ...................................................... 208<br />
DCI Functions<br />
Close DCI........................................................ 150<br />
Configure DCI ................................................. 151<br />
Configure DCI Interrupt................................... 151<br />
DCI RX Buffer Status ...................................... 151<br />
DCI TX Buffer Status...................................... 150<br />
Example of Use............................................... 156<br />
Read DCI RX Buffer........................................ 154<br />
Write DCI TX Buffer........................................ 154<br />
DCI Macros<br />
Disable DCI Interrupt...................................... 155<br />
Enable DCI Interrupt....................................... 155<br />
Set DCI Interrupt Priority ................................. 155<br />
UART ................................................. ............. 149<br />
Ngoại lệ Lỗi ................................................ ...... 278<br />
thoát ........................................... 264, 270, 272, 280, 367<br />
EXIT_FAILURE ................................................. ..... 270<br />
EXIT_SUCCESS ................................................. 270 ...<br />
exp ................................................. ........................ 337<br />
expf ................................................. ....................... 338<br />
Chức năng theo cấp số nhân và Logarithmic<br />
exp ................................................. ................. 337<br />
expf ................................................. ................ 338<br />
frexp ................................................. ............... 344<br />
frexpf ................................................. .............. 345<br />
ldexp ................................................. .............. 346<br />
ldexpf ................................................. ............. 347<br />
đăng nhập ................................................. .................. 349<br />
log10 ................................................. .............. 350<br />
log10f ................................................. ............. 351<br />
logf ................................................. ................. 352<br />
modf ................................................. ............... 353<br />
modff ................................................. .............. 354<br />
hàm mũ<br />
Đôi Floating Point ...................................... 337<br />
Độc Floating Point ....................................... 338<br />
F<br />
fabs ................................................. ....................... 339<br />
fabsf ................................................. ...................... 339<br />
fclose ................................................. ............. 230, 368<br />
feof ................................................. ................ 229, 231<br />
ferror ................................................. .............. 229, 232<br />
fflush ................................................. .............. 233, 373<br />
FFTComplex ................................................. ........... 64<br />
FFTComplexIP ................................................. ........ 66<br />
fgetc ................................................. .............. 233, 371<br />
fgetpos ................................................. .......... 234, 369<br />
fgets ................................................. .............. 235, 371<br />
Chiều rộng ................................................ ............. 253<br />
FILE ................................................. ............... 225, 226<br />
Chức năng truy cập file<br />
fclose ................................................. .............. 230
DCT.......................................................................... 61<br />
DCTIP ...................................................................... 63<br />
Deallocate Memory........................................ 281, 287<br />
debugging logic errors............................................ 195<br />
Decimal ...........................................254, 260, 291, 292<br />
Decimal Digit<br />
Defined............................................................ 198<br />
Number Of....................................... 206, 208, 209<br />
Test for ............................................................ 198<br />
Decimal Point ......................................................... 253<br />
Default Handler ...................................................... 215<br />
Diagnostics, Seeassert.h<br />
difftime.................................................................... 320<br />
Digit, Decimal, SeeDecimal Digit<br />
Digit, Hexadecimal, SeeHexadecimal Digit<br />
Direct Input/Output Functions<br />
fread ................................................................ 240<br />
fwrite................................................................ 248<br />
DisableCNx ............................................................ 123<br />
DisableIntADC................................................ 100, 107<br />
DisableIntCANx ........................................................ 92<br />
DisableIntDCI ......................................................... 155<br />
DisableInterrupts .................................................... 119<br />
DisableIntFLTA....................................................... 180<br />
DisableIntFLTB....................................................... 181<br />
DisableIntlC1 .......................................................... 129<br />
DisableIntlUxRX ..................................................... 147<br />
DisableIntMCPWM ................................................. 180<br />
DisableIntMI2C....................................................... 190<br />
DisableIntOCx ........................................................ 139<br />
DisableIntQEI ......................................................... 169<br />
DisableIntSI2C ....................................................... 191<br />
DisableIntSPIx........................................................ 163<br />
DisableIntTx ........................................................... 115<br />
DisableIntUxTX ...................................................... 148<br />
DisableINTx............................................................ 124<br />
div................................................................... 270, 278<br />
div_t........................................................................ 270<br />
Divide<br />
fflush ................................................. .............. 233<br />
fopen ................................................. .............. 236<br />
freopen ................................................. ........... 242<br />
setbuf ................................................. ............. 261<br />
setvbuf ................................................. ........... 262<br />
Tập tin truy cập chế độ ......................................... 225, 236<br />
Tập tin bộ nhớ đệm<br />
Đệm đầy đủ .......................................... 225, 226<br />
Dòng Buffered ........................................... 225, 226<br />
Unbuffered .............................................. 225, 226<br />
Hoạt động tập tin<br />
Hủy bỏ ................................................. .......... 257<br />
Đổi tên ................................................. ......... 257<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 388 2004 Microchip Technology Inc<br />
Chức năng định vị tập tin<br />
fgetpos ................................................. ........... 234<br />
fseek ................................................. .............. 244<br />
fsetpos ................................................. ........... 245<br />
ftell ................................................. ................. 247<br />
tua lại ................................................. ............ 258<br />
FILENAME_MAX ................................................. 227 ...<br />
File-Chức vụ Chỉ số ..................... 225, 226, 233, 234,<br />
.................................................. ... 239, 240, 245, 248<br />
Bức ảnh, tối đa NumberOpen ............................... 227<br />
Chức năng lọc ................................................ 38 ....<br />
FIR ................................................. ................... 41<br />
FIRDecimate ................................................. 42 ....<br />
FIRDelayInit ................................................. ..... 43<br />
FIRInterpDelayInit ............................................. 45<br />
FIRInterpolate ................................................. 44 ..<br />
FIRLattice ................................................. ......... 45<br />
FIRLMS ................................................. ............ 46<br />
FIRLMSNorm ................................................. 47 ...<br />
FIRStruct ................................................. .......... 40<br />
FIRStructInit ................................................. ..... 49<br />
IIRCanonic ................................................. ....... 50
Integer ............................................................. 278<br />
Long Integer .................................................... 283<br />
Divide by Zero ........................................ 216, 219, 278<br />
Document<br />
Layout ................................................................. 2<br />
Documentation<br />
Conventions ........................................................ 3<br />
Domain Error .......................... 205, 325, 326, 327, 329,<br />
............................ 331, 333, 334, 341, 343, 349, 350,<br />
............................. 351, 352, 357, 358, 361, 362, 363<br />
dot .......................................................................... 253<br />
Double Precision Floating Point<br />
Machine Epsilon.............................................. 206<br />
Maximum Exponent (base 10) ........................ 207<br />
Maximum Exponent (base 2) .......................... 207<br />
Maximum Value .............................................. 206<br />
Minimum Exponent (base 10) ......................... 207<br />
Minimum Exponent (base 2) ........................... 208<br />
Minimum Value ............................................... 207<br />
Number of Binary Digits .................................. 206<br />
Number of Decimal Digits ............................... 206<br />
double Type............................................................ 225<br />
Dream Function...................................................... 253<br />
DSP Libraries ............................................................. 9<br />
dsPIC Peripheral Libraries ....................................... 73<br />
Index<br />
2004 Microchip Technology Inc. DS51456B-page 387<br />
E<br />
EDOM .................................................................... 205<br />
edom ...................................................................... 325<br />
Ellipses (...) .....................................................221, 260<br />
Empty Binary File ................................................... 236<br />
Empty Text File ...................................................... 236<br />
EnableCNx ............................................................. 123<br />
EnableIntADC .................................................100, 107<br />
EnableIntCANx ........................................................ 92<br />
EnableIntDCI.......................................................... 155<br />
EnableIntFLTA ....................................................... 180<br />
EnableIntFLTB ....................................................... 181<br />
IIRCanonicInit ................................................. 51 ..<br />
IIRLattice ................................................. .......... 52<br />
Mô hình OCTAVE IIRLattice ................................ 56<br />
IIRLatticeInit ................................................. ..... 53<br />
IIRTransposed ................................................. . 54<br />
IIRTransposedInit .............................................. 55<br />
FIR ................................................. .......................... 41<br />
FIRDecimate ................................................. ........... 42<br />
FIRDelayInit ................................................. ............ 43<br />
FIRInterpDelayInit ................................................. 45 ...<br />
FIRInterpolate ................................................. ......... 44<br />
FIRLattice ................................................. ................ 45<br />
FIRLMS ................................................. ................... 46<br />
FIRLMSNorm ................................................. .......... 47<br />
FIRStruct ................................................. ................. 40<br />
FIRStructInit ................................................. ............ 49<br />
cờ ................................................. ....................... 253<br />
float.h ............................................... ...................... 206<br />
DBL_DIG ................................................. ........ 206<br />
DBL_EPSILON ............................................... 206<br />
DBL_MANT_DIG ............................................ 206<br />
DBL_MAX ................................................. ...... 206<br />
DBL_MAX_10_EXP ........................................ 207<br />
DBL_MAX_EXP .............................................. 207<br />
DBL_MIN ................................................. ....... 207<br />
DBL_MIN_10_EXP ......................................... 207<br />
DBL_MIN_EXP ............................................... 208<br />
FLT_DIG ................................................. ........ 208<br />
FLT_EPSILON ................................................ 208<br />
FLT_MANT_DIG ............................................. 208<br />
FLT_MAX ................................................. ....... 208<br />
FLT_MAX_10_EXP ......................................... 208<br />
FLT_MAX_EXP ............................................... 209<br />
FLT_MIN ................................................. ........ 209<br />
FLT_MIN_10_EXP .......................................... 209<br />
FLT_MIN_EXP ................................................ 209<br />
FLT_RADIX ................................................. 209 ....<br />
FLT_ROUNDS ................................................ 209<br />
LDBL_DIG ................................................. ...... 209
EnableIntlCx........................................................... 129<br />
EnableIntlUxTX ...................................................... 147<br />
EnableIntMCPWM ................................................. 180<br />
EnableIntMI2C ....................................................... 190<br />
EnableIntOCx......................................................... 139<br />
EnableIntQEI.......................................................... 169<br />
EnableIntSI2C........................................................ 191<br />
EnableIntSPIx ........................................................ 163<br />
EnableIntTx ............................................................ 115<br />
EnableIntUxRX ...................................................... 147<br />
EnableINTx ............................................................ 123<br />
End Of File ............................................................. 227<br />
Indicator .......................................................... 225<br />
Seek................................................................ 244<br />
Test For .......................................................... 231<br />
Environment Function<br />
getenv ............................................................. 281<br />
Environment Variable............................................. 369<br />
EOF........................................................................ 227<br />
ERANGE................................................................ 205<br />
erange.................................................................... 325<br />
errno................................................................205, 325<br />
errno.h.....................................................205, 325, 370<br />
EDOM ............................................................. 205<br />
ERANGE......................................................... 205<br />
errno ............................................................... 205<br />
Error Codes.....................................................205, 305<br />
Error Conditions ..................................................... 325<br />
Error Handler ......................................................... 278<br />
Error Handling Functions<br />
clearerr............................................................ 229<br />
feof.................................................................. 231<br />
ferror ............................................................... 232<br />
perror .............................................................. 252<br />
Error Indicator ........................................................ 225<br />
Error Indicators<br />
Clearing ...................................................229, 258<br />
End Of File...............................................229, 235<br />
Error .........................................................229, 235<br />
LDBL_EPSILON .............................................. 210<br />
LDBL_MANT_DIG ........................................... 210<br />
LDBL_MAX ................................................. 210 ....<br />
LDBL_MAX_10_EXP ...................................... 210<br />
LDBL_MAX_EXP ............................................ 210<br />
LDBL_MIN ................................................. ...... 210<br />
LDBL_MIN_10_EXP ....................................... 210<br />
LDBL_MIN_EXP ............................................. 211<br />
Floating Point<br />
Giới hạn ................................................. .............. 206<br />
Không chuyển đổi ................................................ 225<br />
Các loại, thuộc tính của ....................................... 206<br />
Floating Point, Seefloat.h<br />
Floating-Point Lỗi tín hiệu ..................................... 216<br />
sàn ................................................. ....................... 340<br />
Đôi Floating Point ...................................... 340<br />
Độc Floating Point ....................................... 340<br />
floorf ................................................. ...................... 340<br />
FLT_DIG ................................................. ................ 208<br />
FLT_EPSILON ................................................. ...... 208<br />
FLT_MANT_DIG ................................................. 208 ...<br />
FLT_MAX ................................................. .............. 208<br />
FLT_MAX_10_EXP ................................................ 208<br />
FLT_MAX_EXP ................................................. ..... 209<br />
FLT_MIN ................................................. ............... 209<br />
FLT_MIN_10_EXP ................................................. 209<br />
FLT_MIN_EXP ................................................. ...... 209<br />
FLT_RADIX ................................................. ........... 209<br />
FLT_RADIX chữ số<br />
Số ....................................... 206, 208, 210<br />
FLT_ROUNDS ................................................. ...... 209<br />
................................................. Xả .............. 233, 280<br />
fmod ................................................. ...................... 341<br />
fmodf ................................................. ..................... 343<br />
-fno-ngắn đôi ............................. 206, 207, 208, 225<br />
fopen ............................................... 225, 236, 262, 370<br />
FOPEN_MAX ................................................. ........ 227<br />
Mẫu thức ăn ................................................ .............. 201<br />
Định dạng Specifiers ........................................... 253, 259
Test For .......................................................... 232<br />
Error Messages, Built-In Functions ........................ 379<br />
Error Signal ............................................................ 215<br />
Errors, Seeerrno.h<br />
Errors, Testing For ................................................. 205<br />
Example of Use<br />
ADC, 10-Bit..................................................... 108<br />
ADC, 12-Bit..................................................... 101<br />
CAN .................................................................. 93<br />
DCI.................................................................. 156<br />
I2C .................................................................. 192<br />
Input Capture .................................................. 130<br />
Output Compare ............................................. 140<br />
PWM ............................................................... 182<br />
QEI Functions ................................................. 170<br />
SPI .................................................................. 164<br />
Timers ............................................................. 116<br />
UART .............................................................. 149<br />
Exception Error ...................................................... 278<br />
exit........................................... 264, 270, 272, 280, 367<br />
EXIT_FAILURE ...................................................... 270<br />
EXIT_SUCCESS.................................................... 270<br />
exp ......................................................................... 337<br />
expf ........................................................................ 338<br />
Exponential and Logarithmic Functions<br />
exp .................................................................. 337<br />
expf ................................................................. 338<br />
frexp ................................................................ 344<br />
frexpf ............................................................... 345<br />
ldexp ............................................................... 346<br />
ldexpf .............................................................. 347<br />
log ................................................................... 349<br />
log10 ............................................................... 350<br />
log10f .............................................................. 351<br />
logf .................................................................. 352<br />
modf ................................................................ 353<br />
modff ............................................................... 354<br />
exponential function<br />
Double Floating Point...................................... 337<br />
Định dạng I / O thói quen .......................................... 225<br />
Định dạng đầu vào / đầu ra Chức năng<br />
fprintf ................................................. .............. 238<br />
fscanf ................................................. .............. 242<br />
printf ................................................. ............... 253<br />
scanf ................................................. ............... 259<br />
sprintf ................................................. ............. 263<br />
sscanf ................................................. ............. 263<br />
vfprintf ................................................. ............ 267<br />
vprintf ................................................. ............. 268<br />
vsprintf ................................................. ............ 269<br />
Tiêu đề định dạng<br />
In ấn ................................................. ........... 263<br />
Quét ................................................. ........ 263<br />
fpos_t ................................................. ..................... 226<br />
fprintf ................................................. ............. 225, 238<br />
fputc ................................................. ....................... 239<br />
fputs ................................................. ....................... 239<br />
Chỉ số<br />
2004 Microchip Technology Inc DS51456B trang 389<br />
phần và số mũ chức năng<br />
Đôi Floating Point ..................................... 344<br />
Độc Floating Point ....................................... 345<br />
Chữ số phần ................................................ ........ 253<br />
fread ................................................. ............... 240, 371<br />
................................................. miễn phí ........................ 281<br />
Miễn phí bộ nhớ ................................................ .......... 281<br />
freopen ................................................. ... 225, 242, 370<br />
frexp ................................................. ...................... 344<br />
frexpf ................................................. ..................... 345<br />
fscanf ................................................. ............. 225, 242<br />
fseek ................................................. ...... 244, 265, 369<br />
fsetpos ................................................. ... 245, 265, 369<br />
ftell ................................................. ................. 247, 369<br />
Full Buffering ................................................ ... 261, 262<br />
Đệm đầy đủ ................................................ ..225, 226<br />
fwrite ................................................. ..................... 248<br />
G<br />
getc ................................................. ....................... 250
Single Floating Point ....................................... 338<br />
F<br />
fabs ........................................................................ 339<br />
fabsf ....................................................................... 339<br />
fclose.............................................................. 230, 368<br />
feof ................................................................. 229, 231<br />
ferror............................................................... 229, 232<br />
fflush............................................................... 233, 373<br />
FFTComplex ............................................................ 64<br />
FFTComplexIP ......................................................... 66<br />
fgetc ............................................................... 233, 371<br />
fgetpos ........................................................... 234, 369<br />
fgets ............................................................... 235, 371<br />
Field Width ............................................................. 253<br />
FILE................................................................ 225, 226<br />
File Access Functions<br />
fclose............................................................... 230<br />
fflush ............................................................... 233<br />
fopen ............................................................... 236<br />
freopen............................................................ 242<br />
setbuf .............................................................. 261<br />
setvbuf ............................................................ 262<br />
File Access Modes......................................... 225, 236<br />
File Buffering<br />
Fully Buffered.......................................... 225, 226<br />
Line Buffered........................................... 225, 226<br />
Unbuffered .............................................. 225, 226<br />
File Operations<br />
Remove........................................................... 257<br />
Rename .......................................................... 257<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 388 2004 Microchip Technology Inc.<br />
File Positioning Functions<br />
fgetpos ............................................................ 234<br />
fseek ............................................................... 244<br />
fsetpos ............................................................ 245<br />
ftell .................................................................. 247<br />
getchar ................................................. .................. 251<br />
getcSPIx ................................................. ................ 163<br />
getcUARTx ................................................. ............ 147<br />
getenv ................................................. ............ 281, 369<br />
được ................................................. ................ 251, 371<br />
getsSPIx ................................................. ................ 162<br />
getsUARTx ................................................. ............ 146<br />
GMT ................................................. ...................... 320<br />
gmtime ................................................. ........... 320, 321<br />
Nhân vật đồ họa<br />
Xác định ................................................. .......... 198<br />
Kiểm tra cho ................................................ ............ 198<br />
Greenwich Mean Time ........................................... 320<br />
H<br />
h sửa đổi lần ................................................ ........ 254, 259<br />
HammingInit ................................................. ............ 28<br />
Xử lý<br />
Mặc định ................................................. ........... 215<br />
Lỗi ................................................. ............... 278<br />
Ngắt ................................................. ......... 219<br />
Lồng ................................................. ........... 214<br />
Tín hiệu ................................................. ...... 215, 220<br />
Loại tín hiệu ................................................ ..... 215<br />
Xử lý<br />
Tín hiệu ngắt ............................................... 220<br />
HanningInit ................................................. .............. 28<br />
Tiêu đề tập tin<br />
assert.h ............................................... ............ 195<br />
ctype.h ............................................... ............. 196<br />
errno.h ............................................. 205, 325, 370<br />
float.h ............................................... ............... 206<br />
limits.h ............................................... .............. 211<br />
locale.h ............................................... ............ 213<br />
math.h ............................................... .............. 325<br />
setjmp.h ............................................... ........... 214<br />
signal.h ............................................... ............ 215<br />
stdarg.h ............................................... ............ 221<br />
stddef.h ............................................... ............ 223<br />
stdio.h ............................................... ....... 225, 371
ewind ............................................................. 258<br />
FILENAME_MAX.................................................... 227<br />
File-Position Indicator.....................225, 226, 233, 234,<br />
.....................................................239, 240, 245, 248<br />
Files, Maximum NumberOpen............................... 227<br />
Filtering Functions .................................................... 38<br />
FIR .................................................................... 41<br />
FIRDecimate ..................................................... 42<br />
FIRDelayInit ...................................................... 43<br />
FIRInterpDelayInit............................................. 45<br />
FIRInterpolate ................................................... 44<br />
FIRLattice.......................................................... 45<br />
FIRLMS............................................................. 46<br />
FIRLMSNorm .................................................... 47<br />
FIRStruct........................................................... 40<br />
FIRStructInit ...................................................... 49<br />
IIRCanonic ........................................................ 50<br />
IIRCanonicInit ................................................... 51<br />
IIRLattice........................................................... 52<br />
IIRLattice OCTAVE model ................................ 56<br />
IIRLatticeInit ...................................................... 53<br />
IIRTransposed .................................................. 54<br />
IIRTransposedInit.............................................. 55<br />
FIR ........................................................................... 41<br />
FIRDecimate ............................................................ 42<br />
FIRDelayInit ............................................................. 43<br />
FIRInterpDelayInit .................................................... 45<br />
FIRInterpolate .......................................................... 44<br />
FIRLattice................................................................. 45<br />
FIRLMS .................................................................... 46<br />
FIRLMSNorm ........................................................... 47<br />
FIRStruct .................................................................. 40<br />
FIRStructInit ............................................................. 49<br />
flags........................................................................ 253<br />
float.h ..................................................................... 206<br />
DBL_DIG......................................................... 206<br />
DBL_EPSILON ............................................... 206<br />
DBL_MANT_DIG ............................................ 206<br />
DBL_MAX ....................................................... 206<br />
stdlib.h ............................................. 270, 369, 372<br />
string.h ............................................... ............. 294<br />
time.h ............................................... ....... 317, 373<br />
Heap ................................................. ...................... 368<br />
Chức năng trợ giúp ................................................ 366 ....<br />
Hexadecimal ................................... 254, 260, 291, 292<br />
Chuyển đổi hệ thập lục phân ....................................... 253<br />
Chữ số thập lục phân<br />
Xác định ................................................. ........... 202<br />
Kiểm tra cho ................................................ ............ 202<br />
Tab ngang ................................................ ........ 201<br />
Giờ ................................................. ....... 317, 318, 322<br />
HUGE_VAL ................................................. ........... 325<br />
cosin hyperbol<br />
Đôi Floating Point ...................................... 335<br />
Độc Floating Point ....................................... 336<br />
Chức năng hyperbol<br />
cosh ................................................. ............... 335<br />
coshf ................................................. .............. 336<br />
sinh ................................................. ................ 359<br />
sinhf ................................................. ............... 360<br />
tanh ................................................. ................ 364<br />
tanhf ................................................. ............... 365<br />
sin hyperbol<br />
Đôi Floating Point ...................................... 359<br />
Độc Floating Point ....................................... 360<br />
tang hyperbol<br />
Đôi Floating Point ...................................... 364<br />
Độc Floating Point ....................................... 365<br />
Tôi<br />
I / O Port Chức năng<br />
Cấu hình CN Ngắt .................................. 122<br />
Cấu hình CN Pull-Ups .................................... 122<br />
Cấu hình INT ................................................ 121 ..<br />
Vô hiệu hoá INT ................................................ ..... 120<br />
I / O Port Macros<br />
Vô hiệu hoá CN Ngắt ...................................... 123<br />
Vô hiệu hóa ngắt ............................................ 124<br />
Kích hoạt tính năng ngắt CN ...................................... 123
DBL_MAX_10_EXP ........................................ 207<br />
DBL_MAX_EXP .............................................. 207<br />
DBL_MIN ........................................................ 207<br />
DBL_MIN_10_EXP ......................................... 207<br />
DBL_MIN_EXP ............................................... 208<br />
FLT_DIG ......................................................... 208<br />
FLT_EPSILON ................................................ 208<br />
FLT_MANT_DIG ............................................. 208<br />
FLT_MAX........................................................ 208<br />
FLT_MAX_10_EXP......................................... 208<br />
FLT_MAX_EXP............................................... 209<br />
FLT_MIN ......................................................... 209<br />
FLT_MIN_10_EXP.......................................... 209<br />
FLT_MIN_EXP................................................ 209<br />
FLT_RADIX..................................................... 209<br />
FLT_ROUNDS ................................................ 209<br />
LDBL_DIG....................................................... 209<br />
LDBL_EPSILON.............................................. 210<br />
LDBL_MANT_DIG........................................... 210<br />
LDBL_MAX ..................................................... 210<br />
LDBL_MAX_10_EXP ...................................... 210<br />
LDBL_MAX_EXP ............................................ 210<br />
LDBL_MIN....................................................... 210<br />
LDBL_MIN_10_EXP ....................................... 210<br />
LDBL_MIN_EXP ............................................. 211<br />
Floating Point<br />
Limits............................................................... 206<br />
No Conversion ................................................ 225<br />
Types, Properties Of....................................... 206<br />
Floating Point, Seefloat.h<br />
Floating-Point Error Signal ..................................... 216<br />
floor ........................................................................ 340<br />
Double Floating Point...................................... 340<br />
Single Floating Point....................................... 340<br />
floorf ....................................................................... 340<br />
FLT_DIG................................................................. 208<br />
FLT_EPSILON ....................................................... 208<br />
FLT_MANT_DIG .................................................... 208<br />
FLT_MAX ............................................................... 208<br />
Kích hoạt tính năng ngắt ............................................. 123<br />
Thiết lập ngắt ưu tiên ...................................... 124<br />
Chức năng I2C<br />
Thừa nhận I2C ............................................ 184<br />
Đóng I2C. .................................................. ..... 183<br />
Cấu hình I2C ................................................ 187 ..<br />
Cấu hình I2C ngắt ................................... 183<br />
Dữ liệu sẵn sàng I2C .............................................. 184<br />
Ví dụ sử dụng ............................................... 192<br />
I2C nhàn rỗi ................................................ ............ 184<br />
Thạc sĩ I2C Nhận Chuỗi ..................................... 185<br />
Thạc sĩ I2C Đặt chuỗi ...................................... 185<br />
Thừa nhận không I2C ..................................... 186<br />
Thầy đọc I2C ............................................. 186<br />
Đọc Slave I2C ............................................... 189<br />
I2C Khởi động lại ................................................ ...... 188<br />
I2C Slave Nhận Chuỗi ....................................... 188<br />
I2C Slave Đặt chuỗi ........................................ 189<br />
Bắt đầu I2C ................................................ .......... 190<br />
Dừng I2C ................................................ .......... 190<br />
Viết Thạc sĩ I2C. ............................................ 186<br />
Viết Slave I2C ............................................... 189<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 390 2004 Microchip Technology Inc<br />
Macros I2C<br />
Vô hiệu hoá Thạc sĩ I2C ngắt ........................... 190<br />
Vô hiệu hoá Slave I2C ngắt ............................. 191<br />
Kích hoạt tính năng tổng thể I2C ngắt ............................ 190<br />
Kích hoạt Slave I2C ngắt .............................. 191<br />
Đặt Thạc sĩ I2C ngắt ưu tiên ...................... 191<br />
Đặt Slave I2C ngắt ưu tiên ........................ 191<br />
IdleI2C ................................................. ................... 184<br />
IFFTComplex ................................................. ........... 67<br />
IFFTComplexIP ................................................. ....... 69<br />
Bỏ qua tín hiệu ................................................ .......... 215<br />
IIRCanonic ................................................. .............. 50<br />
IIRCanonicInit ................................................. .......... 51
FLT_MAX_10_EXP ................................................ 208<br />
FLT_MAX_EXP ...................................................... 209<br />
FLT_MIN ................................................................ 209<br />
FLT_MIN_10_EXP ................................................. 209<br />
FLT_MIN_EXP ....................................................... 209<br />
FLT_RADIX ............................................................ 209<br />
FLT_RADIX Digit<br />
Number Of....................................... 206, 208, 210<br />
FLT_ROUNDS ....................................................... 209<br />
Flush............................................................... 233, 280<br />
fmod ....................................................................... 341<br />
fmodf ...................................................................... 343<br />
-fno-short-double .............................206, 207, 208, 225<br />
fopen ...............................................225, 236, 262, 370<br />
FOPEN_MAX ......................................................... 227<br />
Form Feed.............................................................. 201<br />
Format Specifiers ........................................... 253, 259<br />
Formatted I/O Routines.......................................... 225<br />
Formatted Input/Output Functions<br />
fprintf ............................................................... 238<br />
fscanf............................................................... 242<br />
printf ................................................................ 253<br />
scanf................................................................ 259<br />
sprintf .............................................................. 263<br />
sscanf.............................................................. 263<br />
vfprintf ............................................................. 267<br />
vprintf .............................................................. 268<br />
vsprintf............................................................. 269<br />
Formatted Text<br />
Printing ............................................................ 263<br />
Scanning ......................................................... 263<br />
fpos_t...................................................................... 226<br />
fprintf .............................................................. 225, 238<br />
fputc........................................................................ 239<br />
fputs........................................................................ 239<br />
Index<br />
2004 Microchip Technology Inc. DS51456B-page 389<br />
fraction and exponent function<br />
Double Floating Point ..................................... 344<br />
IIRLattice ................................................. ................. 52<br />
Mô hình OCTAVE IIRLattice ........................................ 56<br />
IIRLatticeInit ................................................. ............ 53<br />
IIRTransposed ................................................. ......... 54<br />
IIRTransposedInit ................................................. 55 ....<br />
Hướng dẫn tín hiệu bất hợp pháp ......................................... 217<br />
Giới hạn thực hiện Xác định, Seelimits.h<br />
Chỉ số<br />
End Of tập tin .............................................. 225 , 227<br />
Lỗi ................................................. ....... 225, 232<br />
Chức vụ ..... 225, 233, 234, 239, 240, 245, 248 tập tin<br />
Infinity ................................................. .................... 325<br />
Đầu vào và đầu ra, Seestdio.h<br />
Input Capture chức năng<br />
Đóng Input Capture ........................................ 125<br />
Cấu hình Input Capture .................................. 127<br />
Cấu hình Input Capture Interrupt ................... 126<br />
Ví dụ sử dụng ............................................... 130<br />
Đọc tất cả các đầu vào chụp .................................. 128<br />
Input Capture Macros<br />
Vô hiệu hoá Capture Interrupt ................................ 129<br />
Kích hoạt tính năng Capture Interrupt ................................. 129<br />
Đặt Capture ngắt ưu tiên .......................... 129<br />
Định dạng đầu vào ................................................ ......... 225<br />
Chu kỳ hướng dẫn .................................... 320, 321, 324<br />
int<br />
Giá trị tối đa .............................................. 211<br />
Giá trị tối thiểu ............................................... 211<br />
INT_MAX ................................................. ............... 211<br />
INT_MIN ................................................. ................ 211<br />
Giới hạn số nguyên ................................................ .......... 211<br />
Nội bộ Thông báo lỗi ........................................... 305<br />
Địa chỉ Internet ................................................ ......... 5<br />
Interrupt Handler ................................................ 219 ....<br />
Tín hiệu ngắt ................................................ ....... 217<br />
Xử lý tín hiệu ngắt ........................................ 220<br />
Gián đoạn tin nhắn ............................................. 217<br />
Mã thực thi không hợp lệ tin nhắn ......................... 217<br />
Yêu cầu lưu trữ tin nhắn không hợp lệ ......................... 218
Single Floating Point....................................... 345<br />
Fraction Digits ........................................................ 253<br />
fread................................................................240, 371<br />
free......................................................................... 281<br />
Free Memory.......................................................... 281<br />
freopen....................................................225, 242, 370<br />
frexp ....................................................................... 344<br />
frexpf ...................................................................... 345<br />
fscanf ..............................................................225, 242<br />
fseek .......................................................244, 265, 369<br />
fsetpos ....................................................245, 265, 369<br />
ftell ..................................................................247, 369<br />
Full Buffering...................................................261, 262<br />
Fully Buffered..................................................225, 226<br />
fwrite ...................................................................... 248<br />
G<br />
getc ........................................................................ 250<br />
getchar ................................................................... 251<br />
getcSPIx................................................................. 163<br />
getcUARTx............................................................. 147<br />
getenv .............................................................281, 369<br />
gets .................................................................251, 371<br />
getsSPIx................................................................. 162<br />
getsUARTx............................................................. 146<br />
GMT ....................................................................... 320<br />
gmtime ............................................................320, 321<br />
Graphical Character<br />
Defined ........................................................... 198<br />
Test for............................................................ 198<br />
Greenwich Mean Time........................................... 320<br />
H<br />
h modifier ........................................................254, 259<br />
HammingInit............................................................. 28<br />
Handler<br />
Default ............................................................ 215<br />
Error ................................................................ 278<br />
Interrupt .......................................................... 219<br />
Nested ............................................................ 214<br />
Signal.......................................................215, 220<br />
Inverse cô sin, Seearccosine<br />
Sine nghịch đảo, Seearcsine<br />
Tangent nghịch đảo, Seearctangent<br />
isalnum ................................................. .................. 196<br />
isBOR ................................................. .................... 117<br />
iscntrl ................................................. ..................... 197<br />
isdigit ................................................. ..................... 198<br />
isgraph ................................................. .................. 198<br />
islapha ................................................. ................... 196<br />
islower ................................................. ................... 199<br />
isLVD ................................................. ..................... 117<br />
isMCLR ................................................. .................. 118<br />
isPOR ................................................. .................... 117<br />
isprint ................................................. ..................... 200<br />
ispunct ................................................. ................... 200<br />
isspace ................................................. .................. 201<br />
isupper ................................................. ................... 202<br />
isWDTTO ................................................. ............... 118<br />
isWDTWU ................................................. .............. 118<br />
isWU ................................................. ...................... 119<br />
isxdigit ................................................. ................... 202<br />
J<br />
jmp_buf ................................................. .................. 214<br />
Biện minh cho ................................................. .................... 253<br />
K<br />
KaiserInit ................................................. ................. 29<br />
L<br />
L sửa đổi lần ................................................ ........ 254, 259<br />
l sửa đổi lần ................................................ ......... 254, 259<br />
L_tmpnam ................................................. ..... 227, 265<br />
phòng thí nghiệm ................................................. ........................ 282<br />
LC_ALL ................................................. ................. 213<br />
LC_COLLATE ................................................. ....... 213<br />
LC_CTYPE ................................................. ............ 213<br />
LC_MONETARY ................................................. 213 ...<br />
LC_NUMERIC ................................................. ....... 213<br />
LC_TIME ................................................. ............... 213<br />
LCD, ngoài ............................................... ............ 74<br />
................................................. Bận rộn ................. 75
Signal Type..................................................... 215<br />
Handling<br />
Interrupt Signal ............................................... 220<br />
HanningInit............................................................... 28<br />
Header Files<br />
assert.h ........................................................... 195<br />
ctype.h ............................................................ 196<br />
errno.h .............................................205, 325, 370<br />
float.h .............................................................. 206<br />
limits.h............................................................. 211<br />
locale.h ........................................................... 213<br />
math.h............................................................. 325<br />
setjmp.h .......................................................... 214<br />
signal.h ........................................................... 215<br />
stdarg.h........................................................... 221<br />
stddef.h ........................................................... 223<br />
stdio.h ......................................................225, 371<br />
stdlib.h .............................................270, 369, 372<br />
string.h ............................................................ 294<br />
time.h ...................................................... 317, 373<br />
Heap....................................................................... 368<br />
Helper Functions .................................................... 366<br />
Hexadecimal ...................................254, 260, 291, 292<br />
Hexadecimal Conversion ....................................... 253<br />
Hexadecimal Digit<br />
Defined............................................................ 202<br />
Test for ............................................................ 202<br />
Horizontal Tab........................................................ 201<br />
Hour ........................................................317, 318, 322<br />
HUGE_VAL ............................................................ 325<br />
hyperbolic cosine<br />
Double Floating Point...................................... 335<br />
Single Floating Point ....................................... 336<br />
Hyperbolic Functions<br />
cosh ................................................................ 335<br />
coshf ............................................................... 336<br />
sinh ................................................................. 359<br />
sinhf ................................................................ 360<br />
tanh ................................................................. 364<br />
Ví dụ sử dụng ............................................... 80 ..<br />
Mở ................................................. ................ 75<br />
Đặt chuỗi ................................................ .......... 76<br />
Địa chỉ đọc ................................................ 77 ...<br />
Đọc dữ liệu ................................................ ......... 77<br />
Đặt nhân vật GeneratorAddress ..................... 78<br />
Thiết lập hiển thị Địa chỉ dữ liệu ................................. 78<br />
Viết lệnh ................................................ 79<br />
Viết liệu ................................................ ......... 78<br />
lconv, cấu trúc ............................................... ............. 213<br />
LDBL_DIG ................................................. ............. 209<br />
LDBL_EPSILON ................................................. 210 ....<br />
LDBL_MANT_DIG ................................................. . 210<br />
LDBL_MAX ................................................. ............ 210<br />
LDBL_MAX_10_EXP ............................................. 210<br />
LDBL_MAX_EXP ................................................. 210 ..<br />
LDBL_MIN ................................................. ............. 210<br />
LDBL_MIN_10_EXP ............................................... 210<br />
LDBL_MIN_EXP ................................................. 211 ....<br />
ldexp ................................................. ...................... 346<br />
ldexpf ................................................. ..................... 347<br />
ldiv ................................................. ................. 270, 283<br />
ldiv_t ................................................. ...................... 270<br />
Leap thứ hai ................................................ .. 317, 323<br />
Trái Canh ............................................... ............... 253<br />
libpic30, Xây dựng lại ............................................... . 366<br />
Chỉ số<br />
2004 Microchip Technology Inc DS51456B trang 391<br />
Thư viện<br />
DSP ................................................. ................... 9<br />
dsPIC ngoại vi ............................................... 73<br />
Tiêu chuẩn C ................................................ ...... 193<br />
Tiêu chuẩn C Toán ............................................. 325<br />
Giới hạn<br />
Floating Point ................................................ 206 ..<br />
Integer ................................................. ............ 211<br />
limits.h ............................................... ..................... 211<br />
CHAR_BITS ................................................. 211 ...<br />
CHAR_MAX ................................................. 211 ...
tanhf ................................................................ 365<br />
hyperbolic sine<br />
Double Floating Point...................................... 359<br />
Single Floating Point ....................................... 360<br />
hyperbolic tangent<br />
Double Floating Point...................................... 364<br />
Single Floating Point ....................................... 365<br />
I<br />
I/O Port Functions<br />
Configure CN Interrupts .................................. 122<br />
Configure CN Pull-Ups.................................... 122<br />
Configure INT.................................................. 121<br />
Disable INT ..................................................... 120<br />
I/O Port Macros<br />
Disable CN Interrupts...................................... 123<br />
Disable Interrupts............................................ 124<br />
Enable CN Interrupts...................................... 123<br />
Enable Interrupts............................................. 123<br />
Set Interrupts Priority ...................................... 124<br />
I2C Functions<br />
Acknowledge I2C ............................................ 184<br />
Close I2C. ....................................................... 183<br />
Configure I2C.................................................. 187<br />
Configure I2C Interrupt ................................... 183<br />
Data Ready I2C .............................................. 184<br />
Example of Use............................................... 192<br />
Idle I2C............................................................ 184<br />
Master I2C Get String ..................................... 185<br />
Master I2C Put String...................................... 185<br />
Not Acknowledge I2C..................................... 186<br />
Read Master I2C............................................. 186<br />
Read Slave I2C............................................... 189<br />
Restart I2C...................................................... 188<br />
Slave I2C Get String ....................................... 188<br />
Slave I2C Put String........................................ 189<br />
Start I2C.......................................................... 190<br />
Stop I2C .......................................................... 190<br />
Write Master I2C. ............................................ 186<br />
Write Slave I2C ............................................... 189<br />
CHAR_MIN ................................................. 211 ....<br />
INT_MAX. .................................................. ..... 211<br />
INT_MIN. .................................................. ...... 211<br />
LLONG_MAX ................................................. . 211<br />
LLONG_MIN ................................................. 212 ..<br />
LONG_MAX ................................................. 212 ...<br />
LONG_MIN. .................................................. 212 ..<br />
MB_LEN_MAX ................................................ 212<br />
SCHAR_MAX ................................................. 212<br />
SCHAR_MIN ................................................. 212 ..<br />
SHRT_MAX. .................................................. . 212<br />
SHRT_MIN. .................................................. 212 ..<br />
UCHAR_MAX ................................................. 213<br />
UINT_MAX ................................................. ..... 213<br />
ULLONG_MAX ............................................... 213<br />
ULONG_MAX. ................................................ 213<br />
USHRT_MAX ................................................. . 213<br />
Dòng Buffered ................................................ ... 225, 226<br />
Dòng Buffering ................................................ ......... 262<br />
ll sửa đổi lần ................................................ ......... 254, 259<br />
LLONG_MAX ................................................. ........ 211<br />
LLONG_MIN ................................................. ......... 212<br />
chức năng tải mũ<br />
Đôi Floating Point ..................................... 346<br />
Độc Floating Point ....................................... 347<br />
Giờ địa phương .............................................. 319, 321, 322<br />
Địa phương, C ............................................... .......... 196, 213<br />
Địa phương, khác ............................................... .......... 213<br />
locale.h ............................................... .................... 213<br />
localeconv ................................................. ............. 213<br />
Nội địa hóa, Seelocale.h<br />
localtime ................................................. 0,319, 320, 321<br />
Xác định vị trí nhân vật ................................................ 301 ...<br />
đăng nhập ................................................. ......................... 349<br />
log10 ................................................. ..................... 350<br />
log10f ................................................. .................... 351<br />
hàm logarit<br />
Đôi Floating Point ..................................... 350<br />
Độc Floating Point ....................................... 351
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 390 2004 Microchip Technology Inc.<br />
I2C Macros<br />
Disable Master I2C Interrupt ........................... 190<br />
Disable Slave I2C Interrupt ............................. 191<br />
Enable Master I2C Interrupt............................ 190<br />
Enable Slave I2C Interrupt.............................. 191<br />
Set Master I2C Interrupt Priority...................... 191<br />
Set Slave I2C Interrupt Priority........................ 191<br />
IdleI2C.................................................................... 184<br />
IFFTComplex............................................................ 67<br />
IFFTComplexIP ........................................................ 69<br />
Ignore Signal .......................................................... 215<br />
IIRCanonic ............................................................... 50<br />
IIRCanonicInit........................................................... 51<br />
IIRLattice .................................................................. 52<br />
IIRLattice OCTAVE model........................................ 56<br />
IIRLatticeInit ............................................................. 53<br />
IIRTransposed.......................................................... 54<br />
IIRTransposedInit..................................................... 55<br />
Illegal Instruction Signal ......................................... 217<br />
Implementation-Defined Limits, Seelimits.h<br />
Indicator<br />
End Of File .............................................. 225, 227<br />
Error ........................................................ 225, 232<br />
File Position ..... 225, 233, 234, 239, 240, 245, 248<br />
Infinity ..................................................................... 325<br />
Input and Output, Seestdio.h<br />
Input Capture Functions<br />
Close Input Capture ........................................ 125<br />
Configure Input Capture.................................. 127<br />
Configure Input Capture Interrupt ................... 126<br />
Example of Use............................................... 130<br />
Read All Input Captures .................................. 128<br />
Input Capture Macros<br />
Disable Capture Interrupt................................ 129<br />
Enable Capture Interrupt................................. 129<br />
hàm logarit tự nhiên<br />
Đôi Floating Point ..................................... 349<br />
Độc Floating Point ....................................... 352<br />
logf ................................................. ........................ 352<br />
lỗi logic, gỡ lỗi .......................................... 195<br />
Dài đôi chính xác dấu chấm động<br />
Máy Epsilon ............................................. 210<br />
Exponent tối đa (10 cơ sở) ........................ 210<br />
Exponent tối đa (cơ sở 2) .......................... 210<br />
Giá trị tối đa .............................................. 210<br />
Tối thiểu Exponent (10 cơ sở) ......................... 210<br />
Tối thiểu Exponent (cơ sở 2) ........................... 211<br />
Giá trị tối thiểu ............................................... 210<br />
Số chữ số nhị phân .................................. 210<br />
Số thập phân chữ số ............................... 209<br />
Loại dài đôi ............................................... ..... 225<br />
long int<br />
Giá trị tối đa .............................................. 212<br />
Giá trị tối thiểu ............................................... 212<br />
lâu dài int<br />
Giá trị tối đa .............................................. 211<br />
Giá trị tối thiểu ............................................... 212<br />
lâu dài int<br />
Giá trị tối đa .............................................. 213<br />
unsigned long int<br />
Giá trị tối đa .............................................. 213<br />
LONG_MAX ................................................. .......... 212<br />
LONG_MIN ................................................. ........... 212<br />
longjmp ................................................. .................. 214<br />
Thấp hơn trường hợp chữ cái ký tự<br />
Để chuyển đổi ................................................ ...... 203<br />
Xác định ................................................. ........... 199<br />
Kiểm tra cho ................................................ ............ 199<br />
lseek ................................................. ...................... 369<br />
M<br />
Máy Epsilon<br />
Đôi Floating Point ...................................... 206<br />
Dài đôi Floating Point ............................. 210<br />
Độc Floating Point ....................................... 208
Set Capture Interrupt Priority .......................... 129<br />
Input Formats ......................................................... 225<br />
Instruction Cycles ....................................320, 321, 324<br />
int<br />
Maximum Value .............................................. 211<br />
Minimum Value ............................................... 211<br />
INT_MAX................................................................ 211<br />
INT_MIN................................................................. 211<br />
Integer Limits.......................................................... 211<br />
Internal Error Message........................................... 305<br />
Internet Address ......................................................... 5<br />
Interrupt Handler .................................................... 219<br />
Interrupt Signal ....................................................... 217<br />
Interrupt Signal Handling........................................ 220<br />
Interruption Message ............................................. 217<br />
Invalid Executable Code Message ......................... 217<br />
Invalid Storage Request Message ......................... 218<br />
Inverse Cosine, Seearccosine<br />
Inverse Sine, Seearcsine<br />
Inverse Tangent, Seearctangent<br />
isalnum................................................................... 196<br />
isBOR..................................................................... 117<br />
iscntrl...................................................................... 197<br />
isdigit ...................................................................... 198<br />
isgraph ................................................................... 198<br />
islapha .................................................................... 196<br />
islower .................................................................... 199<br />
isLVD...................................................................... 117<br />
isMCLR................................................................... 118<br />
isPOR ..................................................................... 117<br />
isprint...................................................................... 200<br />
ispunct .................................................................... 200<br />
isspace ................................................................... 201<br />
isupper.................................................................... 202<br />
isWDTTO................................................................ 118<br />
isWDTWU............................................................... 118<br />
isWU....................................................................... 119<br />
isxdigit .................................................................... 202<br />
J<br />
Tầm quan trọng ................ 325, 337, 338, 341, 343, 359, 360<br />
malloc .............................................. 281, 284 , 367, 372<br />
Lập bản đồ nhân vật ............................................... 196<br />
MastergetsI2C ................................................. ....... 185<br />
MasterputsI2C ................................................. ....... 185<br />
MasterReadI2C ................................................. ..... 186<br />
MasterWriteI2C ................................................. ..... 186<br />
Toán ngoại lệ Lỗi ............................................. 278<br />
math.h ............................................... ..................... 325<br />
acos. .................................................. ............. 325<br />
acosf. .................................................. ............ 326<br />
asin. .................................................. .............. 327<br />
asinf ................................................. ............... 327<br />
atan. .................................................. .............. 328<br />
atan2. .................................................. ............ 329<br />
atan2f. .................................................. ........... 331<br />
atanf. .................................................. ............. 329<br />
ceil ................................................. .................. 332<br />
ceilf ................................................. ................. 333<br />
cos ................................................. ................. 333<br />
cosf ................................................. ................ 334<br />
cosh ................................................. ............... 335<br />
coshf ................................................. .............. 336<br />
exp ................................................. ................. 337<br />
expf ................................................. ................ 338<br />
fabs ................................................. ................ 339<br />
fabsf ................................................. ............... 339<br />
sàn ................................................. ................ 340<br />
floorf ................................................. ............... 340<br />
fmod ................................................. ............... 341<br />
fmodf ................................................. .............. 343<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 392 2004 Microchip Technology Inc<br />
frexp ................................................. ............... 344<br />
frexpf ................................................. .............. 345<br />
HUGE_VAL ................................................. 325 ....<br />
ldexp ................................................. .............. 346
jmp_buf................................................................... 214<br />
Justify ..................................................................... 253<br />
K<br />
KaiserInit .................................................................. 29<br />
L<br />
L modifier........................................................ 254, 259<br />
l modifier ......................................................... 254, 259<br />
L_tmpnam ...................................................... 227, 265<br />
labs......................................................................... 282<br />
LC_ALL .................................................................. 213<br />
LC_COLLATE ........................................................ 213<br />
LC_CTYPE............................................................. 213<br />
LC_MONETARY .................................................... 213<br />
LC_NUMERIC ........................................................ 213<br />
LC_TIME ................................................................ 213<br />
LCD, External ........................................................... 74<br />
Busy .................................................................. 75<br />
Example of Use................................................. 80<br />
Open ................................................................. 75<br />
Put String .......................................................... 76<br />
Read Address ................................................... 77<br />
Read Data ......................................................... 77<br />
Set Character GeneratorAddress..................... 78<br />
Set Display Data Address ................................. 78<br />
Write Command ................................................ 79<br />
Write Data ......................................................... 78<br />
lconv, struct ............................................................ 213<br />
LDBL_DIG .............................................................. 209<br />
LDBL_EPSILON..................................................... 210<br />
LDBL_MANT_DIG.................................................. 210<br />
LDBL_MAX............................................................. 210<br />
LDBL_MAX_10_EXP ............................................. 210<br />
LDBL_MAX_EXP ................................................... 210<br />
LDBL_MIN.............................................................. 210<br />
LDBL_MIN_10_EXP............................................... 210<br />
LDBL_MIN_EXP..................................................... 211<br />
ldexp....................................................................... 346<br />
ldexpf...................................................................... 347<br />
ldiv .................................................................. 270, 283<br />
ldexpf ................................................. ............. 347<br />
đăng nhập ................................................. .................. 349<br />
log10 ................................................. .............. 350<br />
log10f ................................................. ............. 351<br />
logf ................................................. ................. 352<br />
modf ................................................. ............... 353<br />
modff ................................................. .............. 354<br />
pow ................................................. ................ 355<br />
powf ................................................. ............... 356<br />
tội lỗi ................................................. .................. 357<br />
sinf ................................................. ................. 358<br />
sinh ................................................. ................ 359<br />
sinhf ................................................. ............... 360<br />
sqrt ................................................. ................. 361<br />
sqrtf ................................................. ................ 362<br />
tan ................................................. .................. 363<br />
TANF ................................................. ................. 363<br />
tanh ................................................. ................ 364<br />
tanhf ................................................. ............... 365<br />
Chức năng toán học, Seemath.h<br />
Chức năng Matrix ................................................ ....... 31<br />
MatrixAdd ................................................. ................ 33<br />
MatrixInvert ................................................. ............. 37<br />
MatrixMultiply ................................................. .......... 34<br />
MatrixScale ................................................. ............. 35<br />
MatrixSubtract ................................................. ......... 35<br />
MatrixTranspose ................................................. ...... 36<br />
Tối đa<br />
Ký tự nhiều byte ......................................... 271<br />
Giá trị tối đa<br />
Đôi Floating Point Exponent (10 cơ sở) ..... 207<br />
Đôi Floating Point Exponent (cơ sở 2) ....... 207<br />
Dài đôi Floating Point Exponent<br />
(10 cơ sở) .......................................... 210<br />
Dài đôi Floating Point Exponent<br />
(Cơ sở 2) ............................................ 210<br />
Ký tự nhiều byte ......................................... 212<br />
rand ................................................. ................ 271<br />
Độc Floating Point Exponent (10 cơ sở) ....... 208
ldiv_t ....................................................................... 270<br />
Leap Second .................................................. 317, 323<br />
Left-Justify .............................................................. 253<br />
libpic30, Rebuilding ................................................ 366<br />
Index<br />
2004 Microchip Technology Inc. DS51456B-page 391<br />
Libraries<br />
DSP .................................................................... 9<br />
dsPIC Peripheral............................................... 73<br />
Standard C...................................................... 193<br />
Standard C Math............................................. 325<br />
Limits<br />
Floating Point.................................................. 206<br />
Integer............................................................. 211<br />
limits.h.................................................................... 211<br />
CHAR_BITS.................................................... 211<br />
CHAR_MAX.................................................... 211<br />
CHAR_MIN ..................................................... 211<br />
INT_MAX. ....................................................... 211<br />
INT_MIN. ........................................................ 211<br />
LLONG_MAX.................................................. 211<br />
LLONG_MIN ................................................... 212<br />
LONG_MAX.................................................... 212<br />
LONG_MIN. .................................................... 212<br />
MB_LEN_MAX................................................ 212<br />
SCHAR_MAX ................................................. 212<br />
SCHAR_MIN................................................... 212<br />
SHRT_MAX. ................................................... 212<br />
SHRT_MIN. .................................................... 212<br />
UCHAR_MAX ................................................. 213<br />
UINT_MAX...................................................... 213<br />
ULLONG_MAX ............................................... 213<br />
ULONG_MAX. ................................................ 213<br />
USHRT_MAX.................................................. 213<br />
Line Buffered...................................................225, 226<br />
Line Buffering......................................................... 262<br />
ll modifier.........................................................254, 259<br />
LLONG_MAX ......................................................... 211<br />
LLONG_MIN .......................................................... 212<br />
Độc Floating Point Exponent (cơ sở 2) ......... 209<br />
Loại char ................................................ ........ 211<br />
Loại đôi ................................................ 206 ....<br />
Kiểu int ................................................ ........... 211<br />
Loại dài đôi ........................................... 210<br />
Loại long int ............................................... 212 ....<br />
Loại dài dài int ............................................ 211<br />
Loại dài dài int ............................ 213<br />
Loại dài int .................................... 213<br />
Loại ngắn int ............................................... 212 ...<br />
Loại ký char ............................................ 212<br />
Loại đơn ................................................ ..... 208<br />
Loại unsigned char ........................................ 213<br />
Loại int ............................................ 213<br />
Loại unsigned short int ................................... 213<br />
MB_CUR_MAX ................................................. ..... 271<br />
MB_LEN_MAX ................................................. ...... 212<br />
mblen ................................................. ..................... 285<br />
mbstowcs ................................................. .............. 285<br />
mbtowc ................................................. .................. 285<br />
memchr ................................................. ................. 294<br />
memcmp ................................................. ................ 295<br />
memcpy ................................................. ................. 297<br />
memmove ................................................. .............. 298<br />
Bộ nhớ<br />
Phân bổ ................................................. .. 278, 284<br />
Deallocate ................................................. ...... 281<br />
Miễn phí ................................................. ................ 281<br />
Phân bổ lại ................................................. ...... 287<br />
memset ................................................. .................. 299<br />
Tin nhắn<br />
Lỗi số học ............................................... 216<br />
Ngắt ................................................. .......... 217<br />
Mã thực thi không hợp lệ ................................. 217<br />
Yêu cầu lưu trữ không hợp lệ .................................. 218<br />
Yêu cầu chấm dứt ....................................... 218<br />
Microchip trang web Internet ....................................... 5<br />
Giá trị tối thiểu<br />
Đôi Floating Point Exponent (10 cơ sở) ..... 207
load exponent function<br />
Double Floating Point ..................................... 346<br />
Single Floating Point....................................... 347<br />
Local Time ..............................................319, 321, 322<br />
Locale, C.........................................................196, 213<br />
Locale, Other ......................................................... 213<br />
locale.h................................................................... 213<br />
localeconv .............................................................. 213<br />
Localization, Seelocale.h<br />
localtime..................................................319, 320, 321<br />
Locate Character ................................................... 301<br />
log .......................................................................... 349<br />
log10 ...................................................................... 350<br />
log10f ..................................................................... 351<br />
logarithm function<br />
Double Floating Point ..................................... 350<br />
Single Floating Point....................................... 351<br />
logarithm function, natural<br />
Double Floating Point ..................................... 349<br />
Single Floating Point....................................... 352<br />
logf ......................................................................... 352<br />
logic errors, debugging .......................................... 195<br />
Long Double Precision Floating Point<br />
Machine Epsilon ............................................. 210<br />
Maximum Exponent (base 10) ........................ 210<br />
Maximum Exponent (base 2) .......................... 210<br />
Maximum Value .............................................. 210<br />
Minimum Exponent (base 10) ......................... 210<br />
Minimum Exponent (base 2) ........................... 211<br />
Minimum Value ............................................... 210<br />
Number of Binary Digits .................................. 210<br />
Number of Decimal Digits ............................... 209<br />
long double Type.................................................... 225<br />
long int<br />
Maximum Value .............................................. 212<br />
Minimum Value ............................................... 212<br />
long long int<br />
Maximum Value .............................................. 211<br />
Minimum Value ............................................... 212<br />
Đôi Floating Point Exponent (cơ sở 2) ....... 208<br />
Dài đôi Floating Point Exponent<br />
(10 cơ sở) ........................................... 210<br />
Dài đôi Floating Point Exponent<br />
(Cơ sở 2) ............................................. 211<br />
Độc Floating Point Exponent (10 cơ sở) ....... 209<br />
Độc Floating Point Exponent (cơ sở 2) ......... 209<br />
Loại char ................................................ ........ 211<br />
Loại đôi ................................................ 207 ....<br />
Kiểu int ................................................ ........... 211<br />
Loại dài đôi ........................................... 210<br />
Loại long int ............................................... ..... 212<br />
Loại dài dài int ............................................ 212<br />
Loại ngắn int ............................................... 212 ...<br />
Loại ký char ............................................. 212<br />
Loại đơn ................................................ ..... 209<br />
Phút ................................................. .... 317, 318, 323<br />
mktime ................................................. ................... 322<br />
modf ................................................. ...................... 353<br />
modff ................................................. ..................... 354<br />
chức năng mô đun<br />
Đôi Floating Point ...................................... 353<br />
Độc Floating Point ....................................... 354<br />
Tháng .............................................. 317, 318 , 322, 323<br />
-msmart-io .............................................. ................ 225<br />
Nhiều byte nhân vật ................................ 271, 285, 293<br />
Số lượng tối đa Bytes ............................. 212<br />
Nhiều byte chuỗi ............................................... 285 , 293<br />
N<br />
NaN ................................................. ....................... 325<br />
Logarithm tự nhiên<br />
Đôi Floating Point ...................................... 349<br />
Độc Floating Point ....................................... 352<br />
NDEBUG ................................................. ............... 195<br />
Chức năng Integer gần<br />
ceil ................................................. .................. 332<br />
ceilf ................................................. ................. 333<br />
Chỉ số<br />
2004 Microchip Technology Inc DS51456B trang 393
long long unsigned int<br />
Maximum Value .............................................. 213<br />
long unsigned int<br />
Maximum Value .............................................. 213<br />
LONG_MAX ........................................................... 212<br />
LONG_MIN ............................................................ 212<br />
longjmp................................................................... 214<br />
Lower Case Alphabetic Character<br />
Convert To ...................................................... 203<br />
Defined............................................................ 199<br />
Test for ............................................................ 199<br />
lseek....................................................................... 369<br />
M<br />
Machine Epsilon<br />
Double Floating Point...................................... 206<br />
Long Double Floating Point............................. 210<br />
Single Floating Point ....................................... 208<br />
Magnitude ................325, 337, 338, 341, 343, 359, 360<br />
malloc..............................................281, 284, 367, 372<br />
Mapping Characters............................................... 196<br />
MastergetsI2C........................................................ 185<br />
MasterputsI2C........................................................ 185<br />
MasterReadI2C ...................................................... 186<br />
MasterWriteI2C ...................................................... 186<br />
Math Exception Error ............................................. 278<br />
math.h .................................................................... 325<br />
acos. ............................................................... 325<br />
acosf. .............................................................. 326<br />
asin. ................................................................ 327<br />
asinf ................................................................ 327<br />
atan. ................................................................ 328<br />
atan2. .............................................................. 329<br />
atan2f. ............................................................. 331<br />
atanf. ............................................................... 329<br />
ceil................................................................... 332<br />
ceilf.................................................................. 333<br />
cos .................................................................. 333<br />
cosf ................................................................. 334<br />
cosh ................................................................ 335<br />
sàn ................................................. ................ 340<br />
floorf ................................................. ............... 340<br />
Lồng nhau tín hiệu Handler ........................................... 214<br />
Xuống dòng .................... 201, 225, 235, 240, 251, 252, 256<br />
Không có bộ nhớ đệm .................................... 225, 226, 261, 262<br />
Nhảy không địa phương, Seesetjmp.h<br />
NotAckI2C ................................................. ............. 186<br />
NULL ............................... 213, 223, 227, 271, 294, 318<br />
O<br />
Mô-đun đối tượng Định dạng ............................................... 7<br />
Bát phân ................................................ 254 , 260, 291, 292<br />
Chuyển đổi bát phân ................................................ 253 ...<br />
offsetof ................................................. .................. 224<br />
OMF ................................................. .......................... 7<br />
mở ................................................. ...................... 370<br />
OpenADC10 ................................................. .......... 103<br />
OpenADC12 ................................................. ............ 96<br />
OpenCapturex ................................................. ....... 127<br />
OpenDCI ................................................. ............... 151<br />
OpenI2C ................................................. ................ 187<br />
OpenMCPWM ................................................. ....... 172<br />
OpenOCx ................................................. .............. 133<br />
OpenQEI ................................................. ............... 167<br />
OpenSPIx ................................................. .............. 160<br />
OpenTimerx ................................................. .......... 111<br />
OpenTimerxx ................................................. ........ 112<br />
OpenUART ................................................. ........... 143<br />
OpenXLCD ................................................. .............. 75<br />
So sánh sản lượng chức năng<br />
Đóng So sánh ............................................... 131<br />
Cấu hình So sánh ........................................ 133<br />
Cấu hình So sánh ngắt .......................... 132<br />
Ví dụ sử dụng .............................................. 140<br />
So sánh là đã đọc Chu kỳ ............................. 136<br />
So sánh là đã đọc Chu kỳ - chế độ PWM ....... 135<br />
Set So sánh Chu kỳ ................................ 138<br />
Đặt so sánh Chu kỳ - chế độ PWM .......... 137<br />
So sánh sản lượng Macros<br />
Vô hiệu hoá So sánh ngắt .............................. 139
coshf ............................................................... 336<br />
exp .................................................................. 337<br />
expf ................................................................. 338<br />
fabs ................................................................. 339<br />
fabsf ................................................................ 339<br />
floor ................................................................. 340<br />
floorf ................................................................ 340<br />
fmod ................................................................ 341<br />
fmodf ............................................................... 343<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 392 2004 Microchip Technology Inc.<br />
frexp ................................................................ 344<br />
frexpf ............................................................... 345<br />
HUGE_VAL..................................................... 325<br />
ldexp ............................................................... 346<br />
ldexpf .............................................................. 347<br />
log ................................................................... 349<br />
log10 ............................................................... 350<br />
log10f .............................................................. 351<br />
logf .................................................................. 352<br />
modf ................................................................ 353<br />
modff ............................................................... 354<br />
pow ................................................................. 355<br />
powf ................................................................ 356<br />
sin ................................................................... 357<br />
sinf .................................................................. 358<br />
sinh ................................................................. 359<br />
sinhf ................................................................ 360<br />
sqrt .................................................................. 361<br />
sqrtf ................................................................. 362<br />
tan ................................................................... 363<br />
tanf .................................................................. 363<br />
tanh ................................................................. 364<br />
tanhf ................................................................ 365<br />
Mathematical Functions, Seemath.h<br />
Matrix Functions ....................................................... 31<br />
MatrixAdd ................................................................. 33<br />
Kích hoạt tính năng so sánh ngắt .............................. 139<br />
So sánh thiết lập ưu tiên ngắt ........................ 139<br />
Định dạng đầu ra ................................................ ...... 225<br />
Lỗi tràn .............................. 205, 325, 337, 338,<br />
.................................................. .. 346, 348, 355, 356<br />
Chồng chéo ........................... 297, 298, 300, 303, 306, 309<br />
P<br />
Pad nhân vật ................................................ ...... 253<br />
Phần trăm ............................................ 254, 259, 260 323<br />
Thư viện ngoại vi, dsPIC ...................................... 73<br />
perror ................................................. .................... 252<br />
pic30-libs ............................................... ................. 366<br />
_exit ................................................. ............... 367<br />
brk ................................................. .................. 367<br />
gần ................................................. .............. 368<br />
getenv ................................................. ............ 369<br />
lseek ................................................. .............. 369<br />
mở ................................................. ............... 370<br />
đọc ................................................. ................ 371<br />
loại bỏ ................................................. ........... 371<br />
đổi tên ................................................. ........... 371<br />
sbrk ................................................. ................ 372<br />
hệ thống ................................................. ............ 372<br />
Hiện ................................................. ................ 373<br />
viết ................................................. ............... 373<br />
Thêm Đăng ................................................ ................ 253<br />
Con trỏ, tạm thời ............................................... . 287<br />
PORStatReset ................................................. ....... 119<br />
pow ................................................. ........................ 355<br />
chức năng điện<br />
Đôi Floating Point ...................................... 355<br />
Độc Floating Point ....................................... 356<br />
Chức năng suất<br />
pow ................................................. ................ 355<br />
powf ................................................. ............... 356<br />
powf ................................................. ....................... 356<br />
chính xác ................................................. ................ 253<br />
Tiền tố ................................................. ..................... 253<br />
tiền tố ................................................. ..................... 202
MatrixInvert .............................................................. 37<br />
MatrixMultiply ........................................................... 34<br />
MatrixScale .............................................................. 35<br />
MatrixSubtract .......................................................... 35<br />
MatrixTranspose....................................................... 36<br />
Maximum<br />
Multibyte Character......................................... 271<br />
Maximum Value<br />
Double Floating Point Exponent (base 10) ..... 207<br />
Double Floating Point Exponent (base 2) ....... 207<br />
Long Double Floating Point Exponent<br />
(base 10) .......................................... 210<br />
Long Double Floating Point Exponent<br />
(base 2) ............................................ 210<br />
Multibyte Character......................................... 212<br />
rand................................................................. 271<br />
Single Floating Point Exponent (base 10)....... 208<br />
Single Floating Point Exponent (base 2)......... 209<br />
Type char ........................................................ 211<br />
Type Double.................................................... 206<br />
Type int ........................................................... 211<br />
Type Long Double........................................... 210<br />
Type long int ................................................... 212<br />
Type long long int............................................ 211<br />
Type long long unsigned int ............................ 213<br />
Type long unsigned int.................................... 213<br />
Type short int .................................................. 212<br />
Type signed char ............................................ 212<br />
Type Single ..................................................... 208<br />
Type unsigned char ........................................ 213<br />
Type unsigned int............................................ 213<br />
Type unsigned short int................................... 213<br />
MB_CUR_MAX ...................................................... 271<br />
MB_LEN_MAX ....................................................... 212<br />
mblen...................................................................... 285<br />
mbstowcs ............................................................... 285<br />
mbtowc ................................................................... 285<br />
memchr .................................................................. 294<br />
memcmp................................................................. 295<br />
Định dạng In ................................................ .......... 225<br />
Nhân vật có thể in<br />
Xác định ................................................. ........... 200<br />
Kiểm tra cho ................................................ ............ 200<br />
printf ................................................. .............. 225, 253<br />
Đồng hồ xử lý mỗi thứ hai ................................ 317<br />
Thời gian xử lý .............................................. 317, 318<br />
Pseudo-Random Số .............................. 287, 289<br />
ptrdiff_t ................................................. .................. 223<br />
Dấu phân cách nhân vật<br />
Xác định ................................................. ........... 200<br />
Kiểm tra cho ................................................ ............ 200<br />
Đẩy Trở lại ................................................ .......... 265<br />
putc ................................................. ....................... 255<br />
putchar ................................................. .................. 256<br />
putcSPIx ................................................. ................ 163<br />
putcUARTx ................................................. ............ 147<br />
putrsXLCD ................................................. ............... 76<br />
đặt ................................................. ....................... 256<br />
putsSPIx ................................................. ................ 162<br />
putsUARTx ................................................. ............ 146<br />
putsXLCD ................................................. ................ 76<br />
PverrideMCPWM ................................................. 174 ..<br />
Chức năng PWM<br />
Đóng cửa PWM ................................................ ..... 171<br />
Cấu hình Override .......................................... 174<br />
Cấu hình PWM ............................................... 172<br />
Cấu hình PWM ngắt ................................ 171<br />
Ví dụ sử dụng ............................................... 182<br />
Thiết lập PWM Dead Thời gian chuyển nhượng .................. 176<br />
Thiết lập PWM Dead Thời gian thế hệ ................... 177<br />
Đặt PWM Duty Cycle ...................................... 175<br />
Thiết lập PWM FaultA. ............................................ 178<br />
Thiết lập PWM FaultB. ............................................ 179<br />
PWM Macros<br />
Vô hiệu hoá FLTA ngắt .................................... 180<br />
Vô hiệu hoá FLTB ngắt .................................... 181<br />
Vô hiệu hoá PWM ngắt .................................... 180<br />
Kích hoạt tính năng ngắt FLTA ..................................... 180
memcpy.................................................................. 297<br />
memmove............................................................... 298<br />
Memory<br />
Allocate ................................................... 278, 284<br />
Deallocate ....................................................... 281<br />
Free................................................................. 281<br />
Reallocate ....................................................... 287<br />
memset................................................................... 299<br />
Message<br />
Arithmetic Error ............................................... 216<br />
Interrupt........................................................... 217<br />
Invalid Executable Code ................................. 217<br />
Invalid Storage Request.................................. 218<br />
Termination Request....................................... 218<br />
Microchip Internet Web Site ....................................... 5<br />
Minimum Value<br />
Double Floating Point Exponent (base 10) ..... 207<br />
Double Floating Point Exponent (base 2) ....... 208<br />
Long Double Floating Point Exponent<br />
(base 10)........................................... 210<br />
Long Double Floating Point Exponent<br />
(base 2)............................................. 211<br />
Single Floating Point Exponent (base 10) ....... 209<br />
Single Floating Point Exponent (base 2) ......... 209<br />
Type char ........................................................ 211<br />
Type Double.................................................... 207<br />
Type int ........................................................... 211<br />
Type Long Double........................................... 210<br />
Type long int.................................................... 212<br />
Type long long int............................................ 212<br />
Type short int .................................................. 212<br />
Type signed char............................................. 212<br />
Type Single ..................................................... 209<br />
Minute..................................................... 317, 318, 323<br />
mktime.................................................................... 322<br />
modf ....................................................................... 353<br />
modff ...................................................................... 354<br />
modulus function<br />
Double Floating Point...................................... 353<br />
Kích hoạt tính năng ngắt FLTB ..................................... 181<br />
Kích hoạt tính năng ngắt PWM ..................................... 180<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 394 2004 Microchip Technology Inc<br />
Đặt ưu tiên FLTA ngắt .............................. 181<br />
Đặt FLTB ngắt ưu tiên .............................. 181<br />
Thiết lập PWM ngắt ưu tiên .............................. 180<br />
Q<br />
Chức năng QEI<br />
Đóng QEI ................................................ ........ 166<br />
Cấu hình QEI ................................................ . 167<br />
Cấu hình QEI ngắt ................................... 166<br />
Ví dụ sử dụng ............................................... 170<br />
Đọc QEI Lượt Chức vụ ................................ 168<br />
Viết QEI Lượt Chức vụ ................................ 169<br />
QEI Macros<br />
Vô hiệu hoá QEI ngắt ...................................... 169<br />
Kích hoạt tính năng QEI ngắt ....................................... 169<br />
Đặt ưu tiên QEI ngắt ................................. 169<br />
qsort ................................................. .............. 276, 286<br />
Nhanh chóng theo ................................................ .............. 286<br />
R<br />
Radix ................................................. ..................... 209<br />
nâng cao ................................ 215, 216, 217, 218, 219, 220<br />
rand ................................................. ............... 287, 289<br />
RAND_MAX ................................................. .. 271, 287<br />
Phạm vi ................................................. .................... 260<br />
Phạm vi Lỗi ............................ 205, 291, 292, 335, 336,<br />
...................... 337, 338, 346, 348, 355, 356, 359, 360<br />
đọc ................................................. ....................... 371<br />
ReadADC10 ................................................. .......... 106<br />
ReadADC12 ................................................. ............ 99<br />
ReadAddrXLCD ................................................. ...... 77<br />
ReadCapture ................................................. ......... 128<br />
ReadDataXLCD ................................................. ...... 77<br />
ReadDCI ................................................. ............... 154<br />
ReadDCOCxPWM ................................................. . 135
Single Floating Point....................................... 354<br />
Month ..............................................317, 318, 322, 323<br />
-msmart-io .............................................................. 225<br />
Multibyte Character ................................ 271, 285, 293<br />
Maximum Number of Bytes............................. 212<br />
Multibyte String............................................... 285, 293<br />
N<br />
NaN ........................................................................ 325<br />
Natural Logarithm<br />
Double Floating Point...................................... 349<br />
Single Floating Point....................................... 352<br />
NDEBUG ................................................................ 195<br />
Nearest Integer Functions<br />
ceil................................................................... 332<br />
ceilf.................................................................. 333<br />
Index<br />
2004 Microchip Technology Inc. DS51456B-page 393<br />
floor ................................................................. 340<br />
floorf................................................................ 340<br />
Nested Signal Handler ........................................... 214<br />
Newline ....................201, 225, 235, 240, 251, 252, 256<br />
No Buffering .................................... 225, 226, 261, 262<br />
Non-Local Jumps, Seesetjmp.h<br />
NotAckI2C.............................................................. 186<br />
NULL............................... 213, 223, 227, 271, 294, 318<br />
O<br />
Object Module Format............................................... 7<br />
Octal................................................ 254, 260, 291, 292<br />
Octal Conversion ................................................... 253<br />
offsetof ................................................................... 224<br />
OMF ........................................................................... 7<br />
open ....................................................................... 370<br />
OpenADC10........................................................... 103<br />
OpenADC12............................................................. 96<br />
OpenCapturex........................................................ 127<br />
OpenDCI ................................................................ 151<br />
OpenI2C................................................................. 187<br />
OpenMCPWM........................................................ 172<br />
OpenOCx ............................................................... 133<br />
Đọc sách, xuất ............................................ 4<br />
ReadQEI ................................................. ............... 168<br />
ReadRegOCx ................................................. ........ 136<br />
ReadSPIx ................................................. .............. 159<br />
ReadTimerx ................................................. ........... 113<br />
ReadTimerxx ................................................. ......... 114<br />
ReadUARTx ................................................. .......... 145<br />
realloc ................................................. ............ 281, 287<br />
Phân bổ lại nhớ ................................................ 287<br />
Xây dựng lại thư viện libpic30 ................................ 366<br />
Chức năng đăng ký ..................................... 272, 280<br />
còn lại<br />
Đôi Floating Point ...................................... 341<br />
Độc Floating Point ....................................... 343<br />
Chức năng còn lại<br />
fmod ................................................. ............... 341<br />
fmodf ................................................. .............. 343<br />
loại bỏ ................................................. .......... 257, 371<br />
đổi tên ................................................. .......... 257, 371<br />
Thiết lập lại ................................................. ............. 271, 293<br />
Thiết lập lại tập tin con trỏ ............................................... 258 ....<br />
Thiết lập lại chức năng / Control<br />
Phát hiện điện áp thấp ......................................... 117<br />
Master Clear lại ......................................... 118<br />
Thiết lập lại từ Brown-out ..................................... 117<br />
Thiết lập lại từ Power-on ...................................... 117<br />
Wake-up từ Sleep ....................................... 119<br />
Watchdog Timer hết giờ ............................... 118<br />
Watchdog Timer Wake-up .............................. 118<br />
Thiết lập lại / Control Macros<br />
Vô hiệu hoá tất cả các ngắt ....................................... 119<br />
Vô hiệu hóa Watchdog Timer ................................. 120<br />
Kích hoạt tính năng Watchdog Timer .................................. 120<br />
Thiết lập lại Ban đại diện bit ............................................... 119 ..<br />
Thiết lập lại POR bit ............................................... 119 ..<br />
RestartI2C ................................................. ............. 188<br />
tua lại ................................................. .... 258, 265, 369<br />
Chế độ làm tròn ................................................ ...... 209<br />
S
OpenQEI ................................................................ 167<br />
OpenSPIx............................................................... 160<br />
OpenTimerx ........................................................... 111<br />
OpenTimerxx ......................................................... 112<br />
OpenUART ............................................................ 143<br />
OpenXLCD............................................................... 75<br />
Output Compare Functions<br />
Close Compare............................................... 131<br />
Configure Compare ........................................ 133<br />
Configure Compare Interrupt .......................... 132<br />
Example of Use .............................................. 140<br />
Read Compare Duty Cycle ............................. 136<br />
Read Compare Duty Cycle - PWM mode ....... 135<br />
Set Compare Duty Cycle ................................ 138<br />
Set Compare Duty Cycle - PWM mode .......... 137<br />
Output Compare Macros<br />
Disable Compare Interrupt.............................. 139<br />
Enable Compare Interrupt .............................. 139<br />
Set Compare Interrupt Priority ........................ 139<br />
Output Formats ...................................................... 225<br />
Overflow Errors .............................. 205, 325, 337, 338,<br />
.................................................... 346, 348, 355, 356<br />
Overlap ........................... 297, 298, 300, 303, 306, 309<br />
P<br />
Pad Characters ...................................................... 253<br />
Percent............................................ 254, 259, 260, 323<br />
Peripheral Libraries, dsPIC ...................................... 73<br />
perror ..................................................................... 252<br />
pic30-libs ................................................................ 366<br />
_exit ................................................................ 367<br />
brk ................................................................... 367<br />
close ............................................................... 368<br />
getenv ............................................................. 369<br />
lseek ............................................................... 369<br />
open................................................................ 370<br />
read................................................................. 371<br />
remove............................................................ 371<br />
rename............................................................ 371<br />
sbrk ................................................................. 372<br />
sbrk ................................................. ................ 368, 372<br />
Các định dạng quét ................................................ ......... 225<br />
scanf ................................................. .............. 225, 259<br />
SCHAR_MAX ................................................. ........ 212<br />
SCHAR_MIN ................................................. ......... 212<br />
Chức năng tìm kiếm<br />
memchr ................................................. .......... 294<br />
strchr ................................................. .............. 301<br />
strcspn ................................................. ............ 304<br />
strpbrk ................................................. ............ 311<br />
strrchr ................................................. ............. 312<br />
strspn ................................................. ............. 313<br />
strstr ................................................. ............... 314<br />
strtok ................................................. .............. 315<br />
Thứ hai ............................................ 317, 318, 320 323<br />
Hạt giống ................................................. .............. 287, 289<br />
Tìm kiếm<br />
Từ lúc bắt đầu của tập tin .................................... 244<br />
Từ Chức vụ hiện nay ..................................... 244<br />
Từ End Of File ............................................. 244<br />
SEEK_CUR ................................................. ... 227, 244<br />
SEEK_END ................................................. ... 228, 244<br />
SEEK_SET ................................................. .... 228, 244<br />
setbuf ................................................. ..... 225, 226, 261<br />
SetCGRamAddr ................................................. ...... 78<br />
SetChanADC10 ................................................. ..... 106<br />
SetChanADC12 ................................................. ....... 99<br />
SetDCMCPWM ................................................. ..... 175<br />
SetDCOCxPWM ................................................. 137 ....<br />
SetDDRamAddr ................................................. ....... 78<br />
setjmp ................................................. .................... 214<br />
setjmp.h ............................................... ................... 214<br />
jmp_buf ................................................. .......... 214<br />
longjmp ................................................. ........... 214<br />
setjmp ................................................. ............. 214<br />
setlocale ................................................. ................ 213<br />
SetMCPWMDeadTimeAssignment ........................ 176<br />
SetMCPWMDeadTimeGeneration ......................... 177<br />
SetMCPWMFaultA ................................................. 178
system............................................................. 372<br />
time ................................................................. 373<br />
write ................................................................ 373<br />
Plus Sign ................................................................ 253<br />
Pointer, Temporary................................................ 287<br />
PORStatReset........................................................ 119<br />
pow......................................................................... 355<br />
power function<br />
Double Floating Point...................................... 355<br />
Single Floating Point ....................................... 356<br />
Power Functions<br />
pow ................................................................. 355<br />
powf ................................................................ 356<br />
powf........................................................................ 356<br />
precision................................................................. 253<br />
Prefix ...................................................................... 253<br />
prefix ...................................................................... 202<br />
Print Formats.......................................................... 225<br />
Printable Character<br />
Defined............................................................ 200<br />
Test for ............................................................ 200<br />
printf ............................................................... 225, 253<br />
Processor Clocks per Second................................ 317<br />
Processor Time .............................................. 317, 318<br />
Pseudo-Random Number .............................. 287, 289<br />
ptrdiff_t ................................................................... 223<br />
Punctuation Character<br />
Defined............................................................ 200<br />
Test for ............................................................ 200<br />
Pushed Back .......................................................... 265<br />
putc ........................................................................ 255<br />
putchar ................................................................... 256<br />
putcSPIx................................................................. 163<br />
putcUARTx............................................................. 147<br />
putrsXLCD................................................................ 76<br />
puts ........................................................................ 256<br />
putsSPIx................................................................. 162<br />
putsUARTx............................................................. 146<br />
putsXLCD................................................................. 76<br />
SetMCPWMFaultB ................................................. 179<br />
SetPointIntUxRX ................................................. 148 ...<br />
SetPriorityIntADC ........................................... 100, 107<br />
SetPriorityIntCANx ................................................. 92 ..<br />
SetPriorityIntDCI ................................................. 155 ....<br />
SetPriorityIntFLTA ................................................. . 181<br />
SetPriorityIntFLTB ................................................. . 181<br />
SetPriorityIntlCx .............................................. 129, 139<br />
Chỉ số<br />
2004 Microchip Technology Inc DS51456B trang 395<br />
SetPriorityIntMCPWM ............................................ 180<br />
SetPriorityIntMI2C ................................................. . 191<br />
SetPriorityIntQEI ................................................. 169 ...<br />
SetPriorityIntSI2C ................................................. . 191<br />
SetPriorityIntSPIx ................................................. 163 ..<br />
SetPriorityIntTx ................................................. ..... 116<br />
SetPriorityIntUxTX ................................................. 148<br />
SetPriorityIntx ................................................. ........ 124<br />
SetPulseOCx ................................................. ........ 138<br />
setvbuf ................................................. ... 225, 226, 262<br />
ngắn int<br />
Giá trị tối đa .............................................. 212<br />
Giá trị tối thiểu ............................................... 212<br />
SHRT_MAX ................................................. .......... 212<br />
SHRT_MIN ................................................. ............ 212<br />
sig_atomic_t ................................................. .......... 215<br />
SIG_DFL ................................................. ............... 215<br />
SIG_ERR ................................................. .............. 215<br />
SIG_IGN ................................................. ............... 215<br />
SIGABRT ................................................. .............. 216<br />
SIGFPE ................................................. ................. 216<br />
SIGILL ................................................. ................... 217<br />
SIGINT ................................................. .................. 217<br />
Tín hiệu<br />
Chấm dứt bất thường .................................... 216<br />
Lỗi ................................................. ............... 215<br />
Floating-Point Lỗi ......................................... 216<br />
Bỏ qua ................................................. ............. 215<br />
Hướng dẫn bất hợp pháp ............................................. 217
PverrideMCPWM ................................................... 174<br />
PWM Functions<br />
Close PWM ..................................................... 171<br />
Configure Override.......................................... 174<br />
Configure PWM............................................... 172<br />
Configure PWM Interrupt ................................ 171<br />
Example of Use............................................... 182<br />
Set PWM Dead Time Assignment .................. 176<br />
Set PWM Dead Time Generation ................... 177<br />
Set PWM Duty Cycle ...................................... 175<br />
Set PWM FaultA. ............................................ 178<br />
Set PWM FaultB. ............................................ 179<br />
PWM Macros<br />
Disable FLTA Interrupt.................................... 180<br />
Disable FLTB Interrupt.................................... 181<br />
Disable PWM Interrupt.................................... 180<br />
Enable FLTA Interrupt..................................... 180<br />
Enable FLTB Interrupt..................................... 181<br />
Enable PWM Interrupt..................................... 180<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 394 2004 Microchip Technology Inc.<br />
Set FLTA Interrupt Priority .............................. 181<br />
Set FLTB Interrupt Priority .............................. 181<br />
Set PWM Interrupt Priority .............................. 180<br />
Q<br />
QEI Functions<br />
Close QEI........................................................ 166<br />
Configure QEI ................................................. 167<br />
Configure QEI Interrupt................................... 166<br />
Example of Use............................................... 170<br />
Read QEI Position Count................................ 168<br />
Write QEI Position Count ................................ 169<br />
QEI Macros<br />
Disable QEI Interrupt ...................................... 169<br />
Enable QEI Interrupt ....................................... 169<br />
Set QEI Interrupt Priority ................................. 169<br />
qsort ............................................................... 276, 286<br />
Ngắt ................................................. ......... 217<br />
Báo cáo ................................................. ....... 219<br />
Yêu cầu chấm dứt ...................................... 218<br />
tín hiệu ............................................... 216, 217, 218, 220<br />
Tín hiệu Handler ................................................ 215, 220<br />
Tín hiệu Handler Loại .............................................. 215<br />
Xử lý tín hiệu, Seesignal.h<br />
signal.h ............................................... .................... 215<br />
nâng cao ................................................. ............... 219<br />
sig_atomic_t ................................................. 215 ...<br />
SIG_DFL ................................................. ........ 215<br />
SIG_ERR ................................................. ....... 215<br />
SIG_IGN ................................................. ........ 215<br />
SIGABRT ................................................. ....... 216<br />
SIGFPE ................................................. .......... 216<br />
SIGILL ................................................. ............ 217<br />
SIGINT ................................................. ........... 217<br />
tín hiệu ................................................. ............. 220<br />
SIGSEGV ................................................. ....... 218<br />
SIGTERM ................................................. ...... 218<br />
ký char<br />
Giá trị tối đa .............................................. 212<br />
Giá trị tối thiểu ............................................... 212<br />
SIGSEGV ................................................. .............. 218<br />
SIGTERM ................................................. .............. 218<br />
sim30 mô phỏng ................................................ ...... 366<br />
tội lỗi ................................................. ......................... 357<br />
sin<br />
Đôi Floating Point ..................................... 357<br />
Độc Floating Point ....................................... 358<br />
sinf ................................................. ........................ 358<br />
Độc chính xác dấu chấm động<br />
Máy Epsilon .............................................. 208<br />
Exponent tối đa (10 cơ sở) ........................ 208<br />
Exponent tối đa (cơ sở 2) .......................... 209<br />
Giá trị tối đa .............................................. 208<br />
Tối thiểu Exponent (10 cơ sở) ......................... 209<br />
Tối thiểu Exponent (cơ sở 2) ........................... 209<br />
Giá trị tối thiểu ............................................... 209
Quick Sort .............................................................. 286<br />
R<br />
Radix ...................................................................... 209<br />
raise ................................ 215, 216, 217, 218, 219, 220<br />
rand ................................................................ 287, 289<br />
RAND_MAX ................................................... 271, 287<br />
Range..................................................................... 260<br />
Range Error............................ 205, 291, 292, 335, 336,<br />
......................337, 338, 346, 348, 355, 356, 359, 360<br />
read ........................................................................ 371<br />
ReadADC10 ........................................................... 106<br />
ReadADC12 ............................................................. 99<br />
ReadAddrXLCD ....................................................... 77<br />
ReadCapture.......................................................... 128<br />
ReadDataXLCD ....................................................... 77<br />
ReadDCI ................................................................ 154<br />
ReadDCOCxPWM.................................................. 135<br />
Reading, Recommended............................................ 4<br />
ReadQEI ................................................................ 168<br />
ReadRegOCx ......................................................... 136<br />
ReadSPIx ............................................................... 159<br />
ReadTimerx............................................................ 113<br />
ReadTimerxx .......................................................... 114<br />
ReadUARTx ........................................................... 145<br />
realloc............................................................. 281, 287<br />
Reallocate Memory ................................................ 287<br />
Rebuilding the libpic30 library ................................ 366<br />
Registered Functions..................................... 272, 280<br />
remainder<br />
Double Floating Point...................................... 341<br />
Single Floating Point ....................................... 343<br />
Remainder Functions<br />
fmod ................................................................ 341<br />
fmodf ............................................................... 343<br />
remove ........................................................... 257, 371<br />
rename ........................................................... 257, 371<br />
Reset.............................................................. 271, 293<br />
Reset File Pointer................................................... 258<br />
Reset/Control Functions<br />
Số chữ số nhị phân .................................. 208<br />
Số thập phân chữ số ............................... 208<br />
sinh ................................................. ........................ 359<br />
sinhf ................................................. ....................... 360<br />
kích thước ................................................. ........................ 254<br />
size_t ....................................... 223, 226, 270, 294, 317<br />
sizeof ....................................... 223, 226, 270, 294, 317<br />
SlavegetsI2C ................................................. ......... 188<br />
SlaveputsI2C ................................................. ......... 189<br />
SlaveReadI2C ................................................. ....... 189<br />
SlaveWriteI2C ................................................. ....... 189<br />
Sắp xếp, nhanh ............................................... .............. 286<br />
Source File Name ............................................... 195 ...<br />
Nguồn dòng Số .............................................. 195<br />
Không gian ................................................. .................... 253<br />
Không gian nhân vật<br />
Xác định ................................................. ........... 201<br />
Kiểm tra cho ................................................ ............ 201<br />
Specifiers ................................................. ...... 253, 259<br />
Chức năng SPI<br />
Đóng SPI ................................................ ........ 158<br />
Cấu hình SPI ................................................ 160 ..<br />
Cấu hình SPI ngắt ................................... 158<br />
Ví dụ sử dụng ............................................... 164<br />
Đọc SPI RX đệm ........................................ 159<br />
SPI đệm trạng ............................................ 159<br />
SPI Get nhân vật ........................................... 163<br />
SPI Nhận Chuỗi ............................................... 162 ..<br />
SPI Đặt nhân vật ........................................... 163<br />
SPI Đặt chuỗi ............................................... 162 ..<br />
Viết SPI TX đệm ......................................... 160<br />
SPI Macros<br />
Vô hiệu hóa ngắt SPI ....................................... 163<br />
Kích hoạt tính năng SPI ngắt ........................................ 163<br />
Đặt ưu tiên ngắt SPI ................................. 163<br />
sprintf ................................................. ............ 225, 263<br />
sqrt ................................................. ........................ 361<br />
sqrtf ................................................. ....................... 362<br />
chức năng căn bậc hai
Low Voltage Detect......................................... 117<br />
Master Clear Reset......................................... 118<br />
Reset from Brown-out ..................................... 117<br />
Reset from Power-on...................................... 117<br />
Wake-up from Sleep ....................................... 119<br />
Watchdog Timer Time-out............................... 118<br />
Watchdog Timer Wake-up .............................. 118<br />
Reset/Control Macros<br />
Disable All Interrupts ....................................... 119<br />
Disable Watchdog Timer ................................. 120<br />
Enable Watchdog Timer.................................. 120<br />
Reset BOR bit ................................................. 119<br />
Reset POR bit ................................................. 119<br />
RestartI2C .............................................................. 188<br />
rewind..................................................... 258, 265, 369<br />
Rounding Mode ...................................................... 209<br />
S<br />
sbrk................................................................. 368, 372<br />
Scan Formats ......................................................... 225<br />
scanf............................................................... 225, 259<br />
SCHAR_MAX ......................................................... 212<br />
SCHAR_MIN .......................................................... 212<br />
Search Functions<br />
memchr ........................................................... 294<br />
strchr ............................................................... 301<br />
strcspn............................................................. 304<br />
strpbrk ............................................................. 311<br />
strrchr .............................................................. 312<br />
strspn .............................................................. 313<br />
strstr ................................................................ 314<br />
strtok ............................................................... 315<br />
Second ............................................317, 318, 320, 323<br />
Seed ............................................................... 287, 289<br />
Seek<br />
From Beginning of File .................................... 244<br />
From Current Position ..................................... 244<br />
From End Of File............................................. 244<br />
SEEK_CUR .................................................... 227, 244<br />
SEEK_END .................................................... 228, 244<br />
Đôi Floating Point ...................................... 361<br />
Độc Floating Point ....................................... 362<br />
Chức năng gốc vuông<br />
sqrt ................................................. ................. 361<br />
sqrtf ................................................. ................ 362<br />
srand ................................................. ..................... 289<br />
sscanf ................................................. ............ 225, 263<br />
Ngăn xếp ................................................. ..................... 368<br />
Thư viện chuẩn C ............................................... 193 ..<br />
Tiêu chuẩn C Locale ............................................... 196 ..<br />
Chuẩn Lỗi ................................................ 225, 228<br />
Tiêu chuẩn đầu vào ................................................ 225, 228<br />
Đầu ra tiêu chuẩn ............................................. 225, 228<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 396 2004 Microchip Technology Inc<br />
StartI2C ................................................. ................. 190<br />
Startup ................................................. ................... 225<br />
Module, thay thế ............................................... . 8<br />
Module, tiểu học ............................................... 8 ...<br />
stdarg.h ............................................... ................... 221<br />
va_arg ................................................. ............ 221<br />
va_end ................................................. ........... 223<br />
va_list ................................................. ............. 221<br />
va_start ................................................. .......... 223<br />
stddef.h ............................................... ................... 223<br />
NULL ................................................. .............. 223<br />
offsetof ................................................. ........... 224<br />
ptrdiff_t ................................................. ........... 223<br />
size_t ................................................. .............. 223<br />
wchar_t ................................................. .......... 223<br />
stderr ....................................... 195, 225, 227, 228, 252<br />
stdin ......................................... 225, 227, 228, 251, 259<br />
stdio.h ............................................... .............. 225, 371<br />
_IOFBF ................................................. .......... 226<br />
_IOLBF ................................................. ........... 226<br />
_IONBF ................................................. .......... 226<br />
BUFSIZ ................................................. .......... 226
SEEK_SET..................................................... 228, 244<br />
setbuf...................................................... 225, 226, 261<br />
SetCGRamAddr ....................................................... 78<br />
SetChanADC10...................................................... 106<br />
SetChanADC12........................................................ 99<br />
SetDCMCPWM ...................................................... 175<br />
SetDCOCxPWM..................................................... 137<br />
SetDDRamAddr........................................................ 78<br />
setjmp..................................................................... 214<br />
setjmp.h.................................................................. 214<br />
jmp_buf ........................................................... 214<br />
longjmp............................................................ 214<br />
setjmp.............................................................. 214<br />
setlocale ................................................................. 213<br />
SetMCPWMDeadTimeAssignment ........................ 176<br />
SetMCPWMDeadTimeGeneration ......................... 177<br />
SetMCPWMFaultA ................................................. 178<br />
SetMCPWMFaultB ................................................. 179<br />
SetPointIntUxRX .................................................... 148<br />
SetPriorityIntADC ........................................... 100, 107<br />
SetPriorityIntCANx ................................................... 92<br />
SetPriorityIntDCI..................................................... 155<br />
SetPriorityIntFLTA .................................................. 181<br />
SetPriorityIntFLTB .................................................. 181<br />
SetPriorityIntlCx.............................................. 129, 139<br />
Index<br />
2004 Microchip Technology Inc. DS51456B-page 395<br />
SetPriorityIntMCPWM............................................ 180<br />
SetPriorityIntMI2C.................................................. 191<br />
SetPriorityIntQEI .................................................... 169<br />
SetPriorityIntSI2C .................................................. 191<br />
SetPriorityIntSPIx ................................................... 163<br />
SetPriorityIntTx ...................................................... 116<br />
SetPriorityIntUxTX ................................................. 148<br />
SetPriorityIntx......................................................... 124<br />
SetPulseOCx ......................................................... 138<br />
setvbuf ....................................................225, 226, 262<br />
short int<br />
Maximum Value .............................................. 212<br />
clearerr ................................................. ........... 229<br />
EOF ................................................. ................ 227<br />
fclose ................................................. .............. 230<br />
feof ................................................. ................. 231<br />
ferror ................................................. .............. 232<br />
fflush ................................................. .............. 233<br />
fgetc ................................................. ............... 233<br />
fgetpos ................................................. ........... 234<br />
fgets ................................................. ............... 235<br />
FILE ................................................. ............... 226<br />
FILENAME_MAX ............................................ 227<br />
fopen ................................................. .............. 236<br />
FOPEN_MAX ................................................. . 227<br />
fpos_t ................................................. ............. 226<br />
fprintf ................................................. .............. 238<br />
fputc ................................................. ............... 239<br />
fputs ................................................. ............... 239<br />
fread ................................................. ............... 240<br />
freopen ................................................. ........... 242<br />
fscanf ................................................. ............. 242<br />
fseek ................................................. .............. 244<br />
fsetpos ................................................. ........... 245<br />
ftell ................................................. ................. 247<br />
fwrite ................................................. .............. 248<br />
getc ................................................. ................ 250<br />
getchar ................................................. ........... 251<br />
được ................................................. ................ 251<br />
L_tmpnam ................................................. ...... 227<br />
NULL ................................................. .............. 227<br />
perror ................................................. ............. 252<br />
printf ................................................. ............... 253<br />
putc ................................................. ................ 255<br />
putchar ................................................. ........... 256<br />
đặt ................................................. ................ 256<br />
loại bỏ ................................................. ........... 257<br />
đổi tên ................................................. ........... 257<br />
tua lại ................................................. ............ 258<br />
scanf ................................................. .............. 259<br />
SEEK_CUR ................................................. 227 ....
Minimum Value ............................................... 212<br />
SHRT_MAX ........................................................... 212<br />
SHRT_MIN............................................................. 212<br />
sig_atomic_t........................................................... 215<br />
SIG_DFL ................................................................ 215<br />
SIG_ERR ............................................................... 215<br />
SIG_IGN ................................................................ 215<br />
SIGABRT ............................................................... 216<br />
SIGFPE.................................................................. 216<br />
SIGILL.................................................................... 217<br />
SIGINT ................................................................... 217<br />
Signal<br />
Abnormal Termination .................................... 216<br />
Error ................................................................ 215<br />
Floating-Point Error......................................... 216<br />
Ignore.............................................................. 215<br />
Illegal Instruction............................................. 217<br />
Interrupt .......................................................... 217<br />
Reporting ........................................................ 219<br />
Termination Request...................................... 218<br />
signal............................................... 216, 217, 218, 220<br />
Signal Handler ................................................215, 220<br />
Signal Handler Type .............................................. 215<br />
Signal Handling, Seesignal.h<br />
signal.h................................................................... 215<br />
raise ................................................................ 219<br />
sig_atomic_t.................................................... 215<br />
SIG_DFL......................................................... 215<br />
SIG_ERR ........................................................ 215<br />
SIG_IGN ......................................................... 215<br />
SIGABRT ........................................................ 216<br />
SIGFPE........................................................... 216<br />
SIGILL............................................................. 217<br />
SIGINT............................................................ 217<br />
signal .............................................................. 220<br />
SIGSEGV........................................................ 218<br />
SIGTERM ....................................................... 218<br />
signed char<br />
Maximum Value .............................................. 212<br />
SEEK_END ................................................. 228 ....<br />
SEEK_SET ................................................. ..... 228<br />
setbuf ................................................. ............. 261<br />
setvbuf ................................................. ............ 262<br />
size_t ................................................. .............. 226<br />
sprintf ................................................. ............. 263<br />
sscanf ................................................. ............. 263<br />
stderr ................................................. .............. 228<br />
stdin ................................................. ................ 228<br />
thiết bị xuất chuẩn ................................................. ............. 228<br />
TMP_MAX ................................................. ...... 228<br />
tmpfile ................................................. ............. 264<br />
tmpnam ................................................. .......... 265<br />
ungetc ................................................. ............ 265<br />
vfprintf ................................................. ............ 267<br />
vprintf ................................................. ............. 268<br />
vsprintf ................................................. ............ 269<br />
stdlib.h ............................................... ..... 270, 369, 372<br />
hủy bỏ ................................................. ............... 271<br />
abs ................................................. ................. 272<br />
atexit ................................................. ............... 272<br />
atof ................................................. ................. 274<br />
atoi ................................................. ................. 275<br />
atol ................................................. ................. 275<br />
bsearch ................................................. .......... 276<br />
calloc ................................................. .............. 278<br />
div ................................................. ................... 278<br />
div_t ................................................. ................ 270<br />
thoát ................................................. .................. 280<br />
EXIT_FAILURE ............................................... 270<br />
EXIT_SUCCESS ............................................. 270<br />
................................................. miễn phí ................. 281<br />
getenv ................................................. ............ 281<br />
phòng thí nghiệm ................................................. ................. 282<br />
ldiv ................................................. .................. 283<br />
ldiv_t ................................................. ............... 270<br />
malloc ................................................. ............. 284<br />
MB_CUR_MAX ............................................... 271<br />
mblen ................................................. ............. 285
Minimum Value ............................................... 212<br />
SIGSEGV............................................................... 218<br />
SIGTERM............................................................... 218<br />
sim30 simulator ...................................................... 366<br />
sin .......................................................................... 357<br />
sine<br />
Double Floating Point ..................................... 357<br />
Single Floating Point....................................... 358<br />
sinf ......................................................................... 358<br />
Single Precision Floating Point<br />
Machine Epsilon.............................................. 208<br />
Maximum Exponent (base 10) ........................ 208<br />
Maximum Exponent (base 2) .......................... 209<br />
Maximum Value .............................................. 208<br />
Minimum Exponent (base 10) ......................... 209<br />
Minimum Exponent (base 2) ........................... 209<br />
Minimum Value ............................................... 209<br />
Number of Binary Digits .................................. 208<br />
Number of Decimal Digits ............................... 208<br />
sinh......................................................................... 359<br />
sinhf........................................................................ 360<br />
size......................................................................... 254<br />
size_t....................................... 223, 226, 270, 294, 317<br />
sizeof....................................... 223, 226, 270, 294, 317<br />
SlavegetsI2C.......................................................... 188<br />
SlaveputsI2C.......................................................... 189<br />
SlaveReadI2C ........................................................ 189<br />
SlaveWriteI2C ........................................................ 189<br />
Sort, Quick ............................................................. 286<br />
Source File Name .................................................. 195<br />
Source Line Number .............................................. 195<br />
Space ..................................................................... 253<br />
Space Character<br />
Defined............................................................ 201<br />
Test for ............................................................ 201<br />
Specifiers ....................................................... 253, 259<br />
SPI Functions<br />
Close SPI ........................................................ 158<br />
Configure SPI.................................................. 160<br />
mbstowcs ................................................. ....... 285<br />
mbtowc ................................................. ........... 285<br />
NULL ................................................. .............. 271<br />
qsort ................................................. ............... 286<br />
rand ................................................. ................ 287<br />
RAND_MAX ................................................. 271 ...<br />
realloc ................................................. ............. 287<br />
size_t ................................................. .............. 270<br />
srand ................................................. .............. 289<br />
strtod ................................................. .............. 289<br />
strtol ................................................. ............... 291<br />
strtoul ................................................. ............. 292<br />
hệ thống ................................................. ............ 293<br />
wchar_t ................................................. ........... 270<br />
wctomb ................................................. ........... 293<br />
wxstombs ................................................. ....... 293<br />
thiết bị xuất chuẩn ....................................... 225, 227, 228, 253, 256<br />
StopI2C ................................................. ................. 190<br />
StopSampADC10 ................................................. 106 ..<br />
StopSampADC12 ................................................. 99 ....<br />
Chỉ số<br />
2004 Microchip Technology Inc DS51456B trang 397<br />
strcat ................................................. ..................... 300<br />
strchr ................................................. ..................... 301<br />
strcmp ................................................. ................... 302<br />
strcoll ................................................. ..................... 303<br />
strcpy ................................................. .................... 303<br />
strcspn ................................................. .................. 304<br />
Suối ................................................. ................. 225<br />
................................................. Nhị phân ............. 225<br />
Đệm ................................................. ........ 262<br />
Đóng ................................................. .... 230, 280<br />
Mở ................................................. ......... 236<br />
Đọc Từ ................................................ . 250<br />
Văn bản ................................................. ................ 225<br />
Viết Để ................................................ 248, 255<br />
dột ................................................. .................. 305<br />
strftime ................................................. .................. 322<br />
Chuỗi
Configure SPI Interrupt ................................... 158<br />
Example of Use............................................... 164<br />
Read SPI RX Buffer ........................................ 159<br />
SPI Buffer Status ............................................ 159<br />
SPI Get Character........................................... 163<br />
SPI Get String ................................................. 162<br />
SPI Put Character........................................... 163<br />
SPI Put String ................................................. 162<br />
Write SPI TX Buffer......................................... 160<br />
SPI Macros<br />
Disable SPI Interrupt....................................... 163<br />
Enable SPI Interrupt........................................ 163<br />
Set SPI Interrupt Priority ................................. 163<br />
sprintf ............................................................. 225, 263<br />
sqrt ......................................................................... 361<br />
sqrtf ........................................................................ 362<br />
square root function<br />
Double Floating Point...................................... 361<br />
Single Floating Point ....................................... 362<br />
Square Root Functions<br />
sqrt .................................................................. 361<br />
sqrtf ................................................................. 362<br />
srand ...................................................................... 289<br />
sscanf............................................................. 225, 263<br />
Stack ...................................................................... 368<br />
Standard C Library................................................. 193<br />
Standard C Locale ................................................. 196<br />
Standard Error................................................ 225, 228<br />
Standard Input................................................ 225, 228<br />
Standard Output............................................. 225, 228<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 396 2004 Microchip Technology Inc.<br />
StartI2C .................................................................. 190<br />
Startup.................................................................... 225<br />
Module, Alternate................................................ 8<br />
Module, Primary .................................................. 8<br />
stdarg.h .................................................................. 221<br />
Chiều dài ................................................. ............ 305<br />
Tìm kiếm ................................................. ........... 314<br />
Chuyển đổi ................................................. ...... 316<br />
Chức năng String, Seestring.h<br />
string.h ............................................... .................... 294<br />
memchr ................................................. .......... 294<br />
memcmp ................................................. ........ 295<br />
memcpy ................................................. ......... 297<br />
memmove ................................................. ...... 298<br />
memset ................................................. .......... 299<br />
NULL ................................................. .............. 294<br />
size_t ................................................. ............. 294<br />
strcat ................................................. .............. 300<br />
strchr ................................................. .............. 301<br />
strcmp ................................................. ............ 302<br />
strcoll ................................................. ............. 303<br />
strcpy ................................................. ............. 303<br />
strcspn ................................................. ........... 304<br />
dột ................................................. ........... 305<br />
strlen ................................................. .............. 305<br />
strncat ................................................. ............ 306<br />
strncmp ................................................. .......... 308<br />
strncpy ................................................. ........... 309<br />
strpbrk ................................................. ............ 311<br />
strrchr ................................................. ............. 312<br />
strspn ................................................. ............. 313<br />
strstr ................................................. ............... 314<br />
strtok ................................................. .............. 315<br />
strxfrm ................................................. ............ 316<br />
strlen ................................................. ..................... 305<br />
strncat ................................................. ................... 306<br />
strncmp ................................................. ................. 308<br />
strncpy ................................................. .................. 309<br />
strpbrk ................................................. ................... 311<br />
strrchr ................................................. .................... 312<br />
strspn ................................................. .................... 313<br />
strstr ................................................. ...................... 314<br />
strtod ................................................. .............. 274, 289<br />
strtok ................................................. ..................... 315
va_arg ............................................................. 221<br />
va_end ............................................................ 223<br />
va_list.............................................................. 221<br />
va_start ........................................................... 223<br />
stddef.h .................................................................. 223<br />
NULL............................................................... 223<br />
offsetof ............................................................ 224<br />
ptrdiff_t ............................................................ 223<br />
size_t............................................................... 223<br />
wchar_t ........................................................... 223<br />
stderr ....................................... 195, 225, 227, 228, 252<br />
stdin......................................... 225, 227, 228, 251, 259<br />
stdio.h............................................................. 225, 371<br />
_IOFBF ........................................................... 226<br />
_IOLBF............................................................ 226<br />
_IONBF ........................................................... 226<br />
BUFSIZ ........................................................... 226<br />
clearerr ............................................................ 229<br />
EOF................................................................. 227<br />
fclose............................................................... 230<br />
feof .................................................................. 231<br />
ferror ............................................................... 232<br />
fflush ............................................................... 233<br />
fgetc ................................................................ 233<br />
fgetpos ............................................................ 234<br />
fgets ................................................................ 235<br />
FILE ................................................................ 226<br />
FILENAME_MAX ............................................ 227<br />
fopen ............................................................... 236<br />
FOPEN_MAX.................................................. 227<br />
fpos_t .............................................................. 226<br />
fprintf ............................................................... 238<br />
fputc ................................................................ 239<br />
fputs ................................................................ 239<br />
fread................................................................ 240<br />
freopen............................................................ 242<br />
fscanf .............................................................. 242<br />
fseek ............................................................... 244<br />
fsetpos ............................................................ 245<br />
strtol ................................................. ............... 275, 291<br />
strtoul ................................................. .................... 292<br />
cấu trúc lconv ................................................ ............. 213<br />
struct tm ................................................ ................. 317<br />
strxfrm ................................................. ................... 316<br />
Chuỗi con ................................................. ............. 315<br />
Con trỏ trừ ............................................... 223<br />
Chấm dứt thành công .......................................... 270<br />
hệ thống ................................................. ........... 293, 372<br />
T<br />
Tab ................................................. ........................ 201<br />
tan ................................................. ......................... 363<br />
TANF ................................................. ........................ 363<br />
tiếp tuyến<br />
Đôi Floating Point ...................................... 363<br />
Độc Floating Point ....................................... 363<br />
tanh ................................................. ....................... 364<br />
tanhf ................................................. ...................... 365<br />
Tạm thời<br />
Tập ................................................. ......... 264, 280<br />
Tên tập tin ................................................. 227, 265<br />
Pointer ................................................. ............ 287<br />
Chấm dứt<br />
Yêu cầu nhắn ........................................... 218<br />
Yêu cầu tín hiệu ................................................ 218<br />
................................................. Thành công ...... 270<br />
................................................. Không thành công 270 ..<br />
Chế độ văn bản ................................................ .............. 236<br />
Văn bản Streams ................................................ .......... 225<br />
Bọ ve ................................................. ....... 317, 318, 320<br />
Hiện ................................................. ............... 324, 373<br />
Thời gian khác biệt ................................................ ...... 320<br />
Cơ cấu thời gian ................................................ 317, 322<br />
Time Zone ................................................ .............. 323<br />
time.h ............................................... .............. 317, 373<br />
asctime ................................................. ........... 318<br />
đồng hồ ................................................. ............... 318<br />
clock_t ................................................. ............ 317<br />
CLOCKS_PER_SEC ...................................... 317
ftell .................................................................. 247<br />
fwrite ............................................................... 248<br />
getc ................................................................. 250<br />
getchar ............................................................ 251<br />
gets ................................................................. 251<br />
L_tmpnam ....................................................... 227<br />
NULL............................................................... 227<br />
perror .............................................................. 252<br />
printf ................................................................ 253<br />
putc ................................................................. 255<br />
putchar ............................................................ 256<br />
puts ................................................................. 256<br />
remove ............................................................ 257<br />
rename............................................................ 257<br />
rewind ............................................................. 258<br />
scanf ............................................................... 259<br />
SEEK_CUR..................................................... 227<br />
SEEK_END ..................................................... 228<br />
SEEK_SET...................................................... 228<br />
setbuf .............................................................. 261<br />
setvbuf............................................................. 262<br />
size_t............................................................... 226<br />
sprintf .............................................................. 263<br />
sscanf.............................................................. 263<br />
stderr ............................................................... 228<br />
stdin................................................................. 228<br />
stdout .............................................................. 228<br />
TMP_MAX....................................................... 228<br />
tmpfile.............................................................. 264<br />
tmpnam ........................................................... 265<br />
ungetc ............................................................. 265<br />
vfprintf ............................................................. 267<br />
vprintf .............................................................. 268<br />
vsprintf............................................................. 269<br />
stdlib.h .................................................... 270, 369, 372<br />
abort ................................................................ 271<br />
abs .................................................................. 272<br />
atexit................................................................ 272<br />
atof .................................................................. 274<br />
ctime ................................................. .............. 319<br />
difftime ................................................. ........... 320<br />
gmtime ................................................. ........... 320<br />
localtime ................................................. ......... 321<br />
mktime ................................................. ........... 322<br />
NULL ................................................. .............. 318<br />
size_t ................................................. .............. 317<br />
strftime ................................................. ........... 322<br />
struct tm ................................................ .......... 317<br />
Hiện ................................................. ................ 324<br />
time_t ................................................. ............. 317<br />
time_t ................................................. ..... 317, 322, 324<br />
Chức năng hẹn giờ<br />
Đóng ................................................. .............. 109<br />
Đóng cửa 32-bit .............................................. ....... 109<br />
Cấu hình ngắt .......................................... 110<br />
Cấu hình ngắt 32-bit ................................ 111<br />
Ví dụ sử dụng ............................................... 116<br />
Mở ................................................. .............. 111<br />
Mở cửa 32-bit .............................................. ....... 112<br />
Đọc ................................................. .............. 113<br />
Đọc 32-bit .............................................. ....... 114<br />
Viết ................................................. ............... 114<br />
Viết 32-bit .............................................. ........ 115<br />
dsPIC<br />
®<br />
Thư viện Công cụ Ngôn ngữ<br />
DS51456B trang 398 2004 Microchip Technology Inc<br />
Thơi gian Macros<br />
Vô hiệu hóa ngắt .............................................. 115<br />
Kích hoạt tính năng ngắt .............................................. 115<br />
Thiết lập ngắt ưu tiên ........................................ 116<br />
TMP_MAX ................................................. ............. 228<br />
tmpfile ................................................. .................... 264<br />
tmpnam ................................................. ................. 265<br />
Thẻ ................................................. .................. 315<br />
ToLower ................................................. ................... 203<br />
toupper ................................................. .................. 204<br />
Chuyển điều khiển ............................................... 214
atoi .................................................................. 275<br />
atol .................................................................. 275<br />
bsearch ........................................................... 276<br />
calloc ............................................................... 278<br />
div.................................................................... 278<br />
div_t................................................................. 270<br />
exit................................................................... 280<br />
EXIT_FAILURE ............................................... 270<br />
EXIT_SUCCESS............................................. 270<br />
free .................................................................. 281<br />
getenv ............................................................. 281<br />
labs.................................................................. 282<br />
ldiv................................................................... 283<br />
ldiv_t................................................................ 270<br />
malloc.............................................................. 284<br />
MB_CUR_MAX ............................................... 271<br />
mblen .............................................................. 285<br />
mbstowcs ........................................................ 285<br />
mbtowc............................................................ 285<br />
NULL ............................................................... 271<br />
qsort ................................................................ 286<br />
rand ................................................................. 287<br />
RAND_MAX .................................................... 271<br />
realloc.............................................................. 287<br />
size_t............................................................... 270<br />
srand ............................................................... 289<br />
strtod ............................................................... 289<br />
strtol ................................................................ 291<br />
strtoul .............................................................. 292<br />
system............................................................. 293<br />
wchar_t............................................................ 270<br />
wctomb............................................................ 293<br />
wxstombs ........................................................ 293<br />
stdout.......................................225, 227, 228, 253, 256<br />
StopI2C .................................................................. 190<br />
StopSampADC10 ................................................... 106<br />
StopSampADC12 ..................................................... 99<br />
Index<br />
2004 Microchip Technology Inc. DS51456B-page 397<br />
Chuyển đổi chức năng ................................................ 58<br />
BitReverseComplex .......................................... 60<br />
CosFactorInit ................................................. 61 ....<br />
DCT ................................................. .................. 61<br />
DCTIP ................................................. .............. 63<br />
FFTComplex ................................................. 64 ....<br />
FFTComplexIP ................................................. . 66<br />
IFFTComplex ................................................. 67 ...<br />
IFFTComplexIP ................................................. 69<br />
TwidFactorInit ................................................. 70 ..<br />
Chuyển đổi chuỗi ................................................ ..... 316<br />
Chức năng lượng giác<br />
acos ................................................. ............... 325<br />
acosf ................................................. .............. 326<br />
asin ................................................. ................ 327<br />
asinf ................................................. ............... 327<br />
atan ................................................. ................ 328<br />
atan2 ................................................. .............. 329<br />
atan2f ................................................. ............. 331<br />
atanf ................................................. ............... 329<br />
cos ................................................. ................. 333<br />
cosf ................................................. ................ 334<br />
tội lỗi ................................................. .................. 357<br />
sinf ................................................. ................. 358<br />
tan ................................................. .................. 363<br />
TANF ................................................. ................. 363<br />
TwidFactorInit ................................................. .......... 70<br />
gõ ................................................. ............... 254, 260<br />
U<br />
Chức năng UART<br />
Đóng UART. .................................................. . 141<br />
Cấu hình UART .............................................. 143<br />
Cấu hình UART ngắt ............................... 142<br />
Ví dụ sử dụng ............................................... 149<br />
Đọc UART ................................................ ..... 145<br />
UART đệm trạng ........................................ 143<br />
UART Nhận vật ....................................... 147<br />
Nhận UART chuỗi ............................................. 146<br />
UART Đặt nhân vật ....................................... 147
strcat ...................................................................... 300<br />
strchr ...................................................................... 301<br />
strcmp .................................................................... 302<br />
strcoll...................................................................... 303<br />
strcpy ..................................................................... 303<br />
strcspn ................................................................... 304<br />
Streams.................................................................. 225<br />
Binary.............................................................. 225<br />
Buffering ......................................................... 262<br />
Closing.....................................................230, 280<br />
Opening .......................................................... 236<br />
Reading From ................................................. 250<br />
Text................................................................. 225<br />
Writing To ................................................248, 255<br />
strerror ................................................................... 305<br />
strftime ................................................................... 322<br />
String<br />
Length............................................................. 305<br />
Search ............................................................ 314<br />
Transform ....................................................... 316<br />
String Functions, Seestring.h<br />
string.h ................................................................... 294<br />
memchr ........................................................... 294<br />
memcmp ......................................................... 295<br />
memcpy .......................................................... 297<br />
memmove ....................................................... 298<br />
memset ........................................................... 299<br />
NULL............................................................... 294<br />
size_t .............................................................. 294<br />
strcat ............................................................... 300<br />
strchr ............................................................... 301<br />
strcmp ............................................................. 302<br />
strcoll .............................................................. 303<br />
strcpy .............................................................. 303<br />
strcspn ............................................................ 304<br />
strerror ............................................................ 305<br />
strlen ............................................................... 305<br />
strncat ............................................................. 306<br />
strncmp ........................................................... 308<br />
UART Đặt chuỗi ............................................. 146<br />
UART Tình trạng ................................................ 141 ...<br />
Viết UART ................................................ ..... 145<br />
UART Macros<br />
Vô hiệu hoá UART RX ngắt ............................. 147<br />
Vô hiệu hoá UART TX ngắt ............................. 148<br />
Kích hoạt tính năng ngắt UART RX .............................. 147<br />
Kích hoạt tính năng ngắt UART TX .............................. 147<br />
Đặt ưu tiên UART RX ngắt ....................... 148<br />
Đặt ưu tiên UART TX ngắt ........................ 148<br />
UCHAR_MAX ................................................. ........ 213<br />
UINT_MAX ................................................. ............ 213<br />
ULLONG_MAX ................................................. ...... 213<br />
ULONG_MAX ................................................. ........ 213<br />
Lỗi Van cân bằng .................................... 205, 325, 337,<br />
............................................. 338, 346, 348 , 355, 356<br />
ungetc ................................................. .................... 265<br />
Universal Time Coordinated ................................... 320<br />
unsigned char<br />
Giá trị tối đa .............................................. 213<br />
int<br />
Giá trị tối đa .............................................. 213<br />
unsigned short int<br />
Giá trị tối đa .............................................. 213<br />
Chấm dứt không thành công ...................................... 270<br />
Upper Case chữ cái ký tự<br />
Để chuyển đổi ................................................ ...... 204<br />
Xác định ................................................. ........... 202<br />
Kiểm tra cho ................................................ ............ 202<br />
USHRT_MAX ................................................. ........ 213<br />
UTC ................................................. ....................... 320<br />
Các chức năng tiện ích, Seestdlib.h<br />
V<br />
va_arg ..................................... 221, 223, 267, 268, 269<br />
va_end ............................................. 223, 267, 268, 269<br />
va_list ................................................. .................... 221<br />
va_start ............................................ 223, 267, 268 , 269<br />
Danh sách Đối số biến, Seestdarg.h<br />
Variable Length Danh sách Đối số ...................... 221, 223,
strncpy ............................................................ 309<br />
strpbrk ............................................................. 311<br />
strrchr.............................................................. 312<br />
strspn .............................................................. 313<br />
strstr ................................................................ 314<br />
strtok ............................................................... 315<br />
strxfrm............................................................. 316<br />
strlen ...................................................................... 305<br />
strncat .................................................................... 306<br />
strncmp .................................................................. 308<br />
strncpy ................................................................... 309<br />
strpbrk .................................................................... 311<br />
strrchr ..................................................................... 312<br />
strspn ..................................................................... 313<br />
strstr ....................................................................... 314<br />
strtod ...............................................................274, 289<br />
strtok ...................................................................... 315<br />
strtol ................................................................275, 291<br />
strtoul ..................................................................... 292<br />
struct lconv ............................................................. 213<br />
struct tm ................................................................. 317<br />
strxfrm .................................................................... 316<br />
Substrings .............................................................. 315<br />
Subtracting Pointers............................................... 223<br />
Successful Termination.......................................... 270<br />
system............................................................ 293, 372<br />
T<br />
Tab ......................................................................... 201<br />
tan .......................................................................... 363<br />
tanf ......................................................................... 363<br />
tangent<br />
Double Floating Point...................................... 363<br />
Single Floating Point ....................................... 363<br />
tanh ........................................................................ 364<br />
tanhf ....................................................................... 365<br />
Temporary<br />
File .......................................................... 264, 280<br />
Filename ................................................. 227, 265<br />
Pointer............................................................. 287<br />
.................................................. .......... 267, 268, 269<br />
Chức năng Vector ................................................ ...... 13<br />
VectorAdd ................................................. ................ 15<br />
VectorConvolve ................................................. ....... 16<br />
VectorCopy ................................................. .............. 17<br />
VectorCorrelate ................................................. ....... 18<br />
VectorDotProduct ................................................. 19 ....<br />
VectorMax ................................................. ............... 19<br />
VectorMin ................................................. ................ 20<br />
VectorMultiply ................................................. .......... 21<br />
VectorNegate ................................................. .......... 21<br />
VectorPower ................................................. ............ 22<br />
VectorScale ................................................. ............. 23<br />
VectorSubtract ................................................. ......... 23<br />
VectorWindow ................................................. ......... 29<br />
VectorZeroPad ................................................. ........ 24<br />
VERBOSE_DEBUGGING ...................................... 195<br />
Vertical Tab ................................................ ............ 201<br />
vfprintf ................................................. ............ 225, 267<br />
vprintf ................................................. ............. 225, 268<br />
vsprintf ................................................. ........... 225, 269<br />
W<br />
wchar_t ................................................. .......... 223, 270<br />
wcstombs ................................................. .............. 293<br />
wctomb ................................................. .................. 293<br />
WDTSWDisable ................................................. 120 ....<br />
WDTSWEnable ................................................. ..... 120<br />
Tuần ................................................. ..................... 323<br />
Không gian trắng .................................... 259, 274, 275, 289<br />
Chỉ số<br />
2004 Microchip Technology Inc DS51456B trang 399<br />
Trắng không gian nhân vật<br />
Xác định ................................................. .......... 201<br />
Kiểm tra cho ................................................ ............ 201<br />
................................................. rộng ....................... 270<br />
Character rộng ............................................... 285 , 293<br />
Rộng chuỗi ký tự ..................................... 285, 293<br />
Wide nhân vật Giá trị ............................................ 223<br />
Chiều rộng ................................................. ..................... 253
Termination<br />
Request Message ........................................... 218<br />
Request Signal................................................ 218<br />
Successful....................................................... 270<br />
Unsuccessful................................................... 270<br />
Text Mode .............................................................. 236<br />
Text Streams.......................................................... 225<br />
Ticks........................................................317, 318, 320<br />
time ................................................................ 324, 373<br />
Time Difference...................................................... 320<br />
Time Structure................................................ 317, 322<br />
Time Zone .............................................................. 323<br />
time.h ............................................................. 317, 373<br />
asctime............................................................ 318<br />
clock................................................................ 318<br />
clock_t............................................................. 317<br />
CLOCKS_PER_SEC ...................................... 317<br />
ctime ............................................................... 319<br />
difftime ............................................................ 320<br />
gmtime ............................................................ 320<br />
localtime.......................................................... 321<br />
mktime ............................................................ 322<br />
NULL............................................................... 318<br />
size_t............................................................... 317<br />
strftime ............................................................ 322<br />
struct tm .......................................................... 317<br />
time ................................................................. 324<br />
time_t .............................................................. 317<br />
time_t ......................................................317, 322, 324<br />
Timer Functions<br />
Close............................................................... 109<br />
Close 32-bit..................................................... 109<br />
Configure Interrupt.......................................... 110<br />
Configure Interrupt 32-bit ................................ 111<br />
Example of Use............................................... 116<br />
Open ............................................................... 111<br />
Open 32-bit ..................................................... 112<br />
Read ............................................................... 113<br />
Read 32-bit ..................................................... 114<br />
chiều rộng ................................................. ............... 253, 259<br />
Chức năng cửa sổ<br />
BartlettInit ................................................. ......... 26<br />
BlackmanInit ................................................. 27 ....<br />
HammingInit ................................................. ..... 28<br />
HanningInit ................................................. ....... 28<br />
KaiserInit ................................................. .......... 29<br />
VectorWindow ................................................. 29 ..<br />
viết ................................................. ....................... 373<br />
WriteCmdXLCD ................................................. ....... 79<br />
WriteDataXLCD ................................................. ....... 78<br />
WriteDCI ................................................. ................ 154<br />
WriteQEI ................................................. ................ 169<br />
WriteSPIx ................................................. .............. 160<br />
WriteTimerx ................................................. ........... 114<br />
WriteTimerxx ................................................. ......... 115<br />
WriteUARTx ................................................. .......... 145<br />
Địa chỉ Email ................................................ ........... 5<br />
Y<br />
Năm ................................................. ........ 317, 318, 323<br />
Z<br />
Không ................................................. ....................... 325<br />
Zero, chia ......................................... 216, 219, 278<br />
DS51456B trang 400 2004 Microchip Technology Inc<br />
Châu Mỹ<br />
Văn phòng công ty<br />
2355 Tây Chandler Blvd<br />
Chandler, AZ 85224-6199<br />
Điện thoại: 480-792-7200<br />
Fax: 480-792-7277<br />
Hỗ trợ kỹ thuật:<br />
http: \\ support.microchip.com<br />
Địa chỉ Web:<br />
www.microchip.com<br />
Atlanta<br />
Alpharetta, GA<br />
Điện thoại: 770-640-0034<br />
Fax: 770-640-0307<br />
Boston
Write................................................................ 114<br />
Write 32-bit...................................................... 115<br />
dsPIC<br />
®<br />
Language Tools Libraries<br />
DS51456B-page 398 2004 Microchip Technology Inc.<br />
Timer Macros<br />
Disable Interrupt.............................................. 115<br />
Enable Interrupt .............................................. 115<br />
Set Interrupt Priority........................................ 116<br />
TMP_MAX.............................................................. 228<br />
tmpfile..................................................................... 264<br />
tmpnam .................................................................. 265<br />
Tokens ................................................................... 315<br />
tolower.................................................................... 203<br />
toupper ................................................................... 204<br />
Transferring Control ............................................... 214<br />
Transform Functions................................................ 58<br />
BitReverseComplex .......................................... 60<br />
CosFactorInit..................................................... 61<br />
DCT................................................................... 61<br />
DCTIP ............................................................... 63<br />
FFTComplex ..................................................... 64<br />
FFTComplexIP.................................................. 66<br />
IFFTComplex .................................................... 67<br />
IFFTComplexIP................................................. 69<br />
TwidFactorInit ................................................... 70<br />
Transform String..................................................... 316<br />
Trigonometric Functions<br />
acos ................................................................ 325<br />
acosf ............................................................... 326<br />
asin ................................................................. 327<br />
asinf ................................................................ 327<br />
atan ................................................................. 328<br />
atan2 ............................................................... 329<br />
atan2f .............................................................. 331<br />
atanf ................................................................ 329<br />
cos .................................................................. 333<br />
cosf ................................................................. 334<br />
Westford, MA<br />
Điện thoại: 978-692-3848<br />
Fax: 978-692-3821<br />
Chicago<br />
Itasca, IL<br />
Điện thoại: 630-285-0071<br />
Fax: 630-285-0075<br />
Dallas<br />
Addison, TX<br />
Điện thoại: 972-818-7423<br />
Fax: 972-818-2924<br />
Detroit<br />
Farmington Hills, MI<br />
Điện thoại: 248-538-2250<br />
Fax: 248-538-2260<br />
Kokomo<br />
Kokomo, IN<br />
Điện thoại: 765-864-8360<br />
Fax: 765-864-8387<br />
Los Angeles<br />
Mission Viejo, CA<br />
Điện thoại: 949-462-9523<br />
Fax: 949-462-9608<br />
San Jose<br />
Mountain View, CA<br />
Điện thoại: 650-215-1444<br />
Fax: 650-961-0286<br />
Toronto<br />
Mississauga, Ontario,<br />
Canada<br />
Điện thoại: 905-673-0699<br />
Fax: 905-673-6509<br />
Châu Á / Thái Bình Dương<br />
Úc - Sydney<br />
Điện thoại: 61-2-9868-6733<br />
Fax: 61-2-9868-6755<br />
Trung Quốc - Bắc Kinh<br />
Điện thoại: 86-10-8528-2100<br />
Fax: 86-10-8528-2104
sin ................................................................... 357<br />
sinf .................................................................. 358<br />
tan ................................................................... 363<br />
tanf .................................................................. 363<br />
TwidFactorInit........................................................... 70<br />
type ................................................................ 254, 260<br />
U<br />
UART Functions<br />
Close UART. ................................................... 141<br />
Configure UART.............................................. 143<br />
Configure UART Interrupt ............................... 142<br />
Example of Use............................................... 149<br />
Read UART..................................................... 145<br />
UART Buffer Status ........................................ 143<br />
UART Get Character....................................... 147<br />
UART Get String ............................................. 146<br />
UART Put Character ....................................... 147<br />
UART Put String ............................................. 146<br />
UART Status ................................................... 141<br />
Write UART..................................................... 145<br />
UART Macros<br />
Disable UART RX Interrupt............................. 147<br />
Disable UART TX Interrupt ............................. 148<br />
Enable UART RX Interrupt.............................. 147<br />
Enable UART TX Interrupt .............................. 147<br />
Set UART RX Interrupt Priority ....................... 148<br />
Set UART TX Interrupt Priority........................ 148<br />
UCHAR_MAX......................................................... 213<br />
UINT_MAX ............................................................. 213<br />
ULLONG_MAX....................................................... 213<br />
ULONG_MAX......................................................... 213<br />
Underflow Errors ....................................205, 325, 337,<br />
.............................................338, 346, 348, 355, 356<br />
ungetc..................................................................... 265<br />
Universal Time Coordinated................................... 320<br />
unsigned char<br />
Maximum Value .............................................. 213<br />
unsigned int<br />
Maximum Value .............................................. 213<br />
Trung Quốc - Thành Đô<br />
Điện thoại: 86-28-8676-6200<br />
Fax: 86-28-8676-6599<br />
Trung Quốc - Phúc Châu<br />
Điện thoại: 86-591-8750-3506<br />
Fax: 86-591-8750-3521<br />
Trung Quốc - Hồng Kông<br />
Điện thoại: 852-2401-1200<br />
Fax: 852-2401-3431<br />
Trung Quốc - Thượng Hải<br />
Điện thoại: 86-21-5407-5533<br />
Fax: 86-21-5407-5066<br />
Trung Quốc - Thẩm Dương<br />
Điện thoại: 86-24-2334-2829<br />
Fax: 86-24-2334-2393<br />
Trung Quốc - Thâm Quyến<br />
Điện thoại: 86-755-8203-2660<br />
Fax: 86-755-8203-1760<br />
Trung Quốc - Thuận Đức<br />
Điện thoại: 86-757-2839-5507<br />
Fax: 86-757-2839-5571<br />
Trung Quốc - Thanh Đảo<br />
Điện thoại: 86-532-502-7355<br />
Fax: 86-532-502-7205<br />
Châu Á / Thái Bình Dương<br />
Ấn Độ - Bangalore<br />
Điện thoại: 91-80-2229-0061<br />
Fax: 91-80-2229-0062<br />
Ấn Độ - New Delhi<br />
Điện thoại: 91-11-5160-8632<br />
Fax: 91-11-5160-8632<br />
Nhật Bản - Kanagawa<br />
Điện thoại: 81-45-471- 6166<br />
Fax: 81-45-471-6122<br />
Hàn Quốc - Seoul<br />
Điện thoại: 82-2-554-7200<br />
Fax: 82-2-558-5932 hoặc<br />
82-2-558-5934<br />
Singapore
unsigned short int<br />
Maximum Value .............................................. 213<br />
Unsuccessful Termination ...................................... 270<br />
Upper Case Alphabetic Character<br />
Convert To ...................................................... 204<br />
Defined............................................................ 202<br />
Test for ............................................................ 202<br />
USHRT_MAX ......................................................... 213<br />
UTC ........................................................................ 320<br />
Utility Functions, Seestdlib.h<br />
V<br />
va_arg .....................................221, 223, 267, 268, 269<br />
va_end.............................................223, 267, 268, 269<br />
va_list ..................................................................... 221<br />
va_start............................................223, 267, 268, 269<br />
Variable Argument Lists, Seestdarg.h<br />
Variable Length Argument List ...................... 221, 223,<br />
............................................................ 267, 268, 269<br />
Vector Functions ...................................................... 13<br />
VectorAdd................................................................. 15<br />
VectorConvolve ........................................................ 16<br />
VectorCopy............................................................... 17<br />
VectorCorrelate ........................................................ 18<br />
VectorDotProduct ..................................................... 19<br />
VectorMax ................................................................ 19<br />
VectorMin ................................................................. 20<br />
VectorMultiply........................................................... 21<br />
VectorNegate ........................................................... 21<br />
VectorPower ............................................................. 22<br />
VectorScale .............................................................. 23<br />
VectorSubtract.......................................................... 23<br />
VectorWindow .......................................................... 29<br />
VectorZeroPad ......................................................... 24<br />
VERBOSE_DEBUGGING ...................................... 195<br />
Vertical Tab ............................................................ 201<br />
Điện thoại: 65-6334-8870<br />
Fax: 65-6334-8850<br />
Đài Loan - Cao Hùng<br />
Điện thoại: 886-7-536-4818<br />
Fax: 886-7-536-4803<br />
Đài Loan - Đài Bắc<br />
Điện thoại: 886-2-2500-6610<br />
Fax: 886-2-2508-0102<br />
Đài Loan - Hsinchu<br />
Điện thoại: 886-3-572-9526<br />
Fax: 886-3-572-6459<br />
CHÂU ÂU<br />
Áo - Weis<br />
Điện thoại: 43-7242-2244-399<br />
Fax: 43-7242-2244-393<br />
Đan Mạch - Ballerup<br />
Điện thoại: 45-4420-9895<br />
Fax: 45-4420-9910<br />
Pháp - Massy<br />
Điện thoại: 33-1-69-53-63-20<br />
Fax: 33-1-69-30-90-79<br />
Đức - Ismaning<br />
Điện thoại: 49-89-627-144-0<br />
Fax: 49-89-627-144-44<br />
Ý - Milan<br />
Điện thoại: 39-0331-742611<br />
Fax: 39-0331-466781<br />
Hà Lan - Drunen<br />
Điện thoại: 31-416-690399<br />
Fax: 31-416-690340<br />
Anh - Berkshire<br />
Điện thoại: 44-118-921-5869<br />
Fax: 44-118-921-5820<br />
WORLDWIDESALES ANDSERVICE<br />
09/27/04<br />
vfprintf............................................................. 225, 267<br />
vprintf.............................................................. 225, 268<br />
vsprintf............................................................ 225, 269<br />
W<br />
Được hỗ trợ bởi<br />
Dịch
wchar_t........................................................... 223, 270<br />
wcstombs ............................................................... 293<br />
wctomb ................................................................... 293<br />
WDTSWDisable ..................................................... 120<br />
WDTSWEnable ...................................................... 120<br />
Week ...................................................................... 323<br />
White Space ....................................259, 274, 275, 289<br />
Index<br />
2004 Microchip Technology Inc. DS51456B-page 399<br />
White-Space Character<br />
Defined ........................................................... 201<br />
Test for............................................................ 201<br />
wide........................................................................ 270<br />
Wide Character ...............................................285, 293<br />
Wide Character String.....................................285, 293<br />
Wide Character Value............................................ 223<br />
Width...................................................................... 253<br />
width................................................................253, 259<br />
Window Functions<br />
BartlettInit.......................................................... 26<br />
BlackmanInit ..................................................... 27<br />
HammingInit...................................................... 28<br />
HanningInit........................................................ 28<br />
KaiserInit........................................................... 29<br />
VectorWindow................................................... 29<br />
write........................................................................ 373<br />
WriteCmdXLCD........................................................ 79<br />
WriteDataXLCD........................................................ 78<br />
WriteDCI................................................................. 154<br />
WriteQEI................................................................. 169<br />
WriteSPIx ............................................................... 160<br />
WriteTimerx............................................................ 114<br />
WriteTimerxx .......................................................... 115<br />
WriteUARTx ........................................................... 145<br />
WWW Address........................................................... 5<br />
Y<br />
Year.........................................................317, 318, 323<br />
Z<br />
Zero........................................................................ 325
Zero, divide by.........................................216, 219, 278<br />
DS51456B-page 400<br />
2004 Microchip Technology Inc.<br />
AMERICAS<br />
Corporate Office<br />
2355 West Chandler Blvd.<br />
Chandler, AZ 85224-6199<br />
Tel: 480-792-7200<br />
Fax: 480-792-7277<br />
Technical Support:<br />
http:\\support.microchip.com<br />
Web Address:<br />
www.microchip.com<br />
Atlanta<br />
Alpharetta, GA<br />
Tel: 770-640-0034<br />
Fax: 770-640-0307<br />
Boston<br />
Westford, MA<br />
Tel: 978-692-3848<br />
Fax: 978-692-3821<br />
Chicago<br />
Itasca, IL<br />
Tel: 630-285-0071<br />
Fax: 630-285-0075<br />
Dallas<br />
Addison, TX<br />
Tel: 972-818-7423<br />
Fax: 972-818-2924<br />
Detroit<br />
Farmington Hills, MI<br />
Tel: 248-538-2250<br />
Fax: 248-538-2260<br />
Kokomo<br />
Kokomo, IN<br />
Tel: 765-864-8360<br />
Fax: 765-864-8387<br />
Los Angeles<br />
Mission Viejo, CA<br />
Tel: 949-462-9523
Fax: 949-462-9608<br />
San Jose<br />
Mountain View, CA<br />
Tel: 650-215-1444<br />
Fax: 650-961-0286<br />
Toronto<br />
Mississauga, Ontario,<br />
Canada<br />
Tel: 905-673-0699<br />
Fax: 905-673-6509<br />
ASIA/PACIFIC<br />
Australia - Sydney<br />
Tel: 61-2-9868-6733<br />
Fax: 61-2-9868-6755<br />
China - Beijing<br />
Tel: 86-10-8528-2100<br />
Fax: 86-10-8528-2104<br />
China - Chengdu<br />
Tel: 86-28-8676-6200<br />
Fax: 86-28-8676-6599<br />
China - Fuzhou<br />
Tel: 86-591-8750-3506<br />
Fax: 86-591-8750-3521<br />
China - Hong Kong SAR<br />
Tel: 852-2401-1200<br />
Fax: 852-2401-3431<br />
China - Shanghai<br />
Tel: 86-21-5407-5533<br />
Fax: 86-21-5407-5066<br />
China - Shenyang<br />
Tel: 86-24-2334-2829<br />
Fax: 86-24-2334-2393<br />
China - Shenzhen<br />
Tel: 86-755-8203-2660<br />
Fax: 86-755-8203-1760<br />
China - Shunde<br />
Tel: 86-757-2839-5507<br />
Fax: 86-757-2839-5571<br />
China - Qingdao
Tel: 86-532-502-7355<br />
Fax: 86-532-502-7205<br />
ASIA/PACIFIC<br />
India - Bangalore<br />
Tel: 91-80-2229-0061<br />
Fax: 91-80-2229-0062<br />
India - New Delhi<br />
Tel: 91-11-5160-8632<br />
Fax: 91-11-5160-8632<br />
Japan - Kanagawa<br />
Tel: 81-45-471- 6166<br />
Fax: 81-45-471-6122<br />
Korea - Seoul<br />
Tel: 82-2-554-7200<br />
Fax: 82-2-558-5932 or<br />
82-2-558-5934<br />
Singapore<br />
Tel: 65-6334-8870<br />
Fax: 65-6334-8850<br />
Taiwan - Kaohsiung<br />
Tel: 886-7-536-4818<br />
Fax: 886-7-536-4803<br />
Taiwan - Taipei<br />
Tel: 886-2-2500-6610<br />
Fax: 886-2-2508-0102<br />
Taiwan - Hsinchu<br />
Tel: 886-3-572-9526<br />
Fax: 886-3-572-6459<br />
EUROPE<br />
Austria - Weis<br />
Tel: 43-7242-2244-399<br />
Fax: 43-7242-2244-393<br />
Denmark - Ballerup<br />
Tel: 45-4420-9895<br />
Fax: 45-4420-9910<br />
France - Massy<br />
Tel: 33-1-69-53-63-20<br />
Fax: 33-1-69-30-90-79<br />
Germany - Ismaning
Tel: 49-89-627-144-0<br />
Fax: 49-89-627-144-44<br />
Italy - Milan<br />
Tel: 39-0331-742611<br />
Fax: 39-0331-466781<br />
Netherlands - Drunen<br />
Tel: 31-416-690399<br />
Fax: 31-416-690340<br />
England - Berkshire<br />
Tel: 44-118-921-5869<br />
Fax: 44-118-921-5820<br />
WORLDWIDESALES ANDSERVICE<br />
09/27/04