找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4793|回复: 1
收起左侧

电机转同时点阵显示

[复制链接]
ID:81203 发表于 2015-5-26 19:16 | 显示全部楼层 |阅读模式
/*********************************************************

            电机转同时点阵显示
********************************************************/
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit da  =P2^7;
sbit shcp=P2^5;
sbit stcp=P2^6;
uint led_array_count,anode_next;
bit motor_flag=0,led_array_flag;
uchar anode,negative;
uchar a,b;
////////////////////////////////////////////
void delays(uchar ms)
{
        uint a;
        while(ms--)  for(a=0;a<100;a++);
}
////////////////////////////////////////初始化定时器
void initial_timer0()
{
          TMOD=0X02;         
          TH0=0x38;      //100us
          TL0=0x38;
          TR0=1;
          EA=1;
          ET0=1;
}
///////////////////////////////////////////////////////////////////////
uchar code motor_run[]={0x08,0x0c,0x04,0x06,0x02,0x03,0x01,0x09};              //最高频率250us
/////////////////////////////////////////////////////////////////////
uchar code led_array_anode[]={ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
                                     0xC1,0x01,0x00,0x00,0x00,0x00,0x80,0x83,
                               0x60,0x01,0x01,0x00,0x00,0x80,0x80,0x06,
                                     0x30,0x00,0x01,0x01,0x80,0x80,0x00,0x0C,
                                     0x18,0x00,0x00,0x81,0x81,0x00,0x00,0x18,
                                     0x0C,0x00,0x80,0x80,0x01,0x01,0x00,0x30,
                                     0x06,0x80,0x80,0x00,0x01,0x01,0x01,0x60,
                                     0x83,0x80,0x00,0x00,0x00,0x00,0x01,0xC1,
                                     0xE1,0x01,0x01,0x00,0x00,0x80,0x80,0x87,
                                     0x62,0xC3,0x01,0x00,0x00,0x80,0xC3,0x46,
                                     0x30,0x62,0x03,0x01,0x80,0xC0,0x46,0x0C,
                                     0x08,0x14,0x22,0x41,0x82,0x44,0x28,0x10,
                               0x00,0x08,0x14,0x22,0x44,0x28,0x10,0x00,
                                     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,
                                     0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,
                                     0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xE0,  //16
                                     0x00,0x00,0x00,0x00,0x80,0xC0,0xE0,0xF0,
                               0x00,0x00,0x00,0x80,0xC0,0xE0,0xF0,0xF8,
                                     0x00,0x00,0x80,0xC0,0xE0,0xF0,0xF8,0xFC,
                                     0x00,0x80,0xC0,0xE0,0xF0,0xF8,0xFC,0xFE,
                                     0x80,0xC0,0xE0,0xF0,0xF8,0xFC,0xFE,0xFF,
                                     0xC0,0xE0,0xF0,0xF8,0xFC,0xFE,0xFF,0xFF,
                                  0xE0,0xF0,0xF8,0xFC,0xFE,0xFF,0xFF,0xFF,
                                  0xF0,0xF8,0xFC,0xFE,0xFF,0xFF,0xFF,0xFF,
                                 0xF8,0xFC,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,
                                0xFC,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
                                 0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
                                0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
                               0x00,0x7E,0x7E,0x7E,0x7E,0x7E,0x7E,0x00,
                                0x00,0x00,0x3C,0x3C,0x3C,0x3C,0x00,0x00,
                               0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,   //31
                              };
///////////////////////////////////////////////////////////////////
uchar led_array_negative[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};          //负极
//////////////////////////////////////                                         //595送数据
void input595(uchar dat)
{
        uchar b;
        shcp=0;
        for(b=0;b<8;b++)
          {
                        da=dat&0x80;
                        dat=dat<<1;
                        shcp=1;
                        shcp=0;
    }
}
////////////////////////////////////                                          //595输出数据
void output595()
{
        stcp=0;
        stcp=1;
}
//////////////////////////////////////////////////////////////////
void motor_foreward()
{
        uint motor_time;
                        if(!led_array_flag)
                 {
                         motor_time++;
                         if(motor_time==5)
                         {
                                 motor_time=0;
                                                P3=motor_run[a];
                                                a++;
                                                if(a>=8)
                                                 {
                                                         a=0;
                                                 }
                                }
                        }
}
//////////////////////////////////////////////////////////////////////
void refresh_led_array()                                                     //刷新点阵
{
  if(!led_array_flag)
        {
                anode_next++;
                if(anode_next==100)   //1s
                {
                        anode_next=0;
                        anode=anode+8;
                        if(anode>240)
                        {
                                anode=0;
      }
    }
                 for(negative=0;negative<8;negative++)
                         {
                                 input595(led_array_anode[anode+negative]);
                                 input595(led_array_negative[negative]);
                                 output595();
                         }
         }                         
}
///////////////////////////////////////
void main()
{
        initial_timer0();
//        initial_timer1();
        while(1)
        {
                refresh_led_array();
                motor_foreward();
  }
}
/////////////////////////////////////
void timer0_interrupt()interrupt 1
{
    led_array_count++;
         if(led_array_count==10)   //1ms
        {
                led_array_count=0;
                !led_array_flag;
        }
}


回复

使用道具 举报

ID:896220 发表于 2021-3-24 21:39 来自手机 | 显示全部楼层
我想问一下 这能显示88的  还是1616的
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表