给51黑电子论坛的朋友们们分享一个51单片机驱动16*16点阵的例子,用了4个74hc573驱动芯片,电路图如下:
仿真工程文件及源程序下载:
16x16_led点阵.rar
(67.38 KB, 下载次数: 64)
源程序:
- #include <reg51.h>
- #include<intrins.h>
- /* 数据端接口定义 */
- sbit sck = P2^0; //输入时钟
- sbit row_dat = P2^1; //行数据时钟
- sbit row_buf_sck = P2^2; //行锁存
- //sbit row_mr = P2^4; //移位寄存器清零端
- //sbit row_oe = P2^5; //输出使能
- /* 选通端接口定义 */
- sbit col_dat = P2^6; //列数据时钟
- sbit col_buf_sck = P2^3; //列锁存
- unsigned int code sel[16] = {0xff7f,0x7fff,0xffbf,0xbfff,0xffdf,0xdfff,0xffef,0xefff,
- 0xfff7,0xf7ff,0xfffb,0xfbff,0xfffd,0xfdff,0xfffe,0xfeff};
- unsigned char code hanzi[33][32] =
- {
- {0x08,0x02,0x08,0x44,0x0F,0xA8,0xF8,0x10,0x08,0x68,0x0F,0x84,0x02,0x02,0x3C,0x42,
- 0x08,0x42,0x08,0x42,0xFF,0xFE,0x08,0x42,0x08,0x42,0x08,0x42,0x00,0x02,0x00,0x00},//姓
- {0x00,0x20,0x04,0x20,0x04,0x20,0x08,0x40,0x10,0x7F,0x28,0xC2,0xE6,0xC2,0x21,0x42,
- 0x22,0x42,0x24,0x42,0x28,0x42,0x30,0x42,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00},//名
- {0x12,0x22,0x0A,0x22,0x47,0xA4,0x28,0x24,0x00,0x28,0x04,0xB0,0x59,0x20,0x42,0xFF,
- 0x7C,0x20,0x41,0x30,0x40,0xA8,0x7F,0x24,0x00,0x24,0x10,0x22,0x0C,0x22,0x00,0x00},//梁
- {0x00,0x01,0x7F,0xE2,0x40,0x0C,0x5F,0xF0,0x40,0x08,0x7F,0xE6,0x00,0x00,0x02,0x00,
- 0x07,0x7F,0x1A,0x42,0xE2,0x42,0x02,0x42,0x0A,0x42,0x06,0x7F,0x03,0x00,0x00,0x00},//贻
- {0x00,0x41,0x10,0x42,0x10,0x8C,0x11,0x00,0x12,0x00,0x14,0x08,0x18,0x06,0xFF,0xE0,
- 0x18,0x08,0x14,0x06,0x12,0x00,0x11,0x00,0x10,0x88,0x10,0x47,0x00,0x40,0x00,0x00},//杰
- {0x08,0x20,0x08,0x22,0x08,0x41,0xFF,0xFE,0x08,0x80,0x09,0x00,0x00,0x00,0xFC,0xFF,
- 0x12,0x92,0x12,0x92,0x22,0x92,0x22,0x92,0x22,0x92,0x42,0xFF,0x0E,0x00,0x00,0x00},//指
- {0x00,0x20,0x00,0x20,0x7E,0x20,0x49,0x20,0x49,0x30,0x49,0x2C,0x49,0x20,0x49,0x20,
- 0x49,0x22,0x49,0x21,0x49,0xFE,0x79,0x20,0x01,0x20,0x07,0x20,0x00,0x20,0x00,0x00},//导
- {0x04,0x20,0x25,0x50,0x25,0x92,0x25,0x11,0xFF,0x7E,0x25,0xA0,0x2D,0x20,0x14,0x21,
- 0x21,0x02,0x0E,0x04,0xF1,0xC8,0x10,0x30,0x10,0xCC,0x1F,0x02,0x10,0x01,0x00,0x00},//教
- {0x00,0x00,0x3F,0xE1,0x00,0x02,0x00,0x0C,0xFF,0xF0,0x00,0x00,0x40,0x00,0x47,0xF8,
- 0x44,0x00,0x44,0x00,0x7F,0xFF,0x44,0x10,0x44,0x08,0x47,0xF0,0x40,0x00,0x00,0x00},//师
- {0x00,0x01,0x00,0x21,0x7C,0x21,0x44,0x42,0x44,0xA2,0x7D,0x92,0x46,0x8C,0x44,0x84,
- 0x44,0x88,0x7C,0x90,0x44,0xA0,0x44,0xC0,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x00},//罗
- {0x00,0x10,0x00,0x20,0x00,0xC0,0x07,0x00,0x00,0x00,0x00,0x02,0x00,0x01,0xFF,0xFE,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x02,0x00,0x01,0x80,0x00,0x70,0x00,0x00},//小
- {0x02,0x00,0x22,0x00,0x2A,0x00,0x2A,0xFF,0x2A,0xA8,0x2A,0xA8,0x2A,0xA8,0xFE,0xA8,
- 0x2A,0xA8,0x2A,0xAA,0x2A,0xA9,0x2A,0xFE,0x2A,0x00,0x22,0x00,0x02,0x00,0x00,0x00},//青
- {0x20,0x00,0x27,0xFF,0x24,0x00,0x24,0x10,0x26,0x90,0x25,0x90,0x24,0x90,0xFC,0xFE,
- 0x24,0x90,0x25,0x90,0x26,0x90,0x24,0x12,0x24,0x01,0x27,0xFE,0x20,0x00,0x00,0x00},//南
- {0x00,0x00,0x00,0x00,0x00,0xFF,0xFE,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,
- 0x92,0x92,0x92,0x92,0x92,0x92,0xFE,0x92,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00},//昌
- {0x04,0x01,0x04,0x01,0x04,0x02,0x04,0x04,0x04,0x08,0x04,0x30,0x04,0xC0,0xFF,0x00,
- 0x04,0xC0,0x04,0x30,0x04,0x08,0x04,0x04,0x04,0x02,0x04,0x01,0x04,0x01,0x00,0x00},//大
- {0x02,0x20,0x0C,0x20,0x88,0x20,0x69,0x20,0x09,0x20,0x09,0x22,0x89,0x21,0x69,0x7E,
- 0x09,0x60,0x09,0xA0,0x19,0x20,0x28,0x20,0xC8,0x20,0x0A,0x20,0x0C,0x20,0x00,0x00},//学
- {0x24,0x10,0x24,0x60,0x25,0x80,0x7F,0xFF,0xC5,0x00,0x44,0x80,0x00,0x20,0x44,0x20,
- 0x33,0x20,0x00,0x20,0x00,0x20,0xFF,0xFF,0x00,0x40,0x00,0x40,0x00,0x40,0x00,0x00},//科
- {0x02,0x20,0x0C,0x20,0x88,0x20,0x69,0x20,0x09,0x20,0x09,0x22,0x89,0x21,0x69,0x7E,
- 0x09,0x60,0x09,0xA0,0x19,0x20,0x28,0x20,0xC8,0x20,0x0A,0x20,0x0C,0x20,0x00,0x00},//学
- {0x08,0x20,0x08,0x22,0x08,0x41,0xFF,0xFE,0x08,0x80,0x09,0x01,0x10,0x01,0x11,0x02,
- 0x11,0xC2,0x11,0x34,0xFF,0x08,0x11,0x14,0x11,0x62,0x11,0x81,0x10,0x01,0x00,0x00},//技
- {0x00,0x08,0x08,0x10,0x08,0x20,0x08,0x40,0x08,0x80,0x0B,0x00,0x0C,0x00,0xFF,0xFF,
- 0x0C,0x00,0x0B,0x00,0x48,0x80,0x38,0x40,0x08,0x20,0x08,0x10,0x00,0x08,0x00,0x00},//术
- {0x02,0x20,0x0C,0x20,0x88,0x20,0x69,0x20,0x09,0x20,0x09,0x22,0x89,0x21,0x69,0x7E,
- 0x09,0x60,0x09,0xA0,0x19,0x20,0x28,0x20,0xC8,0x20,0x0A,0x20,0x0C,0x20,0x00,0x00},//学
- {0x00,0x00,0x7F,0xFF,0x44,0x20,0x5A,0x10,0x61,0xE0,0x08,0x01,0x30,0x82,0x24,0x8C,
- 0x24,0xF0,0xA4,0x80,0x64,0x80,0x24,0xFC,0x24,0x82,0x28,0x82,0x30,0x8E,0x00,0x00},//院
- {0x00,0x80,0x01,0x00,0x06,0x00,0x1F,0xFF,0xE0,0x00,0x00,0x00,0x20,0x00,0x24,0x9F,
- 0x24,0x92,0xA4,0x92,0x64,0x92,0x24,0x92,0x24,0x92,0x24,0x9F,0x20,0x00,0x00,0x00,},//信
- {0x00,0x02,0x00,0x0C,0x00,0x00,0x3F,0xC0,0x2A,0x9C,0x2A,0x82,0x6A,0x82,0xAA,0xA2,
- 0x2A,0x9A,0x2A,0x82,0x2A,0x82,0x3F,0xCE,0x00,0x00,0x00,0x10,0x00,0x0C,0x00,0x00},//息
- {0x02,0x20,0x0C,0x20,0x88,0x20,0x69,0x20,0x09,0x20,0x09,0x22,0x89,0x21,0x69,0x7E,
- 0x09,0x60,0x09,0xA0,0x19,0x20,0x28,0x20,0xC8,0x20,0x0A,0x20,0x0C,0x20,0x00,0x00},//学
- {0x24,0x10,0x24,0x60,0x25,0x80,0x7F,0xFF,0xC5,0x00,0x44,0x80,0x00,0x20,0x44,0x20,
- 0x33,0x20,0x00,0x20,0x00,0x20,0xFF,0xFF,0x00,0x40,0x00,0x40,0x00,0x40,0x00,0x00},//科
- {0x02,0x00,0x22,0x00,0x2A,0x7E,0xA6,0x44,0x62,0x44,0x22,0x44,0x26,0x44,0x2A,0x7E,
- 0x22,0x00,0x02,0x00,0x7F,0xFF,0x40,0x10,0x44,0x08,0x5B,0x10,0x60,0xE0,0x00,0x00},//部
- {0x00,0x00,0x00,0x00,0x1F,0xF8,0x11,0x10,0x11,0x10,0x11,0x10,0x11,0x10,0xFF,0xFE,
- 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x1F,0xF9,0x00,0x01,0x00,0x0F,0x00,0x00},//电
- {0x01,0x00,0x41,0x00,0x41,0x00,0x41,0x00,0x41,0x00,0x41,0x02,0x41,0x01,0x47,0xFE,
- 0x45,0x00,0x49,0x00,0x51,0x00,0x61,0x00,0x41,0x00,0x01,0x00,0x01,0x00,0x00,0x00},//子
- {0x00,0x80,0x01,0x00,0x06,0x00,0x1F,0xFF,0xE0,0x00,0x00,0x00,0x20,0x00,0x24,0x9F,
- 0x24,0x92,0xA4,0x92,0x64,0x92,0x24,0x92,0x24,0x92,0x24,0x9F,0x20,0x00,0x00,0x00},//信
- {0x00,0x02,0x00,0x0C,0x00,0x00,0x3F,0xC0,0x2A,0x9C,0x2A,0x82,0x6A,0x82,0xAA,0xA2,
- 0x2A,0x9A,0x2A,0x82,0x2A,0x82,0x3F,0xCE,0x00,0x00,0x00,0x10,0x00,0x0C,0x00,0x00},//息
- {0x00,0x04,0x20,0x04,0x20,0x04,0x20,0x04,0x20,0x04,0x20,0x04,0x20,0x04,0x3F,0xFC,
- 0x20,0x04,0x20,0x04,0x20,0x04,0x20,0x04,0x20,0x04,0x20,0x04,0x00,0x04,0x00,0x00},//工
- {0x24,0x10,0x24,0x60,0x25,0x80,0x7F,0xFF,0xC4,0x80,0x44,0x60,0x00,0x02,0x7C,0x92,
- 0x44,0x92,0x44,0x92,0x44,0xFE,0x44,0x92,0x44,0x92,0x7C,0x92,0x00,0x82,0x00,0x00},//程
- };
- void send_data_row(unsigned int dat); /* 发送行数据端数据函数 */
- void send_data_col(unsigned int dat); /* 发送列选通端数据函数 */
- void display(unsigned char *p);
- void delay(unsigned int m);
- void main()
- {
- unsigned char i,j;
- // row_mr = 1;
- // row_oe = 0;
- while(1)
- {
- for(i=0;i<33;i++) //33个代码
- {
- for(j=0;j<15;j++) //循环显示汉字十遍
-
- display(hanzi[i]); //显示一个汉字
- }
- }
- }
- void send_data_row(unsigned int dat)
- {
- unsigned char i;
-
- for(i=0;i<16;i++)
- {
- sck = 0;
- row_dat = dat&0x8000; //temp<<=1;
- dat = dat<<1; //ds = CY;
- sck = 1;
- }
- row_buf_sck = 0;
- _nop_();
- _nop_();
- row_buf_sck = 1;
- }
- void send_data_col(unsigned int dat)
- {
- unsigned char i;
- for(i=0;i<16;i++)
- {
- sck = 0;
- col_dat = dat&0x8000;
- dat = dat<<1;
- sck = 1;
- }
- col_buf_sck = 0;
- _nop_();
- _nop_();
- col_buf_sck = 1;
- }
- void delay(unsigned int m)
- {
- unsigned char i;
- for(;m>0;m--)
- {
- for(i=0;i<124;i++)
- {;}
- }
- }
- void display(unsigned char *p)
- {
- unsigned char i;
- // unsigned int temp;
- for(i=0;i<32;i++)
- {
- if(i<16)
- {
- send_data_row(0x0000);
- // temp = sel[i]|0xff00;
- send_data_col(sel[i]);
- send_data_row(*p);
- p++;
- delay(2);
- }
- else
- {
- send_data_row(0x0000);
- // temp = (sel[i]<<8)|0x00ff;
- send_data_col(sel[i-16]);
- send_data_row((*p)<<8);
- p++;
- delay(2);
- }
- }
- }
复制代码 |