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

📄 yaonew.c

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

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

typedef unsigned char uchar;
typedef unsigned int uint;

bit left_flag;

code char pattern[17][3]={    //3幅图片的字模
{0xff,0xff,0xff}, //在长沙的时候教过你怎么算,所以我就不多说了
{0xff,0xff,0xff},
{0xff,0xff,0xff},
{0xff,0xf9,0xff},
{0xff,0xf6,0x9f},
{0xff,0xee,0xa6},
{0xfe,0xdd,0x78},
{0x7e,0xbb,0x7f},
{0x00,0x77,0x7f},
{0x7e,0xbb,0x7f},
{0xfe,0xdd,0x78},
{0xff,0xee,0xa6},
{0xff,0xf6,0x9f},
{0xff,0xf9,0xff},
{0xff,0xff,0xff},
{0xff,0xff,0xff},
{0xff,0xff,0xff},
};
uchar phase,th1,tl1,index,count;

main()
{
    EA=0;     //中断总使能,高电平有效,他为高时,各中断自行使能,他为低,中断无效
    EX1=1;    //外部中断1使能,高电平有效
    ET1=1;    //内部时钟中断1使能,高有效
    ET0=1;
    EX0=1;
    PX0=1;    //外部中断优先级别设置
    IT1=1;    //外部中段1工作模式选择,为1是下降沿为中断信号,0时低电平为中断信号
    IT0=1;
    //TR1=1;
    //TR0=1;
    TMOD=0x11;
    index=0;
    EA=1;     
    while(1)
    {
    }
}

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

void Int1_Handle(void) interrupt 2 using 2
{
  /* uint tr_time;
    left_flag=0;
    TR1=0;
        tr_time=TH0<<8|TL0;
    TL0=0;
    TH0=0;
    TR0=1;
    tr_time=65535-tr_time/SEG;
    th1=tr_time/256;
    TH1=th1;
    tl1=tr_time % 256;
    TL1=tl1;      */
   /* if (count<3*INTERVAL){        //3幅图片循环
        count++;
    } 
    else{
        count=0;
    }  */
    index=1;//count/INTERVAL;
   /* if (th1!=0xff || tl1!=0xff)
    {   
        phase=17;
        TR1=1;
    }
    else{
        TR1=0;
    }  */
}
void timer0() interrupt 1 using 3
{
 //P0=~P0;
}


void Timer1(void) interrupt 3 using 3
{
    if (phase<SEG)            //17段依次显示
    {
        //P0=pattern[phase][index];
        P2=pattern[phase][index];
       // if(left_flag)
                     phase++;
                     if(phase>10)
                                 phase=0;
        //else
          //  phase--;
        //TH1=th1;
        //TL1=tl1;
    }
}


⌨️ 快捷键说明

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