Home > other >  MCU internal timer 0, in P2.0 mouth to create a cycle of 1 ms (0.001 s, 1 KHZ), the duty ratio is 1/
MCU internal timer 0, in P2.0 mouth to create a cycle of 1 ms (0.001 s, 1 KHZ), the duty ratio is 1/

Time:11-01

By 51 MCU internal timer 0, in P2.0 mouth to create a cycle of 1 ms (0.001 s, 1 KHZ), duty ratio is 1/5 (200 us) high level continuous square wave, and at the same time make eight LED light-emitting diodes, take turns to light, interval is about 0.5 s

CodePudding user response:

https://blog.csdn.net/xianfajushi/article/details/81331101

CodePudding user response:

Have no matter to send you a written before, it is ok to look at the write a timer interrupt handling, but be in assembly!

//program starts

Code_SEG SEGMENT code//the name of the data area definition
RSEG code_SEG

ORG 0000 h
AJMP 0160 h;
//the interrupt routine entry
ORG 0003 h
INT0_EXIT:
LJMP EX0_ZHD_MAIN;
RETI;
ORG 000 bh
LJMP TIME0_ZHD_MAIN;
RETI;
ORG 0013 h
LJMP EX1_ZHD_MAIN;
RETI;
ORG 001 bh
LJMP TIME1_ZHD_MAIN;
RETI;
ORG 0023 h//serial port interrupt entry 1
LJMP S1BUF_ZHD_MAIN;
RETI;
ORG 002 bh
RETI;
ORG 0043 h/2/serial port interrupt entry
LJMP S2BUF_ZHD_MAIN;
RETI;

ORG 0160 h
//system initialization
# include & lt; The PROGRAM/COMMAND_SATR. ASM>//system, anti-fuzzy initial program */
The NOP.
The NOP.
MAIN:
AJMP MAIN;//returns to the system main program

/* -- -- -- -- -- -- -- -- -- subroutine area -- -- -- -- -- -- -- -- -- -- - */
# include & lt; The system/XT_RW1_MAIN. ASM>//system task thread 1
# include & lt; The system/XT_RW2_MAIN. ASM>//system task thread 2
# include & lt; The system/XT_RW3_MAIN. ASM>//system task thread 3

# include & lt; The system/_CON_PZH_CHXJ. ASM>//& lt; System libraries & gt; Header files define
# include & lt; The system/XTxRW_T0ZHD_CHX. ASM>//multitasking system timer interrupt subroutine
# include & lt; The PROGRAM/EX_ZHD_CHXJ. ASM>//external interrupt subroutine
# include & lt; The PROGRAM/TIME1_ZHD_CHX. ASM>//timer interrupt subroutine

//on STC system subroutine
# include & lt; The PROGRAM/STC_ADJC_CHX. ASM>//AD detection subroutine
# include & lt; The PROGRAM/STC_PWM_CHX. ASM>//system PWM definition
# include & lt; The PROGRAM/STC_FLASH_CHXJ. ASM>//on STC microcontroller internal erasable FLASH read and write subroutines

//system subroutine
# include & lt; The PROGRAM/S1BUF_ZHD_CHX. ASM>//& lt; System libraries & gt; A serial port interrupt handling subroutine
2# include & lt; The PROGRAM/S1BUF_DATA_OUT. ASM>//serial port interrupt output processing subroutine
2# include & lt; The PROGRAM/S2BUF_ZHD_CHX. ASM>//& lt; System libraries & gt; A serial port interrupt handling subroutine
2# include & lt; The PROGRAM/S2BUF_DATA_OUT. ASM>//serial port interrupt output processing subroutine
2# include & lt; The PROGRAM/CRC16M_IRAM_CHX. ASM>//& lt; System libraries & gt; CRC16 efficacy data subroutine
# include & lt; The PROGRAM/CRC16M_XRAM_CHX. ASM>//& lt; System libraries & gt; CRC16 efficacy data subroutine
# include & lt; The PROGRAM/CRC16M_CSHB. ASM>//& lt; System libraries & gt; CRC16 parameter list
//# include & lt; The PROGRAM/I2C_RW_CHXJ. ASM>//& lt; System libraries & gt; Header files define
//# include & lt; The PROGRAM/SMALL_SUBB_CHX. ASM>//& lt; System libraries & gt; Small division subroutine
//# include & lt; The PROGRAM/CRC8_1_RAM_CHX. ASM>//& lt; System libraries & gt; CRC8 efficacy data subroutine
//# include & lt; The PROGRAM/CRC8_IRAM_CHX. ASM>//& lt; System libraries & gt; Timer interrupt handling subroutine 1
//# include & lt; The PROGRAM/CRC8_XRAM_CHX. ASM>//& lt; System libraries & gt; CRC8 efficacy data subroutine
//# include & lt; The PROGRAM/DIN_ZHX_CHXJ. ASM>//data input register instruction parse subroutine
//# include & lt; The PROGRAM/BCH_ZHX_CHXJ. ASM>//keep a register instruction analytical processing subroutine
//# include & lt; The PROGRAM/BIT_BCD_CHXJ. ASM>//& lt; System libraries & gt; Turn the binary decimal subroutine
//# include & lt; The PROGRAM/MUL_CHXJ. Asm>//& lt; System libraries & gt; Take a way to program
//# include & lt; The PROGRAM/SUBB_CHXJ. Asm>//& lt; System libraries & gt; Big division subroutine

END



////-- -- -- -- -- -- -- -- -- -- -- -- system register initialization -- -- -- -- -- -- -- -- -- -- -- --
MOV R0, # 080 h;
The CLR A;
CLR_RAM:
MOV @ R0, A;
DJNZ R0, CLR_RAM;
; -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --//
//-- -- -- -- -- -- -- -- -- -- -- -- base register Settings -- -- -- -- -- -- -- -- -- -- -- --
MOV SP, # 60 h;//set the main program stack starting address
MOV TMOD, # 21 h;//time0: timed mode 0 time1: way 2
MOV AUXR, # 11000000 b;//open independent open the double serial port baud rate generator

MOV SCON, # 040 h;
MOV TH1 e6h # 0;

MOV PCON, # 80 h;
MOV IP, # 008 h;
MOV, IE # 090 h;//open the timer 0 interrupt
SETB TR0;//open the timer 0
SETB TR1.//open the timer 1
SETB REN;

//pin function set
MOV P0M0, # 00000100 b;
MOV P1M0, # 00001110 b;
MOV P2M0, # 11110000 b;
MOV P3M0, # 10110000 b;

CodePudding user response:

reference 1/f, the wise know already should good karma response:
https://blog.csdn.net/xianfajushi/article/details/81331101

Such precision requirements, the C language?
  • Related