;After pressing the start key (PT2.1), the program realizes LED flashing
;Purpose: Learning the input and output control of I/O port
;===============================================
;Complete code download address: http://www.51hei.com/f/xhpms.rar
; filename: 111.asm
; chip : csu1181b
; author :
; date : 2012-07-18
;============================================
include csu1181b.inc
;=================================================
; program start
;==============================================
org 0000h ;
goto a1 ;
org 0005h ;
;***************************************************
; Determine whether the start key is pressed
;***********************************************
a1: CLRWDT ; Clear the watchdog
MOVLW 00H ; Store the data 00H in W for setting the I/O port as an input port
MOVWF PT2EN ; Store the data in W in PT2EN (25h) to set the I/O port as an input port
MOVLW 0FFH ; Store the data 0FFH in W for setting the I/O port to pull-up mode
MOVWF PT2PU ;Store the data in W into PT2PU (26h) and set the I/O port to pull-up mode
BTFSC PT2,1 ;Judge whether PT2.1 is 0, if yes, skip the next instruction (Judge whether a key is pressed, if yes, execute the following program, if no, wait for the key to be pressed)
GOTO A1 ;Unconditionally transfer to A1
;***************************************************
; Flashing program segment
;***************************************************
A2: CLRWDT ;Clear watchdog
MOVLW 0FFH ;Store the data 0FFH into W and use it to set the I/O port as output
MOVWF PT3EN ;Store the data in W into PT3EN (29h) and set the I/O port as output
MOVLW 0 ;Store the data 00H into W and use it to set the I/O port to disable pull-up mode
MOVWF PT3PU ;Store the data in W in PT3PU (2ah) and set the I/O port to disable pull-up mode
MOVLW 01010101B ;Store the data 01010101B in W and use it as the output data of the I/O port
MOVWF PT3 ;Output the data in W from PT3 (28h) to drive external devices (light up the LED)
CALL M001 ;Delay
MOVLW 10101010B ;Store the data 10101010B in W and use it as the output data of the I/O port
MOVWF PT3 ;Output the data in W from PT3 (28h) to drive external devices (light up the LED)
CALL M001 ;Delay
goto a2 ;Return and repeatedly execute the program
;********************************************************
; Delay program segment
;****************************************************
M001: MOVLW 2 ;
MOVWF 80H ;
M002: MOVLW 248 ;
MOVWF 81H ;
M003: MOVLW 250 ;
MOVWF 82H ;
M004: DECFSZ 82H,1 ; (The result after decrement is stored in 82h) If the decrement is 0, skip the next instruction
; DECFSZ 82H,0 ; (The result after decrement is stored in the working register) If the decrement is 0, skip the next instruction
GOTO M004 ;
DECFSZ 81H,1 ;
GOTO M003 ;
DECFSZ 80H,1 ;
GOTO M002 ;
RETURN ; The subroutine returns
to end ; End
;================================================
Reference address:Xinhai MCU flashes after pressing the start button
;Purpose: Learning the input and output control of I/O port
;===============================================
;Complete code download address: http://www.51hei.com/f/xhpms.rar
; filename: 111.asm
; chip : csu1181b
; author :
; date : 2012-07-18
;============================================
include csu1181b.inc
;=================================================
; program start
;==============================================
org 0000h ;
goto a1 ;
org 0005h ;
;***************************************************
; Determine whether the start key is pressed
;***********************************************
a1: CLRWDT ; Clear the watchdog
MOVLW 00H ; Store the data 00H in W for setting the I/O port as an input port
MOVWF PT2EN ; Store the data in W in PT2EN (25h) to set the I/O port as an input port
MOVLW 0FFH ; Store the data 0FFH in W for setting the I/O port to pull-up mode
MOVWF PT2PU ;Store the data in W into PT2PU (26h) and set the I/O port to pull-up mode
BTFSC PT2,1 ;Judge whether PT2.1 is 0, if yes, skip the next instruction (Judge whether a key is pressed, if yes, execute the following program, if no, wait for the key to be pressed)
GOTO A1 ;Unconditionally transfer to A1
;***************************************************
; Flashing program segment
;***************************************************
A2: CLRWDT ;Clear watchdog
MOVLW 0FFH ;Store the data 0FFH into W and use it to set the I/O port as output
MOVWF PT3EN ;Store the data in W into PT3EN (29h) and set the I/O port as output
MOVLW 0 ;Store the data 00H into W and use it to set the I/O port to disable pull-up mode
MOVWF PT3PU ;Store the data in W in PT3PU (2ah) and set the I/O port to disable pull-up mode
MOVLW 01010101B ;Store the data 01010101B in W and use it as the output data of the I/O port
MOVWF PT3 ;Output the data in W from PT3 (28h) to drive external devices (light up the LED)
CALL M001 ;Delay
MOVLW 10101010B ;Store the data 10101010B in W and use it as the output data of the I/O port
MOVWF PT3 ;Output the data in W from PT3 (28h) to drive external devices (light up the LED)
CALL M001 ;Delay
goto a2 ;Return and repeatedly execute the program
;********************************************************
; Delay program segment
;****************************************************
M001: MOVLW 2 ;
MOVWF 80H ;
M002: MOVLW 248 ;
MOVWF 81H ;
M003: MOVLW 250 ;
MOVWF 82H ;
M004: DECFSZ 82H,1 ; (The result after decrement is stored in 82h) If the decrement is 0, skip the next instruction
; DECFSZ 82H,0 ; (The result after decrement is stored in the working register) If the decrement is 0, skip the next instruction
GOTO M004 ;
DECFSZ 81H,1 ;
GOTO M003 ;
DECFSZ 80H,1 ;
GOTO M002 ;
RETURN ; The subroutine returns
to end ; End
;================================================
Previous article:Assembly language and assembly process
Next article:Xinhai comes with a pen-segment LCD
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
MoreDaily News
- 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
Guess you like
- Writing cmd files in CCS
- Switching Power Supply Interest Group 17th Task
- The live broadcast has ended [Microchip Embedded Security Solutions | RISC-V Safe Place]
- I am offering a reward to find a DSP expert with sufficient skills to be my mentor. It will be paid.
- Old topic: Why do we need to place a 0.1uF capacitor near the chip IC?
- fdc2214 oled capacitor test msp430 program source code
- Can NPN stn0214 work with 500V added to VCE?
- The application principle and connection method of AND gate circuit
- Fundamentals of Digital Logic with Verilog Design 3rd Edition
- [2022 Digi-Key Innovation Design Competition] Material Unboxing STM32H745I-DISCO