1、单片机原理与应用实验报告单片机原理与应用课程实 验 报 告北京理工大学机电学院实验一 P1口基本实验一、实验目的掌握如何建立项目,并用Keil C51软件调试程序。二、实验内容掌握P1口基本实验中的编程方法,调试程序。三、实验程序 #includeunsigned char L; delay(unsigned int ms) unsigned char j;unsigned int i;for(i=0;ims;i+) for(j=0;j60;j+);void display() P1=L; delay(1000); main() unsigned char i;L=0xFF;display()
2、; L=0x00; display();while(1) L=0x01; display();for(i=0;i8;i+) L=L1; display(); L=0x80; display(); for(i=0;i1; /*L右移1位*/ display(); 由两边向中间亮:#includeunsigned char L; delay(unsigned int ms) unsigned char j;unsigned int i;for(i=0;ims;i+) for(j=0;j60;j+) ;void display() P1=L; delay(1000); main() unsigned
3、 char i;L=0xFF; display(); L=0x00; display();while(1) L=0x01; display(); for(i=0;i8;i+) L=L1; display(); L=0x80; display(); for(i=0;i1; display(); 实验二 P1口扩展实验一、实验目的掌握EL-8051-III型单片机实验系统。二、实验内容掌握P1口扩展实验中的编程方法,调试程序。三、实验程序#includedelay(unsigned int ms) unsigned char j; unsigned int i; for(i=0;ims;i+) f
4、or(j=0;j60;j+); main() unsigned char K; P1=0x00; delay(1000); P1=0xff; delay(1000); while(1) K=P1&0x03; switch(K) case 0:P1=0xff;break; case 1:P1=0xf3;delay(1000);P1=0xff;delay(1000);break; case 2:P1=0xcf;delay(1000);P1=0xff;delay(1000);break; case 3:P1=0x03;delay(1000);P1=0xff;delay(1000);break; de
5、fault: break; 实验三 简单I/O口扩展实验 交通灯控制实验一、实验目的学习在单片机系统中扩展简单I/O接口的方法。二、实验内容掌握交通灯控制的编程方法,调试程序。三、实验程序 #includeunsigned char xdata *code L=0xCFA0; delay(unsigned int ms) unsigned char j; unsigned int i; for(i=0;ims;i+) for(j=0;j60;j+); main() unsigned char i; *L=0xff; while(1) *L=0x81; delay(3000); for(i=0;
6、i=9;i+) *L=0x21; delay(1000); *L=0x01; delay(100); for(i=0;i=4;i+) *L=0x41; delay(200); *L=0x01; delay(200); *L=0x81; delay(500); for(i=0;i=9;i+) *L=0x84; delay(1000); *L=0x80; delay(100); for(i=0;i=4;i+) *L=0x82; delay(200); *L=0x80; delay(200); 实验四 中断实验 有急救车的交通灯控制实验一、实验目的学习中断处理程序的编程方法。二、实验内容掌握急救车的
7、交通灯控制的编程方法,调试程序。三、实验程序 #includeunsigned char xdata *code L=0xCFB0;sbit flag=P32; delay(unsigned int ms) unsigned char j; unsigned int i; for(i=0;ims;i+) for(j=0;j60;j+); void sevice_int0() interrupt 0 using 2 unsigned char i=10; flag=1; while(i-) *L=0x7e; delay(1000); main() unsigned char i; IP=0x01
8、; IE=0x81; *L=0xff; while(1) for(i=0;i3;i+) *L=0x81; delay(1000); for(i=0;i=9;i+) *L=0x21; delay(1000); *L=0x01; delay(100); for(i=0;i=4;i+) *L=0x41; delay(200); *L=0x01; delay(200); *L=0x81; delay(200); for(i=0;i=9;i+) *L=0x84; delay(1000); *L=0x80; delay(100); for(i=0;i=4;i+) *L=0x82; delay(200);
9、*L=0x80; delay(200); 实验五 内部定时器实验一、实验目的学习复合定时的编程方法。二、实验内容掌握复合定时的编程方法,调试程序。三、实验程序 #includesbit control=P10;sbit light=P17;timer0() interrupt 1 using 1 control=!control; TH0=(65536-50000)/256; TL0=(65536-50000)%256;timer1() interrupt 3 using 2 light=!light; main() TMOD=0x61; TH0=(65536-50000)/256; TL0=
10、(65536-50000)%256; TH1=256-5; TL1=256-5; IP=0x08; EA=1; ET0=1; ET1=1; TR0=1; TR1=1; while(1);实验六 内部定时器与中断实验一、实验目的学习内部定时器/计数器的使用和编程方法。二、实验内容掌握定时器与中断复合编程方法,调试程序。三、实验程序#includeunsigned int i=0,a=0;unsigned int l16=0x18,0x3C,0x7E,0xFF,0xE7,0xC3,0x81,0x00,0x81,0xC3,0xE7,0xFF,0x7E,0x3C,0x18,0x00;unsigned
11、int b16=0x81,0x00;delay(unsigned int ms) unsigned int j; unsigned int i; for(i=0;ims;i+) for(j=0;j60;j+); void sevice_int0() interrupt 0 using 2 int i; for(i=0;i=5) i=0; if(a15) a=0; P1=la; a+; main() int a; IP=0x01;IE=0x83; TMOD=0x01; TH0=(65536-50000)/256; TL0=(65536-50000)%256; EA=1; ET0=1; TR0=1
12、; while(1);实验七 数码显示实验一、实验目的学习数码管显示数字的原理。二、实验内容掌握动态扫描键盘的方法,调试程序。三、实验程序#includeunsigned char BUF=0; /*定时器每中断一次BUF加1*/unsigned char SBF0=0,SBF1=0,MBF0=0,MBF1=0; /*秒、分各位清零*/unsigned code table11=0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40; /*数码管真值表*/unsigned xdata *L=0xcfa0; /*74LS273端口地址*/ delay(unsigned int ms) /*延时子程序*/ unsigned char j; unsigned in
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1