微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > MCU和单片机设计讨论 > 16*64点阵程序

16*64点阵程序

时间:10-02 整理:3721RD 点击:
   最近在家无聊,做了一个16*64的点阵,行扫描用的是154,列用的是595,效果还不错,把程序贴出来共享。
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define light 5     //定义亮度                  
/*****************************接口定义********************************/
sbit SHCP=P3^5;//595的移位信号         
sbit STCP=P3^3;//是595的锁存信号            
sbit SDA_R=P3^2;//数据   
sbit OE=P3^4;//输出使能
sbit ID=P2^3;//行控制线D      
sbit IC=P2^2;//行控制线C
sbit IB=P2^1;//行控制线B
sbit IA=P2^0;//行控制线A
/********************************************************************/

#define  scan0    {IA=0;IB=0;IC=0;ID=0;}
#define  scan1    {IA=1;IB=0;IC=0;ID=0;}
#define  scan2    {IA=0;IB=1;IC=0;ID=0;}
#define  scan3    {IA=1;IB=1;IC=0;ID=0;}
#define  scan4    {IA=0;IB=0;IC=1;ID=0;}
#define  scan5    {IA=1;IB=0;IC=1;ID=0;}
#define  scan6    {IA=0;IB=1;IC=1;ID=0;}
#define  scan7    {IA=1;IB=1;IC=1;ID=0;}
#define  scan8    {IA=0;IB=0;IC=0;ID=1;}
#define  scan9    {IA=1;IB=0;IC=0;ID=1;}
#define scan10    {IA=0;IB=1;IC=0;ID=1;}
#define scan11    {IA=1;IB=1;IC=0;ID=1;}
#define scan12    {IA=0;IB=0;IC=1;ID=1;}
#define scan13    {IA=1;IB=0;IC=1;ID=1;}
#define scan14    {IA=0;IB=1;IC=1;ID=1;}
#define scan15    {IA=1;IB=1;IC=1;ID=1;}
uchar Move,Speed,line;  //(移位 速度 行 ) 定义
uint zimuo;                     //字模计数器
uint uiAllData;
uchar BUFF[10];              //缓存
void   DelayMs(void);              // 延时
void   in_data();       // 调整移动数据
void   rxd_data();       // 发送移动数据
const uchar code hanzi[];
/******************************************************/
/*****不影响其他端口的扫描*************************/
void scan(unsigned char Value)
{switch(Value)
        {case  0: scan0;break;
    case  1: scan1;break;
     case  2: scan2;break;
      case  3: scan3;break;
             case  4: scan4;break;
        case  5: scan5;break;
         case  6: scan6;break;
          case  7: scan7;break;
                 case  8: scan8;break;
         case  9: scan9;break;
        case 10:scan10;break;
       case 11:scan11;break;
            case 12:scan12;break;
    case 13:scan13;break;
   case 14:scan14;break;
     case 15:scan15;break;
    default:break;
        }
}
/**************************延时***********************/
void DelayMs(void)
{
  uchar TempCyc;
  for(TempCyc=100;TempCyc>1;TempCyc--)
     {;}
}
/********************************************/
/*主函数*/
void main()
{  
   Move=0;
   zimuo=0;
   while(1)  
   {
   while(zimuo<uiAllData)//2048)//定义显示字幕数据的长度 2048/32=64 即显示完64个16*16大小的字符后 重新循环
    {
  while(Move<16) //数据移位。
       {
      for(Speed=0;Speed<4;Speed++) //移动速度控制
       {
      for(line=0;line<16;line++)
     {
    in_data(); //调整移动数据
    rxd_data(); //装载移动数据
    scan(line); //输出行扫描      
    STCP=1;//锁存
    STCP=0;
    OE=0;//打开屏使能端
    DelayMs();  //延时,等待一段时间,让这列显示的内容在人眼内产生“视觉暂留”现象。
    OE=1;
     
           }
   }
       Move++;                     //移动一步
      }
     Move=0;
  zimuo=zimuo+32; //换下一个字
    }
   zimuo=0;
   }
}   
/**********************************************************/
void in_data(void)                         //调整数据一个屏4个字的数据
{
char s;
for(s=4;s>=0;s--)                       //一个屏能显示4个字 取最前面的字发送给595的最前面
{
    //zimuo 是个计算显示到哪个字的计数器 s是取4个字的循环 line是显示到哪一行 根据这几个参数计算出一个屏中现在需要显示的数据 放入BUFF 内存中 等待发送给595
   BUFF[2*s]=hanzi[zimuo+32*s+2*line]; //要知道为什么这么算就需要知道取模的方向和原理  一行有8个字节 (一个中文16*16的字 一行有2个字节)
   BUFF[2*s+1]=hanzi[zimuo+1+32*s+2*line];//把一个字的首字节放入BUFF[0]中 后面一个字节放入BUFF[1] 以此类推剩下的3个字            
}
}
/***********************发送移动的数据****************************/
void rxd_data(void)              //串行发送数据
{
  uchar s;
  uchar inc,tempyid,temp,k;
  
  if(Move<8)
    inc=0;
  else
    inc=1;
  for(s=0+inc;s<8+inc;s++)     //发送8字节数据
{
  if(Move<8)
       tempyid=Move;
     else
     tempyid=Move-8;
     temp=(BUFF[s]>>tempyid)|(BUFF[s+1]<<(8-tempyid)); //h1左移tempyid位后和h2右移8-tempyid相或,取出移位后的数据。
     temp=255-temp;
      for(k=0;k<8;k++)//一个字节8位 发送给595
        {
         SHCP=0; //上升沿移位595      
      SDA_R=(bit)(temp&0x80);//通过IO口送一个位给 595
         temp=temp<<1;  //字节移位 准备送下一位      
            SHCP=1;
        }
   }
}
const uchar code hanzi[]={/*移动显示汉字字模,*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x08,0x00,0x10,0x20,0xFE,0x1E,0x00,0x02,0x44,0x02,0x28,0x02,0xFF,0x7E,0x10,0x12,
0x10,0x12,0xFE,0x12,0x10,0x12,0x54,0x12,0x92,0x12,0x11,0x11,0x14,0x11,0x88,0x10,/*"新",0*/
0x08,0x00,0x08,0x00,0xF8,0x3F,0x04,0x01,0x04,0x01,0x02,0x01,0xF8,0x1F,0x08,0x01,
0x08,0x01,0x08,0x01,0xFF,0x7F,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,/*"年",1*/
0x08,0x02,0x08,0x02,0x08,0x02,0xC8,0x1F,0x18,0x12,0x2A,0x12,0x0A,0x12,0x0A,0x12,
0xE9,0x7F,0x08,0x02,0x08,0x05,0x08,0x05,0x88,0x08,0x88,0x08,0x48,0x10,0x28,0x60,/*"快",2*/
0x00,0x04,0x00,0x0F,0xF8,0x00,0x08,0x00,0x88,0x00,0x84,0x00,0x84,0x00,0xFC,0x3F,
0x80,0x00,0x90,0x04,0x90,0x08,0x88,0x10,0x84,0x20,0x82,0x20,0xA0,0x00,0x40,0x00,/*"乐",3*/
0x00,0x00,0x00,0x00,0xFF,0x7F,0x20,0x00,0x20,0x00,0x20,0x00,0xE0,0x0F,0x20,0x08,
0x20,0x08,0x10,0x08,0x10,0x08,0x08,0x08,0x08,0x08,0x04,0x08,0x02,0x05,0x01,0x02,/*"万",4*/
0x80,0x00,0x80,0x00,0xFF,0x7F,0x80,0x00,0xFC,0x1F,0x84,0x10,0xFC,0x1F,0x80,0x00,
0xFC,0x1F,0x80,0x10,0xFF,0x7F,0x80,0x10,0xFC,0x1F,0x80,0x00,0xA0,0x00,0x40,0x00,/*"事",5*/
0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x3E,0x7F,0x22,0x44,0x22,0x44,0x22,0x44,0x22,
0x42,0x22,0x24,0x22,0x28,0x22,0x10,0x22,0x28,0x22,0x44,0x3E,0x42,0x22,0x01,0x00,/*"如",6*/
0x80,0x00,0xFC,0x1F,0x10,0x04,0x20,0x02,0xFF,0x7F,0x00,0x00,0xF8,0x0F,0x08,0x08,
0xF8,0x0F,0x08,0x08,0xF8,0x0F,0x40,0x00,0x8A,0x20,0x8A,0x48,0x09,0x48,0xF0,0x0F,/*"意",7*/
0x00,0x00,0x40,0x00,0x80,0x00,0x00,0x01,0x00,0x01,0x20,0x00,0x20,0x10,0x24,0x20,
0x24,0x20,0x24,0x40,0x22,0x40,0x22,0x48,0x21,0x08,0x20,0x08,0xC0,0x0F,0x00,0x00,/*"心",8*/
0x10,0x00,0x10,0x1F,0x10,0x11,0x7E,0x11,0x10,0x1F,0x18,0x11,0x38,0x1F,0x54,0x11,
0x12,0x11,0x10,0x1F,0x80,0x00,0x10,0x21,0x12,0x49,0x12,0x48,0xE1,0x0F,0x00,0x00,/*"想",9*/
0x80,0x00,0x80,0x00,0xFF,0x7F,0x80,0x00,0xFC,0x1F,0x84,0x10,0xFC,0x1F,0x80,0x00,
0xFC,0x1F,0x80,0x10,0xFF,0x7F,0x80,0x10,0xFC,0x1F,0x80,0x00,0xA0,0x00,0x40,0x00,/*"事",10*/
0x00,0x0A,0x00,0x12,0x00,0x02,0xFC,0x7F,0x04,0x02,0x04,0x02,0x04,0x22,0x7C,0x22,
0x44,0x22,0x44,0x14,0x44,0x14,0x44,0x48,0x54,0x4C,0x22,0x52,0x02,0x61,0x81,0x40,/*"成",11*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x10,0x00,0x48,0x00,0x24,0x00,0x12,0x00,0x09,0x80,0x04,0x40,0x02,0x20,0x01,
0x40,0x02,0x80,0x04,0x00,0x09,0x00,0x12,0x00,0x24,0x00,0x48,0x00,0x10,0x00,0x20,/*"《",0*/
0x08,0x02,0x7F,0x02,0x08,0x1E,0x3E,0x09,0x08,0x04,0x7F,0x3F,0x00,0x24,0xBE,0x7F,
0x22,0x24,0x3E,0x3F,0x22,0x04,0x3E,0x04,0x22,0x04,0x22,0x04,0x2A,0x05,0x12,0x02,/*"静",1*/
0x40,0x00,0x80,0x00,0xFF,0x7F,0x10,0x01,0x30,0x01,0x90,0x3F,0x88,0x10,0x4C,0x11,
0x4A,0x0A,0xA9,0x08,0x08,0x05,0x08,0x02,0x08,0x05,0x88,0x08,0x48,0x70,0x28,0x20,/*"夜",2*/
0x00,0x00,0xF8,0x1F,0x88,0x10,0x88,0x10,0xF8,0x1F,0x88,0x10,0x88,0x10,0xF8,0x1F,
0x00,0x00,0x80,0x00,0x10,0x11,0x12,0x21,0x12,0x68,0x13,0x48,0xE0,0x0F,0x00,0x00,/*"思",3*/
0x04,0x00,0x09,0x00,0x12,0x00,0x24,0x00,0x48,0x00,0x90,0x00,0x20,0x01,0x40,0x02,
0x20,0x01,0x90,0x00,0x48,0x00,0x24,0x00,0x12,0x00,0x09,0x00,0x04,0x00,0x02,0x00,/*"》",4*/
0x80,0x00,0x00,0x01,0xFC,0x3F,0x04,0x01,0xF4,0x0F,0x04,0x09,0xFC,0x3F,0x04,0x09,
0xF4,0x0F,0x04,0x01,0xF4,0x0F,0x14,0x08,0x12,0x08,0xF2,0x0F,0x11,0x08,0x00,0x00,/*"唐",5*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x0C,0x00,0x08,0x00,0x04,0x00,0x00,0x00,/*",",6*/
0x80,0x00,0x80,0x00,0xFE,0x3F,0xC0,0x01,0xA0,0x02,0x90,0x0C,0x8C,0x70,0xFB,0x27,
0x00,0x01,0x80,0x00,0xFE,0x7F,0x80,0x00,0x80,0x00,0x80,0x00,0xA0,0x00,0x40,0x00,/*"李",7*/
0x40,0x00,0x40,0x00,0x20,0x00,0xFC,0x1F,0x04,0x10,0x04,0x10,0x04,0x10,0x04,0x10,
0xFC,0x1F,0x04,0x10,0x04,0x10,0x04,0x10,0x04,0x10,0xFC,0x1F,0x04,0x10,0x00,0x00,/*"白",8*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x0C,0x00,0x08,0x00,0x04,0x00,0x00,0x00,/*",",9*/
0x80,0x00,0x00,0x01,0xFC,0x7F,0x04,0x01,0x04,0x01,0x04,0x01,0xFC,0x3F,0x84,0x01,
0x84,0x03,0x44,0x05,0x44,0x09,0x24,0x11,0x24,0x61,0x12,0x21,0x0A,0x01,0x01,0x01,/*"床",10*/
0x10,0x08,0x60,0x18,0x20,0x04,0xFF,0x7F,0x00,0x00,0x7C,0x10,0x44,0x12,0x7C,0x12,
0x44,0x12,0x44,0x12,0x7C,0x12,0x44,0x12,0x44,0x12,0x54,0x10,0x24,0x14,0x00,0x08,/*"前",11*/
0x00,0x3F,0x3E,0x21,0x22,0x21,0x22,0x21,0x22,0x3F,0x3E,0x21,0x22,0x21,0x22,0x21,
0x22,0x3F,0x3E,0x21,0x00,0x21,0x80,0x20,0x80,0x20,0x40,0x20,0x20,0x28,0x00,0x10,/*"明",12*/
0xE0,0x0F,0x20,0x08,0x20,0x08,0x20,0x08,0xE0,0x0F,0x20,0x08,0x20,0x08,0x20,0x08,
0xE0,0x0F,0x20,0x08,0x10,0x08,0x10,0x08,0x08,0x08,0x04,0x0A,0x02,0x04,0x00,0x00,/*"月",13*/
0x80,0x00,0x84,0x08,0x98,0x18,0xB0,0x08,0x90,0x04,0x80,0x20,0xFE,0x7F,0x20,0x02,
0x20,0x02,0x20,0x02,0x20,0x02,0x10,0x42,0x10,0x42,0x08,0x42,0x04,0x7C,0x02,0x00,/*"光",14*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x0C,0x00,0x08,0x00,0x04,0x00,0x00,0x00,/*",",15*/
0x04,0x00,0xB4,0x3F,0x0C,0x10,0x44,0x0A,0x44,0x04,0xB8,0x7F,0x02,0x44,0x7E,0x24,
0x12,0x05,0x11,0x3D,0x7F,0x05,0x18,0x05,0xA8,0x06,0x84,0x0C,0x42,0x70,0x21,0x20,/*"疑",16*/
0x00,0x00,0xF0,0x0F,0x10,0x08,0xF0,0x0F,0x10,0x08,0xF0,0x0F,0x00,0x00,0xFF,0x7F,
0x80,0x00,0x90,0x00,0x90,0x1F,0x90,0x00,0xA8,0x00,0xC4,0x00,0x02,0x7F,0x00,0x00,/*"是",17*/
0x00,0x04,0x88,0x04,0x88,0x04,0x88,0x24,0xBF,0x7C,0x88,0x27,0xE8,0x24,0x88,0x24,
0x88,0x24,0x88,0x2C,0x88,0x14,0xB8,0x04,0x8C,0x40,0x83,0x40,0x00,0x7F,0x00,0x00,/*"地",18*/
0x00,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x1F,0x80,0x00,
0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x20,0xFE,0x7F,0x00,0x00,/*"上",19*/
0xF8,0x1F,0x80,0x00,0xFE,0x7F,0x82,0x20,0xB8,0x0E,0x80,0x00,0xB8,0x0E,0x10,0x00,
0x10,0x1F,0x7E,0x11,0x38,0x1F,0x54,0x11,0x14,0x1F,0x12,0x11,0x10,0x1F,0x10,0x11,/*"霜",20*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x0C,0x00,0x12,0x00,0x12,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,/*"。",21*/
0x24,0x08,0x48,0x18,0x90,0x08,0x90,0x04,0xFF,0x7F,0x20,0x02,0x90,0x04,0x88,0x08,
0xF4,0x17,0x82,0x60,0x81,0x00,0xFC,0x1F,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,/*"举",22*/
0x00,0x01,0x08,0x01,0x30,0x01,0x20,0x01,0x08,0x01,0x30,0x01,0x10,0x01,0x00,0x01,
0xFF,0x7F,0x00,0x01,0x80,0x02,0x40,0x04,0x20,0x0C,0x10,0x18,0x08,0x30,0x04,0x10,/*"头",23*/
0x08,0x00,0x10,0x3F,0x7F,0x21,0x04,0x3F,0x04,0x21,0x24,0x3F,0x14,0x21,0x8C,0x38,
0x00,0x00,0xFC,0x3F,0x80,0x00,0xF8,0x1F,0x80,0x00,0x80,0x00,0xFE,0x7F,0x00,0x00,/*"望",24*/
0x00,0x3F,0x3E,0x21,0x22,0x21,0x22,0x21,0x22,0x3F,0x3E,0x21,0x22,0x21,0x22,0x21,
0x22,0x3F,0x3E,0x21,0x00,0x21,0x80,0x20,0x80,0x20,0x40,0x20,0x20,0x28,0x00,0x10,/*"明",25*/
0xE0,0x0F,0x20,0x08,0x20,0x08,0x20,0x08,0xE0,0x0F,0x20,0x08,0x20,0x08,0x20,0x08,
0xE0,0x0F,0x20,0x08,0x10,0x08,0x10,0x08,0x08,0x08,0x04,0x0A,0x02,0x04,0x00,0x00,/*"月",26*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x0C,0x00,0x08,0x00,0x04,0x00,0x00,0x00,/*",",27*/
0x10,0x18,0x30,0x3E,0xD8,0x05,0x48,0x04,0x44,0x04,0x46,0x04,0xC5,0x7F,0x44,0x04,
0x44,0x04,0x44,0x04,0x44,0x08,0x44,0x4A,0x44,0x51,0xC4,0x62,0x44,0x44,0x00,0x00,/*"低",28*/
0x00,0x01,0x08,0x01,0x30,0x01,0x20,0x01,0x08,0x01,0x30,0x01,0x10,0x01,0x00,0x01,
0xFF,0x7F,0x00,0x01,0x80,0x02,0x40,0x04,0x20,0x0C,0x10,0x18,0x08,0x30,0x04,0x10,/*"头",29*/
0x00,0x00,0xF8,0x1F,0x88,0x10,0x88,0x10,0xF8,0x1F,0x88,0x10,0x88,0x10,0xF8,0x1F,
0x00,0x00,0x80,0x00,0x10,0x11,0x12,0x21,0x12,0x68,0x13,0x48,0xE0,0x0F,0x00,0x00,/*"思",30*/
0x08,0x02,0x08,0x06,0x08,0x02,0x08,0x02,0x7F,0x7F,0x08,0x11,0x08,0x11,0xBE,0x11,
0x62,0x0A,0x22,0x0A,0x22,0x04,0x22,0x04,0x3E,0x0A,0x82,0x71,0x60,0x20,0x00,0x00,/*"故",31*/
0x80,0x00,0x80,0x01,0xC0,0x08,0x60,0x18,0x10,0x0C,0xF8,0x07,0x00,0x11,0xC0,0x30,
0x30,0x1E,0xF8,0x09,0x10,0x08,0x00,0x04,0x00,0x03,0xE0,0x00,0x1E,0x00,0x00,0x00,/*"乡",32*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x0C,0x00,0x12,0x00,0x12,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,/*"。",33*/
};
uint uiAllData = sizeof( hanzi )-128;

维吾尔人认购日通过该好好

444444444444444444444444444444444444444

谢谢小编分享!

谢谢分享,学习学习。

大哥32*64 08接口移动的怎么些呀
R1   595   上屏幕
R2   595   下屏幕
G1   595   上屏幕
G2   595   下屏幕
LCK   
SCK
NE
H138_A
H138_B
H138_C
H138_D

也做过16*160的, 与小编共勉!

啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊

没图么

hao123456

小编,有图么?

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top