单片机用T0定时1s,图片上的4B是怎么得到的? 单片机我想用T0定时器定时1s,用T1计数器来计算1s时间内...
\u5355\u7247\u673a\u8ba9T0\u5b9a\u65f61s\u6709\u4ec0\u4e48\u529e\u6cd5\uff1f\u9996\u5148\uff0c
\u7cbe\u786e\u5b9a\u65f6\uff0c\u90a3\u4e48\u5c31\u5fc5\u987b\u7528\u5230\u786c\u4ef6\u5b9a\u65f6\u5668\u4e86\uff0c\u800c\u4e0d\u80fd\u7528\u7f51\u4e0a\u90a3\u4e9b\u5b9e\u9a8c\u5ba4\u6559\u5b66delay\u51fd\u6570\uff1b
\u6240\u4ee5\u8bf4\uff0c\u4f60\u5f97\u5b66\u4e60\u7814\u7a76\u4f60\u7528\u7684\u5355\u7247\u673a\u786c\u4ef6\u5b9a\u65f6\u5668\u7684\u914d\u7f6e\u65b9\u6cd5\uff1b
\u786c\u4ef6\u5b9a\u65f6\u5668\u5b66\u4f1a\u914d\u7f6e\u4f7f\u7528\u540e\u3002\u6bd4\u5982\uff0c\u4f60\u914d\u7f6e1ms\u57fa\u7840\u65f6\u95f4\u5b9a\u65f6\u5668\u8fdb\u5165\u4e2d\u65ad\u670d\u52a1\u51fd\u65701\u6b21\uff0c
\u7136\u540e\u5728\u4e2d\u65ad\u670d\u52a1\u51fd\u6570timer_ISR\u91cc\u9762\uff0c\u518d\u5b9a\u4e49\u4e00\u4e2astatic\u9759\u6001\u53d8\u91cfcnt\uff0c
\u6bcf\u8fdb\u51651\u6b21\u4e2d\u65ad\u670d\u52a1\u51fd\u6570timer_ISR\uff0c\u53d8\u91cfcnt++\uff0c\u5f53cnt = 1000\u4e86\uff0c\u662f\u4e0d\u662f\u5c31\u610f\u5473\u77401s\u65f6\u95f4\u5230
\u4e86\u3002
\u6253\u4e2a\u6bd4\u65b9\uff0c\u4f60\u5f88\u5feb\uff0c\u6bcf\u8fc71ms\u4f60\u94bb\u8fdb\u5c4b\u91cc\u6253\u4e2a\u624b\u67aa\uff0c\u5f53\u4f60\u6253\u4e861000\u6b21\u624b\u67aa \uff0c\u662f\u4e0d\u662f\u5c31\u610f\u5473\u77401s\u65f6\u95f4\u5c31\u8fc7\u53bb\u4e86\uff01
\u30101\u3011\u5faa\u73af\u83b7\u53d6\u662f\u5426\u6307\u4ece\u5f53\u524d\u65f6\u523b\u7b97\u8d77\uff0c\u524d\u4e00\u79d2\u5185T1\u8ba1\u5f97\u7684\u65b9\u6ce2\u6570\u3002
\u30102\u3011\u8fd9\u91cc\u7f3a\u5c11\u4e00\u4e2a\u53c2\u6570\uff0c\u5c31\u662f\u5faa\u73af\u83b7\u53d6\u7684\u91c7\u6837\u5468\u671ft\uff08S\uff09\uff0c\u59820.1S\u3002
\u30103\u3011\u6839\u636et\uff0c\u8bbe\u5b9aT0\u4e2d\u65ad\u3002\u603b\u5171\u5e94\u8be5\u67091/t\u4e2a\u91c7\u6837\u7247\u6bb5PulseNum[1/t]\uff0c\u6bcf\u6b21T0\u4e2d\u65ad\uff0c\u586b\u5145PulseNum[i++%(1/t)]\u3002\u5e76\u6e05\u9664T1\u521d\u503c\u3002
\u30104\u3011\u4e3b\u7a0b\u5e8f\u6c42\u548cPulseNum[1/t]\u5373\u53ef\u3002
\u30105\u3011\u6ce8\u610fT1\u6ea2\u51fa\u91cf\u7a0b\u3002
11059200÷12÷20=46080
对应的重载值就是65536 - 46080 = 19456 = 0x4C00。减去软处理时的三个指令周期,就是0x4BFD。
绛旓細杩欐槸鍦11.0592MHz鐨澶栭儴鏅舵尟鍓嶆彁涓嬶紝鐢变簬瀹氭椂鍣ㄦ湰韬棤娉曞欢杩1绉掗偅涔堥暱鐨勬椂闂达紝鎵浠ョ敤杞欢鍒嗘垚20浠斤紝姣忎唤灏辨槸 11059200梅12梅20=46080 瀵瑰簲鐨勯噸杞藉煎氨鏄65536 - 46080 = 19456 = 0x4C00銆傚噺鍘昏蒋澶勭悊鏃剁殑涓変釜鎸囦护鍛ㄦ湡锛屽氨鏄0x4BFD銆
绛旓細5銆乿oid 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鍗曠墖鏈猴紝鎷ユ湁涓や釜瀹氭椂鍣紝鐢ㄦ潵涓柇璁℃暟锛屽垎鍒槸T0鍜孴1銆傝52鍗曠墖鏈哄拰51鍗曠墖鏈虹殑瀹氭椂鍣ㄦ槸涓鏍风殑锛屽彧鏄5...
绛旓細銆0銆戝惎鍔T0鏃讹紙瀹氭椂妯″紡锛20-50mS涓柇锛夛紝鍚姩T1銆傘1銆戝湪T0涓柇涓紝璁℃椂锛堝锛20mS璁50娆″悗锛夛紝鍒拌揪1S锛璁剧鏍囧織銆傜洿鎺ヨ鍙朤H1锛孴L1鐨鍊间繚瀛樺埌鍙橀噺x銆傚苟娓呴櫎T1璁℃暟鍊笺傘2銆戝湪涓荤▼搴忎腑娴嬪埌绉掓爣蹇楋紝娓呴櫎锛屽皢x閫佹樉绀哄崟鍏冦傘3銆戞牴鎹叿浣撶殑LCD妯″潡锛岀粍缁囧浘褰㈡暟鎹紝閫丩CD妯″潡銆=== 銆0銆-鍒濆...
绛旓細1. 鏂瑰紡0鏄13浣瀹氭椂/璁℃暟鍣ㄦ柟寮忥紝鍏朵腑TH0鍗犳嵁楂8浣嶏紝TL0鍗犳嵁浣5浣嶏紙鍙浣跨敤浣5浣嶏紝楂3浣嶆湭浣跨敤锛夈2. 瀵逛簬甯哥敤鐨12鍒嗛鐨51绯诲垪锛岄昏緫鍥惧涓嬶細宸ヤ綔鍘熺悊濡備笅锛T0绔槸瀹氭椂鍣/璁℃暟鍣0鐨勫閮ㄤ俊鍙疯緭鍏ョ锛堥氬父杩炴帴鍒癙3.4 i/o鍙o級锛3. TR0鏄畾鏃跺櫒/璁℃暟鍣ㄧ殑杩愯鎺у埗浣嶏紙浣嶄簬TCON.5锛夛紱TF0鏄畾鏃...
绛旓細//TMOD=0x61; //瀹氭椂鍣0锛屾柟寮1锛涜鏁板櫒1锛屾柟寮2 TMOD=0x25;//TH0=(65536-50000)/256; //TH0=0x3C //TL0=(65536-50000)%256; // TL0=0xB0 瀹氭椂50ms TH1=6;TL1=6;TH0=0;TL0=0;//TH1=0X00;// TL1=0X00;TR0=1;ET0=1;TR1=1;ET1=1;EA=1;} void main(void){...
绛旓細TMOD = 0x01; //瀹氭椂鍣0锛屽伐浣滄柟寮1 TH0 = (65536-50000)/256;TL0 = (65536-50000)%256; //50ms涓柇涓娆 EA = 1;ET0 = 1;TR0 = 1;} void main(void){ initT0();while(1)if(time==20) //涓柇20娆锛1s { time=0;LED=锛丩ED; //P1.0涓婄殑LED锛1s浜垨鐏竴娆 } } voi...
绛旓細;浠跨収渚7.11 ;TC=M-T/T璁℃暟=9E58H(鍏朵腑T=25ms)ORG 0000H LJMP MAIN ORG 000BH AJMP BRT0 ORG 0030H MAIN:CLR P1 MOV TMOD,#01H;T0涓烘柟寮1 SETB EA SETB ET0 SETB TR0 MOV TH0,#9EH MOV TL0,#58H MOV R0,#04H MOV A,#01H LOOP:SJMP $;绛夊緟涓柇 ORG 0080H BRT0:DJN...
绛旓細鏂瑰紡0锛氫负13浣瀹氭椂/璁℃暟鍣ㄦ柟寮 鍏朵腑TH0鍗犻珮8浣嶏紝TL0鍗犱綆5浣嶏紙鍙敤浣5浣嶏紝楂3浣嶆湭鐢級濡傛灉鏄父鐢鐨12鍒嗛鐨51绯诲垪鐨勮瘽閫昏緫鍥惧涓嬶細宸ヤ綔鍘熺悊濡備笅锛T0绔細瀹氭椂鍣/璁℃暟鍣0澶栭儴淇″彿杈撳叆绔紙涓鑸负i/o鍙3.4锛塗R0锛氬畾鏃跺櫒/璁℃暟鍣ㄧ殑杩愯鎺у埗浣嶏紙涓篢CON.5锛塗F0锛氬畾鏃跺櫒/璁℃暟鍣0婧㈠嚭鏍囧織浣嶏紙涓篢CON...
绛旓細鍓嶄竴绉掑唴T1璁″緱鐨鏂规尝鏁般傘2銆戣繖閲岀己灏戜竴涓弬鏁帮紝灏辨槸寰幆鑾峰彇鐨勯噰鏍峰懆鏈焧锛圫锛夛紝濡0.1S銆傘3銆戞牴鎹畉锛岃瀹T0涓柇銆傛诲叡搴旇鏈1/t涓噰鏍风墖娈礟ulseNum[1/t]锛屾瘡娆0涓柇锛屽~鍏匬ulseNum[i++%(1/t)]銆傚苟娓呴櫎T1鍒濆笺傘4銆戜富绋嬪簭姹傚拰PulseNum[1/t]鍗冲彲銆傘5銆戞敞鎰廡1婧㈠嚭閲忕▼銆
绛旓細LJMP MAIN ORG 000BH LJMP T0ISR ORG 0030H MAIN:MOV TMOD,#51H MOV TH0,#HIGH(65536-50000)MOV TL0,#LOW(65536-50000)MOV TH1,#0 MOV TL1,#0 SETB TR0 SETB TR1 SETB ET0 SETB EA MOV R2,#20 SJMP T0ISR:CLR TR0 MOV TH0,#HIGH(65536-50000)MOV TL0,#LOW(65536-50000)SETB ...