Title: ?2? ??????PIC16F8XX
1?2? ??????PIC16F8XX
- PIC????????????????,???????????PIC?????,??????????
,??????????????????????????????????,??????????????
??????????PIC??????????? - ???????????PIC??,?????????PIC16F8???????????,?????
?????????????????????? - PIC16F8?????????PIC16F84A?PIC16F873?PIC16F877??
22.1 PIC16F84A???
- 2.1.1 PIC16F84A????
- PIC16F8X???18???Flash/EEPROM
8?????????.PIC16F8X??????????,?
PIC16F83?PIC16F84?PIC16CR83? PIC16CR84,?????????PI
C16LF8X,PIC16LCR8X?? -
- PIC16F84A????PIC16F???????????????18??,??
?????????,??????,???????????????????????????PIC???
???????,?????????? -
- ?????????????????????,????????????????
??????????????,??????????????????,????OSC1/CLKIN
???????????????????4????OSC2/CLKOUT????,??????????
???????????????????????????????,???????????????
3- ?PIC16F84A?????????(inv)??,?????L????????
???????????????????????,PIC16F84A????,??RA0-RA3
RA4/T0CK1RB0/INTRB1-RB7??????????RA4/
TOCK1?????????,?????????,???????????????RB0???????
?,?????????????Vss?????VDD????,??????2.0V5.5V,?
??????????????PIC16F84A???????????2.1???
?2.1 PIC16F84A?????
4- PIC16F84A?????????????????(RISC
CPU),??????????? - ???????????,????35??
- ????????(2??),??1?????
- ???? DC10 MHZ ????
- DC400ns ?????
- 14 ????,8 ? ???
- ????????15??
- ??? 8 ??
- ???4?
- ??RB0/INT ?? ??????
- TMR0 ????????
- PORTBlt74gt ??????????
- ?? EEPROM ??????
- Flash ???????,???1000??
- EEPROM ?????????,???1000?,???? gt 40??
- ?2.1?PIC16F8X???????????????
5?2.1?PIC16F8X????????????
PIC16F8X ? ? ????? (WORDS) ????? RAM (BYTE) ?? EEPROM (BYTE) ???? ( MHz )
PIC16F83 512 Flash 36 64 10
PIC16F84 1K Flash 68 64 10
PIC16CR83 512 ROM 36 64 10
PIC16CR84 1K ROM 68 64 10
PIC16F84A??????????,?????? ???????13??? ??????
(LED????I/O),?????? 25mA,?????? 20
mA? ???TMR0?8????/???? ??PIC16F84A??????????????P
OR(Power-on reset)???????PWRT(Power up
Timer)?????????OST????????WDT(Watch Dog Timer) ??
62.1.2 PIC16F84A ????
- PIC16F84A?????????2.2?????????????????????
?????????????????????????8????????????????????????
????????????????????????? - 1.?????(Flash Program Memory)
- PIC16F84A????????Flash?????????1024??,?1????1
4????Flash?????????????????????????????????????(Wr
iter)?????
?2.3 Flash ???
?2.2 PIC16F84A??????
7- 1)??(Reset)??????? (??1000h)
- ????,????????WDT?????????PIC?????,PIC?????????????
? - 2)????????? (??0004h)
- ???(Timer)???????????????????????
- 3)?????? (2007h)
- ?????????PIC??????????,????????,?????????,????????
??????????????????????,??????????,???????(Writer)?
?????
?2.4 2007h??????(14 ?)
R ??????? ? P ????
-n ?????? u ???
? 13-4 ???????? CP
1 -??????? 0 -?????????
???????,PIC???????????????? ? 3
Power up ?????? (PWRTE inv) 1
-Power up?????? 0 -Power up?????
?????????72ms?PIC Reset? ???????
? 2 WDT????????? (WDTE)
1 -WDT????? 0
-WDT?????? ? 1-0 ???????
8- 2.?????RAM (Random Access Memory)
- RAM????????????????????(?????????????)???
???????RAM??????????????,???????????,???????,?????
????????????????????????????2.4???????????????????
??????(Bank)????????????????12 ?(??
00h-0Bh)????????????SFR?????PIC?????,I/O??????????
???????????13???68?(?? 0Ch-4Fh)?????????GPR
(General Purpose Registers)???????????????????????
?????????
?2.5 RAM ?????
9- 3.????????EEPROM (Electrically Erasable
Programmable Read Only Memory) - ?RAM??,EEPROM????????,???????????EEPROM???
?????????????????64???????100????????????????????,
????????,???????????100???????,???????????????????
??????40?? - 4.???????SFR (Special Function Registers)
- ????????????,SFR???????16???????????2.3?????
?????????????160??,???????????????????????????????
??????????,???????????????????????
10- 5.?????(Program Counter)
- ????????????????????????????13?????
??????????????1?????????????????????,?????????????
??? - 6.?????
- ??????????????????????????????????????????
???????,??????????????????,???????????????????
?????????RETURN????????????????????????????????
??????CALL????????,???????????,???????????????????
?????????(PUSH)????????RETURN???,?????????????????
???,?????????(POP)???????,???????????,???????????,
??????????????????? ?????????????,??????RETURN????
????????2.6,???????????,???????? - 7.?????(Instruction Register)
- ?????????????(Instruction)?????????,???????
?FECTCH? - 8.????
- ??????????????(??)???????????????????????
??
11?2.6 ???????????
12- 9.???????????(Multiplexer and Arithmetic Logic
Unit) - ?????????????PIC????????????????????????????
??????????????????????????CPU????????,????????????
? - 10.?????
- ????????W Register???????????????????????????
?????????????????????????????????I/O???? - 11.?????(Status Register)
- ?????????????????????????????(??????,????????
?),??????? ?????????????? - 12.???????FSR (File Select Register)
- ?????,?????????????????FSR???????RAM?????????
????????????????????????????????????????,?????7?,?
?????0?127??????????????????????????,????????RP0
?????FSR????8????,????????????????????????????????
????????? ????????PIC16F84A?????80(50h)?127(7Fh)??
?????
13- 13.???????(Address Multiplexer)
- ?RAM?????????,???????????????(7?)???????RP0?
????????????????????????(7 ?)?FSR?????????????????
????????????????? - 14.EEDATA ???
- EEDATA??????EEPROM????????????????????
- 15.EEADR ???
- EEADR????EEPROM???????????8????,????0?255?
?????PIC16F84A??????64?,??6 ???????EEPROM??? - 16.???(Timer)
- PIC16F84A???????8?????????TMR0?8??????????25
6?????256???,?????????????SFR?INTCON????TOIF ??
1????????????????????????????,SFR?INTCOM????GIF??T
OIE?????1?
14- 17.I/O ?????
- PIC16F84A????????13??????????????????????
??????,??????????13 ????5???8?????5?????A?,8
?????B??????????,??????????,?13 ?????????????? - 18.????????
- ????????PIC????????,PIC???????????????????
???????????????????????????????????????????,??????
?????,???????????????????????PIC???????????????? - PIC16F84A??????????,????????(1??)?4???????
??????????????8??(2??)??20MHz?????,?????1/20MHz,50
ns,????????200ns?PIC?1?????500?????
15- 2.1.3 PIC16F84A ???
- PIC16F84A???,?????????????????????????????
? - ?????(Power-on )
- ???,???PIC?????????????????????????PIC????
- ?????(Oscillator Start-up Timer)???,?????????????
???????????????PIC???? - ????(Power-on Reset)???,PIC??????????
- ???(Watchdog)??????????????PIC???????????PIC?????
?????????????PIC??????????????,PIC????????????????
????????????,PIC??????????
162.2 PIC16F873???
- 2.2.1 PIC16F873????
- ???????PIC??????,???????PIC16F84A,????????
???????,??????,?????????????????PIC16F873?????????
?????PIC16F873???PIC16F84A???????????????????????
- PIC16F873????PIC16F84A?????????????????????
???????4 K ??,?????RAM ???192??,EEPROM?128????????
????????????????????????(A/D)????????????????PIC16
F84A?????????,????????PIC16F84A??????????????? - ?2.7?PIC16F873?????,?????????????
- RA0-5 ????? A MCKLR Master
Clear (?????) - RB0-7 ????? B Vpp ??????
- RC0-7 ????? C THV Test
Mode ?????? - AN0-4 ???? VREF/- ????
(A/D??) - RX USART?????? SS Sleep
??
17- TX USART?????? T0CK1 ?????0????
- SCK ??????? T1OSO ?????1??????
- SCL SPI,I2Cmode?? T1OSI
?????1?????? - DT ???? T1CK1
?????1???? - CK ???? PGD ??????
- SDO SPI???? PGC ??????
- SDI SPI ???? PGM ???????
- SDA ??????(I2Cmode) INT ??????
- OSC1/CLKIN ???? VDD ??
- OSC2/CLKOUT ???? Vss ??
(Ground) - CCP1,2 Capture?? / ???? / PWM??
18- 1.PIC16F873????????SFR (Special Function
Register) - PIC16F873?RAM???????4 ???(Bank)?????????128????
?????SFR???????????32????33 ??????????????????????
?????96???2??3?????0??1?????????,????????????2
??????192 ??? - 2.PIC16F873???(Configuration)?
- PIC16F837?????????????????????????2007h??
???????????????????????????????????? - ???????PIC???????2.9?????????????
?2.9 ??????????
19- 2.2.2 PIC16F873??????
-
- PIC16F837????????A?B?C????A??6?,B??8?,C??
8?????????22??????????????,A?B?C???????PIC16F873??
A,B,C?????????????????????,???????,??A/D????????,?
?????????????????PIC16F873??????????
20- 1.????A?
- ????A??RA0-RA5?6??????????????????????,??????,
?????????????????0???????????????PIC16F84A,???????
??????????? - ????????????,??????(Mode)????TRISA????????????
????????????,????ADCON0?ADCON1??????????????????,T
RISA???????????????????????,????TRISA?????????????
(1)?????A????????2.10???
?2.10 ????A????
21- 2.????B?
- ????B??RB0-RB7?8?????????????????????????????
???????????????????,???????????????
(ICSP)???,B???????????PIC16F873?ICSP?PIC16F84A????
?? - RB4-RB7?4?????????????????????,B??????TR
ISA???4????,?4???,4?????????????????????????INTCOM
????RBIF???,?????????????0004h,????????? - ??,RB0/INT????????????????????,INTCON????IN
TE ????1?????????????????,?OPTION????RBPU???????1?
,?????,0????????
?2.11 ????B????
22- 3.????C?
- ????C??B????8??????????C???????????????,?
????????1??????,?????????????????? - RC0??????????1???????????????????????????
???T1CON???????RC1???????????1????????????CCP2
(Capture2 input/Compare2 output/Pulse Width
Modulation2 (PWM2) output)?????????1??????T1CON???
??????CCP2???????CCP2CON???????
?2.12 ????C????
23- 2.2.3 PIC16F873?????
- PIC16F837??3???????????????????????,???????
- ?????0
- PIC16F873??????0?PIC16F84A??????0??????
,??????????? - ?????0?8??????,??????255?
- ?????????????
- ???8?????Pre-scale???
- ???????????
- ?????????(?????????FFh??00h)
- ????????,?????????????
24- ?????1
- ?????1??2.13??,???16??????
(TMR1H,TMR1L)????2?8????????????????Pre-scale,????
1,2, 4,8?????TMR1IE???PIE ??1?,??????????????????F
FFFh??0000h??TMR1IF????,??????? - ?????1?????????????????????T1CON???
TMR1CS????TMR1CS??0?,??????1??????????????????????
??????????????
?2.13 ?????1????
25- ?????2
- ??????????8 ?????? (TMR2)
??????????????? ??????4????????????4????????????
?????1,4,16?????????????1?16??16????????? - ????????????2.14????????????????????????,
???????00h????? ?????????????2??0?????????????????
??????????????FFh?????????????????????????????????
?,???????????????????5,??????????????5??,?????????
??(PIR1)TMR2IF??1?????? ?????2????T2CON???TMR2ON??
??????????
?2.14 ?????2????
26- 2.2.4 PIC16F873 CCP??
- CCP???PIC16F873??????CCP?????Capture,Comp
are?PWM (Pulse Width Modulation)
?????????,?????????????????????PIC16F873???CCP???
CCP1 CCP2 ????
???? ???? ???????1 ???????????????,??????
???? ???? ??????,????????1?? ?????,?????CCP1?????
???? PWM ??????1??????2????,?????????????
???? ???? ??????,????????1?? ?????,?????CCP2?????
???? ???? ????????,????????1?? ??,??????????
???? PWM ??????1??????2????,?????????????
PWM ???? ??????1??????2????,?????????????
PWM ???? ??????1??????2????,?????????????
PWM PWM ??????,?????2????????????
?2.3 CCP1?CCP2???????
27- ?????? CCP??????
- 1.????(Capture)??
- ????????,RC2/CCP1 ??(13??)?????????????????CCPR1
(CCPR1L?CCPR1H) ??????TRISC???????RC2/CCP1
????????? ????????2.15? - ??RC2/CCP1 ?? (?? 13) ??????????????????CCP1CON???
?CCP1M 0 ??CCP1M 3 ??4?????
?2.15 CCP???????
28- 2.????(Compare)??
- ????????CCPR1????????????1(TMR1)????????????
?????????2.16??? ????????,??CCP1????CCP1M0
??CCP1M3 ???????????????? ??????????2.5?
???,???TRISC?????RC2/CCP1?(?? 13)??????
???????1????????????? ????????????,???????????
?2.16 CCP???????
29- PWM??
- ????PWM (Pulse Width Modulation)
???,??CCP1?? (?? 13) ????????? ????????????2.17???
???PWM??,?CCP1CON????CCP1M3 ??CCP1M2 ??1????
?2.17 PWM???????????
30- ??????PWM?????Duty???????
- 1) PWM??
- Pulse?????TRM2?PR2?????????,?????????
- PWM???? (PR2?? 1)4??????????2?????
- ???1 (10MHz??????)
- ?? PR2 255
- ????? 0.1 µs (10MHz??)
- ?????2?Prescaler? 16
- PWM?? (2551)40.11E-0616
- 1.6384 ms(610Hz)
- 2) PWM????????
- ??????????Pulse???????,?????????
- ???3 (10MHz???Duty??)
- ?? CCPR1L CCP1X CCP1Y 1023
- ????? 0.1 µs (10MHz??)
- ?????2?Prescaler? 16
- PWM ??????? 10230.11E-0616
- 1.6368 ms
31- ??????,PWM?????????
- ?PR2?????PWM???
- ?CCPR1L????CCP1CON?????PWM Duty??
- ?TRISC?????CCP1 (?? 13) ??????
- ?T2CON????????????Prescaler??
- ?CCP1CON???CCP1M3??CCP1M2???PWM?? (11XX)?
32- 2.2.5 PIC16F873 ????(A/D)??
- ????????????????????,???????????????
PIC16F873??10?????????,??????????1/1024??????
???????0 V?5 V???????5V,??????5/1024
V,?0.004883 V (?5 mV)? - 1.??????
- ??PIC16F873????????5?????????
(AN0-AN4),????????????????PIC16F873???1???????????
????????????,???????????????????1???????40us,?????
??????????????????????????????? - ??????????????ADCON1???PCFG0??PCFG3??4
????? PIC??????????????ADCON0????CHS0?,CHS1??CHS2?
?????? ?????????TRISA???????1????????????????2.18?
??
33- 2??????????
- ?????????Vss (0V) ?VDD (5V)
??,?????VREF- (????) ?VREF (????)
?????????????,VREF-?VREF ??????Vss?VDD???
??,??????Vss,??????3V?,?????3V?????????????1/1024,
?3/10240.002929 (?3mV)? - VREF-?VREF???,???ADCON1???PCFG0??PCFG
3??????? ??VREF-?VREF????,??????AN2???AN3????????
?????VREF,VREF-?????Vss????????,?????Vss,?????VD
D?
?2.19 ???????????
34- 3????????
- ?????????ADRESH?ADRESL?????????????2.20?????????8?
????????16???????ADRESH???,ADRESL??????????10?????
??16 ????????10???10??,??ADCON1????ADFM?????????2.
20??,ADFM?0,??10?,1???10??
?2.20 ????????
35- ????????
- ??2.21?,???????ON?,????????ANx???????
?????????CHOLD??,??????????????????????????
?????????????,??ADCON0???CHS0,CHS1?CHS2???????,???
??????????,????????????????????????,??????????????
?????????????? ??????20 us? ??????????????
????????????????,????20 us? ???,???????????????,??
?????????????????????
?2.21 ?????????????
36- 5?????????
- ?????????????????????1???1.6us
(TAD)??????????ADCON0????ADCS0??ADCS1???????2?????
?4?????? - ????1.6 us???????,??????????PIC????,???
?????1.6 us???????,RS??????SLEEP?????????
?2.22 ????
37- 6.??????????
- ??????????????????????????????
- SLEEP????????
- ???PIC??????????????????,????SLEEP????????????????
?????RC???,?????ADCON0???ADCS0??ADCS1??1?1
??????4 us?ADCON0???GO??1?SLEEP?????PIC??SLEEP???S
LEEP??????????????,?????????????????????2.23??? -
?2.23 SLEEP??????????
38- 2.2.6 PIC16F873 ??????USART
-
- PIC16F873????????????????,?????/?????USART
(Addressable Universal Synchronous Asynchronous
Receiver Transmitter)???????????MSSP(Master
Synchronous Serial Port)???USART?????????????????
(?????)?????-?Master (?????)?????-? Slave
(?????)? -
- USART?????????????????????????8??????????
??,?????????,????????9????
39- 1.????
- ?????,??????????1?0?????????,?????????????????????
????????? (8 ? ?9??) ??????????,??????????????????
??????????,???????????????????,????????H????????H?
???L??? (START) ?,?????????????,??,???????????????
??????????STOP ? (H??) ???????????USART???,???????
??????????????????,??????????????????????????,????
?????Tx?????Rx?????,????????? (?????)?
40- 2?????????
- ??????RC6/TX/CK (17 ??)
???????,RC7/RX/DT (18 ??)???????????????USART????,
TX ?RX?????????TRISC?????,?C???6 ????0
(????),?7????1(????)???RC6?RC7??USART???,?????????
?(??????????)SPEN ????,??TXSRA???SYNC
??USART??????2.24???
?2.24 USART ????
41- 3 USART??????
-
- USART???????????BRG (Baud Rate
Generator)????????????????BRG???????????????SPBRG,
???8???????????????USART???,??????????(TXSTA)?BRGH
????????????
42- 4.USART????????
- USART?????,??????????SPEB??RC6????TX????TXREG?????
?????,??????TSR (Transmit Shift Register)
?????TX???????????????????(TXSTA)?TXEN
??1?????????????????????
?2.25 USART???????????
43?2.26 ???USART???????
?2.27 ?????USART???????
44- 5.USART????????
- ?2.28???USART??????????????USART?????,??
??????????????SPEN ??1???RC7?USART?????RX?????,?RX
?????????????????RSR????????????????,??????????3??
???????SPBRG??????????????(TXSTA)?BRGH
??????????RSR??????????RSR??????????STOP
??,??RSR?????????RCREG?????????RCREG????,PIR1?????
???RCIF ??1??????????????,??????????????(PIE1)?RCI
E ??1??? - ??2.28??,RCREG?????2?????FIFO
???????,?????2???????????????????????????????????,
RCIF ??????,?RCREG??????????,??????0?
?2.28 USART??????????
45- ??????RSR??????,?RCREG?2?????FIFO (First
In First Out) ???????????RCSTA????OERR
??????????Overlay?????????????RSR????????????????U
SART???????????????,???RCSTA????CREN
???,????CREN????OERR?????? - ??????????USART??????????????????????????
??????????????RSR??????????,RCSTA????FERR
???????????RERR ????RCSTA????RX9D
????????????1??????????????,?RCREG???????????RCSTA
?????????FERR ??????
462.3 PIC16F877???
- ????PIC?????????Microchip??????????,???
??????????????,????????????PIC16F877???????????,??
Flash?????,????????????????CPU?????????????,??????
???????????PIC16F877??????????????PIC?????????????
?????????????????????????????????????
47- 2.3.1 PIC16F877??
- PIC16F877??PIC16F87X??????????,??????
- ???RISC CPU
- 35?????
- ????????2????,????????
- ????DC20MHZ????,DC 200ns????
- 8K14?FLASH?????
- ????(??14????)
- 8????????
- ?????????????
- ????(POR)??????????????
- ????????
- ?????
- ??????(ICSP)
48- ?????
- Timer0???????8????/???
- Timer1???????16????????,????????,?Sleep??????
- Timer2??8??????,??????????8????/???
- 10????A/D???
- ??SPI(???)?I2C(?/?)???SSP
- ??9??????????????/???(USART/SCI)
- ??RD,WR?CS??(?40/44??)8????????
- ?????????????
49- PIC16F877?? Flash program
??????,????????,???? ICD(In Circuit
Debug)??,??????????????????,??????????????????????
?,PIC16F877????PLCC(Plastic Leaded Chip Carrier)?
QFP(Quad Flat Package)???????,???????,?????????? - PIC16F877(??2.30) ?????(Flash)???,??????,?
ROM ?????? 8K ??,? 2K ???,??? 4??? RAM ??? 512
???(00f1FFh),? 128 ?????????,???? 4 ????,?????
???????????,???????????,?? I/O?CCP?Timer?USART?MSS
P ??
50- 2.3.2 ??????
- PIC16F877 ????????????,?? CPU?POM?RAM?I/O
??????,?????????,???? - A/D converter???????,?????? 8 ????????
CCP??????????PWM,????????? - Timer,?????,? Timer0?Timer1?Timer2 ?3??
- USARTUniversal Synchronous Asynchronous Receiver
Transmitter,??/??????,? RS232?RS485 ?? - MSSPMaster Synchronous Serial Port,???(I2C)????(S
PI)???? - ??????,??? EEPROM ??????????,??????????????,??????
??
51?2.30 PIC16F877 ????
?2.31 PIC16F877 RAM???
52- 2.3.3 PIC16F877 ????
- 1.PIC ????
- ??????????????????????,????/???????????,??
??????,??????????????,????????,PIC16F877
????????20MHz????????13(OSC1/CLKIN)???14(OSC2/CLK
OUT),????????4??? - LP?????????(Low Power Crystal)
- XT?????/???(Crystal/Resonator)
- HS???????(High Speed Crystal/Resonator)
- RC????/??(Resister/Capacitor)
?2.32 ??????
53- 2.?????????
- PIC16F877 ?????? 5V,?? ??11 ? ??32,??12 ?
??31 ?????,?????? ??1,?? Reset
?,??????????,???????????2.33? - 3.?????
- PIC16F877 ???????????? 7 ????,??? 33
??????????????,??????????????,????????????????????
??PIC ? 8?????,???????,?????? 8 ???,?? I/O ???
PORTA(RA0RA5)?PORTB(RB0RB7)?PORTC(RC0RC7)?PORTD
(RD0RD7)? PORTE(RE0RE2)?,?????????
54- PORTA
- PIC16F877?PORTA ???6?(RA0RA5),PORTA
??????????????,??????,PORTA ??????????,??????????
- PORTB
- PORTB ???8?(RB0RB7),?????????????????,??,??????,?
??????,??? ??36(RB3/PGM)???39(RB6/PGC)?
??40(RB7/PGD)? - PORTC
- PORTC ???8?(RC0RC7),??????? I/O
?,?????????????????,?? CCP(??????)?I2C?SPI(???????
?)?UART(????????)?? - PORTD
- PORTD ???8?(RD0RD7),?????? I/O?,?? PSP(Parallel
Slave Port)????????????????????,??????????????????
? - PORTE
- PORTE ???3?(RE0RE2),PORTE ? ??8?9?10 ?????,????
I/O ??,????????,??? PORTD ???????????????,?/RD?/WR
?/CS ?,????PORTE ???
55?2.33 ???????
?2.11 ???????