單片機(jī)雙色點(diǎn)陣顯示1種顏色
#include
#include
//unsigned char segout[8]={0,1,2,3,4,5,6,7}; //8列
unsigned char segout[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; //8列
unsigned char code tab[]={
0x00,0x6C,0x92,0x82,0x44,0x28,0x10,0x00
};
sbit LATCH = P1^0;
sbit SRCLK= P1^1;
sbit SER = P1^2;
//公共端信號控制
sbit LATCH_B = P2^2;
sbit SRCLK_B= P2^1;
sbit SER_B= P2^0;
void DelayUs2x(unsigned char t)
{
while(--t);
}
void DelayMs(unsigned char t)
{
while(t--)
{
//大致延時1mS
DelayUs2x(245);
DelayUs2x(245);
}
}
void SendByte(unsigned char dat)
{
unsigned char i;
for(i=0;i<8;i++)
{
SRCLK=0;
SER=dat&0x80;
dat<<=1;
SRCLK=1;
}
}
void Send2Byte(unsigned char dat1,unsigned char dat2)
{
SendByte(dat1);
SendByte(dat2);
}
void Out595(void)
{
LATCH=1;
_nop_();
LATCH=0;
}
void SendSeg(unsigned char dat)
{
unsigned char i;
for(i=0;i<8;i++) //發(fā)送字節(jié)
{
SRCLK_B=0;
SER_B=dat&0x80;
dat<<=1;
SRCLK_B=1;
}
LATCH_B=1; //鎖存
_nop_();
LATCH_B=0;
}
void main()
{
unsigned char i;
while(1)
{
for(i=0;i<8;i++) //8列顯示
{
SendSeg(segout[i]);
Send2Byte(~tab[i],0xff);
Out595();
DelayMs(1);
Send2Byte(0xff,0xff);//delay(10); //防止重影
Out595();
}
}
}