t0_m0_t_gh.a51

来自「C51 Timer 0 的使用 Timer_0_mode_0_timer_ga」· A51 代码 · 共 44 行

A51
44
字号
$INCLUDE   (reg_c51.INC)

org 000h
ljmp begin

org 00Bh
ljmp it_timer0

;/**
; * FUNCTION_PURPOSE: This file set up timer 0 in mode 0 (13 bits timer) 
; * with a hardware gate.
; * The 13-bits register consist of all 8 bits of TH0 and the lower 5 bits   
; * of TL0. The upper 3 bits of TL0 are undeterminate and are ignored.   
; * FUNCTION_INPUTS: P3.2(INT0)=1 : GATE Input
; * FUNCTION_OUTPUTS: void
; */
org 0100h

begin:
	ANL TMOD,#0F0h;			   	/* Timer 0 mode 0 with hardware gate */
	ORL TMOD,#08h;			   	   /* GATE0=1; C/T0#=0; M10=0; M00=0; */
	
	MOV TH0,#00h;			         /* init values */
	MOV TL0,#00h;		
	SETB ET0;						   /* enable timer0 interrupt */
	SETB EA;                      /* enable interrupts */
	SETB TR0;						   /* timer0 run */
	JMP $;						      /* endless  */
  


;/**
; * FUNCTION_PURPOSE: timer0 interrupt
; * FUNCTION_INPUTS: void
; * FUNCTION_OUTPUTS: P1.0 toggle period = 2 * 8192 cycles  
; */
it_timer0:

	CLR TF0;						/* reset  interrupt flag (already done by hardware)*/
	CPL P1.0;					/* P1.0 toggle when interrupt. */
   RETI

end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?