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) #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
Previous article:51 single chip microcomputer course design: Ultrasonic ranging based on 51 single chip microcomputer
Next article:51 MCU development interrupt
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- STM32 branch uses register method instead of HAL to drive DAC
- An important wireless technology is about to debut!
- 8 output modes of MSP430 microcontroller
- Audio circuit delay
- Unused nucleo F334, L053 F091
- Problems with RS485 communication self-transceiver circuit
- Many netizens recommend: Yatli AT-START-F403A, you deserve it! The event will be online soon, so stay tuned~
- The mobile station adds a new board, the STM32F723 Discovery Kit
- [Teardown of the car wireless charger] - Disassembling the Deli wireless car charger
- TTP250-S001 dimming solution and capacitive touch switch chip