⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 yaoeasy01.c

📁 基于8051单片机的摇棒系统
💻 C
字号:

/******************************/
//        ---------------
//          LED显示摇棒
//        ---------------
/******************************/
#include <reg51.h>
#define SEG 17        //每幅图片分成17列来显示
#define INTERVAL 20    //每幅图片在左右摇摆20
//次后换下一幅

typedef unsigned char uchar;
typedef unsigned int uint;

code char zikup0[17][3]={    
{0x00,0x00,0x00,},
{0x00,0x00,0x08,}, 
{0x00,0x04,0x08,},
{0xf8,0xf4,0xc8,},
{0x08,0x14,0xff,},
{0x08,0x14,0xc8,},
{0x08,0x54,0x08,},
{0x08,0x94,0x08,},
{0xff,0x1f,0x00,},
{0x08,0x94,0x08,},
{0x08,0x54,0x08,},
{0x08,0x14,0xc8,},
{0x08,0x14,0xff,},
{0xf8,0xf4,0xc8,},
{0x00,0x04,0x08,},
{0x00,0x00,0x08,},
{0x00,0x00,0x00,},
};

code char zikup2[17][3]={
{0x00,0x00,0x00},
{0x00,0x00,0x04},
{0x00,0x00,0x03},
{0x01,0x7f,0x00},
{0x01,0x00,0x7f},
{0x01,0x05,0x00},
{0x01,0x05,0x01},
{0x01,0x05,0x02},
{0x7f,0x3f,0x00},
{0x01,0x05,0x02},
{0x01,0x05,0x01},
{0x01,0x05,0x00},
{0x01,0x00,0x7f},
{0x01,0x7f,0x00},
{0x00,0x00,0x03},
{0x00,0x00,0x04},
{0x00,0x00,0x00},
};
uchar phase,th1,tl1,index,count;


main()
{
    EA=0;     
    EX1=1;   
    ET1=1;  
    PX0=1;   
    IT1=1;    
    TMOD=0x11;
    index=0;
    EA=1;     
    while(1)
    {
    }
}

void Int0_Handle(void) interrupt 2 using 2
{
    uint t0_time;
    TR0=0;
    TR1=0;
    TF1=0;
        t0_time=TH0<<8|TL0;
    TL0=0;
    TH0=0;
    TR0=1;
    t0_time=65535-t0_time/SEG;
    th1=t0_time/256;
    TH1=th1;
    tl1=t0_time % 256;
    TL1=tl1;
    if (count<3*INTERVAL){   
        count++;
    }
    else{
        count=0;
    }
    index=count/INTERVAL;
    if (th1!=0xff || tl1!=0xff){    
        phase=0;
        TR1=1;
    }
    else{
        TR1=0;
    }
}

void Timer1(void) interrupt 3 using 3
{
 uchar p2temp,p2temp2,p2temp3,i;
 p2temp=zikup2[phase][index];
 p2temp2=0;
 for(i=8;i>0;i--)
 {
  p2temp3=p2temp&1;
  p2temp=p2temp>>1;
  p2temp3=p2temp3<<i-1;
  p2temp2=p2temp2|p2temp3;
 }
    if (phase<SEG)            //17段依次显示
    {
        P0=~zikup0[phase][index];
        P2=~p2temp2;
        phase++;
        TH1=th1;
        TL1=tl1;
    }
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -