求高手解答基于51单片机的LED4片16*16点阵显示的程序和电路图

2025-01-07 08:23:30
推荐回答(2个)
回答1:

#include 

#define uchar unsigned char

uchar i,j,k=15;

sbit  xsi=P2^0;            //X轴数据线

sbit  xrck=P2^1;          //X轴锁存线

sbit  xsck=P2^2;         //X轴时钟线

sbit  ysi=P2^3;            //Y轴数据线

sbit  yrck=P2^4;         //Y轴锁存线

sbit  ysck=P2^5;         //Y轴时钟线

sbit kg= P3^2;

uchar code zbm[][32]={

{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,

0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,},

{0xFF,0xFF,0xFF,0xF7,0xBF,0xF7,0xBF,0xFB,0xBF,0xFD,0x03,0xE0,0xFF,0xFF,0xFF,0xFF,

0x01,0xF0,0x7F,0xEF,0xBF,0xEF,0x9F,0xEF,0xDF,0xEF,0xFF,0xF1,0xFF,0xFF,0xFF,0xFF},/*"北",0*/

{0xF7,0xFF,0xF7,0xFF,0xF7,0xEF,0xF7,0xF3,0x37,0xFF,0xB7,0xFE,0xB6,0xDE,0xD5,0x80,

0xDB,0xFE,0x5B,0xFF,0x9B,0xFB,0xFB,0xF7,0xFB,0xE7,0xFB,0xFF,0xFF,0xFF,0xFF,0xFF},/*"京",1*/

{0xFF,0xEF,0x5F,0xF7,0xDF,0xFA,0xEF,0xFD,0x0F,0xFA,0xFF,0xDF,0xBF,0xEF,0xC7,0xF3,

0x58,0xFC,0xEF,0xFB,0xAF,0xF7,0xCF,0xEF,0xEF,0xCF,0xFF,0xDF,0xFF,0xDF,0xFF,0xFF},/*"欢",2*/

{0xBF,0xF7,0xBF,0xF7,0xBB,0xF6,0x37,0xF1,0xFF,0xF7,0x07,0xF6,0xF7,0xF6,0x7B,0xF7,

0xF9,0xEF,0x0F,0xE8,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xBB,0xFD,0xBF,0xFD,0xFF,0xFD,0xFF,0xFD,0xFF,0xFF},/*"阵",4*/

{0xFF,0xEF,0xFF,0xF7,0xFF,0xF9,0x7F,0xFE,0x81,0xBD,0x75,0xDD,0x65,0xE5,0x55,0xF8},

{0xB6,0xFD,0x9A,0xFD,0x28,0x80,0xBC,0xFE,0xBF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFF},/*"屏",5*/

{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},

{0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,},

};

void ys (uchar a)       //延时

{

 uchar b;

 for (;a>0;a--)

 for (b=100;b>0;b--) ;

}

void yfs()       //Y轴发数

{

 ysck=0;

 yrck=0;

 k++;

 if (k==16)

  {

  k=0;

  ysi=0;

  }

  else

 ysi=1;

 ysck=1;

 P2=P2|0X12;            //把数据锁存    

}

void xfs(uchar a)        //X轴发数

{

 uchar b,a1,a2;

 a1=~zbm[6][a*2+1];

 a2=~zbm[6][a*2];

 xsck=0;

 xrck=0;

 for (b=0;b<8;b++)

 {

  a1=a1<<1; 

  xsi=CY;

  xsck=1;

  xsck=0;  

 }

  for (b=0;b<8;b++)

 {

  a2=a2<<1; 

  xsi=CY;

  xsck=1;

  xsck=0;  

 }

}  

void  fs(uchar a)          //X轴发数

{

 uchar b;

 xsck=0;

 xrck=0;

 for (b=0;b<8;b++)

 {

  a=a<<1; 

  xsi=CY;

  xsck=1;

  xsck=0;  

 }

}

void gdhs(uchar *zz,uchar N,uchar Time) //流动显示N个汉字     滚动函数

{ //参数三个:字符串字模首地址、字数、显示流动速度 

uchar FontNum,i,j,row; //循环变量,字数计数、16次流动、16列扫描 

for(FontNum=0;FontNum

 { 

  for(i=0;i<16;i++) //字到字流动 16次左移才能完成 

  { 

   for(j=0;j

    { 

     k=15;

     for(row=0;row<16;row++) //显示16*16屏幕一次 

      { 

       yfs(); //选通显示列     //行选线,P3 低四位 

       fs (~*(zz+FontNum*32+(i+row)*2+1)); //以移动偏移为基础获取新数据  

       fs(~*(zz+FontNum*32+(i+row)*2)); //获取显示数据 循环显示关键算法 

       ys (12); //适当延时 

      } 

    } 

  } 

 } 

}

void wbzd ()  interrupt   0       //外部中断

{

   j++;

   if (j>1)

   j=0;

   ys(10);

   while (!kg)

   {

     k=15;

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

     {

      yfs();

      xfs(i);

    ys(10);

      }

   }

  if (j==0)

     gdhs(zbm,8,2);

  if (j==1)

   gdhs(zbm1,10,1);

}

void main ()

{

 EA = 1; //打开总中断 

 EX0=1;

 IT0=1;

 while (1)

 {

     if (j==0)

    gdhs(zbm,8,3);

   if (j==1)

      gdhs(zbm1,10,3);

 }

}

回答2:

用74LS595吧,基本大同小异,懂得原理就觉得简单了,我有Proteus仿真电路图