#include "reg51.h"
#include "ps7219.h"
/*void ps7219_reset()
{
unsigned char i;
ps7219_pin_RST=0;
for(i=0;i<125;i++)
ps7219_delay();
ps7219_pin_RST=1;
for(i=0;i<255;i++)
ps7219_delay();
ps7219_pin_RST=0;
for(i=0;i<125;i++)
ps7219_delay();
}
*/
void ps7219_init()
{ ps7219_send_data(addr_close,0x01);
ps7219_send_data(addr_scan_count,0x03);
ps7219_send_data(addr_light_con,0x09);
ps7219_send_data(addr_trans_mode,0xff);
}
void ps7219_echo(unsigned char add)
{ unsigned char i;
ps7219_send_data(add,0x30); for(i=0;i<125;i++)
ps7219_delay();ps7219_delay();
ps7219_send_data(add,0x6d); for(i=0;i<125;i++) ps7219_delay();
ps7219_send_data(add,0x79); for(i=0;i<125;i++)ps7219_delay();
ps7219_send_data(add,0x33);for(i=0;i<125;i++) ps7219_delay();
ps7219_send_data(add,0x5b);for(i=0;i<125;i++) ps7219_delay();
ps7219_send_data(add,0x5f);for(i=0;i<125;i++)ps7219_delay();
ps7219_send_data(add,0x70); for(i=0;i<125;i++)ps7219_delay();
ps7219_send_data(add,0xff); for(i=0;i<125;i++)ps7219_delay();
ps7219_send_data(add,0x73); for(i=0;i<125;i++)ps7219_delay();
ps7219_send_data(add,0x7e); for(i=0;i<125;i++)ps7219_delay();
ps7219_send_data(add,0x77); for(i=0;i<125;i++)ps7219_delay();
ps7219_send_data(add,0x1f); for(i=0;i<125;i++)ps7219_delay();
ps7219_send_data(add,0x4e);for(i=0;i<125;i++) ps7219_delay();
ps7219_send_data(add,0x3d); for(i=0;i<125;i++) ps7219_delay();
ps7219_send_data(add,0x4f); for(i=0;i<125;i++) ps7219_delay();
ps7219_send_data(add,0x47); for(i=0;i<125;i++) ps7219_delay();
}
void ps7219_send_data(unsigned char addr,da)
{
unsigned char i,byte_out;
byte_out=addr;
ps7219_pin_DIN=1;
ps7219_pin_CLK=1;
ps7219_pin_LOAD=0;
for(i=0;i<8;i++)
{
ps7219_pin_CLK=1;
ps7219_pin_DIN=(bit)(byte_out&0x80);
byte_out=byte_out<<1;
ps7219_pin_CLK=0;
ps7219_delay();
}
ps7219_pin_CLK=1;
byte_out=da;
for(i=0;i<7;i++)
{
ps7219_pin_CLK=1;//时钟信号
ps7219_pin_DIN=(bit)(byte_out&0x80);
byte_out=byte_out<<1;
ps7219_pin_CLK=0;
ps7219_delay();
}
ps7219_pin_LOAD=1;//得出最后一位时要把load变为1。不然会数据丢失.
ps7219_pin_CLK=1;
ps7219_pin_DIN=(bit)(byte_out&0x80);
ps7219_pin_CLK=0;
ps7219_delay();
ps7219_pin_CLK=1;
}
void ps7219_delay(void)
{
unsigned char i;
for(i=0;i<125;i++)
{}
}
void main()
{
ps7219_init();
ps7219_send_data(addr_test,0x01);
while(1)
{ps7219_init();
ps7219_echo(0x02);
ps7219_echo(0x03);ps7219_echo(0x04);ps7219_echo(0x01);}
}
这是用MAX7219的程序。
为什么没反应啊??? |