如何利用定时器T0的工作方式1实现1秒钟延时程序(单片机)?
1、#include <reg52.h>
2、#define uchar unsigned char
3、#define uint unsigned int
4、sbit LED = P0^0;uchar T_Count = 0;void main(){TMOD = 0x01;TH0 = (65535-50000)/256;TL0 = (65535-50000)%256;IE = 0x82;TR0 = 1;while(1);}
5、void LED_Flash() interrupt 1{TH0 = (65535-50000)/256;TL0 = (65535-50000)%256;if(++T_Count == 20){LED = !LED;T_Count = 0;}}
6、这个程序是1秒钟LED灯会亮与灭显示。
绛旓細1 宸ヤ綔鏂瑰紡0 瀹氭椂鍣/璁℃暟鍣═0宸ヤ綔鍦ㄦ柟寮0鏃讹紝16浣嶈鏁板櫒鍙敤浜13浣嶏紝鍗砊H0鐨勯珮8浣嶅拰TL0鐨勪綆5浣嶏紝缁勬垚涓涓13浣嶅畾鏃跺櫒/璁℃暟鍣ㄣ1锛夈佸伐浣滃湪瀹氭椂鏂瑰紡 2锛夈佸伐浣滃湪璁℃暟鏂瑰紡 2 宸ヤ綔鏂瑰紡1 瀹氭椂鍣═0宸ヤ綔鏂瑰紡1涓庡伐浣滄柟寮0绫诲悓锛屽樊鍒湪浜庡叾涓殑璁℃暟鍣ㄧ殑浣嶆暟銆傚伐浣滄柟寮0浠13浣嶈鏁板櫒鍙備笌璁℃暟锛屽伐浣滄柟寮1...
绛旓細;鏅舵尟涓12MHZ,姣1ms鍙栧弽涓娆″氨鍙疄鐜板懆鏈熶负2ms鐨勬柟娉 ORG 0000H LJMP MAIN ORG 000BH LJMP B_T0 ORG 0030H MAIN: MOV TMOD,#01H ;鏂瑰紡1瀹氭椂 MOV TH0,#0FCH ;瀹氭椂1ms MOV TL0,#18H SETB EA ;鎵撳紑瀹氭椂鍣鎬讳腑鏂 SETB ET0 ;鎵撳紑瀹氭椂鍣0涓柇 SETB TR0 ;鎵撳紑瀹氭椂鍣0...
绛旓細;鏃堕挓鍛ㄦ湡鏄櫠鎸鐜囩殑鍊掓暟锛岃岃鏁板懆鏈烼鏄椂閽熷懆鏈熺殑12鍊嶏紝鎵浠ヨ鏁板懆鏈熶负1us銆;浣跨敤瀹氭椂鍣═0锛宸ヤ綔鍦鏂瑰紡1锛屽綋瀹氭椂涓40ms鏃讹紝璁℃暟鍒濆间负25536=63C0H锛涘綋瀹氭椂涓20ms;鏃讹紝璁℃暟鍒濆间负45536=B1E0H銆;绋嬪簭娈靛涓嬶紝浣跨敤瀹氭椂鍣═0锛屾煡璇㈡柟寮忓畬鎴愶細CLR P1.0;鍏堣緭鍑40ms浣庣數骞 LOOP1锛歁OV TMOD,#01H...
绛旓細TMOD鏄8浣嶅瘎瀛樺櫒锛屽墠4浣嶆帶鍒禩1锛屽悗4浣嶆帶鍒T0,4浣嶇殑鎰忎箟鍒嗗埆鏄棬鎺у埗1浣嶏紝鍔熻兘閫夋嫨浣1浣嶏紝鏂瑰紡閫夋嫨浣2浣 T1鏂瑰紡2锛歍MOD=0x20
绛旓細T0鐨鍒濆间负TH0 =0D8H锛孴L0 = 0F0H銆傦紙2锛夌▼搴 ORG0000H;绋嬪簭鍏ュ彛 BEGIN:AJMP MAIN ;杞富绋嬪簭 ORG 000BH ;T0涓柇鍏ュ彛 AJMP IT0P;杞琓0涓柇澶勭悊绋嬪簭IT0P ORG 0100H ;涓荤▼搴忓叆鍙 MAIN: MOV TMOD,#01H;璁剧疆T0涓鏂瑰紡1瀹氭椂 MOV TL0,#0F0H;T0鍒濆鍖栵紝瑁呭垵鍊肩殑浣8浣...
绛旓細杩欐牱涓嶄粎楹荤儲鑰屼笖褰卞搷绮惧害銆傛柟寮2閬垮厤浜嗕笂杩扮己闄凤紝閫傜敤浣滆緝绮剧‘鐨勫畾鏃惰剦鍐蹭俊鍙峰彂鐢熷櫒銆傚畠鐨勫畾鏃舵椂闂翠负锛歵=锛2^8锛T0鍒濆硷級脳鏃堕挓鍛ㄦ湡脳12 4.宸ヤ綔鏂瑰紡3 鐗规畩宸ヤ綔鏂瑰紡鍙傜敤浜嶵0锛岄櫎浜嗘槸鐢8浣嶅瘎瀛樺櫒TL0澶栵紝鍏跺姛鑳藉拰鎿嶄綔涓庢柟寮0鍜鏂瑰紡1瀹屽叏鐩稿悓锛屽彲浣瀹氭椂鍣ㄤ娇鐢锛屼篃鍙敤浣滆鏁板櫒銆備絾鏄紝鍙︿竴涓鏁板櫒TH...
绛旓細鍊熻姳鐚經锛歄RG 4000H AJMP START ORG 401BH AJMP INQP ORG 4030H START:MOV TMOD,#10H MOV TH1,#03CH MOV TL1,#0B0H SETB TR1 SETB ET1 SETB EA MOV R1,#50 MOV A,#0FEH LOOP: MOV P1,A AJMP LOOP LOOP2:MOV P1,#0FFH AJMP INQP INQP :JNB P3.0 LOOP2 MOV TH1,#03CH ...
绛旓細鐢ㄥ畾鏃跺櫒瀹氭椂100ms锛屽彲浠ヤ粠鍗曠墖鏈轰竴涓紩鑴氳緭鍑轰竴涓柟娉紝灏辫兘鐪嬪埌鏁堟灉浜嗐傝屼綘瀵笰CC.0 鍙栧弽锛岃繖鏄湪鍐呴儴鐨勶紝涔熺湅涓嶅埌瀹氭椂鐨勬晥鏋滃憖銆備綘绋嬪簭鏄噰鐢ㄦ煡璇㈡柟娉曞垽鏂畾鏃跺埌锛屽嵆鍒ゆ柇TF0鐨勭姸鎬侊紝灏变笉鑳界敤寮涓柇锛孲ETB EA SETB ET0 杩欎袱琛岃鍒犳帀鐨勩傛敼鎴愬涓嬭繖鏍 START:MOV P2.0,1 MOV TMOD,#0...
绛旓細TMOD =0x00锛涘畾鏃舵ā寮0锛歍MOD=0X00;瀹氭椂妯″紡1:TMOD=0x01,锛涘畾鏃舵ā寮2锛歍MOD=0x02,锛氬畾鏃舵ā寮3锛歍MOD=0x03锛瀹氭椂鍣ㄧ殑璁剧疆鍙互鍙傝冿細http://wenku.baidu.com/link?url=ck_kKiaEesHTuPS0bgamp45a80Wb2QGGlU00Nyl2Koh3cniMS37Du_pdS14v62Wu6L81L1Vfz8aogPUOHPOJrFaxbu8Vg65XdzpZyS_tBbK ...
绛旓細F0 ;璁剧疆涓涓杞负瀹氭椂鏂瑰紡鐨鏍囧織浣 WAIT: AJMP WAITIT0P: CLR EA ;CPU鍏抽棴涓柇 JB F0,EXTN1 ;F0=1杞鏁宸ヤ綔妯″紡SETB F0 mov TMOD,#00 mov TL0,#ocHmov TH0#0feHSETB EARETEXTN1: INC R1 ;璁℃暟鍣ㄥ姞1 MOV A,R1CJNE A,#64H,EXTN2 ;璁℃暟鏄惁鍒100CLR F0 ;寮鍚鏃舵爣蹇桵OV R1,#0...