PIC18F458 single-chip microcomputer sleep state working mode and activation

Publisher:泥匠手Latest update time:2012-12-11 Source: 51heiKeywords:PIC18F458 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/*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

Keywords:PIC18F458 Reference address:PIC18F458 single-chip microcomputer sleep state working mode and activation

Previous article:PIC microcontroller drives LED digital tube display program
Next article:PIC single chip stopwatch program design

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号