Debugged flashing program

Publisher:ZhenxiangLatest update time:2018-01-22 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

First, let's make the first light flash:

start: SETB P0.0; (1) turns off the light
       LCALL DELAY; (2) is a delay, calling the delay subroutine instruction
       CLR P0.0; (3) turns on the light
       LCALL DELAY; (4) is exactly the same as the second one, also calling the delay subroutine instruction


       LJMP start; (5) Jump back to execute the first instruction
DELAY: MOV R7, #250; (6) Let R7 be a counter and load a constant
D1: MOV R6, #250; (7) Let R6 be a counter and load a constant
D2: DJNZ R6, D2; (8) Let R6 decrement by 1 and determine whether R6 is 0. If R6 is 0, execute the instruction below. If R6 is not 0, jump to D2 and continue to decrement R6 by 1.
 DJNZ R7, D1; (9) Let R7 decrement by 1 and determine whether R7 is 0. If R7 is 0, execute the instruction below. If R7 is not 0, jump to D1 to make R6 complete a new round of counting.
 RET; (10) Return instruction.
 END; (11) End of program


Then there are the flashing programs:

;------------------Main program------------------
START: CLR P0.0;P0.0 outputs a low level to light up LED 1
       ACALL DELAY;Call the delay subroutine
       SETB P0.0;P0.0 outputs a high level to turn off LED1
       CLR P0.1;P0.1 outputs a low level to light up LED2
       ACALL DELAY;Call the delay subroutine
       SETB P0.1;P0.1 outputs a high level to turn off LED2
       CLR P0.2;P0.2 outputs a low level to light up LED3
       ACALL DELAY;Call the delay subroutine
       SETB P0.2;P0.2 outputs a high level to turn off LED3
       CLR P0.3;P0.3 outputs a low level to light up LED4
       ACALL DELAY;Call the delay subroutine
       SETB P0.3;P0.3 outputs a high level to turn off LED4
       CLR P0.4;P0.4 outputs a low level to light up LED5
       ACALL DELAY;Call the delay subroutine
       SETB P0.4;P0.4 outputs a high level to turn off LED5
       CLR P0.5;P0.5 outputs a low level to turn on LED6
       ACALL DELAY;Call the delay subroutine
       SETB P0.5;P0.5 outputs a high level to turn off LED6
       CLR P0.6;P0.6 outputs a low level to turn on LED7
       ACALL DELAY;Call the delay subroutine
       SETB P0.6;P0.6 outputs a high level to turn off LED7
       CLR P0.7;P0.7 outputs a low level to turn on LED8
       ACALL DELAY;Call the delay subroutine
       SETB P0.7;P0.7 outputs a high level to turn off LED8
       ACALL DELAY;Call the delay subroutine
       AJMP START;After the eight lights are on, return to the beginning and loop again
       ;------Delay subroutine-------
DELAY: MOV R0,#255;R0 is loaded with 255
D1: MOV R1,#255;Load 255 into R1
       DJNZ R1,$;Decrement R1 to zero and then execute the next instruction
       DJNZ R0,D1;Decrement R0 by 1. If it is zero, execute the next instruction. If it is not zero, jump to D1
       RET;Return from the subroutine
;============================================================================================================;
 END;End of program


Reference address:Debugged flashing program

Previous article:Using C51 to make a running light
Next article:A simple alarm system based on 89C51

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号