kwjy

自学MCU-51之 8X8 LED 点阵屏静态显示

0
阅读(2112)

好久没来更新了,之前写的LED点阵代码一直有错误,没时间来改写,今晚终于搞定了,由于疏忽将行列独立分开导致错误,原理很简单,送一侦行数据数据,导通一列LED;循环8次正好一组数据;不多说了上代码;还有就是群主的书里内容讲解的很详细,快要胜过视屏讲解了,呵呵,好书就得有好的推荐方式才对、、、、、、




#include <reg52.h>
#include <intrins.h>

typedef signed char   Int8;
typedef unsigned char Uint8;
typedef signed int  Int16;
//typedef unsigned int  Uint16;
#define delay_5US()  _nop_(); _nop_(); _nop_(); _nop_(); _nop_();
#define Lend P0

Uint8 code zimo[] = {//0x80,0x42,0x24,0x18,0x18,0x24,0x42,0x80
//0x0C,0x12,0x22,0x44,0x44,0x22,0x12,0x0C
0x0C,0x1E,0x3E,0x7C,0x7C,0x3E,0x1E,0x0C
};

sbit sDat = P1^0;
sbit sClk = P1^2;
sbit sRck = P1^1;
sbit WELA = P1^6;
sbit DULA = P1^7;

void Init();
void Write_595_Byte(Int8 byte);
void LED_scmao();

void main()
{
Init();

while(1);

}

void Init()
{
TMOD = 0x01;
TH0 = 0xfc;
TL0 = 0x66;
EA = 1;
ET0 = 1;
TR0 = 1;
DULA = 1;
Lend = 0;
DULA = 0;
WELA = 1;
Lend = 0xff;
WELA = 0;
// sDat = 0;
// sClk = 0;
// sRck = 0;
// Lend = 0xff;
// Write_595_Byte(0);
}

void Write_595_Byte(Int8 byte)
{
Int8 i = 0;
sClk = 1;
sRck = 1;
    for(i = 0;i < 8;i++)
    {
     sClk = 0;
    delay_5US();
    if(byte & 0x80)
    sDat = 1;
    else
    sDat = 0;

    sClk = 1;
    delay_5US();
    byte <<= 1;
    }
    sRck = 0;
    delay_5US();
    sRck = 1;
}

void LED_scmao()
{
      static Int8 x = 0;

    switch(x)
   {
    case 0: Lend = 0xff;Write_595_Byte(zimo[x]);Lend = 0xfe; x++; break;
   case 1: Lend = 0xff;Write_595_Byte(zimo[x]);Lend = 0xfd; x++; break;
   case 2: Lend = 0xff;Write_595_Byte(zimo[x]);Lend = 0xfb; x++; break;
   case 3: Lend = 0xff;Write_595_Byte(zimo[x]);Lend = 0xf7; x++; break;
   case 4: Lend = 0xff;Write_595_Byte(zimo[x]);Lend = 0xef; x++; break;
   case 5: Lend = 0xff;Write_595_Byte(zimo[x]);Lend = 0xdf; x++; break;
   case 6: Lend = 0xff;Write_595_Byte(zimo[x]);Lend = 0xbf; x++; break;
   case 7: Lend = 0xff;Write_595_Byte(zimo[x]);Lend = 0x7f; x = 0; break;
   default:break;
  }
}

void Time0() interrupt 1
{
   static Int8 m = 0;

   TH0 = 0xfc;
   TL0 = 0x66;
   m++;

   if(m == 2)
   {
    m = 0;
    LED_scmao();
   }
}

上图:







下节点阵动态显示。。。。。。。。。