单片机上机考试习题

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

实验二流水灯问题1四灯四键#includereg51.hvoidmain(){unsignedchari;P0=0xff;while(1){i=P1;P0=i;}}问题2走马灯#includereg51.hvoidmain(void){inti,j,k;P0=0xfe;while(1){i=0xfe;for(k=0;k8;k++){P0=i;i=1;i++;for(j=0;j20000;j++);}}}实验三外部中断问题1两中断分高低优先级#includereg51.hsbitP15=P1^5;unsignedinti;voidmain(){EA=1;EX0=1;EX1=1;IT0=1;IT1=1;PX1=1;P0=0X55;P15=0;while(1){P0=0X55;}}voidxx0(void)interrupt0{for(i=0;i60000;i++)P0=0x0f;}voidxx1(void)interrupt2{P0=0x00;P15=1;for(i=0;i10000;i++);P15=0;}问题2一键八灯中断实现+1#includereg51.hsbitP10=P1^0;chari;voidmain(void){i=0;EA=1;EX0=1;IT0=1;while(1);}voidxt0(void)interrupt0{i++;P0=~i;}实验四定时器中断问题1定时器三灯亮灭#includereg51.hsbitP01=P0^1;sbitP02=P0^2;sbitP00=P0^0;chari,j;main(){i=0;j=0;TMOD=0X01;TH0=0Xec;TL0=0X78;EA=1;ET0=1;TR0=1;while(1);}voidxx0(void)interrupt1{TH0=0Xec;TL0=0X78;i++;if(i==25){i=0;j++;if(j==1)P02=!P02;elseif(j==2){P01=!P01;P02=!P02;}elseif(j==3){P02=!P02;}elseif(j==4){P00=!P00;P01=!P01;P02=!P02;j=0;}}}问题2定时器一秒闪一次#includereg51.hsbitP00=P0^0;chari;main(){i=0;TMOD=0X01;TH0=0Xd8;TL0=0Xf0;EA=1;ET0=1;TR0=1;P0=0xff;while(1);}voidxx0(void)interrupt1{TH0=0Xd8;TL0=0Xf0;i++;if(i==50){i=0;P00=!P00;}}问题3数码管定时器#includereg51.hunsignedcharcodetab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};unsignedchari,j,k,m,n,dbbuf[2];voiddesplay(){P1=03;P0=dbbuf[0];P1=0x02;for(n=0;n200;n++);P1=03;P0=dbbuf[1];P1=0x01;for(n=0;n200;n++);}voidmain(){i=0;j=0;TMOD=0X01;TH0=0Xd8;TL0=0Xf0;EA=1;ET0=1;TR0=1;while(1){desplay();}}voidxx0(void)interrupt1{TH0=0Xd8;TL0=0Xf0;i++;if(i==100){i=0;j++;j=j%100;k=j/10;m=j%10;dbbuf[0]=tab[k];dbbuf[1]=tab[m];}}实验五串口通信问题1双机接发#includereg51.hsbitP10=P1^0;voidmain(){TMOD=0X20;TH1=0XFD;TL1=0XFD;TR1=1;SCON=0X50;while(1){while(!RI);RI=0;P0=SBUF;}}问题2虚拟#includereg51.hsbitP10=P1^0;voidmain(){TMOD=0X20;TH1=0XFD;TL1=0XFD;TR1=1;SCON=0X50;while(1){while(!RI);RI=0;P0=SBUF;SBUF=P0;while(!TI);TI=0;}}问题六步进电机问题1测量步距角约0.17°不用软件仿真直接连硬件#includereg51.hunsignedinti,j;voidmain(){while(1){for(j=0;j200;j++){P1=0xfe;for(i=0;i300;i++);P1=0xfd;for(i=0;i300;i++);P1=0xfb;for(i=0;i300;i++);P1=0xf7;for(i=0;i300;i++);}while(1);}}问题2使步进电机转180°不用软件仿真直接连硬件#includereg51.hunsignedinti,j;voidmain(){while(1){for(j=0;j267;j++){P1=0xfe;for(i=0;i300;i++);P1=0xfd;for(i=0;i300;i++);P1=0xfb;for(i=0;i300;i++);P1=0xf7;for(i=0;i300;i++);}while(1);}}问题3使步进电机转起来#includereg51.hunsignedinti;voidmain(){while(1){P1=0xfe;for(i=0;i20000;i++);P1=0xfd;for(i=0;i20000;i++);P1=0xfb;for(i=0;i20000;i++);P1=0xf7;for(i=0;i20000;i++);}}实验7电子琴#includereg51.hchark;sbitP00=P0^0;sbitP10=P1^0;sbitP11=P1^1;sbitP12=P1^2;sbitP13=P1^3;sbitP14=P1^4;sbitP15=P1^5;sbitP16=P1^6;unsignedintcodetab[]={0xfc44,0xfcac,0xfd09,0xfd34,0xfd82,0xfdc8,0xfe06};voidmain(){TMOD=0X01;EA=1;ET0=1;P00=0;while(1){if(P10==0){k=0;TH0=tab[0]/256;TL0=tab[0]%256;TR0=1;while(P10==0);TR0=0;P00=0;}elseif(P11==0){k=1;TH0=tab[1]/256;TL0=tab[1]%256;TR0=1;while(P11==0);TR0=0;P00=0;}elseif(P12==0){k=2;TH0=tab[2]/256;TL0=tab[2]%256;TR0=1;while(P12==0);TR0=0;P00=0;}elseif(P13==0){k=3;TH0=tab[3]/256;TL0=tab[3]%256;TR0=1;while(P13==0);TR0=0;P00=0;}elseif(P14==0){k=4;TH0=tab[4]/256;TL0=tab[4]%256;TR0=1;while(P14==0);TR0=0;P00=0;}elseif(P15==0){k=5;TH0=tab[5]/256;TL0=tab[5]%256;TR0=1;while(P15==0);TR0=0;P00=0;}elseif(P16==0){k=6;TH0=tab[6]/256;TL0=tab[6]%256;TR0=1;while(P16==0);TR0=0;P00=0;}}}voidxx0(void)interrupt1{TH0=tab[k]/256;TL0=tab[k]%256;P00=!P00;}

1 / 10
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功