2876 views|0 replies

1379

Posts

0

Resources
The OP
 

Timer/Counter Experiment 2 [Copy link]

There are usually two requirements for counting at work: first, display the count value, and second, interrupt and alarm when the count value reaches a certain level. The first type is like various counters and odometers, and the second type is like the counting on the production line mentioned in the previous example. Let's look at the first type first. Our hardware is connected like this: the oscillator composed of 324 is connected to the external pin T1 of the timer/counter 1. We use this to do a counting experiment. To display the count value, of course, it is best to use a digital tube, but we haven't talked about this part yet. In order to avoid complicating the problem, we use the 8 LEDs of the P1 port to display the counted data.

The procedure is as follows:

ORG 0000H

AJMP START

ORG 30H

START:

MOV SP,#5FH

MOV TMOD,#01000000B; Timer/Counter 1 is used for counting, no need to set all 0s

SETB TR1 ;Start counter 1 to start running.

LOOP: MOV A,TL0

MOV P1,A

AJMP LOOP

END

Connect the output of 324 to T1 with a wire (there are pads on the printed board) and run this program. Pay attention to placing the board in the correct position (LM324 is placed on the left hand side, and the LEDs are arranged from high to low). What do you see? As the LED connected to 324 flashes, the 8 LEDs of the microcontroller are also changing. Pay attention to observe whether they are in binary:
00000000

00000001

00000010

00000011

.

.

.

Is this order changing? That's right, this is the data in TL0.

Procedure 2:

ORG 0000H

AJMP START

ORG 001BH

AJMP TIMER1 ; Timer 1 interrupt processing

ORG 30H

START: MOV SP,#5FH

MOV TMOD,#01010000B; Timer/Counter 1 is used for counting, mode 1, 0 is not used, all bits are set to 0

MOV TH1,#0FFH

MOV TL1,#0FAH; preset value, requiring every 6 pulses counted to be an event

SETB EA

SETB ET1; Enable general interrupt and timer 1 interrupt

SETB TR1 ;Start counter 1 to start running.

AJMP$

TIMER1:

PUSH ACC

PUSH PSW

CPL P1.0; when the count value reaches, P1.0 is inverted

MOV TH1,#0FFH

MOV TL1,#0FAH ; Reset the initial value of the count

POP PSW

POP ACC

RETI

END

The program above does a very simple job, which is to invert P1.0 after every 6 pulses. Therefore, the result of the experiment should be: if the LED connected to LM324 turns on and off 6 times, the LED connected to P1.0 turns on or off once. This is actually the second application of the counter we mentioned above.

Procedure 3: External interrupt experiment

ORG 0000H

AJMP START

ORG 0003H ;Direct entry to external interrupt

AJMP INT0

ORG 30H

START: MOV SP,#5FH

MOV P1,#0FFH; all lights off

MOV P3,#0FFH; Set P3 port to high level

SETB EA

SETB EX0

AJMP$

INT0:

PUSH ACC

PUSH PSW

CPL P1.0

POP PSW

POP ACC

RETI

END

This post is from MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list