標題: 51單片機數(shù)碼管動態(tài)100遞減程序 [打印本頁]
作者: daniu 時間: 2014-12-27 13:07
標題: 51單片機數(shù)碼管動態(tài)100遞減程序
#include <REG51.H>-
#define uchar unsigned char-
#define uint unsigned int-
sbit cun_1=P0^6;//段選的鎖存器使能端;-
sbit cun_2=P0^7;//位選的鎖存器使能端;-
uchar num,a,bai,shi,ge;-
void delay(uint z);-
void display(uchar bai,uchar shi,uchar ge);-
void init();-
uchar code table[]={-
0x3f,0x06,0x5b,0x4f,-
0x66,0x6d,0x7d,0x07,-
0x7f,0x6f,0x77,0x7c,-
0x39,0x5e,0x79,0x71};-
main()-
{-
init();-
while(1)-
{ -
if(a==20)-
{-
a=0;-
num--;-
if(num==0)-
num=100;-
bai=num/100;-
shi=num%100/10;-
ge=num%10;-
}-
display(bai,shi,ge);-
}-
}-
void display(uchar bai,uchar shi,uchar ge)-
{-
cun_2=1;-
P2=~0XFE;-
cun_2=0;-
cun_1=1;-
P1=~table[bai];-
cun_1=0;-
delay(2);-
cun_2=1;-
P2=~0XFd;-
cun_2=0;-
cun_1=1;-
P1=~table[shi];-
cun_1=0;-
delay(2);-
cun_2=1;-
P2=~0XFb;-
cun_2=0;-
cun_1=1;-
P1=~table[ge];-
cun_1=0;-
delay(2);-
}-
void delay(uint z)-
{-
uint x,y;-
for(x=z;x>0;x--)-
for(y=1000;y>0;y--);-
}-
void init()-
{-
num=101;-
TMOD=0x01;-
TH0=(65536-50000)/256;-
TL0=(65536-50000)%256;-
EA=1;-
ET0=1;-
TR0=1;-
}-
void time_0() interrupt 1-
{-
TH0=(65536-50000)/256;-
TL0=(65536-50000)%256;-
a++;-
}-
歡迎光臨 (http://www.torrancerestoration.com/bbs/) |
Powered by Discuz! X3.1 |