TXT

chengxu

By Darrell Carpenter,2014-03-30 08:45
13 views 0
chengxu

单片机流水灯C程序20090618 星期四 下午 08:16#include <absacc.h> //

    包含头文件

    #include <reg51.h> //包含头文件

    /***************************数据类型定义***************************/

    #define uchar unsigned char //数据类型定义

    #define A for(i=max;i>min;i--)

    #define B for(i=min;i<max;i++)

    #define SA P0=a[i]

    #define SB P2=b[i]

void delay(uchar k)

    {

    int j;

    while(k--)

    for(j=0;j<200;j++);

    }

void main()

    {

    char i=0,j=0;

    char max=7,min=0;

    uchar k1=20,k2=10,k3=4;

    uchar a[8]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe}; uchar b[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};

    uchar a1[8]={0x00,0x7e,0x7e,0x7e,0x7e,0x7e,0x7e,0x00}; uchar a2[8]={0xff,0x81,0xbd,0xbd,0xbd,0xbd,0x81,0xff}; uchar a3[8]={0xff,0xff,0xc3,0xdb,0xdb,0xc3,0xff,0xff}; uchar a4[8]={0xff,0xff,0xff,0xe7,0xe7,0xff,0xff,0xff}; uchar b1[8]={0x81,0x42,0x24,0x18,0x18,0x24,0x42,0x81};

    //--------------------------------modle four start for(j=1;j<5;j++)

    {

    i=j-1;

    switch(j)

     {case 1:P2=~a1[i];P0=a1[i];break;

     case 2:P2=~a2[i];P0=a2[i];break;

     case 3:P2=~a3[i];P0=a3[i];break;

     case 4:P2=~a4[i];P0=a4[i];break;

     default: break;

     }

delay(100);

    P0=0xff;

    P2=0x00; //---------------clear

}

    delay(100);

    //--------------------------------modle four end

//--------------------------------modle one start

    P0=a[7];

    P2=b[0];

    while(k3--)

    {

     B{SB;delay(k1);}

     SB;

     A{SA;delay(k1);}

     SA;

     A{SB;delay(k1);}

     SB;

     B{SA;delay(k1);}

     SA;

     max--;

     min++;

    P0=a[max];

    }

    //--------------------------------modle one end

//--------------------------------modle two start

    {

    for(j=1;j<5;j++)

     {

     for(k3=10;k3>0;k3--)

     for(i=0;i<4;i++)

     {

     P2=b1[i];

     switch(j)

     {case 4:P0=a1[i];break;

     case 3:P0=a2[i];break;

     case 2:P0=a3[i];break;

     case 1:P0=a4[i];break;

     default: break;

     }

     delay(1);

     P0=0xff; //---------------clear

     }

     delay(k2);

    }

    }

    //--------------------------------modle two end

//--------------------------------modle three start

    {

    for(j=1;j<5;j++)

     {

     for(k3=10;k3>0;k3--)

     for(i=0;i<4;i++)

     {

     P2=b1[i];

     switch(j)

     {case 1:P0=a1[i];break;

     case 2:P0=a2[i];break;

     case 3:P0=a3[i];break;

     case 4:P0=a4[i];break;

     default: break;

     }

     delay(1);

     P0=0xff; //---------------clear

     }

     delay(k2);

    }

    }

    //--------------------------------modle three end

}

Report this document

For any questions or suggestions please email
cust-service@docsford.com