SW006010 Microchip Technology, SW006010 Datasheet

no-image

SW006010

Manufacturer Part Number
SW006010
Description
MPLAB 17C SOFTWARE
Manufacturer
Microchip Technology
Datasheets

Specifications of SW006010

Tool Function
Compiler
Tool Type
Compiler
Processor Series
PIC17C
Lead Free Status / RoHS Status
Not applicable / Not applicable
For Use With/related Products
MPLAB®
Lead Free Status / Rohs Status
Lead free / RoHS Compliant
®
MPLAB
C17
C COMPILER
LIBRARIES
 2002 Microchip Technology Inc.
DS51296A

Related parts for SW006010

SW006010 Summary of contents

Page 1

... Microchip Technology Inc. ® MPLAB C COMPILER LIBRARIES C17 DS51296A ...

Page 2

... Serialized Quick Turn Programming (SQTP service mark of Microchip Technology Incorporated in the U.S.A. All other trademarks mentioned herein are property of their respective companies. © 2002, Microchip Technology Incorporated. Printed in the U.S.A., All Rights Reserved. Printed on recycled paper. Microchip received QS-9000 quality system ...

Page 3

... Introduction ................................................................................... 87 4.2 Highlights ...................................................................................... 87 4.3 Character Classification Functions ............................................... 87 4.4 Number and Text Conversion Functions ...................................... 91 4.5 Delay Functions ............................................................................ 96 4.6 Memory and String Manipulation Functions ................................. 98  2002 Microchip Technology Inc. MPLAB Table of Contents ® C17 Libraries ................................................................... 7 ® Functions .................................................................... 36 ® C17 C COMPILER LIBRARIES DS51296A-page iii ...

Page 4

... Chapter 5. Math Library 5.1 Introduction .................................................................................103 5.2 Highlights ....................................................................................103 5.3 32-Bit Integer and 32-Bit Floating Point Math Libraries ..............103 5.4 Decimal/Floating Point and Floating Point/Decimal Conversions 106 Glossary ................................................................................................. 109 Index ....................................................................................................... 125 Worldwide Sales and Service ............................................................... 132 DS51296A-page iv  2002 Microchip Technology Inc. ...

Page 5

... Index – Cross-reference listing of terms, features and sections of this document. • Worldwide Sales and Service – gives the address, telephone and fax number for Microchip Technology Inc. sales and service locations throughout the world.  2002 Microchip Technology Inc. ® ...

Page 6

... The revision level of the document. Examples #define START c:\autoexec.bat <label>, <exp> MPASMWIN [main.asm] errorlevel {0|1} “filename” list [“list_option..., “list_option”] 0xFFFF, 0x007A char isascii (char, ch); File > Save OK, Cancel <Tab>, <Ctrl-C> MPLAB IDE User’s Guide  2002 Microchip Technology Inc. ...

Page 7

... Microsoft Windows This manual assumes that users are familiar with the Microsoft system. Many excellent references exist for this software program, and should be consulted for general operation of Windows.  2002 Microchip Technology Inc. ® Manuals Preface ® MCU MPASM ® ...

Page 8

... Emulators - The latest information on Microchip in-circuit emulators. This includes the MPLAB ICE 2000. In-Circuit Debuggers - The latest information on Microchip in-circuit debuggers. These include the MPLAB ICD and MPLAB ICD 2. apRNOVT^-page 4 files for information on common problems not addressed in this user’s  2002 Microchip Technology Inc. ...

Page 9

... Plus, this line provides information on how customers can receive the most current upgrade kits. The Information Line Numbers are: 1-800-755-2345 for U.S. and most of Canada. 1-480-792-7302 for the rest of the world.  2002 Microchip Technology Inc. ® II device programmer and PICSTART Preface ® ...

Page 10

... MPLAB C17 C Compiler Libraries NOTES: apRNOVT^-page 6  2002 Microchip Technology Inc. ...

Page 11

... MPLAB IDE. This results from MPLINK linker looking for the library source files in the absolute path of c:\mcc\src.  2002 Microchip Technology Inc. ® MPLAB ...

Page 12

... All Memory Models c:\mcc\src\math Compact Large pmc42ac.lib pmc42al.lib pmc43c.lib pmc43l.lib pmc44c.lib pmc44l.lib pmc752c.lib pmc752l.lib pmc756ac.lib pmc756al.lib pmc756c.lib pmc756l.lib pmc762c.lib pmc762l.lib pmc766c.lib pmc766l.lib cmath17.lib , where is c:\mcc  2002 Microchip Technology Inc. ...

Page 13

... The source code may be found in c:\mcc\src\startup, where c:\mcc is the compiler install directory.  2002 Microchip Technology Inc. Memory Model Small Compact/Medium/Large c0s17.o c0l17.o All Memory Models idata17.o apRNOVS^-page 9 ...

Page 14

... The source code can be found in c:\mcc\src\proc, where c:\mcc is the compiler install directory. apRNOVS^-page 10 Memory Model Small Compact/Medium/Large int42as.o int42al.o int43s.o int43l.o int44s.o int44l.o int752s.o int752l.o int756as.o int756al.o int756s.o int756l.o int762s.o int762l.o int766s.o int766l.o All Memory Models p17c42a.o p17c43.o p17c44.o p17c752.o p17c756a.o p17c756.o p17c762.o p17c766.o  2002 Microchip Technology Inc. ...

Page 15

... Interrupt Functions • Port B Functions ® • Microwire • Pulse Width Modulation (PWM) Functions • Reset Functions • SPI™ Functions • Timer Functions • USART Functions  2002 Microchip Technology Inc. MPLAB Functions ® C17 C COMPILER LIBRARIES apRNOVS^-page 11 ...

Page 16

... PIE2 None adcclose.c (); CloseADC PIC17C756 Starts an A/D conversion by setting the register. adc16.h void ConvertADC (void); None This function sets the bit in the GO ADCON0 None adcconv.c ConvertADC(); register. ADCON0 bit in the GO ADCON0 ADON bit in the GO ADCON0 register.  2002 Microchip Technology Inc. ...

Page 17

... OpenADC Device: Function: Include: Prototype: Arguments:  2002 Microchip Technology Inc. Hardware Peripheral Library PIC17C756 Configures the A/D convertor. adc16.h void OpenADC (static unsigned char config, static unsigned char channel); config The value of config can be a combination of the following values (defined in ): adc16 ...

Page 18

... The value of channel can be one of the following values (defined in ): adc16.h ADC_CH0 Channel 0 ADC_CH1 Channel 1 ADC_CH2 Channel 2 ADC_CH3 Channel 3 ADC_CH4 Channel 4 ADC_CH5 Channel 5 ADC_CH6 Channel 6 ADC_CH7 Channel 7 ADC_CH8 Channel 8 ADC_CH9 Channel 9 ADC_CH10 Channel 10 ADC_CH11 Channel 11 is set, then the result is bit is ADFM  2002 Microchip Technology Inc. ...

Page 19

... ConvertADC(); result = ReadADC(); // read result itoa(result,str); putsUSART1(str); CloseADC(); CloseUSART1(); return; }  2002 Microchip Technology Inc. Hardware Peripheral Library This function first clears the channel select bits in the register, which selects channel 0. It then ORs the value channel with register. ADCON0 None adcset.c SetChanADC(ADC_CH0) ...

Page 20

... OpenCapture3 - PIC17C756 OpenCapture4 - PIC17C756 This function configures the specified input capture. captur16.h void OpenCapture1 (static unsigned char config); void OpenCapture2 (static unsigned char config); void OpenCapture3 (static unsigned char config); void OpenCapture4 (static unsigned char config);  2002 Microchip Technology Inc. ...

Page 21

... OpenCapture1 OpenCapture2 OpenCapture3 OpenCapture4 (Continued) Arguments: Remarks:  2002 Microchip Technology Inc. Hardware Peripheral Library config The value of config can be a combination of the following values (defined in ): captur16.h All OpenCapture functions CAPTURE_INT_ONInterrupts ON CAPTURE_INT_OFFInterrupts OFF OpenCapture1 C1_EVERY_FALL_EDGE C1_EVERY_RISE_EDGE C1_EVERY_4_RISE_EDGE C1_EVERY_16_RISE_EDGE CAPTURE1_PERIOD CAPTURE1_CAPTURE OpenCapture2 ...

Page 22

... This function reads the value of the respective input capture SFRs. Capture1: CA1L,CA1H Capture2: CA2L,CA2H Capture3: CA3L,CA3H Capture4: CA4L,CA4H This function returns the result of the capture event. The value is a 16-bit unsigned integer. cap1read.c cap2read.c cap3read.c cap4read.c unsigned int result; result = ReadCapture1();  2002 Microchip Technology Inc. ...

Page 23

... Configure Capture1 OpenCapture1(C1_EVERY_4_RISE_EDGE&CAPTURE1_CAPTURE); // Configure Timer3 OpenTimer3(TIMER_INT_OFF&T3_SOURCE_INT); // Configure USART OpenUSART1(USART_TX_INT_OFF&USART_RX_INT_OFF& while(!PIR1bits.CA1IF); result = ReadCapture1(); // read result uitoa(result,str); if(!CapStatus.Cap1OVF) { putsUSART1(str); CloseCapture1(); } CloseTimer3(); CloseUSART1(); return; }  2002 Microchip Technology Inc. Hardware Peripheral Library USART_ASYNCH_MODE&USART_EIGHT_BIT& USART_CONT_RX, 25); // Wait for event // convert to string // write string // to USART apRNOVS^-page 19 ...

Page 24

... DataRdyI2C (void); None Determines if there is a byte to be read from the register. This function returns 1 if there is data in the returns 0 which indicates no data in dtrdyi2c.c if (!DataRdyI2C()); register SSPBUF SSPBUF register else SSPBUF register. SSPBUF  2002 Microchip Technology Inc. ...

Page 25

... Device: Function: Include: Prototype: Arguments: Remarks: Return Value: File Name: Code Example:  2002 Microchip Technology Inc. Hardware Peripheral Library This function operates identically to ReadI2C. # define in i2c16.h PIC17C756 This function is used to read a predetermined data string length 2 from the I C bus. ...

Page 26

... The value of function parameter sync_mode can be one of the following values defined in i2c16.h: 2 SLAVE_7 I C Slave mode, 7-bit address 2 SLAVE_10 I C Slave mode, 10-bit address 2 MASTER I C Master mode register and SSPSTAT bits of the ACKEN SSPCON2 2 C peripheral operation can  2002 Microchip Technology Inc. ...

Page 27

... Device: Function: Include: Prototype: Arguments: Remarks: Return Value: File Name: Code Example:  2002 Microchip Technology Inc. Hardware Peripheral Library slew The value of function parameter slew can be one of the following values defined in i2c16.h: SLEW_OFF Slew rate disabled for 100kHz mode SLEW_ON ...

Page 28

... RestartI2C (void); None 2 This function generates bus restart condition. None rstrti2c.c RestartI2C(); PIC17C756 2 Generates I C bus start condition. i2c16.h void StartI2C (void); None 2 This function generates bus start condition. None starti2c.c StartI2C(); 2 C bus. This 2 C bus.  2002 Microchip Technology Inc. ...

Page 29

... Code Example: Note: The routines to follow are specialized and specific devices such as, but not limited to, the Microchip 24LC01B. Each of the routines depicted below utilize the previous basic 'C' routines in a composite standalone function.  2002 Microchip Technology Inc. Hardware Peripheral Library PIC17C756 2 Generates I C bus stop condition ...

Page 30

... The return value there was a bus collision error there was a not ack error else returns 0 if there were no errors. i2ceebw.c temp = EEByteWrite(0xA0, 0x30, 0xA5); static unsigned char 2 C bus bus. This memory device  2002 Microchip Technology Inc. ...

Page 31

... Function: Include: Prototype: Arguments: Remarks: Return Value: File Name: Code Example:  2002 Microchip Technology Inc. Hardware Peripheral Library PIC17C756 This function is used to read a single byte from the I i2c16.h unsigned char EECurrentAddRead (static unsigned char control); control EEPROM control / bus device select address byte. ...

Page 32

... The return value there was a bus collision error there was a not ack error else returns 0 if there were no errors. i2ceesr.c temp = EESequentialRead(0xA0, 0x70, rdptr, 15 bus bus. The memory devices SSPBUF 2 C bus memory ;  2002 Microchip Technology Inc. ...

Page 33

... EEByteWrite(0xA0, 0x30, 0xA5); temp = EEAckPolling(0xA0); temp = EECurrentAddRead(0xA1); temp = EEPageWrite(0xA0, 0x70, wrptr); temp = EEAckPolling(0xA0); temp = EESequentialRead(0xA0, 0x70, rdptr, 15); temp = EERandomRead(0xA0,0x30  2002 Microchip Technology Inc. Hardware Peripheral Library 2 C communications with a Microchip 2 C module of the PIC17C756 such routines such as 11,12,13,14,15,16,0}; //400Khz Baud clock(9) @16 MHz ...

Page 34

... This function disables global interrupts by setting the of the register. CPUSTA None disable.c Disable(); PIC17C4X, PIC17C756 Enables global interrupts. int16.h void Enable (void); None This function enables global interrupts by clearing the bit of the register. CPUSTA None enable.c enable();; bit GLINTD GLINTD  2002 Microchip Technology Inc. ...

Page 35

... OpenRA0INT(INT_ON & INT_RISE_EDGE); Enable(); while(PORTB != 0xFF); // wait for interrupt and check Disable(); CloseRA0INT(); }  2002 Microchip Technology Inc. Hardware Peripheral Library PIC17C4X, PIC17C756 Configures the external interrupt pin RA0/INT. int16.h void OpenRA0INT (static unsigned char config); config ...

Page 36

... Enables the internal pull-up resistors on portb16.h void EnablePullups (void); None This function enables the internal pull-up resistors on clearing the bit in the NOT_RBPU PORTA None pullen.c EnablePullups(); PORTB. bit in the register. PORTA . PORTB . by PORTB register. . PORTB by PORTB register.  2002 Microchip Technology Inc. ...

Page 37

... Device: Function: Include: Prototype: Arguments: Remarks: Return Value: File Name: Code Example:  2002 Microchip Technology Inc. Hardware Peripheral Library PIC17C4X, PIC17C756 Configures the interrupts and internal pull-up resistors on . PORTB portb16.h void OpenPORTB (static unsigned char config); config The value of config can be a combination of the following values ...

Page 38

... PORTB to clear mismatch // enable internal pullups // enable global interrupts PressedKey = ’1’; break; PressedKey = ’2’; break; PressedKey = ’3’; break; PressedKey = ’4’; break;  2002 Microchip Technology Inc. ...

Page 39

... Key = 0x00  2002 Microchip Technology Inc. Hardware Peripheral Library PressedKey = ’5’; break; PressedKey = ’6’; break; PressedKey = ’7’; break; PressedKey = ’8’; break; PressedKey = ’9’; ...

Page 40

... This function returns 1 if the Microwire device is ready else returns 0 which indicates that the internal write cycle is not complete or there could be a bus error. drdymwir.c while (!DataRdyMwire()); This function operates identically to ReadMwire. #define in mwire16.h and register settings. PORTx  2002 Microchip Technology Inc. ...

Page 41

... Remarks: Return Value: File Name: Code Examples: putcMwire Function: File Name:  2002 Microchip Technology Inc. Hardware Peripheral Library PIC17C756 This routine reads a string from the Microwire device. mwire16.h void getsMwire (static unsigned char far *rdptr, static unsigned char length); rdptr Pointer to PICmicro RAM area for placement of writing data read from Microwire device ...

Page 42

... Single byte of data to write to Microwire device. This function writes out single data byte to a Microwire device utilizing the SSP module.This function operates identically to putcMwire. This function returns -1 if there was a write collision, else it returns a 0. writmwir.c WriteMwire(0xFF);  2002 Microchip Technology Inc. ...

Page 43

... CloseMwire(); } void busy_poll(void) { W_CS = var = DataRdyMwire(); }while(var != 0); W_CS = 0; } void write_byte(unsigned char address, unsigned char data)  2002 Microchip Technology Inc. Hardware Peripheral Library 0x0C 10x09 20x80 10x09 20x00 10x08 20x80 10x08 20x00 PORTAbits.RA2 //ensure CS is negated //enable SSP perpiheral ...

Page 44

... W_CS = 0; } void erase_all(void) { W_CS = 1; putcMwire(ERAL1); //erase all command byte 1 putcMwire(ERAL2); //erase all command byte 2 W_CS = 0; } apRNOVS^-page 40 //write command //address //write single byte //read one byte //read command //address (A7 - A0) //assert chip select //negate chip select  2002 Microchip Technology Inc. ...

Page 45

... Code Example: OpenPWM1 OpenPWM2 OpenPWM3 Device: Function: Include: Prototype: Arguments:  2002 Microchip Technology Inc. Hardware Peripheral Library ClosePWM1 - PIC17C4X, PIC17C756 ClosePWM2 - PIC17C4X, PIC17C756 ClosePWM3 - PIC17C756 This function disables the specified PWM channel. pwm16.h void ClosePWM1 (void); void ClosePWM2 (void); void ClosePWM3 (void); ...

Page 46

... The dutycycle, or more specifically the high time of the PWM waveform, can be calculated from the following formula: PWM x Dutycycle = (DCx<9:0> where DCx<9:0> is the 10-bit value from the registers. OSC OSC OSC OSC OSC OSC PWxDCH:PWxDCL  2002 Microchip Technology Inc. ...

Page 47

... PIR1bits.TMR1IF = 0; SetDCPWM2(i); } ClosePWM2(); CloseTimer1(); return; }  2002 Microchip Technology Inc. Hardware Peripheral Library This function writes the new value for dutycycle to the specified PWM channel dutycycle registers. PWM1: PW1DCL,PW1DCH PWM2: PW2DCL,PW2DCH PWM3: PW3DCL,PW3DCH The maximum resolution of the PWM waveform can be ...

Page 48

... MCLR pin while in normal operation. This situation is indicated by the following status bits POR = 1 if Brown-out is enabled BOR = 1 if WDT is enabled This function returns 1 if the reset was due to MCLR during normal operation, otherwise 0 is returned. reset16.c if(isMCLR()); then ... in the header file  2002 Microchip Technology Inc. ...

Page 49

... Code Example: isWDTTO Device: Function: Include: Prototype: Arguments: Remarks:  2002 Microchip Technology Inc. Hardware Peripheral Library PIC17C4X, PIC17C756 Detects a Power-on Reset condition. reset16.h char isPOR (void); None This function detects if the microcontroller just left a Power-on Reset. This condition is indicated by the following status bits: ...

Page 50

... This function returns 1 if device was brought out of WDT, otherwise 0 is returned. reset16.c if(isWDTWU()); then ... PIC17C4X, PIC17C756 Detects if the microcontroller was just waken up from SLEEP via the MCLR pin or interrupt. reset16.h char isWU (void); None . SLEEP in the header file by the SLEEP  2002 Microchip Technology Inc. ...

Page 51

... Code Example: Example of Use 2.10.2 There are no interdependencies between reset functions. See individual function code examples.  2002 Microchip Technology Inc. Hardware Peripheral Library This function detects if the microcontroller was brought out of by the MCLR pin or an interrupt. This condition is SLEEP ...

Page 52

... This function returns 1 if there is data in the else returns a 0. dtrdyspi.c while (!DataRdySPI()); This function operates identically to ReadSPI. #define in spi16.h PIC17C756 Reads in data string from the SPI bus. spi16.h static unsigned char far *rdptr, static unsigned void getsSPI ( char length); register SSPBUF  2002 Microchip Technology Inc. ...

Page 53

... Include: Prototype: Arguments: Remarks: Return Value: File Name: Code Example:  2002 Microchip Technology Inc. Hardware Peripheral Library rdptr Character type pointer to PICmicro RAM area for placement of data read from SPI device. length Number of bytes to read from SPI device. This function reads in a predetermined data string length from the SPI bus ...

Page 54

... This function returns a byte of data read during a SPI read cycle. readspi.c char ReadSPI(); PIC17C756 Writes a single byte of data (one character) out to the SPI bus. spi16.h unsigned char WriteSPI (static unsigned char data_out); data_out Single byte to write to SPI device on bus. register. SSPBUF  2002 Microchip Technology Inc. ...

Page 55

... Microchip Technology Inc. Hardware Peripheral Library This function writes a single data byte out and then checks for a write collision. This function operates identically to putcSPI. This function returns - write collision occurred else write collision ...

Page 56

... Microchip Technology Inc. ...

Page 57

... SPI_CS = 0; var = putcSPI(RDSR); var = fetcSPI(); SPI_CS = 1; } while (var & 0x01); //stay in loop until notbusy }  2002 Microchip Technology Inc. Hardware Peripheral Library //assert chip select //read data byte //negate chip select //negate chip select //assert chip select //send read status command ...

Page 58

... OpenTimer1 (static unsigned char config); void OpenTimer2 (static unsigned char config); void OpenTimer3 (static unsigned char config); config The value of config can be a combination of the following values (defined in ): timers16.h All OpenTimer functions TIMER_INT_ON Interrupts ON TIMER_INT_OFF Interrupts OFF  2002 Microchip Technology Inc. ...

Page 59

... OpenTimer0 OpenTimer1 OpenTimer2 OpenTimer3 (Continued) Remarks: Return Value: File Name: Code Example:  2002 Microchip Technology Inc. Hardware Peripheral Library OpenTimer0 T0_EDGE_FALL External clock on falling edge T0_EDGE_RISE External clock on rising edge T0_SOURCE_EXT External clock source (I/O pin) T0_SOURCE_INT Internal clock source (T T0_PS_1_1 Prescale -> ...

Page 60

... These functions returns the value of the timer register(s) which may be 8-bits or 16-bits. Timer0: int (16-bits) Timer1: char (8-bits) Timer2: char (8-bits) Timer3: int (16-bits) Timer1_16: int (16-bits) t0read.c t1read.c t2read.c t3read.c t12read.c unsigned int result; result = ReadTimer0();  2002 Microchip Technology Inc. ...

Page 61

... Include: Prototype: Arguments: Remarks: Return Value: File Name: Code Example:  2002 Microchip Technology Inc. Hardware Peripheral Library PIC17C4X, PIC17C756 Reads the contents of the specified timer register(s). timers16.h void WriteTimer0 (static unsigned int timer); void WriteTimer1 (static unsigned char timer); void WriteTimer2 (static unsigned char timer); ...

Page 62

... OpenTimer0(TIMER_INT_OFF&T0_SOURCE_NT&T0_PS_1_32); // configure USART OpenUSART1(USART_TX_INT_OFF&USART_RX_INT_OFF& while(1) { while(!PORTBbits.RB3); //wait for RB3 high result = ReadTimer0(); //read timer if(result>0xc000) break; WriteTimer0(0); uitoa(result,str); putsUSART1(str); } CloseTimer0(); CloseUSART1(); return; } apRNOVS^-page 58 USART_ASYNCH_MODE&USART_EIGHT_BIT& USART_CONT_RX, 25); //write new value //convert to string //print string //close modules  2002 Microchip Technology Inc. ...

Page 63

... CloseUSART2 Device: Function: Include: Prototype: Arguments: Remarks: Return Value: File Name: Code Example:  2002 Microchip Technology Inc. Hardware Peripheral Library BusyUSART1: PIC17C4X, PIC17C756 BusyUSART2: PIC17C756 Returns the status of the flag bit in the TRMT usart16.h char BusyUSART1 (void); char BusyUSART2 (void); ...

Page 64

... The length of this string should be at least len + 1. len The value of len is limited to the available amount of RAM locations remaining in any one bank - 1. There must be one extra location to store the null character. register. PIR flag bit in the RCIF PIR  2002 Microchip Technology Inc. ...

Page 65

... Device: Function: Include: Prototype: Arguments:  2002 Microchip Technology Inc. Hardware Peripheral Library This function waits for and reads len number of characters out of the specified USART. There is no timeout when waiting for characters to arrive. After len characters have been written to the string, a null character is appended to the end of the string. ...

Page 66

... The value of data is a pointer to a string in contiguous RAM locations within the same bank. This function writes a string of data in program memory to the USART, including the null character. None u1putrs.c u2putrs.c rom char mybuff [20]; putrsUSART1(mybuff);  2002 Microchip Technology Inc. ...

Page 67

... Code Example: ReadUSART1 ReadUSART2 Device: Function: Include: Prototype: Arguments:  2002 Microchip Technology Inc. Hardware Peripheral Library putsUSART1: PIC17C4X, PIC17C756 putsUSART2: PIC17C756 Writes a string of characters to the USART including the null character. usart16.h void putsUSART1 (static char *data); void putsUSART2 (static char *data); ...

Page 68

... WriteUSART2: PIC17C756 Writes a byte (one character) to the USART transmit buffer, including the 9th bit if enabled. usart16.h void WriteUSART1 (static char data); void WriteUSART2 (static char data); data The value of data can be any number from 0x00 to 0xff.  2002 Microchip Technology Inc. ...

Page 69

... WriteUSART1(PORTD);//write value of PORTD if(PORTD == 0x80) break; } CloseUSART1(); return; }  2002 Microchip Technology Inc. Hardware Peripheral Library This function writes a byte to the USART transmit buffer. The 9th bit is written as well. The 9th data bits are saved in a union named with the following declaration: USART_Status ...

Page 70

... MPLAB C17 C Compiler Libraries NOTES: apRNOVS^-page 66  2002 Microchip Technology Inc. ...

Page 71

... Device: Function: Include: Prototype: Arguments: Remarks: Return Value: File Name: Code Example:  2002 Microchip Technology Inc. MPLAB is the compiler install directory. C Functions PIC17C4X, PIC17C756 Returns the status of the busy flag of the Hitachi HD44780 LCD controller. xlcd.h unsigned char BusyXLCD (void); ...

Page 72

... MPASM™ User's Guide with MPLINK™ and MPLIB™ (DS33014) for information on linking. This function also requires three external routines to be provided by the user for specific delays: DelayFor18TCY() 18 Tcy delay DelayPORXLCD delay DelayXLCD delay #define . If no define is xlcd.h in the #define UPPER  2002 Microchip Technology Inc. ...

Page 73

... Device: Function: Include: Prototype: Arguments: Remarks: Return Value: File Name: Code Example:  2002 Microchip Technology Inc. Software Peripheral Library None xlcd.c OpenXLCD(EIGHT_BIT&LINES_5X7); PIC17C4X, PIC17C756 Writes a string of characters in ROM to the Hitachi HD44780 LCD controller. xlcd.h void putrsXLCD (static rom char *buffer); ...

Page 74

... The data read from the controller is for the character generator RAM or the display data RAM depending on the previous Set??RamAddr() function that was called. This function returns the 8-bit data value. xlcd.c char data; while ( BusyXLCD() ); data = ReadAddrXLCD(); Bit0 A0  2002 Microchip Technology Inc. ...

Page 75

... File Name: Code Example: WriteCmdXLCD Device: Function: Include: Prototype: Arguments:  2002 Microchip Technology Inc. Software Peripheral Library PIC17C4X, PIC17C756 Sets the character generator address. xlcd.h void SetCGRamAddr (static unsigned char CGaddr); CGaddr Character generator address. This function sets the character generator address of the Hitachi HD44780 LCD controller ...

Page 76

... The data read from the controller is for the character generator RAM or the display data RAM depending on the previous Set??RamAddr() function that was called. This function operates identically to putcXLCD. None xlcd.c char data; data = ReadUSART1(); WriteDataXLCD(data); );  2002 Microchip Technology Inc. ...

Page 77

... LCD OpenXLCD(EIGHT_BIT&LINES_5X7); // configure USART OpenUSART1(USART_TX_INT_OFF&USART_RX_INT_OFF& while(1) { while(!DataRdyUSART1()); //wait for data data = ReadUSART1(); WriteDataXLCD(data); if(data=='Q') break; } CloseXLCD(); CloseUSART1(); return; }  2002 Microchip Technology Inc. Software Peripheral Library USART_ASYNCH_MODE&USART_EIGHT_BIT& USART_CONT_RX, 25); //read data //write to LCD //close modules apRNOVS^-page 73 ...

Page 78

... This function is called to generate an I sequence. A bit field in the global structure ( ) is set the slave device did not ack. BUS_STATUS.ack This error condition could also indicate a bus error on the SDA line error occurred this bit field BUS_STATUS 2 C bus acknowledge BUS_STATUS  2002 Microchip Technology Inc. ...

Page 79

... Function: Include: Prototype: Arguments: Remarks: Return Value: File Name: Code Example: SWNotAckI2C Function: File Name:  2002 Microchip Technology Inc. Software Peripheral Library far ram union i2cbus_state { struct { unsigned busy :1; bus state is busy unsigned clk :1; clock timeout or failure unsigned ack :1; acknowledge error or ...

Page 80

... This condition can be evaluated by testing the bit field bit field is 1, then there was an error, else This function operates identically to SWGetcI2C. swgtci2c.c char SWReadI2C(); 2 C implementation. file. swi2c16 clock line data byte. If there was this BUS_STATUS.clk  2002 Microchip Technology Inc. ...

Page 81

... Code Example: SWStopI2C Device: Function: Include: Prototype: Arguments: Remarks: Return Value: File Name: Code Example:  2002 Microchip Technology Inc. Software Peripheral Library PIC17CXXX 2 Generates I C restart bus condition. swi2c16.h void SWRestartI2C (void); None This function is called to generate an I None swrsti2c.c SWRestartI2C() ...

Page 82

... The clock and data pins are user defined in the file and must be set per application requirements. This function operates identically to SWPutcI2C. This function returns -1 if there was an error condition else returns a 0. swptci2c.c char x; SWWriteI2C(x implementation device. swi2c16.h  2002 Microchip Technology Inc. ...

Page 83

... SWPutcI2C(0xA0); // control byte swAckI2C(); var = SWPutcI2C(0x10); // word address swAckI2C(); var = SWPutcI2C(0x66); // data SWAckI2C(); SWStopI2C();  2002 Microchip Technology Inc. Software Peripheral Library Memory Device. In all the examples file and must be set per application swi2c16.h :1; // clock timeout or failure :1; // acknowledge error or not ACK :5 ...

Page 84

... SWPutcI2C(0xA1); SWAckI2C(); var = SWGetsI2C(rdptr,9); SWStopI2C(); } void current_address(void) { SWStartI2C(); SWPutcI2C(0xA1); // control byte SWAckI2C(); SWGetcI2C(); SWNotAckI2C(); SWStopI2C(); } void ack_poll(void) { SWStartI2C(); var = SWPutcI2C(0xA0); SWAckI2C(); while (BUS_STATUS.ack) { BUS_STATUS.ack = 0; SWRestartI2C(); var = SWPutcI2C(0xA0); // data SWAckI2C(); } SWStopI2C(); } apRNOVS^-page 80 // word address // control byte  2002 Microchip Technology Inc. ...

Page 85

... File Name: Code Example: OpenSWSPI Device: Function: Include: Prototype: Arguments: Remarks:  2002 Microchip Technology Inc. Software Peripheral Library PIC17C4X, PIC17C756 Clears the chip select (CS) pin that is specified in the header file. swspi16.h swspi16.h void SWClearCSSPI (void); None This function clears the I/O pin that is specified in be the chip select (CS) pin for the software SPI ...

Page 86

... This function operates identically to putcSWSPI. This function returns the byte of data that was read from the data in (DIN) pin of the software SPI. swspi16.c char addr; WriteSWSPI(addr); swspi16 swspi16.h  2002 Microchip Technology Inc. ...

Page 87

... SPI OpenSWSPI(); for(address=0;address<0x10;address++) { ClearCSSWSPI(); WriteSWSPI(0x02); WriteSWSPI(address); //send address h WriteSWSPI(address); //send address low SetCSSWSPI(); Delay10KTCYx(50); } return; }  2002 Microchip Technology Inc. Software Peripheral Library //clear CS pin //send write cmd //set CS pin //wait 5000,000TCY apRNOVS^-page 83 ...

Page 88

... UART to the correct input or ouput state and logic level. The I/O pins used for receive data (RXD) and transmit data (TXD) must be defined in the header file uart16_a.asm The definitions that must be made to ensure that the software UART operates correctly are: .  2002 Microchip Technology Inc. ...

Page 89

... Code Example: putcUART Function: File Name: putsUART Device: Function: Include: Prototype: Arguments: Remarks: Return Value: File Name: Code Example:  2002 Microchip Technology Inc. Software Peripheral Library I/O pin definitions SWTXD equ PORTx SWTXDpin equ ? TRIS_SWTXD equ DDRx SWRXD equ PORTx ...

Page 90

... WriteUART (static char data); data Byte of data written to software UART. The value of data can be any 8-bit value. This function writes the specified byte of data out the software UART. This function operates identically to putcUART. None uart16_a.asm char x; WriteUART(x); //bounce it back  2002 Microchip Technology Inc. ...

Page 91

... Function Descriptions 4.3.1 isalnum Device: Function: Include: Prototype: Arguments: Remarks: Return Value: File Name:  2002 Microchip Technology Inc. ® MPLAB C17 C COMPILER PIC17C4X, PIC17C756 Alphanumeric character classification. ctype.h char isalnum (static char ch); ch Character. This function determines alphanumeric character in the ranges of: ...

Page 92

... PIC17C4X, PIC17C756 Control character classification. ctype.h char iscntrl (static char ch); ch Character. This function determines control character in the ranges of: 0x00 to 0x1F 0x7f This function returns 1 when the argument is within the specified range of values; otherwise 0 is returned. iscntrl.c  2002 Microchip Technology Inc. ...

Page 93

... File Name: isupper Device: Function: Include: Prototype: Arguments: Remarks: Return Value: File Name:  2002 Microchip Technology Inc. General Software Library PIC17C4X, PIC17C756 Numeric character classification. ctype.h char isdigit (static char ch); ch Character. This function determines numeric character in the ranges of: ...

Page 94

... Character. This function determines ifch is a hexadecimal character in the ranges of (0x41 to 0x46 (0x61 to 0x66 (0x30 to 0x39) This function returns 1 when the argument is within the specified range of values; otherwise 0 is returned. isxdig.c  2002 Microchip Technology Inc. ...

Page 95

... Device: Function: Include: Prototype: Arguments: Remarks: Return Value: File Name:  2002 Microchip Technology Inc. General Software Library PIC17C4X, PIC17C756 Converts a string to an 8-bit signed byte. stdlib.h char atob (static char *string); string Pointer to ASCII string. This function converts the ASCII string into an 8-bit signed byte. ...

Page 96

... An 8-bit signed byte. string Pointer to ASCII string. This function converts the 8-bit signed byte in the argument value to a ASCII string representation. The string must be long enough to hold the ASCII representation which is: number(3) + sign(1) + null(  2002 Microchip Technology Inc. ...

Page 97

... Return Value: File Name: itoa Device: Function: Include: Prototype: Arguments: Remarks: Return Value: File Name:  2002 Microchip Technology Inc. General Software Library The conversion process uses the minimum amount of characters in the string. Some examples are: -120 5 characters - 57 4 characters -6 3 characters 0 ...

Page 98

... This function converts upper case alphabetical ASCII character provided that the argument is a valid lower case alphabetical haracter. This function returns a lower case character if the argument was upper case to begin with, otherwise the original character is returned. .c toupper  2002 Microchip Technology Inc. ...

Page 99

... Device: Function: Include: Prototype: Arguments: Remarks: Return Value: File Name:  2002 Microchip Technology Inc. General Software Library PIC17C4X, PIC17C756 Converts an 8-bit unsigned byte to string. stdlib.h void ubtoa (static unsigned char value, static char *string); value An 8-bit signed byte. string Pointer to ASCII string ...

Page 100

... Delay10TCYx (static unsigned char unit); unit The value of unit can be any 8-bit value from 2 to 255 value of 0 represents sending 256 to the function. This function creates delays of multiples of 10 instruction cycles. None dy1otcyx.asm for the instruction. Nop()  2002 Microchip Technology Inc. ...

Page 101

... Function: Include: Prototype: Arguments: Remarks: Return Value: File Name:  2002 Microchip Technology Inc. General Software Library PIC17C4X, PIC17C756 Delay of multiples of 100 instruction cycles (Tcy). delays.h void Delay100TCYx (static unsigned char unit); unit The value of unit can be any 8-bit value from 2 to 255 value of 0 represents sending 256 to the function ...

Page 102

... Pointer to destination array. src Pointer to source array. memsize Number of elements of src array copied into dest. This function copies the first memsize number of elements in src to the array dest. None memcpy.c  2002 Microchip Technology Inc. ...

Page 103

... Function: Include: Prototype: Arguments: Remarks: Return Value: File Name:  2002 Microchip Technology Inc. General Software Library PIC17C4X, PIC17C756 Copies the specified character into the destination array. mem.h void memset (static char *dest, static char value, static unsigned char memsize); dest Pointer to destination array ...

Page 104

... Returns the length of the string. string.h unsigned char strlen (static char *str); str Pointer to string. This function determines the length of the string minus the null character. This function returns the length of the string in an unsigned 8-bit byte. strlen.c  2002 Microchip Technology Inc. ...

Page 105

... Device: Function: Include: Prototype: Arguments: Remarks: Return Value: File Name:  2002 Microchip Technology Inc. General Software Library PIC17C4X, PIC17C756 Converts all upper case characters in a string to lower case. string.h void strlwr (static char *str); str Pointer to string. This function converts all upper case characters in str to lower case characters ...

Page 106

... MPLAB C17 C Compiler Libraries NOTES: apRNOVS^-page 102  2002 Microchip Technology Inc. ...

Page 107

... The representation is shown below: Format IEEE-754 Microchip where s is the sign bit the LSb of the exponent and placeholder for the mantissa and exponent bits.  2002 Microchip Technology Inc. ® MPLAB C17 C COMPILER Exponent Mantissa 0 sxxx xxxx ...

Page 108

... C function calls. The operands of the math routine are not passed as arguments to the function.Table 5-1 shows the syntax, operation, operand(s) required and where to extract the result of the operation. apRNOVS^-page 104 IEEE-754 TO MICROCHIP MICROCHIP TO IEEE-754  2002 Microchip Technology Inc. ...

Page 109

... MOVWF int1 MOVFP AARGB1, MOVWF int1+1 MOVFP AARGB2, MOVWF int1+2 MOVFP AARGB3, MOVWF int1+3  2002 Microchip Technology Inc. MATH FUNCTIONS Operation A·B (unsigned 32-bit integers) A·B (signed 32-bit integers) A/B (unsigned 32-bit integers) A/B (signed 32-bit integers) A·B (32-bit floating point) ...

Page 110

... Exp is the and decreasing to 2 and Z are values as described 10 - greater than or  2002 Microchip Technology Inc. ...

Page 111

... The exponent is stored in a biased format, which simply means that 0x7F has been added to the true exponent that of the number. To extract the exponent to be used in the above calculation, subtract 0x7F from the value stored in AEXP.  2002 Microchip Technology Inc – ...

Page 112

... For more details on the sources of error, please consult AN575. apRNOVS^-page 108 , a simple binary expansion is used, as shown in the formula below – 2 – Bit22 ) 2 ⋅ Bit21 ) 2 ⋅ + … → -12 -13 - -22 - – Bit0 ) 2 ⋅ -15 -16 -  2002 Microchip Technology Inc. ...

Page 113

... A section which has been assigned to a target memory block in the linker command file. The linker allocates an assigned section into its specified target memory block. Asynchronous Stimulus (Simulators) Data generated to simulate external inputs to a simulator device.  2002 Microchip Technology Inc. ® MPLAB C17 C COMPILER ...

Page 114

... On a PICmicro MCU device, data memory (RAM) is comprised of General Purpose Registers (GPRs) and Special Function Registers (SFRs). Some devices also have EEPROM data memory. apRNOVS^-page 110 ® ICE 2000, MPLAB ICD, MPLAB ICD 2) ® IDE v5.xx/v6.xx) ® microcontroller modes of  2002 Microchip Technology Inc. ...

Page 115

... Expressions are used in the operand field of the source line and may contain constants, symbols, or combinations of constants and/or symbols separated by arithmetic or logical operators. Each constant or symbol may be preceded by a plus or minus to indicate a positive or negative expression.  2002 Microchip Technology Inc. apRNOVS^-page 111 ...

Page 116

... However, if the current instruction changes the program counter, this prefetched instruction is explicitly ignored, causing a forced NOP cycle. G GPR General Purpose Register. The portion of PICmicro MCU data memory (RAM) available for general use, e.g., program-specific variables. apRNOVS^-page 112  2002 Microchip Technology Inc. ...

Page 117

... A sequence of bits that tells a central processing unit to perform a particular operation and can contain data to be used in the operation. Instruction Set (Language Tools) The collection of machine language instructions that a particular processor understands. Internal Linkage (Linkers)  2002 Microchip Technology Inc. ® apRNOVS^-page 113 ...

Page 118

... Such an input may be either "level sensitive" - the interrupt condition will persist as long as the input is active or "edge triggered" interrupt is signaled by a low-to-high or high-to-low transition on the input. Some processors have several interrupt request inputs allowing different priority interrupts. apRNOVS^-page 114  2002 Microchip Technology Inc. ...

Page 119

... Instructions are binary strings. The collection of all possible instructions for a particular processor is known as its "instruction set". Machine Language A set of instructions for a specific central processing unit, designed to be usable by a processor without being translated. Also called machine code.  2002 Microchip Technology Inc. apRNOVS^-page 115 ...

Page 120

... Instructions that are translated directly into machine code. Mnemonics are used to perform arithmetic and logical operations on data residing in program or data memory of a microcontroller. They can also move data in and out of registers and memory as well as change the flow of program execution. Also referred to as Opcodes. apRNOVS^-page 116  2002 Microchip Technology Inc. ...

Page 121

... Library/Precompiled Object Overview MPASM Assembler Microchip Technology’s relocatable macro assembler. MPASM assembler is a command-line or Windows-based PC application that provides a platform for developing assembly language code for Microchip’s PICmicro microcontroller (MCU) families, KeeLoq devices and Microchip memory devices. Generically, MPASM assembler will refer to the entire development platform including the macro assembler and utility functions ...

Page 122

... Opcodes Operational Codes. See Mnemonics. Operators Arithmetic symbols, like the plus sign ‘+’ and the minus sign ‘-’, that are used when forming well-defined expressions. Each operator has an assigned precedence. OTP apRNOVS^-page 118  2002 Microchip Technology Inc. ...

Page 123

... The memory area in a microcontroller where instructions are stored. Also, the memory in the emulator or simulator containing the downloaded target application firmware. Programmer A device used to program electrically programmable semiconductor devices such as microcontrollers.  2002 Microchip Technology Inc.   Windows 2000.  ...

Page 124

... The process of converting an instruction to an identical, but smaller instruction. This is useful for saving on code size. The assembler currently knows how to RELAX a CALL instruction into an RCALL instruction. This is done when the symbol that is being called is within +/- 32k instruction words from the current instruction. apRNOVS^-page 120  2002 Microchip Technology Inc. ...

Page 125

... The trace buffer captures the information that is on the bus at one instance. Therefore, one trace buffer entry will contain execution information for three instructions. The number of captured cycles from one piece of information to another for a single instruction execution is referred to as the skew.  2002 Microchip Technology Inc. apRNOVS^-page 121 ...

Page 126

... Step Into (MPLAB IDE v5.xx/v6.xx) This command is the same as Single Step. Step Into (as opposed to Step Over) follows a CALL instruction into a subroutine. apRNOVS^-page 122  2002 Microchip Technology Inc. ...

Page 127

... Lines of text that you build for inserting into your files at a later time. The MPLAB Editor stores templates in template files. Tool Bar (MPLAB IDE v5.xx/v6.xx) A row or column of icons that you can click on to execute MPLAB IDE functions.  2002 Microchip Technology Inc. apRNOVS^-page 123 ...

Page 128

... Watch Variable (MPLAB IDE v5.xx/v6.xx) A variable that you may monitor during a debugging session in a watch window. Watch Window (MPLAB IDE v5.xx/v6.xx) Watch windows contain a list of watch variables that are updated at each breakpoint. apRNOVS^-page 124 ??( ??) ??< ??> ??= [ ] { } # ??/ ??' ??! ??- \ ^ | ~  2002 Microchip Technology Inc. ...

Page 129

... Example of Use ........................................ 21 Open ........................................................ 17 Read ........................................................ 20 Character Classification ................................. 99 Alphabetic .............................................. 100 Alphanumeric ........................................... 99 ASCII ...................................................... 100 Control ................................................... 100 Decimal .................................................. 101 Hexadecimal .......................................... 102 Lower Case Alphabetic .......................... 101  2002 Microchip Technology Inc. ® MPLAB C17 C COMPILER Index Upper Case Alphabetic .......................... 101 Characters Control .................................................... 100 ClearSWCSSPI ............................................... 93 Clock_test ....................................................... 86 CloseADC ....................................................... 12 CloseCapture ...

Page 130

... L LCD, External ..................................................79 Busy ..........................................................79 Example of Use ........................................85 Open .........................................................80 Put Character ...........................................81 Put ROM String ........................................81 Read Address ...........................................82 Read Data ................................................82 Set Character Generator Address ............83 Set Display Data Address .........................83 Write Command ........................................83  2002 Microchip Technology Inc. ...

Page 131

... String to Unsigned Byte (A to UB) ......... 104 String to Unsigned Integer (A to UI) ....... 104 Unsigned Byte to String ( ......... 107 Unsigned Integer to String ( ....... 107 Numeric Character ....................................... 101 O Object Files, Precompiled .......................... 9, 10 OpenADC ....................................................... 13 OpenCapture .................................................. 17  2002 Microchip Technology Inc. OpenI2C ......................................................... 24 OpenMwire ..................................................... 42 OpenPORTB .................................................. 38 OpenPWM ...................................................... 47 OpenRA0INT .................................................. 35 OpenSPI ......................................................... 58 OpenSWSPI ................................................... 93 OpenTimer ...................................................... 65 OpenUART ..................................................... 96 OpenUSART ...

Page 132

... Example of Use ........................................ 98 Get Character ........................................... 96 Get String ................................................. 96 Open ........................................................ 96 Put Character ........................................... 97 Put String ................................................. 97 Read ......................................................... 98 Write ......................................................... 98 ubtoa ............................................................. 107 uitoa .............................................................. 107 Upper Case Characters ................................ 113 USART ..............................................................iii USART, Hardware .......................................... 70 Buzy ......................................................... 70 Close ........................................................ 70 Data Ready .............................................. 71 Example of Use ........................................ 77 Get Character ........................................... 71 Get String ................................................. 71 Open ........................................................ 73  2002 Microchip Technology Inc. ...

Page 133

... Put Character ........................................... 73 Put ROM String ........................................ 74 Put String ................................................. 74 Read ........................................................ 75 Write ........................................................ 75 V Variables Used by the Floating Point Libraries .................... 116 W Watchdog Timer (WDT) ........................... 52, 54 WriteCmdXLCD .............................................. 83 WriteDataXLCD .............................................. 84 WriteI2C ......................................................... 29 WriteMwire ..................................................... 44 WriteSPI ......................................................... 60 WriteSWSPI ................................................... 94 WriteTimer ...................................................... 68 WriteUART ..................................................... 98 WriteUSART ................................................... 75  2002 Microchip Technology Inc. Index DS51296A-page 129 ...

Page 134

... MPLAB C17 C Compiler Libraries NOTES: DS51296A-page 130  2002 Microchip Technology Inc. ...

Page 135

... NOTES:  2002 Microchip Technology Inc. Index DS51296A-page 131 ...

Page 136

... Korea Microchip Technology Korea 168-1, Youngbo Bldg. 3 Floor Samsung-Dong, Kangnam-Ku Seoul, Korea 135-882 Tel: 82-2-554-7200 Fax: 82-2-558-5934 Singapore Microchip Technology Singapore Pte Ltd. 200 Middle Road #07-02 Prime Centre Singapore, 188980 Tel: 65-6334-8870 Fax: 65-6334-8850 Taiwan Microchip Technology (Barbados) Inc., Taiwan Branch 11F-3, No ...

Related keywords