《实验二(按键控制数码管输出值).docx》由会员分享,可在线阅读,更多相关《实验二(按键控制数码管输出值).docx(2页珍藏版)》请在第一文库网上搜索。
1、03F,006,0x5B,04F,0x66,0x6D,0x7D,0x07,0x7F,0x6F(0-9码值)实验一(学号流水灯)#includechar Tab=09 码值;int count,miao;此处有一个延时函数void main(void)(TMOD=0x01;TH0=(65536-1000)/256;TL0=(65536-1000)%256;EA=1; ETO=1; TRO=1; count=0; miao=0; while(l)(if(miao=0)(P2=0xFE;P0=Tab2;delay(l);)(中间需补齐)if(miao=9)(P2=0x7F;P0=Tab5;delay
2、(l);P2=0xBF;P0=Tab3;delay(l);P2=0xDF;P0=Tab2;delay(l);P2=0xEF;P0=Tab0;delay(l);P2=0xF7;P0=Tab0;delay(l);P2=0xFB;P0=Tab3;delay(l);P2=0xFD;P0=Tab0;delay(l);P2=0xFE;P0=Tab9;delay(l);换行换行void Time0(void) interrupt 1(TH0=(65536-1000)/256;TL0=(65536-1000)%256;count+;if(count=1000)(count=0;miao+;)if(miao=1
3、0)(miao=0;)#include实验二(按键控制数码管输出值)char Tab=09 码值;sbit feng=PlAO;unsigned char flag=O;void time(unsigned int i) while(i-);void main(void) char i;while(l) P2=0xFE;if(P3=07F) PO=Tabl;flag=O;)else if(P3=0BF)P0=Tab2;flag=l;)if(P3=0DF)P0=Tab3;flag=0;)if(P3=0EF) P0=Tab4;flag=l;)if(P3=0xF7)(P0=Tab5;flag=0;)
4、if(P3=0xFB)(P0=Tab6;flag=l;)jf(P3=0xFD)(P0=Tab7;flag=0;)if(P3=0FE)(P0=Tab8;flag=l;)if(fag=l)(feng=l;time(50);feng=O;time(50);)实验四(通过光敏传感器控制LED灯与蜂鸣器)#includesbit P20=P2A0;sbit P21=P2A1;sbit P22=P2A2;void main(void)(TH0=(65536-1000)/256;TL0=(65536-1000)%256;EA=1;ETO=1;TRO=1;while(l)(if(P20=0)(TRO=O;el
5、seTRO=1;)void Time0(void) interrupt 1(TH0=(65536-1000)/256;TL0=(65536-1000)%256;P21=-P21;P22=P22;)实验三串口连接#include03Fz0x06,0x5B,04Fz0x66,0x6D,0x7D,007,0x7F,0x6FUnsigned char Tab=09 码值;sbit feng=P2AO;void main(void)char i;SCON = 0x50;TMOD = 0x21;TH0=(65536-1000)/256;TL0=(65536-1000)%256;THl=0xE6;TLl=0xE6;TR1=1;while(l)(while(RI)(i=SBUF;Pl=Tabi;RI=0;if(i%2=0)(EA=1;ETO=1;TRO=1;)else(EA=O;ETO=O;TRO=O;)void Time0(void) interrupt 1TH0=(65536-1000)/256;TL0=(65536-1000)%256;feng=feng;