Файл: The PIC Microcontroller Book for beginning (Nebojsa Matic).pdf

ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 15.06.2025

Просмотров: 1186

Скачиваний: 0

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

Chapter 6 - Samples

Previous page

Table of contents

Chapter overview

Next page

Serial Communication

SCI is an abbreviation for Serial Communication Interface and, as a special subsystem, it exists on most microcontrollers. When it is not available, as is the case with PIC16F84, it can be created in software.

As with hardware communication, we use standard NRZ (Non Return to Zero) format also known as 8 (9)-N-1, or 8 or 9 data bits, without parity bit and with one stop bit. Free line is defined as the status of logic one. Start of transmission - Start Bit, has the status of logic zero. The data bits follow the start bit (the first bit is the low significant bit), and after the bits we place the Stop Bit of logic one. The duration of the stop bit 'T' depends on the speed of transmission and is adjusted according to the needs of the transmission. For the transmission speed of 9600 baud, T is 104 uS.

1.CD (Carrier Detect)

2.RXD (Receive Data)

3.TXD (Transmit Data)

4.DTR (Data terminal Ready)

5.GND (Ground)

6.DSR (Data Set Ready)

7.RTS (Request To Send)

8.CTS (Clear To Send)

9.RI (Ring Indicator)

Pin designations on RS232 connector

In order to connect a microcontroller to a serial port on a PC computer, we need to adjust the level of the signals so communicating can take place. The signal level on a PC is -10V for logic zero, and +10V for logic one. Since the signal level on the microcontroller is +5V for logic one, and 0V for logic zero, we need an intermediary stage that will convert the levels. One chip specially designed for this task is MAX232. This chip receives signals from -10 to +10V and converts them into 0 and 5V.

The circuit for this interface is shown in the diagram below:

http://www.mikroelektronika.co.yu/english/product/books/PICbook/6_12Poglavlje.htm (1 of 6) [4/2/2003 16:19:14]

Chapter 6 - Samples

Connecting a microcontroller to a PC via a MAX232 line interface chip.

File RS232.inc contains a group of macros used for serial communication.

http://www.mikroelektronika.co.yu/english/product/books/PICbook/6_12Poglavlje.htm (2 of 6) [4/2/2003 16:19:14]

Chapter 6 - Samples

http://www.mikroelektronika.co.yu/english/product/books/PICbook/6_12Poglavlje.htm (3 of 6) [4/2/2003 16:19:14]

Chapter 6 - Samples

Using the macro:

RS232init Macro for initializing RB0 pin and line for transmitting data (TX-pin). Example: RS232init

SEND S_string Sending ASCII character. Argument is ASCII sign.

Example: SEND 'g'

SENDw Sending data found in W register.

Example: movlw 't'

SENDw

RECEIVE macro in interrupt routine receives data for RS232 and stores it in RXD register

Example:

At the beginning of the main program, we need to declare variables RS_TEMP1, RE_TEMP2, TXD, RXD and TX pin on microcontroller. After resetting a microcontroller the program sends a greeting message to PC computer: $ PIV16F84 on line $, and is ready to receive data from RX line.

We can send and receive data from PC computer from some communication program. When microcontroller receives data, it will send a message: Character received from PIC16F84: x, thus confirming that reception was successful.

http://www.mikroelektronika.co.yu/english/product/books/PICbook/6_12Poglavlje.htm (4 of 6) [4/2/2003 16:19:14]


Chapter 6 - Samples

Main program:

http://www.mikroelektronika.co.yu/english/product/books/PICbook/6_12Poglavlje.htm (5 of 6) [4/2/2003 16:19:14]

Chapter 6 - Samples

Previous page

Table of contents

Chapter overview

Next page

© Copyright 1999. mikroElektronika. All Rights Reserved. For any comments contact webmaster.

http://www.mikroelektronika.co.yu/english/product/books/PICbook/6_12Poglavlje.htm (6 of 6) [4/2/2003 16:19:14]


Appendix A - Instruction Set

Previous page

Table of contents

Chapter overview

Next page

Appendix A

Instruction Set

Introduction

Appendix contains all instructions presented separately with examples for their use. Syntax, description and its effects on status bits are given for each instruction.

A.1 MOVLW

A.2 MOVWF

A.3 MOVF

A.4 CLRW

A.5 CLRF

A.6 SWAPF

A.7 ADDLW

A.8 ADDWF

A.9 SUBLW

A.10 SUBWF

A.11 ANDLW

A.12 ANDWF

A.13 IORLW

A.14 IORWF

A.15 XORLW

A.16 XORWF

A.17 INCF

A.18 DECF

A.19 RLF

A.20 RRF

A.21 COMF

A.22 BCF

A.23 BSF

A.24 BTFSC

A.25 BTFSS

A.26 INCFSZ

A.27 DECFSZ

A.28 GOTO

A.29 CALL

A.30 RETURN

A.31 RETLW

A.32 RETFIE

A.33 NOP

A.34 CLRWDT

http://www.mikroelektronika.co.yu/english/product/books/PICbook/A_Dodatak.htm (1 of 21) [4/2/2003 16:19:25]

Appendix A - Instruction Set

A.35 SLEEP

A.1 MOVLW Write constant in W register

A.2 MOVWF Copy W to f

A.3 MOVF Copy f to d

http://www.mikroelektronika.co.yu/english/product/books/PICbook/A_Dodatak.htm (2 of 21) [4/2/2003 16:19:25]


Appendix A - Instruction Set

A.4 CLRW Write 0 in W

A.5 Write 0 in f

http://www.mikroelektronika.co.yu/english/product/books/PICbook/A_Dodatak.htm (3 of 21) [4/2/2003 16:19:25]

Appendix A - Instruction Set

A.6 SWAPF Copy the nibbles from f to d crosswise

A.7 ADDLW Add W to a constant

http://www.mikroelektronika.co.yu/english/product/books/PICbook/A_Dodatak.htm (4 of 21) [4/2/2003 16:19:25]

Appendix A - Instruction Set

A.8 ADDWF Add W to f

A.9 SUBLW Subtract W from a constant

http://www.mikroelektronika.co.yu/english/product/books/PICbook/A_Dodatak.htm (5 of 21) [4/2/2003 16:19:25]

Appendix A - Instruction Set

A.10 SUBWF Subtract W from f

A.11 ANDLW Logic AND W with constant

http://www.mikroelektronika.co.yu/english/product/books/PICbook/A_Dodatak.htm (6 of 21) [4/2/2003 16:19:25]

Appendix A - Instruction Set

A.12 ANDWF Logic AND W with f

A.13 IORLW Logic OR W with constant

http://www.mikroelektronika.co.yu/english/product/books/PICbook/A_Dodatak.htm (7 of 21) [4/2/2003 16:19:25]

Appendix A - Instruction Set

A.14 IORWF Logic OR W with f

A.15 XORLW Logic exclusive OR W with constant

http://www.mikroelektronika.co.yu/english/product/books/PICbook/A_Dodatak.htm (8 of 21) [4/2/2003 16:19:25]

Appendix A - Instruction Set

A.16 XORWF Logic exclusive OR W with f

A.17 INCF

Increment f

http://www.mikroelektronika.co.yu/english/product/books/PICbook/A_Dodatak.htm (9 of 21) [4/2/2003 16:19:25]

Appendix A - Instruction Set

A.18 DECF

Decrement f

http://www.mikroelektronika.co.yu/english/product/books/PICbook/A_Dodatak.htm (10 of 21) [4/2/2003 16:19:25]

Appendix A - Instruction Set

A.19 RLF

Rotate f to the left through CARRY

http://www.mikroelektronika.co.yu/english/product/books/PICbook/A_Dodatak.htm (11 of 21) [4/2/2003 16:19:25]

Appendix A - Instruction Set

A.20 RRF

Rotate f to the right through CARRY

http://www.mikroelektronika.co.yu/english/product/books/PICbook/A_Dodatak.htm (12 of 21) [4/2/2003 16:19:25]

Appendix A - Instruction Set

A.21 COMF Complement f

http://www.mikroelektronika.co.yu/english/product/books/PICbook/A_Dodatak.htm (13 of 21) [4/2/2003 16:19:25]


Appendix A - Instruction Set

A.22 BCF

Reset bit b in f

A.23 BSF

Set bit b in f

http://www.mikroelektronika.co.yu/english/product/books/PICbook/A_Dodatak.htm (14 of 21) [4/2/2003 16:19:25]

Appendix A - Instruction Set

A.24 BTFSC

Test bit b in f, skip if it = 0

A.25 BTFSS

Test bit b in f, skip if =1

http://www.mikroelektronika.co.yu/english/product/books/PICbook/A_Dodatak.htm (15 of 21) [4/2/2003 16:19:25]

Appendix A - Instruction Set

A.26 INCFSZ

Increment f, skip if=0

A.27 DECFSZ

Decrement f, skip if = 0

http://www.mikroelektronika.co.yu/english/product/books/PICbook/A_Dodatak.htm (16 of 21) [4/2/2003 16:19:25]

Appendix A - Instruction Set

A.28 GOTO Jump to address

A.29 CALL

Call a program

http://www.mikroelektronika.co.yu/english/product/books/PICbook/A_Dodatak.htm (17 of 21) [4/2/2003 16:19:25]

Appendix A - Instruction Set

A.30 RETURN

Return from a subprogram

A.31 RETLW Return from a subprogram with constant in W

http://www.mikroelektronika.co.yu/english/product/books/PICbook/A_Dodatak.htm (18 of 21) [4/2/2003 16:19:25]

Appendix A - Instruction Set

A.32 RETFIE

Return from interrupt routine

A.33 NOP No operation

A.34 CLRWDT Initialize watchdog timer

http://www.mikroelektronika.co.yu/english/product/books/PICbook/A_Dodatak.htm (19 of 21) [4/2/2003 16:19:25]

Appendix A - Instruction Set

A.35 SLEEP

Stand by mode

Previous page

Table of contents

Chapter overview

Next page

http://www.mikroelektronika.co.yu/english/product/books/PICbook/A_Dodatak.htm (20 of 21) [4/2/2003 16:19:25]