The use of single chip computer scattered transfer table program

Publisher:快乐的舞蹈Latest update time:2016-01-22 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Using a scatter table can reduce program writing as much as possible and is convenient.

Reduce the number of judgments.

Program name: scatter program test
; Description: LED1 lights up after starting, press any key, register r0 starts to increase from zero, and according to the content of r0, the program scatters to
the corresponding place to execute, so as to light up different LEDs
; Entry: p3.0--p3.3
; Exit: P0
; Practice date: 2007--06--17     Good mood

;Revision date: 2007--06--18     
;Revision content: Change the original ljmp part to ajmp, and change the end value of R0 to 08
;**************************************************************************
   org    0000h
   ljmp    main
   org    0030h
main:   mov    p0,     #07fh      ;Initialize port P0, turn on led1
   mov    r0,     #00h      ;Initialize R0, set R0 to 1
;**********************Key detection********************************************
st:   mov    P3,     #0Fh      ;Set port P3 to prepare for key detection, set the lower 3 bits of p3 to 0
   mov    a,      p3       ;Read the status of port P3
   cjne    a,      #0fh,    F1   ;Judge whether a key is pressed, if so, jump to F1 (Compare and transfer, compare the size of a and #0fh
                  ; if they are not equal, transfer, otherwise execute sequentially, if the first number is greater than the second number, CY
                  ; clear to zero, otherwise set to 1, do not affect other operation bits, 3-byte instruction
   acall    del
   ajmp    st
;**********************Debounce*******************************************
F1:   acall    del           ;Delay
   cjne    a,      #0fh,    f2   ;Judge the key again, if pressed, then zone key processing program, otherwise interference
   ajmp    st
;**********************Key processing************************************************mov
F2:   inc    r0            ;r0 plus 1
   cjne    r0,     #08h,    F3   ;Judge whether R0 = 8, if equal, execute sequentially and clear R0, otherwise jump to the scattered transfer program
   mov    r0,     #00h      ;R0 clear
   ajmp    main
;**********************Scattered transfer processing************************************************
F3:   mov    DPTR,     #TAB      ; transfer the data table address to DPTR
   mov    a,      R0       ; send the offset to a
   clr              ; clear the carry bit
   rlc              ; shift the content of accumulator a to the left (equivalent to *2)
   jnc    nadd           ; if cy is zero, jump to NADD, otherwise execute sequentially
   inc    dph           ; if cy is 1, DPH+1 (because DPTR is a 16-bit address and a is 8 bits, adding one here is equivalent to the lower 8 bits of DPTR
                  ; carry to the upper 8 bits) correct the address
NADD:   jmp    @a+DPTR          ; bulk instruction, add the unsigned number in a to the 16 bits of the data pointer DPTR, and the sum is used as the next instruction
                  ; the address is sent to PC, a and dptr are not changed, and the flag bit is not affected. The variable address method is used to realize unconditional transfer
                  ; its characteristic is that the transfer address can be changed in the program
; ****************************Data table************************************************
TAB:   nop
   nop               ; empty instruction, correct address
   ajmp    pb1
   ajmp    pb2
   ajmp    pb3
   ajmp    pb4
   ajmp    pb5
   ajmp    pb6
   ajmp    pb7
   
   
;***********************延时***************************************************
del:   mov    R1,    #014h
d1:   mov    R2,    #0FFH
d2:   mov    r5,    #01fh
    djnz    R5,    $
    djnz    R2,    d2
    djnz    R1,    d1
    ret
;***********************显示**************************************************
pb1:   mov    p0,    #03fh
    acall    del
    ljmp    st
pb2:   mov    p0,    #01fh
    acall    del
    ljmp    st
pb3:   mov    p0,    #0fh
    acall    del
    ajmp    st
pb4:   mov    p0,    #07h
    acall    del
    ajmp    st
pb5:   mov    p0,    #03h
    acall    del
    ajmp    st
pb6:   mov    p0,    #01h
    acall    del
    ajmp    st
pb7:   mov    p0,    #00h
    acall    del
    ajmp    st
    end

Reference address:The use of single chip computer scattered transfer table program

Previous article:Microcontroller interrupt experiment
Next article:The use of single chip computer scattered transfer table program

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号