Ibrahim Dogan - Advanced PIC Microcontroller Projects in C

Здесь есть возможность читать онлайн «Ibrahim Dogan - Advanced PIC Microcontroller Projects in C» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Город: Burlington, Год выпуска: 2008, ISBN: 2008, Издательство: Elsevier Ltd, Жанр: Программирование, Компьютерное железо, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

Advanced PIC Microcontroller Projects in C: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Advanced PIC Microcontroller Projects in C»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

• The only project book on the PIC 18 series using the C programming language
• Features 20 complete, tried and test projects
• Includes a CD-ROM of all the programs, hex listings, diagrams, and data sheets

Advanced PIC Microcontroller Projects in C — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Advanced PIC Microcontroller Projects in C», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

create a 1 second delay between the flashes.

Programmer: Dogan Ibrahim

File: FLASH2.C

Date: May, 2007

********************************************************************/

#define LED PORTB.0

#define ON 1

#define OFF 0

#define One_Second_Delay Delay_ms(1000)

void main() {

TRISB = 0; // Configure PORTB as output

for(;;) // Endless loop

{

LED = ON; // Turn ON LED

One_Second_Delay; // 1 second delay

LED = OFF; // Turn OFF LED

One_Second_Delay; // 1 second delay

}

}

картинка 86

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.

/***********************************************************************

READING FROM THE EEPROM

=========================

This program reads data from addresses 0 to 0x2F of the EEPROM and then

sends this data to PORTB of the microcontroller.

Programmer: Dogan Ibrahim

File: EEPROM.C

Date: May, 2007

************************************************************************/

void main() {

unsigned int j;

unsigned char Temp;

TRISB = 0; // Configure PORTB as output

for (j=0; j <= 0x2F; j++) {

Temp = Eeprom_Read(j);

PORTB = Temp;

Delay_ms(20);

}

}

картинка 87

Figure 4.18: Program to read from the EEPROM

4.3.2 LCD Library

One thing all microcontrollers lack is some kind of video display. A video display would make a microcontroller much more user-friendly, enabling text messages, graphics, and numeric values to be output in a more versatile manner than with 7-segment displays, LEDs, or alphanumeric displays. Standard video displays require complex interfaces and their cost is relatively high. LCDs are alphanumeric (or graphic) displays which are frequently used in microcontroller-based applications. These display devices come in different shapes and sizes. Some LCDs have forty or more character lengths with the capability to display several lines. Others can be programmed to display graphic images. Some modules offer color displays, while others incorporate backlighting so they can be viewed in dimly lit conditions.

There are basically two types of LCDs as far as the interfacing technique is concerned: parallel and serial. Parallel LCDs (e.g., the Hitachi HD44780 series) are connected to the microcontroller circuitry such that data is transferred to the LCD using more than one line, usually four or eight data lines. Serial LCDs are connected to a microcontroller using one data line only, and data is transferred using the RS232 asynchronous data communications protocol. Serial LCDs are generally much easier to work with but more costly than parallel ones. In this book only parallel LCDs are discussed, as they are used more often in microcontroller-based projects.

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «Advanced PIC Microcontroller Projects in C»

Представляем Вашему вниманию похожие книги на «Advanced PIC Microcontroller Projects in C» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «Advanced PIC Microcontroller Projects in C»

Обсуждение, отзывы о книге «Advanced PIC Microcontroller Projects in C» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x