首先来介绍一下LED单元板,LED单元板说白了就是LED点阵模块,一个模块是由偶数个8*8的小LED模块构成,每一个8*8LED模块采用一块移位存储寄存器(74HC595)和一块移位寄存器(74HC138)来驱动8*8LED模块的显示。
LED单元板的显示采用动态扫描的方式,简单地说就是逐行轮流点亮,这样扫描驱动电路就可以实现16行的同名列共用一套列驱动器。在轮流点亮一遍的过程中,每行LED点亮的时间是几位短暂的,如果以1ms计算,扫描16行则只需16ms,扫描频率为1000/16=62.5HZ,由于这个频率足够快,给人眼的视觉印象就会是在连续稳定地显示,并不觉察有闪烁现象。
为了实现汉字的扫描,需要制作汉字字模数据,汉字字模的数据需要用取模软件来提取,下图是我提取字模时的参数设置:
贴出程序:
/*
µ¥Æ¬»ú£ºSTC12C5A60S2
*/
//×°ÔØÍ·Îļþ
#include <reg52.h>
#include <intrins.h>
//Êý¾ÝÀàÐͶ¨Òå
typedef unsigned char u8;
typedef unsigned int u16;
typedef unsigned long u32;
//STC12C5A60S2 ÉùÃ&pide;GPIO¶Ë¿ÚÏà¹ØµÄ¼Ä´æÆ&pide;
sfr P0M0=0X94;
sfr P0M1=0X93;
sfr P1M0=0X92;
sfr P1M1=0X91;
sfr P2M0=0X96;
sfr P2M1=0X95;
//STC12C5A60S2 ÉùÃ&pide;ÓëPCAÏà¹ØµÄ¼Ä´æÆ&pide;
sfr CCON=0XD8;//PCA¿ØÖÆ¿ØÖƼĴæÆ&pide;
sbit CCF0=CCON^0;//PCAÄ£¿é0ÖжϱêÖ¾
sbit CCF1=CCON^1;//PCAÄ£¿é1ÖжϱêÖ¾
sbit CR=CCON^6;//PCA¼ÆÊýÆ&pide;ÕóÁÐÔËÐпØÖÆλ
sbit CF=CCON^7;//PCA¼ÆÊýÆ&pide;ÕóÁÐÒç³ö±ê־λ
sfr CMOD=0XD9;//PCA¹¤×&pide;ģʽ¼Ä´æÆ&pide;
sfr CL=0XE9;//PCAµÄ16λ¼ÆÊýÆ&pide; µÍ8λ ¸´Î»ÖµÎª00H ±£´æPCAµÄ×°ÔØÖµ
sfr CH=0XF9;//PCAµÄ16λ¼ÆÊýÆ&pide; ¸ß8λ ¸´Î»ÖµÎª00H ±£´æPCAµÄ×°ÔØÖµ
sfr CCAPM0=0XDA;//PCAÄ£¿é0µÄ±È½Ï/²¶»ñ¼Ä´æÆ&pide;
//µ±PCAÄ£¿éÓÃÓÚPWMģʽʱ£¬CCAPXLºÍCCAPXHÓÃÀ´¿ØÖÆÊä³öµÄÕ¼¿Õ±È ¸´Î»ÖµÊÇ00H
sfr CCAP0L=0XEA;//PCAÄ£¿é0¼Ä´æÆ&pide;µÄµÍλ×Ö½Ú
sfr CCAP0H=0XFA;//PCAÄ£¿é0¼Ä´æÆ&pide;µÄ¸ßλ×Ö½Ú
sfr CCAPM1=0XDB;//PCAÄ£¿é1µÄ±È½Ï/²¶»ñ¼Ä´æÆ&pide;
sfr CCAP1L=0XEB;//PCAÄ£¿é1¼Ä´æÆ&pide;µÄµÍλ×Ö½Ú
sfr CCAP1H=0XFB;//PCAÄ£¿é1¼Ä´æÆ&pide;µÄµÍλ×Ö½Ú
sfr PCAPWM0=0XF2;//PCAÄ£¿éPWM¼Ä´æÆ&pide;0
sfr PCAPWM1=0XF3;//PCAÄ£¿éPWM¼Ä´æÆ&pide;1
//08½Ó¿ÚLEDµ¥Ôª°åÒý½Å¶¨Òå
sbit A_LED=P0^0;
sbit B_LED=P0^1;
sbit C_LED=P0^2;
sbit D_LED=P0^3;
sbit CLK_LED=P0^4;//ÒÆλʱÖÓ
sbit STB_LED=P0^5;//Ëø´æʱÖÓ
sbit R1_LED=P2^0;//ÉÏ°ëÆÁÄ»ºìÉ«Êý¾Ý 1¿ªÏÔʾ 0¹ØÏÔʾ
sbit R2_LED=P2^1;//Ï°ëÆÁÄ»ºìÉ«Êý¾Ý
sbit G1_LED=P2^2;//ÉÏ°ëÆÁÄ»ÂÌÉ«Êý¾Ý 1¿ªÏÔʾ 0¹ØÏÔʾ
sbit G2_LED=P2^3;//Ï°ëÆÁÄ»ÂÌÉ«Êý¾Ý
sbit B1_LED=P2^4;//ÉÏ°ëÆÁÄ»À¶É«Êý¾Ý 1¿ªÏÔʾ 0¹ØÏÔʾ
sbit B2_LED=P2^5;//Ï°ëÆÁÄ»À¶É«Êý¾Ý
sbit OE_LED=P1^3;//OE=1¹Ø±ÕÏÔʾ OE=0¿ªÏÔʾ ²ÉÓÃPWM·½Ê½¿ÉʵÏÖÁÁ¶Èµ&pide;½Ú
//ʵÑéÊý×é
u8 zifu[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
//16*64
u8 code pic[16][8]=
//C:\Users\shuo\Desktop\??1.bmp(0)
{
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x02,0x01,0x82,0x20,0x22,0x00,0x1C},
{0x3F,0xE1,0x6E,0x02,0x20,0x22,0x03,0xE0},
{0x10,0x40,0x22,0x1F,0xFC,0x2F,0xC2,0x00},
{0x08,0x80,0x22,0x02,0x20,0xB2,0x42,0x20},
{0x07,0x03,0x4B,0x80,0x00,0xA2,0x42,0x20},
{0x18,0xC1,0x4A,0x1F,0xF8,0xA2,0x43,0xFE},
{0x62,0x31,0x6A,0x01,0x08,0xBF,0xE0,0x20},
{0x02,0x01,0x2A,0x01,0x08,0x22,0x01,0x24},
{0x1F,0xC1,0x2F,0x81,0x08,0x25,0x01,0x22},
{0x02,0x01,0xA0,0x01,0x18,0x25,0x02,0x21},
{0x02,0x01,0x40,0x01,0x00,0x28,0x84,0x21},
{0x7F,0xF0,0xBF,0x81,0x00,0x30,0x60,0xE0},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
};
//ÐÐɨÃè
void Choose_Hang(u8 i)
{
switch(i)
{
case 0: D_LED=0; C_LED=0; B_LED=0; A_LED=0; break;
case 1: D_LED=0; C_LED=0; B_LED=0; A_LED=1; break;
case 2: D_LED=0; C_LED=0; B_LED=1; A_LED=0; break;
case 3: D_LED=0; C_LED=0; B_LED=1; A_LED=1; break;
case 4: D_LED=0; C_LED=1; B_LED=0; A_LED=0; break;
case 5: D_LED=0; C_LED=1; B_LED=0; A_LED=1; break;
case 6: D_LED=0; C_LED=1; B_LED=1; A_LED=0; break;
case 7: D_LED=0; C_LED=1; B_LED=1; A_LED=1; break;
case 8: D_LED=1; C_LED=0; B_LED=0; A_LED=0; break;
case 9: D_LED=1; C_LED=0; B_LED=0; A_LED=1; break;
case 10: D_LED=1; C_LED=0; B_LED=1; A_LED=0; break;
case 11: D_LED=1; C_LED=0; B_LED=1; A_LED=1; break;
case 12: D_LED=1; C_LED=1; B_LED=0; A_LED=0; break;
case 13: D_LED=1; C_LED=1; B_LED=0; A_LED=1; break;
case 14: D_LED=1; C_LED=1; B_LED=1; A_LED=0; break;
case 15: D_LED=1; C_LED=1; B_LED=1; A_LED=1; break;
default:break;
}
}
/*
ºì ÂÌ À¶ Èç¹ûÖ»ÏÔʾºìÉ«Ö»Ðè°ÑÂÌÉ«ºÍÀ¶É«µÄֵд0¼È¿ÉÒԹرÕÂÌÉ«ºÍÀ¶É«ÏÔʾ£¬
ʹÆäÖ»ÏÔʾºìÉ«
ÏÔʾʲôÑÕÉ«¾Í×¢Ê͵ôʲôÑÕÉ«¾Í¿ÉÒÔÁË
*/
//ºìÉ«È«ÆÁÄ»
void Red_Send_595(u8 dat)
{
u8 j,i;
for(j=0;j<16;j++)
{
if(j==16) j=0;
for(i=0; i<8; i++)
{
dat <<= 1;
//ÉèÖÃÏÔʾµÄÑÕÉ«
//R1_LED=CY;
//R2_LED=CY;
G1_LED=CY;
G2_LED=CY;
B1_LED=CY;
B2_LED=CY;
//ÒÆλʱÖÓ ÕýÌø±äÏÂÒƶ¯
CLK_LED=1;
CLK_LED=0;
}
STB_LED=1;
STB_LED=0;
Choose_Hang(j);
}
}
//ÂÌÉ«È«ÆÁÄ»
void Green_Send_595(u8 dat)
{
u8 j,i;
for(j=0;j<16;j++)
{
if(j==16) j=0;
for(i=0; i<8; i++)
{
dat <<= 1;
R1_LED=CY;
R2_LED=CY;
//G1_LED=CY;
//G2_LED=CY;
B1_LED=CY;
B2_LED=CY;
CLK_LED=1;
CLK_LED=0;
}
STB_LED=1;
STB_LED=0;
Choose_Hang(j);
}
}
//À¶É«È«ÆÁÄ»
void Blue_Send_595(u8 dat)
{
u8 j,i;
for(j=0;j<16;j++)
{
for(i=0; i<8; i++)
{
dat <<= 1;
R1_LED=CY;
R2_LED=CY;
G1_LED=CY;
G2_LED=CY;
//B1_LED=CY;
//B2_LED=CY;
CLK_LED=1;//ÉÏÉýÑØ·¢ÉúÒÆλ
CLK_LED=0;
}
STB_LED=1;//ÉÏÉýÑؽ«Êý¾ÝË͵½Êä³ö¼Ä´æÆ&pide;
STB_LED=0;//Ëø´æÏÔʾÊý¾Ý
Choose_Hang(j);
}
}
//ÉÏ°ëÆÁÄ»ÏÔʾ
//ÏÔʾһ¸ö×Ö½Ú ·¢ËÍÒ»¸ö×Ö½Ú ²¢ Ëø´æÒ»¸ö×Ö½ÚÊý¾Ý
//1ÏÔʾ°×É« 0²»ÏÔʾ
void Byte_Send_595_Up(u8 dat)
{
u8 i;
for(i=0; i<8; i++)
{
dat <<= 1;
R1_LED=0;
R2_LED=0;//¹Ø±ÕÏ°ëÆÁÄ»ÏÔʾ
G1_LED=0;
G2_LED=0;//¹Ø±ÕÏ°ëÆÁÄ»ÏÔʾ
B1_LED=CY;
B2_LED=0;//¹Ø±ÕÏ°ëÆÁÄ»ÏÔʾ
CLK_LED=1;
_nop_();
_nop_();
CLK_LED=0;
}
}
//
void Byte_Send_595_Down(u8 dat)
{
u8 i;
for(i=0; i<8; i++)
{
dat <<= 1;
R1_LED=0;
R2_LED=0;//¹Ø±ÕÏ°ëÆÁÄ»ÏÔʾ
G1_LED=0;
G2_LED=CY;//¹Ø±ÕÏ°ëÆÁÄ»ÏÔʾ
B1_LED=0;
B2_LED=0;//¹Ø±ÕÏ°ëÆÁÄ»ÏÔʾ
CLK_LED=1;
_nop_();
_nop_();
CLK_LED=0;
}
}
//ʹÓÃÓ²¼þPWM0
void PCA_PWM0_Init(void)
{
CCON=0;//³õʼ»¯PCA¼Ä´æÆ&pide; Çå³þ²¢¸´Î»
CL=0;//PCA¼ÆÊýÆ&pide;µÍλ¸´Î»
CH=0;//PCA¼ÆÊýÆ&pide;¸ßλ¸´Î»
CMOD=0X02;//PCA/PWMµÄʱÖÓÔ´ÊÇSYS£¬²»Óö¨Ê±Æ&pide;0£¬PWMµÄʱÖÓÔ´2·ÖƵ
CCAP0L=CCAP0H=0X40;
CCAPM0=0X42;//8λPWM ÎÞÖжÏ
CR=1;
}
////ÉÏ°ëÆÁÄ»
////»µãº¯Êý
////yÁÐ n=1ÏÔʾ n=0²»ÏÔʾ
//void Draw_Point_Led(y)
//{
// u8 k,m,z,temp;
// k=y/8;//Ëã³öµÚ¼¸¸ö×Ö½Ú
// temp=zifu[k];
// m=y%8;//×ֽڵĵڼ¸Î»
// zifu[k]=((temp|0x80)>>m);
// for(z=0;z<8;z++)
// Byte_Send_595(zifu[z]);
// STB_LED=0;
// STB_LED=1;
//// Choose_Hang(x);
//}
//»16*32ͼƬ ÉÏ°ëÆÁÄ»
void Draw_Pic_Up()
{
u8 i,j,k;
for(k=0;k<16;k++)
{
for(i=0;i<16;i++)
{
for(j=0;j<8;j++)
{
Byte_Send_595_Up(pic[i][j]);
}
OE_LED=1;
STB_LED=1;
Choose_Hang(i);
STB_LED=0;
OE_LED=0;
}
}
}
void Draw_Pic_Down()
{
u8 i,j,k;
for(k=0;k<16;k++)
{
for(i=0;i<16;i++)
{
for(j=0;j<8;j++)
{
Byte_Send_595_Down(pic[i][j]);
}
OE_LED=1;
STB_LED=1;
Choose_Hang(i);
STB_LED=0;
OE_LED=0;
}
}
}
void main()
{
P0M0=0XFF; P0M1=0X00;//P0¿ÚÍÆÍêÊä³ö
P1M0=0XFF; P1M1=0X00;//P1¿ÚÍÆÍêÊä³ö
P2M0=0XFF; P2M1=0X00;//P2¿ÚÍÆÍêÊä³ö
//PCA_PWM0_Init();
while(1) {
Draw_Pic_Up();
}
}
效果图: