示例#1
0
// Sleep mode - External peripherals all allowed to run unless specified
void SystemPwrSave(unsigned short NapSetting)
{
	//KL WARNING - modified for simpler behaviour, manage your own interrupt wake sources
	uint16_t IPLshadow; // Interrupt context saving

	IPLshadow = SRbits.IPL;
	SRbits.IPL = 0b111;	// Stop all interrupts from vectoring

	/*Note: Add/remove power down settings as needed*/
	U1PWRCbits.USBPWR = 0; // MCHP Bug, not cleared in usb detach +120uA

	// Wdt
	if (NapSetting & WAKE_ON_WDT)
		{ClrWdt();RCONbits.SWDTEN = 1;}	// Turn on WDT

	// Go to sleep... zzzzzzzzzzzzzz
	if(NapSetting & LOWER_PWR_SLOWER_WAKE)	RCONbits.PMSLP = 0;
	else 									RCONbits.PMSLP = 1; 
	Sleep();
	__builtin_nop();

	// ON RETURN FROM SLEEP 
	if (NapSetting & WAKE_ON_WDT)
		{ClrWdt();RCONbits.SWDTEN = 0;}	// Turn off WDT

	SRbits.IPL = IPLshadow; // Effectively re-enable ints - will vector if flags are set!
    return ;                       
}
示例#2
0
int main(void)
{
        unsigned long int adval;
        init_adcs();

        while(1) {
                AD1CHSbits.CH0SA = 14;
                AD1CON1bits.SAMP = 1;
                while(!AD1CON1bits.DONE);
                adval = *((&ADC1BUF0) + 14);
                adval = ((3300L*adval)/4096L);
                //adval = 3*((4096L/adval)*3.3);
                __builtin_nop();
        }       
        return 0;
}