單片機(jī)C語(yǔ)言實(shí)例-132-雙色點(diǎn)陣雙色交替動(dòng)態(tài)顯示
內(nèi)容:使用hc595驅(qū)動(dòng)雙色點(diǎn)陣
------------------------------------------------*/
#include<reg52.h> //包含頭文件,一般情況不需要改動(dòng),頭文件包含特殊功能寄存器的定義
#include <intrins.h>
unsigned char segout[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; //8列
unsigned char code tab[96]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //空格
0x00,0x7E,0xFF,0xC3,0xC3,0xFF,0x7E,0x00, //字符0
0x00,0x00,0x43,0xFF,0xFF,0x03,0x00,0x00, //字符1
0x00,0x63,0xC7,0xCF,0xDB,0xF3,0x63,0x00, //字符2
0x00,0x42,0xDB,0xDB,0xDB,0xFF,0x66,0x00, //字符3
0x00,0x3E,0x46,0xFF,0xFF,0x06,0x06,0x00, //字符4
0x00,0xF6,0xF7,0xD3,0xD3,0xDF,0xDE,0x00, //字符5
0x00,0x7E,0xFF,0xDB,0xDB,0xDF,0x4E,0x00, //字符6
0x00,0xC0,0xC0,0xC7,0xFF,0xF8,0xC0,0x00, //字符7
0x00,0xFF,0xFF,0xDB,0xDB,0xFF,0xFF,0x00, //字符8
0x00,0x72,0xFB,0xDB,0xDB,0xFF,0x7E,0x00, //字符9
0x00,0x00,0x00,0x00,0x00,0x00,0x00,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;
/*------------------------------------------------
uS延時(shí)函數(shù),含有輸入?yún)?shù) unsigned char t,無(wú)返回值
unsigned char 是定義無(wú)符號(hào)字符變量,其值的范圍是
0~255 這里使用晶振12M,精確延時(shí)請(qǐng)使用匯編,大致延時(shí)
長(zhǎng)度如下 T=tx2+5 uS
------------------------------------------------*/
void DelayUs2x(unsigned char t)
{
while(--t);
}
/*------------------------------------------------
mS延時(shí)函數(shù),含有輸入?yún)?shù) unsigned char t,無(wú)返回值
unsigned char 是定義無(wú)符號(hào)字符變量,其值的范圍是
0~255 這里使用晶振12M,精確延時(shí)請(qǐng)使用匯編
------------------------------------------------*/
void DelayMs(unsigned char t)
{
while(t--)
{
//大致延時(shí)1mS
DelayUs2x(245);
DelayUs2x(245);
}
}
/*------------------------------------------------
發(fā)送字節(jié)程序
帶有方向參數(shù),可以選擇從高位節(jié)寫入或者低位寫入
------------------------------------------------*/
void SendByte(unsigned char dat,bit direction)
{
unsigned char i,temp;
if(direction==0)
temp=0x80;
else
temp=0x01;
for(i=0;i<8;i++)
{
SRCLK=0;
SER=dat&temp;
if(direction==0)
dat<<=1;
else
dat>>=1;
SRCLK=1;
}
}
/*------------------------------------------------
發(fā)送雙字節(jié)程序
------------------------------------------------*/
void Send2Byte(unsigned char dat1,unsigned char dat2,bit direction)
{
SendByte(dat1,direction);
SendByte(dat2,direction);
}
/*------------------------------------------------
595鎖存程序
------------------------------------------------*/
void Out595(void)
{
LATCH=0;
_nop_();
LATCH=1;
}
/*------------------------------------------------
發(fā)送位碼字節(jié)程序
使用另外一片單獨(dú)595
------------------------------------------------*/
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=0; //鎖存
_nop_();
LATCH_B=1;
}
/*------------------------------------------------
主程序
------------------------------------------------*/
void main()
{
unsigned char i,k,l;
while(1)
{
for(k=0;k<=88;k++) //所有的字符個(gè)數(shù)
for(l=20;l>0;l--) //延時(shí)長(zhǎng)度,改變此值可以改變流動(dòng)速度
for(i=0;i<=7;i++) //8列顯示
{
SendSeg(segout);
Send2Byte(~(*(tab+i+k)),0xff,0);
Out595();
DelayMs(1);
Send2Byte(0xff,0xff,0);//delay(10); //防止重影
Out595();
}
for(k=0;k<=88;k++) //所有的字符個(gè)數(shù)
for(l=20;l>0;l--) //延時(shí)長(zhǎng)度,改變此值可以改變流動(dòng)速度
for(i=0;i<=7;i++) //8列顯示
{
SendSeg(segout[7-i]);
Send2Byte(0xff,~(*(tab+i+k)),1); //寫入字節(jié)方向改變
Out595();
DelayMs(1);
Send2Byte(0xff,0xff,0);//delay(10); //防止重影
Out595();
}
}
}
更多詳情參考附件文檔
+08:00C132聯(lián)盟網(wǎng)8960.png (23.04 KB, 下載次數(shù): 1)
下載附件
保存到相冊(cè)
2022-1-13 10:11 上傳
游客,如果您要查看本帖隱藏內(nèi)容請(qǐng) 回復(fù)
|