1、 51单片机16X32LED点阵程序#include#include intrins.h#define uchar unsigned char#define uint unsigned int#define light 3 /定义亮度 /*接口定义*/sbit SHCP=P16;/595的移位信号 sbit STCP=P15;/是595的锁存信号 /*如果用的是普通单片机 没有P4.1口 请改为其他口*/ sbit SDA_R=P36;/红数据 sbit SDA_G=P14;/绿数据 sbit OE=P17;/输出使能 sbit IA=P10;/行控制线A /*如果用的是普通单片机 没有P4.
2、0口 请改为其他口*/ sbit IB=P11;/行控制线B sbit IC=P12;/行控制线C sbit ID=P13;/行控制线Dsbit Speek=P23;/蜂鸣器/*/#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;#defin
3、e 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;
4、ID=1;#define scan15 IA=1;IB=1;IC=1;ID=1;uchar Move,Speed,line; /(移位 速度 行 ) 定义uint zimuo; /字模计数器uint uiAllData;uchar BUFF10; /缓存void DelayMs(void); / 延时void in_data(); / 调整移动数据void rxd_data(); / 发送移动数据const uchar code hanzi;/*/*不影响其他端口的扫描*/void scan(unsigned char Value)switch(Value)case 0: scan0;brea
5、k;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:scan1
6、5;break;default:break;/*延时*/*void Delay1ms(unsigned int tima)unsigned int a,b;for(a = tima; a 0; a-)for(b = 110; b 0; b-);*/*/void Delay_15us(unsigned int time)do_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();while(-time);/*主函数
7、*/void main() Move=0;zimuo=0;while(1) /利用sizeof()语句 运算字幕有效数据的总数;while(zimuouiAllData)/2048)/定义显示字幕数据的长度 2048/32=64 即显示完64个16*16大小的字符后 重新循环 for(Move = 0;Move16;Move+)/数据移位。for(Speed=0;Speed10;Speed+) /移动速度控制for(line=0;line=0;s-) /一个屏能显示4个字 取最前面的字发送给595的最前面/zimuo 是个计算显示到哪个字的计数器 s是取4个字的循环 line是显示到哪一行 根
8、据这几个参数计算出一个屏中现在需要显示的数据 放入BUFF 内存中 等待发送给595BUFF2*s+0=hanzizimuo+0+32*s+2*line;/要知道为什么这么算就需要知道取模的方向和原理 一行有8个字节 (一个中文16*16的字 一行有2个字节)BUFF2*s+1=hanzizimuo+1+32*s+2*line;/把一个字的首字节放入BUFF0中 后面一个字节放入BUFF1 以此类推剩下的3个字 /*发送移动的数据*/void rxd_data(void) /串行发送数据uchar s;uchar inc,tempyid,temp;if(Move8)inc=0;else inc
9、=1;for(s=0+inc;s4+inc;s+) /发送4字节数据if(Move8) tempyid=Move;else tempyid=Move-8;temp=(BUFFs(8-tempyid);/h1左移tempyid位后和h2右移8-tempyid相或,取出移位后的数据。temp=255-temp;/temp1=(BUFF1stempyid)|(BUFF1s+1(8-tempyid);/h1左移tempyid位后和h2右移8-tempyid相或,取出移位后的数据。/temp1=255-temp1;ACC = temp;/if(zimuo 104) /当显示完512/32=16个字后变绿
10、色显示/SDA_G=1;/* for(k=0;k1; /字节移位 准备送下一位SHCP=1;*/SHCP = 0; ACC = 1; SDA_R = CY; SHCP = 1;SHCP = 0; ACC = 1; SDA_R = CY; SHCP = 1;SHCP = 0; ACC = 1; SDA_R = CY; SHCP = 1;SHCP = 0; ACC = 1; SDA_R = CY; SHCP = 1;SHCP = 0; ACC = 1; SDA_R = CY; SHCP = 1;SHCP = 0; ACC = 1; SDA_R = CY; SHCP = 1;SHCP = 0; AC
11、C = 1; SDA_R = CY; SHCP = 1;SHCP = 0; ACC = 1; SDA_R = CY; SHCP = 1;/取模说明: 取模软件用PC2002 资料包里有 直接打开即可用配置请看此程序目录下的配置图片/const uchar code hanzi=/*移动显示汉字字模,*/移动显示汉字0x90,0x00,0x90,0x01,0x88,0x20,0xC8,0x7F,0x44,0x20,0x2C,0x12,0x16,0x02,0x45,0x0A,0xC4,0x12,0x44,0x12,0x24,0x22,0x24,0x62,0x14,0x22,0x84,0x02,0x
12、04,0x01,0x00,0x00,/*你,6*/0x40,0x00,0x40,0x00,0xFE,0x7F,0x20,0x00,0x20,0x00,0x10,0x02,0x18,0x02,0xE8,0x3F,0x0C,0x02,0x0A,0x02,0x09,0x02,0x08,0x02,0x08,0x02,0xE8,0x7F,0x08,0x00,0x00,0x00,/*在,7*/0xE0,0x7B,0x4F,0x4A,0x49,0x2A,0x49,0x2A,0xE9,0x2B,0x49,0x1A,0x49,0x2A,0xF9,0x2B,0x49,0x4A,0x4F,0x4A,0x29,0x4
13、A,0x20,0x5A,0x10,0x2A,0x88,0x0A,0x04,0x09,0x00,0x00,/*哪,8*/0xFC,0x1F,0x84,0x10,0x84,0x10,0x84,0x10,0xFC,0x1F,0x84,0x10,0x84,0x10,0xFC,0x1F,0x80,0x00,0x80,0x00,0xFC,0x1F,0x80,0x00,0x80,0x00,0x80,0x00,0xFF,0x7F,0x00,0x00,/*里,9*/0x60,0x02,0x1C,0x0A,0x10,0x12,0x10,0x12,0x10,0x02,0xFF,0x7F,0x10,0x02,0x10
14、,0x12,0x70,0x14,0x1C,0x0C,0x13,0x04,0x10,0x0A,0x90,0x49,0x10,0x50,0x14,0x60,0x08,0x40,/*我,10*/0x80,0x00,0x80,0x00,0xFC,0x3F,0x80,0x00,0x90,0x0C,0xA0,0x04,0xC0,0x02,0xFE,0x7F,0x80,0x01,0xC0,0x02,0xA0,0x04,0x90,0x18,0x8C,0x70,0x83,0x20,0x80,0x00,0x80,0x00,/*来,11*/0x00,0x00,0xFE,0x3F,0x00,0x18,0x00,0x0
15、6,0x80,0x01,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0xA0,0x00,0x40,0x00,/*了,12*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x00,0x00,0x08,0x00,0x00,0x00,/*!,13*/;uint uiAllData = sizeof( hanzi )-128;word文档 可自由复制编辑