• Nenhum resultado encontrado

AAAA SEL 0629 AAAA. Aplicação de Microprocessadores I. Aula 2 PIC 18F45k22. Marcelo Andrade da Costa Vieira

N/A
N/A
Protected

Academic year: 2021

Share "AAAA SEL 0629 AAAA. Aplicação de Microprocessadores I. Aula 2 PIC 18F45k22. Marcelo Andrade da Costa Vieira"

Copied!
22
0
0

Texto

(1)

AA

AAAA

SEL–0629

Aplicação de

Microprocessadores I

Aula 2

PIC 18F45k22

Marcelo Andrade da Costa Vieira

(2)

AA

Família de Microcontroladores PIC

Microprocessadores de 8-bit, 16-bit e 32-bit;

A linha de 32-bit possui ULA de 32-bit, clock de até

(3)

AA

Família PIC de 8-bits

Classificados de acordo com o tamanho do barramento de

instruções. Isso define o tamanho da palavra de

instruções, o número de instruções e a sua velocidade

1.

Baseline: 12-bits

2.

Mid-range: 14-bits

3.

Enhanced Mid-range: 14-bits

(4)

AA

(5)

AA

(6)

AA

(7)

AA

PIC 18F45K22

Memória de Instruções de 16K x 16 bits (High-Performance) – FLASH – 32KB

Memória de dados (SRAM) com 1,5 Kbytes de uso geral – endereçamento de 12 bits (4096

bytes) divididos em 16 bancos de 256 bytes cada;

40 pinos – 35 portas de I/O configuráveis como entrada ou saída;

Memória adicional interna do tipo EEPROM não volátil de 256bytes;

34 fontes de interrupções diferentes com 2 níveis de prioridade;

Programação com 75 instruções (otimizadas para C)

Frequência máxima de operação de até 40 MHz (10 MIPS)

Pilha (Stack) de 31 posições;

Periféricos: 7 Timers, PWM, Conversor A/D e D/A, USART, etc...

(8)

AA

PIC 18F45K22

PIC18(L)F2X/4XK22

DS41412F-page 6

2010-2012 Microchip Technology Inc.

Pin Diagrams (40-pin)

40-pin PDIP

RB7/PGD

RB6/PGC

RB5

RB4

RB3

RB2

RB1

RB0

V

DD

V

SS

RD7

RD6

RD5

RD4

RC7

RC6

RC5

RC4

RD3

RD2

MCLR/V

PP

/RE3

RA0

RA1

RA2

RA3

RA4

RA5

RE0

RE1

RE2

V

DD

V

SS

RA7

RA6

RC0

RC1

RC2

RC3

RD0

RD1

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

40

39

38

37

36

35

34

33

32

31

30

29

28

27

26

25

24

23

22

21

PIC18

(L)F4

XK22

10

2

3

4

5

6

1

17

18

19 20

11 12 13 14

34

8

7

40 39

38 37

36 35

15

27

28

29

30

21

22

23

24

25

26

32 31

9

33

RA

3

RA

2

RA

1

RA

0

MC

LR

/V

PP

/R

E

3

RB

3

PG

D/

R

B

7

PG

C/

R

B

6

RB

5

RB

4

RC6 RC5 RC4 RD3 RD2 RD1 RD0 RC3 RC2 RC1

RA6

RA7

V

SS

V

DD

RE2

RE1

RE0

RA5

RA4

RC7

RD4

RD5

RD6

RD7

V

SS

V

DD

RB0

RB1

RB2

40-pin UQFN

PIC18(L)F4XK22

RC0

16

(9)

AA

(10)

AA

Memória RAM

Memória de dados de 2K x 8 bits;

Endereçado por duto de 12 bits

(4096 bytes);

16 bancos de 256 bytes cada;

Registrador BSR para seleção do

banco:

4 bits do BSR (MSB)

8 bits da instrução (LSB)

256 bytes de acesso direto (0 e 15)

(GPR + SFR)

Seleção na instrução se o acesso é

direto (a = 0) ou via banco (a = 1).

2010-2012 Microchip Technology Inc. DS41412F-page 79

PIC18(L)F2X/4XK22

FIGURE 5-7: DATA MEMORY MAP FOR PIC18(L)F25K22 AND PIC18(L)F45K22 DEVICES

Bank 0

Bank 1

Bank 14

Bank 15

Data Memory Map

BSR<3:0> = 0000 = 0001 = 1111 060h 05Fh F60h FFFh 00h 5Fh 60h FFh Access Bank When ‘a’ = 0:

The BSR is ignored and the Access Bank is used. The first 96 bytes are general purpose RAM (from Bank 0).

The second 160 bytes are Special Function Registers (from Bank 15).

When ‘a’ = 1:

The BSR specifies the Bank used by the instruction.

F5Fh F00h EFFh 1FFh 100h 0FFh 000h Access RAM FFh 00h FFh 00h FFh 00h GPR GPR SFR(1)

Access RAM High Access RAM Low Bank 2 = 0110 = 0010 (SFRs) 2FFh 200h 3FFh 300h 4FFh 400h 5FFh 500h 6FFh 600h 7FFh 700h 8FFh 800h 9FFh 900h AFFh A00h BFFh B00h CFFh C00h DFFh D00h E00h Bank 3 Bank 4 Bank 5 Bank 6 Bank 7 Bank 8 Bank 9 Bank 10 Bank 11 Bank 12 Bank 13 FFh 00h FFh 00h FFh 00h FFh 00h FFh 00h FFh 00h FFh 00h FFh 00h FFh 00h FFh 00h FFh 00h FFh 00h GPR FFh 00h = 0011 = 0100 = 0101 = 0111 = 1000 = 1001 = 1010 = 1011 = 1100 = 1101 = 1110 Unused Read 00h Unused GPR GPR GPR SFR

Note 1: Addresses F38h through F5Fh are also used by SFRs, but are not part of the Access RAM. Users must always use the complete address or load the proper BSR value to access these registers.

F38h F37h

(11)

AA

SFR

2010-2012 Microchip Technology Inc. DS41412F-page 83

PIC18(L)F2X/4XK22

TABLE 5-1:

SPECIAL FUNCTION REGISTER MAP FOR PIC18(L)F2X/4XK22 DEVICES

Address Name Address Name Address Name Address Name Address Name

FFFh TOSU FD7h TMR0H FAFh SPBRG1 F87h —(2) F5Fh CCPR3H

FFEh TOSH FD6h TMR0L FAEh RCREG1 F86h —(2) F5Eh CCPR3L

FFDh TOSL FD5h T0CON FADh TXREG1 F85h —(2) F5Dh CCP3CON

FFCh STKPTR FD4h —(2) FACh TXSTA1 F84h PORTE F5Ch PWM3CON

FFBh PCLATU FD3h OSCCON FABh RCSTA1 F83h PORTD(3) F5Bh ECCP3AS

FFAh PCLATH FD2h OSCCON2 FAAh EEADRH(4) F82h PORTC F5Ah PSTR3CON

FF9h PCL FD1h WDTCON FA9h EEADR F81h PORTB F59h CCPR4H FF8h TBLPTRU FD0h RCON FA8h EEDATA F80h PORTA F58h CCPR4L FF7h TBLPTRH FCFh TMR1H FA7h EECON2(1) F7Fh IPR5 F57h CCP4CON

FF6h TBLPTRL FCEh TMR1L FA6h EECON1 F7Eh PIR5 F56h CCPR5H FF5h TABLAT FCDh T1CON FA5h IPR3 F7Dh PIE5 F55h CCPR5L FF4h PRODH FCCh T1GCON FA4h PIR3 F7Ch IPR4 F54h CCP5CON FF3h PRODL FCBh SSP1CON3 FA3h PIE3 F7Bh PIR4 F53h TMR4 FF2h INTCON FCAh SSP1MSK FA2h IPR2 F7Ah PIE4 F52h PR4 FF1h INTCON2 FC9h SSP1BUF FA1h PIR2 F79h CM1CON0 F51h T4CON FF0h INTCON3 FC8h SSP1ADD FA0h PIE2 F78h CM2CON0 F50h TMR5H FEFh INDF0(1) FC7h SSP1STAT F9Fh IPR1 F77h CM2CON1 F4Fh TMR5L

FEEh POSTINC0(1) FC6h SSP1CON1 F9Eh PIR1 F76h SPBRGH2 F4Eh T5CON

FEDh POSTDEC0(1) FC5h SSP1CON2 F9Dh PIE1 F75h SPBRG2 F4Dh T5GCON

FECh PREINC0(1) FC4h ADRESH F9Ch HLVDCON F74h RCREG2 F4Ch TMR6

FEBh PLUSW0(1) FC3h ADRESL F9Bh OSCTUNE F73h TXREG2 F4Bh PR6

FEAh FSR0H FC2h ADCON0 F9Ah —(2) F72h TXSTA2 F4Ah T6CON

FE9h FSR0L FC1h ADCON1 F99h —(2) F71h RCSTA2 F49h CCPTMRS0

FE8h WREG FC0h ADCON2 F98h —(2) F70h BAUDCON2 F48h CCPTMRS1

FE7h INDF1(1) FBFh CCPR1H F97h (2) F6Fh SSP2BUF F47h SRCON0

FE6h POSTINC1(1) FBEh CCPR1L F96h TRISE F6Eh SSP2ADD F46h SRCON1

FE5h POSTDEC1(1) FBDh CCP1CON F95h TRISD(3) F6Dh SSP2STAT F45h CTMUCONH

FE4h PREINC1(1) FBCh TMR2 F94h TRISC F6Ch SSP2CON1 F44h CTMUCONL

FE3h PLUSW1(1) FBBh PR2 F93h TRISB F6Bh SSP2CON2 F43h CTMUICON

FE2h FSR1H FBAh T2CON F92h TRISA F6Ah SSP2MSK F42h VREFCON0 FE1h FSR1L FB9h PSTR1CON F91h —(2) F69h SSP2CON3 F41h VREFCON1

FE0h BSR FB8h BAUDCON1 F90h —(2) F68h CCPR2H F40h VREFCON2

FDFh INDF2(1) FB7h PWM1CON F8Fh (2) F67h CCPR2L F3Fh PMD0

FDEh POSTINC2(1) FB6h ECCP1AS F8Eh (2) F66h CCP2CON F3Eh PMD1

FDDh POSTDEC2(1) FB5h (2) F8Dh LATE(3) F65h PWM2CON F3Dh PMD2

FDCh PREINC2(1) FB4h T3GCON F8Ch LATD(3) F64h ECCP2AS F3Ch ANSELE

FDBh PLUSW2(1) FB3h TMR3H F8Bh LATC F63h PSTR2CON F3Bh ANSELD

FDAh FSR2H FB2h TMR3L F8Ah LATB F62h IOCB F3Ah ANSELC FD9h FSR2L FB1h T3CON F89h LATA F61h WPUB F39h ANSELB FD8h STATUS FB0h SPBRGH1 F88h —(2) F60h SLRCON F38h ANSELA

Note 1: This is not a physical register.

2: Unimplemented registers are read as ‘0’.

3: PIC18(L)F4XK22 devices only.

(12)

AA

(13)

AA

10 bits - 30 canais multiplexados

2010-2012 Microchip Technology Inc. DS41412F-page 297

PIC18(L)F2X/4XK22

17.0

ANALOG-TO-DIGITAL

CONVERTER (ADC) MODULE

The Analog-to-Digital Converter (ADC) allows

conversion of an analog input signal to a 10-bit binary

representation of that signal. This device uses analog

inputs, which are multiplexed into a single sample and

hold circuit. The output of the sample and hold is

connected to the input of the converter. The converter

generates a 10-bit binary result via successive

approximation and stores the conversion result into the

ADC result registers (ADRESL and ADRESH).

The ADC voltage reference is software selectable to

either V

DD

or a voltage applied to the external reference

pins.

The ADC can generate an interrupt upon completion of

a conversion. This interrupt can be used to wake-up the

device from Sleep.

Figure 17-1

shows the block diagram of the ADC.

FIGURE 17-1:

ADC BLOCK DIAGRAM

Note: Additional ADC channels AN5-AN7 and AN20-AN27 are only available on PIC18(L)F4XK22 devices.

11111 11110 11101 11100 11011 FVR BUF2 DAC CTMU AN28(1) AN27(1) 00101 00100 AN5(1) AN4 00011 00010 AN3 AN2 00001 00000 AN1 AN0 5 CHS<4:0> 10-Bit ADC ADCMD ADON GO/DONE 10 0 = Left Justify 1 = Right Justify ADFM 10 ADRESH ADRESL 00 01 AVDD 10 11 FVR BUF2 Reserved VREF+/AN3 2 PVCFG<1:0> 00 01 AVSS 10 11 Reserved Reserved VREF-/AN2 2 NVCFG<1:0>

(14)

AA

(15)

AA

(16)

AA

Portas de I/0

Definir se é entrada ou saída (TRIS

A

, TRIS

B

, etc.);

Quando for escrever na porta (saída), usar os registradores LAT

A

,

LAT

B

, etc.

Quando for ler o estado de um pino (entrada), usar os registradores

PORT

A

, PORT

B

, etc.

Definir se a porta é analógica ou digital, devido ao conversor A/D

(17)

AA

Portas de I/0

AA

Portas de I/0

2010-2012 Microchip Technology Inc.

DS41412F-page 135

PIC18(L)F2X/4XK22

10.0

I/O PORTS

Depending on the device selected and features

enabled, there are up to five ports available. All pins of

the I/O ports are multiplexed with one or more alternate

functions from the peripheral features on the device. In

general, when a peripheral is enabled, that pin may not

be used as a general purpose I/O pin.

Each port has five registers for its operation. These

registers are:

• TRIS register (data direction register)

• PORT register (reads the levels on the pins of the

device)

• LAT register (output latch)

• ANSEL register (analog input control)

• SLRCON register (port slew rate control)

The Data Latch (LAT register) is useful for

read-modify-write operations on the value that the I/O pins are

driving.

A simplified model of a generic I/O port, without the

interfaces to other peripherals, is shown in

Figure 10-1

.

FIGURE 10-1:

GENERIC I/O PORT

OPERATION

10.1

PORTA Registers

PORTA is an 8-bit wide, bidirectional port. The

corresponding data direction register is TRISA. Setting

a TRISA bit (= 1) will make the corresponding PORTA

pin an input (i.e., disable the output driver). Clearing a

TRISA bit (= 0) will make the corresponding PORTA

pin an output (i.e., enable the output driver and put the

contents of the output latch on the selected pin).

Reading the PORTA register reads the status of the

pins, whereas writing to it, will write to the PORT latch.

The Data Latch (LATA) register is also memory mapped.

Read-modify-write operations on the LATA register read

and write the latched output value for PORTA.

The RA4 pin is multiplexed with the Timer0 module

clock input and one of the comparator outputs to

become the RA4/T0CKI/C1OUT pin. Pins RA6 and

RA7 are multiplexed with the main oscillator pins; they

are enabled as oscillator or I/O pins by the selection of

the main oscillator in the Configuration register (see

Section 24.1 “Configuration Bits”

for details). When

they are not used as port pins, RA6 and RA7 and their

associated TRIS and LAT bits are read as ‘0’.

The other PORTA pins are multiplexed with analog

inputs, the analog V

REF

+ and V

REF

- inputs, and the

comparator voltage reference output. The operation of

pins RA<3:0> and RA5 as analog is selected by setting

the ANSELA<5, 3:0> bits in the ANSELA register which

is the default setting after a Power-on Reset.

Pins RA0 through RA5 may also be used as comparator

inputs or outputs by setting the appropriate bits in the

CM1CON0 and CM2CON0 registers.

The RA4/T0CKI/C1OUT pin is a Schmitt Trigger input.

All other PORTA pins have TTL input levels and full

CMOS output drivers.

The TRISA register controls the drivers of the PORTA

pins, even when they are being used as analog inputs.

The user should ensure the bits in the TRISA register

are maintained set when using them as analog inputs.

EXAMPLE 10-1:

INITIALIZING PORTA

Data

Bus

WR LAT

WR TRIS

RD Port

Data Latch

TRIS Latch

RD TRIS

Input

Buffer

I/O pin

(1)

Q

D

CK

Q

D

CK

EN

Q

D

EN

RD LAT

or Port

Note 1:

I/O pins have diode protection to V

DD

and V

SS

.

TRISx

ANSELx

Note:

On a Power-on Reset, RA5 and RA<3:0>

are configured as analog inputs and read

as ‘0’. RA4 is configured as a digital input.

MOVLB

0xF

; Set BSR for banked SFRs

CLRF

PORTA

; Initialize PORTA by

; clearing output

; data latches

CLRF

LATA

; Alternate method

; to clear output

; data latches

MOVLW

E0h

; Configure I/O

MOVWF

ANSELA ; for digital inputs

MOVLW 0CFh

; Value used to

; initialize data

; direction

MOVWF TRISA

; Set RA<3:0> as inputs

; RA<5:4> as outputs

(18)

AA

(19)

AA

EESC – USP

• 

CCP = Capture, Compare, PWM;

• 

Periférico presente em alguns microcontroladores PIC

• 

Modo Capture: contagem de tempo entre dois eventos ocorridos

no pino do PIC (borda de descida ou subida)

• 

Modo Compare: contagem de tempo entre dois eventos ocorridos

no pino do PIC e comparação com um valor pré determinado

• 

Modo PWM: geração de um pulso PWM no pino do PIC

• 

Pode gerar interrupção

• 

Utiliza os temporizadores do PIC para geração da base de tempo:

(20)

AA

EESC – USP

PWM

Pulse Width Modulation = Modulação por largura de

pulso

Onda de frequência constante mas com largura de

pulso variável (ciclo de trabalho ou duty cycle)

Obtenção de uma tensão analógica a partir de um

(21)

AA

EESC – USP

PWM

Uso um filtro passa baixa com frequência de corte

menor do que a frequênca do PWM

RC

f

c

π

2

1

=

(22)

AA

Referências

Documentos relacionados

Na hepatite B, as enzimas hepáticas têm valores menores tanto para quem toma quanto para os que não tomam café comparados ao vírus C, porém os dados foram estatisticamente

Enfatizando o papel dos SPAP e seguindo as orientações do NICE, em 2010, Prytherch e colaboradores desenvolveram o ViEWS, um sistema que revelou os melhores

Do amor,&#34; mas do amor vago de poeta, Como um beijo invizivel que fluctua.... Ella

De um modo geral, quase todos consideram que o ensino das Ciências em contexto escolar deve capacitar os alunos com um nível de literacia científica adequado, embora não exista

RESUMO Este trabalho é resultado de uma pesquisa realizada no Instituto de Reabilitação e Prevenção em Saúde Indaiá, teve como objetivos identificar a prevalência de doentes

i) A condutividade da matriz vítrea diminui com o aumento do tempo de tratamento térmico (Fig.. 241 pequena quantidade de cristais existentes na amostra já provoca um efeito

Despercebido: não visto, não notado, não observado, ignorado.. Não me passou despercebido