|
这两天在proteus上弄了个16*64点阵,8个595级联实现。现在想调节整屏的灰度,实现8级或16级灰度,论坛里有人说是控制595的OE使能端,但我还是不明白具体怎么个控制法,希望高手能指点下,感激不尽!Keil工程文件和Proteus电路图已放在压缩包里。
原理图:
![](http://cache.amobbs.com/bbs_upload782111/files_17/ourdev_473291.JPG)
(原文件名:全图.JPG)
点击此处下载 ourdev_473292.rar(文件大小:69K) (原文件名:16×64LED.rar)
源代码如下:
/*************************************************/
#include<reg51.h>
/*************************************************/
#define uchar unsigned char
sbit hc595_ds=P2^0; //管脚定义
sbit hc595_shcp=P2^1;
sbit hc595_stcp=P2^2;
sbit hc595_oe=P2^3;
/*************************************************/
uchar code table1[]={0x08,0x00,0x08,0x08,0x1F,0xFC,0x11,0x00,
0x21,0x00,0x41,0x10,0x1F,0xF8,0x11,0x00,
0x11,0x00,0x11,0x04,0xFF,0xFE,0x01,0x00,
0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00}; //年
uchar code table2[]={0x01,0x00,0x01,0x00,0x01,0x00,0x09,0x20,
0x09,0x10,0x11,0x0C,0x11,0x04,0x21,0x10,
0x41,0x10,0x01,0x20,0x01,0x40,0x00,0x80,
0x01,0x00,0x02,0x00,0x0C,0x00,0x70,0x00}; //少
uchar code table3[]={0x00,0x08,0x3F,0xFC,0x20,0x00,0x28,0x08,
0x24,0x18,0x22,0x20,0x21,0x40,0x20,0x80,
0x21,0x40,0x22,0x30,0x24,0x18,0x28,0x08,
0x20,0x00,0x20,0x04,0x3F,0xFE,0x00,0x00}; //区
uchar code table4[]={0x04,0x80,0x04,0x80,0x04,0x88,0x04,0x98,
0x04,0xA0,0x7C,0xC0,0x04,0x80,0x04,0x80,
0x04,0x80,0x04,0x80,0x04,0x80,0x04,0x80,
0x1C,0x82,0xE4,0x82,0x44,0x7E,0x00,0x00}; //北
/*************************************************/
void hc595_write_data(uchar data_ds); //数据移位到595移位寄存器
void hc595_display(); //数据锁存到595存储寄存器,并送到8位并口输出
void delay(int n); //延时
/*************************************************/
void main()
{
uchar i;
hc595_oe=0;
while(1)
{
for(i=0;i<16;i++)
{
hc595_write_data(table1[2*i]); //写数据到595移位寄存器,一共8个595
hc595_write_data(table1[2*i+1]);
hc595_write_data(table2[2*i]);
hc595_write_data(table2[2*i+1]);
hc595_write_data(table3[2*i]);
hc595_write_data(table3[2*i+1]);
hc595_write_data(table4[2*i]);
hc595_write_data(table4[2*i+1]);
//hc595_oe=1; //关显示
P1=i;P3=i; //选择要扫描的行
hc595_display(); //数据锁存到595存储寄存器,并送到8位并口输出
//hc595_oe=0; //输出允许,开显示
delay(100);
}
}
}
/*************************************************/
void hc595_write_data(uchar data_ds)
{
uchar n_bit;
for(n_bit=0;n_bit<8;n_bit++)
{
hc595_shcp=0;
hc595_ds=data_ds&(1<<n_bit);
hc595_shcp=1;
}
}
/*************************************************/
void hc595_display()
{
hc595_stcp=0;
delay(1);
hc595_stcp=1;
}
/*************************************************/
void delay(int n)
{
while(n--);
}
/*************************************************/ |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|