C8051F021单片机实验指导
C8051F021单片机实验指导

提要:实验项目1、单片机的IO编程实验1 IO开关量输入实验实验2 IO输出驱动继电器(或光电隔离器)实验实验3 IO输入/输出------半导体温度传感器DS18B20实验2、单片机的中断系统实验1 外部外部中断----脉冲计数实验3、单片机的定时器/计数器实验1 计数器实验实验2 秒时钟发生器实验4、单片机的串口特点和编程实验1 P C机串口通讯实验实验2 R S485通讯实验5、存储器实验1 RAM存储器读写实验6、PWM发生器实验1 PWM发生器(模拟)实验实验1 PWM发生器(内部)实验7、WDG看门狗实验1 外扩WDG(MAX813)实验实验2 WDG(内部)实验8、SPI总线实验1 SPI(模拟)实验-----TLC2543 AD转换实验实验2 SPI(模拟)实验-----TLV5616 DA转换实验9、I2C总线实验1 I2C(模拟)实验-----AT24C01读写实验实验2 I2C(内部)实验-----AT24C01读写实验10、综合实验实验1 HD7279LED数码管显示实验实验2 HD7279键盘实验实验3 外部中断---电机转速显示实验11、步进电机正反转实验12、TFT液晶显示彩色条纹实验13、16X16LED点阵显示汉字实验一、单片机的IO编程实验1 IO开关量输入实验目的:学习单片机读取IO引脚状态的的方法。
内容:编程读取IO引脚状态。
设备:EL-EMCU-I试验箱、EXP-C8051F021 CPU板。
编程:首先要把相关的引脚设置在IO的输入状态,然后写一个循环,不停地检测引脚的状态。
步骤:1、将CPU板正确安放在CPU接口插座上,2、连线:用导线将试验箱上MCU部分的IO1--- IO8分别连接到SWITCH 的8个拨码开关的K1---K8的输出端子K1---K8上,连接好仿真器。
3、试验箱上电,在PC机上打开Keil C环境,打开试验程序文件夹IO_INPUT 下的工程文件IO_INPUT.Uv2编译程序,上电,在函数main()的最后一句设置断点,进入调试状态,打开窗口Peripherals-->IO-Port-->P3,改变开关状态,运行程序到断点处,观察窗口的数值与开关的对应关系。
基于C8051F021的剩余电压测量系统设计

2 硬件 电路设计和关键模块分析
种以单片机 C 0 1 01 8 5F 2 为核心控制单元 的智能
微 处 理器 选 用单片机 C 0 10 1 为控 制 85F 2 作
测量系统,实现了对用电没备剩余 电压的测量。
器, 控制电压的通断电以及信号采集 、 显示等工作。
单片机 C 010 1 8 5F 2 的主要特点是 : 内核和指令系
由单片机系统 、相位检 测电路、断电控制电路与
驱动电路、电压采集 电路、L D显示、按键输入 K i C 1 C e — 5 的编译环境,程序代码可读性和移植性 l 等几 部分组成。系统工作流程如下 : 连接测量样品, 强 。
确定接线无误后, 按下开关键 , 系统先进行初始化 , 电源指示灯亮,L D显示交流电压的实时值,操 C 作员通过调压旋钮将 电压稳定到 2 0 在测量前, 2V;
1 系统结构及功能
系统 的结 构框 图如 图 1 示 ,整 个系统 主要 所
统与 MC 一 1 Sபைடு நூலகம்5 系列单片机完全兼容 ; 指令执行速
度高达 2MIS; 5 P 全部 I 、R T T G引脚均允 / S 、JA 0 许5 V输入 ; 运行程序过程中可进行 内部、外部时 钟切换以减小单片机功耗等。软件运行环境采用
s se b r c c e t y t m y p a t a t s. il
Ke wo ds C8 5 F; R e iua Vo mg ; me s r me t y tm y r : 0 1 s l d l e au e n s s e
★基金项 目 : 中国
长基金项 目 《 电器产 品剩余 电压 检测方法的研究 》 2 1J 0 5 o ( 0 0K 1
8051单片机实验报告

8051单片机实验报告练习题一1-1修改例程一的源程序:(1)将A寄存器的初值改为80H(正逻辑,数据位为1表示发光二极管点亮),再对源程序进行简单修改,使程序运行后发光二极管点亮情况与修改前相同。
(2)将LED向左循环移位点亮改为向右循环移位点亮。
(3)加快LED循环移位点亮的速度。
(1)在源程序MOV A,#080H后加CPL A(对A取反,80H取反后为7FH)。
(2)将RR A改为RL A。
(3)删除几个CALL DELAY。
1-2将例程二0-F的循环显示改为0-9的循环显示。
将源程序中CJNE A,#10H,MAIN改为CJNE A,#0AH,MAIN.练习题二2-1通过对例程5的程序进行修改和上机调试,改变原程序的功能。
(1)将KEY2,KEY4的功能对调。
(2)每次停下再启动后,更改发光二极管点亮的循环方向。
(1)将ORG 0003H改为0013H,将ORG 0013H改为0003H;将MOV IP,#01H改为MOV IP,#04H;将SETB EX1改为SETB EX0,将SETB EX0改为SETB EX1,将CLR EX0改为CLR EX1;将CLR IE1改为CLR IE0,将CLR IE0改为CLR IE1;(2)程序如下,主要利用两个循环分别进行左移与右移。
$include (C8051F020.inc)ORG 0000HLJMP INITIALORG 0013HLJMP STARORG 0003HLJMP STOPORG 0100HINITIAL: LCALL Init_DeviceMOV R4,#0FHMOV P3,#0FFHMOV A,#0FFHMOV DPTR,#7F80HMOVX @DPTR,AMOV A,#0FEHMOV R1,#1HMOV IP,#04HMOV TCON,#05HSETB EX0SETB EALOOP1: CLR EACJNE R4,#0FH,LOOP2RL ACJNE R4,#0FH,LOOP2MOV P3,ACJNE R4,#0FH,LOOP2INC R1CJNE R4,#0FH,LOOP2SETB EALCALL DELAY1LCALL DELAY1LCALL DELAY1LCALL DELAY1CJNE R1,#8,LOOP1MOV R1,#0HSJMP LOOP1LOOP2: CLR EACJNE R4,#0F0H,LOOP1RR ACJNE R4,#0F0H,LOOP1MOV P3,ACJNE R4,#0F0H,LOOP1DEC R1SETB EALCALL DELAY1LCALL DELAY1LCALL DELAY1LCALL DELAY1CJNE R1,#0,LOOP2MOV R1,#8SJMP LOOP2STOP: PUSH ACCMOV A,R1MOV DPTR,#TABMOVC A,@A+DPTRMOV DPTR,#7F80HMOVX @DPTR,ASETB EX1JNZ $MOV A,#0FFHMOVX @DPTR,ACLR EX1POP ACCCLR IE0RETISTAR: MOV A,#00HCLR IE1PUSH ACCMOV A,R4CPL AMOV R4,APOP ACCRETITAB: DB 0C0H,0F9H,0A4H,0B0H,099HDB 092H,082H,0F8H,080H DELAY1: MOV R6,#0D1: MOV R7,#0DJNZ R7,$DJNZ R6,D1RET$include (Init_Device.inc) ;END2-2修改例程6,将计数范围由0-F扩展至00-FF(使用定时器/计时器0),并在2位数码管上用10进制数显示计数结果(00-99)。
8051单片机实训指导书

单片机实验指导书基础部分实训1 认识单片机一、单片机概述一台能够工作的计算机要有这样几个部份构成:CPU(进行运算、控制)、RAM (数据存储)、ROM(程序存储)、输入/输出设备(例如:串行口、并行输出口等)。
在个人计算机上这些部份被分成若干块芯片,安装一个称之为主板的印刷线路板上。
而在单片机中,这些部份,全部被做到一块集成电路芯片中了,所以就称为单片(单芯片)机,而且有一些单片机中除了上述部份外,还集成了其它部份如A/D,D/A等。
二、单片机的外部结构(1)单片机的引脚拿到一块芯片,想要使用它,首先必须要知道怎样连线,我们用的一块称之为89C51的芯片,下面我们就看一下如何给它连线。
电源:这当然是必不可少的了。
单片机使用的是5V电源,其中正极接40引脚,负极(地)接20引脚。
振蒎电路:单片机是一种时序电路,必须提供脉冲信号才能正常工作,在单片机内部已集成了振荡器,使用晶体振荡器,接18、19脚。
只要买来晶振,电容,连上就可以了,按图1-1接上即可。
复位引脚:按图1-1中画法连好,至于复位是何含义及为何需要复要复位,在单片机功能中介绍。
EA引脚:EA引脚接到正电源端。
至此,一个单片机就接好,通上电,单片机就开始工作了。
图1-1(二)单片机芯片引脚功能1.主电源引脚(1)GND 接地(2)VCC正常操作时为十5V电源。
2.时钟电路引脚(1)XTAL1:(2)XTAL2:3.控制线与电源复用引脚(1)RST/VPD:RST是复位信号,高电平有效。
VPD为第二功能,即备用电源输入端。
(2)ALE/PROG:ALE为地址锁存允许信号输出引脚。
PROG为编程信号,第二功能,低电平有效。
(3)PSEN:片外ROM选通信号输出端,低电平有效。
(4)EA/VPP:EA为内部和外部ROM控制端当EA=1时,从内ROM开始访问当EA=0时,只访问外部ROMVPP是编程电源输入端4.并行输入/输出引脚(1)P0口:P0.0~P0.7统称为P0口(2)P1口:P1.0~P1.7统称为P1口(3)P2口:P2.0~P2.7统称为P2口(4)P3口:P3.0~P3.7统称为P3口P3口每一位可用作第二功能,而且P3口的每一条引脚都可以独立设置为第一功能的I/O口功能和第二功能。
C8051F021型单片机实现数据采集系统

C8051F021型单片机实现数据采集系统
介绍的功角测量数据采集卡是采用Cygnal 公司C8051F021 型单片机实现的PCI 总线接口卡。
该卡通过2 片双口RAM 分别实现与GPS 接收板和上位机(PC)的数据交换,从而实现高速、可靠的数据采集、处理与传送。
本数据采集卡采用片内12 位高速ADC 并配以片外采样保持电路,通过直接交流采样方法精确快速地实现对电压和电流的采样,保证了电力系统实时测量的要求。
1 引言
实现自动化的过程中,首要环节就是数据采集。
为此我们研究开发了电力系统功角广域测控系统,其中,用C8051F021 型单片机实现的数据采集卡不仅可以准确、高效、实时地进行AD 数据采集并通过双口RAM 和PCI 接口与上位机交换数据,还可以通过与GPS 接收通信接收秒脉冲实现采集数据异地同步。
2 功角及其测量
2.1 发电机的功角
发电机通过变压器、输出线路与无限大容量系统母线联接组成的输电系统如
若
上式也称作发电机的功率特性。
式中Xd∑=Xd+XTL,其中Xd 为发电机d 轴等值电抗,XTL 为发电机与无限大系统间的联系电抗,Eq 为发电机的空载电势,V、I 为系统参考母线电压和电流,ψ为母线电压与电流间的
相位差。
当发电机的电势Eq 和受端电压V 均恒定时,传输功率P 是角度
δ的正弦函数,角度δ为Eq 与V 之间的相位差角。
因功率P 的大小与δ角度切相关,因此称δ为功率角或功角。
C8051F020入门指导

接到端口I/O引脚。
DAC为电压输出方式,有灵活的输出更新机制。这一机制允许 用软件写和定时器2、定时器3及定时器4的溢出信号更新DAC输出。
C8051F020/2的DAC之电压基准由专用的VREFD输入引脚提供,而
C8051F021/3的DAC之电压基准由器件内部的电压基准提供。DAC在 作为比较器的参考电压或为ADC差分输入提供偏移电压时非常有用。
1.9 比较器和DAC
C8051F020/1/2/3系列MCU内部有两个12位DAC和两个比较器。 MCU与每个比较器和DAC之间的数据和控制接口通过特殊功能寄存 器实现。MCU可以将任何一个DAC或比较器置于低功耗关断方式。 比较器的回差电压可以用软件编程。每个比较器都能在上升沿、下 降沿或在两个边沿都产生中断。这些中断能将MCU从休眠方式唤醒。比 较器的输出状态可以用软件查询。可通过设置交叉开关将比较器的输出
1.8 8 位模/数转换器
C8051F020有一个片内8位SAR ADC(ADC1),带有一个8通道输入多路 选择器和可编程增益放大器。该ADC工作在500ksps的最大采样速率时可提供 真正的8位精度,INL为±1LSB。有8个用于测量的输入端。ADC1完全由CIP51通过特殊功能寄存器控制。ADC0的电压基准可以在模拟电源电压(AV+) 和一个外部VREF引脚之间选择。
配置为两个单端输入或一个差分输入。
可编程增益放大器接在模拟多路选择器之后,增益可以用软件设置,从 0.5到16以2的整数次幂递增。 A/D转换有4种启动方式:软件命令、定时器2溢出、定时器3溢出和外部 信号输入。这种灵活性允许用软件事件、外部硬件信号或周期性的定时器 溢出信号触发转换。 转换结束由一个状态位指示,或者产生中断(如果中断被使能)。在转 换完成后,10或12位转换结果数据字被锁存到两个特殊功能寄存器中。这 些数据字可以用软件控制为左对齐或右对齐。
C8051F2xx 开发板用户指南说明书

Rev. 0.6 9/06Copyright © 2006 by Silicon LaboratoriesC8051F2xx-DKXX EVELOPMENT IT SER S UIDE1. Kit ContentsThe C8051F2xx Development Kits contain the following items:•C8051F206 or C8051F226 Target Board•C8051Fxxx Development Kit Quick-Start Guide•Silicon Laboratories IDE and Product Information CD-ROM. CD content includes:•Silicon Laboratories Integrated Development Environment (IDE)•Keil Software 8051 Development Tools (macro assembler, linker, evaluation ‘C’ compiler)•Source code examples and register definition files •Documentation•C8051F2xx Development Kit User’s Guide (this document)•AC to DC Power Adapter•USB Debug Adapter (USB to Debug Interface)•USB Cable2. Hardware Setup using a USB Debug AdapterThe target board is connected to a PC running the Silicon Laboratories IDE via the USB Debug Adapter as shown in Figure 1.1.Connect the USB Debug Adapter to the JTAG connector on the target board with the 10-pin ribbon cable.2.Connect one end of the USB cable to the USB connector on the USB Debug Adapter.3.Connect the other end of the USB cable to a USB Port on the PC.4.Connect the ac/dc power adapter to power jack P1 on the target board.Notes:•Use the Reset button in the IDE to reset the target when connected using a USB Debug Adapter.•Remove power from the target board and the USB Debug Adapter before connecting or disconnecting the ribbon cable from the target board. Connecting or disconnecting the cable when the devices have power can damage the device and/or the USB Debug Adapter.Figure 1. Hardware Setup using a USB Debug AdapterPWRP1.6C8051F2xx-DK3. Software SetupThe included CD-ROM contains the Silicon Laboratories Integrated Development Environment (IDE), Keil software 8051 tools and additional documentation. Insert the CD-ROM into your PC’s CD-ROM drive. An installer will auto-matically launch, allowing you to install the IDE software or read documentation by clicking buttons on the Installa-tion Panel. If the installer does not automatically start when you insert the CD-ROM, run autorun.exe found in the root directory of the CD-ROM. Refer to the readme.txt file on the CD-ROM for the latest information regarding known IDE problems and restrictions.4. Silicon Laboratories Integrated Development EnvironmentThe Silicon Laboratories IDE integrates a source-code editor, source-level debugger and in-system Flash program-mer. The use of third-party compilers and assemblers is also supported. This development kit includes the Keil Software A51 macro assembler, BL51 linker and evaluation version C51 ‘C’ compiler. These tools can be used from within the Silicon Laboratories IDE.4.1. System RequirementsThe Silicon Laboratories IDE requirements:•Pentium-class host PC running Microsoft Windows 98SE or later.•One available COM or USB port.•64 MB RAM and 40MB free HD space recommended.4.2. Assembler and LinkerA full-version Keil A51 macro assembler and BL51 banking linker are included with the development kit and are installed during IDE installation. The complete assembler and linker reference manual can be found under the Help menu in the IDE or in the “SiLabs\MCU\hlp” directory (A51.pdf).4.3. Evaluation C51 ‘C’ CompilerAn evaluation version of the Keil C51 ‘C’ compiler is included with the development kit and is installed during IDE installation. The evaluation version of the C51 compiler is the same as the full professional version except code size is limited to 4kB and the floating point library is not included. The C51 compiler reference manual can be found under the Help menu in the IDE or in the “SiLabs\MCU\hlp” directory (C51.pdf).4.4. Using the Keil Software 8051 Tools with the Silicon Laboratories IDETo perform source-level debugging with the IDE, you must configure the Keil 8051 tools to generate an absolute object file in the OMF-51 format with object extensions and debug records enabled. You may build the OMF-51 absolute object file by calling the Keil 8051 tools at the command line (e.g. batch file or make file) or by using the project manager built into the IDE. The default configuration when using the Silicon Laboratories IDE project manager enables object extension and debug record generation. Refer to Applications Note AN104 - Integrating Keil 8051 Tools Into the Silicon Labs IDE in the “SiLabs\MCU\Documentation\Appnotes” directory on the CD-ROM for additional information on using the Keil 8051 tools with the Silicon Laboratories IDE.To build an absolute object file using the Silicon Laboratories IDE project manager, you must first create a project.A project consists of a set of files, IDE configuration, debug views, and a target build configuration (list of files and tool configurations used as input to the assembler, compiler, and linker when building an output object file).The following sections illustrate the steps necessary to manually create a project with one or more source files, build a program and download the program to the target in preparation for debugging. (The IDE will automatically create a single-file project using the currently open and active source file if you select Build/Make Project before a project is defined.)C8051F2xx-DK4.4.1. Creating a New Project1.Select Project→New Project to open a new project and reset all configuration settings to default.2.Select File→New File to open an editor window. Create your source file(s) and save the file(s) with a rec-ognized extension, such as .c, .h, or .asm, to enable color syntax highlighting.3.Right-click on “New Project” in the Project Window. Select Add files to project. Select files in the filebrowser and click Open. Continue adding files until all project files have been added.4.For each of the files in the Project Window that you want assembled, compiled and linked into the targetbuild, right-click on the file name and select Add file to build. Each file will be assembled or compiled as appropriate (based on file extension) and linked into the build of the absolute object file.Note: If a project contains a large number of files, the “Group” feature of the IDE can be used to organize.Right-click on “New Project” in the Project Window. Select Add Groups to project. Add pre-definedgroups or add customized groups. Right-click on the group name and choose Add file to group. Select files to be added. Continue adding files until all project files have been added.4.4.2. Building and Downloading the Program for Debugging1.Once all source files have been added to the target build, build the project by clicking on the Build/MakeProject button in the toolbar or selecting Project→Build/Make Project from the menu.Note: After the project has been built the first time, the Build/Make Project command will only build the files that have been changed since the previous build. To rebuild all files and project dependencies, click on the Rebuild All button in the toolbar or select Project→Rebuild All from the menu.2.Before connecting to the target device, several connection options may need to be set. Open theConnection Options window by selecting Options→Connection Options... in the IDE menu. First, select the appropriate adapter in the “Serial Adapter” section. Next, the correct “Debug Interface” must be selected.C8051F2xx family devices use the JTAG debug interface. Once all the selections are made, click the OK button to close the window.3.Click the Connect button in the toolbar or select Debug→Connect from the menu to connect to the device.4.Download the project to the target by clicking the Download Code button in the toolbar.Note: To enable automatic downloading if the program build is successful select Enable automatic con-nect/download after build in the Project→Target Build Configuration dialog. If errors occur during the build process, the IDE will not attempt the download.5.Save the project when finished with the debug session to preserve the current target build configuration,editor settings and the location of all open debug views. To save the project, select Project->Save Project As... from the menu. Create a new name for the project and click on Save.C8051F2xx-DK5. Example Source CodeExample source code and register definition files are provided in the “SiLabs\MCU\Examples\C8051F2xx”directory during IDE installation. These files may be used as a template for code development. Example applications include a blinking LED example which configures the green LED on the target board to blink at a fixed rate.5.1. Register Definition FilesRegister definition files C8051F200.inc and C8051F200.h define all SFR registers and bit-addressable control/status bits. They are installed into the “SiLabs\MCU\Examples\C8051F2xx” directory during IDE installation. The register and bit names are identical to those used in the C8051F2xx data sheet. Both register definition files are also installed in the default search path used by the Keil Software 8051 tools. Therefore, when using the Keil 8051 tools included with the development kit (A51, C51), it is not necessary to copy a register definition file to each project’s file directory.5.2. Blinking LED ExampleThe example source files blink.asm and blinky.c show examples of several basic C8051F2xx functions. These include; disabling the watchdog timer (WDT), configuring the Port I/O crossbar, configuring a timer for an interrupt routine, initializing the system clock, and configuring a GPIO port. When compiled/assembled and linked this program flashes the green LED on the target board about five times a second using the interrupt handler with a timer.C8051F2xx-DK 6. Target BoardThe C8051F2xx Development Kit includes a target board with a C8051F206/26 device pre-installed for evaluation and preliminary software development. Numerous input/output (I/O) connections are provided to facilitate prototyping using the target board. Refer to Figure2 for the locations of the various I/O connectors.P1Power connector (accepts input from 7 to 15 VDC unregulated power adapter)J1VDDMonEn, Ties MONEN to +3VD2 or GND to enable/disable the VDD monitorJ264-pin I/O connector providing access to all I/O signalsP2.5Connects SW2 to port pin P2.5LED Connects LED D2 to port pin P2.4PWMIN Connects PWM low-pass filter to port pin P2.7J4JTAG connector for Debug Adapter interfaceJ5Connects P3.0 to analog signal from J6J6Analog I/O configuration connectorJ7Connects P3.1 to analog signal from J6X1Analog I/O terminal blockFigure 2. C8051F206 and C8051F226 Target BoardsC8051F2xx-DK6.1. System Clock SourcesThe C8051F2xx device installed on the target board features a internal oscillator which is enabled as the system clock source on reset. After reset, the internal oscillator operates at a frequency of 2MHz (+/-2%) by default but may be configured by software to operate at other frequencies. Therefore, in many applications an external oscillator is not required. However, an external crystal may be installed on the target board for additional applications. The target board is designed to facilitate the installation of an external crystal at the pads marked Q1. Refer to the C8051F2xx datasheet for more information on configuring the system clock source. Following are a few part numbers of suitable crystals:Freq(MHz)Digikey P/N ECS P/N22.1184X063-ND ECS-221-20-1 (20pF loading capacitance)18.432X146-ND ECS-184-20-1 (20pF loading capacitance)11.0592X089-ND ECS-110.5-20-1 (20pF loading capacitance)6.2. Switches and LEDsTwo switches are provided on the target board. Switch SW1 is connected to the RESET pin of the C8051F2xx device on the target board. Pressing SW1 puts the device into its hardware-reset state. The device will leave the reset state after SW1 is released. Switch SW2 is connected to the device’s general purpose I/O (GPIO) pin through headers. Pressing SW2 generates a logic low signal on the port pin. Remove the shorting block from the header to disconnect SW2 from the port pins. The port pin signal is also routed to a pin on the J2 I/O connector. See Table1 for the port pins and headers corresponding to each switch.Two LEDs are also provided on the target board. The red LED labeled PWR is used to indicate a power connection to the target board. The green LED labeled with a port pin name is connected to the device’s GPIO pin through headers. Remove the shorting block from the header to disconnect the LED from the port pin. The port pin signal is also routed to a pin on the J2 I/O connector. See Table1 for the port pins and headers corresponding to each LED.Table 1. Target Board I/O DescriptionsDescription I/O HeaderSW1Reset noneSW2P2.5P2.5Green LED P2.4LEDRed LED PWR none6.3. Target Board JTAG Interface (J4)The JTAG connector (J4) provides access to the JTAG pins of the C8051F2xx. It is used to connect the Serial Adapter or the USB Debug Adapter to the target board for in-circuit debugging and Flash programming. Table2 shows the JTAG pin definitions.Table 2. JTAG Connector Pin DescriptionsPin #Description1+3VD (+3.3VDC)2, 3, 9GND (Ground)4TCK5TMS6TDO7TDI8, 10Not ConnectedC8051F2xx-DK6.4. Analog I/O (J5, J6, J7, Terminal Block)An Analog I/O Configuration connector (J6) provides the ability to route analog I/O signals from the C8051F2xx to a terminal block in addition to connector J2 by installing shorting blocks on J6. Additionally, if shorting blocks are installed on J5 and J7, the analog signals routed through J6 can be inputs to the C8051F2xx at port pins P3.0 and/or P3.1. The port pins can then be configured as inputs to the on-chip ADC for evaluation. J6 also allows the user to route analog signals from the terminal block to port pins P1.3 and P1.4. These port pin can then be configured as inputs to Comparator 1. The PWM signal from the low-pass filter is also routed to J6 to provide a user controlled analog voltage level. This signal can then be used to evaluate the on-chip ADC by placing a shorting block on J6 (provided the J5 or J7 header is shorted). Refer to Figure3 to determine the shorting block installation positions required to create the desired analog signal paths. Refer to Table3 for terminal block connections and Table4 for J6 pin definitions.Figure 3. J6 Analog I/O Configuration ConnectorTable 3. Terminal Block Pin DescriptionsPin #Description1VREF2GND7AIN28AIN1Table 4. J6 Connector Pin DescriptionsPin #Description1P1.4/CP1-2, 9, 10NC3AIN24P3.0AIN5P1.3/CP1+6PWM7AIN18P3.1AIN6.5. VDD Monitor Disable (J1)The VDD Monitor of the C8051F2xx may be disabled by moving the shorting block on J1 from pins 1-2 to pins 2-3, as shown in Figure4.Figure 4. VDD Monitor Hardware SetupC8051F2xx-DK6.6. Low-pass Filter (PWMIN)The C8051F2xx target board features a low-pass filter that may be connected to port pin P2.7. Install a shorting block on connector “PWMIN” to connect the P2.7 pin of the target device to the low-pass filter input. The output of the low-pass filter is routed to the PWM signal at J6[6]. To route the PWM signal to the ADC on the target device, a shorting block should be placed on “PWMIN”, and a shorting block placed on connector “P3.0AIN” (J5) or “P3.1AIN” (J7). Connector J6 is used to connect the PWM voltage to the P3.0AIN or P3.1AIN signal routed to the corresponding port pins (See Figure3). These port pins are then configured for use by the ADC.The C8051F2xx may be programmed to generate a PWM (Pulse-Width Modulated) waveform which is then input to the low-pass filter to implement a user-controlled PWM digital-to-analog converter. Refer to Applications Note AN110 - Implementing 16-Bit PWM Using an On-Chip Timer in the “Documentation” directory on the CD-ROM for a discussion on generating a programmable dc voltage level with a PWM waveform and low-pass filter.6.7. Expansion I/O Connector (J2)The target board provides access to all C8051F2xx signals (except the four JTAG signals: TCK, TMS, TDO and TDI used to connect the Emulation Cartridge – these are accessed using test points in place near the J4 header) via the 64-pin connector J2. A small through-hole prototyping area is also provided. All I/O signals routed to connector J2 are also routed to through-hole connection points between J2 and the prototyping area (see Figure2). The signal layout pattern of these connection points is identical to the adjacent J2 connector pins. Table5 shows the pin-out of the J2 connector.Table 5. J2 Pin DescriptionsPin Description Pin Description1,46,64+3VD2 (voltage supply)21P2.42XTAL122P2.53P1.623P2.24P1.724P2.35P1.425P2.06P1.526P2.17P1.227P3.68P1.328P3.79P1.029P3.410P1.130P3.511P0.631P3.212P0.732P3.313P0.433P3.014P0.534P3.115P0.236/RST16P0.339,41,42,45,47,63GND17P0.048,50PWM (pulse-width modulator) 18P0.153VREF19P2.662VDDMONEN20P2.7C8051F2xx-DK 7. SchematicC8051F2xx-DKD OCUMENT C HANGE L ISTRevision 0.4 to Revision 0.5⏹Section 1, added USB Debug Adapter and USB Cable.⏹Section 2, changed name from "Hardware Setup" to "Hardware Setup using an EC2 Serial Adapter".⏹Section 2, added 2 Notes bullets.⏹Section 2, removed Note from bottom of page.⏹Added Section 3, "Hardware Setup using a USB Debug Adapter".⏹Section 5.4.2, changed step 2 to include new instructions.⏹Section 7, J4, changed "Serial Adapter" to "Debug Adapter".⏹Target Board DEBUG Interface Section, added USB Debug Adapter.⏹DEBUG Connector Pin Descriptions Table, changed pin 4 to C2D.⏹Changed "jumper" to "header".⏹EC2 Serial Adapter section, added EC2 to the section title, table title and figure title.⏹EC2 Serial Adapter section, changed "JTAG" to "DEBUG".⏹Added "USB Debug Adapter" section.Revision 0.5 to Revision 0.6⏹Removed EC2 Serial Adapter from Kit Contents.⏹Removed Section 2. Hardware Setup using an EC2 Serial Adapter. See RS232 Serial Adapter (EC2) User's Guide.⏹Removed Section 8. EC2 Serial Adapter. See RS232 Serial Adapter (EC2) User's Guide.⏹Removed Section 9. USB Debug Adapter. See USB Debug Adapter User's Guide.DisclaimerSilicon Laboratories intends to provide customers with the latest, accurate, and in-depth documentation of all peripherals and modules available for system and software implementers using or intending to use the Silicon Laboratories products. Characterization data, available modules and peripherals, memory sizes and memory addresses refer to each specific device, and "Typical" parameters provided can and do vary in different applications. Application examples described herein are for illustrative purposes only. Silicon Laboratories reserves the right to make changes without further notice and limitation to product information, specifications, and descriptions herein, and does not give warranties as to the accuracy or completeness of the included information. Silicon Laboratories shall have no liability for the consequences of use of the information supplied herein. This document does not imply or express copyright licenses granted hereunder to design or fabricate any integrated circuits. The products must not be used within any Life Support System without the specific written consent of Silicon Laboratories. A "Life Support System" is any product or system intended to support or sustain life and/or health, which, if it fails, can be reasonably expected to result in significant personal injury or death. Silicon Laboratories products are generally not intended for military applications. Silicon Laboratories products shall under no circumstances be used in weapons of mass destruction including (but not limited to) nuclear, biological or chemical weapons, or missiles capable of delivering such weapons.Trademark InformationSilicon Laboratories Inc., Silicon Laboratories, Silicon Labs, SiLabs and the Silicon Labs logo, CMEMS®, EFM, EFM32, EFR, Energy Micro, Energy Micro logo and combinations thereof, "the world’s most energy friendly microcontrollers", Ember®, EZLink®, EZMac®, EZRadio®, EZRadioPRO®, DSPLL®, ISOmodem ®, Precision32®, ProSLIC®, SiPHY®, USBXpress® and others are trademarks or registered trademarks of Silicon Laboratories Inc. ARM, CORTEX, Cortex-M3 and THUMB are trademarks or registered trademarks of ARM Holdings. Keil is a registered trademark of ARM Limited. All other products or brand names mentioned herein are trademarks of their respective holders. Silicon Laboratories Inc.400 West Cesar ChavezAustin, TX 78701USAIoT Portfolio/IoT SW/HW /simplicity Quality /quality Support and Community 。
80C51单片机原理实验指导书

MCS51单片机实验指导书(第2版)2006.11.8 修改了音乐演奏程序中的有关休止符的BUG淮阴师范学院计算机科学系2006.9实验板结构实验板结构如下图所示:注意:实验板与PC机连接时一定要先连接串行通信电缆,然后再将其电源线插入USB 接口;拆除时先断开其电源,再断开串行通信电缆。
否则极易损坏PC机的串口。
最好先关闭微机电源,再连接或拆除实验板。
实验要求1、实验前预习实验内容,理解实验原理。
2、按规定时间进入实验室,登记领取实验板和连接线,按操作程序将实验板连接到PC 机上,开始实验。
2、实验完毕请指导老师确认后,按操作程序拆除实验板,将连接线收拾好,与实验板一起归还指导老师,方可离开实验室。
3、按时撰写并上交实验报告。
实验报告格式为:(1)实验目的,(2)实验内容,(3)源代码及流程图,(4)结果记录及分析,(5)思考题,(6)体会及设想。
51单片机集成开发环境MedWin V2.39简介1、安装从网站免费下载MedWin V2.39集成开发环境安装程序压缩包,将其释放后,按照默认路径安装到C:\Manley\PmedWin文件夹。
2、设置(1)每次启动MedWin会出现对话框,询问使用仿真器还是模拟仿真,应点击[模拟仿真]按钮。
(2)设置仿真器点击[设置]—[设置仿真器]命令,选择时钟频率为12兆赫兹。
(3)设置工作目录 MedWin 集成开发环境默认的工作目录为C:\MedWin\PMedWin,建议根据需要建立自己的工作目录。
注意:不得使用长文件名或长目录名!(4)设置编译器将C语言编译器C51(文件夹)拷贝到C:\MedWin文件夹下,点击[设置]—[设置编译工具]命令,打开“设置编译工具”对话框,使用汇编语言时选择第一行,使用C语言时选择第二行,如下图所示。
3、使用(1)新建项目点击[项目管理]—[新建项目] 命令,输入项目名称,点击[确定]按钮,出现“添加项目文件”对话框,输入源代码文件名,如T1.C(或T1.ASM),单击[打开]按钮,出现代码窗口,即可开始编程。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
提要:实验项目1、单片机的IO编程实验1 IO开关量输入实验实验2 IO输出驱动继电器(或光电隔离器)实验实验3 IO输入/输出------半导体温度传感器DS18B20实验2、单片机的中断系统实验1 外部外部中断----脉冲计数实验3、单片机的定时器/计数器实验1 计数器实验实验2 秒时钟发生器实验4、单片机的串口特点和编程实验1 P C机串口通讯实验实验2 R S485通讯实验5、存储器实验1 RAM存储器读写实验6、PWM发生器实验1 PWM发生器(模拟)实验实验1 PWM发生器(内部)实验7、WDG看门狗实验1 外扩WDG(MAX813)实验实验2 WDG(内部)实验8、SPI总线实验1 SPI(模拟)实验-----TLC2543 AD转换实验实验2 SPI(模拟)实验-----TLV5616 DA转换实验9、I2C总线实验1 I2C(模拟)实验-----AT24C01读写实验实验2 I2C(内部)实验-----AT24C01读写实验10、综合实验实验1 HD7279LED数码管显示实验实验2 HD7279键盘实验实验3 外部中断---电机转速显示实验11、步进电机正反转实验12、TFT液晶显示彩色条纹实验13、16X16LED点阵显示汉字实验一、单片机的IO编程实验1 IO开关量输入实验目的:学习单片机读取IO引脚状态的的方法。
内容:编程读取IO引脚状态。
设备:EL-EMCU-I试验箱、EXP-C8051F021 CPU板。
编程:首先要把相关的引脚设置在IO的输入状态,然后写一个循环,不停地检测引脚的状态。
步骤:1、将CPU板正确安放在CPU接口插座上,2、连线:用导线将试验箱上MCU部分的IO1--- IO8分别连接到SWITCH 的8个拨码开关的K1---K8的输出端子K1---K8上,连接好仿真器。
3、试验箱上电,在PC机上打开Keil C环境,打开试验程序文件夹IO_INPUT 下的工程文件IO_INPUT.Uv2编译程序,上电,在函数main()的最后一句设置断点,进入调试状态,打开窗口Peripherals-->IO-Port-->P3,改变开关状态,运行程序到断点处,观察窗口的数值与开关的对应关系。
实验2 IO输出驱动继电器(或光电隔离器)实验目的:学习IO输出控制方法。
内容:通过单片机的IO引脚驱动继电器动作。
设备:EL-EMCU-I试验箱、EXP-C8051F021 CPU板。
编程:首先要把相关的引脚设置在IO的输出状态,然后写一个循环,依次输出高低电平。
步骤:1、将CPU板正确安放在CPU接口插座上,2、连线:用导线将MCU的IO1、IO2分别连接到RELAY的R_IN和光电隔离的输入P_IN上,R_OUT和P_OUT分别连接到发光二极管L1和L2的输入孔L1和L2上,连接好仿真器。
3、试验箱上电,在PC机上打开Keil C环境,打开试验程序文件夹IO_OUTPUT下的工程文件IO_OUTPUT.Uv2编译程序,上电,进入调试状态,打开窗口Peripherals-->IO-Port-->P3,单步运行程序,观察窗口的数值变化。
4、全速运行程序,观察继电器的发光二极管的亮灭变化,同时确定继电器动作(或光电隔离器导通)与IO输出电平的关系。
实验3 IO输入/输出------半导体温度传感器DS18B20实验目的:学习IO引脚编程实现交替输入、输出的方法。
内容:通过单片机的IO引脚与半导体温度传感器实现单线通讯。
设备:EL-EMCU-I试验箱、EXP-C8051F021 CPU板。
编程:根据18B20的资料(见备注),将IO引脚设置在输出状态,分别模拟出不同的命令时序,例如复位、读寄存器等;再改变IO引脚的为输入状态,接收传感器输出的数据。
步骤:1、将CPU板正确安放在CPU接口插座上,2、连线:用导线将MCU的IO1连接到传感器的接口端子DQ上,连接好仿真器。
3、试验箱上电,在PC机上打开Keil C环境,打开试验程序文件夹IO_INOUTPUT下的工程文件IO_INOUTPUT.Uv2编译程序,上电,进入调试状态,打开窗口VIEW-- Watch &Call stack Windows,按照程序注释说明设置断点,全速运行程序到断点处,观察变量i的数据,用手摸住传感器DS18B20芯片,再运行到断点处,观察窗口的变量数值的变化。
4、备注:DSl8B20数字温度计提供9位(二进制)温度读数指示,器件的温度信息经过单线接口送入DSl8B20或从DSl8B20送出,因此从主机CPU到DSl8B20仅需一条线(和地线),DSl8B20的电源可以由数据线本身提供而不需要外部电源。
因为每一个DSl8B20在出厂时已经给定了唯一的序号,因此任意多个DSl8B20可以存放在同一条单线总线上,这允许在许多不同的地方放置温度敏感器件。
DSl8B20的测量范围从-55到+125增量值为0.5可在l s(典型值)内把温度变换成数字。
二、单片机的中断系统实验1外部中断----脉冲计数实验目的:学习单片机的外部中断使用方法。
内容:对外部中断计数显示。
设备:EL-EMCU-I试验箱、EXP-C8051F021 CPU板。
编程:首先第一步设置单片机的IO为输入状态,第二步设置引脚的中断触发方式,一般设置为边沿触发,第三步,设置外部中断的优先级,第四步,编写中断服务程序,包括中断入口跳转等,第五步,设置中断使能,允许外部引脚触发中断。
第六步,设置死循环,主程序结束,交给中断服务程序完成计数。
步骤:1、将CPU板正确安放在CPU插座上,CPU板上跳线J7短接在INT0处;2、连线:用导线将MCU的INT0连接到单脉冲输出孔P-,连接好仿真器。
3、试验箱上电,在PC机上打开Keil C环境,打开试验程序文件夹EXT_INT1下的工程文件EXT_INT1.Uv2,编译程序,上电,进入调试状态,打开窗口VIEW-- Watch &Call stack Windows,按照程序注释说明设置断点,全速运行程序,每按下一次单脉冲开关Paulse,程序运行到断点处一次,观察变量num的变化。
三、单片机的定时器/计数器实验1 计数器实验目的:学习单片机的定时/计数器的计数功能使用方法。
内容:对外部单脉冲信号进行计数,计数10个后产生计数中断。
设备:EL-EMCU-I试验箱、EXP-C8051F021 CPU板。
编程:使用定时/计数器的计数功能,将外部时钟信号加在计数器的计数时钟输入引脚上,当计数10次后,计数器溢出,触发标志位,编程控制分频输出引脚电平翻转,产生分频后的时钟信号。
步骤:1、将CPU板正确安放在CPU接口插座上,2、连线:用导线将MCU的T0连接到DDS信号源的OUTPUT上(设置信号源的Vpp=2~5V之间;使之符合TTL电平的要求,高电平约在3~5V之间,低电平约在0~0.8V之间)。
此外将跳线J8跳到T1位置,连接好仿真器。
3、试验箱上电,在PC机上打开Keil C环境,打开试验程序文件夹COUNTER 下的工程文件COUNTER.Uv2,编译程序,上电,进入调试状态,单步运行程序观察每条语句执行后相关寄存器的变化。
4、上电全速运行程序,用示波器的两个通道观察时钟信号发生器的输出信号OUTPUT和单片机的MCU_IO1的波形,比较二者的频率关系实验2 秒时钟发生器实验目的:学习单片机的定时/计数器的定时功能使用方法。
内容:产生频率为0.5Hz的时钟输出。
设备:EL-EMCU-I试验箱、EXP-C8051F021 CPU板。
编程:使用定时/计数器的定时功能,时钟源采用系统时钟,根据时钟源的频率配置初值寄存器,使能定时器中断,在中断服务程序中翻转一个IO引脚输出,产生0.5Hz的时钟输出。
步骤:1、将CPU板正确安放在CPU接口插座上,2、连线:用导线将MCU的IO1连接到发光二极管L1的输入L1上,连接好仿真器。
3、试验箱上电,在PC机上打开Keil C环境,打开试验程序文件夹TIMER_SECOND下的工程文件TIMER_SECOND.Uv2,编译程序,上电,进入调试状态,单步运行程序观察每条语句执行后相关寄存器的变化。
4、全速运行程序,观察发光二极管的亮灭情况。
5、备注:现在的单片机系统时钟较高,难于产生1秒的定时中断,所以,可以设置定时时间为50毫秒,在中断服务程序中设置程序计数,当累加到1秒后,控制输出IO引脚电平翻转,驱动发光二极管。
四、单片机的串口特点和编程实验1 PC机串口通讯实验目的:学习单片机串口的使用方法。
内容:与PC机实现通讯。
设备:EL-EMCU-I试验箱、EXP-C8051F021 CPU板。
编程:第一步,配置串口工作在8位,波特率可变异步通讯工作方式,波特率由定时器1确定,同时使能其中断并清除其中断标志位;第二步,配置定时器1,工作在8位自动重装入模式,根据波特率计算其初值。
第三步,编写串口中断服务程序,只处理接收中断,对发送中断只清除标志,不做其他处理。
第四步,设置死循环,交由中断服务程序处理。
步骤:1、将CPU板正确安放在CPU接口插座上;2、连线:用导线将MCU的INT0 (TXD)、SOMI (RXD)分别连接到RS232的232TXD、232RXD,用附带的直连串口线连接试验箱的DB9和计算机的串口,接好仿真器。
3、试验箱上电,在PC机上打开Keil C环境,打开试验程序文件夹RS232下的工程文件RS232.Uv2,编译程序,上电,进入调试状态,单步运行程序观察每条语句执行后相关寄存器的变化。
4、打开PC机的超级终端,设置波特率115200、数据位8、无流控、无校验等信息,PC机全速运行试验程序,在超级终端里输入可显示字符,观察超级终端的显示,断开连接的串口线,再输入字符,观察显示有什么不同。
5、备注:在串口中断服务程序中,要清除中断标志位。
在发送数据前,要检测发送状态位在发送结束状态。
实验2 RS485通讯实验目的:学习单片机串口的使用方法以及RS485通讯。
内容:使用Max485芯片进行电平转换,实现差分方式通讯。
设备:EL-EMCU-I试验箱、EXP-C8051F021 CPU板。
(需2套)步骤:1、将两个实验箱的CPU板正确安放在CPU接口插座上,CPU板上的跳线J7均短接在INT0处。
2、连线:发送设备:(1)用导线将MCU的INT0 (TXD)、SOMI (RXD)、IO1、INT0分别连接到RS485的TXD、RXD、E485和单脉冲输出P-孔;CPU板上跳线J7短接在INT0处;(3)用两根导线顺序连接两个实验箱的UR1差分接口(上、下分别对接)。