PIC微控制器
外观
PIC微控制器(PIC microcontroller),是一种使用哈佛结构的精简指令集微控制器,由Microchip公司研发而成。
PIC的架构是明显的最低限度。它具有以下特点:
- 分离式的程序存储器和数据存储器(哈佛结构)
- 少量的固定长度指令
- 指令是单周期执行(4时钟周期),仅流程转移指令(call, goto, return, 成立时的条件跳跃)需两个指令周期
- 所有 RAM 位置均可当作作为算数或其他运算的源寄存器或目的寄存器使用
- 一个堆栈用于存放子程序调用的返回地址
- 较小的数据寻址空间,但使用多个 bank 的方式(每个 bank 通常为 128 字节),来存取较大的 RAM
- 寄存器、外部输入输出端口等均映射在数据空间中
- 程序计数器也是映射到数据空间和写入(这是用来执行间接跳跃)
历史
[编辑]PIC 微控制器源自于 1980 年代由通用仪器所推出的 PIC1650 系列,当时的 PIC 是周边接口控制器(Peripheral Interface Controller)的简称。
GI 的微电子部门于 1987 年分拆成为 Microchip Technology (微芯) 公司。
PIC 产品系列
[编辑]PIC 的产品线宽广,型号众多,现有数百种,各主要系列如下:
8-bit(资料宽度)微控制器
[编辑]使用哈佛结构,脚本与资料的位元宽度可以不同。但各指令的脚本长度均相同。
- Baseline 系列 (12-bit 脚本)
- PIC10F : 6 接脚
- PIC12C5 , PIC12F5 : 8 接脚
- PIC16C5 , PIC16F5 : 14 以上接脚
- Midrange (中端) 系列 (14-bit 脚本)
- PIC12C6 , PIC12F6 : 8 接脚
- PIC16 : 14 以上接脚
- PIC16F1 : 新推出的 Enhanced Midrange (强化中端) 系列
- PIC18 (8-bit 里的高阶) 系列 (16-bit 脚本)
- PIC18 : PIC18C , PIC18Fxxx , 少数早期的 PIC18Fxxxx
- PIC18 Extended : 目前绝大多数的 PIC18Fxxxx, PIC18FxxJxx, PIC18FxxKxx
- flash 产品:
- microchip 收购SST,拥有flash 产品
16-bit(资料宽度)微控制器
[编辑]相当于不具 DSP 相关功能的 dsPIC 微控制器
- PIC24 系列
- PIC24F
- PIC24H
32-bit(资料宽度)微控制器
[编辑]- PIC32 : 采用 MIPS 的 M4K 内核,与其他 PIC 不同。
dsPIC 微控制器(16-bit 资料宽度)
[编辑]- dsPIC30F
- dsPIC33F
8-bit PIC 的指令集
[编辑]PIC的指令十分精简,只有35个,简单易学,故执行速度比8051快。其指令集又分成12-bit PIC instruction set,和14-bit PIC instruction set.
Opcode(二进制) | 助记体 | 说明 |
---|---|---|
0000 0000 0000 |
NOP | No operation |
0000 0000 0010 |
OPTION | Load OPTION register with contents of W |
0000 0000 0011 |
SLEEP | Go into standby mode |
0000 0000 0100 |
CLRWDT | Reset watchdog timer |
0000 0000 01ff |
TRIS f | Move W to port control register (f=1..3) |
0000 001 fffff |
MOVWF f | Move W to f |
0000 010 xxxxx |
CLRW | Clear W to 0 (a.k.a CLR x,W) |
0000 011 fffff |
CLRF f | Clear f to 0 (a.k.a. CLR f,F) |
0000 10d fffff |
SUBWF f,d | Subtract W from f (d = f − W) |
0000 11d fffff |
DECF f,d | Decrement f (d = f − 1) |
0001 00d fffff |
IORWF f,d | Inclusive OR W with F (d = f OR W) |
0001 01d fffff |
ANDWF f,d | AND W with F (d = f AND W) |
0001 10d fffff |
XORWF f,d | Exclusive OR W with F (d = f XOR W) |
0001 11d fffff |
ADDWF f,d | Add W with F (d = f + W) |
0010 00d fffff |
MOVF f,d | Move F (d = f) |
0010 01d fffff |
COMF f,d | Complement f (d = NOT f) |
0010 10d fffff |
INCF f,d | Increment f (d = f + 1) |
0010 11d fffff |
DECFSZ f,d | Decrement f (d = f − 1) and skip if zero |
0011 00d fffff |
RRF f,d | Rotate right F (rotate right through carry) |
0011 01d fffff |
RLF f,d | Rotate left F (rotate left through carry) |
0011 10d fffff |
SWAPF f,d | Swap 4-bit halves of f (d = f<<4 | f>>4) |
0011 11d fffff |
INCFSZ f,d | Increment f (d = f + 1) and skip if zero |
0100 bbb fffff |
BCF f,b | Bit clear f (Clear bit b of f) |
0101 bbb fffff |
BSF f,b | Bit set f (Set bit b of f) |
0110 bbb fffff |
BTFSC f,b | Bit test f, skip if clear (Test bit b of f) |
0111 bbb fffff |
BTFSS f,b | Bit test f, skip if set (Test bit b of f) |
1000 kkkkkkkk |
RETLW k | Set W to k and return |
1001 kkkkkkkk |
CALL k | Save return address, load PC with k |
101 kkkkkkkkk |
GOTO k | Jump to address k (9 bits!) |
1100 kkkkkkkk |
MOVLW k | Move literal to W (W = k) |
1101 kkkkkkkk |
IORLW k | Inclusive or literal with W (W = k OR W) |
1110 kkkkkkkk |
ANDLW k | AND literal with W (W = k AND W) |
1111 kkkkkkkk |
XORLW k | Exclusive or literal with W (W = k XOR W) |
Opcode(二进制) | 助记元 | 说明 |
---|---|---|
00 0000 0000 0000 |
NOP | No operation |
00 0000 0000 1000 |
RETURN | Return from subroutine, W unchanged |
00 0000 0000 1001 |
RETFIE | Return from interrupt |
00 0000 0110 0010 |
OPTION | Write W to OPTION register |
00 0000 0110 0011 |
SLEEP | Go into standby mode |
00 0000 0110 0100 |
CLRWDT | Reset watchdog timer |
00 0000 0110 01ff |
TRIS f | Write W to tristate register f |
00 0000 1 fffffff |
MOVWF f | Move W to f |
00 0001 0 xxxxxxx |
CLRW | Clear W to 0 (W = 0) |
00 0001 1 fffffff |
CLRF f | Clear f to 0 (f = 0) |
00 0010 d fffffff |
SUBWF f,d | Subtract W from f (d = f − W) |
00 0011 d fffffff |
DECF f,d | Decrement f (d = f − 1) |
00 0100 d fffffff |
IORWF f,d | Inclusive OR W with F (d = f OR W) |
00 0101 d fffffff |
ANDWF f,d | AND W with F (d = f AND W) |
00 0110 d fffffff |
XORWF f,d | Exclusive OR W with F (d = f XOR W) |
00 0111 d fffffff |
ADDWF f,d | Add W with F (d = f + W) |
00 1000 d fffffff |
MOVF f,d | Move F (d = f) |
00 1001 d fffffff |
COMF f,d | Complement f (d = NOT f) |
00 1010 d fffffff |
INCF f,d | Increment f (d = f + 1) |
00 1011 d fffffff |
DECFSZ f,d | Decrement f (d = f − 1) and skip if zero |
00 1100 d fffffff |
RRF f,d | Rotate right F (rotate right through carry) |
00 1101 d fffffff |
RLF f,d | Rotate left F (rotate left through carry) |
00 1110 d fffffff |
SWAPF f,d | Swap 4-bit halves of f (d = f<<4 | f>>4) |
00 1111 d fffffff |
INCFSZ f,d | Increment f (d = f + 1) and skip if zero |
01 00 bbb fffffff |
BCF f,b | Bit clear f (Clear bit b of f) |
01 01 bbb fffffff |
BSF f,b | Bit set f (Set bit b of f) |
01 10 bbb fffffff |
BTFSC f,b | Bit test f, skip if clear (Test bit b of f) |
01 11 bbb fffffff |
BTFSS f,b | Bit test f, skip if set (Test bit b of f) |
10 0 kkkkkkkkkkk |
CALL k | Save return address, load PC with k |
10 1 kkkkkkkkkkk |
GOTO k | Jump to address k (11 bits) |
11 00xx kkkkkkkk |
MOVLW k | Move literal to W (W = k) |
11 01xx kkkkkkkk |
RETLW k | Set W to k and return |
11 1000 kkkkkkkk |
IORLW k | Inclusive or literal with W (W = k OR W) |
11 1001 kkkkkkkk |
ANDLW k | AND literal with W (W = k AND W) |
11 1010 kkkkkkkk |
XORLW k | Exclusive or literal with W (W = k XOR W) |
11 110x kkkkkkkk |
SUBLW k | Subtract W from literal (W = k − W) |
11 111x kkkkkkkk |
ADDLW k | Add literal to W (W = k + W) |
PIC刻录器
[编辑]刻录晶片的方式有两种:普通刻录和在线刻录。
早期的 PIC16C 系列需使用平行刻录。 程序存储器为 Flash 的版本使用方便的序列刻录方式,称为 ICSP。
开发环境
[编辑]Microchip 公司提供免费的开发环境 (MPLAB IDE) 与汇编器,也出售付费与提供有条件免费版本的 C 语言编译器。另有第三方软件商开发各式 C, BASIC 等编译器与开发环境可以选用。
MPLAB 的下一代多平台开发环境 MPLAB-X (基于 Java 技术) 目前尚处于 beta 阶段。
外部链接
[编辑]- Microchip.com(页面存档备份,存于互联网档案馆) 官方网站(美国)
- the PICList(页面存档备份,存于互联网档案馆) FAQ and Archive from the "PICList" email list hosted at MIT。A well respected source of manufacturer-independent solutions, source code, and expertise.
- GPUTILS(页面存档备份,存于互联网档案馆) Open Source assembler and linker.
- Free software tools(页面存档备份,存于互联网档案馆) Free C, C++, Pascal, Basic compilers for the PIC microcontroller series.
- [1](页面存档备份,存于互联网档案馆)Example C code for the rfPIC
- example of robot controlled by PIC16F877A: [2] [3]
- USB Pic Programmer(页面存档备份,存于互联网档案馆) An open source project for a universal PIC programmer
- [4](页面存档备份,存于互联网档案馆) A PIC microcontroller based Network I/O controller
- GameBoy® GB–PIC© Project[永久失效链接] Enable GameBoy hardware to PIC16F877