【51 MCU】Exam routines | Assembly implementation

Publisher:SereneNature7Latest update time:2021-06-18 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Table of contents

Interrupt 3 programs

First program

Second program

The third program

DA Conversion

Triangle

Triangle2

Rectangular wave

Display/Keyboard:

Dynamic display of digital tube (implemented in C language):

Matrix keyboard (implemented in C language)

Addition, multiplication

The second routine

Routines

Routines

Interrupt 3 programs


First program

ORG 0000H

RESET: AJMP MAIN

ORG 000BH

AJMP IT0P

MAIN: MOV SP, #60H;

MOV TMOD, #01;

ACALL PT0M0;

HRER: AJMP HERE

PT0M0: MOV  TL0, #0CH

MOV TH0, #0FEH

SETB ET0;

SETB OF;

SETB TR0;

RIGHT

IT0P: MOV  TL0, #0CH

MOV TH0, #0FEH

CPL P1.0;

RARELY;


Second program

ORG 0000H

RESET: AJMP MAIN

ORG 000BH

AJMP IT0P

ORG 0100H

MAIN: MOV SP, #60H

MOV B, 0AH

ACALL PT0M0

HERE: AJMP HERE

PT0M0: MOV TMOD, #01H

MOV TL0, #

MOV TH0, #

SETB ET0

SETB OF

SETB TR0

RIGHT

IT0P: MOV TL0,# 

MOV TH0,# 

JNZ B, LOOP

RTURN: RETI


The third program

ORG 0000H

RESET: AJMP MAIN

ORG 000BH

AJMP IT0P

ORG 001BH

AJMP IT1P

ORG 1000H

MAIN: MOV SP, #60H

ACALL PT0M2

LOOP: MOV C, F0

JNC LOOP

HERE: AJMP HERE

PT0M0: MOV TMOD, #25H

MOV TL0, #FFH

MOV TH0, #FFH

SETB ET0

MOV TL1, #06H

MOV TH1, #06H

CLR F0

SETB OF

SETB TR0

RIGHT

IT0P: CLR TR0

SETB F0

RARELY

IT1P: CPL P1.0

RARELY


DA Conversion

Triangle

ORG 0100H

START: MOV R0, #0FEH

MOV A, #00H

LOOP: MOVX @R0, A

INC A

JNZ LOOP


Triangle2

ORG 0100H

START: MOV R0, #0FEH

MOV A, #00H

UP: MOVX @R0, A

INC A

JNZ UP

DOWN: DEC A

MOVX @R0, A

JNZ DOWN

AJMP UP


Rectangular wave

ORG 0100H

START: MOV R0, #0FEH

MOV A, #data1

MOVX @R0, A

ACALL DELAY1 

MOV A, #data2

MOVX @R0, A

ACALL DELAY2


Display/Keyboard:

Dynamic display of digital tube (implemented in C language):

#include

#define uchar unsigned char

#define uint unsigned int


#define DigW P1 //Set P1 port as bit selection port (select the number of bits)

#define DigD P2 //P2 is segment selection (select which segment of the digital tube lights up)

uchar show[] = {5, 2, 0, 1, 3, 1, 4};

float DigT[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 

                0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71}; // Common cathode digital tube 0~9, af segment code table

/******************************Delay function*****************************/


void delay() {

    uint j;

    for (j = 0; j < 150; j++);

}


/**************************Main function****************************/

void main(void) {

    Dig_W = 0x00; // Turn off the digital tube

    You_D = 0x00;


    while (1) {

        fly temp = 0x80;

        for (uchar i = 0; i < 7; i++) {

            Dig_W = tmep;

            Dig_D = DigT[show[i]+1];

            delay();

            temp = temp >> 1;

        }

    }

}


Matrix keyboard (implemented in C language)

insert image description here

#include


#define uchar unsigned char

#define uint unsigned int


#define Dig_W  P1

#define Dig_D  P2

#define io_KEY    P3


uchar key_T[] = {0xee, 0xde, 0xbe, 0x7e,

                 0xed, 0xdd, 0xbd, 0x7d,

                 0xeb, 0xdb, 0xbb, 0x7b,

                 0xe7, 0xd7, 0xb7, 0x77}; //Key value


uchar dis_T[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f,

                 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71}; // Common cathode digital tube 0~9, af segment code table

fly zhi = 0;

/******************************Delay function*****************************/

void d_ms()

{ uint j;

for(j=0;j<150;j++);

}

/**************************Display function****************************/

void display(uchar num) {

    flying i, temp;

    temp = 0x80;

    Dig_W = temp;

    Dig_D = dis_T[num];

    temp = temp >> 1;

}


uint Scanner() {

    int column = 0, row = 0, key = 0, a;

    io_KEY = 0xf0; //The last 4 positions of P2 port are high level and the first 4 positions are low level. When a key is pressed, the number of columns is determined.

    while (io_KEY == 0xf0); //Judge whether there is a signal input at port P2

    Column = io_KEY; //Save the number of columns


    delay();

    io_KEY = 0x0f; //The last 4 positions of P2 port are low level and the first 4 positions are high level. When a key is pressed, the number of rows is determined.

    while (io_KEY == 0x0f); //Judge whether there is a signal input at P2 port

    row = io_KEY; // Number of rows saved

    key = column | row;

    return button;

}


/**************************Main function****************************/

void main(void) {

    uint KeyV = 0;

    Dig_W = 0x00; // Turn off the digital tube

    You_D = 0x00;


    while (1) {

        KeyV = Scanner(); //Get the key value

        for (int i = 0; i < 16; i++) //Judge the key value

        {

            if (key_T[i] == KeyV) {

                zhi = i;

                break;

            }

        }

        display(zhi);

    }


Addition, multiplication

    MOV R0,#60H

    MOV R2,#10H

    CLR A

YOU: MOV @R0,A

    INC R0

    INC A

    DJNZ R2,TU

    MOV R0, #60H

    MOV R1, #70H

    MOV R2, #10H

TT: MOV A,@R0

    MOV @R1,A

    INC R0

    INC R1

    DJNZ R2,TT

    RIGHT

    END


The second routine

     MOV 70H, #12H

     MOV 71H, #90H

     MOV 72H, #78H

     MOV 60H, #56H

     MOV 61H, #34H

     MOV 62H, #12H

     MOV R0,#70H

     MOV R1,#60H

     MOV R2,#03H

     CLR CY

LOOP:MOV A,@R0

     ADDC A,@R1

     And A

     MOV @R1,A

     INC  R0

     INC  R1

     DJNZ R3,LOOP

     END


Routines

        MOV 30H,#45H

LOOP: MOV A,30H

    SWAP A

ANL A,#0FH

MOV 31H,A

MOV A,30H

ANL A,#0FH

MOV 32H,A

END

MOV 32H, #98H

MOV 31H,#76H

MOV 30H, #54H

MOV R2, #04H

LOOP: CLR CY

MOV A,30H

RLC A

MOV 30H,A

MOV A,31H

RLC A

MOV 31H,A

MOV A,32H

RLC A

MOV 32H,A

DJNZ R2,LOOP

RIGHT

END                                                                                   

Routines

ORG 0000H

START: MOV R0,#60H

MOV DPTR,#QW1

MOV R5, #0

MOV R7,#10H

LOOP: MOV A,R5

MOVC A,@A+DPTR

MOV @R0,A

INC R0

INC R5

DJNZ R7,LOOP

LJMP QW2

QW1: DB 60H,61H,62H,63H,64H,65H,66H,67H

DB 68H,69H,6AH,6BH,6CH,6DH,6EH,6FH

QW2:MOV R0,#60H

MOV R1,#70H

MOV R5,#0FH


Reference address:【51 MCU】Exam routines | Assembly implementation

Previous article:51 single chip microcomputer course design: Ultrasonic ranging based on 51 single chip microcomputer
Next article:51 MCU development interrupt

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号