rfid_sleep.c

来自「找的一个用U2270B开发的射频卡项目文件」· C语言 代码 · 共 114 行

C
114
字号
// $Id: rfid_Sleep.c,v 1.4 2006/10/18 18:15:12 tprescott Exp $
/*****************************************************
Project : rfid_Sleep.c
Date    : 9/08/2006
Author  : Toby Prescott                   
Company : Atmel                           
Comments: AVR Studio GCC

Revisions:
	v1.0 - Started written for CodeVision 
	v2.2 - 3/8/06 Changed to Switch
	v2.6 - 9/8/06 Clean for WinAVR
*****************************************************/

#include "rfid_Sleep.h"

volatile unsigned char sleepFlag = 0;			// Sleep mode flag

// *******************************************************************************
// *   Sleep Recovery Routine
// *******************************************************************************
void slp_RecoverSleep(void)
{
	MCUCR &= ~0x38;						// Set uC to run power mode
		
	PORTA=0xFF;							// Set Ports back to opperational mode
	DDRA=0x00;
	
	PORTB=0xFF;
	DDRB=0xE0;
	
	PORTC=0xFF;
	DDRC=0x40;
	
	PORTD=0xFD;
	DDRD=0xE6;
	
	PORTF=0xF7;
	DDRF=0x0E;

    #if defined (__AVR_ATmega128__)//mega128 pinout
	PORTE=0xCF;
	DDRE=0x00;
	PORTG=0xFF;
	DDRG=0x07;
    #elif defined (__AVR_AT90USB1287__)//usb1287 pinout
	PORTE=0xFF;
	DDRE=0x07;
    #endif

 	U2270_InitReader();                     // Recall saved Reader states
    lcd_Init_Display();                     // Initialize LCD
 	lcd_Write_Display(CMD,ALL_POINTS_OFF); 	// Turn LCD ON
 	upDate = 0;                        		// Write to LCD

}

// *******************************************************************************
// *   Sleep Mode Routine
// *******************************************************************************
void slp_EnterSleep(void)
{
	lcd_Write_Display(CMD,DISPLAY_OFF);    	// Turn the LCD OFF 
 	lcd_Write_Display(CMD,ALL_POINTS_ON);   // Put LCD in Low PWR mode
	RFIDTimer_Stop();                          // Stop Timer
	LCDTimer_Stop();							// Stop Timer
	GenericTimer_Stop();							// Stop Timer
		
	PORTA=0x00;								// Set Ports to low power state
	DDRA=0x00;
	
	PORTB=0x7F;
	DDRB=0x00;
	
	PORTC=0xBE;
	DDRC=0x41;
	
	PORTD=0x00;
	DDRD=0x00;
	
	PORTE=0xCC;
	DDRE=0x00;
	
	PORTF=0xF0;
	DDRF=0x00;
	
    #if defined (__AVR_ATmega128__)//mega128 pinout
	PORTG=0xF8;
	DDRG=0x00; 	
    #elif defined (__AVR_AT90USB1287__)//usb1287 pinout
    #endif

	sleepFlag = 1;						// Enable sleep

    while(sleepFlag == 1)			// Continue sleep through RTC wakeup's
    {
        MCUCR |= 0x38;				// Place uC in power down mode
	    sei();                		// (re)set the Global Interrupt Enable Bit 
	    asm("sleep");               // Return to sleep
        #if defined (__AVR_ATmega128__)//mega128 
    	if((PINE & PWRDETECT128) != 0)			//Check that PWR switch is on		
        #elif defined (__AVR_AT90USB1287__)//usb1287 
    	if((PINC & PWRDETECT1287) != 0)			//Check that PWR switch is on		
        #endif
    	{
    		sleepFlag = 0;   			//If PWR switch is off, got to sleep
    	} 
    }
	
    slp_RecoverSleep();					// Return I/O to ready states               
}

			

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?