Выбрать главу

  LED = OFF;        // Turn OFF LED

  One_Second_Delay; // 1 second delay

 }

}

Figure 4.17: Another program to flash an LED

4.3 mikroC Library Functions

A large set of library functions is available with the mikroC compiler. These library functions can be called from anywhere in a program, and they do not require that header files are included in the program. The mikroC user manual gives a detailed description of each library function, with examples. In this section, the available library functions are identified, and the important and commonly used library functions are described in detail, with examples.

Table 4.2 gives a list of the mikroC library functions, organized in functional order.

Table 4.2: mikroC library functions

Library Description
ADC Analog-to-digital conversion functions
CAN CAN bus functions
CANSPI SPI-based CAN bus functions
Compact Flash Compact flash memory functions
EEPROM EEPROM memory read/write functions
Ethernet Ethernet functions
SPI Ethernet SPI-based Ethernet functions
Flash Memory Flash memory functions
Graphics LCD Standard graphics LCD functions
T6963C Graphics LCD T6963-based graphics LCD functions
I²C I²C bus functions
Keypad Keypad functions
LCD Standard LCD functions
Manchester Code Manchester code functions
Multi Media Multimedia functions
One Wire One wire functions
PS/2 PS/2 functions
PWM PWM functions
RS-485 RS-485 communication functions
Sound Sound functions
SPI SPI bus functions
USART USART serial communication functions
Util Utilities functions
SPI Graphics LCD SPI-based graphics LCD functions
Port Expander Port expander functions
SPI LCD SPI-based LCD functions
ANSI C Ctype C Ctype functions
ANSI C Math C Math functions
ANSI C Stdlib C Stdlib functions
ANSI C String C String functions
Conversion Conversion functions
Trigonometry Trigonometry functions
Time Time functions

Some of the frequently used library functions are:

• EEPROM library

• LCD library

• Software UART library

• Hardware USART library

• Sound library

• ANSI C library

• Miscellaneous library

4.3.1 EEPROM Library

The EEPROM library includes functions to read data from the on-chip PIC microcontroller nonvolatile EEPROM memory, or to write data to this memory. Two functions are provided:

• Eeprom_Read

• Eeprom_Write

The Eeprom_Read function reads a byte from a specified address of the EEPROM. The address is of type integer, and thus the function supports PIC microcontrollers with more than 256 bytes. A 20ms delay should be used between successive reads from the EEPROM to guarantee the return of correct data. In the following example, the byte at address 0x1F of the EEPROM is read and stored in variable Temp:

Temp = Eeprom_Read(0x1F);

The Eeprom_Write function writes a byte to a specified address of the EEPROM. The address is of type integer and thus the function supports PIC microcontrollers with more than 256 bytes. A 20ms delay should be used between successive reads or writes to the EEPROM to guarantee the correct transfer of data to the EEPROM. In the following example, number 0x05 is written to address 0x2F of the EEPROM:

Eeprom_Write(0x2F, 0x05);

Example 4.11

Write a program to read the contents of EEPROM from address 0 to 0x2F and then send this data to PORTB of a PIC microcontroller.

Solution 4.11

The required program is given in Figure 4.18. A for loop is used to read data from the EEPROM and then send it to PORT B of the microcontroller. Notice that a 20ms delay is used between each successive read.