Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
9
Добавлен:
21.12.2020
Размер:
8.16 Mб
Скачать

PIC18F8722 FAMILY

11.7PORTG, TRISG and LATG Registers

PORTG is a 6-bit wide, bidirectional port. The corresponding data direction register is TRISG. Setting a TRISG bit (= 1) will make the corresponding PORTG pin an input (i.e., put the corresponding output driver in a high-impedance mode). Clearing a TRISG bit (= 0) will make the corresponding PORTG pin an output (i.e., put the contents of the output latch on the selected pin).

The Data Latch register (LATG) is also memory mapped. Read-modify-write operations on the LATG register, read and write the latched output value for PORTG.

PORTG is multiplexed with EUSART and CCP functions (Table 11-13). PORTG pins have Schmitt Trigger input buffers.

When enabling peripheral functions, care should be taken in defining TRIS bits for each PORTG pin. Some peripherals override the TRIS bit to make a pin an output, while other peripherals override the TRIS bit to make a pin an input. The user should refer to the corresponding peripheral section for the correct TRIS bit settings. The pin override value is not loaded into the TRIS register. This allows read-modify-write of the TRIS register without concern due to peripheral overrides.

The sixth pin of PORTG (RG5/MCLR/VPP) is an input only pin. Its operation is controlled by the MCLRE configuration bit. When selected as a port pin (MCLRE = 0), it functions as a digital input only pin; as such, it does not have TRIS or LAT bits associated with its operation. Otherwise, it functions as the device’s Master Clear input. In either configuration, RG5 also functions as the programming voltage input during programming.

Note: On a Power-on Reset, RG5 is enabled as a digital input only if Master Clear functionality is disabled. All other 5 pins are configured as digital inputs.

EXAMPLE 11-7: INITIALIZING PORTG

CLRF

PORTG

; Initialize PORTG by

 

 

; clearing output

 

 

; data latches

CLRF

LATG

; Alternate method

 

 

; to clear output

 

 

; data latches

MOVLW

0x04

; Value used to

 

 

; initialize data

 

 

; direction

MOVWF

TRISG

; Set RG1:RG0 as outputs

 

 

; RG2 as input

 

 

; RG4:RG3 as inputs

 

 

 

2004 Microchip Technology Inc.

Preliminary

DS39646B-page 151

PIC18F8722 FAMILY

TABLE 11-13: PORTG FUNCTIONS

Pin Name

Function

TRIS

I/O

I/O

Description

Setting

Type

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

RG0/ECCP3/P3A

 

RG0

0

O

DIG

LATG<0> data output.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

I

ST

PORTG<0> data input.

 

 

 

 

 

 

 

 

 

 

 

ECCP3

0

O

DIG

ECCP3 compare and ECCP3 PWM output. Takes priority over

 

 

 

 

 

 

 

 

 

port data.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

I

ST

ECCP3 capture input.

 

 

 

 

 

 

 

 

 

 

 

 

 

P3A

0

O

DIG

ECCP3 Enhanced PWM output, channel B. May be configured for

 

 

 

 

 

 

 

 

 

tri-state during Enhanced PWM shutdown events. Takes priority over

 

 

 

 

 

 

 

 

 

port data.

 

 

 

 

 

 

 

RG1/TX2/CK2

 

RG1

0

O

DIG

LATG<1> data output.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

I

ST

PORTG<1> data input.

 

 

 

 

 

 

 

 

 

 

 

 

 

TX2

0

O

DIG

Asynchronous serial transmit data output (EUSART2 module). Takes

 

 

 

 

 

 

 

 

 

priority over port data.

 

 

 

 

 

 

 

 

 

 

 

 

 

CK2

0

O

DIG

Synchronous serial clock output (EUSART2 module). Takes priority

 

 

 

 

 

 

 

 

 

over port data.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

I

ST

Synchronous serial clock input (EUSART2 module).

 

 

 

 

 

 

 

RG2/RX2/DT2

 

RG2

0

O

DIG

LATG<2> data output.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

I

ST

PORTG<2> data input.

 

 

 

 

 

 

 

 

 

 

 

 

 

RX2

1

I

ST

Asynchronous serial receive data input (EUSART2 module).

 

 

 

 

 

 

 

 

 

 

 

 

 

DT2

1

O

DIG

Synchronous serial data output (EUSART2 module). Takes priority

 

 

 

 

 

 

 

 

 

over port data. User must configure as an input.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

I

ST

Synchronous serial data input (EUSART2 module). User must

 

 

 

 

 

 

 

 

 

configure as an input.

 

 

 

 

 

 

 

RG3/CCP4/P3D

 

RG3

0

O

DIG

LATG<3> data output.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

I

ST

PORTG<3> data input.

 

 

 

 

 

 

 

 

 

 

 

 

 

CCP4

0

O

DIG

CCP4 compare and PWM output; takes priority over port data and

 

 

 

 

 

 

 

 

 

P3D function.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

I

ST

CCP4 capture input.

 

 

 

 

 

 

 

 

 

 

 

 

 

P3D

0

O

DIG

ECCP3 Enhanced PWM output, channel D. May be configured for

 

 

 

 

 

 

 

 

 

tri-state during Enhanced PWM shutdown events. Takes priority over

 

 

 

 

 

 

 

 

 

port data.

 

 

 

 

 

 

 

RG4/CCP5/P1D

 

RG4

0

O

DIG

LATG<4> data output.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

I

ST

PORTG<4> data input.

 

 

 

 

 

 

 

 

 

 

 

 

 

CCP5

0

O

DIG

CCP5 compare and PWM output. Takes priority over port data and

 

 

 

 

 

 

 

 

 

P1D function.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

I

ST

CCP5 capture input.

 

 

 

 

 

 

 

 

 

 

 

 

 

P1D

0

O

DIG

ECCP1 Enhanced PWM output, channel B. May be configured for

 

 

 

 

 

 

 

 

 

tri-state during Enhanced PWM shutdown events. Takes priority over

 

 

 

 

 

 

 

 

 

port data.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

(1)

 

 

 

RG5/MCLR/V

PP

 

RG5

I

ST

PORTG<5> data input; enabled when MCLRE configuration bit

 

 

 

 

 

 

 

 

 

is clear.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

I

ST

External Master Clear input; enabled when MCLRE configuration

 

 

 

 

MCLR

 

 

 

 

 

 

 

 

 

 

bit is set.

 

 

 

 

 

 

 

 

 

 

 

 

 

VPP

I

ANA

High-voltage detection; used for ICSP™ mode entry detection.

 

 

 

 

 

 

 

 

 

Always available regardless of pin mode.

 

 

 

 

 

 

 

Legend:

PWR = Power Supply, O = Output, I = Input, ANA = Analog Signal, DIG = Digital Output, ST = Schmitt Buffer Input,

 

 

TTL = TTL Buffer Input, x = Don’t care (TRIS bit does not affect port direction or is overridden for this option).

Note 1:

RG5 does not have a corresponding TRISG bit.

 

DS39646B-page 152

Preliminary

2004 Microchip Technology Inc.

PIC18F8722 FAMILY

TABLE 11-14: SUMMARY OF REGISTERS ASSOCIATED WITH PORTG

 

 

 

 

 

 

 

 

 

 

 

 

 

Reset

Name

 

Bit 7

Bit 6

Bit 5

Bit 4

 

Bit 3

Bit 2

 

Bit 1

Bit 0

Values on

 

 

 

 

 

 

 

 

 

 

 

 

 

page

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

PORTG

 

RG5(1)

RG4

 

RG3

RG2

 

RG1

RG0

60

LATG

 

LATG5(1)

LATG4

 

LATG3

LATG2

 

LATG1

LATG0

60

TRISG

 

TRISG4

 

TRISG3

TRISG2

 

TRISG1

TRISG0

60

Legend:

— = unimplemented, read as ‘0’. Shaded cells are not used by PORTG.

 

 

 

Note 1:

RG5 and LATG5 are only available when

MCLR

is disabled (MCLRE configuration bit = 0; otherwise, RG5

 

and LATG5 read as ‘0’.

 

 

 

 

 

 

 

 

 

 

2004 Microchip Technology Inc.

Preliminary

DS39646B-page 153

Соседние файлы в папке Склад