//74HC138引脚:P22,P23,P24,P25,P26,P27
//24C02引脚:P20-SDA,P21-SCL
//red595:11脚-P10,12脚-P11,14脚-P12,13脚控制脚-P16
//green595:11脚-P13,12脚-P14,14脚-P15,13脚控制脚-P17
//74HC595:11脚SH_CP是数据输入时钟线,12脚ST_CP是输出存储器锁存时钟线,13脚OE是输出有效(低电平有效),14脚DS是串行数据输入
#include <intrins.h>
#include <REGX52.H>
#define uint unsigned int
#define uchar unsigned char
sbit saomiao1=P2^2;
sbit saomiao2=P2^3;
sbit saomiao3=P2^4;
sbit saomiao4=P2^5;
sbit saomiao5=P2^6;
sbit saomiao6=P2^7;
sbit redSH_CP=P1^0;
sbit redST_CP=P1^1;
sbit redOE=P1^6;
sbit redDS=P1^2;
sbit greenSH_CP=P1^3;
sbit greenST_CP=P1^4;
sbit greenOE=P1^7;
sbit greenDS=P1^5;
uchar a;
uchar code display[]=
{
0xF7,0xF6,0x31,0x47,0xF7,0xFF,0xFD,0x85,0xB5,0xB5,0xB5,0xB5,0xB5,0x85,0xFD,0xFF,
0xFD,0xFE,0x00,0xFF,0xFC,0xFF,0x00,0xB6,0xB6,0xB6,0x80,0xB6,0xB6,0xB6,0x00,0xFF
}; //福
void delay(uint b)//延时
{
while(b--);
}
void shuaxin(uchar a)//138译码器刷新列
{
switch(a)
{
case(1):
saomiao4=1;saomiao5=1;saomiao6=1; break;
case(2):
saomiao4=0;saomiao5=1;saomiao6=1; break;
case(3):
saomiao4=1;saomiao5=0;saomiao6=1; break;
case(4):
saomiao4=0;saomiao5=0;saomiao6=1; break;
case(5):
saomiao4=1;saomiao5=1;saomiao6=0; break;
case(6):
saomiao4=0;saomiao5=1;saomiao6=0; break;
case(7):
saomiao4=1;saomiao5=0;saomiao6=0; break;
case(8):
saomiao4=0;saomiao5=0;saomiao6=0; break;
case(9):
saomiao1=1;saomiao2=1;saomiao3=1; break;
case(10):
saomiao1=0;saomiao2=1;saomiao3=1; break;
case(11):
saomiao1=1;saomiao2=0;saomiao3=1; break;
case(12):
saomiao1=0;saomiao2=0;saomiao3=1; break;
case(13):
saomiao1=1;saomiao2=1;saomiao3=0; break;
case(14):
saomiao1=0;saomiao2=1;saomiao3=0; break;
case(15):
saomiao1=1;saomiao2=0;saomiao3=0; break;
case(16):
saomiao1=0;saomiao2=0;saomiao3=0; break;
default :break;
}
}
void Init_red595(uchar valueL,uchar valueH)//红色595发送函数初始化
{
uchar i;
for(i=0;i<8;i++)
{
redDS=valueL>>7;//把valueL最高位的值赋给redDS
valueL<<=1;//把valueL原来的值左移一位,再赋值给valueL,(有赋值操作,所以会改变原先的值)多出来的最低位自动用0来填充,valueL的最高位发送出去
redSH_CP=0;
_nop_();
_nop_();
redSH_CP=1;
}
for(i=0;i<8;i++)
{
redDS=valueH>>7;
valueH<<=1;
redSH_CP=0;
_nop_();
_nop_();
redSH_CP=1;
}
redST_CP=0;
_nop_();
_nop_();
redST_CP=1;
}
void red_send()//发送红色点阵数据
{
uint index;
greenOE=1;//绿色595输出不使能
for(index=1;index<17;index++)
{
redOE=1;//红色595输出不使能
shuaxin(index);//138译码器刷新
Init_red595(display[index+16],display[index]);//带入红色点阵要发送的数据
redOE=0;//红色595输出使能
delay(500);
}
}
void Init_green595(uchar valueL,uchar valueH)//绿色595发送函数初始化
{
uchar i;
for(i=0;i<8;i++)
{
greenDS=valueL>>7;
valueL<<=1;
greenSH_CP=0;
_nop_();
_nop_();
greenSH_CP=1;
}
for(i=0;i<8;i++)
{
greenDS=valueH>>7;
valueH<<=1;
greenSH_CP=0;
_nop_();
_nop_();
greenSH_CP=1;
}
greenST_CP=0;
_nop_();
_nop_();
greenST_CP=1;
}
void green_send()//发送绿色点阵数据
{
uint index;
redOE=1;//红色595输出不使能
for(index=1;index<17;index++)
{
greenOE=1;//绿色595输出不使能
shuaxin(index);//138译码器刷新
Init_green595(display[index+16],display[index]);//带入绿色点阵要发送的数据
greenOE=0;//绿色595输出使能
delay(500);
}
}
void main()
{
while(1)
{
red_send();//红色显示
//green_send();//绿色显示
}
}