?? prog.c
字號:
#include "reg51.h"
#include "math.h"
#include "string.h"
#include "intrins.h"
#define uchar unsigned char
#define high 1/* 高電平 */
#define low 0 /* 低電平 */
//sbit Dat4094=P1^4;/* 4094A數(shù)據(jù)*/
// sbit En=P1^5; /* 使能 */
sbit ESS=P1^6;//數(shù)據(jù)腳
sbit clk=P1^3;//時鐘
sbit storge=P1^1;//鎖存
//uchar code LED_acess[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//LED段碼0,1,2,3,4,5,6,7,8,9
uchar code LED_acess[10]={0x04,0x1f,0x22,0x0a,0x19,0x48,0x40,0x1e,0x00,0x08};//LED段碼0,1,2,3,4,5,6,7,8,9
uchar idata a[6];
uchar time_NUM;
//uchar s ;
long int time_con;
long int time_T;
bit flag;
//函數(shù)申明
void Clock(void);
// void Sclock(void);
void Delay(uchar us);/*延時 us 微秒*/
void SendDate(uchar dat1);
void Init(void);
void show(void);
void Delay(uchar us)/*延時函數(shù)*/
{
uchar time;
for(time=us;time>0;time--);
}
void Clock(void) /*時鐘上升沿函數(shù)*/
{
clk=low;
Delay(2);
clk=high;
Delay(2);
}
//void Sclock(void) /*鎖存時鐘上升沿函數(shù)*/
//{
// sclk=low;
// Delay(2);
// sclk=high;
// Delay(2);
//}
void SendData(uchar dat1) /*給74HC595發(fā)數(shù)據(jù)函數(shù)*/
{
uchar numBIT;
for(numBIT=0;numBIT<8;numBIT++)
{
if(dat1&0x80)
ESS=low;
else
ESS=high;
dat1= _crol_(dat1,1);
Clock();
}
}
void show(void) /*調(diào)LED顯屏顯示函數(shù)*/
{
uchar num;
storge=low;
for(num=0;num<6;num++)
{
if(flag)
SendData(LED_acess[a[num]]|0x80);
else
SendData(LED_acess[a[num]]);
}
storge=high;
}
void Time0(void) interrupt 1 using 0 /*定時器0中斷*/
{
EA=0;
TH0=0x3c;/*五十毫秒*/
TL0=0xb0;
time_NUM++;
EA=1;
}
void Init(void) /*初始化函數(shù)*/
{
// WDTRST=0x1e;
IE=IE|0x82;
TMOD=TMOD|0x01;
TH0=0x3c;/*五十毫秒*/
TL0=0xb0;
TR0=1;
time_con=57600;
show();
P0=0Xfe;
/* CHPENR=0x87;
CHPENR=0x59;
CHPCON=CHPCON|0x10;
CHPENR=0X00; 片外存儲器使能*/
}
void mul_time(void)
{
time_con++;
time_T=time_con;
a[5]=time_T%10;
time_T=time_T/10;
a[4]=time_T%6;
time_T=time_T/6;
a[3]=time_T%10;
time_T=time_T/10;
a[2]=time_T%6;
time_T=time_T/6;
a[1]=time_T%10;
a[0]=time_T/10;
}
void main(void) /*主函數(shù)*/
{
Init();
while(1)
{
if(time_NUM>=20)
{
time_NUM=0;
mul_time();
flag=!flag;
}
show();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -