新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 單片機(jī)計(jì)數(shù)器T0作定時(shí)技術(shù)

單片機(jī)計(jì)數(shù)器T0作定時(shí)技術(shù)

作者: 時(shí)間:2013-03-12 來(lái)源:網(wǎng)絡(luò) 收藏

6.匯編源程序(查詢(xún)法)

SECOND EQU 30H

TCOUNT EQU 31H

ORG 00H

START: MOV SECOND,#00H

MOV TCOUNT,#00H

MOV TMOD,#01H

MOV TH0,#(65536-50000) / 256

MOV TL0,#(65536-50000) MOD 256

SETB TR0

DISP: MOV A,SECOND

MOV B,#10

DIV AB

MOV DPTR,#TABLE

MOVC A,@A+DPTR

MOV P0,A

MOV A,B

MOVC A,@A+DPTR

MOV P2,A

WAIT: JNB TF0,WAIT

CLR TF0

MOV TH0,#(65536-50000) / 256

MOV TL0,#(65536-50000) MOD 256

INC TCOUNT

MOV A,TCOUNT

CJNE A,#20,NEXT

MOV TCOUNT,#00H

INC SECOND

MOV A,SECOND

CJNE A,#60,NEX

MOV SECOND,#00H

NEX: LJMP DISP

NEXT: LJMP WAIT

TABLE: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH

END

7. C語(yǔ)言源程序(查詢(xún)法)

#include AT89X51.H>

unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,

0x66,0x6d,0x7d,0x07,

0x7f,0x6f,0x77,0x7c,

0x39,0x5e,0x79,0x71,0x00};

unsigned char second;

unsigned char tcount;

void main(void)

{

TMOD=0x01;

TH0=(65536-50000)/256;

TL0=(65536-50000)%6;

TR0=1;

tcount=0;

second=0;

P0=dispcode[second/10];

P2=dispcode[second];

while(1)

{

if(TF0==1)

{

tcount++;

if(tcount==20)

{

tcount=0;

second++;

if(second==60)

{

second=0;

}

P0=dispcode[second/10];

P2=dispcode[second];

}

TF0=0;

TH0=(65536-50000)/256;

TL0=(65536-50000)%6;

}

}

}

51單片機(jī)相關(guān)文章:51單片機(jī)教程


單片機(jī)相關(guān)文章:單片機(jī)教程


單片機(jī)相關(guān)文章:單片機(jī)視頻教程


單片機(jī)相關(guān)文章:單片機(jī)工作原理


塵埃粒子計(jì)數(shù)器相關(guān)文章:塵埃粒子計(jì)數(shù)器原理


評(píng)論


相關(guān)推薦

技術(shù)專(zhuān)區(qū)

關(guān)閉