您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 经营企划 > 单片机与串口连接构成猜数字小游戏
单片机与串口连接构成猜数字小游戏仿真图:程序:#includeREGX51.H#includestdlib.hunsignedcharled[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};unsignedchark;voiddelay0_5s(){unsignedchari;for(i=0;i0x0a;i++){TH0=0X3C;TL0=0XB0;TR0=1;while(!TF0);TF0=0;}}voiddelay_t(unsignedchart){unsignedchari;for(i=0;it;i++)delay0_5s();}voidmain(){unsignedchari,j;SCON=0X50;PCON=0X00;TMOD=0X20;TH1=0XFD;TL1=0XFD;TR1=1;EA=1;ES=1;while(1){P2=0x07;P0=1+rand()%100;j=P0;for(i=0;i=7;i++){if(j0x80){k++;j=1;}elsej=1;}delay_t(100);}}voidserial()interrupt4{unsignedcharj;EA=0;if(RI==1){RI=0;if(SBUF==k){SBUF=k;while(!TI);TI=0;j=P0;P1=0x00;while(SBUF!=0x02){while(!RI);RI=0;}SBUF=0x02;while(!TI);TI=0;P0=j;EA=1;}else{EA=1;}}}
本文标题:单片机与串口连接构成猜数字小游戏
链接地址:https://www.777doc.com/doc-6197978 .html