硬件设计
原理图:
仿真图:
左右滚动:
上下滚动:
程序设计:
/*********************************************************************功能:16*16LED点阵显示目的:用两种滚动模式显示“极寒钛科技创作”显示方式:列扫描方式取模软件:PCtoLCD2002完美版**********************************************************************/#include <reg52.h>#define uchar unsigned char#define uint unsigned int sbit datal595=P1^0; //列数据线sbit datah595=P1^1; //行数据线sbit clk595=P1^2; //数据输入时钟线sbit str595=P1^3; //输出存储器锁存时钟线sbit oe595=P1^4; //oe输出使能//取模方式:阴码、逐列式、逆向、十六进制、C51格式自定义 (使用Pctolcd2002软件)uchar code displaydata[]= //在ROM中定义一个可变长度数组,供用户填充一定个数的字模{//可填充的最大字模数取决于您所选用的单片机ROM空间大小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,0x04,0x10,0x03,0xD0,0x00,0xFF,0xFF,0x90,0x00,0x10,0x43,0x02,0x30,0x02,0x8F,0xFE,0x80,0x02,0x43,0x02,0x2C,0x62,0x10,0x5A,0x2C,0xC6,0x43,0x00,0x80,0x00,0x00,/*"极",0*/0x10,0x11,0x0C,0x11,0x44,0x09,0x54,0x05,0x54,0x03,0xFC,0x21,0x55,0x25,0x56,0x45,0x54,0x49,0xFC,0x91,0x54,0x03,0x54,0x05,0x44,0x09,0x14,0x11,0x0C,0x11,0x00,0x00,/*"寒",1*/0x40,0x01,0x20,0x01,0x38,0x01,0xE7,0x7F,0x24,0x21,0x24,0x11,0x04,0x89,0x20,0x40,0x20,0x30,0x20,0x2E,0xFF,0x41,0x20,0x0E,0x20,0x30,0x20,0x40,0x20,0x80,0x00,0x00,/*"钛",2*/0x24,0x08,0x24,0x06,0xA4,0x01,0xFE,0xFF,0xA3,0x00,0x22,0x01,0x00,0x04,0x22,0x04,0xCC,0x04,0x00,0x04,0x00,0x04,0xFF,0xFF,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x00,/*"科",3*/0x10,0x04,0x10,0x44,0x10,0x82,0xFF,0x7F,0x10,0x01,0x90,0x80,0x08,0x80,0x88,0x40,0x88,0x43,0x88,0x2C,0xFF,0x10,0x88,0x28,0x88,0x46,0x88,0x81,0x08,0x80,0x00,0x00,/*"技",4*/0x40,0x00,0x50,0x00,0x4E,0x3E,0x48,0x02,0x48,0x02,0xFF,0xFF,0x48,0x12,0x48,0x22,0x48,0x1E,0x40,0x00,0xF8,0x0F,0x00,0x40,0x00,0x80,0xFF,0x7F,0x00,0x00,0x00,0x00,/*"制",5*/0x00,0x01,0x80,0x00,0x60,0x00,0xF8,0xFF,0x07,0x00,0x40,0x00,0x30,0x00,0x0F,0x00,0xF8,0xFF,0x88,0x08,0x88,0x08,0x88,0x08,0x88,0x08,0x08,0x08,0x08,0x00,0x00,0x00,/*"作",6*///至此字模插入结束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};/*----------------------------------函数名字:delay_ms形式参数:无字符整型 i:延时多少函数功能:以1ms为单位的函数延时返 回 值:无 ------------------------------------*/void delay_ms(uint i) {uint j;for(;i>0;i--)for(j=110;j>0;j--);}/*----------------------------------函数名字:senddata 形式参数:无字符整型 datah:行的数据 无字符整型 datal:列的数据函数功能:把数据发送给芯片74HC595返 回 值:无 ------------------------------------*/void senddata(uint datah,uint datal) //向行和列的4个595同时发送数据,显示其中的一列数据{uchar i=0;uint m,n;oe595=0;str595=0;for(;i<16;i++) //行和列各有两片595驱动,所以行和列分别需要连续送两个字节数据 {clk595=0;m=datah;//行为高电平驱动n=~datal; //列为低电平驱动m&=0x8000;n&=0x8000;datah595=(bit)m; //在每个clk周期,同时送出行和列的1bit串行数据datal595=(bit)n;datah<<=1; datal<<=1;clk595=1;}str595=1; //一列数据送完,锁存到输出端进行显示str595=0;}/*----------------------------------函数名字:char_max 形式参数:无字符字符型 *dat:两个8位数据的第一个数据的地址函数功能:受到取模软件的限制,需要对字模表的数据进行重新排列将两个8位的数据拼成显示所需16位的数据返回值 :uint:返回排列好的值 ------------------------------------*/uint char_max(uchar *dat){uint l,h;h = (uint)*(dat+1);//16位中的高字节数据h <<= 8;h &=0xff00;l = (uint)*dat;//16位中的低字节数据l &= 0x00ff;return l|h;}/*----------------------------------函数名字:horizontal 形式参数:无字符字符型 time:字符移动的速度无字符字符型 counth:移动全部字符所需的列数无符号字符型指针 p:字符显示数据的首地址函数功能:显示字符水平移动返回值 :无 ------------------------------------*/void horizontal(uchar time,uint count,uchar *p) //垂直移动 {uint datah,datal; //datah是行数据,datal是列选通uchar x,y;uint z;for(z=0;z<count;z++) //显示字模表中的所有汉字(包括有用字模前后的的清屏数据){for(y=0;y<time;y++) //该屏数据重复显示time次后刷新,实际上这是水平移动的速度{for(x=0;x<16;x++) //发送一整屏数据,16个16位 {p += 2;datah = char_max(p);datal = 0x0001<<x; //列选通位移到相应的列上进行选通//datah=~datah; //去掉此行前面的注释则水平移动程反白显示senddata(datah,datal); //将行和列数据发送出去进行一列的显示}p-=32; //指针恢复为这个汉字首地址,准备重复显示该屏数据time次} //该屏数据经过了time次的显示,显示数据准备更新p+=2; //指向了该汉字的下一列,左移一列汉字} //移动了字模表中的所有汉字,左移过程结束oe595=1;}
附:http://www.jh-/archives/7536