资源描述
单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,*,*,*,实验用硬件平台(含USB接口写入线),蜂鸣器,驱动器,AD,EEPROM,232电平转换,晶振,继电器,实验用硬件平台(含USB接口写入线)蜂鸣器驱动器ADEEPR,1,实验用硬件平台(含并口写入线和电源),实验用硬件平台(含并口写入线和电源),2,单片机在线系统AY-MPU89S51E,AT89S52单片机(跳线,接上排针,时),6位数码管动态显示(P0输出字形、P2.05选择位),8位LED显示(P1),6位按键输入(P2.72,P3.3),EEPROM:256字节(IIC接口,P3.2 P3.4),8位AD(串行接口)P3.57,蜂鸣器(P1.7)、继电器,RS232接口(P3.1、P3.2),温度传感器,单片机在线系统AY-MPU89S51EAT89S52单片机(,3,显示部分,232接口,驱动+继电器,显示部分232接口驱动+继电器,4,单片机在线系统AY-MPU89S51E课件,5,单片机在线系统AY-MPU89S51E课件,6,单片机在线系统AY-MPU89S51E课件,7,流水灯实验(实验1、2),1、掌握51单片机如何控制信号输出。,2、掌握Keil C集成开发环境的使用。,3、掌握51开发平台的使用。,4、8个发光管(L1L8)接在P1的07,为0时点亮。,5、功能:,首先点亮L1、然后L2、最后是L8,接着点亮L8、然后是L7 L6 L1,如此循环,间隔0.11.0秒,流水灯实验(实验1、2)1、掌握51单片机如何控制信号输出,8,实验1:流水灯实验(汇编程序),ORG 000H,START:MOV A,#0FFH,CLR C,MOV R2,#08H,LOOP:RLC A,MOV P1,A ;输出至P1口,LCALL DELAY ;调用延迟子程序(延迟100毫秒),DJNZ R2,LOOP,MOV R2,#07H ;设右移7次,LOOP1:RRC A,MOV P1,A ;输出至P1口,LCALL DELAY,DJNZ R2,LOOP1,JMP START ;跳回到START,再一次循环。,DELAY:MOV R4,#200 ;延迟子程序(100毫秒)250*2*200=500*200us,D1:MOV R5,#248;=50*2ms=100ms,DJNZ R5,$;2us,DJNZ R4,D1;2us,RET,END,实验1:流水灯实验(汇编程序)ORG 000H,9,流水灯实验(C程序),#include reg52.h,void Delay(),unsigned char i,j;,for(i=0;i255;i+),for(j=0;j255;j+);,void main(),unsigned char i,dat;,while(1),dat=0 x01;,for(i=0;i8;i+),P1=dat;,/L1 is first light,then L2 L3 L8,dat=dat1;,Delay();,dat=0 x80;,for(i=0;i1;,Delay();,流水灯实验(C程序)#include reg52.hd,10,查表法点亮LED,给定表格(33个8位数),为1则点亮相应的发光二极管,间隔0.30.9秒,查表法点亮LED给定表格(33个8位数),11,实验2:流水灯实验(汇编程序),BEEP BIT P2.0,BUFF_LED_LP EQU 21H ;亮灯循环寄存器,org 000h,JMP START,ORG 100H,;-,start:mov P1,#0ffh ;初始化MCU端口,MOV A,#00H ;初始化寄存器,MOV PSW,#00H,MOV IE,#00H,MOV SP,#30H,MOV BUFF_LED_LP,#00H,LOOP:MOV DPTR,#TAB_A_LAMP ;设置亮灯花型列表地址(32种),MOV A,BUFF_LED_LP ;查询方式读取花型,MOVC A,A+DPTR,CPL A,MOV P1,A ;LED小灯控制口,LCALL DEL1S,INC BUFF_LED_LP,MOV A,BUFF_LED_LP,CJNE A,#32,LOOP,MOV BUFF_LED_LP,#00H,JMP LOOP,实验2:流水灯实验(汇编程序)BEEP BIT,12,实验2:流水灯实验(汇编程序)续,TAB_A_LAMP:DB 00111100B,10000001B,11000011B,11100111B,11111111B,11100111B,11000011B,10000001B,00000000B,DB 00011000B,00111100B,01111110B,11111111B,00000000B,10101010B,10101010B,11001100B,DB 10000000B,11000000B,11100000B,11110000B,11111000B,11111100B,11111110B,11111111B,DB 11111110B,11111100B,11111000B,11110000B,11100000B,11000000B,10000000B,00000000B,deL1S:MOV R5,#03H ;延时子程序(约0.5秒),DEL1S0:mov R6,#0ffh,DEL1S1:mov R7,#0ffh,djnz R7,$,djnz R6,del1S1,DJNZ R5,DEL1S0,;CPL BEEP,ret,END,实验2:流水灯实验(汇编程序)续,13,实验2:流水灯实验(C程序),#include reg52.h,code unsigned char tab=0 x3c,0 x81,0 xc3,0 xe7,0 xff,0 xe7,0 xc3,0 x81,0 x00,0 x18,0 x3c,0 x7e,0 xff,0 x00,0 xaa,0 xaa,0 xcc,0 x80,0 xc0,0 xe0,0 xf0,0 xf8,0 xfc,0 xfe,0 xff,0 xfe,0 xfc,0 xf8,0 xf0,0 xe0,0 xc0,0 x80,0 x00;,void delay(),unsigned char i,j,k;,for(i=0;i2;i+),for(j=0;j255;j+),for(k=0;k255;k+);,void main(),unsigned char i;,while(1),for(i=0;i33;i+),P1=tabi;,delay();,实验2:流水灯实验(C程序)#include reg52.,14,实验5:按键应用实验(汇编),KEY BIT P3.3,SW1 BIT P2.7;P2.2 by htq,ORG 000H,START:mov sp,#40h,mov p2,#0ffh,mov p3,#0ffh,MOV P1,#0ffh;,clr key,WAIT:;JB KEY,$;等候按键!by htq,JB SW1,$,lcall delay,cpl P1.0,JNB SW1,$;wait key is released,lcall delay;by htq,JMP wait,DELAY:MOV R3,#200,D1:MOV R4,#200,DJNZ R4,$,DJNZ R3,D1,RET,END,功能:按下SW1一次,发光管L1点亮或熄灭,实验5:按键应用实验(汇编)KEY BIT P3.,15,实验5:按键应用实验(C),/key SW1 is down,LED1 is swap(on or off),#include reg52.h,#define uchar unsigned char,sbit KEY=P33;,sbit SW1=P27;,sbit LED1=P10;,void Delay(),uchar i,j;,for(i=0;i200;i+),for(j=0;j200;j+);,void main(),KEY=0;,while(1),while(SW1);,Delay();,LED1=!LED1;,while(!SW1);,Delay();,实验5:按键应用实验(C)/key SW1 is down,16,;check all 6 key,light correspond LEDs,edit by htq 2009.9.4,keydatequ 22h,KEY BIT P3.3,ORG 000H,START:mov sp,#40h,mov p2,#0ffh,mov p3,#0ffh,MOV P1,#0ffh;,clr key,WAIT:;JB KEY,$;等候按键!by htq,mov a,P2,cpla;if some key is down,then the bit is 0,anla,#0fch,movkeydat,a;,mov P0,a,jznokey;the down key is 1,;some key is down,jbkeydat.7,sw1;sw1 is down,jbkeydat.6,sw2;sw2 is down,jbkeydat.5,sw3;sw3 is down,jbkeydat.4,sw4;sw4 is down,jbkeydat.3,sw5;sw5 is down,jbkeydat.2,sw6;sw6 is down,sjmpnokey,实验5:按键应用实验(keylight1.asm),;check all 6 key,light corre,17,sw1:,cplp1.0,sjmpnokey1,sw2:,cplp1.1,sjmpnokey1,sw3:,cplp1.2,sjmpnokey1,sw4:,cplp1.3,sjmpnokey1,sw5:,cplp1.4,sjmpnokey1,sw6:,cplp1.5,nokey1:,call delay;by htq,nokey:,JMP wait,DELAY:,movR2,#5,d2:,MOV R3,#200,D1:MOV R4,#200,DJNZ R4,$,DJNZ R3,D1,djnzr2,d2,RET,END,sw1:,18,实验5:按键应用实验(keylight1.c),/check all 6 key,light correspond LEDs,edit by htq 2009.9.18,#include reg52.h,#define uchar unsigned char,sbit KEY=P33;,sbit SW1=P27;,sbit LED1=P10;,sbit LED2=P11;,sbit LED3=P12;,sbit LED4=P13;,sbit LED5=P14;,sbit LED6=P15;,bdata uchar KeyDat;,void Delay(),uchar i,j;,for(i=0;i200;i+),for(j=0;j8;,TL0=(unsigned char)(65536-4000);,Count4ms=Count4ms+1;,if(Count4ms=250),Count4ms=0;,SecFlag=1;,P2=Tabdisp_cnt;/disp,P0=Tab1disp_buffdisp_cnt;,disp_cnt=disp_cnt+1;,if(disp_cnt=2),disp_cnt=0;,void FillDispBuffer(void),disp_buff0=sec/10;,disp_buff1=sec%10;,void ChangeTime(void),SecFlag=0;,sec=sec-1;,if(sec=255),sec=99;,FillDispBuffer();,void main(),/initial,TMOD=0 x01;,TH0=(65536-400
展开阅读全文