给个例子,也许可以满足你的要求:
#include "reg51.h"
#define FOSC 12000000L
#define T1XXH (65536-FOSC/12* 2/1000) +2 // 2ms timer calculation method in 12T mode
#define T1XXL (65536-FOSC/12* 8/1000) // 8ms timer calculation method in 12T mode
/* define SFR */
sbit TEST_100Hz = P1^0; // 100Hz Out
/* Timer1 interrupt routine */
void tm1_isr() interrupt 3 using 1
{
TEST_100Hz = ! TEST_100Hz;
if(TEST_100Hz)
{
TL1 += T1XXH; //reload timer1 low byte
TH1 = T1XXH >> 8; //reload timer1 high byte
}
else
{
TL1 += T1XXL; //reload timer1 low byte
TH1 = T1XXL >> 8; //reload timer1 high byte
}
}
//-----------------------------------------------
/* main program */
void main()
{
TMOD = 0x10; //set timer1 as mode1 (16-bit)
TL1 = T1XXH; //initial timer1 low byte
TH1 = T1XXH >> 8; //initial timer1 high byte
TEST_100Hz=1;
TR1 = 1; //timer1 start running
ET1 = 1; //enable timer1 interrupt
EA = 1; //open global interrupt switch
while (1); //loop
}
;如下即可:
ORG 0000H
MOV TMOD, #01H
SETB TR0
LP1:
SETB P1.0
MOV R2, #6
LOOP:
MOV TH0, #(65536 - 16666) / 256
MOV TL0, #(65536 - 16666) MOD 256
JNB TF0, $
CLR TF0
CLR P1.0
DJNZ R2, LOOP
SJMP LP1
END