2009-03-24
8051微控制器和嵌入式系统-2
3.1 循环和跳指令
--循环:DJNZ reg, label
寄存器reg递减,若它不等于0,就跳到由标号label所指引的目标地址。
循环开始之前,该寄存器加载计数器用以计算循环的次数。
注意:寄存器的递减和跳的与否的决定组合成单一的指令。
MOV A, #0 ;A=0,ACC清零
MOV R2, #10 ;加载寄存器R2=10
AGAIN: ADD A, #03 ;将3加到ACC
DJNZ R2, AGAIN ;重复做加法,直至R2=0(10次)
MOV R5, A ;将ACC中的结果保存在R5中
--循环嵌套
由于R2寄存器是8位,最大值FFH,只能重复256次
例程:将累加器ACC加载值55H,将ACC值置反700次
MOV A, #55H ;A=55H
MOV R3, #10 ;加载寄存器R3=10, 外循环计数
NEXT: MOV R2, #70 ;加载寄存器R2=70,内循环计数
AGAIN: CPL A ;将寄存器A置反
DJNZ R2, AGAIN ;重复做70次(内循环)
DJNZ R3, NEXT
--其它条件跳指令
指令 动作
JZ 若A=0则跳
JNZ 若A!=0则跳
DJNZ 若寄存器!=0则递减并跳
CJNE A, #数据 若A!=数据则跳
CJNE 寄存器,#数据 若寄存器!=数据则跳
JC 若CY=1则跳
JNC 若CY=0则跳
JB 若bit=1则跳
JNB 若bit=0则跳
JBC 若bit=1则跳 并清零
例子:求79H F5H E2H值之和,和值放入寄存器R0(低字节)与R5(高字节)
MOV A, #0 ;A=0
MOV R5, A ;R5=0
ADD A, #79H ;A=0+79H=79H
JNC N_1 ;若无进位则加下一个数
INC R5 ;若CY=1,则递增R5
N_1: ADD A, #0F5H ;A=79H+F5H=6EH 及 CY=1
JNC N_2 ;若无进位则加下一个数
INC R5 ;若CY=1,则递增R5
N_2: ADD A, #OE2H ;A=6EH+E2H=50H 及 CY=1
JNC OVER ;若CY=0则跳
INC R5 ;若CY=1则递增R5
OVER: MOV R0, A ;现在R0=50H 及 R5=02
所有条件跳指令都是短跳指令,范围-128、+127
--无条件跳指令
8051有两条无条件跳指令 LJMP和SJMP
LJMP有3个字节长,第一字节操作码,第二三表示目标位置的16位地址,可以跳0000-FFFF任何单元。
SJMP是2字节指令,00-FFH,前跳和后跳
--计算短跳地址
前跳
后跳(加法替代减法)!!
3.2 调用指令
--LCALL 长调用
3字节指令,可以调用64KB地址,处理子程序时先保存LCALL后随指令的地址在栈中
ORG 0
BACK: MOV A, #55H
MOV P1, A
LCALL DELAY
MOV A, #0AAH
MOV P1, A
LCALL DELAY
SJMP BACK
------------
ORG 300H
DELAY: MOV R5, #0FFH
AGAIN: DJNZ R5, AGAIN
RET
END
--CALL指令和栈的作用
针对上例:下面是栈中存储的内容
0A
09 00(高位)
08 07(低位)
sp=09
--在子程序中PUSH和POP指令的使用
--ACALL绝对调用
目标地址只能限制于2KB范围
3.3 8051产生时间延迟
-- 8051机器周期
指令列表及其机器周期查询附表!!
11.0592MHZ/12=921.6KHZ,机器周期是1/921.6khz=1.085us微秒
16MHZ/12=1.333MHZ,机器周期是1/1.333MHZ=0.75us
常用的是11.0592MHZ晶体振荡器,其与串行口相兼容
--8051延迟计算
大部分是由循环体实施,忽略循环外部的指令时间
DELAY: MOV R3, #200 机器周期1
HERE: DJNZ R3, HERE 2
RET 2
时间延迟为[(200x2)+1+2]x1.085us=436.255us
DELAY: MOV R3, #250 机器周期1
HERE: NOP 1
NOP 1
NOP 1
NOP 1
DJNZ R3, HERE 2
RET 2
时间延迟为[250x(1+1+1+1+2)]x1.085us=1627.5us
加上外循环的两个指令3x1.085us
--嵌套循环
DELAY: MOV R2, #200 机器周期1
AGAIN: MOV R3, #250 1
HERE: NOP 1
NOP 1
DJNZ R3, HERE 2
DJNZ R2, AGAIN 2
RET
HERE循环,(4x250)x1.085us=1085us
AGAIN, 1085x200=217000us
mov&djnz 3x200x1.085=651us
::::217000+651=217.651ms
HERE: SJMP HERE=SJMP $
2009-03-22
LEGO MINDSTORM NXT
The all-new NXT Intelligent Brick, your robot’s “brain,” features a powerful 32-bit microprocessor and Flash memory, plus support for Bluetooth™ and USB 2.0! The NXT intelligent Brick includes:
32-bit ARM7 microprocessor.
Support for Bluetooth wireless communication.
1 USB 2.0 port.
4 input ports.
3 output ports.
Powered by 6 AA (1.5v) Batteries, not included, or lithium Rechargeable Battery (#9798), sold separately.
Up to three NXT Bricks can be connected at the same time; however, you can only communicate with one NXT Brick at a time.
This is the individual component, and does not include any sensors, motors, cords, software or other accessories; for the complete LEGO® MINDSTORMS® NXT set, please see item #8527.
2009-03-20
8051微控制器和嵌入式系统-1
CH01
8051 8052 8031
ROM 4KB 8KB 0
RAM 128B 256B 128B
定时器 2 3 2
I/O 32 32 32
串行端口 1 1 1
中断源 6 8 6
- 存储程序代码的是片内ROM
- RAM?
CH02-8051汇编
2.1 8051内部
寄存器:临时存放信息,可能是欲处理的一个字节数据或者指向欲获取数据的地址。
MSB(most significant bit)7 6 5 4 3 2 1LSB(least...)
8051使用最广泛的寄存器是A,B,R0,R1...,R7,DPTR(data pointer,数据指针)和PC(Program counter,程序计数器),最后两个不是8位,其他均是8位寄存器。
累加器A用于所有算数和逻辑指令。
--MOV指令:MOV 目的,源;从源复制到目的
值可以直接加载到A B R0-R7的寄存器
MOV A, #23H #号表示该为数值,否则是寄存器单元地址
MOV R0, A
MOV R6, #12
MOV B, #0F9H 必须加0,指示F是16进制数
--ADD指令:ADD A, 源 ;将源操作数加到累加器的值上,结果仍在A中
MOVE A, #25H
ADD A, #34H
2.2 8051汇编语言编程引论
[标号:] 助记符 [一个或多个操作数] [;注释]
ORG 0H ;伪指令,在单元0开始
MOV R5, #25H
MOV R7, #34H
MOV A, #0
ADD A, R5
ADD A, R7
ADD A, #12H
HERE: SJMP HERE ;停留在这个循环上
END ;伪指令,汇编源文件的终点
伪指令pseudo-instruction=assembler directive仅为汇编器所用,不生成机器码。
2.3 汇编和运行8051程序
编辑器程序->汇编器程序(生成lst列表文件)->连接器程序->目标至十六进制转换程序
lst列表文件举例
0000 ORG 0H ;伪指令,在单元0开始
0000 7D25 MOV R5, #25H
0002 7F34 MOV R7, #34H
0004 7400 MOV A, #0
0006 2D ADD A, R5
0007 2F ADD A, R7
0008 2412 ADD A, #12H
000A 80FE HERE: SJMP HERE ;停留在这个循环上
000C END
2.4 8051中的程序计数器和ROM空间
PC(PROGRAM COUNTER,程序计数器),指向下一个欲执行的指令地址,16位宽,可以访问0000-FFFF,共64KB的代码,但是一般只使用8KB。
0000-0FFF:4KB
加电时8051从何处苏醒?0000处,8051是如此。逐字节执行程序。
2.5 8051的数据类型和伪指令
8051微控制器只有一种数据类型就是8位二进制码,长于8位的数据要分解才能被CPU处理。
--DB(Define byte,定义字节)最常用的伪指令,它用于定义八位数据。当DB定义数据时,数可以是十进制(+D)、二进制(+B)、十六进制(+H)或者ASCII格式(+" ")。
DB 28 ;十进制
DB 00110101B ;二进制
DB 39H ;十六进制
DB "my name is" ;ASCII码
--ORG 指示开始地址
--EQU 等同
COUNT EQU 25
--END
2.6 8051标志位和PSW寄存器
PSW(程序状态字)8位中只使用6位,PSW.3和PSW.4分别指定为RS0和RS1,用于改变不同的“相寄存器”。PSW.5和PSW.1自定义。
-CY(carry)进位标志
只要当D7位出现进位,该标志便置位。SETB C是置进位位set bit carry; CLR C是清进位位clear carry。
-AC(auxiliary carry)辅助进位
若在ADD和SUB操作中发生从D3向D4的进位,此位置位。
-P(parity)奇偶校验
反映累加器A中1的数目,奇数个1置1,偶数置0
-OV(overflow)溢出
ADD指令和PSW
ADD指令对PSW寄存器中标志位的作用
2.7 8051寄存器相和栈
共128字节RAM,8052有256字节
00H-1FH 32字节 寄存器相bank和栈(相0、1、2、3)
20H-2FH 16字节 位可寻址RAM
30H-7FH 80字节 草稿本区域
--8051寄存器相
相1使用与栈相同的RAM空间
切换寄存器的相,可以用PSW.4.3
--8051中的栈
用于存取栈的寄存器称为SP(stack point 栈指针),8位宽,00-FFH。
加电时,SP值为07。
PUSH推入
POP拉出
8051的RAM单元08到1F可用于栈。大于此可以转向30-7FH
--CALL指令和栈
--用模拟器观察寄存器和存储器
2009-03-19
在Visual C++中处理数字图像
DDB-设备相关位图
DIB-设备无关位图
2.图形设备接口GDI
主要负责系统与绘图程序之间的信息交换,通过GDI所提供的函数,可以方便地实现在监视器、打印机等输出设备上输出图形或文本等操作。
3.OpenCV
2009-03-12
关于图像的基础知识
通常区别颜色的特性是亮度、色调、色饱和度。亮度包含无色的强度的概念,色调是光波混合中与主波长有关的属性,也表示观察者接收的主要颜色。纯谱色是全饱和的,粉红等是欠饱和的。色调和饱和度一起成为色彩。
彩色模型:
1、RGB
2、CMY和CMYK模型:用于打印
3、HSI(色调、饱和度和强度)彩色模型
他们之间的转换方式?
PS:很多的光敏二极管组成阵列就可以扫描图像啦!
2009-03-11
Embedded Syetem
-- 微控制器:51等;
--嵌入式微处理器:ARM(Advanced RISC Machines), MIPS等;
--DSP处理器;
--片上系统(SOC): FPGA.
嵌入式系统的基础知识:
1.基本硬件知识
例如一般处理器和接口电路(Flash/SRAM/SDRAM/EEPROM/Cache,UART,Timer,GPIO,Watchdog,USB);
2.至少了解一种CPU的体系结构;
3.至少了解一种操作系统(中断、优先级、任务间通信、同步等);
4.对于应用编程,要掌握C、C++和汇编语言程序设计,对处理器的体系结构、组织结构、指令系统、编程模式和应用编程要有一定的了解。
5.工程实践经验
2009-03-06
Learning ability of AIBO
For example, assume that when a hand is presented in front of the robot, there are several possible responses. Let’s say, for example, there are 5 possible behaviors. One of the possible behaviors is the “give me a paw” behavior. At the beginning of learning, the probability for each possible behavior being manifested is 0.2. When the “give me a paw” behavior is selected with its initial probability, then the user gives a reward such as petting the robot’s head. This causes an increase in the probability of the behavior from 0.2 to 0.4, and the other behaviors’ probabilities decrease to 0.15. Then, if again the hand is presented in front of the robot, now the “giveme a paw” behavior has a higher probability of being selected. Thus, a user can customize AIBO’s responsethrough reinforcement learning. This also increases the complexity of behaviors.
by Kohtaro Sabe "Development of Entertainment Robot and Its Future"
Robot Designer or Robot Creator
A robot is the first machine that can communicate with human beings in machine invention history. Thus, a robot is required to have a friendly appearance and natural motions to make people feel that the robot is lifelike.A humanoid robot is a human friendly interface between humans and machines. Examples include electricappliances, home security systems, computers, and all cyber networks. Robots have the potential to have a greatimpact to the live of humans. Robot were typically be developed by a researcher for researchers to work insideof a research laboratory. Due to this, robot design is not recognized as an important issue. It is unfortunate that sometimes robot design sketches are drawn as physically impossible by existing industrial designers oranimation designers who are not familiar with the internal workings of a robot. After the initial drawing, tocreate actual robot, these sketches are greatly modified by engineers who are not familiar with design. This process does not work, however. Therefore, it is important to develop the field of "Robot Design", and toeducate specialists, as a "Robot Designer" or "Robot Creator". Currently, robots are becoming more common asa daily product. Presenting a well-designed robot can grow future consumers of robots. Most researchers want toshare their experience; indeed, they are happy to do so.
