AT89S52单片机精简开发板资料
- 格式:pdf
- 大小:1.88 MB
- 文档页数:22
电子报/2009年/2月/15日/第015版智能电子AT89S51/52单片机简易编程器湖北田家淑闲瑕之余,笔者选用带ISP功能的AT89S51/52系列单片机,很轻易地完成了系统开发。
所谓ISP,即In System Preogrammerable在线系统可编程。
也就是说,单片机可在系统应用板上进行编程,然后立即运行。
利用ISP在线编程的电路见附图。
整个电路可用万用板搭建,利用PC机的串口进行数据通讯,单片机编程脚为⑥~⑨脚。
由于AT89S51/52⑨脚是复位端,所以按图示接法,此板只能作为编程板用。
若要使此板能运行,则⑨脚需加上“编程”和“运行”切换开关。
在“运行”状态下,⑨脚需接常规RC复位电路。
“编程”时,⑨脚改接到+5V供电端,将电压提升至编程所需的高电平。
此编程器若需稳定工作,可在MAX232和AT89S51之间加74HC244作驱动缓冲。
但大多数情况下,附图所示电路均可满足要求。
软件名称为“电子在线ISP编程器V2.0",网上随处可下载,采用WINDOWS操作界面,使用方便。
具体使用方法如下:先打开软件界面,然后打开编程器,在保证串口线(用平行线,不可用交叉线)连接可靠的情况下,点击软件中的“ID鉴别”,对话框中将出现芯片型号:AT89S51或AT89S52,点击“擦除”,右下方将有进度条一闪而过,出现对话:擦除完毕。
此时,再点击“ID鉴别”,若出现提示“线路不通或无法识别的芯片”,则应重新开启编程器一次,再点击"ID鉴别”。
在成功显示型号之后,点击“文件”下拉菜单至“加载Hex文件”,在电脑中选择十六进制的预先编译好的文件,双击该文件名,则此文件名将出现在对话框中,表示已被选中。
最后点击“写入”,写入操作即可很快完成。
一个“跑马灯”程序只需0.8s左右即可写入完毕,很方便。
切记:每次进行芯片操作时,如写入、擦除和校验,都必须进行“ID鉴别”,以检查稳定性。
说明:1.单片机可做成系统完整板,设计成切换编程/运行。
AT89S52单片机485通讯开发板使用手册【简要说明】一、尺寸:长72mmX宽72mmX高12mm二、主要芯片:AT89S52,MAX485三、工作电压:6V至40V,功耗小于1W四、特点:1、具有稳压电路,输入电压广,具有电源指示灯。
2、具有485通信。
3、单片机标准十针下载接口。
(可使用并口下载线和USB下载线下载)4、支持波特率 2400 4800 9600 192005、采用的按键,机械寿命长。
6、单片机编程,客户可以自己更改,提供参考程序7、所以I/O口以引出。
8、具有系统复位按键9、P2口四位按键输入10、P1口四位信号灯指示11、通过编程可以实现与485设备之间直接通信12、板子静态功耗小于1W13、具有续流保护14、具有电磁抗干扰能力15、板子稳定工作可靠16、板子可安装在DIN导轨上面17、标准的11.0592M晶振(晶振在单片机下面)。
18、端子采用螺旋压接端子19、工作温度-40度至 +70度20、工作湿度 40% ~ 80%RH使用说明:【标注说明】【功能描述】【原理图】【PCB图】【元件清单】【应用举例】【源代码程序】/********************************************************************汇诚科技实现功能:此版配套测试程序使用芯片:AT89S52晶振:11.0592MHZ波特率:9600编译环境:Keil作者:zhangxinchunleo【声明】此程序仅用于学习与参考,引用请注明版权和作者信息!/********************************************************************程序说明:1、所有IO口流水灯3次。
2、所有IO口闪烁输出5次。
3、按下P2.0按键点亮P1.0灯,按下P2.1按键点亮P1.1灯,按下P2.2按键点亮P1.2灯,按下P2.3按键点亮P1.3灯,4、接收串口发送的数据再返回原值。
AT89S52单片机开发板实验手册概述:AT89S52多功能单片机开发板特点:1. 板载资源丰富,常见的控制对象基本已经包括.2. 采用在系统方式(ISP)编程,通过下载电路下载程序,不用烧录器即可下载程序,调试方便.3. 可由直流稳压电源或通过USB数据线供电.按键保持的电源开关,连接线路时只用按一下即可断开电源.扩展了若干个电源接口,板上电源可以外接给其他电路板使用.4. 所有板上资源均用排针引出,可方便用ARM,DSP或其他控制器控制.5. 红外发射/接收 ,PS/2接口接入键盘,时钟芯片,数字温度计测温等模块的程序编成了子函数,已经模块化,工程应用需要时可以直接调用.6. 配套光盘提供程序,常用软件(编译软件,烧录软件,字模提取,串口上位机软件,C语言所有库函数等),视频教程(主要为计算机屏幕操作的录像),开发板用户手册,原理图,器件 Datasheet等.配套提供的所有程序均可直接运行,注释已经尽量详细,能满足从单片机 入门到进阶的需要.7. 基于以上各模块,提供了综合应用的实例,即:可通过PC机键盘或通过红外发射进行控制的电子万年历等.(具体见实验介绍).本开发板含有如下功能模块:01. 流水灯 (控制8个超亮LED闪烁)02. 方波,PWM信号输出03. 按键中断04. 四位数码管动态显示05. 计数脉冲信号并显示06. 报警与音乐演奏07. 4×4键盘扩展08. 看门狗+上电自动复位+手动复位+电源监控09. 128*64点阵式液晶显示 (可显示画面和文字等)10. RS232串行通讯 (单片机通过串口与PC机进行通讯,板上数码管和上位机软件均可显示通讯的数据,提供上位机软件)11. 红外信号发射与接收 (单片机控制红外二极管发射红外信号并接收信号,也可以通过遥控器发射,单片机控制接收信号并处理)12. 温度测量13. I2C接口的E2PROM (AT24C08,8K容量,可用于断电时存储数据等场合,单片机软件模拟I2C总线协议与之通讯)14. 时钟芯片 (扩展时钟芯片以获取年/月/日,当前时间,星期等信息)15. PS2接口 (可外接PC机的键盘做系统的输入)16. 可通过键盘/红外遥控控制的电子万年历 (液晶屏显示年/月/日,当前时间,星期,闹铃定闹的时间,倒计时状态等;可以修改闹铃时间和倒计时的起始时间;可显示环境温度;可通过PS/2接口接入键盘或通过红外发射来校正时间,开/关闹铃等.)实验注意事项:1. 板上扩展有两个电源接口(接线柱),正负极已经标出,外接时极性不能接反.2. 通电时,最好不要用手拿着电路板,防止短路;接线时最好断开电源(开关为J1).3. 调试出现故障注意查看复位电路是否接入(最好直接接上上电自动复位电路(即J14中将上电自动复位端和复位端用短路冒短接,接好后还可以通过S17手动复位),看门狗复位可以在后面再接入).4. 下载程序时单片机P1.5,P1.6,P1.7三个脚禁止接到功能模块,否则会影响程序下载.程序比较大时,5K,6K或以上的代码时,下载可能比较慢,如果下载失败,一般重试一次即可成功下载.5. 由于并口的影响,断开电源时可能发光LED也有微弱发光,为正常现象.6. 程序以光盘中程序目录下的为准.7. 数码管和液晶不能同时接入系统,否则任一部分都不能正常使用.编程软件和烧录软件等的使用见视频教程.如有疑问可到论坛发帖.实验目录(Ⅰ)基本实验1. 流水灯-------------------------------------------------------------------------------------------42. 方波-PWM信号输出 --------------------------------------------------------------------------63. 按键中断----------------------------------------------------------------------------------------84. 四位数码管动态显示-------------------------------------------------------------------------105. 计数脉冲信号并显示-------------------------------------------------------------------------126. 报警与音乐演奏-------------------------------------------------------------------------------137. 4×4键盘扩展----------------------------------------------------------------------------------138. 看门狗+上电自动复位+手动复位+电源监控----------------------------------------------149. 128*64点阵式液晶显示 ------------------------------------------------------------------1410. RS232串行通讯------------------------------------------------------------------------------1511. 红外信号发射与接收-------------------------------------------------------------------------1612. 温度测量---------------------------------------------------------------------------------------2313. I2C接口的E2PROM--------------------------------------------------------------------------2314. 时钟芯片---------------------------------------------------------------------------------------2415. PS2接口---------------------------------------------------------------------------------------24(Ⅱ)综合实验16. 可调式电子万年历-------------------------------------------------------25 综合应用的实例会不断添加,敬请关注我们的网站.(Ⅰ)基本实验1.流水灯实验内容:利用单片机I/O口输出高低变化的电平,控制流水灯按程序设置的功能闪烁.接线说明J7接入单片机P0口.注意:单片机端口有两种操作方式,一种是写端口,如 P0=0xff; 另一种是读端口,如if(P0==0xff) ,即读I/O口P0的状态,值为0xff 时满足条件.程序清单:/***************************************************************函数功能: 控制8个流水灯闪烁接线说明: 流水灯接线柱接到P0口学习内容: 单片机IO口(输入/输出)的应用整理时间: 2006-10 ****************************************************************/#include<reg52.h>delay(int k); //延时函数预定义main(){int i;int data1=0x7f;int data2=0xfe;while(1){int abb=0xfe; //变量abb赋初值for(i=0;i<8;i++){P0=abb;delay(1000); //延时1秒abb=abb<<1; //8个灯依次点亮}P0=0xff; //8个灯均灭delay(1000);abb=0x7f;for(i=0;i<8;i++){P0=abb;delay(1000);abb=abb>>1; //8个灯换个方向依次点亮}P0=0xff; //8个灯均灭delay(1000);P0=0x00; //8个灯均灭delay(1000);P0=0xff; //8个灯均灭delay(1000);}}delay(int k) //延时函数,大致延时K毫秒{int d,n;for(d=0;d<k;d++){for(n=0;n<125;n++){;} //由经验值,12M晶振时大概的延时时间(延时1ms) }}2.方波输出<1>. 利用板上NE555组成振荡器产生方波.占空比及周期可以通过相关电阻,电容的数值计算得出.(线路已经接好,上电后L2即开始闪烁)<2>. 通过单片机定时器产生方波通过设定定时器的定时值,计数值满时溢出产生中断,在中断服务程序中使相应管脚输出电平反相,从而产生方波信号.接线说明:单片机P1.2接到流水灯上(J7)的任意一个程序清单:/*********************************************************************** 函数功能: 利用内部定时器输出方波控制流水灯接线说明: P1.2接到流水灯上(J7)的任意一个学习内容: 单片机内部定时器/计数器的应用编程思想: 单片机内部定时器最大定时值不超过一秒, 可以用累加的方式增加定时时间整理时间: 2006-10 ***********************************************************************/ #include <reg52.h>int time=0;sbit P1_2=P1^2; //定义控制脚void timeout1() interrupt 1 using 2 //定时器0的中断服务程序{if(++time==100) //延时100*10ms(即1秒)时输出反向{P1_2=~P1_2;time=0;}TH0=(65536-10000)/256; //重装数据,延时10msTL0=(65536-10000)%256;TR0=1;}main(){TMOD=TMOD&0xf0|0x01; //定时器0工作在方式1EA=1;ET0=1;TH0=(65536-10000)/256; //延时10msTL0=(65536-10000)%256;TR0=1;while(1){;}}<3>.单片机输出PWM波形输出PWM信号的原理与产生方波大致一样.设定一个数组,存入不同的延时值,定时器装入初值,溢出后产生中断,在中断服务取出数组中的定时值赋给定时器的数据寄存器 , 从而产生PWM波形.高低电平的维持时间有数组的值决定.接线说明:单片机I/O口P1.0接到流水灯上的任意一个.程序清单:/*******************************************************************函数功能: 利用内部定时器输出PWM信号控制流水灯接线说明: P1.0接到流水灯上的任意一个学习内容: 单片机内部定时器/计数器的应用编程思想: 输出低电平1000微秒,高电平15000微秒(12M的晶振时),可应用于电力电子技术中升压斩波电路等做IGBT的触发信号等.整理时间: 2006-10 *******************************************************************/#include <reg52.h>sbit P1_0=P1^0; //定义变量P1_0代表I/O口P1口的0脚bit i=0;int tab[2]={1000,15000};void timeserver() interrupt 3 using 3 //定时器1中断服务程序{P1_0=~P1_0; //输出取反i=~i;TH1=(65536-tab[i])/256;TL1=(65536-tab[i])%256;TR1=1;}main(){P1_0=0;TMOD=TMOD&0x0f|0x10; //不改变定时器0的工作状态,定时器1工作于方式1 TH1=(65536-tab[i])/256; //定时器存入初值TL1=(65536-tab[i])%256;EA=1; //CPU开中断TR1=1; //定时器1开始工作while(1){;} //等待定时器中断}3.按键中断通过设定单片机中断的形式,如下降沿产生中断或低电平产生中断.按键输入低电平到相应中断输入管脚,单片机识别出中断信号,如果CPU和相应外部中断使能有效(即EA---CPU中断使能位,EX0,EX1---外部中断使能位),则进入中断服务程序.接线说明:中断按键的线路已经连接好,不用另外接线. 数码管用跳线冒接入(即AA连接到P0.0,BB 连接到P0.1依次接入,CON1…CON4分别接到P2.7……P2.4)程序清单:/****************************************************************函数功能: 利用内部中断控制数码管显示接线说明: 数码管用跳线冒接入学习内容: 单片机中断(外部)的应用编程思想: 单片机识别出中断0或中断1就转向中断服务程序整理时间: 2006-10 *****************************************************************/#include <reg52.h>bit flag1=0,flag2=0;void service_int1() interrupt 0 //外部中断0的中断服务程序,0为中断源序号,2为//使用的寄存器(可更改){flag1=1; //允许数码管显示数据}void service_int2() interrupt 2 //外部中断1的中断服务程序{flag2=1; //允许数码管显示数据}void delay() //延时程序{int j;for(j=32400;j>0;j--){;}}void main(){EX0=1; //开外部中断EX1=1;EA=1; //开CPU中断P0=0x00;P2=0xff;IP=0x04; //设置中断优先级,外部中断0的级别设为最高,外部中断1和其他中断同级//不设优先级则按单片机硬件决定while(1){P0=0x00;P2=0xff;if(flag1==1){P0=0xd5; //显示 3P2=0x00;flag1=0;delay();}if(flag2==1){P0=0xdb; //显示 6P2=0x00;flag2=0; //清除显示使能delay();}}}4. 四位数码管动态显示数码管每个显示数字共用数据线(8根线),每个分别有一个使能管脚,显示数据采用隐消的编程方法,即每一位显示一段时间再轮换.接线说明:数码管用跳线冒接入(即AA连接到P0.0,BB连接到P0.1依次接入,CON1…CON4分别接到P2.7……P2.4).数码管何液晶不能同时接入系统,否则任一部分都不能正常使用.程序清单:/************************************************************************* 函数功能: 数码管数值动态显示接线说明: 用跳线冒接入数码管学习内容: 常用的输出显示器件的编程应用编程思想: 用隐消的方法实现数码管的动态显示,显示部分整理成库文件,方便以后直接应用整理时间: 2006-10 *************************************************************************/ #include <reg52.h>#include <LED8888.h> //调用封装好的显示库函数main(){int j,k;k=1286; //显示值,实现数值累加显示while(1){for(j=1;j<70;j++){Led(k); //数码显示}k+=1;}}以下为 LED8888.hchar shuju[10]={0x5f,0x44,0x9d,0xd5,0xc6,0xd3,0xdb,0x45,0xdf,0xd7}; //数码管显示数字0-9void led8888_Delay(int j) //延时函数{int m;for(m=0;m<j;m++){i;intfor(i=0; i<300; i++){;} //约1ms}}void Led(int k){if(k>999){P2=P2&0x7f; //P2.7输出低电平,选通千位数P0=shuju[k/1000]; //取千位数led8888_Delay(2); //延时P2=P2|0xff; //销隐}if(k>99){P2=P2&0xbf; //P2.6输出低电平,选通百位数P0=shuju[k%1000/100]+0x20; //取出百位数,点亮数码管百位后的那一点led8888_Delay(2); //延时P2=P2|0xff; //销隐}if(k>9){P2=P2&0xdf; //P2.5输出低电平,选通十位数P0=shuju[k%100/10]; //取十位数led8888_Delay(2); //延时P2=P2|0xff; //销隐}if(k>=0){P2=P2&0xef;P0=shuju[k%10]; //取出个位数led8888_Delay(2);P2=P2|0xff;}}5. 计数脉冲信号并显示利用单片机计数器功能,计数外部输入的脉冲信号,计算得出频率值.接线说明:FIN接入单片机I/O口P3.5.数码管接入程序清单:/********************************************************************** 函数功能: 计数外部(555电路)的脉冲接线说明: FIN接入单片机I/O口P3.5.学习内容: 单片机内部定时器/计数器的应用整理时间: 2006-10 **********************************************************************/ #include <reg52.h>#include <LED8888.h>int count=0; //显示值赋初值main(){TMOD=0x55; //计数器1工作在方式1TL1=(65536-5)%256; //设置初值,计数4次后产生定时/计数器中断TH1=(65536-5)/256;TR1=1; //启动计数器EA=1; //开CPU中断,不开中断也行,没有用到计数器中断 ET1=1;while(1){count=TL1; //显示当前计数值Led(count);}}6. 报警与音乐演奏通过单片机内部定时器,输出频率改变的信号给讯响器电路,并改变节拍即可产生音乐.程序参见光盘部分.接线说明:NC接到单片机I/O口P1.27. 4×4键盘扩展原理:采用矩阵扫描的形式, 识别按键,然后转入相应处理,程序参见光盘部分.接线说明:接线柱J16接到单片机P1口.(J16的第一个脚对应接P1.0),数码管接入.8. 看门狗+上电自动复位电路+手动复位电路+电源监控外部看门狗: 采用MAX813L,程序跑飞时可以强制复位,相当于一个定时器,有一个设定的计数值,计数没有溢出之前将其计数值清零,然后重新计数,这个过程即:”喂狗”,如果在计数溢出之前没有清零,则计数器溢出,从而产生强制复位信号.工业控制干扰大的场合必用看门狗电路防止出现意外事故.附带功能:电源检测功能,当电源电压低于门限值时相关引脚电平跳变,可以输入到单片机中断口,使单片机保存数据等. 程序参见光盘部分.接线说明:NF接到P3.2,NG接到P1.4,J14中将看门狗输出与复位脚用短路冒短接起来。
- 64 -基于AT89S52的单片机开发板设计周丽荣(吉林航空工程学校,吉林 吉林 132102)摘 要:单片机技术自发展以来已广泛应用于各个领域中,需求量巨大,产生了单片机开发板。
本设计就是一种基于AT89S52单片机、实验程序源代码采用C 语言编程方式、配套有电路原理图、液晶显示等功能的通用开发板。
因为本设计中所有单片机输入、输出端口开放,能够满足在校学生学习单片机开发、爱好者进行单片机设计等功能。
关键词:单片机AT89S52;开发板;液晶显示中图分类号:TP36 文献标识码:A 文章编号:1000-8136(2011)33-0064-021 引言单片机技术自发展以来已走过20多年的发展历程,单片机技术的发展得力于微处理器技术以及超大规模集成电路技术的发展,且在广泛的应用领域拉动下,以性能价格比高、使用广泛等表现,较微处理器更具有代表性。
小到电子玩具,大到工业控制、军事设施、航空航天技术等行业都有单片机应用的影子。
针对51单片机技术在电子行业自动化方面的重要应用,为了满足广大学生、爱好者、产品开发者迅速学会掌握单片机这门技术,提出了设计单片机开发板的思想。
本文在概述开发板设计系统的基础上,首先介绍开发软件的使用方法,然后引入各个模块的作用、给出各个模块的电路原理图,并且提出该模块在系统中完成什么功能,最后将对单片机开发流程进行分析。
2 设计要求设计一个单片机开发板,能够实现典型的功能,如蜂鸣器、跑马灯、数码管显示等功能,也要实现一些常用的功能,如液晶显示、外围电路扩展等功能。
这些功能能够满足基本的学习、开发和设计的需求。
3 单片机开发板系统介绍3.1 单片机开发板的系统框图根据设计的基本要 求,综合各方面的因素,采用AT89S52单片机作 为主控器,外围电路由 典型的蜂鸣器、跑马灯、4位数码管显示、液晶显示、矩阵键盘输入等模块组成,为了提高验证程序效率,设计了ISP 接口,直接烧录芯片即可。
AT89S52简介AT89S52是一个8位单片机,片内ROM全部采用FLASH ROM技术,与MCS-51系列完全兼容,它能以3V的超低电压工作,晶振时钟最高可达24MHz。
AT89S52是标准的40引脚双列直插式集成电路芯片,有4个八位的并行双向I/O端口,分别记作P0、P1、P2、P3。
第31引脚需要接高电位使单片机选用内部程序存储器;第9引脚是复位引脚,要接一个上电手动复位电路;第40脚为电源端VCC,接+5V电源,第20引脚为接地端VSS,通常在VCC和VSS引脚之间接0.1μF高频滤波电容。
第18、19脚之间接上一个12MHz的晶振为单片机提供时钟信号。
AT89S52单片机说明如下:此芯片是一种高性能低功耗的采用CMOS工艺制造的8位微控制器,它提供下列标准特征:8K字节的程序存储器,256字节的RAM,32条I/O线,2个16位定时器/计数器, 一个5中断源两个优先级的中断结构,一个双工的串行口, 片上震荡器和时钟电路。
引脚说明::电源电压·VCC·GND:地·P0口:P0口是一组8位漏极开路型双向I/O口,作为输出口用时,每个引脚能驱动8个TTL逻辑门电路。
当对0端口写入1时,可以作为高阻抗输入端使用。
当P0口访问外部程序存储器或数据存储器时,它还可设定成地址数据总线复用的形式。
在这种模式下,P0口具有内部上拉电阻。
在EPROM编程时,P0口接收指令字节,同时输出指令字节在程序校验时。
程序校验时需要外接上拉电阻。
·P1口:P1口是一带有内部上拉电阻的8位双向I/O口。
P1口的输出缓冲能接受或输出4个TTL逻辑门电路。
当对P1口写1时,它们被内部的上拉电阻拉升为高电平,此时可以作为输入端使用。
当作为输入端使用时,P1口因为内)。
部存在上拉电阻,所以当外部被拉低时会输出一个低电流(IIL·P2口:P2是一带有内部上拉电阻的8位双向的I/O端口。
AT89S52单片机开发板设计报告摘要本设计以AT89S52单片机为中心控制器,由51最小系统及复位电路、电源和USB下载模块、发光二极管模块、蜂鸣器电路、数码管显示模块、矩阵键盘模块、点阵显示电路、继电器电路、温度传感器DS18B20模块、串口通信接口电路、电机驱动电路、时钟芯片DS1302模块、存储器AT24C02、AD转化模块、DA转化模块、旋转拨码开关、1602和12864液晶接口、电路外部RAM 62256模块组成。
各模块介绍一、 AT89S522单片机及晶振电路和复位电路如下图1-1、1-2、1-3所示,为单片机最小系统及其晶振电路和复位电路图。
图1-1 AT89S52单片机引脚图AT89S52单片机是ATMEL公司生产的一款低功耗、高性能的CMOS 8位微控制器,具有8K在系统可编程Flash存储器,使用该公司高密度非易失性存储器技术制造,与MCS-51单片机兼容(引脚和指令完全兼容)。
AT89S52具有以下标准功能: 8k字节Flash,256字节RAM,32 位I/O 口线,看门狗定时器,2 个数据指针,三个16 位定时器/计数器,一个6向量2级中断结构,全双工串行口,片内晶振及时钟电路。
另外,AT89S52 可降至0Hz 静态逻辑操作,支持2种软件可选择节电模式。
空闲模式下,CPU停止工作,允许RAM、定时器/计数器、串口、中断继续工作。
掉电保护方式下,RAM内容被保存,振荡器被冻结,单片机一切工作停止,直到下一个中断或硬件复位为止。
主要性能:(1)与MCS-51单片机产品兼容(2)8K字节在线系统可编程Flash存储器(3)1000次擦写周期(4)4.0V-5.5V工作电压(5)全静态操作:0Hz~33Hz(6)三级加密程序存储器(7)256*8字节的内部数据存储器(8)32个可编程I/O口线(9)三个16位定时器/计数器(10)八个中断源(11)全双工UART串行通道(12)低功耗空闲和掉电模式(13)掉电后中断可唤醒(14)看门狗定时器(15) 双数据指针(16) 掉电标识符(17) 快速编程周期(18) 灵活ISP编程(字节和模式)(19) 绿色(-免费)工作包操作详细引脚功能描述:P0 口:P0口是一个8位漏极开路的双向I/O口。
单片机AT89S52中文资料AT89S521主要性能l 与MCS-51单片机产品兼容l 8K字节在系统可编程Flash存储器l 1000次擦写周期l 全静态操作:0Hz~33MHzl 三级加密程序存储器l 32个可编程I/O口线l 三个16位定时器/计数器l 八个中断源l 全双工UART串行通道l 低功耗空闲和掉电模式l 掉电后中断可唤醒l 看门狗定时器l 双数据指针l 掉电标识符功能特性描述AT89S52是一种低功耗、高性能CMOS8位微控制器,具有8K 在系统可编程Flash 存储器。
使用Atmel 公司高密度非易失性存储器技术制造,与工业80C51 产品指令和引脚完全兼容。
片上Flash允许程序存储器在系统可编程,亦适于常规编程器。
在单芯片上,拥有灵巧的8 位CPU 和在系统可编程Flash,使得A T89S52为众多嵌入式控制应用系统提供高灵活、超有效的解决方案。
AT89S52具有以下标准功能:8k字节Flash,256字节RAM,32 位I/O 口线,看门狗定时器,2 个数据指针,三个16 位定时器/计数器,一个6向量2级中断结构,全双工串行口,片内晶振及时钟电路。
另外,A T89S52 可降至0Hz 静态逻辑操作,支持2种软件可选择节电模式。
空闲模式下,CPU停止工作,允许RAM、定时器/计数器、串口、中断继续工作。
掉电保护方式下,RAM内容被保存,振荡器被冻结,单片机一切工作停止,直到下一个中断或硬件复位为止。
R8 位微控制器8K 字节在系统可编程FlashAT89S52Rev. 1919-07/01AT89S522引脚结构AT89S523方框图引脚功能描述AT89S524VCC : 电源GND: 地P0 口:P0口是一个8位漏极开路的双向I/O口。
作为输出口,每位能驱动8个TTL逻辑电平。
对P0端口写“1”时,引脚用作高阻抗输入。
当访问外部程序和数据存储器时,P0口也被作为低8位地址/数据复用。
AT89S52单片机介绍AT89S52 具有以下标准功能:8k 字节 Flash,256 字节 RAM,32 位 I/O 口线,看门狗定时器,2 个数据指针,三个 16 位定时器/计数器,一个 6 向量 2 级中断结构,全双工串行口,片内晶振及时钟电路。
另外,AT89S52 可降至 0Hz 静态逻辑操作,支持 2 种软件可选择节电模式。
空闲模式下,CPU停止工作,允许 RAM、定时器/计数器、串口、中断继续工作。
掉电保护方式下,RAM 内容被保存,振荡器被冻结,单片机一切工作停止,直到下一个中断或硬件复位为止。
图 1.1 单片机引脚图VCC : 电源 GND: 地P0 口:P0 口是一个 8 位漏极开路的双向 I/O 口。
作为输出口,每位能驱动 8 个 TTL 逻辑电平。
对 P0 端口写“1”时,引脚用作高阻抗输入。
当访问外部程序和数据存储器时,P0 口也被作为低 8 位地址/数据复用。
在这种模式下,P0 具有内部上拉电阻。
在 flash 编程时,P0 口也用来接收指令字节;在程序校验时,输出指令字节。
程序校时,需要外部上拉电阻。
P1 口:P1 口是一个具有内部上拉电阻的 8 位双向 I/O 口,p1 输出缓冲器能驱动 4 个TTL 逻辑电平。
对 P1 端口写“1”时,内部上拉电阻把端口拉高,此时可以作为输入口使用。
作为输入使用时,被外部拉低的引脚由于内部电阻的原因,将输出电流(IIL)。
此外,P1.0 和 P1.2 分别作定时器/计数器 2 的外部计数输入(P1.0/T2)和时器/计数器 2的触发输入(P1.1/T2EX),具体如下表所示。
表1.1 AT89S52 P1口第二功能表P2 口:P2 口是一个具有内部上拉电阻的 8 位双向 I/O 口,P2 输出缓冲器能驱动 4 个TTL 逻辑电平。
对 P2 端口写“1”时,内部上拉电阻把端口拉高,此时可以作为输入口使用。
作为输入使用时,被外部拉低的引脚由于内部电阻的原因,将输出电流(IIL)在访问外部程序存储器或用 16 位地址读取外部数据存储器(例如执行 MOVX @DPTR)时,P2 口送出高八位地址P3 口:P3 口是一个具有内部上拉电阻的 8 位双向 I/O 口,p2 输出缓冲器能驱动 4 个TTL 逻辑电平。
AT89S52单片机简介AT89S52为ATMEL所生产的一种低功耗、高性能CMOS8位微控制器,具有8K在系统可编程Flsah存储器。
(一)、AT89S52主要功能列举如下:1、拥有灵巧的8位CPU和在系统可编程Flash2、晶片内部具时钟振荡器(传统最高工作频率可至12MHz)3、内部程序存储器(ROM)为8KB4、内部数据存储器(RAM)为256字节5、32个可编程I/O口线6、8个中断向量源7、三个16位定时器/计数器8、三级加密程序存储器9、全双工UART串行通道(二)、AT89S52各引脚功能介绍:VCC:AT89S52电源正端输入,接+5V。
VSS:电源地端。
XTAL1:单芯片系统时钟的反相放大器输入端。
XTAL2:系统时钟的反相放大器输出端,一般在设计上只要在XTAL1和XTAL2上接上一只石英振荡晶体系统就可以动作了,此外可以在两引脚与地之间加入一20PF的小电容,可以使系统更稳定,避免噪声干扰而死机。
RESET:AT89S52的重置引脚,高电平动作,当要对晶片重置时,只要对此引脚电平提升至高电平并保持两个机器周期以上的时间,AT89S51便能完成系统重置的各项动作,使得内部特殊功能寄存器之内容均被设成已知状态,并且至地址0000H处开始读入程序代码而执行程序。
EA/Vpp:"EA"为英文"ExternalAccess"的缩写,表示存取外部程序代码之意,低电平动作,也就是说当此引脚接低电平后,系统会取用外部的程序代码(存于外部EPROM中)来执行程序。
因此在8031及8032中,EA引脚必须接低电平,因为其内部无程序存储器空间。
如果是使用8751内部程序空间时,此引脚要接成高电平。
此外,在将程序代码烧录至8751内部EPROM时,可以利用此引脚来输入21V的烧录高压(Vpp)。
ALE/PROG:ALE是英文"AddressLatchEnable"的缩写,表示地址锁存器启用信号。
AT89S52单片机资料和最小系统AT89S52单片机的最小系统AT89S52单片机的引脚(P1口)P1.0—P1.7: 准双向I/O口(内置了上拉电阻)输出时一切照常,在作输入口用时要先对其写“1”。
P1.0—P1.7: 准双向I/O口(内置了上拉电阻)输出时一切照常,仅在作输入口用时要先对其写“1”。
P1.0—P1.7: 准双向I/O口(内置了上拉电阻)输出时一切照常,仅在作输入口用时要先对其写“1”。
在读数据之前,先要向相应的锁存器做写1操作的I/O口称为准双向口;P0.0—P0.7: 双向I/O (内置场效应管上拉)寻址外部程序存储器时分时作为双向8位数据口和输出低8位地址复用口;不接外部程序存储器时可作为8位准双向I/O口使用。
P2.0—P2.7: 双向I/O (内置了上拉电阻)寻址外部程序存储器时输出高8位地址;不接外部程序存储器时可作为8位准双向I/O口使用。
P3.0—P3.7: 双功能口(内置了上拉电阻)它具有特定的第二功能。
在不使用它的第二功能时它就是普通的通用准双向I/O口。
引脚第二功能P3.0 RxD: 串行口接收数据输入端P3.1 TxD: 串行口发送数据输出端P3.2 INT0: 外部中断0输入端P3.3 INT1: 外部中断1输入端P3.4 T0: 外部计数0脉冲输入端P3.5 T1: 外部计数1脉冲输入端P3.6 WR: 写外设控制信号输出端P3.7 RD: 读外设控制信号输出端51单片机的8个特殊引脚●Vcc, GND: 电源端●XTAL1, XTAL2: 片内振荡电路输入、输出端●RESET: 复位端正脉冲有效(宽度 10 mS)●EA/Vpp: 寻址外部ROM控制端。
低有效片内有ROM时应当接高电平。
●ALE/PROG: 地址锁存允许控制端。
●PSEN:选通外部ROM的读(OE)控制端。
低有效51单片机的4个8位的I/O口●P0.0—P0.7:8位数据口和输出低8位地址复用口(复用时是双向口;不复用时也是准双向口) ●P1.0—P1.7: 通用I/O口(准双向口)✹P2.0—P2.7: 输出高8位地址(用于寻址时是输出口;不寻址时是准双向口)✹P3.0—P3.7: 具有特定的第二功能(准双向口)注意:在不外扩ROM/RAM时,P0~P3均可作通用I/O口使用,而且都是准双向I/O口!P0口需外接上拉电阻P1—P3 可接也可不接在用作输入时都需要先置”1”矩阵键盘1. 键扫描键扫描就是要判断有无键按下,当扫描到有键按下时再进行下一步处理,否则退出键盘处理程序。
AT89S52单片机实验板使用说明书注:用户拿到开发板后先测试开发板的好坏,方法是给开发板通上电,如果数码管从0开始进行加计数那么说明开发板是好的。
如果通电后电路板没有反应,请及时联系我们。
此时用户应该将LED-J2的跳线冒去掉,因为,8个LED和数码管是共用数据线的,当然,如果不去也不影响实验效果。
实验板使用注意事项:下载线和开发板的连接要正确,并口ISP下载线采用10芯排线,其中10芯排线的红色边一端是第1个脚,对应目标电路板接口的MOSI,在使用时请注意不要接反,以免损坏下载线和电路板。
USB-ISP下载线电路板和开发板上都有ISP的标号,连接时对应连接就可以了,千万不要接反,以免损坏下载线和电路板。
1.开发板PCB顶视图和底视图2.开发板尺寸:9cm*7cm3.开发板资源:(1)AT89S52单片机,可实现ISP编程(2)4位共阳数码管(3)八只贴片LED发光二极管(4)一个串口,与电脑进行串口通信(5)所有单片机引脚引出接口,本开发板将单片机的40个引脚全部引出,包括电源和地,方便用户扩展外设。
(6) DC-5V稳压电源供电接口(7) USB供电接口(8) DC-5V稳压电源供电 USB供电选择接口(9)系统复位按键,便于调试程序(10)ISP编程接口,通过此接口可以实现ISP在系统编程,不用将芯片从开发板拿下来就可以通过下载线将程序下载到单片机内,避免了以往采用编程器编程频繁拔插单片机的麻烦和易损坏芯片的风险。
(11)电源总开关,本开发板上有一个电源总开关,通过此开关可以方便的控制开发板的电源,避免频繁繁拔电源的麻烦。
注:本电源总开关采用的是进口金属封装左右拨动式电源总开关,质量可靠,放心使用。
避免了市场上很多开发板上使用的廉价的易损坏朔料封装开关给用户带来的不必要的烦脑。
4.开发板供电方式:(1)USB供电(2)DC-5V稳压电源供电(3)USB-ISP下载线供电注:在选用USB-ISP供电时,USB-ISP下载线电路板上的JP2必须用跳线冒接上。
单片机AT89S52中文资料2007-04-05 10:37AT89S521主要性能l 与MCS-51单片机产品兼容l 8K字节在系统可编程Flash存储器l 1000次擦写周期l 全静态操作:0Hz~33MHzl 三级加密程序存储器l 32个可编程I/O口线l 三个16位定时器/计数器l 八个中断源l 全双工UART串行通道l 低功耗空闲和掉电模式l 掉电后中断可唤醒l 看门狗定时器l 双数据指针l 掉电标识符功能特性描述AT89S52是一种低功耗、高性能CMOS8位微控制器,具有8K 在系统可编程Flash 存储器。
使用Atmel 公司高密度非易失性存储器技术制造,与工业80C51 产品指令和引脚完全兼容。
片上Flash允许程序存储器在系统可编程,亦适于常规编程器。
在单芯片上,拥有灵巧的8 位CPU 和在系统可编程Flash,使得AT89S52为众多嵌入式控制应用系统提供高灵活、超有效的解决方案。
AT89S52具有以下标准功能: 8k字节Flash,256字节RAM,32 位I/O 口线,看门狗定时器,2 个数据指针,三个16 位定时器/计数器,一个6向量2级中断结构,全双工串行口,片内晶振及时钟电路。
另外,AT89S52 可降至0Hz 静态逻辑操作,支持2种软件可选择节电模式。
空闲模式下,CPU停止工作,允许RAM、定时器/计数器、串口、中断继续工作。
掉电保护方式下,RAM内容被保存,振荡器被冻结,单片机一切工作停止,直到下一个中断或硬件复位为止。
R8 位微控制器8K 字节在系统可编程FlashAT89S52Rev. 1919-07/01AT89S522引脚结构AT89S523方框图引脚功能描述AT89S524VCC : 电源GND: 地P0 口:P0口是一个8位漏极开路的双向I/O口。
作为输出口,每位能驱动8个TTL逻辑电平。
对P0端口写“1”时,引脚用作高阻抗输入。
当访问外部程序和数据存储器时,P0口也被作为低8位地址/数据复用。
AT89S52简介AT89S52是一个8位单片机,片内ROM全部采用FLASH ROM技术,与MCS-51系列完全兼容,它能以3V的超低电压工作,晶振时钟最高可达24MHz。
AT89S52是标准的40引脚双列直插式集成电路芯片,有4个八位的并行双向I/O 端口,分别记作P0、P1、P2、P3。
第31引脚需要接高电位使单片机选用内部程序存储器;第9引脚是复位引脚,要接一个上电手动复位电路;第40脚为电源端VCC,接+5V电源,第20引脚为接地端VSS,通常在VCC和VSS引脚之间接0.1μF高频滤波电容。
第18、19脚之间接上一个12MHz的晶振为单片机提供时钟信号。
AT89S52单片机说明如下:此芯片是一种高性能低功耗的采用CMOS工艺制造的8位微控制器,它提供下列标准特征:8K字节的程序存储器,256字节的RAM,32条I/O线,2个16位定时器/计数器, 一个5中断源两个优先级的中断结构,一个双工的串行口, 片上震荡器和时钟电路。
引脚说明:·V CC:电源电压·GND:地·P0口:P0口是一组8位漏极开路型双向I/O口,作为输出口用时,每个引脚能驱动8个TTL逻辑门电路。
当对0端口写入1时,可以作为高阻抗输入端使用。
当P0口访问外部程序存储器或数据存储器时,它还可设定成地址数据总线复用的形式。
在这种模式下,P0口具有内部上拉电阻。
在EPROM编程时,P0口接收指令字节,同时输出指令字节在程序校验时。
程序校验时需要外接上拉电阻。
·P1口:P1口是一带有内部上拉电阻的8位双向I/O口。
P1口的输出缓冲能接受或输出4个TTL逻辑门电路。
当对P1口写1时,它们被内部的上拉电阻拉升为高电平,此时可以作为输入端使用。
当作为输入端使用时,P1口因为内部存在上拉电阻,所以当外部被拉低时会输出一个低电流(I IL)。
·P2口:P2是一带有内部上拉电阻的8位双向的I/O端口。
t a o c h i p .c nFeatures•Compatible with MCS ®-51 Products•8K Bytes of In-System Programmable (ISP) Flash Memory –Endurance: 1000 Write/Erase Cycles • 4.0V to 5.5V Operating Range•Fully Static Operation: 0 Hz to 33 MHz •Three-level Program Memory Lock •256 x 8-bit Internal RAM •32 Programmable I/O Lines •Three 16-bit Timer/Counters •Eight Interrupt Sources•Full Duplex UART Serial Channel•Low-power Idle and Power-down Modes •Interrupt Recovery from Power-down Mode •Watchdog Timer •Dual Data Pointer •Power-off Flag•Fast Programming Time•Flexible ISP Programming (Byte and Page Mode)•Green (Pb/Halide-free) Packaging Option1.DescriptionThe AT89S52 is a low-power, high-performance CMOS 8-bit microcontroller with 8K bytes of in-system programmable Flash memory. The device is manufactured using Atmel’s high-density nonvolatile memory technology and is compatible with the indus-try-standard 80C51 instruction set and pinout. The on-chip Flash allows the program memory to be reprogrammed in-system or by a conventional nonvolatile memory pro-grammer. By combining a versatile 8-bit CPU with in-system programmable Flash on a monolithic chip, the Atmel AT89S52 is a powerful microcontroller which provides a highly-flexible and cost-effective solution to many embedded control applications.The AT89S52 provides the following standard features: 8K bytes of Flash, 256 bytes of RAM, 32 I/O lines, Watchdog timer, two data pointers, three 16-bit timer/counters, a six-vector two-level interrupt architecture, a full duplex serial port, on-chip oscillator, and clock circuitry. In addition, the AT89S52 is designed with static logic for operation down to zero frequency and supports two software selectable power saving modes. The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port, and interrupt system to continue functioning. The Power-down mode saves the RAM con-tents but freezes the oscillator, disabling all other chip functions until the next interrupt or hardware reset.t a o c h i p .c n21919C–MICRO–3/05AT89S522.Pin Configurations2.140-lead PDIP2.244-lead TQFP2.344-lead PLCC2.442-lead PDIPt a o c h i p .c n31919C–MICRO–3/05AT89S523.Block Diagramt a o c h i p .c n41919C–MICRO–3/05AT89S524.Pin Description4.1VCCSupply voltage.4.2GNDGround.4.3Port 0Port 0 is an 8-bit open drain bidirectional I/O port. As an output port, each pin can sink eight TTL inputs. When 1s are written to port 0 pins, the pins can be used as high-impedance inputs. Port 0 can also be configured to be the multiplexed low-order address/data bus during accesses to external program and data memory. In this mode, P0 has internal pull-ups.Port 0 also receives the code bytes during Flash programming and outputs the code bytes dur-ing program verification. External pull-ups are required during program verification .4.4Port 1Port 1 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 1 output buffers can sink/source four TTL inputs. When 1s are written to Port 1 pins, they are pulled high by the inter-nal pull-ups and can be used as inputs. As inputs, Port 1 pins that are externally being pulled low will source current (I IL ) because of the internal pull-ups.In addition, P1.0 and P1.1 can be configured to be the timer/counter 2 external count input (P1.0/T2) and the timer/counter 2 trigger input (P1.1/T2EX), respectively, as shown in the follow-ing table.Port 1 also receives the low-order address bytes during Flash programming and verification.4.5Port 2Port 2 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 2 output buffers can sink/source four TTL inputs. When 1s are written to Port 2 pins, they are pulled high by the inter-nal pull-ups and can be used as inputs. As inputs, Port 2 pins that are externally being pulled low will source current (I IL ) because of the internal pull-ups.Port 2 emits the high-order address byte during fetches from external program memory and dur-ing accesses to external data memory that use 16-bit addresses (MOVX @ DPTR). In this application, Port 2 uses strong internal pull-ups when emitting 1s. During accesses to external data memory that use 8-bit addresses (MOVX @ RI), Port 2 emits the contents of the P2 Special Function Register.Port 2 also receives the high-order address bits and some control signals during Flash program-ming and verification.Port Pin Alternate FunctionsP1.0T2 (external count input to Timer/Counter 2), clock-outP1.1T2EX (Timer/Counter 2 capture/reload trigger and direction control)P1.5MOSI (used for In-System Programming)P1.6MISO (used for In-System Programming)P1.7SCK (used for In-System Programming)t a o c h i p .c n51919C–MICRO–3/05AT89S524.6Port 3Port 3 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 3 output buffers can sink/source four TTL inputs. When 1s are written to Port 3 pins, they are pulled high by the inter-nal pull-ups and can be used as inputs. As inputs, Port 3 pins that are externally being pulled low will source current (I IL ) because of the pull-ups.Port 3 receives some control signals for Flash programming and verification.Port 3 also serves the functions of various special features of the AT89S52, as shown in the fol-lowing table.4.7RSTReset input. A high on this pin for two machine cycles while the oscillator is running resets the device. This pin drives high for 98 oscillator periods after the Watchdog times out. The DISRTO bit in SFR AUXR (address 8EH) can be used to disable this feature. In the default state of bit DISRTO, the RESET HIGH out feature is enabled.4.8ALE/PROGAddress Latch Enable (ALE) is an output pulse for latching the low byte of the address during programming.In normal operation, ALE is emitted at a constant rate of 1/6 the oscillator frequency and may be used for external timing or clocking purposes. Note, however, that one ALE pulse is skipped dur-ing each access to external data memory.If desired, ALE operation can be disabled by setting bit 0 of SFR location 8EH. With the bit set, ALE is active only during a MOVX or MOVC instruction. Otherwise, the pin is weakly pulled high. Setting the ALE-disable bit has no effect if the microcontroller is in external execution mode.Port Pin Alternate Functions P3.0RXD (serial input port)P3.1TXD (serial output port)P3.2INT0 (external interrupt 0)P3.3INT1 (external interrupt 1)P3.4T0 (timer 0 external input)P3.5T1 (timer 1 external input)P3.6WR (external data memory write strobe)P3.7RD (external data memory read strobe)t a o c h i p .c n61919C–MICRO–3/05AT89S524.9PSENWhen the AT89S52 is executing code from external program memory, PSEN is activated twice nal data memory.4.10code from external program memory locations starting at 0000H up to FFFFH. Note, however, EA should be strapped to V CC for internal program executions.This pin also receives the 12-volt programming enable voltage (V PP ) during Flash programming.4.11XTAL1Input to the inverting oscillator amplifier and input to the internal clock operating circuit.4.12XTAL2Output from the inverting oscillator amplifier.5.Special Function RegistersA map of the on-chip memory area called the Special Function Register (SFR) space is shown in Table 5-1.Note that not all of the addresses are occupied, and unoccupied addresses may not be imple-mented on the chip. Read accesses to these addresses will in general return random data, and write accesses will have an indeterminate effect.User software should not write 1s to these unlisted locations, since they may be used in future products to invoke new features. In that case, the reset or inactive values of the new bits will always be 0.Timer 2 Registers: Control and status bits are contained in registers T2CON (shown in Table 5-2) and T2MOD (shown in Table 10-2) for Timer 2. The register pair (RCAP2H, RCAP2L) are the Capture/Reload registers for Timer 2 in 16-bit capture mode or 16-bit auto-reload mode.Interrupt Registers: The individual interrupt enable bits are in the IE register. Two priorities can be set for each of the six interrupt sources in the IP register.t a o c h i p .c n71919C–MICRO–3/05AT89S52Table 5-1.AT89S52 SFR Map and Reset Values0F8H 0FFH 0F0H B 000000000F7H 0E8H 0EFH 0E0H ACC 000000000E7H 0D8H 0DFH 0D0H PSW 000000000D7H 0C8H T2CON 00000000T2MOD XXXXXX00RCAP2L 00000000RCAP2H 00000000TL200000000TH2000000000CFH 0C0H 0C7H 0B8H IP XX0000000BFH 0B0H P3111111110B7H 0A8H IE 0X0000000AFH 0A0H P211111111AUXR1XXXXXXX0WDTRST XXXXXXXX0A7H 98H SCON 00000000SBUF XXXXXXXX9FH 90H P11111111197H 88H TCON 00000000TMOD 00000000TL000000000TL100000000TH000000000TH100000000AUXR XXX00XX08FH 80HP011111111SP 00000111DP0L 00000000DP0H 00000000DP1L 00000000DP1H 00000000PCON 0XXX000087Ht a o c h i p .c n81919C–MICRO–3/05AT89S52Table 5-2.T2CON – Timer/Counter 2 Control RegisterT2CON Address = 0C8H Reset Value = 0000 0000BBit Addressable BitTF2EXF2RCLK TCLK EXEN2TR2C/T2CP/RL27654321Symbol FunctionTF2Timer 2 overflow flag set by a Timer 2 overflow and must be cleared by software. TF2 will not be set when either RCLK = 1or TCLK = 1.EXF2Timer 2 external flag set when either a capture or reload is caused by a negative transition on T2EX and EXEN2 = 1. When Timer 2 interrupt is enabled, EXF2 = 1 will cause the CPU to vector to the Timer 2 interrupt routine. EXF2 must be cleared by software. EXF2 does not cause an interrupt in up/down counter mode (DCEN = 1).RCLK Receive clock enable. When set, causes the serial port to use Timer 2 overflow pulses for its receive clock in serial port Modes 1 and 3. RCLK = 0 causes Timer 1 overflow to be used for the receive clock.TCLK Transmit clock enable. When set, causes the serial port to use Timer 2 overflow pulses for its transmit clock in serial port Modes 1 and 3. TCLK = 0 causes Timer 1 overflows to be used for the transmit clock.EXEN2Timer 2 external enable. When set, allows a capture or reload to occur as a result of a negative transition on T2EX if Timer 2 is not being used to clock the serial port. EXEN2 = 0 causes Timer 2 to ignore events at T2EX.TR2Start/Stop control for Timer 2. TR2 = 1 starts the timer.C/T2Timer or counter select for Timer 2. C/T2 = 0 for timer function. C/T2 = 1 for external event counter (falling edge triggered).CP/RL2Capture/Reload select. CP/RL2 = 1 causes captures to occur on negative transitions at T2EX if EXEN2 = 1. CP/RL2 = 0 causes automatic reloads to occur when Timer 2 overflows or negative transitions occur at T2EX when EXEN2 = 1. When either RCLK or TCLK = 1, this bit is ignored and the timer is forced to auto-reload on Timer 2 overflow.t ao c h i .c n91919C–MICRO–3/05AT89S52Dual Data Pointer Registers: To facilitate accessing both internal and external data memory, two banks of 16-bit DataPointer Registers are provided: DP0 at SFR address locations 82H-83H and DP1 at 84H-85H. Bit DPS = 0 in SFR AUXR1 selects DP0 and DPS = 1 selects DP1. The user should ALWAYS initialize the DPS bit to the appropriate value before accessing the respective Data Pointer Register.Power Off Flag: The Power Off Flag (POF) is located at bit 4 (PCON.4) in the PCON SFR. POF is set to “1” during power up. It can be set and rest under software control and is not affected by reset.Table 5-3.AUXR: Auxiliary RegisterAUXRAddress = 8EH Reset Value = XXX00XX0BNot Bit Addressable –––W D I D LE D ISRTO––D ISALEBit7654321–Reserved for future expansion DISALEDisable/Enable ALE DISALE Operating Mode0ALE is emitted at a constant rate of 1/6 the oscillator frequency 1ALE is active only during a MOVX or MOVC instructionDISRTO Disable/Enable Reset out DISRTO 0Reset pin is driven High after WDT times out 1Reset pin is input onlyWDIDLE Disable/Enable WDT in IDLE mode WDIDLE 0WDT continues to count in IDLE mode 1WDT halts counting in IDLE modeTable 5-4.AUXR1: Auxiliary Register 1AUXR1Address = A2H Reset Value = XXXXXXX0BNot Bit Addressable–––––––D PSBit7654321–Reserved for future expansion DPSData Pointer Register Select DPS 0Selects DPTR Registers DP0L, DP0H 1Selects DPTR Registers DP1L, DP1Ht a o c h i p .c n101919C–MICRO–3/05AT89S526.Memory OrganizationMCS-51 devices have a separate address space for Program and Data Memory. Up to 64K bytes each of external Program and Data Memory can be addressed.6.1Program MemoryIf the EA pin is connected to GND, all program fetches are directed to external , program fetches to addresses 0000H through 1FFFH are directed to internal memory and fetches to addresses 2000H through FFFFH are to external memory.6.2Data MemoryThe AT89S52 implements 256 bytes of on-chip RAM. The upper 128 bytes occupy a parallel address space to the Special Function Registers. This means that the upper 128 bytes have the same addresses as the SFR space but are physically separate from SFR space.When an instruction accesses an internal location above address 7FH, the address mode used in the instruction specifies whether the CPU accesses the upper 128 bytes of RAM or the SFR space. Instructions which use direct addressing access the SFR space.For example, the following direct addressing instruction accesses the SFR at location 0A0H (which is P2).MOV 0A0H, #dataInstructions that use indirect addressing access the upper 128 bytes of RAM. For example, the following indirect addressing instruction, where R0 contains 0A0H, accesses the data byte at address 0A0H, rather than P2 (whose address is 0A0H).MOV @R0, #dataNote that stack operations are examples of indirect addressing, so the upper 128 bytes of data RAM are available as stack space.7.Watchdog Timer (One-time Enabled with Reset-out)The WDT is intended as a recovery method in situations where the CPU may be subjected to software upsets. The WDT consists of a 14-bit counter and the Watchdog Timer Reset (WDTRST) SFR. The WDT is defaulted to disable from exiting reset. To enable the WDT, a user must write 01EH and 0E1H in sequence to the WDTRST register (SFR location 0A6H). When the WDT is enabled, it will increment every machine cycle while the oscillator is running. The WDT timeout period is dependent on the external clock frequency. There is no way to disable the WDT except through reset (either hardware reset or WDT overflow reset). When WDT over-flows, it will drive an output RESET HIGH pulse at the RST pin.7.1Using the WDTTo enable the WDT, a user must write 01EH and 0E1H in sequence to the WDTRST register (SFR location 0A6H). When the WDT is enabled, the user needs to service it by writing 01EH and 0E1H to WDTRST to avoid a WDT overflow. The 14-bit counter overflows when it reaches 16383 (3FFFH), and this will reset the device. When the WDT is enabled, it will increment every machine cycle while the oscillator is running. This means the user must reset the WDT at least every 16383 machine cycles. To reset the WDT the user must write 01EH and 0E1H to WDTRST. WDTRST is a write-only register. The WDT counter cannot be read or written. WhenAT89S52 WDT overflows, it will generate an output RESET pulse at the RST pin. The RESET pulse dura-tion is 98xTOSC, where TOSC = 1/FOSC. To make the best use of the WDT, it should beserviced in those sections of code that will periodically be executed within the time required toprevent a WDT reset.7.2WDT During Power-down and IdleIn Power-down mode the oscillator stops, which means the WDT also stops. While in Power-down mode, the user does not need to service the WDT. There are two methods of exitingPower-down mode: by a hardware reset or via a level-activated external interrupt which isenabled prior to entering Power-down mode. When Power-down is exited with hardware reset,servicing the WDT should occur as it normally does whenever the AT89S52 is reset. ExitingPower-down with an interrupt is significantly different. The interrupt is held low long enough forthe oscillator to stabilize. When the interrupt is brought high, the interrupt is serviced. To preventthe WDT from resetting the device while the interrupt pin is held low, the WDT is not started untilthe interrupt is pulled high. It is suggested that the WDT be reset during the interrupt service forthe interrupt used to exit Power-down mode.To ensure that the WDT does not overflow within a few states of exiting Power-down, it is best toreset the WDT just before entering Power-down mode.Before going into the IDLE mode, the WDIDLE bit in SFR AUXR is used to determine whetherthe WDT continues to count if enabled. The WDT keeps counting during IDLE (WDIDLE bit = 0)as the default state. To prevent the WDT from resetting the AT89S52 while in IDLE mode, theuser should always set up a timer that will periodically exit IDLE, service the WDT, and reenterIDLE mode.With WDIDLE bit enabled, the WDT will stop to count in IDLE mode and resumes the countupon exit from IDLE.8.UARTThe UART in the AT89S52 operates the same way as the UART in the AT89C51 and AT89C52.For further information on the UART operation, please click on the document link below:/dyn/resources/prod_documents/DOC4316.PDF9.Timer 0 and 1Timer 0 and Timer 1 in the AT89S52 operate the same way as Timer 0 and Timer 1 in theAT89C51 and AT89C52. For further information on the timers’ operation, please click on thedocument link below:/dyn/resources/prod_documents/DOC4316.PDFt a o c h i p.c n10.Timer 2Timer 2 is a 16-bit Timer/Counter that can operate as either a timer or an event counter. TheTable 5-2). Timer 2 has three operating modes: capture, auto-reload (up or down counting), and baud rate generator.The modes are selected by bits in T2CON, as shown in Table 10-1. Timer 2 consists of two 8-bitregisters, TH2 and TL2. In the Timer function, the TL2 register is incremented every machinecycle. Since a machine cycle consists of 12 oscillator periods, the count rate is 1/12 of the oscil-lator frequency.Table 10-1.Timer 2 Operating ModesRCLK +TCLK CP/RL2TR2MODE00116-bit Auto-reload01116-bit Capture1X1Baud Rate GeneratorX X0(Off)In the Counter function, the register is incremented in response to a 1-to-0 transition at its corre-sponding external input pin, T2. In this function, the external input is sampled during S5P2 ofevery machine cycle. When the samples show a high in one cycle and a low in the next cycle,the count is incremented. The new count value appears in the register during S3P1 of the cyclefollowing the one in which the transition was detected. Since two machine cycles (24 oscillatorperiods) are required to recognize a 1-to-0 transition, the maximum count rate is 1/24 of theoscillator frequency. To ensure that a given level is sampled at least once before it changes, thelevel should be held for at least one full machine cycle.10.1Capture ModeIn the capture mode, two options are selected by bit EXEN2 in T2CON. If EXEN2 = 0, Timer 2 isa 16-bit timer or counter which upon overflow sets bit TF2 in T2CON. This bit can then be usedto generate an interrupt. If EXEN2 = 1, Timer 2 performs the same operation, but a 1-to-0 transi-tion at external input T2EX also causes the current value in TH2 and TL2 to be captured intoRCAP2H and RCAP2L, respectively. In addition, the transition at T2EX causes bit EXF2 inT2CON to be set. The EXF2 bit, like TF2, can generate an interrupt. The capture mode is illus-trated in Figure 10-1.10.2Auto-reload (Up or Down Counter)Timer 2 can be programmed to count up or down when configured in its 16-bit auto-reloadmode. This feature is invoked by the DCEN (Down Counter Enable) bit located in the SFRT2MOD (see Table 10-2). Upon reset, the DCEN bit is set to 0 so that timer 2 will default tocount up. When DCEN is set, Timer 2 can count up or down, depending on the value of theT2EX pin.t a o c h i p.c nt a o c h i p .c nAT89S52Figure 10-1.Timer in Capture ModeFigure 10-2 shows Timer 2 automatically counting up when DCEN = 0. In this mode, two optionsare selected by bit EXEN2 in T2CON. If EXEN2 = 0, Timer 2 counts up to 0FFFFH and then sets the TF2 bit upon overflow. The overflow also causes the timer registers to be reloaded with the 16-bit value in RCAP2H and RCAP2L. The values in Timer in Capture ModeRCAP2H and RCAP2L are preset by software. If EXEN2 = 1, a 16-bit reload can be triggered either by an overflow or by a 1-to-0 transition at external input T2EX. This transition also sets the EXF2 bit. Both the TF2 and EXF2 bits can generate an interrupt if enabled.Setting the DCEN bit enables Timer 2 to count up or down, as shown in Figure 10-2. In this mode, the T2EX pin controls the direction of the count. A logic 1 at T2EX makes Timer 2 count up. The timer will overflow at 0FFFFH and set the TF2 bit. This overflow also causes the 16-bit value in RCAP2H and RCAP2L to be reloaded into the timer registers, TH2 and TL2, respectively.A logic 0 at T2EX makes Timer 2 count down. The timer underflows when TH2 and TL2 equal the values stored in RCAP2H and RCAP2L. The underflow sets the TF2 bit and causes 0FFFFH to be reloaded into the timer registers.The EXF2 bit toggles whenever Timer 2 overflows or underflows and can be used as a 17th bit of resolution. In this operating mode, EXF2 does not flag an interrupt.Table 10-2.T2MOD – Timer 2 Mode Control RegisterT2MOD Address = 0C9H Reset Value = XXXX XX00BNot Bit Addressable––––––T2OE DCENBit7654321Symbol Function –Not implemented, reserved for future T2OE Timer 2 Output Enable bitDCENWhen set, this bit allows Timer 2 to be configured as an up/down counterFigure 10-2.Timer 2 Auto Reload Mode (DCEN = 0)Figure 10-3.Timer 2 Auto Reload Mode (DCEN = 1)t a o c h i p.c nt a o c h i p .c nAT89S5211.Baud Rate GeneratorTimer 2 is selected as the baud rate generator by setting TCLK and/or RCLK in T2CON (Table 5-2). Note that the baud rates for transmit and receive can be different if Timer 2 is used for the receiver or transmitter and Timer 1 is used for the other function. Setting RCLK and/or TCLK puts Timer 2 into its baud rate generator mode, as shown in Figure 11-1.The baud rate generator mode is similar to the auto-reload mode, in that a rollover in TH2 causes the Timer 2 registers to be reloaded with the 16-bit value in registers RCAP2H and RCAP2L, which are preset by software.The baud rates in Modes 1 and 3 are determined by Timer 2’s overflow rate according to the fol-lowing equation.The Timer can be configured for either timer or counter operation. In most applications, it is con-figured for timer operation (CP/T2 = 0). The timer operation is different for Timer 2 when it isused as a baud rate generator. Normally, as a timer, it increments every machine cycle (at 1/12 the oscillator frequency). As a baud rate generator, however, it increments every state time (at 1/2 the oscillator frequency). The baud rate formula is given below.where (RCAP2H, RCAP2L) is the content of RCAP2H and RCAP2L taken as a 16-bit unsignedinteger.Timer 2 as a baud rate generator is shown in Figure 11-1. This figure is valid only if RCLK or TCLK = 1 in T2CON. Note that a rollover in TH2 does not set TF2 and will not generate an inter-rupt. Note too, that if EXEN2 is set, a 1-to-0 transition in T2EX will set EXF2 but will not cause a reload from (RCAP2H, RCAP2L) to (TH2, TL2). Thus, when Timer 2 is in use as a baud rate generator, T2EX can be used as an extra external interrupt.Note that when Timer 2 is running (TR2 = 1) as a timer in the baud rate generator mode, TH2 or TL2 should not be read from or written to. Under these conditions, the Timer is incremented every state time, and the results of a read or write may not be accurate. The RCAP2 registers may be read but should not be written to, because a write might overlap a reload and cause write and/or reload errors. The timer should be turned off (clear TR2) before accessing the Timer 2 or RCAP2 registers.Modes 1 and 3 Baud Rates Timer 2 Overflow Rate 16-----------------------------------------------------------=Modes 1 and 3Baud Rate ---------------------------------------Oscillator Frequency 32 x [65536-RCAP2H,RCAP2L)]-------------------------------------------------------------------------------------=t a o c h i p .c nFigure 11-1.Timer 2 in Baud Rate Generator Mode12.Programmable Clock OutA 50% duty cycle clock can be programmed to come out on P1.0, as shown in Figure 12-1. This pin, besides being a regular I/O pin, has two alternate functions. It can be programmed to input the external clock for Timer/Counter 2 or to output a 50% duty cycle clock ranging from 61 Hz to 4 MHz (for a 16-MHz operating frequency).To configure the Timer/Counter 2 as a clock generator, bit C/T2 (T2CON.1) must be cleared and bit T2OE (T2MOD.1) must be set. Bit TR2 (T2CON.2) starts and stops the timer.The clock-out frequency depends on the oscillator frequency and the reload value of Timer 2 capture registers (RCAP2H, RCAP2L), as shown in the following equation.In the clock-out mode, Timer 2 roll-overs will not generate an interrupt. This behavior is similar towhen Timer 2 is used as a baud-rate generator. It is possible to use Timer 2 as a baud-rate gen-erator and a clock generator simultaneously. Note, however, that the baud-rate and clock-out frequencies cannot be determined independently from one another since they both use RCAP2H and RCAP2L.Clock-Out Frequency Oscillator Frequency 4 x [65536-(RCAP2H,RCAP2L)]------------------------------------------------------------------------------------=AT89S52 Figure 12-1.Timer 2 in Clock-Out Mode13.InterruptsThe AT89S52 has a total of six interrupt vectors: two external interrupts (INT0 and INT1), threetimer interrupts (Timers 0, 1, and 2), and the serial port interrupt. These interrupts are all shownin Figure 13-1.Each of these interrupt sources can be individually enabled or disabled by setting or clearing abit in Special Function Register IE. IE also contains a global disable bit, EA, which disables allinterrupts at once.Note that Table 13-1 shows that bit position IE.6 is unimplemented. User software should notwrite a 1 to this bit position, since it may be used in future AT89 products.Timer 2 interrupt is generated by the logical OR of bits TF2 and EXF2 in register T2CON. Nei-ther of these flags is cleared by hardware when the service routine is vectored to. In fact, theservice routine may have to determine whether it was TF2 or EXF2 that generated the interrupt,and that bit will have to be cleared in software.The Timer 0 and Timer 1 flags, TF0 and TF1, are set at S5P2 of the cycle in which the timersoverflow. The values are then polled by the circuitry in the next cycle. However, the Timer 2 flag,TF2, is set at S2P2 and is polled in the same cycle in which the timer overflows.t a o c h i p.c nt a o c h i p .c nFigure 13-1.Interrupt SourcesTable 13-1.Interrupt Enable (IE) Register(MSB) (LSB)EA–ET2ESET1EX1ET0EX0Enable Bit = 1 enables the interrupt. Enable Bit = 0 disables the interrupt.Symbol Position FunctionEA IE.7Disables all interrupts. If EA = 0, no interrupt is acknowledged. If EA = 1, eachinterrupt source is individually enabled or disabled by setting or clearing its enable bit.–IE.6Reserved.ET2IE.5Timer 2 interrupt enable bit.ES IE.4Serial Port interrupt enable bit.ET1IE.3Timer 1 interrupt enable bit.EX1IE.2External interrupt 1 enable bit.ET0IE.1Timer 0 interrupt enable bit.EX0IE.0External interrupt 0 enable bit.User software should never write 1s to reserved bits, because they may be used in future AT89 products.。
AT89S52 简介AT89S52是一个8位单片机,片内ROM全部采用FLASH ROM技术,与MCS-51系列完全兼容,它能以3V的超低电压工作,晶振时钟最高可达24MHz。
AT89S52是标准的40引脚双列直插式集成电路芯片,有4个八位的并行双向I/O 端口,分别记作P0、P1、P2、P3。
第31引脚需要接高电位使单片机选用内部程序存储器;第9引脚是复位引脚,要接一个上电手动复位电路;第40脚为电源端VCC,接+5V电源,第20引脚为接地端VSS,通常在VCC和VSS引脚之间接0.1卩F高频滤波电容。
第18、19脚之间接上一个12MHz的晶振为单片机提供时钟信号。
AT89S52单片机说明如下:此芯片是一种高性能低功耗的采用CMOS工艺制造的8位微控制器,它提供下列标准特征:8K字节的程序存储器,256字节的RAM,32条I/O线,2个16 位定时器/计数器,一个5中断源两个优先级的中断结构,一个双工的串行口,片上震荡器和时钟电路。
引脚说明:•V CC :电源电压•GND:地•P0 口:P0 口是一组8位漏极开路型双向I/O 口,作为输出口用时,每个引脚能驱动8个TTL逻辑门电路。
当对0端口写入1时,可以作为高阻抗输入端使用。
当P0 口访问外部程序存储器或数据存储器时,它还可设定成地址数据总线复用的形式。
在这种模式下,P0 口具有内部上拉电阻。
在EPROM编程时,P0 口接收指令字节,同时输出指令字节在程序校验时。
程序校验时需要外接上拉电阻。
•P1 口:P1 口是一带有内部上拉电阻的8位双向I/O 口。
P1 口的输出缓冲能接受或输出4个TTL逻辑门电路。
当对P1 口写1时,它们被内部的上拉电阻拉升为高电平,此时可以作为输入端使用。
当作为输入端使用时,P1 口因为内部存在上拉电阻,所以当外部被拉低时会输出一个低电流(I IL)。
•P2 口:P2是一带有内部上拉电阻的8位双向的I/O端口。
P2 口的输出缓冲能驱动4个TTL逻辑门电路。
AT89S52单片机介绍 AT89S52是一种低功耗、高性能CMOS8位微控制器,具有8K 在系统可编程Flash 存储器。
使用Atmel 公司高密度非易失性存储器技术制造,与工业80C51 产品指令和引脚完全兼容。
片上Flash允许程序存储器在系统可编程,亦适于常规编程器。
在单芯片上,拥有灵巧的8 位CPU 和在系统可编程Flash,使得AT89S52为众多嵌入式控制应用系统提供高灵活、超有效的解决方案[7]。
2.1.1 主要性能(1)与MCS-51单片机产品兼容(2)8K字节在系统可编程Flash存储器(3)1000次擦写周期(4)全静态操作:0Hz~33Hz(5)三级加密程序存储器(6)32个可编程I/O口线(7)三个16位定时器/计数器(8)八个中断源(9)全双工UART串行通道(10)低功耗空闲和掉电模式(11)掉电后中断可唤醒(12)看门狗定时器(13)双数据指针(14)掉电标识符2.1.2 引脚功能图2.1 AT89S52引脚图VCC : 电源GND : 地P0 口:P0口是一个8位漏极开路的双向I/O口。
作为输出口,每位能驱动8个TTL逻辑电平。
对P0端口写“1”时,引脚用作高阻抗输入。
当访问外部程序和数据存储器时,P0口也被作为低8位地址/数据复用。
在这种模式下,P0具有内部上拉电阻。
在flash编程时,P0口也用来接收指令字节;在程序校验时,输出指令字节。
程序校验时,需要外部上拉电阻。
P1 口:P1 口是一个具有内部上拉电阻的8 位双向I/O 口,p1 输出缓冲器能驱动4 个TTL 逻辑电平。
对P1 端口写“1”时,内部上拉电阻把端口拉高,此时可以作为输入口使用。
作为输入使用时,被外部拉低的引脚由于内部电阻的原因,将输出电流(IIL)。
此外,P1.0和P1.2分别作定时器/计数器2的外部计数输入(P1.0/T2)和时器/计数器2的触发输入(P1.1/T2EX),具体如下表所示。