f3050c23ac53a106
获得 0 次赞
帮助过0人
#include<reg52.h>sbit a=P0^0;sbit b=P0^1;sbit c=P0^2;sbit OE0=P0^3;sbit OE1=P0^4;sbit OE2=P0^5;sbit KEY1=P3^2;sbit KEY2=P3^3;sbit KEY3=P3^4;sbit KEY4=P3^5;unsigned char code LedChar[7][8]={{0xC30x810x000x000x000x810xFF0xFF}{0xFF0x810x000x000x000x810xFF0xFF}{0xFF0xFF0x000x000x000xFF0xFF0xFF}{0xFF0xFF0xFF0x000xFF0xFF0xFF0xFF} //不按按键时{0xEF0xDF0xBF0x000xBF0xDF0xEF0xFF} //左转{0xF70xFB0xFD0x000xFD0xFB0xF70xFF} //右转{0xFF0xFF0xFF0xFF0xFF0xFF0x660x99} //W }; unsigned char LedBuff[16]={0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF};void buan(); //不按按键函数void ting(); //刹车时函数void you(); //左转时函数void zuo(); //右转时函数void main(){TMOD=0x01;TH0=0xFC;TL0=0x67;EA=1;ET0=1;TR0=1;while(1){ if(KEY1==0) { zuo(); } else if(KEY2==0) { you(); } else { buan(); }}}/@@*中断函数*/void zhongduan() interrupt 1 //用于显示刷新{ static unsigned char i=0;TH0=0xFC;TL0=0x67;P1=0xFF;switch(i){ case 0:a=0;b=0;c=0;OE0=0;OE1=1;OE2=1;i++;P1=LedBuff[0];break; case 1:a=0;b=0;c=1;OE0=0;OE1=1;OE2=1;i++;P1=LedBuff[1];break; case 2:a=0;b=1;c=0;OE0=0;OE1=1;OE2=1;i++;P1=LedBuff[2];break; case 3:a=0;b=1;c=1;OE0=0;OE1=1;OE2=1;i++;P1=LedBuff[3];break; case 4:a=1;b=0;c=0;OE0=0;OE1=1;OE2=1;i++;P1=LedBuff[4];break; case 5:a=1;b=0;c=1;OE0=0;OE1=1;OE2=1;i++;P1=LedBuff[5];break; case 6:a=1;b=1;c=0;OE0=0;OE1=1;OE2=1;i++;P1=LedBuff[6];break; case 7:a=1;b=1;c=1;OE0=0;OE1=1;OE2=1;i++;P1=LedBuff[7];break; case 8:a=0;b=0;c=0;OE0=1;OE1=0;OE2=1;i++;P1=LedBuff[8];break; case 9:a=0;b=0;c=1;OE0=1;OE1=0;OE2=1;i++;P1=LedBuff[9];break; case 10:a=0;b=1;c=0;OE0=1;OE1=0;OE2=1;i++;P1=LedBuff[10];break; case 11:a=0;b=1;c=1;OE0=1;OE1=0;OE2=1;i++;P1=LedBuff[11];break; case 12:a=1;b=0;c=0;OE0=1;OE1=0;OE2=1;i++;P1=LedBuff[12];break; case 13:a=1;b=0;c=1;OE0=1;OE1=0;OE2=1;i++;P1=LedBuff[13];break; case 14:a=1;b=1;c=0;OE0=1;OE1=0;OE2=1;i++;P1=LedBuff[14];break; case 15:a=1;b=1;c=1;OE0=1;OE1=0;OE2=1;i=0;P1=LedBuff[15];break; default:break;}}/@@*左转*/void zuo(){LedBuff[0]=LedChar[4][0];LedBuff[1]=LedChar[4][1];LedBuff[2]=LedChar[4][2];LedBuff[3]=LedChar[4][3];LedBuff[4]=LedChar[4][4];LedBuff[5]=LedChar[4][5];LedBuff[6]=LedChar[4][6];LedBuff[7]=LedChar[4][7];LedBuff[8]=LedChar[6][0];LedBuff[9]=LedChar[6][1];LedBuff[10]=LedChar[6][2];LedBuff[11]=LedChar[6][3];LedBuff[12]=LedChar[6][4];LedBuff[13]=LedChar[6][5];LedBuff[14]=LedChar[6][6];LedBuff[15]=LedChar[6][7];}/@@*右转*/void you(){LedBuff[0]=LedChar[5][0];LedBuff[1]=LedChar[5][1];LedBuff[2]=LedChar[5][2];LedBuff[3]=LedChar[5][3];LedBuff[4]=LedChar[5][4];LedBuff[5]=LedChar[5][5];LedBuff[6]=LedChar[5][6];LedBuff[7]=LedChar[5][7];LedBuff[8]=LedChar[6][0];LedBuff[9]=LedChar[6][1];LedBuff[10]=LedChar[6][2];LedBuff[11]=LedChar[6][3];LedBuff[12]=LedChar[6][4];LedBuff[13]=LedChar[6][5];LedBuff[14]=LedChar[6][6];LedBuff[15]=LedChar[6][7];}/@@*不按按键*/void buan(){static unsigned char cnt=0;static unsigned int jisu=0;static unsigned char f=0;LedBuff[0]=LedChar[cnt][0];LedBuff[1]=LedChar[cnt][1];LedBuff[2]=LedChar[cnt][2];LedBuff[3]=LedChar[cnt][3];LedBuff[4]=LedChar[cnt][4];LedBuff[5]=LedChar[cnt][5];LedBuff[6]=LedChar[cnt][6];LedBuff[7]=LedChar[cnt][7];LedBuff[8]=LedChar[6][0];LedBuff[9]=LedChar[6][1];LedBuff[10]=LedChar[6][2];LedBuff[11]=LedChar[6][3];LedBuff[12]=LedChar[6][4];LedBuff[13]=LedChar[6][5];LedBuff[14]=LedChar[6][6];LedBuff[15]=LedChar[6][7];for(f=0;f>50;f++);jisu++;if(jisu>=400){ jisu=0; cnt++; if(cnt>=4) { cnt=0; }}}芯片用的是74hc138