51 MCU Simulation Example

Publisher:dandan666Latest update time:2015-01-19 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
This is a commonly used program segment - a subroutine - a standard program, which obtains input data or controls output data through port scanning to achieve the purpose of saving bits or bytes - saving hardware resources.
Regarding scanning, we can understand it by starting with the bit and its inversion to realize the running light. The running light-scanning can be realized by shifting. The running light-scanning can be realized by sending the byte data (01H, 02H, 04H, 08H, 10H, 20H, 40H, 80H—anode tube) through the port. The running light-scanning can be realized through the data table (DB  01H, 02H, 04H, 08H, 10H, 20H, 40H, 80H—cathode tube). The running light-scanning can be realized by loop jump. When scanning, pay attention to the input comparison and output check—obtaining input requires comparing data, and sending output requires checking the output.
Scan to get port bytes
Scan output bit movement produces dynamic effects (01, 02, 04, 08, 10, 20, 40, 80), which can be done with byte tables
Scan and output character bytes, and change characters by delay to create a digital carry effect
ORG 0000H
START:
dbuf      equ   30h   ; set the first address of the storage area
temp      equ   40h   ; set buffer first address
         org 00h
         mov 30h,#2 ; store data
         mov 31h,#0
         mov 32h,#1
         mov 33h,#0
         mov 34h,#7
         mov 35h,#1
         mov r0,#dbuf
         mov r1,#temp
         mov r2,#6      ; six-digit display
         mov dptr,#segtab ; segment table first address
dp00:     mov a,@r0     ; get the data to be displayed
         movc a,@a+dptr ; look up the table to get the segment code
         mov @r1,a      ;segment code temporarily stored
         inc r1
         inc r0
         djnz r2,dp00                                                          
disp0:    mov r0,#temp     ;display subroutine
         mov r1,#6       ; scan 6 times
         mov r2,#01h     ; start from the first bit
dp01:    mov a,@r0
         mov p2,a    ; segment code output
         mov a,r2    ; get bit code
         mov p1,a    ; bit code output
         acall delay   ; call delay
         mov a,r2
         rl a
         mov r2,a
         inc r0
         djnz r1,dp01
         sjmp disp0
segtab:   db 0C0H,0F9H,0A4H,0B0H,99H,92H   ; common anode tube
         db 82H,0F8H,80H,90H,88H,88H,83H
delay:    mov r4,#29h          ;delay subroutine
aa1:     mov r5,0ffh
aa:       djnz r5,aa
         djnz r4,aa1
         right
         end
???????????????????????
************************************************************************
Scanning can also be performed in other program forms, such as loops, incrementing or decrementing judgment programs, etc. Scanning technology can be used for dot matrix displays and liquid crystal display (LCD) displays. These require character encoding, display delay, and scanning ports to make full use of resources (save resources).
 
 
Example   1 - About dynamic display - LED flashing
 
ORG 0000H
  START: 
    MOV   A,#0FFH    ; Byte transfer
    MOV   P3,A   ; Byte transfer
       MOV  P1,A
       MOV C, 0A0H ;bit transfer
    JNB   0A0H, GUAN; if the bit level is low, it is true, then transfer; if the direct address bit is 0, transfer
       MOV   P1,#00H;   P1 port is first assigned #0FFH, then assigned #00H, which will cause flickering
RIGHT
GUAN : 
       MOV   P3,#00H; assign #0FFH to port P3 first, then assign #00H, which will cause flickering. You can also use the inversion instruction
     RET    ; can produce a flashing effect
 END 
Other methods (such as delay subroutines) can also achieve dynamic display. [page]
 
Example   2 - Simulation of a single LED light and a single button
ORG   0000H    ; This is a pseudo instruction. The machine does not execute it. It is used for program communication. The starting address of instruction execution is represented by D in decimal, H in hexadecimal, and B in binary. One byte (8-bit machine, 16-bit machine, 32-bit machine, 64-bit machine) is executed at a time. It can also be executed bit by bit, that is, one bit.
ORG   00000000B   has the same function as ORG 0000H. Note that 8 bits are one byte. A 16-bit processor needs to be represented by 0000 0000H. For 16 or 32 bits or above, it is more effective to use an operating system (Wince, Linux, etc.), which can utilize a large number of low-level, professional, and standardized control-oriented library functions (such as: API, etc.).
START:   ; This is a pseudo instruction, the machine does not execute it. It is just for the sake of the comprehensibility of the assembly language story.
   MAIN:     ; Pseudo instruction, main program, used to distinguish subroutines
   PC→MOV   A, #00H    ; transfer the immediate value 00000000B (constant 0D) to the accumulator ACC (special register, which can be used to store calculation results, etc.). To exchange data with other storage addresses through accumulator A. Note that PC is automatically shifted (automatically +1) to the address of the next statement. Using this statement essentially gives PC an initial position.
PC→MOV   P1, A     ; transfer the number in the accumulator (constant 0D) to port P1 (all 8 bits of port P1 are set to 0, low level, all bits of port P1 are in the off state, and the LED light is in the ready state for system response), and transfer data by byte. Special memory: PC→ indicates the address pointed by the pointer, and it will automatically increase by 1.
PC→MOV   C, 0A0H    ; Check the status of P2.0 port, and transfer the status of P2.0 port (determined by the key status) to the bit accumulator C. The address of bit accumulator C is the carry flag CY (D7H\PSW.7) of PSW (Program Status Word Register). P2.0 port can be on or off, that is, set to 1 or 0, high level or low level), and data is transferred by byte. Data is exchanged through bit accumulator C and other storage addresses. This statement can also be written as: MOV   C, P2.0, compare byte data transfer MOV  A, #00H or MOV   A, P1.
PC→MOV   P1.0, C; equivalent to MOV   90H, C; transfer the value in the bit accumulator C address to the P1.0 port (90H is its direct address), that is, transfer the state of the P2.0 port (determined by the direct address 0A0H state) to the direct address 90H, P1.0 port
PC→MOV   P1.1, C   ; equivalent to MOV   91H, C
PC→MOV   P1.2, C   ; equivalent to MOV   92H, C
PC→MOV   P1.3, C   ; equivalent to MOV   93H, C   , etc.
END; pseudo instruction, program end mark
 
Example   3 - Scanning to achieve digital movement change simulation
Example   4 - Dual-digital tube dual-port digital carry simulation
 
Example   5 - Dual-port digital display of dual-quadruple digital tube group - Single-port scanning mobile simulation - Dot matrix
Dual quad digital tube set dual port digital display - single port scanning mobile simulation, can be decomposed into
a)   Dual-port digital display of dual-quadruple digital tube group - single port no scanning no movement - > digital changes (depending on the digital meter and pointer),
b)   Dual-port digital display of dual-quadruple digital tube group - single-port scanning movement - > the number does not change (depending on the number table and pointer),
c)    Dual-port digital display of dual-quadruple digital tube group—single-port scanning movement—>digital changes (depending on the digital meter and pointer),
Reference address:51 MCU Simulation Example

Previous article:The interrupt architecture of 51 single chip microcomputer
Next article:Intelligent single pendulum period measuring instrument

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号