51 single chip microcomputer system application

Publisher:bobojrtLatest update time:2015-10-12 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Application 1:  Suppose there is a 51 application system connected as shown in the attached figure. Please explain how the LED connected to the P1.0 port changes when the system executes the following program segments A and B respectively? What is the difference between the display changes of the corresponding program segments A and B?

[Reprint] 51 single chip microcomputer system application

Program segment A:

LP: CPL P1.0

    MOV R0,#0

     DJNZ R0,$

    JMP LP

Program segment B:

LP: SETB P1.0

    DJNZ R0,$

    CLR P1.0

    DJNZ R0,$

    DJNZ R0,$

    JMP LP

Answer: For both program segments A and B, the LED will periodically switch between on and off states. In each on-off switching cycle, for program segment A, the LED stays on for the same length of time as it stays off; for program segment B, the LED stays on for twice as long as it stays off. The LED on-off cycle for program segment B is approximately 1.5 times that for program segment A.

 

Application 2: Assume that the 51 application system is connected as shown in the figure of application 1, and the crystal frequency used in the system is 12MHz. Try to write a program segment to use the timer/counter 1 of the 51 microcontroller to realize that the display status of the LED connected to P1.0 is flipped every 10 seconds.

 

answer:

     MOV TMOD,#20H       ; T1 timing mode 2: 8-bit automatic reload

     MOV TH1,#(256-250); Timing period 250us (corresponding to 12MHz crystal oscillator, each machine cycle = 1us) 

     MOV TL1,TH1         ;

     CLR TF1             ; Clear T1 overflow flag

     SETB TR1            ; Start T1 timing

     MOV R0,#0           ; R0 is used to accumulate the number of times T1 overflows

     MOV R1,#0           ; R1 is used to accumulate the number of times R0 reaches 200

LP:   JBC TF1, L1          ; if TF1 is 1, clear TF1 and proceed to accumulate the number of overflows

     JMP LP              ; loop and wait for T1 to overflow

L1:   INC R0              ; cumulative T1 overflow times

     CJNE R0,#200,LP     ;If it does not reach 200 times, it will wait for the next overflow

     MOV R0,#0           ; Ensure that the value of R0 is between 0 and 199

     INC R1              ; the number of times the cumulative time reaches 50ms (250us*200=50ms)

     CJNE R1,#200,LP     ; If the accumulated time does not reach 10s, it will wait for the next overflow

     MOV R1,#0           ; Ensure that the value of R1 is between 0 and 199

     CPL P1.0            ; if the accumulated time reaches 10s, flip the P1.0 state once (50ms*200=10s)

     JMP LP              ; Continue looping to accumulate time

Reference address:51 single chip microcomputer system application

Previous article:51 MCU Exercises
Next article:51 MCU on-chip devices and interrupts (4)

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号