⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 key.c

📁 use a simply manner to transfer little lendian ASCII number to hexcdemical, and vice versa.
💻 C
字号:
#include "1163app.h"

uint8_t ScanKey(void)
{ 	static uint8_t newkey, oldkey, keytmr;
	uint8_t tmpkey = 0;
	
	if (~KeyPort & (1<<ONkeyPin)) tmpkey |= 0x01;
	if (~KeyPort & (1<<OFFkeyPin)) tmpkey|= 0x02;
	if (~RotaryPort & (1<<RotaryKeyPin)) tmpkey |= 0x04;
	if (tmpkey) IniDimDet();
	if (newkey == tmpkey)
	{	if (newkey != oldkey)
		{	if (++keytmr >= 4)
			{	oldkey = newkey;
				return oldkey;
			}
		}
	}
	else
	{	newkey = tmpkey;
		keytmr = 0;
	}	
	return KEY_NULL;
}

/*
DESC: Read the status of rotatory
  In:
 Out:*/
void ScanRotator(void)
{	static uint8_t RotatorIn,RotatorCnt;
	uint8_t status;
	
	status = (RotatorIn << 1) & 0xFE;
	if (RotaryPort & (1 << RotaryAPin)) status++;
	status <<= 1;
	if (RotaryPort & (1 << RotaryBPin)) status++;
	if ((status ^ RotatorIn) & 0x03)
	{	IniDimDet();
		RotatorTmr = ROTATORTMR;
		if (++RotatorCnt == 3) 
		{	RotatorCnt = 0;
			RotatorIn = status;
			status &= 0x3F;
			switch (status)
			{	case 0x07:
				case 0x38:
					if ( RotatorR++ < 99);
					RotaryDir = 'R';
					break;
				
				case 0x34:
				case 0x0B:
					if ( RotatorL++ < 99);
					RotaryDir = 'L';
					break;
			}
		}
	}
	else
	{	RotatorCnt = 0;			
	}
}


/*
Desc:Transfer hexadecimal number to decimal number
  In: hexadecimal start address  
 Out: highest address of decimal*/
uint8_t *Hex2Dec(uint8_t *dstptr)
{	uint16_t temp;
	temp =(uint16_t) *dstptr;
	do
	{	*dstptr++ = (temp % 10) | 0x30;
		temp /= 10;
	}while (temp);
	return --dstptr;
}


/*
DESC: Transfer decimal to hexadecimal
  In: decimal data
 Out: hexadecimal data*/
uint8_t Dec2Hex(uint8_t *srcptr)
{	uint8_t i=1, j=1, data=0;
	while (*(++srcptr) != Paket_EOL) i++;
	for ( ; i>0; i--)
	{	data += (*(--srcptr) - 0x30) * j;
		j *= 10;		
	}
	return data;	
}

/*
DESC: change byte number to BCD and send it through uart0
  In: data
 Out: N/A*/
void SendAsChar (uint8_t data)
{	uint8_t i = 100, j = 0;
	if (data == 0)
	{	uart_putchar(0x30);
		return;
	}
	for ( ; ; )
	{	if ((data >= i) || j)
		{	j = 1;
			uart_putchar((data / i) | 0x30);
			data %= i;
		}
		if (i == 1) break;
		i /= 10;
	}
}

⌨️ 快捷键说明

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