74HC595驱动两位数码管程序Word版
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
/*==================================================================== ====================================================================== ==*/
/*============================================================================= ==============================================================*/
#include<reg52.h>
#include <math.h>
#include <intrins.h>
#include<string.h>
#include<stdio.h>
#define unchar unsigned char
#define unint unsigned int
#define unlong unsigned long
/*============================================================================= ==============================================================*/
/*============================================================================= ==============================================================*/
#define dmx_total_data 3
#define DMAX 101
#define DMIN 0
#define CONTIME_T1 20000
#define CONTIME_T3 200
#define CONTIME_T2 100
#define TIME0 256-17
#define BUTTON1 1
#define BUTTON2 2
sfr WDT_CONTR =0XE1;
sfr ISP_DATA =0XE2;
sfr ISP_ADDRH =0XE3;
sfr ISP_ADDRL =0XE4;
sfr ISP_LMD =0XE5;
sfr ISP_TRIG =0XE6;
sfr ISP_CONTR =0XE7;
sfr P1M0 =0X91;
sfr P1M1 =0X92;
sfr AUXR =0X8E;
unint data I_address;
unint data dis_Addr_Rg;
unint data dis_Addr_Rg;
unchar data Counter = 10;
sbit an_DOWN =P3^7;
sbit an_UP =P1^4;
sbit sdo =P1^7;
sbit clk =P1^6;
sbit stb =P1^5;
sbit Bd_flg_RT =P3^4;
unchar data dis[ ];
unsigned code disp[10]={0xA0,0xF9,0xC4,0xD0,0x99,0x92,0x82,0xF8,0x80,0x90};
/*-------------------------------------------------------------------------------------------------------------------*/
void delay10ms(void)
{
unsigned char i,j;
for(i=20;i>0;i--)
for(j=248;j>0;j--);
}
//-------------按键延时---------------//
void ButtonDelay(void)
{
unchar i,j;
for(i = 0; i++; i < 50)
for(j = 0; j++; j < 200);
}
/*--------------------------------------------------------------------------------------------------*/
unchar ButtonScan (void)
{
unchar ButtonNum = 0;
if(P3^4 == 0)
{
/*延时防止按键抖动,如果晶振是12M的话。
如果是其他的只要让延时在30ms就可以了*/
ButtonDelay();
if(P3^4 == 0)
{
I_address++;
if (I_address==100)
{
I_address== 0;
}
}
while(!P3^4); /*等待按键松开*/
ButtonDelay();
ButtonNum = an_UP;
}
if(P1^7 == 0)
{
ButtonDelay();
if(P1^7 == 0)
{
I_address--
if (I_address==100)
{
I_address== 0;
}
}
while(!P1^7); /*等待按键松开*/
ButtonDelay();
ButtonNum = an_DOWN ;
}
return ButtonNum;
}
/*
--------------------------------------------------------------------------------------------------------------------------------------------------------*/
void diss (unsigned char Data)
{
unchar i;
for(i=0;i<8;i++);
{
clk=0;
sdo=Data&0x80;
Data<<=1;
_nop_();
_nop_();
clk=1;
_nop_();
_nop_();
}
stb=0;
_nop_();
_nop_();
stb=1;
}
/*--------------------------------------------------------------------------------------------------------------------------*/
void display(void)
{
unchar num1,num2;
num1=I_address/10;
num2=I_address%10;
diss(disp[num1]);
delay10ms();
diss(disp[num2]);
delay10ms();
}
/*-------------------------------------------------------------------------------------------------------------------------------*/
void main(void)
{
while(1)
{
display(disp);
ButtonScan(I_address);
}
}
(注:可编辑下载,若有不当之处,请指正,谢谢!)。