/*This program implements the sleep mode of PIC18F458, and activates it from sleep mode by generating "level change interrupt" by the key on the experimental board. The sleep and active states are displayed by 8 LEDs connected to port D. When in sleep mode, the high 4
LEDs light up and the low 4 LEDs turn off; after activation, the high 4 LEDs turn off and the low 4 LEDs light up*/
#include "p18f458.h"
unsigned long i;
/*System initialization subroutine*/
void initial()
{
INTCON=0x08; /*Global interrupt disabled, "level change interrupt" only performs wake-up function*/
/*Clear B port level change interrupt flag*/
TRISA=0x00; /*Port A is set to output*/
TRISB=0XF0; /*RB1 output, RB4 input*/
TRISD=0X00; /*Port D is output*/
TRISE=0x00; /*Port E is set to output*/
PORTBbits.RB1=0;
PORTAbits.RA3=0;
PORTE=0; /*Set K1, K2, K3, K4 four column lines to 0*/
PORTB=PORTB; /*Read the value of PORTB, latch the old value, and prepare for "level change
interrupt"*/
}
void SLEEP()
{
_asm
SLEEP /*Enter sleep state*/
_endasm
}
/*Main program*/
main ()
{
initial(); /*Initialization*/
PORTD=0X0F; /*The upper 4 LEDs are on*/
SLEEP(); /*The MCU starts to enter sleep mode*/
PORTD=0XF0; /*After activation, the lower 4 LEDs are on*/
while(1)
{
;
}
}
Complete!
-----------PIC18F458 MCU sleep mode and activation written in assembly language-----------------------
;This program implements the sleep mode of PIC18F458,
;http://www.51hei.com This program has been tested with the MCU experiment board of this site
; and the "level change interrupt" generated by the button on the experiment board activates it from the sleep state.
LIST P=18F458
INCLUDE "P18F458.INC"
COUNT EQU 0X20
ORG 0X00
GOTO MAIN
ORG 0X30
;************Display subroutine****************
DISPLAY
CLRF PORTA
MOVWF SSPBUF
LOOP NOP
BTFSS PIR1,SSPIF
GOTO LOOP
NOP
BCF PIR1,SSPIF
BSF PORTA,5 ;For detailed program statements, please refer to Section 3. 1. 3
RETURN
;**********Initialization subroutine*************
INITIAL
BCF INTCON, GIE ;Global interrupt disabled, "level change interrupt" only executes wake-up function
BSF INTCON, RBIE ;PORTB level change interrupt enabled
BCF INTCON, RBIF ;Clear B port level change interrupt flag
BCF TRISA, 5 ;Set RA5 to output mode to output latch signal
BCF TRISB, 1
BCF TRISA, 3
BCF TRISE, 0
BCF TRISE, 1
BSF TRISB, 4 ;Set the input and output mode of each port related to the keyboard
BCF TRISC, 5
BCF TRISC, 3 ;Set SCK and SDO to output mode
MOVLW 0XC0
MOVWF SSPSTAT ;Set SSPSTAT register
MOVLW 0X30
MOVWF SSPCON1 ;Set the SPI control mode, allow SSP mode, and send on the falling edge of the clock
,
which corresponds to the characteristic of "
when the SCLK of 74HC595 jumps from low to high,
the serial input data (DI) is moved into the register"
BCF PORTB, 1
BCF PORTA, 3
BCF PORTE, 0
BCF PORTE, 1 ;Set the four column lines K1, K2, K3, and K4 to 0 to
create the initial conditions
for the generation of level change interrupts
RETURN ;Return
;****************************************
MAIN NOP
CALL INITIAL ;Initialize
MOVLW 0X08
MOVWF COUNT
MOVLW 0XFF ;"FF" is the display segment code of "DARK"
NEXT1
CALL DISPLAY ;Before sleep mode, all 8 LEDs display "DARK"
DECF COUNT, 1
BTFSS STATUS, Z
GOTO NEXT1
SLEEP ;PIC16F877 enters "sleep mode"
NOP
MOVLW 0X08
MOVWF COUNT
MOVLW 0X90 ;"90" is the display segment code of "9"
NEXT
CALL DISPLAY ;After waking up from sleep mode, display 8 characters "9"
DECF COUNT, 1
BTFSS STATUS, Z
GOTO NEXT
NOP
END
Previous article:PIC microcontroller drives LED digital tube display program
Next article:PIC single chip stopwatch program design
- Popular Resources
- Popular amplifiers
- CVPR 2023 Paper Summary: Explainable AI for CV
- CVPR 2023 Paper Summary: Efficient and Scalable Vision
- Chip Manufacturing: A Practical Tutorial on Semiconductor Process Technology (Sixth Edition)
- Python and machine learning practice: decision tree, ensemble learning, support vector machine and neural network algorithm detailed explanation and programming implementation
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
- Commonly used algorithms for drones - Kalman filter (Part 9)
- Reset time problem
- Why does DLL not found error appear when running VB with Ginkgo?
- The problem of STM8L151k4t6 with programmed code being damaged by soldering?
- DSP28335 external interrupt configuration process
- Circuit PCB Design
- What is Wi-Fi 6?
- MSP430F5529 Getting Started with Small Examples
- What will the elevators of the future look like?
- Thoughts on the development of single-chip microcomputers