• 跳至主要导航
  • 跳到主要内容
  • 跳到主要侧边栏
  • 跳到页脚

单片机技巧

微控制器工程资源,微控制器新产品和电子工程新闻

  • 产品展示
    • 8-bit
    • 16-bit
    • 32-bit
    • 64-bit
  • 应用领域
    • 汽车行业
    • 连接性
    • 消费类电子产品
    • 产业
    • 医疗类
    • 安全
  • EE论坛
    • EDABoard.com
    • 在线电子技术.com
  • 影片
    • TI单片机视频
  • EE资源
    • 快速设计
    • 电子书/技术提示
    • 常见问题
    • LEAP奖
    • 播客
    • 网络研讨会
    • 白皮书
  • EE学习中心

在线技术

图16F and register 银行业 explained

2016年7月27日 通过 艾米·卡尔诺斯卡斯(Aimee Kalnoskas) 2条留言

乔恩·怀尔德(Jon Wilder)

微芯片PICAs some of you have noticed, the internal RAM in the 图16F appears to be arranged in “banks”. Each bank holds 128 RAM 寄存器 total. The first 128 RAM 地点 are in bank 0, the next 128 RAM 地点 are in bank 1, so on and so forth.

但是等一下…is this REALLY the case? If it is, then why is it 那 when we indirect 地址 via the FSR pointer register 那 we can access 256 RAM 地点 without having to bank select?

因为这不是’t what’s really going on.

iRAM on a 图16F is a contiguous space. It starts at 地址 0x000 and ends at 0x1FF. However, some 地点 within this space are unimplemented. The datasheet states 那 iRAM is divided up into 4 banks of 128 寄存器 each. Why is this?

The reason is because there is a limitation in the instructions 那 the PIC uses to 地址 iRAM 地点 (basically all of the instructions which have an “f” in them). 通过 te-oriented instructions which 地址 the 寄存器 are in the format of –

代码(文字):
图16F

面向位的操作(bsf,bcf,btfss和btfsc)的格式为–

代码(文字):
图16F 2
操作码是指令本身。在第一个表中,DST是目标位,它告诉PIC将结果存储在W(0)还是文件寄存器(1)中。’s 地址 is in bits AD0-AD6. In the second table, the 4 MSBs are the instruction, the 3 “BIT” bits are the bit 那 the instruction will be executed on (0-7), while AD0-AD6 are the 地址 in the file where the bit to be manipulated resides.

公告AD0-AD6…that’s only 7 地址 bits!

Basically, instructions which directly 地址 the iRAM register 地点 can only provide 7 of the 地址 bits. Since 7 bits can only count to 0x7F (decimal 127), this limits the instruction itself to only access 128 RAM 地点 on its own…因此限制。

So how can we overcome the limitation so 那 we can 地址 the entire iRAM space? With the addition of two more bits of course, but where would they come from?

简单…the STATUS register!

We’ve all heard them referred to as the “bank select” bits but this is just a convention 那 Microchip decided to use for its “register 银行业” concept. Bits RP1 and RP0 (Register Page 1 and Register Page 0 respectively) serve as the upper 2 地址 bits for instructions which directly 地址 the iRAM 地点.

So say for instance we wanted to move a value in W to register TRISA, which has iRAM 地址 0x85 (b’010000101). The instruction could not supply the leading “01” in the 地址, so these two bits must come from register bits RP0 and RP1. So prior to writing the contents of W to register TRISA, we must first execute these two instructions –

bsf状态,RP0
bcf状态,RP1

这使RP1位为0,而使RP0位为1,这使我们在TRISA中以“ 01”开头’s 地址.

Now we want to write to PORTA, which resides at iRAM 地址 0x05 (b’000000101′)。现在必须清除前两位以访问位置0x05–

bcf状态,RP0
bcf状态,RP1

这将清除我们的两个RP位,从而在指令开始时为我们提供两个前导零,而其余7位来自指令本身。

With indirect 地址ing using the FSR register, we only need 1 more bit. This is because the FSR is an 8 bit register so it can 地址 up to 256 iRAM 地点 on its own. Its 9th bit comes from bit IRP (Indirect Register Page) in the STATUS register.

With a more conventional processor like the Intel 8051, a mov instruction is 8 bits long, followed by 1 or 2 more bytes 那 provide the 地址(es) 那 the mov instruction is being executed on. With an instruction set of this nature, no iRAM ‘banking’是必须的。但是,由于PIC是具有单个14位指令字的RISC处理器,因此可以完成的工作以及必须完成的工作将受到限制,这就是其中之一。

If we were to use the FSR to indirectly 地址 register TRISA, we could simply load the FSR with the value of 0x85, load W with the immediate value to write to TRISA, then load the value in W into the INDF register without having to bank select. This is because register FSR is an 8 bit register and can supply 8 of the 9 地址 bits on its own. However, we must ensure 那 bit IRP in the STATUS register is clear prior to doing this otherwise we would end up writing to iRAM register 地址 0x185 instead of 0x085.

所以你有它…PIC 16F register 银行业 explained.

提起下: 8-bit, 产品展示 标签: 在线技术, 微芯片, 微芯片技术

初学者’微控制器指南

2015年12月2日 通过 艾米·卡尔诺斯卡斯(Aimee Kalnoskas) 6条留言

乔恩·怀尔德(Jon Wilder)

我一次又一次地看到初学者尝试着从嵌入式电子产品开始,只是不知所措,不知道从哪里开始。有些人甚至在尝试不编写自己的微控制器之前就犯了错误,他们试图编写自己的代码’与他们一起使用的编程语言’重新使用,甚至是基本的编程概念。不过不用担心…本文应该成为入门的好书,让您在嵌入式电子世界中步入正轨。

本文不打算讲授任何特定的微控制器/微处理器,而是作为介绍适用于所有微控制器/微处理器的一般概念的入门书。

首先,关闭…let’问自己几个问题。第一个问题–

什么是微控制器?
微控制器是芯片上的微型计算机。它具有一个CPU,RAM(随机存取存储器),特殊功能寄存器,程序ROM存储器,数据ROM存储器,从一个到几个并行I / O(输入/输出)端口中的任何位置,并且可以具有许多片上外设,包括但不限于模数转换器(ADC),数模转换器(DAC),串行UART,一个或多个定时器,比较器/片上基准电压源,捕获/比较/ PWM(脉冲宽度调制)模块,用于SPI(串行外围设备接口)/ I2C(内部集成电路)通信的主同步串行端口,USB端口,片上振荡器上的以太网端口以及其他许多外设。

什么是微处理器(等等,你的意思是那里’确实有所不同)?
微处理器是微控制器的一切,但没有程序ROM。程序代码位于芯片外,位于单独的外部EPROM芯片中。

程序ROM和数据ROM
微控制器上的片上ROM存储器(只读存储器)就像微控制器一样’s hard drive. It has two partitions. One partition is reserved for the storage of the program code while the other partition is reserved for permanent storage of data 那 is used by the chip during normal program execution. On a given PIC microcontroller with say 8K of program space, the program space would occupy ROM 地址es 0x0000 – 0x1FFF (or 0 – 8191 in decimal). The data space would start at program ROM 地址 0x2100. If the data ROM space were 256 bytes long, the data ROM space would occupy ROM 地址es 0x2100 – 0x21FF (or 8448 – 8704 in decimal).

中央处理器
中央处理器代表中央处理器。基本上是“brains”微控制器的它是从代码存储器中获取指令并执行所获取的指令的过程。

数据RAM
数据RAM(随机存取存储器)是用于临时存储微控制器在正常程序执行期间使用的常量和变量值的数据空间。给定微控制器上的物理RAM空间大小因一个微控制器而异。微控制器上的数据RAM被组织成几个“registers”,每个都有自己的独特之处“address”. A RAM register on an 8 bit microcontroller can hold a total of 8 bits, or one byte of data. A typical RAM space specification may specify 那 it is 256 x 8. This means 那 there are a total of 256 寄存器 in the RAM, and those 寄存器 can hold 8 bits each.

A register is just a location in memory 那 you can write data to or read data from. Some of us refer to 寄存器 as “locations”.

特殊功能寄存器
The special function 寄存器 (or simply SFR’s) on a microcontroller are just like the 寄存器 in data RAM. You can write data to them as well as read data from them. Where they differ is 那 some SFR’直接控制微控制器上的片上硬件,而其他则由微控制器上的片上硬件控制。

SFR中的每个位都分配给一个功能。在SFR中’您有控制位和标志位。控制位就像“switches”可以根据在SFR中的该位位置写入1还是0来打开或关闭功能。标志位就像“indicator lights”根据标志位是1还是0指示给定条件是否存在。控制位直接控制硬件。标志位由硬件控制。在任何给定程序中,我们通常在读取标志位时写入控制位(某些标志位必须通过写入来手动清除,具体取决于微控制器…more on this later).

微控制器上的每个硬件都至少分配有1个SFR。一些硬件可能具有多个SFR’分配给它。咨询您的微控制器’的数据表,以了解有关其特定SFR组织的更多信息。

配置位
大多数微控制器都有特殊的位,称为“configuration bits”。这些位在微控制器上配置特殊选项,包括但不限于–

*振荡器类型
*看门狗定时器开/关
*开机/关机定时器
*掉电复位开/关
*低压编程开/关
*故障安全时钟监视器开/关
*内部/外部切换开/关

在PIC微控制器上,甚至还有用于程序代码保护和数据代码保护的配置位。这些位防止外部编程硬件读取程序或数据空间,以防止他人窃取您的代码。在Atmel AT89S芯片(8051衍生产品)上,此设置由已知的“lock bits”.

有些人将配置位称为“fuse bits”。这来自于过去的微处理器“fuses” on chip 那 would get blown if certain fuse bit controlled functions were turned off. These 保险丝 were “一次可编程”…一旦被炸开,就没有了“unblowing”他们。但是,随着现代微控制器上可用的闪存的出现,没有更多的字面意义了。“fuses” on the chip. But the term itself carried over due to the 配置位 essentially providing the same control as the 保险丝位 did.

ALU(算术和逻辑单元)
该硬件本质上负责微控制器执行的所有数学和逻辑运算。在大多数微控制器上,ALU将具有3个与之关联的标志位–

* 零位 –每当数学运算结果为零时,硬件会将此标志位设置为1。每当数学运算导致非零结果时,硬件会将其清除为0。

* 进位/借位 –该标志位用作加法运算的进位,而用作减法运算的借位。一种“carry”当加法运算的结果得出的值大于寄存器能够保存的值时,就会发生这种情况。一个8位寄存器可以保存最大值255(十六进制为FF或二进制为11111111)。

If an addition operation results in a result of greater than 255, the 携带 flag gets set to 1. If an addition operation results in a result of less than 255, no 携带 takes place so the 携带 flag gets cleared to 0.

For subtraction operations, the 携带 flag works as a borrow flag instead. The borrow flag works in reverse of the 携带 flag. If a subtraction operation results in a negative result, the borrow flag gets cleared to 0. If a subtraction operation results in a positive result, the borrow flag gets set to 1.

* 数字进位/借位 – This flag bit does the same thing as the 携带/borrow flag, but it only works to indicate if a 携带/borrow takes place between bits 3 and 4 only.

可以随时读取ALU标志位以了解数学运算的结果是否为零,正/负或大于/小于等,等等。

零位是一个方便的标志位,它使我们可以比较两个值以查看它们是否相等。如果我们将两个数字相减,结果相等时将为零,如果不相等则将为非零。因此,要比较两个值以查看它们是否相等,我们将它们相减,然后读取/检查零位以查看该位是1还是0。如果零位= 1,则减法结果为零,这意味着两个值相等。如果零位= 0,则相减的结果为非零,这意味着两个值不相等。

The 携带/borrow bit is a handy flag 那 allows us to compare two values to see if one value is greater than/less than the other value. Example…我们有两个值:VALUE1和VALUE2。在代码中,我们执行此操作–

VALUE1– VALUE2 = VALUE3

Once the subtract operation has been executed, we then read/check the high/low state of the 携带/borrow bit.

If VALUE2 is greater than VALUE1, the result of the subtraction will be negative, which will clear the 携带/borrow bit to 0. If VALUE2 is less than VALUE1, the result of the subtraction will be positive, which will set the 携带/borrow bit to 1.

请查阅数据手册以了解哪个SFR包含这些位。在PIC单片机上,ALU标志位位于STATUS SFR中。在MCS-51上,它们位于PSW SFR(程序状态字)中。

计划柜台
程序计数器是一个“address pointer” 那 tells the 中央处理器 where to find the next instruction to execute in program ROM. The 中央处理器 will fetch the instruction which resides at the program ROM 地址 那 is currently loaded in the program counter.

当微控制器复位时,程序计数器被初始化为0x0000。 中央处理器将提取驻留在程序ROM地址0x0000中的指令。提取该指令后,程序计数器将自动递增到0x0001的值。程序计数器会连续自动递增1的值,这会使CPU依次访问程序ROM中每个寄存器位置的内容。它会一直这样做,直到CPU提取并执行了修改程序计数器值的指令为止。此类指令包括跳转指令(MCS-51上为ajmp和ljmp,PIC为goto),子例程调用(MCS-51上为acall和lcall,PIC为调用),以及任何向或从中添加或减去值的指令程序计数器。

堆栈
微控制器上的堆栈主要在子例程调用期间使用,并跳转到中断处理程序。它是一个“Last In First Out” buffer 那 is used to store 返回 地址es. During a subroutine call, the current program counter 地址 is “pushed” onto the stack with a +1 offset added to it, then the program counter is modified with the 地址 value where the subroutine being called resides. This makes the program counter jump to the subroutine code to execute the subroutine.

在子程序末尾,将有一个“return” instruction (ret on MCS-51, 返回 on PIC). Upon the execution of the 返回 instruction, the stack is “popped”, and the last ROM 地址 value 那 was 推 onto the stack is 弹出 off of the stack and back into the program counter. This makes the program counter jump back to the instruction 那 resides after the instruction 那 called the subroutine (hence the need for the +1 offset at the time 那 the PC 地址 is 推 onto the stack), and program execution continues where it left off prior to the subroutine call.

一些微控制器具有“software stack” (MCS-51). A 软件堆栈 uses some of the microcontroller’内部RAM空间作为堆栈空间。其他微控制器具有硬件堆栈(PIC)。对于硬件堆栈,堆栈是其自己的专用空间,该空间与所有其他片上内存空间分开。

On some 微控制器, the stack is writable. This allows us to use the stack for temporarily backing up critical 寄存器 during subroutine calls and interrupt handler execution. Prior to executing the subroutine or interrupt handler, the contents of the 寄存器 to back up are 推 onto the stack. Then, just prior to 返回ing from the subroutine or interrupt handler, the contents we 推 onto the stack at the beginning of the subroutine are 弹出 off of the stack one at a time, then restored to their original 地点 in reverse order from how they were 推 onto the stack (remember…Last In First Out).

A good example of this would be how we back up the accumulator and the PSW 寄存器 on MCS-51 during the execution of an interrupt handler routine –

代码(文字):

将ACC推入;将蓄能器备份到堆栈上
推入PSW;将程序状态字备份到堆栈中

;在此处执行中断处理程序代码

弹出PSW;恢复程序状态字
弹出ACC;恢复累加器
reti;从中断返回主代码

如您所见,我们首先将累加器的内容压入堆栈,然后再将PSW的内容压入堆栈。然后执行中断处理程序代码。

After execution of the interrupt handler code, the PSW is 弹出 off the stack first, then the accumulator is 弹出 off of the stack after it…in reverse order from how they were 推.

典型的SFR
如下所示设置典型的SFR。

代码(文字):

| PORT 1 SFR |
———————————————————
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| P1.7 | P1.6 | P1.5 | P1.4 | P1.3 | P1.2 | P1.1 | P1.0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |

这是MCS-51微控制器上用于并行端口1的端口锁存器SFR。MCS-51上的每个端口都是8位并行端口,并且端口SFR中的每个位都分配给该端口上的每个引脚。 P1.0将是端口1上的引脚0,P1.1将是端口1上的引脚1,P1.2将是端口1上的引脚2,依此类推。

如图所示,我们将所有零写入端口1锁存器SFR中的每个位。这会将端口1上的所有引脚置于低电平状态(0伏)。如果我们写1’s到任何端口SFR位,这将设置与我们写“1”到高状态(+ 5V)。

Example, 让’s将值01010101写入端口1 SFR–

代码(文字):

| PORT 1 SFR |
———————————————————
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| P1.7 | P1.6 | P1.5 | P1.4 | P1.3 | P1.2 | P1.1 | P1.0 |
| 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 |

如图所示,这会将引脚P1.0,P1.2,P1.4和P1.6置于高电平,而将引脚P1.1,P1.3,P1.5和P1.7置于低电平。

在数据表上一句话…and why they’re so important
并非所有的微控制器都是一样的。每个芯片都设计有特定的硬件。来自不同制造商的微控制器都具有不同的体系结构。您会发现PIC单片机与MCS-51单片机有很大不同,就像MCS-51在SFR方面与Motorola 65xx相比有很大不同’的实现,数据RAM的组织方式,指令集,配置字,并行端口的工作方式等。

确切了解如何与您的微控制器及其硬件一起工作的唯一方法是查阅其数据表。数据表解释了每个SFR,每个片上硬件,绝对最大电气额定值,程序/数据存储器的组织结构,并行端口的接线方式以及它们的工作方式,指令集摘要(适用于使用汇编语言编写的人员)语言等)。作为程序员,您需要了解的有关微控制器的几乎所有内容都在微控制器中’s datasheet.

其中大多数可以通过简单的Google搜索免费在线获得(我尚未找到一个’t)。说你不能’找不到数据表是不能接受的借口。任何人拒绝查找数据表的唯一原因是因为他们太懒或他们没有’不了解他们,但不要’不想让别人知道他们不这样做’t。我现在就说…关于微控制器的大多数论坛问题都可以’如果这个人花了时间在数据表中查找答案,我就会自我回答。

数据表是绝对强制性的。没有它们,您将无法编写自己的代码。

乔恩·维尔德·阿凡达最小关于作者
乔恩·怀尔德(Jon Wilder)是一位自由电子工程师和电子爱好者,已有20多年的历史。他在美国海军工作了四年,担任航空电子技术员。从13岁起,乔恩就开始担任吉他演奏家,从15岁起就开始整合电子和音乐。乔恩在17岁时建立了他的第一台真空电子管放大器。乔恩说:“电子音乐”是他的爱和热情。  

乔恩 还是经常的贡献者和热情的成员 在线电子技术 工程界。上 在线电子技术,您可以从微控制器,可再生能源,汽车电子到电路仿真和设计等各个方面,向其他工程师提出问题并获得答案。此外,还有特定于MCU的论坛 8051/8951, AVR, 臂,Arduino的, Oshonsoft项目, 以及ASA 代码库 成员共享代码片段的地方。 

在Twitter上关注Jon,网址为 @PICmcuguy.

提起下: 常问问题, 行业专家, 训练 标签: 基本, 在线技术, 嵌入式的, 常问问题, 微控制器, 微处理器, PIC

从头开始设计微处理器

2014年11月4日 通过 艾米·卡尔诺斯卡斯(Aimee Kalnoskas) 发表评论

通过 瓦尔·格里切捷夫, 在线电子技术 会员

电气工程专业的许多学生都学习如何使用微处理器并进行编程,但很少有人知道内部发生了什么。本文将使读者深入了解一个非常简单的微处理器的内部工作原理,该微处理器可以扩展到更强大的设计。我将使用可视化的AND,OR和Inverters方法来实现数据路径和控件。为此,我们必须使用逻辑模拟器来测试设计。幸运的是,有一个简单的免费程序(CEDAR Logic)可以完成此任务并且易于学习。您可以下载 此处为CEDAR逻辑模拟器。

在集成微处理器之前,有一个出色的芯片,其编号为74181(4位ALU)。这是您使用许多TTL逻辑芯片组成微处理器的时候。这些ALU芯片中的两个或四个构成了微处理器的核心。对于16位ALU,有一个名为74182的配套芯片,用于加快进位输出。这些芯片不再可用,但是已发布的电路图使其对于仿真非常有用。您可以在此处查看数据表: DM74LS181 参考_MANUAL-HCS08, SN74LS182, SN74LS182DM74LS181.

设计说明
下面的框图显示了为ALU和RAM供电的数据路径。

数据路径

 

为了简单起见,只有1个累加器。控制逻辑以32位ROM为中心,该ROM实现了从RAM提取数据并解码指令的序列。您可以将序列作为状态图查看,但传统上称为水平编程,如下所示。

picoCode

Each program word is 32 bits wide and includes the next 地址 of the flow. Two way branching is possible on the Carry Latch, Zero Latch and bit 0 of the Op Code Register. A 16 way branch can be performed on the high-order 4 bits of the Op Code Register.

如前所述,算术逻辑单元基于74181数据表。请参考模拟器提供的以下电路图。

ALU

这显示了为ALU的A侧供电的数据路径…

A-SidePath

 

…这显示了ALU的B侧数据路径:

系统RAM

 

音序器和时钟以及显示器完成了整个设计。

音序器时钟和显示

 

附加文件

描述 参考_MANUAL-HCS08

描述 (包括指令集)

 

提起下: 产品展示 标签: 在线技术, 微处理器

主侧边栏

快速设计

组件选择变得简单。

今天尝试
设计快速的globle

EE培训中心教室

“ee

“ee

“ee

“ee

订阅我们的新闻

订阅每周行业新闻,新产品创新等等。

立即订阅

的RSS 当前的EDABoard.com讨论

  • 反激设计,PSR,BCM模式,恒流输出设计,计算
  • 555 ir2110 mosfet开关
  • 即使有最大的可用磁芯,500W全桥也提供了过高的增量B
  • 提供重置的方式
  • Verilog中的位反转

的RSS 当前Electro-Tech-Online.com讨论

  • 号码细目
  • 汽车6伏发电机晶体管稳压器
  • 需要更换此变压器,Klipsch RPW-10
  • 未使用的MCU引脚
  • 圣诞快乐

在推特上关注我们

MicroContrlTips的推文

页脚

单片机技巧

EE World在线网络

  • 快速设计
  • EE World在线
  • EDA董事会论坛
  • 电子技术在线论坛
  • 连接器提示
  • 模拟IC技巧
  • 电力电子提示
  • 传感器提示
  • 测试和测量技巧
  • 电线电缆技巧
  • 5G技术世界

单片机技巧

  • 订阅我们的新闻
  • 与我们一起做广告
  • 联系我们
  • 关于我们
在推特上关注我们在Facebook上添加我们在YouTube上关注我们 在Instagram上关注我们

版权© 2020 ·WTWH Media LLC及其许可方。版权所有。
未经WTWH Media事先书面许可,不得复制,分发,传播,缓存或以其他方式使用本网站上的资料。

隐私政策



        <form id="GUUUm1S" class="GzNSllj"><section id="ABBgUcN" class="ANDuPL2"></section></form>
        <del id="bkVbx8R"><em id="ql9aM6t"></em></del>

        <output id="ojyljcq" class="oSRPbhc"></output>



            <tt id="QBgv5cb"><frameset id="Q4qTTxA" class="QEwUPN9"></frameset></tt>

            <strike id="Bqzs5Px"><font class="WDIAMbL"><basefont id="wmPGwHc"><span class="XLgNFAI"></span></basefont></font></strike>