-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.xml
55 lines (55 loc) · 39.1 KB
/
search.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title><![CDATA[Summary of C]]></title>
<url>%2F2019%2F02%2F01%2FSummary-of-C%2F</url>
<content type="text"><![CDATA[计算运算符优先级大于关系运算符,关系运算符优先级大于逻辑运算符,“非”大于计算运算符。 typedef vs #define #define是C指令,用于为各种数据类型定义别名,与typedef类似,但是他们有以下几种不同: typedef仅限于为类型定义符号名称,#define不仅可以为类型定义别名,也能为数值定义别名,比如你可以定义1为ONE。[#define ONE 1]定义结束后没有分号。 [typedef unsigned char BYTE;]定义结束后有分号。 typedef是由编译器执行解释的,#define语句是由预编译器进行处理的。 scanf()在读取字符串的时候,只要遇到空格就停止读取,例如”this is test”对scanf来说就是三个字符串。 指针:指针变量的定义和初始化,一般有两种方式。1, 定义时直接进行初始化赋值 unsigned char a; unsigned char *p = &a; 2, 定义后再进行赋值 unsigned char a; unsigned char *p; p = &a; 在定义的指针变量前边加上*,这个*p就代表了这个p是个指针变量,不是个普通变量,它是专门用来存放变量地址的。此外,定义*p的时候,用了unsigned char来定义,这里表示指针指向的变量类型是unsigned char型。 指针变量p和普通变量a的区别定义一个变量a,同时也可以给变量a赋值a=1,也可以a=2。定义一个指针变量p,另外还定义一个普通变量a=1,普通变量b=2,那么指针变量可以指向a的地址,也可以指向b的地址,可以写成p=&a,也可以写成p=&b,但就是不能写成p=1或者p=2或者p=a,这三种表达方式都是错误的。因此这个地方,不要看定义*p的时候前边有个unsigned char型,就错误的赋值p=1,这个只是说明p指向的变量是这个unsigned char类型的,而p本身是个指针变量,不可以给他赋值普通的值或者变量。 定义指针p和取值运算p的区别“*”这个符号,在C语言有三个用法,第一个用法很简单,乘法; 第二个用法是定义指针变量的时候用,这个地方使用“*”代表的意思是p是一个指针变量,而非普通的变量; 第三个用法就是取值运算,和定义指针变量是完全两码事,比如: unsigned char a=1; unsigned char b=2; unsigned char *p; p = &a; b = *p; 这样两步运算完了之后,b的值就成了1.在这段代码中,&a表示取a这个变量的地址,把这个地址送给p之后,在用*p运算表示的就是去指针变量p指向的地址的变量的值,又把这个值送给了 b,最终的结果相当于b=a。同样*p,放在定义的位置就是定义指针变量,放在执行代码中就是取值运算。 复合数据类型复合数据类型主要包括:结构体数据类型,共用体数据类型和枚举体数据类型。 1.结构体数据类型声明结构体变量类型一般如下: struct 结构体名 { 类型1变量名1; 类型2变量名2; ,,, 类型n变量名n; }结构体变量名1,结构体变量命名2,...,结构体变量名n; 这种声明方式实在声明结构体类型的同时又用它定义了结构体变量,此时的结构体名是可以省略的,但如果省略后,就不能再次定义这样的结构体变量了。这种方式把类型定义和变量定义混在一起,降低了程序的灵活性和可读性,因此并不建议采用这种方式,而是推荐一下这种方式: struct 结构体名 { 类型1变量名1; 类型2变量名2; ,,, 类型n变量名n; }; struct 结构体名 结构体变量名1,结构体变量名2,...结构体变量名n; 为方便理解,下面构造一个实际的表示日期时间的结构体。 struct sTime{ unsigned int year; unsigned char mon; unsigned char day; unsigned char hour; unsigned char min; unsigned char sec; unsigned char week; }; struct sTime bufTime; struct是结构体类型的关键字,sTime是这个结构体的名字,bufTime就是定义了一个具体的结构体变量。那如果要是给结构体变量的成员赋值的话,写法是 bufTime.year = 0x2013; bufTime.mon = 0x10; 数组的元素也可以是结构体类型,因此可以构成结构体数组,结构体数组的每一个元素都是具有相同结构体类型的结构体变量。例如前面构造的这个结构类型,直接定义成struct sTime bufTime[3];就表示一个结构体数组,这个数组的3个元素,每一个都是结构体变量。同样的道理,结构体数组中的元素的成员需要赋值,就可以写成 bufTime[0].year = 0x2013; bufTime[0].mon = 0x10; 一个指针变量指向一个结构体变量的时候,称之为结构指针变量。结构指针是指向的结构体变量的首地址,通过结构体指针也可以访问到这个结构变量。结构体指针变量生命的形式一般如下: struct sTime *pbufTime; 这里要特别注意的是,使用结构体指针对结构体成员的访问和使用结构体变量名对结构体成员的访问,其表达式有所不同相比。结构体指针对结构体成员的访问表达式为 pbufTime -> year = 0x2013; 或者是 (*pbufTime).year = 0x2013; 很明显前者更简洁,所以推荐大家使用前者。 2.共用体数据类型共用体也称之为联合体,共用体定义和结构体十分类似,同样推荐以下形式: union 共用体名 { 数据类型1成员名1; 数据类型2成员名2; ,,, 数据类型n成员名n; }; union 共用体名 共用体变量; 共用体几个变量共用一个内存位置,也就是成员1,成员2,,,,成员n都用一个内存位置。共用体成员的访问方式和结构体一样的,成员访问的方式是:共用体名。成员名,使用指针来访问的方式是:共用体名->成员名。共用体可以出现在结构体内,结构体也可以出现在共用体内,在编程的日常应用中,最多应用是结构体出现在共用体内,例如: union { unsigned int value; struct { unsigned char first; unsigned char second; }half; }number; 这样一个结构体定义到一个共用体内部,如果采用无符号整形赋值的时候,直接调用value这个变量,同时,也可以通过访问或赋值给first和second这两个变量来访问或修改value的高字节和低字节。 共用体和结构体的主要区别如下: 结构体和共用体都是由多个不同的数据类型成员组成,但在任何一个时刻,共用体只能存放一个被选中的成员,而结构体的成员都存在。 对于共同体的不同成员的赋值,将会改变其他成员的值,而对于结构体不同成员的赋值是相互之间不影响的。 3.枚举数据类型C语言提供了一种称为枚举的数据类型,在枚举类型的定义中列举出所有可能的值,并可以为每个值取一个形象的名字,他的这一特性可以提高程序代码的可读性。枚举的说明如下: enum 枚举名 { 标识符 1 [ = 整形常量], 标识符 2 [ = 整形常量], ,,, 标识符 n [ = 整形常量] }; enum 枚举名 枚举变量; 枚举的说明形式中,如果没有初始化,那么“=整形常量”是可以被省略的,如果是默认值的话,从第一个标识符顺序赋值0,1,2,,,,但是当枚举中任何一个成员被赋值后,它后边的成员按照依次加1的规则确定数值。 枚举的使用,有几点要注意: 枚举中每个成员结束符是逗号,而不是分号,最后一个成员的逗号可以省略。 枚举成员的初始化值可以是负值,但是后边的成员依次加1。 枚举类型变量只能取枚举结构中的某个标识符常量,不可以在范围之外。 C文件的读写打开文件 fopen( ) 函数来创建一个新的文件或者打开一个已有的文件,这个调用会初始化类型 FILE 的一个对象,类型 FILE 包含了所有用来控制流的必要的信息。下面是这个函数调用的原型: FILE *fopen( const char * filename, const char * mode ); 在这里,filename 是字符串,用来命名文件,访问模式 mode 的值可以是下列值中的一个: 关闭文件为了关闭文件,请使用 fclose( ) 函数。函数的原型如下: int fclose(FILE *fp); 如果成功关闭文件,fclose( ) 函数返回零,如果关闭文件时发生错误,函数返回 EOF。这个函数实际上,会清空缓冲区中的数据,关闭文件,并释放用于该文件的所有内存。EOF 是一个定义在头文件 stdio.h 中的常量。 C 标准库提供了各种函数来按字符或者以固定长度字符串的形式读写文件。 写入文件下面是把字符写入到流中的最简单的函数: int fputc( int c, FILE *fp ); 函数 fputc() 把参数 c 的字符值写入到 fp 所指向的输出流中。如果写入成功,它会返回写入的字符,如果发生错误,则会返回 EOF。您可以使用下面的函数来把一个以 null 结尾的字符串写入到流中: int fputs( const char *s, FILE *fp ); 函数 fputs() 把字符串 s 写入到 fp 所指向的输出流中。如果写入成功,它会返回一个非负值,如果发生错误,则会返回 EOF。您也可以使用 int fprintf(FILE fp,const char format, …) 函数来写把一个字符串写入到文件中。尝试下面的实例: #include <stdio.h> int main() { FILE *fp = NULL; fp = fopen("/tmp/test.txt", "w+"); fprintf(fp, "This is testingforfprintf...\n"); fputs("This is testing forfputs...\n", fp); fclose(fp); } 当上面的代码被编译和执行时,它会在 /tmp 目录中创建一个新的文件 test.txt,并使用两个不同的函数写入两行。接下来让我们来读取这个文件。 读取文件char *fgets( char *buf, int n, FILE *fp ); 函数 fgets() 从 fp 所指向的输入流中读取 n - 1 个字符。它会把读取的字符串复制到缓冲区 buf,并在最后追加一个 null 字符来终止字符串。 如果这个函数在读取最后一个字符之前就遇到一个换行符 ‘\n’ 或文件的末尾 EOF,则只会返回读取到的字符,包括换行符。您也可以使用 int fscanf(FILE fp, const char format, …) 函数来从文件中读取字符串,但是在遇到第一个空格字符时,它会停止读取。 #include <stdio.h> int main() { FILE *fp = NULL; char buff[255]; fp = fopen("/tmp/test.txt", "r"); fscanf(fp, "%s", buff); printf("1: %s\n", buff ); fgets(buff, 255, (FILE*)fp); printf("2: %s\n", buff ); fgets(buff, 255, (FILE*)fp); printf("3: %s\n", buff ); fclose(fp); } 当上面的代码被编译和执行时,它会读取上一部分创建的文件,产生下列结果: 1: This 2: is testing for fprintf... 3: This is testing for fputs... 首先,fscanf() 方法只读取了 This,因为它在后边遇到了一个空格。其次,调用 fgets() 读取剩余的部分,直到行尾。最后,调用 fgets() 完整地读取第二行。 二进制I/O函数下面两个函数用于二进制输入和输出: size_t fread(void *ptr, size_t size_of_elements, size_t number_of_elements, FILE *a_file); size_t fwrite(const void *ptr, size_t size_of_elements, size_t number_of_elements, FILE *a_file); 这两个函数都是用于存储块的读写 - 通常是数组或结构体。 参考文献 >-- 郭天祥 C语言版 >-- 菜鸟教程]]></content>
<categories>
<category>编程语言</category>
</categories>
<tags>
<tag>The C programing language</tag>
</tags>
</entry>
<entry>
<title><![CDATA[单片机分时复用]]></title>
<url>%2F2019%2F01%2F27%2F%E5%8D%95%E7%89%87%E6%9C%BA%E5%88%86%E6%97%B6%E5%A4%8D%E7%94%A8%2F</url>
<content type="text"><![CDATA[IO口种类那么io有哪几类呢?这里说的是51单片机总的io分为哪几类。单片机总的io会分为这几类:电平可变化的io口和VCC、GND两类。其中电平可变化的io有P0口、P1口、P2口、P3口、P4口、P5口。那么所谓P0.0又是什么呢?这里个人理解为:p0.0属于P0,P0称为P0口,P0.0称为P0.0端口,如果需要定义一个端口,可使用 sbit Sftclk = P0^0,这样就申明了一个端口P1.6为Sftclk,注意这里是端口而不是口。如果需要使用口怎么办呢?可使用 P0 == 0xFF,这样就可以让P0口的所有端口置成1,即P0.0 = 1,P0.1 = 1……P0.7 = 1,这就是P0口和P0.0的区别。 注意:C-51的数据类型扩充定义: sfr : 特殊功能寄存器声明 sfr16 : sfr的十六位数据声明 sbit : 特殊功能位声明 bit : 位变量声明 接着说单片机的口,P0口普通的io,没有第二功能的,而除了P0口外的其他口都有第二功能,多的第二功能甚至有四个功能。 1:P0端口的结构及工作原理P0端口8位中的一位结构图见下图: 由上图可见,P0端口由锁存器、输入缓冲器、切换开关、一个与非门、一个与门及场效应管驱动电路构成。再看图的右边,标号为P0.X引脚的图标,也就是说P0.X引脚可以是P0.0到P0.7的任何一位,即在P0口有8个与上图相同的电路组成。下面,我们先就组成P0口的每个单元部份跟大家介绍一下:先看输入缓冲器:在P0口中,有两个三态的缓冲器,在学数字电路时,我们已知道,三态门有三个状态,即在其的输出端可以是高电平、低电平,同时还有一种就是高阻状态(或称为禁止状态),大家看上图,上面一个是读锁存器的缓冲器,也就是说,要读取D锁存器输出端Q的数据,那就得使读锁存器的这个缓冲器的三态控制端(上图中标号为‘读锁存器’端)有效。下面一个是读引脚的缓冲器,要读取P0.X引脚上的数据,也要使标号为‘读引脚’的这个三态缓冲器的控制端有效,引脚上的数据才会传输到我们单片机的内部数据总线上。 P0口默认是开漏输出,开漏输出如果要输出高电平,IO电平要靠外部的上拉电阻才能拉成高电平,如果没有外部上拉电阻IO电平就是一个不确定态,所以要用P0口时外部需要加上上拉电阻 上拉电阻就是将不确定的信号通过一个电阻拉到高电平,同时此电阻也起到一个限流作用,下拉就是下拉到低电平,比如IO设置为开漏输出高电平或者高阻态时,默认的电平就是不确定的这时候就需要添加上拉或者下拉让它保持一个确定的状态 D锁存器:构成一个锁存器,通常要用一个时序电路,时序的单元电路在学数字电路时我们已知道,一个触发器可以保存一位的二进制数(即具有保持功能),在51单片机的32根I/O口线中都是用一个D触发器来构成锁存器的。大家看上图中的D锁存器,D端是数据输入端,CP是控制端(也就是时序控制信号输入端),Q是输出端,Q非是反向输出端。对于D触发器来讲,当D输入端有一个输入信号,如果这时控制端CP没有信号(也就是时序脉冲没有到来),这时输入端D的数据是无法传输到输出端Q及反向输出端Q非的。如果时序控制端CP的时序脉冲一旦到了,这时D端输入的数据就会传输到Q及Q非端。数据传送过来后,当CP时序控制端的时序信号消失了,这时,输出端还会保持着上次输入端D的数据(即把上次的数据锁存起来了)。如果下一个时序控制脉冲信号来了,这时D端的数据才再次传送到Q端,从而改变Q端的状态。 多路开关:在51单片机中,当内部的存储器够用(也就是不需要外扩展存储器时,这里讲的存储器包括数据存储器及程序存储器)时,P0口可以作为通用的输入输出端口(即I/O)使用,对于8031(内部没有ROM)的单片机或者编写的程序超过了单片机内部的存储器容量,需要外扩存储器时,P0口就作为‘地址/数据’总线使用。 那么这个多路选择开关就是用于选择是做为普通I/O口使用还是作为‘数据/地址’总线使用的选择开关了。大家看上图,当多路开关与下面接通时,P0口是作为普通的I/O口使用的,当多路开关是与上面接通时,P0口是作为‘地址/数据’总线使用的。 输出驱动部份:从上图中我们已看出,P0口的输出是由两个MOS管组成的推拉式结构,也就是说,这两个MOS管一次只能导通一个,当V1导通时,V2就截止,当V2导通时,V1截止。 前面我们已将P0口的各单元部件进行了一个详细的讲解,下面我们就来研究一下P0口做为I/O口及地址/数据总线使用时的具体工作过程。 1、作为I/O端口使用时的工作原理P0口作为I/O端口使用时,多路开关的控制信号为0(低电平),看上图中的线线部份,多路开关的控制信号同时与与门的一个输入端是相接的,我们知道与门的逻辑特点是“全1出1,有0出0”那么控制信号是0的话,这时与门输出的也是一个0(低电平),与让的输出是0,V1管就截止,在多路控制开关的控制信号是0(低电平)时,多路开关是与锁存器的Q非端相接的(即P0口作为I/O口线使用)。P0口用作I/O口线,其由数据总线向引脚输出(即输出状态Output)的工作过程:当写锁存器信号CP 有效,数据总线的信号→锁存器的输入端D→锁存器的反向输出Q非端→多路开关→V2管的栅极→V2的漏极到输出端P0.X。前面我们已讲了,当多路开关的控制信号为低电平0时,与门输出为低电平,V1管是截止的,所以作为输出口时,P0是漏极开路输出,类似于OC门,当驱动上接电流负载时,需要外接上拉电阻。下图就是由内部数据总线向P0口输出数据的流程图(红色箭头)。P0口用作I/O口线,其由引脚向内部数据总线输入(即输入状态Input)的工作过程:数据输入时(读P0口)有两种情况 1、读引脚读芯片引脚上的数据,读引脚数时,读引脚缓冲器打开(即三态缓冲器的控制端要有效),通过内部数据总线输入,请看下图(红色箭头)。 2、读锁存器通过打开读锁存器三态缓冲器读取锁存器输出端Q的状态,请看下图(红色箭头): 在输入状态下,从锁存器和从引脚上读来的信号一般是一致的,但也有例外。例如,当从内部总线输出低电平后,锁存器Q=0,Q非=1,场效应管T2开通,端口线呈低电平状态。此时无论端口线上外接的信号是低电乎还是高电平,从引脚读入单片机的信号都是低电平,因而不能正确地读入端口引脚上的信号。又如,当从内部总线输出高电平后,锁存器Q=1,Q非=0,场效应管T2截止。如外接引脚信号为低电平,从引脚上读入的信号就与从锁存器读入的信号不同。为此,8031单片机在对端口P0一P3的输入操作上,有如下约定:为此,8051单片机在对端口P0一P3的输入操作上,有如下约定:凡属于读-修改-写方式的指令,从锁存器读入信号,其它指令则从端口引脚线上读入信号。读-修改-写指令的特点是,从端口输入(读)信号,在单片机内加以运算(修改)后,再输出(写)到该端口上。下面是几条读–修改-写指令的例子。 这样安排的原因在于读-修改-写指令需要得到端口原输出的状态,修改后再输出,读锁存器而不是读引脚,可以避免因外部电路的原因而使原端口的状态被读错。P0端口是8031单片机的总线口,分时出现数据D7一D0、低8位地址A7一AO,以及三态,用来接口存储器、外部电路与外部设备。P0端口是使用最广泛的I/O端口。 2、作为地址/数据复用口使用时的工作原理在访问外部存储器时P0口作为地址/数据复用口使用。 这时多路开关‘控制’信号为‘1’,‘与门’解锁,‘与门’输出信号电平由“地址/数据”线信号决定;多路开关与反相器的输出端相连,地址信号经“地址/数据”线→反相器→V2场效应管栅极→V2漏极输出。例如:控制信号为1,地址信号为“0”时,与门输出低电平,V1管截止;反相器输出高电平,V2管导通,输出引脚的地址信号为低电平。请看下图(蓝色字体为电平):反之,控制信号为“1”、地址信号为“1”,“与门”输出为高电平,V1管导通;反相器输出低电平,V2管截止,输出引脚的地址信号为高电平。请看下图(蓝色字体为电平):可见,在输出“地址/数据”信息时,V1、V2管是交替导通的,负载能力很强,可以直接与外设存储器相连,无须增加总线驱动器。P0口又作为数据总线使用。在访问外部程序存储器时,P0口输出低8位地址信息后,将变为数据总线,以便读指令码(输入)。在取指令期间,“控制”信号为“0”,V1管截止,多路开关也跟着转向锁存器反相输出端Q非;CPU自动将0FFH(11111111,即向D锁存器写入一个高电平‘1’)写入P0口锁存器,使V2管截止,在读引脚信号控制下,通过读引脚三态门电路将指令码读到内部总线。请看下图如果该指令是输出数据,如MOVX @DPTR,A(将累加器的内容通过P0口数据总线传送到外部RAM中),则多路开关“控制”信号为‘1’,“与门”解锁,与输出地址信号的工作流程类似,数据据由“地址/数据”线→反相器→V2场效应管栅极→V2漏极输出。如果该指令是输入数据(读外部数据存储器或程序存储器),如MOVX A,@DPTR(将外部RAM某一存储单元内容通过P0口数据总线输入到累加器A中),则输入的数据仍通过读引脚三态缓冲器到内部总线,其过程类似于上图中的读取指令码流程图。通过以上的分析可以看出,当P0作为地址/数据总线使用时,在读指令码或输入数据前,CPU自动向P0口锁存器写入0FFH,破坏了P0口原来的状态。因此,不能再作为通用的I/O端口。大家以后在系统设计时务必注意,即程序中不能再含有以P0口作为操作数(包含源操作数和目的操作数)的指令。 2、P1端口的结构及工作原理P1口的结构最简单,用途也单一,仅作为数据输入/输出端口使用。输出的信息有锁存,输入有读引脚和读锁存器之分。P1端口的一位结构见下图.由图可见,P1端口与P0端口的主要差别在于,P1端口用内部上拉电阻R代替了P0端口的场效应管T1,并且输出的信息仅来自内部总线。由内部总线输出的数据经锁存器反相和场效应管反相后,锁存在端口线上,所以,P1端口是具有输出锁存的静态口。由上图可见,要正确地从引脚上读入外部信息,必须先使场效应管关断,以便由外部输入的信息确定引脚的状态。为此,在作引脚读入前,必须先对该端口写入l。具有这种操作特点的输入/输出端口,称为准双向I/O口。8051单片机的P1、P2、P3都是准双向口。P0端口由于输出有三态功能,输入前,端口线已处于高阻态,无需先写入l后再作读操作。P1口的结构相对简单,前面我们已详细的分析了P0口,只要大家认真的分析了P0口的工作原理,P1口我想大家都有能力去分析,这里我就不多论述了。单片机复位后,各个端口已自动地被写入了1,此时,可直接作输入操作。如果在应用端口的过程中,已向P1一P3端口线输出过0,则再要输入时,必须先写1后再读引脚,才能得到正确的信息。此外,随输入指令的不同,H端口也有读锁存器与读引脚之分。 3、P2端口的结构及工作原理:P2端口的一位结构见下图: 由图可见,P2端口在片内既有上拉电阻,又有切换开关MUX,所以P2端口在功能上兼有P0端口和P1端口的特点。这主要表现在输出功能上,当切换开关向下接通时,从内部总线输出的一位数据经反相器和场效应管反相后,输出在端口引脚线上;当多路开关向上时,输出的一位地址信号也经反相器和场效应管反相后,输出在端口引脚线上。对于8031单片机必须外接程序存储器才能构成应用电路(或者我们的应用电路扩展了外部存储器),而P2端口就是用来周期性地输出从外存中取指令的地址(高8位地址),因此,P2端口的多路开关总是在进行切换,分时地输出从内部总线来的数据和从地址信号线上来的地址。因此P2端口是动态的I/O端口。输出数据虽被锁存,但不是稳定地出现在端口线上。其实,这里输出的数据往往也是一种地址,只不过是外部RAM的高8位地址。在输入功能方面,P2端口与P0和H端口相同,有读引脚和读锁存器之分,并且P2端口也是准双向口。可见,P2端口的主要特点包括:①不能输出静态的数据;②自身输出外部程序存储器的高8位地址;②执行MOVX指令时,还输出外部RAM的高位地址,故称P2端口为动态地址端口。即然P2口可以作为I/O口使用,也可以作为地址总线使用,下面我们就不分析下它的两种工作状态。1、作为I/O端口使用时的工作过程当没有外部程序存储器或虽然有外部数据存储器,但容易不大于256B,即不需要高8位地址时(在这种情况下,不能通过数据地址寄存器DPTR读写外部数据存储器),P2口可以I/O口使用。这时,“控制”信号为“0”,多路开关转向锁存器同相输出端Q,输出信号经内部总线→锁存器同相输出端Q→反相器→V2管栅极→V2管9漏极输出。由于V2漏极带有上拉电阻,可以提供一定的上拉电流,负载能力约为8个TTL与非门;作为输出口前,同样需要向锁存器写入“1”,使反相器输出低电平,V2管截止,即引脚悬空时为高电平,防止引脚被钳位在低电平。读引脚有效后,输入信息经读引脚三态门电路到内部数据总线。2、作为地址总线使用时的工作过程P2口作为地址总线时,“控制”信号为‘1’,多路开关车向地址线(即向上接通),地址信息经反相器→V2管栅极→漏极输出。由于P2口输出高8位地址,与P0口不同,无须分时使用,因此P2口上的地址信息(程序存储器上的A15~A8)功数据地址寄存器高8位DPH保存时间长,无须锁存。 4、P3端口的结构及工作原理P3口是一个多功能口,它除了可以作为I/O口外,还具有第二功能,P3端口的一位结构见下图。 由上图可见,P3端口和Pl端口的结构相似,区别仅在于P3端口的各端口线有两种功能选择。当处于第一功能时,第二输出功能线为1,此时,内部总线信号经锁存器和场效应管输入/输出,其作用与P1端口作用相同,也是静态准双向I/O端口。当处于第二功能时,锁存器输出1,通过第二输出功能线输出特定的内含信号,在输入方面,即可以通过缓冲器读入引脚信号,还可以通过替代输入功能读入片内的特定第二功能信号。由于输出信号锁存并且有双重功能,故P3端口为静态双功能端口。P3口的特殊功能(即第二功能): 使P3端品各线处于第二功能的条件是: 1、串行I/O处于运行状态(RXD,TXD);2、打开了处部中断(INT0,INT1);3、定时器/计数器处于外部计数状态(T0,T1)4、执行读写外部RAM的指令(RD,WR)在应用中,如不设定P3端口各位的第二功能(WR,RD信叼的产生不用设置),则P3端口线自动处于第一功能状态,也就是静态I/O端口的工作状态。在更多的场合是根据应用的需要,把几条端口线设置为第二功能,而另外几条端口线处于第一功能运行状态。在这种情况下,不宜对P3端口作字节操作,需采用位操作的形式。端口的负载能力和输入/输出操作:P0端口能驱动8个LSTTL负载。如需增加负载能力,可在P0总线上增加总线驱动器。P1,P2,P3端口各能驱动4个LSTTL负载。前已述及,由于P0-P3端口已映射成特殊功能寄存器中的P0一P3端口寄存器,所以对这些端口寄存器的读/写就实现了信息从相应端口的输入/输出。例如:MOV A, P1 ;把Pl端口线上的信息输入到AMoV P1, A ;把A的内容由P1端口输出MOV P3, #0FFH ;使P3端口线各位置1 剩下的P4口做第二功能主要是扩展外部数据存储器用的,P5口第二功能是:复位脉冲输入端、主时钟输入、SPI接口的从机选择信号。]]></content>
<categories>
<category>单片机</category>
</categories>
<tags>
<tag>51单片机</tag>
<tag>IO口</tag>
</tags>
</entry>
<entry>
<title><![CDATA[Markdown简明语法教程]]></title>
<url>%2F2019%2F01%2F26%2FMarkdown%E7%AE%80%E6%98%8E%E8%AF%AD%E6%B3%95%E6%95%99%E7%A8%8B%2F</url>
<content type="text"><![CDATA[1. 斜体和粗体使用 * 和 ** 表示斜体和粗体。 示例: 这是 斜体,这是 粗体。 2. 分级标题使用 === 表示一级标题,使用 — 表示二级标题。 示例: 1234567这是一个一级标题============================这是一个二级标题--------------------------------------------------### 这是一个三级标题 你也可以选择在行首加井号表示不同级别的标题 (H1-H6),例如:# H1, ## H2, ### H3,#### H4。 3. 外链接使用 [描述](链接地址) 为文字增加外链接。 示例: 这是去往 本人博客 的链接。 4. 无序列表使用 *,+,- 表示无序列表。 示例: 无序列表项 一 无序列表项 二 无序列表项 三 5. 有序列表使用数字和点表示有序列表。 示例: 有序列表项 一 有序列表项 二 有序列表项 三 6. 文字引用使用 > 表示文字引用。 示例: 野火烧不尽,春风吹又生。 7. 行内代码块使用 `代码` 表示行内代码块。 示例: 让我们聊聊 html。 8. 代码块使用 四个缩进空格 表示代码块。 示例: 这是一个代码块,此行左侧有四个不可见的空格。 9. 插入图像使用 ![描述](图片链接地址) 插入图像。 示例: Cmd Markdown 高阶语法手册1. 内容目录在段落中填写 [TOC] 以显示全文内容的目录结构。 [TOC] 2. 标签分类在编辑区任意行的列首位置输入以下代码给文稿标签: 标签: 数学 英语 Markdown 或者 Tags: 数学 英语 Markdown 3. 删除线使用 ~~ 表示删除线。 这是一段错误的文本。 4. 注脚使用 [^keyword] 表示注脚。 这是一个注脚[^footnote]的样例。 这是第二个注脚[^footnote2]的样例。 5. LaTeX 公式$ 表示行内公式: 质能守恒方程可以用一个很简洁的方程式 $E=mc^2$ 来表达。 $$ 表示整行公式: $$\sum_{i=1}^n a_i=0$$ $$f(x_1,x_x,\ldots,x_n) = x_1^2 + x_2^2 + \cdots + x_n^2 $$ $$\sum^{j-1}{k=0}{\widehat{\gamma}{kj} z_k}$$ 访问 MathJax 参考更多使用方法。 6. 加强的代码块支持四十一种编程语言的语法高亮的显示,行号显示。 非代码示例: 1$ sudo apt-get install vim-gnome Python 示例: 123456789101112@requires_authorizationdef somefunc(param1='', param2=0): '''A docstring''' if param1 > param2: # interesting print 'Greater' return (param2 - param1 + 1) or Noneclass SomeClass: pass>>> message = '''interpreter... prompt''' JavaScript 示例: 1234567891011121314151617/*** nth element in the fibonacci series.* @param n >= 0* @return the nth element, >= 0.*/function fib(n) { var a = 1, b = 1; var tmp; while (--n >= 0) { tmp = a; a += b; b = tmp; } return a;}document.write(fib(10)); 7. 流程图示例12345678910st=>start: Start:>https://www.zybuluo.comio=>inputoutput: verificationop=>operation: Your Operationcond=>condition: Yes or No?sub=>subroutine: Your Subroutinee=>endst->io->op->condcond(yes)->econd(no)->sub->io 更多语法参考:流程图语法参考8. 序列图示例 1123Alice->Bob: Hello Bob, how are you?Note right of Bob: Bob thinksBob-->Alice: I am good thanks! 示例 212345Title: Here is a titleA->B: Normal lineB-->C: Dashed lineC->>D: Open arrowD-->>A: Dashed open arrow 更多语法参考:序列图语法参考9. 甘特图甘特图内在思想简单。基本是一条线条图,横轴表示时间,纵轴表示活动(项目),线条表示在整个期间上计划和实际的活动完成情况。它直观地表明任务计划在什么时候进行,及实际进展与计划要求的对比。 12345678910111213title 项目开发流程section 项目确定 需求分析 :a1, 2016-06-22, 3d 可行性报告 :after a1, 5d 概念验证 : 5dsection 项目实施 概要设计 :2016-07-05 , 5d 详细设计 :2016-07-08, 10d 编码 :2016-07-15, 10d 测试 :2016-07-22, 5dsection 发布验收 发布: 2d 验收: 3d 更多语法参考:甘特图语法参考10. Mermaid 流程图1234A[Hard edge] -->|Link text| B(Round edge)B --> C{Decision}C -->|One| D[Result one]C -->|Two| E[Result two] 更多语法参考:Mermaid 流程图语法参考11. Mermaid 序列图1234Alice->John: Hello John, how are you?loop every minute John-->Alice: Great!end 更多语法参考:Mermaid 序列图语法参考12. 表格支持 项目 价格 数量 计算机 \$1600 5 手机 \$12 12 管线 \$1 234 13. 定义型列表名词 1: 定义 1(左侧有一个可见的冒号和四个不可见的空格) 代码块 2: 这是代码块的定义(左侧有一个可见的冒号和四个不可见的空格) 代码块(左侧有八个不可见的空格) 14. Html 标签本站支持在 Markdown 语法中嵌套 Html 标签,譬如,你可以用 Html 写一个纵跨两行的表格: <table> <tr> <th rowspan="2">值班人员</th> <th>星期一</th> <th>星期二</th> <th>星期三</th> </tr> <tr> <td>李强</td> <td>张明</td> <td>王平</td> </tr> </table> 值班人员 星期一 星期二 星期三 李强 张明 王平 15. 内嵌图标本站的图标系统对外开放,在文档中输入 <i class="icon-weibo"></i> 即显示微博的图标: 替换 上述 i 标签 内的 icon-weibo 以显示不同的图标,例如: <i class="icon-renren"></i> 即显示人人的图标: 更多的图标和玩法可以参看 font-awesome 官方网站。 16. 待办事宜 Todo 列表使用带有 [ ] 或 [x] (未完成或已完成)项的列表语法撰写一个待办事宜列表,并且支持子列表嵌套以及混用Markdown语法,例如: - [ ] **Cmd Markdown 开发** - [ ] 改进 Cmd 渲染算法,使用局部渲染技术提高渲染效率 - [ ] 支持以 PDF 格式导出文稿 - [x] 新增Todo列表功能 [语法参考](https://github.com/blog/1375-task-lists-in-gfm-issues-pulls-comments) - [x] 改进 LaTex 功能 - [x] 修复 LaTex 公式渲染问题 - [x] 新增 LaTex 公式编号功能 [语法参考](http://docs.mathjax.org/en/latest/tex.html#tex-eq-numbers) - [ ] **七月旅行准备** - [ ] 准备邮轮上需要携带的物品 - [ ] 浏览日本免税店的物品 - [x] 购买蓝宝石公主号七月一日的船票 对应显示如下待办事宜 Todo 列表: Cmd Markdown 开发 改进 Cmd 渲染算法,使用局部渲染技术提高渲染效率 支持以 PDF 格式导出文稿 新增Todo列表功能 语法参考 改进 LaTex 功能 修复 LaTex 公式渲染问题 新增 LaTex 公式编号功能 语法参考 七月旅行准备 准备邮轮上需要携带的物品 浏览日本免税店的物品 购买蓝宝石公主号七月一日的船票 [^footnote]: 这是一个 注脚 的 文本。 [^footnote2]: 这是另一个 注脚 的 文本。]]></content>
<categories>
<category>编程语言</category>
</categories>
<tags>
<tag>Markdown</tag>
</tags>
</entry>
<entry>
<title><![CDATA[Matlab简介]]></title>
<url>%2F2019%2F01%2F26%2FMatlab%2F</url>
<content type="text"><![CDATA[MATLAB被广泛用来作为计算工具在科学和工程涵盖领域物理,化学,数学和工程流。它在一定范围内的应用,包括: 信号处理和通信 图像和视频处理 控制系统 测试和测量 计算金融 计算生物学 系统预定义变量 eps 计算机的最小整数,在PC上,它等于2^-52 inf或Inf,表示无穷大 NaN表示Not a number 不定量 flops 浮点运算次数,用于统计算量 函数Matlab提供的通用数理类函数包括: 基本数学函数 特殊函数 特殊矩阵函数 矩阵分解和分析函数 数据分析函数 微分方程求解 多项式函数 非线性方程及其优化函数 数值积分函数 信号处理函数 log()函数在Matlab当中是指以e为底的对数即ln。 帮助指令 help,他的工作机理是把指定名字的那个M文件的第一段注释内容显示出来,已构成自己文件的在线求索 lookfor,指令可以根据用户提供的完整或不完整的关键词,去搜索出一组有关的指令。 exit,检查指定名字的变量或函数文件的存在性 what,按扩展名分类列出(在搜索路径中)指定目录上的文件名 which列出制定名字文件所在的目录 矩阵运算和数组运算矩阵运算是按矩阵运算法则进行的运算;数组运算无论是何种运算操作都是元素逐个进行。 什么是残差?残差在数理统计中是指实际观察值与估计值(拟合值)之间的差。“残差”蕴含了有关模型基本假设的重要信息。如果回归模型正确的话, 我们可以将残差看作误差的观测值。它应符合模型的假设条件,且具有误差的一些性质。利用残差所提供的信息,来考察模型假设的合理性及数据的可靠性称为残差分析。 高斯消去法高斯消去法的基本思想是对线性方程组的增广矩阵进行行初等变换,使增广矩阵中的 系数矩阵 变为上三角矩阵,从而解除最后一个未知数Xn的值,然后再依次带回,求出其余的未知数的值。 线性方程组什么时候无解?多个解?唯一解?奇异矩阵?矩阵的秩? M文件M文件有两类,命令文件和函数文件。两者的区别在于:命令文件没有输入参数,也不返回输出参数;而函数文件可以输入参数,也可以返回输出参数。命令文件对MATLAB工作空间中的变量进行操作,而函数文件中定义的变量为局部变量,当函数执行完毕时这些不变量被清除出。]]></content>
<categories>
<category>编程语言</category>
</categories>
<tags>
<tag>Matlab</tag>
<tag>线性代数</tag>
<tag>数学建模</tag>
</tags>
</entry>
<entry>
<title><![CDATA[Hello World]]></title>
<url>%2F2019%2F01%2F23%2Fhello-world%2F</url>
<content type="text"><![CDATA[Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub. Quick StartCreate a new post1$ hexo new "My New Post" More info: Writing Run server1$ hexo server More info: Server Generate static files1$ hexo generate More info: Generating Deploy to remote sites1$ hexo deploy More info: Deployment]]></content>
</entry>
</search>