以下是ps7219.h文件源码:#define addr_bit_1 0x01
#define addr_bit_2 0x02
#define addr_bit_3 0x03
#define addr_bit_4 0x04
#define addr_bit_5 0x05
#define addr_bit_6 0x06
#define addr_bit_7 0x07
#define addr_bit_8 0x08
#define addr_trans_mode 0x09
#define addr_light_con 0x0a
#define addr_scan_count 0x0b
#define addr_close 0x0c
#define addr_echo_test 0x0d
sbit ps7219_pin_RST = P1^4;
sbit ps7219_pin_LOAD = P1^5;
sbit ps7219_pin_DIN = P1^6;
sbit ps7219_pin_CLK = P1^7;
void ps7219_init();
void ps7219_reset();
void ps7219_echo(unsigned char da_1 da_2 da_3 da_4);
void ps7219_send_data(unsigned char addr da);
void ps7219_delay(void);
以下是ps7219.c文件源码:#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_reset();
ps7219_send_data(addr_scan_count 0 0 0 0 ps7219_echo(unsigned char da_1 da_2 da_3 da_4)
{
ps7219_send_data(0x01 da_1);
ps7219_send_data(0x02 da_2);
ps7219_send_data(0x03 da_3);
ps7219_send_data(0x04 da_4);
}
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_CLK=1;
ps7219_pin_LOAD=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++)
{}
}