LED点阵字右移

2020-02-04 09:18发布

#include <reg52.h>
#include <intrins.h>
#define BLKN 2             //列锁存器数

char code reserv[3] _at_ 0x3b;

sbit G_74138 = P2^4;
sbit SDATA_595 = P2^5;
sbit SHCP_595 = P2^6;
sbit STCP_595 = P2^7;

unsigned char data disparam[32];
unsigned char temp;

unsigned char  code bmp[][32]=
{

{
0x10,0x08,0xF8,0x0B,0x10,0x08,0x10,0x10,0xFC,0x17,0x00,0x32,0x08,0x52,0xFC,0x93,
0x40,0x14,0x44,0x10,0xFE,0x1F,0x40,0x10,0xA0,0x10,0x90,0x10,0x0E,0x11,0x04,0x16
},

{
0x02,0x00,0x01,0x00,0x3F,0xFC,0x20,0x04,0x40,0x08,0x1F,0xE0,0x00,0x40,0x00,0x80,
0x01,0x04,0xFF,0xFE,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x05,0x00,0x02,0x00
},

{
0x02,0x00,0x04,0x00,0x08,0x04,0x7F,0xFE,0x40,0x04,0x40,0x24,0x4F,0xF4,0x48,0x24,
0x48,0x24,0x48,0x24,0x48,0x24,0x4F,0xE4,0x48,0x24,0x40,0x04,0x40,0x14,0x40,0x08
},


{
0x02,0x00,0x02,0x00,0x02,0x04,0xFF,0xFE,0x04,0x00,0x04,0x00,0x08,0x00,0x08,0x08,
0x1F,0xFC,0x28,0x08,0x48,0x08,0x88,0x08,0x08,0x08,0x08,0x08,0x0F,0xF8,0x08,0x08
},


{
0x08,0x40,0x1C,0x40,0xF0,0xFC,0x11,0x84,0x12,0x48,0xFC,0x30,0x10,0x60,0x39,0xA0,
0x34,0x3E,0x54,0x42,0x90,0xC4,0x11,0x24,0x10,0x18,0x10,0x30,0x10,0xC0,0x17,0x00
},


{
0x00,0x40,0x08,0x40,0x7C,0x40,0x00,0x44,0x05,0xFE,0xFE,0x44,0x10,0x44,0x10,0x44,
0x20,0x44,0x24,0x44,0x42,0x84,0xFE,0x84,0x41,0x04,0x01,0x04,0x02,0x28,0x04,0x10
},

{
0x02,0x00,0x01,0x00,0x7F,0xFE,0x48,0x02,0x86,0x84,0x02,0x80,0x10,0x80,0x0C,0x80,
0x04,0x84,0xFF,0xFE,0x01,0x00,0x01,0x40,0x02,0x20,0x04,0x10,0x18,0x0C,0x60,0x04
},

{
0x08,0x40,0xFC,0x40,0x08,0xA0,0x48,0xA0,0x49,0x10,0x4A,0x0E,0x4D,0xF4,0x48,0x00,
0x7C,0x48,0x06,0x48,0x05,0x48,0x1D,0x50,0xE5,0x10,0x44,0x24,0x17,0xFE,0x08,0x00
}

};

void delayms(unsigned int ms)
{
        unsigned char k;
        while(ms--)
        {
                for(k=0;k<114; k++);
        }
}


void writeData_595()
{
        unsigned char m;
        for(m=0; m<8; m++)
        {
                temp = temp<<1;
                SDATA_595 = CY;
       
                SHCP_595 = 1;
                _nop_();
                _nop_();
                SHCP_595 = 0;
        }
}


void right_shift()
{
        unsigned char i;

       
        for(i=0; i<16;  i++)
        {
                if(disparam[2*i] & 0x01 ==1)
                {
                        disparam[2*i] = (disparam[2*i] >>1)|0x80;
                                         disparam[2*i+1] = (disparam[2*i+1] >>1)|0x80;
                }
                else
                {
                           disparam[2*i] = (disparam[2*i] >>1)|0x80;
       
                          disparam[2*i+1] = ((disparam[2*i+1] >>1)|0x80)&0x7f;
                }

        }
}
  

void main()
{
        unsigned char i,k;
        SHCP_595 = 1;
        STCP_595 = 0;
        P2 = 0xf0;

        TMOD = 0x01;
        TH0 = 0xfc;
        TL0 = 0x66;

        IE = 0x82;
        TR0 = 1;

        while(1)
        {
                for(k=0; k<8; k++)
                {
                        for(i=0;i<32;i++)
                        {
                                disparam = ~bmp[k];
                        }
                       

                        delayms(1000);
                       
                        for(i=0; i<16; i++)
                        {
                                right_shift();
                                delayms(60);
                        }
       
                }

        }


}

  void leddisplay(void) interrupt 1
{
        unsigned row, j = BLKN;

        TH0 = 0xfc;
        TL0 = 0x66;

        row = P2;
        row = (++row)&0x0f;

        G_74138 = 1;
        temp = disparam[row*BLKN+1];
        writeData_595();
        temp = disparam[row*BLKN];
        writeData_595();

        P2 &= 0xf0;
        STCP_595 = 1;
        P2 |= row;
        STCP_595 = 0;
        G_74138 = 0;
}
各位能否详细解释下这个void right_shift()右移程序吗,谢谢
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
7条回答
yanxinboy
1楼-- · 2020-02-04 11:21
程序学习LA .
liaohaolin
2楼-- · 2020-02-04 12:37
LZ 你的QQ多少,我想问你点事情。
liaohaolin
3楼-- · 2020-02-04 16:48
 精彩回答 2  元偷偷看……
zk16
4楼-- · 2020-02-04 22:17
好像是伟纳的程序
wgm8023ln
5楼-- · 2020-02-04 23:14
学习下啊
yaohengyong1314
6楼-- · 2020-02-04 23:40
mark

一周热门 更多>