c51 74ls164--165--595
164跑馬燈,
#include
#include
#define uint unsigned int
#define uchar unsigned char
sbit dat=P2^6;
sbit clk=P2^7;
uchar ii;
uchar code seg7code[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x00,0xff};//0-9,-,全滅
void sendbyte(uchar seg)
{
uchar num,c;
num=seg7code[seg];
for(c=0;c<8;c++)
{
dat=num&0x80;
num=_crol_(num,1);
clk=0;
clk=1;
}
}
void delayms(int ms)
{
uchar mi,mj;
for(;ms>0;ms--)
for(mi=6;mi>0;mi--)
for(mj=82;mj>0;mj--);
}
void main()
{
for(ii=0;ii<10;ii++)
{
sendbyte(ii);
delayms(200);
}
}
////////*****************以下為參考
#include
#define uint unsigned int
#define uchar unsigned char
sbit dat=P2^6;
sbit clk=P2^7;
uchar ii;
uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff};//0-9,-,全滅
void sendbyte(uchar byte)
{
uchar num,c;
num=tab[byte];
for(c=0;c<8;c++)
{
dat=num&0x80;
num=num<<1;
clk=0;
clk=1;
}
}
void display(uint i) //顯示字符序號
{
uchar j,k;
j=i/10;
k=(i-10*j);
sendbyte(k);
sendbyte(j);
}
void delayms(int ms) //1ms delay
{
uchar mi,mj;
for(;ms>0;ms--)
for(mi=6;mi>0;mi--)
for(mj=82;mj>0;mj--);
}
void main()
{
while(1)
{
for(ii=12;ii>0;ii--)
{
display(tab[ii]);
delayms(200);
}
}
}
參考以下資料
作者:龍嘯蒼天
發(fā)表時(shí)間:2007-1-6 16:44:18
74hc595的c51驅(qū)動(dòng)程序
帶鎖存功能的串入并出芯片。這里給出74hc595的c51驅(qū)動(dòng)程序。
//作者:曬太陽的小豬
//個(gè)人blog:http://emcu.c51bbs.com
//轉(zhuǎn)載使用請注明
//定時(shí)器晶體振蕩器11.0592M.
#i nclude
#i nclude
#define uint unsigned int
#define uchar unsigned char
#define nop() _nop_();_nop_();
sbit CLK=P2^0;
sbit DAT=P2^1;
sbit RCLK=P2^2;
//sbit CS=P2^3;
uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff};//0-9,-,全滅
void sendbyte(uchar byte)
{
uchar num,c;
num=tab[byte];
for(c=0;c<8;c++)
{
CLK=0;
DAT=num&0x80;
num=num<<1;
CLK=1;
}
// RCLK=0;
// nop();
// nop();
// RCLK=1;
}
void out595(void)
{
RCLK=0;
nop();
RCLK=1;
}
void display(uchar word)
{
uchar i,j;
i=word/10;
j=word-10*i;
sendbyte(j);
sendbyte(i);
out595();
}
main()
{
while(1)
{
display(19);
display(86);
}
while(1);
}
74hc165的驅(qū)動(dòng)程序
//74hc165是常用的并入串出芯片,這里給出74hc165的驅(qū)動(dòng)程序
//作者:曬太陽的小豬
//個(gè)人blog:http://emcu.c51bbs.com
//轉(zhuǎn)載使用請注明
//--------------3片74hc165級連讀程序---------
/*void read74hc165m(void)
{
uchar basic,basic1,basic2,basic3,c;
PL=1;
nop();
PL=0;
nop();
PL=1;
basic=0;
basic=basic<<1;
if(SETBSC) basic|=0x01;
for(c=0;c<7;c++)
{
CLOCK=0;
nop();
CLOCK=1;
basic=basic<<1;
if(SETBSC) basic|=0x01;
}
basic1=basic;
basic=0;
for(c=0;c<8;c++)
{
CLOCK=0;
nop();
CLOCK=1;
basic=basic<<1;
if(SETBSC) basic|=0x01;
}
basic2=basic;
basic=0;
for(c=0;c<8;c++)
{
CLOCK=0;
nop();
CLOCK=1;
basic=basic<<1;
if(SETBSC) basic|=0x01;
}
basic3=basic;
}
74hc164的驅(qū)動(dòng)程序
74hc64很簡單的串入并出芯片。經(jīng)常用于單片機(jī)端口的擴(kuò)展。這里給出使用74hc164驅(qū)動(dòng)數(shù)碼管,做靜態(tài)顯示的程序??梢灾苯诱{(diào)用
//作者:曬太陽的小豬
//個(gè)人blog:http://emcu.c51bbs.com
//轉(zhuǎn)載使用請注明
#i nclude
#define uint unsigned int
#define uchar unsigned char
sbit dat=P2^6;
sbit clk=P2^7;
uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff};//0-9,-,全滅
void sendbyte(uchar byte)
{
uchar num,c;
num=tab[byte];
for(c=0;c<8;c++)
{dat=num&0x80;
num=num<<1;
clk=0;
clk=1;
}
}
void display(uint i)
{uchar j,k,l,m;
j=i/10;
k=(i-10*j);
sendbyte(k);
sendbyte(j);
}