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

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

Интервал:

Закладка:

Сделать

The block diagram of the project is shown in Figure 6.45. The circuit diagram is given in Figure 6.46. A PIC18F452 microcontroller with a 4MHz resonator is used in the project. Columns of the keypad are connected to port pins RB0–RB3 and rows are connected to port pins RB4–RB7 via pull-down resistors. The LCD is connected to PORTC in default mode, as in Figure 6.39. An external reset button is also provided to reset the microcontroller should it be necessary.

Figure 645 Block diagram of the project Figure 646 Circuit diagram of the - фото 221

Figure 6.45: Block diagram of the project

Figure 646 Circuit diagram of the project Project PDL The project PDL is - фото 222

Figure 6.46: Circuit diagram of the project

Project PDL

The project PDL is shown in Figure 6.47. The program consist of two parts: function getkeypad and the main program. Function getkeypad receives a key from the keypad. Inside the main program the two numbers and the required operation are received from the keypad. The microcontroller performs the required operation and displays the result on the LCD.

Function getkeypad:

START

IF a key is pressed

Get the key code (0 to 15)

Return the key code

ENDIF

END

Main program:

START

Configure LCD

Wait 2 seconds

DO FOREVER

Display No1:

Read first number

Display No2:

Read second number

Display Op:

Read operation

Perform operation

Display result

Wait 5 seconds

ENDDO

END

картинка 223

Figure 6.47: Project PDL

Project Program

The program listing for the program KEYPAD.C is given in Figure 6.48. Each key is given a numeric value as follows:

0 1 2 3

4 5 6 7

8 9 10 11

12 13 14 15

The program consists of a function called getkeypad , which reads the pressed keys, and the main program. Variable MyKey stores the key value (0 to 15) pressed, variables Op1 and Op2 store respectively the first and second numbers entered by the user. All these variables are cleared to zero at the beginning of the program. A while loop is then formed to read the first number and store in variable Op1 . This loop exits when the user presses the ENTER key. Similarly, the second number is read from the keyboard in a second while loop. Then the operation to be performed is read and stored in variable MyKey , and a switch statement is used to perform the required operation and store the result in variable Calc . The result is converted into a string array using function LongToStr . The leading blank characters are then removed as in Project 8. The program displays the result on the LCD, waits for five seconds, and then clears the screen and is ready for the next calculation. This process is repeated forever.

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

CALCULATOR WITH KEYPAD AND LCD

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

In this project a 4 x 4 keypad is connected to PORTB of a PIC18F452

microcontroller. Also an LCD is connected to PORTC. The project is a simple

calculator which can perform integer arithmetic.

The keys are organized as follows:

0 1 2 3

4 5 6 7

8 9 10 11

12 13 14 15

The keys are labeled as follows:

1 2 3 4

5 6 7 8

9 0 Enter

+ − * /

Author: Dogan Ibrahim

Date: July 2007

File: KEYPAD.C

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

#define MASK 0xF0

#define Enter 11

#define Plus 12

#define Minus 13

#define Multiply 14

#define Divide 15

//

// This function gets a key from the keypad

//

unsigned char getkeypad() {

unsigned char i, Key = 0;

PORTB = 0x01; // Start with column 1

while((PORTB MASK) == 0) // While no key pressed

{

PORTB = (PORTB << 1); // next column

Key++; // column number

if (Key == 4) {

PORTB = 0x01; // Back to column 1

Key = 0;

}

}

Delay_Ms(20); // Switch debounce

for(i = 0x10; i !=0; i <<= 1) // Find the key pressed

{

if ((PORTB i) != 0) break;

Key = Key + 4;

}

PORTB=0x0F;

while ((PORTB MASK) != 0); // Wait until key released

Delay_Ms(20); // Switch debounce

return (Key); // Return key number

}

//

// Start of MAIN program

//

void main() {

unsigned char MyKey, i,j,lcd[5],op[12];

unsigned long Calc, Op1, Op2;

TRISC = 0; // PORTC are outputs (LCD)

TRISB = 0xF0; // RB4-RB7 are inputs

//

// Configure LCD

//

Lcd_Init(&PORTC); // LCD is connected to PORTC

Lcd_Cmd(LCD_CLEAR);

Lcd_Out(1,1, "CALCULATOR"); // Display CALCULATOR

Delay_ms(2000); // Wait 2 seconds

Lcd_Cmd(LCD_CLEAR); // Clear display

//

// Program loop

//

for(;;) // Endless loop

{

MyKey = 0;

Op1 = 0;

Op2 = 0;

Lcd_Out(1,1, "No1: "); // Display No1:

while(1) // Get first no

{

MyKey = getkeypad();

if (MyKey == Enter) break; // If ENTER pressed

MyKey++;

if (MyKey == 10) MyKey = 0; // If 0 key pressed

Lcd_Chr_Cp(MyKey + '0');

Op1 = 10*Op1 + MyKey; // First number in Op1

}

Lcd_Out(2,1, "No2: "); // Display No2:

while(1) // Get second no

{

MyKey = getkeypad();

if (MyKey == Enter) break; // If ENTER pressed

MyKey++;

if (MyKey == 10) MyKey = 0; // If 0 key pressed

Lcd_Chr_Cp(MyKey + '0');

Op2 = 10*Op2 + MyKey; // Second number in Op2

}

Lcd_Cmd(LCD_CLEAR); // Clear LCD

Lcd_Out(1,1, "Op: "); // Display Op:

MyKey = getkeypad(); // Get operation

Lcd_Cmd(LCD_CLEAR);

Lcd_Out(1,1, "Res="); // Display Res=

switch(MyKey) // Perform the operation

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

Интервал:

Закладка:

Сделать

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