|
#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]={
{0xC3,0x81,0x00,0x00,0x00,0x81,0xFF,0xFF},
{0xFF,0x81,0x00,0x00,0x00,0x81,0xFF,0xFF},
{0xFF,0xFF,0x00,0x00,0x00,0xFF,0xFF,0xFF},
{0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF}, //不按按鍵時(shí)
{0xEF,0xDF,0xBF,0x00,0xBF,0xDF,0xEF,0xFF}, //左轉(zhuǎn)
{0xF7,0xFB,0xFD,0x00,0xFD,0xFB,0xF7,0xFF}, //右轉(zhuǎn)
{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x66,0x99}, //W
};
void buan(); //不按按鍵函數(shù)
void ting(); //剎車時(shí)函數(shù)
void you(); //左轉(zhuǎn)時(shí)函數(shù)
void zuo(); //右轉(zhuǎn)時(shí)函數(shù)
void main()
{
while(1)
{
if(KEY1==0)
{
you();
}
else if(KEY2==0)
{
zuo();
}
else
{
buan();
}
}
}
/*不按按鍵*/
void buan()
{
static unsigned char cnt1=0;
static unsigned char d=0;
static unsigned int tmr=0;
static unsigned char i=0;
P1=0xFF;
switch(i)
{
case 0:a=0;b=0;c=0;OE0=0;OE1=1;OE2=1;i++;P1=LedChar[cnt1][0];break;
case 1:a=0;b=0;c=1;OE0=0;OE1=1;OE2=1;i++;P1=LedChar[cnt1][1];break;
case 2:a=0;b=1;c=0;OE0=0;OE1=1;OE2=1;i++;P1=LedChar[cnt1][2];break;
case 3:a=0;b=1;c=1;OE0=0;OE1=1;OE2=1;i++;P1=LedChar[cnt1][3];break;
case 4:a=1;b=0;c=0;OE0=0;OE1=1;OE2=1;i++;P1=LedChar[cnt1][4];break;
case 5:a=1;b=0;c=1;OE0=0;OE1=1;OE2=1;i++;P1=LedChar[cnt1][5];break;
case 6:a=1;b=1;c=0;OE0=0;OE1=1;OE2=1;i++;P1=LedChar[cnt1][6];break;
case 7:a=1;b=1;c=1;OE0=0;OE1=1;OE2=1;i++;P1=LedChar[cnt1][7];break;
case 8:a=0;b=0;c=0;OE0=1;OE1=0;OE2=1;i++;P1=LedChar[6][0];break;
case 9:a=0;b=0;c=1;OE0=1;OE1=0;OE2=1;i++;P1=LedChar[6][1];break;
case 10:a=0;b=1;c=0;OE0=1;OE1=0;OE2=1;i++;P1=LedChar[6][2];break;
case 11:a=0;b=1;c=1;OE0=1;OE1=0;OE2=1;i++;P1=LedChar[6][3];break;
case 12:a=1;b=0;c=0;OE0=1;OE1=0;OE2=1;i++;P1=LedChar[6][4];break;
case 13:a=1;b=0;c=1;OE0=1;OE1=0;OE2=1;i++;P1=LedChar[6][5];break;
case 14:a=1;b=1;c=0;OE0=1;OE1=0;OE2=1;i++;P1=LedChar[6][6];break;
case 15:a=1;b=1;c=1;OE0=1;OE1=0;OE2=1;i++;P1=LedChar[6][7];break;
case 16:a=0;b=0;c=0;OE0=1;OE1=1;OE2=1;i++;P1=LedChar[cnt1][0];break;
case 17:a=0;b=0;c=1;OE0=1;OE1=1;OE2=0;i++;P1=LedChar[cnt1][1];break;
case 18:a=0;b=1;c=0;OE0=1;OE1=1;OE2=0;i++;P1=LedChar[cnt1][2];break;
case 19:a=0;b=1;c=1;OE0=1;OE1=1;OE2=0;i++;P1=LedChar[cnt1][3];break;
case 20:a=1;b=0;c=0;OE0=1;OE1=1;OE2=0;i++;P1=LedChar[cnt1][4];break;
case 21:a=1;b=0;c=1;OE0=1;OE1=1;OE2=0;i++;P1=LedChar[cnt1][5];break;
case 22:a=1;b=1;c=0;OE0=1;OE1=1;OE2=0;i++;P1=LedChar[cnt1][6];break;
case 23:a=1;b=1;c=1;OE0=1;OE1=1;OE2=0;i=0;P1=LedChar[cnt1][7];break;
default:break;
}
for(d=0;d>50;d++);
tmr++;
if(tmr>=500)
{
tmr=0;
cnt1++;
if(cnt1>=4)
{
cnt1=0;
}
}
}
/*右轉(zhuǎn)*/
void you()
{
static unsigned char i=0;
P1=0xFF;
switch(i)
{
case 0:a=0;b=0;c=0;OE0=0;OE1=1;OE2=1;i++;P1=LedChar[5][0];break;
case 1:a=0;b=0;c=1;OE0=0;OE1=1;OE2=1;i++;P1=LedChar[5][1];break;
case 2:a=0;b=1;c=0;OE0=0;OE1=1;OE2=1;i++;P1=LedChar[5][2];break;
case 3:a=0;b=1;c=1;OE0=0;OE1=1;OE2=1;i++;P1=LedChar[5][3];break;
case 4:a=1;b=0;c=0;OE0=0;OE1=1;OE2=1;i++;P1=LedChar[5][4];break;
case 5:a=1;b=0;c=1;OE0=0;OE1=1;OE2=1;i++;P1=LedChar[5][5];break;
case 6:a=1;b=1;c=0;OE0=0;OE1=1;OE2=1;i++;P1=LedChar[5][6];break;
case 7:a=1;b=1;c=1;OE0=0;OE1=1;OE2=1;i++;P1=LedChar[5][7];break;
case 8:a=0;b=0;c=0;OE0=1;OE1=0;OE2=1;i++;P1=LedChar[6][0];break;
case 9:a=0;b=0;c=1;OE0=1;OE1=0;OE2=1;i++;P1=LedChar[6][1];break;
case 10:a=0;b=1;c=0;OE0=1;OE1=0;OE2=1;i++;P1=LedChar[6][2];break;
case 11:a=0;b=1;c=1;OE0=1;OE1=0;OE2=1;i++;P1=LedChar[6][3];break;
case 12:a=1;b=0;c=0;OE0=1;OE1=0;OE2=1;i++;P1=LedChar[6][4];break;
case 13:a=1;b=0;c=1;OE0=1;OE1=0;OE2=1;i++;P1=LedChar[6][5];break;
case 14:a=1;b=1;c=0;OE0=1;OE1=0;OE2=1;i++;P1=LedChar[6][6];break;
case 15:a=1;b=1;c=1;OE0=1;OE1=0;OE2=1;i++;P1=LedChar[6][7];break;
case 16:a=0;b=0;c=0;OE0=1;OE1=1;OE2=1;i++;P1=LedChar[5][0];break;
case 17:a=0;b=0;c=1;OE0=1;OE1=1;OE2=0;i++;P1=LedChar[5][1];break;
case 18:a=0;b=1;c=0;OE0=1;OE1=1;OE2=0;i++;P1=LedChar[5][2];break;
case 19:a=0;b=1;c=1;OE0=1;OE1=1;OE2=0;i++;P1=LedChar[5][3];break;
case 20:a=1;b=0;c=0;OE0=1;OE1=1;OE2=0;i++;P1=LedChar[5][4];break;
case 21:a=1;b=0;c=1;OE0=1;OE1=1;OE2=0;i++;P1=LedChar[5][5];break;
case 22:a=1;b=1;c=0;OE0=1;OE1=1;OE2=0;i++;P1=LedChar[5][6];break;
case 23:a=1;b=1;c=1;OE0=1;OE1=1;OE2=0;i=0;P1=LedChar[5][7];break;
default:break;
}
}
芯片使用的是74h138
只寫了一部分
|
|