key.c

来自「Atmega168+HMC1052+OLED开发指南针」· C语言 代码 · 共 76 行

C
76
字号
#include "common.h"


void KeyProcess(uint n)
{
	if(n>=500)
	{
		if(UnitONmark)
		ACCCalibrationisOK=0;
	}
	else if(n>=250)
	{
		if(UnitONmark)
		HMC1052CalibrationisOK=0;
	}
	else if(n>0)
	{
		UnitONmark^=1;
		if(UnitONmark)
		{
			PORTD=0;
			oled_initial();
			clear_screen();	
		}
		else
		{
			clear_screen();
			oled_reset();
			SPI_MasterInit();
			MainOLED_WCom(0xAD);	// SET DC/DC BOOSTER(8AH=OFF,8BH=ON)
    		MainOLED_WCom(0x8A);	// built-in DC-DC turn off
			MainOLED_WCom(0xAE);	// Display turn off
			PORTD&=0b00001111;
			PORTD|=0b11110000;
			OLED_POWER_OFF;
			//BATT_POWER_OFF;
		}
	}
	KeyCounter=0;
}

void Key(void)
{
	if(!KeyValue) 
	{ 
		KeyMark=0;
		if(!KeyCounter)
			return ; 		/*no pressing, exit*/
	} 
	if(KeyMark) /*detect pressing for the first time?*/ 
	{ 
		KeyCounter++; /*detecting pressing is not first time*/ 
		//if(Qdsj==KeyCounter) /*pressing for Qdsj times?*/ 
		//{ 
			//KeyCounter-=Ljsj;
		//	KeyProcess(KeyValue,1); /*Processing button*/ 
		//} 
		//else
		//{ return ; } /* pressing button is not get to Qdsj times*/ 
	} 
	else /*detect pressing first time*/ 
	{
		_delay_loop_1(100); /*delay 10ms*/
		if(!KeyValue) 
		{
			KeyProcess(KeyCounter);
			return ; /*no pressing, exit*/
		}
		else
		{
			//BATT_POWER_ON;
			KeyMark=1;
		}
	}
} 

⌨️ 快捷键说明

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