STC15单片机基于74HC595和TM1637的两种LED程序.docx

上传人:b****2 文档编号:1851856 上传时间:2022-10-24 格式:DOCX 页数:8 大小:15.53KB
下载 相关 举报
STC15单片机基于74HC595和TM1637的两种LED程序.docx_第1页
第1页 / 共8页
STC15单片机基于74HC595和TM1637的两种LED程序.docx_第2页
第2页 / 共8页
STC15单片机基于74HC595和TM1637的两种LED程序.docx_第3页
第3页 / 共8页
STC15单片机基于74HC595和TM1637的两种LED程序.docx_第4页
第4页 / 共8页
STC15单片机基于74HC595和TM1637的两种LED程序.docx_第5页
第5页 / 共8页
点击查看更多>>
下载资源
资源描述

STC15单片机基于74HC595和TM1637的两种LED程序.docx

《STC15单片机基于74HC595和TM1637的两种LED程序.docx》由会员分享,可在线阅读,更多相关《STC15单片机基于74HC595和TM1637的两种LED程序.docx(8页珍藏版)》请在冰豆网上搜索。

STC15单片机基于74HC595和TM1637的两种LED程序.docx

STC15单片机基于74HC595和TM1637的两种LED程序

敬告:

没有51单片机基础的人请慎重下载

高质量实用性51单片机STC15W系列程序(6),STC8A系列可参考

STC15单片机基于74HC595和TM1637的两种LED程序

//第一种(74HC595):

#include

#include

sbitSCLK=P2^0;

sbitRCLK=P2^1;

sbitDIO=P2^2;

unsignedcharcodeled_code[]=

{//0123456789

//bCdEF-

0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0xbf

};

unsignedcharcodeled_num[]={0x01,0x02,0x04,0x08};

voidSelect_Position(unsignedchar*buf);

unsignedcharrec[4];

bitflag=0;

voidTimer0_config(unsignedintms);

voidmain()

{

unsignedchartmpbuf[16]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};

P2M1&=0xF8;P2M0&=0xF8;

Timer0_config

(1);

EA=1;

while

(1)

{

if(flag)

{

flag=0;

Select_Position(tmpbuf);

}

}

}

voidDisplay_byte(unsignedchardat)

{

unsignedcharmask;

for(mask=0x80;mask!

=0;mask>>=1)

{

if((dat&mask)==0)

DIO=0;

else

DIO=1;

SCLK=0;

SCLK=1;

}

}

voidSelect_Position(unsignedchar*buf)

{

staticunsignedcharj=0;

staticunsignedchari=0;

//for(j=0;j<4;j++)

//{

rec[j]=*(buf[i]+led_code);

Display_byte(rec[j]);

Display_byte(led_num[j]);

i++;

j++;

i=i&0x0F;

j=j&0x03;

RCLK=0;

RCLK=1;

//}

}

//voidSelect_Position(unsignedchar*buf)

//{

////staticunsignedchark;

////staticunsignedchari;

//unsignedcharj;

//unsignedcharrec;

//for(j=0;j<4;j++)

//{

//rec=*(buf[j]+led_code);

//Display_byte(rec);

//Display_byte(led_num[j]);

////i=i&0x0F;

////k=k&0x03;

//

//RCLK=0;

//RCLK=1;

//}

//}

voidTimer0_config(unsignedintms)

{

unsignedlongtmp;

tmp=11059200/12;

tmp=(tmp*ms)/1000;

tmp=65536-tmp;

TH0=(unsignedchar)(tmp>>8);

TL0=(unsignedchar)tmp;

TMOD&=0xF0;

AUXR&=0x7F;

ET0=1;

TR0=1;

}

 

voidTimer0_interrupt()interrupt1

{

unsignedinttmr10ms;

tmr10ms++;

if(tmr10ms>=500)

{

tmr10ms=0;

flag=1;

}

}

/******************************************************/

//第二种(TM1637):

//TM1637程序:

#include"Library.h"

voidDelay_us()

{

_nop_();

_nop_();

_nop_();

}

voidStart()

{

CLK=1;

DIO=1;

Delay_us();

DIO=0;

Delay_us();

CLK=0;

}

voidStop()

{

CLK=0;

DIO=0;

Delay_us();

CLK=1;

Delay_us();

DIO=1;

Delay_us();

}

bitWrite_btye(unsignedchardat)

{

bitack;

unsignedcharmask;

for(mask=0x01;mask!

=0;mask<<=1)

{

CLK=0;

if(dat&mask)

DIO=1;

else

DIO=0;

CLK=1;

}

CLK=0;

Delay_us();

CLK=1;

ack=DIO;

Delay_us();

CLK=0;

return~ack;

}

voidWrite_dat(unsignedchar*dat,unsignedcharlen)

{

bitack;

do{

Start();

ack=Write_btye(0x40);

}while(!

ack);

Start();

Write_btye(0xC0);

while(len>0)

{

Write_btye(*dat++);

len--;

}

Start();

Write_btye(0x8F);//ÏÔʾ¿ª

Stop();

}

//main.c

#include"Library.h"

unsignedcharcodecodenum[16]={

0x3F,0x06,0x5B,0x4F,

0x66,0x6D,0x7D,0x07,

0x7F,0x67,0x77,0x7C,

0x39,0x5E,0x79,0x71

};

bitflag=0;

voidTimer0_config(unsignedintms);

voidmain()

{

//unsignedcharcodebuf[4]={0x39,0x5E,0x79,0x71};

unsignedchari=0;

P2M1&=0xFC;P2M0&=0xFC;

Timer0_config

(1);

EA=1;

while

(1)

{

if(flag)

{

flag=0;

Write_dat(codenum+i,4);

i++;

if(i>=13)

{

i=0;

}

}

}

}

voidTimer0_config(unsignedintms)

{

unsignedlongtmp;

tmp=MAIN_Fosc/12;

tmp=(tmp*ms)/1000;

tmp=65536-tmp;

TH0=(unsignedchar)(tmp>>8);

TL0=(unsignedchar)tmp;

TMOD&=0xF0;

AUXR&=0x7F;

ET0=1;

TR0=1;

}

voidTimer0_interrupt()interrupt1

{

unsignedinttmr10ms;

tmr10ms++;

if(tmr10ms>=500)

{

tmr10ms=0;

flag=1;

}

}

//Library.h

#ifndef_Library_H

#define_Library_H

#include

#include

#defineMAIN_Fosc11059200L

sbitCLK=P2^1;

sbitDIO=P2^0;

voidWrite_dat(unsignedchar*dat,unsignedcharlen);

#endif

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > IT计算机 > 电脑基础知识

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1