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

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

Интервал:

Закладка:

Сделать

//

#task(rate=2s, max=10ms)

void task_B3() {

output_toggle(PIN_B3); // Toggle RB3

}

//

// Start of MAIN program

//

void main() {

set_tris_b(0); // Configure PORTB as outputs

rtos_run(); // Start RTOS

}

картинка 323

Figure 10.8: Program listing of the project

The file that contains CCS RTOS declarations should be included at the beginning of the program. The preprocessor command #use delay tells the compiler that we are using a 4MHz clock. Then the RTOS timer is declared as Timer 0, and minor_cycle time is declared as 10ms using the preprocessor command #use rtos .

The program consists of four similar tasks:

task_B0 flashes the LED connected to RB0 at a rate of 250ms. Thus, the LED is ON for 250ms, then OFF for 250ms, and so on. CCS statement output_toggle is used to change the state of the LED every time the task is called. In the CCS compiler PIN_B0 refers to port pin RB0 of the microcontroller.

task_B1 flashes the LED connected to RB1 at a rate of 500ms as described.

task_B2 flashes the LED connected to RB2 every second as described.

• Finally, task_B3 flashes the LED connected to RB3 every two seconds as described.

The program given in Figure 10.8 is a multi-tasking program where the LEDs flash independently of each other and concurrently.

PROJECT 10.2 — Random Number Generator

In this slightly more complex RTOS project, a random number between 0 and 255 is generated. Eight LEDs are connected to PORTB of a PIC18F452 microcontroller. In addition, a push-button switch is connected to bit 0 of PORTD (RD0), and an LED is connected to bit 7 of PORTD (RD7).

Three tasks are used in this project: Live , Generator , and Display .

• Task Live runs every 200ms and flashes the LED on port pin RD7 to indicate that the system is working.

• Task Generator increments a variable from 0 to 255 continuously and checks the status of the push-button switch. When the push-button switch is pressed, the value of the current count is sent to task Display using a messaging queue.

• Task Display reads the number from the message queue and sends the received byte to the LEDs connected to PORTB. Thus, the LEDs display a random pattern every time the push button is pressed.

Figure 10.9 shows the project’s block diagram. The circuit diagram is given in Figure 10.10. The microcontroller is operated from a 4MHz crystal.

Figure 109 Block diagram of the project Figure 1010 Circuit diagram of the - фото 324

Figure 10.9: Block diagram of the project

Figure 1010 Circuit diagram of the project The program listing of the project - фото 325

Figure 10.10: Circuit diagram of the project

The program listing of the project (RTOS2.C) is given in Figure 10.11. The main part of the program is in the later portion, and it configures PORTB pins as outputs. Also, bit 0 of PORTD is configured as input and other pins of PORTD are configured as outputs.

/////////////////////////////////////////////////////////////////////////////

//

// SIMPLE RTOS EXAMPLE - RANDOM NUMBER GENERATOR

// --------------------------------------------------------------------------

//

// This is a simple RTOS example. 8 LEDs are connected to PORTB

// of a PIC18F452 microcontroller. Also, a push-button switch is

// connected to port RC0 of PORTC, and an LED is connected to port

// RC7 of the microcontroller. The push-button switch is normally at logic 1.

//

// The program consists of 3 tasks called "Generator", "Display", and "Live".

//

// Task "Generator" runs in a loop and increments a counter from 0 to 255.

// This task also checks the state of the push-button switch. When the

// push-button switch is pressed, the task sends the value of the count to the

// "Display" task using messaging passing mechanism. The “Display” task

// receives the value of count and displays it on the PORTB LEDs.

//

// Task "Live" flashes the LED connected to port RC7 at a rate of 250ms.

// This task is used to indicate that the system is working and is ready for

// the user to press the push-button.

//

// The microcontroller is operated from a 4MHz crystal

//

// Programmer: Dogan Ibrahim

// Date: September, 2007

// File: RTOS2.C

//

//////////////////////////////////////////////////////////////////////////////

#include "C:\NEWNES\PROGRAMS\rtos.h"

#use delay (clock=4000000)

int count;

//

// Define which timer to use and minor_cycle for RTOS

//

#use rtos(timer=0, minor_cycle=1ms)

//

// Declare TASK "Live" - called every 200ms

// This task flashes the LED on port RC7

//

#task(rate=200ms, max=1ms)

void Live() {

output_toggle(PIN_D7);

}

//

// Declare TASK "Display" - called every 10ms

//

#task(rate=10ms, max=1ms, queue=1)

void Display() {

if (rtos_msg_poll() > 0) // Is there a message ?

{

output_b(rtos_msg_read()); // Send to PORTB

}

}

//

// Declare TASK "Generator" - called every millisecond

//

#task(rate=1ms, max=1ms)

void Generator() {

count++; // Increment count

if (input(PIN_D0) == 0) // Switch pressed ?

{

rtos_msg_send(Display,count); // send a message

}

}

//

// Start of MAIN program

//

void main() {

set_tris_b(0); // Configure PORTB as outputs

set_tris_d(1); // RD0=input, RD7=output

rtos_run(); // Start RTOS

}

картинка 326

Figure 10.11: Program listing of the project

PROJECT 10.3 — Voltmeter with RS232 Serial Output

In this RTOS project, which is more complex than the preceding ones, the voltage is read using an A/D converter and then sent over the serial port to a PC. The project consists of three tasks: Live , Get_voltage , and To_RS232 .

• Task Live runs every 200ms and flashes the LED connected to port pin RD7. This LED indicates that the system is working.

• Task Generator runs every millisecond and increments a byte variable called count continuously. When the push-button switch is pressed, pin 0 of PORTD (RD0) goes to logic 0. When this happens, the current value of count is sent to task Display using RTOS function call rtos_msg_send(display, count) , where Display is the name of the task where the message is sent and count is the byte sent.

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

Интервал:

Закладка:

Сделать

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