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», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

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

Интервал:

Закладка:

Сделать

rec_size++;

LongToStr(rec_size,txt);

Newline();

Text_To_Usart("Saving record:");

Text_To_Usart(txt);

Delay_ms(10000);

}

break;

case '3':

//

// Start the A/D converter, get temperature readings every

// 10 seconds, and then APPEND to the existing file

//

Text_To_Usart("Appending data to the existing file...");

Newline();

ret_status = Mmc_Fat_Assign(&filename,1); // Assign the file

if (!ret_status) {

Text_To_Usart("File does not exist - can not append...");

Newline();

Text_To_Usart("Restart the program and choose option 2...");

Newline();

for(;;);

} else {

//

// Read the temperature from A/D converter, format and save

//

for(;;) {

Mmc_Fat_Append();

Get_Temperature();

Mmc_Fat_Write(temperature,9);

rec_size++;

LongToStr(rec_size,txt);

Newline();

Text_To_Usart("Appending new record:");

Text_To_Usart(txt);

Delay_ms(10000);

}

}

default:

Text_To_Usart("Wrong choice...Restart the program and try again...");

Newline();

for(;;);

}

}

картинка 249

Figure 7.15: Program listing of the project

The following functions are created at the beginning of the program, before the main program:

Newline sends a carriage return and a line feed to the UART so the cursor moves to the next line.

Text_To_Usart receives a text string as its argument and sends it to the UART to display on the PC screen.

Get_Temperature starts the A/D conversion and receives the converted data into a variable called Vin . The voltage corresponding to this value is then calculated in millivolts and divided by 10 to find the actual measured temperature in °C. The decimal part of the found temperature is then converted into string form using function LongToStr . The leading spaces are removed from this string, and the resulting string is stored in character array temperature . Then the fractional parts of the measured temperature, a carriage return, and a line feed are added to this character array, which is later written to the SD card.

The following operations are performed inside the main program:

• Initialize the UART to 2400 baud

• Initialize the SPI bus

• Initialize the FAT file system

• Display menu on the PC screen

• Get a choice from the user (1, 2, or 3)

• If the choice = 1, assign the temperature file, read the temperature records, and display them on the PC screen

• If the choice = 2, create a new temperature file, get new temperature readings every ten seconds, and store them in the file

• If the choice = 3, assign to the temperature file, get new temperature readings every ten seconds, and append them to the existing temperature file

• If the choice is not 1, 2, or 3, display an error message on the screen The menu options are described here in more detail:

Option 1 : The program attempts to assign the existing temperature file. If the file does not exist, the error messages “File does not exist…No saved data…” and “Restart the program and save data to the file…” are displayed on the screen, and the user is expected to restart the program. If, on the other hand, the temperature file already exists, then the message: “Sending saved data to the PC…” is displayed on the PC screen. Function Mmc_Fat_Reset is called to set the file pointer to the beginning of the file and also return the size of the file in bytes. Then a for loop is formed, temperature records are read from the card one byte at a time using function Mmc_Fat_Read , and these records are sent to the PC screen using function Usart_Write . At the end of the data the message “End of data…” is sent to the PC screen.

Option 2 : In this option, the message “Saving data in a NEW file…” is sent to the PC screen, and a new file is created using function Mmc_Fat_Assign with the create flag set to 0x80. The message “TEMPERATURE DATA – SAVED EVERY 10 SECONDS” is written on the first line of the file using function Mmc_Fat_Write . Then, a for loop is formed, the SD card is set to file append mode by calling function Mmc_Fat_Append , and a new temperature reading is obtained by calling function Get_Temperature . The temperature is then written to the SD card. Also, the current record number appears on the PC screen to indicate that the program is actually working. This process is repeated after a ten-second delay.

Option 3 : This option is very similar to Option 2, except that a new file is not created but rather the existing temperature file is opened in read mode. If the file does not exist, then an error message is displayed on the PC screen.

Default : If the user entry is a number other than 1, 2, or 3, then this option runs and displays the error message “Wrong choice…Restart the program and try again…” on the PC screen.

The project can be tested by connecting the output of the microcontroller to the serial port of a PC (e.g., COM1) and then running the HyperTerminal terminal emulation software. Set the communications parameters to 2400 baud, 8 data bits, 1 stop bit, and no parity bit. Figure 7.16 shows a snapshot of the PC screen when Option 2 is selected to save the temperature records in a new file. Notice that the current record numbers are displayed on the screen as they are written to the SD card.

Figure 716 Saving temperature records on an SD card with Option 2 Figure 717 - фото 250

Figure 7.16: Saving temperature records on an SD card with Option 2

Figure 7.17 shows a screen snapshot where Option 1 is selected to read the temperature records from the SD card and display them on the PC screen.

Figure 717 Displaying the records on the PC screen with Option 1 Finally - фото 251

Figure 7.17: Displaying the records on the PC screen with Option 1

Finally, Figure 7.18 shows a screen snapshot when Option 3 is selected to append the temperature readings to the existing file.

Figure 718 Saving temperature records on an SD card with Option 3 CHAPTER 8 - фото 252

Figure 7.18: Saving temperature records on an SD card with Option 3

CHAPTER 8

Advanced PIC18 Projects — USB Bus Projects

The Universal Serial Bus (USB) is one of the most common interfaces used in electronic consumer products today, including PCs, cameras, GPS devices, MP3 players, modems, printers, and scanners, to name a few.

The USB was originally developed by Compaq, Microsoft, Intel, and NEC, and later by Hewlett-Packard, Lucent, and Phillips as well. These companies eventually formed the nonprofit corporation USB Implementers Forum Inc. to organize the development and publication of USB specifications.

This chapter describes the basic principles of the USB bus and shows how to use USB-based applications with PIC microcontrollers. The USB bus is a complex protocol. A complete discussion of its design and use is beyond the scope of this chapter. Only the basic principles, enough to be able to use the USB bus, are outlined here. On the other hand, the functions offered by the mikroC language that simplify the design of USB-based microcontroller projects are described in some detail.

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

Интервал:

Закладка:

Сделать

Похожие книги на «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