📄 platform.c
字号:
#include "std.h"
#include "key.h"
#define _KEYBOARDLINE_NUM_ 1 //HOW MANY ADC USE TO KEY BOARD
#define _KEYBOARDLEVEL_NUM_ 8
#define _PT1KLEVEL_NUM_ 8
/////////// ADC key LEVELS dividing line///////////////////////////////////////
#define _KEYBOARD_1_ 0x0080 //128
#define _KEYBOARD_2_ 0x0100 //256
#define _KEYBOARD_3_ 0x0180 //384
#define _KEYBOARD_4_ 0x0200 //512
#define _KEYBOARD_5_ 0x0280 //640
#define _KEYBOARD_6_ 0x0300 //768
#define _KEYBOARD_7_ 0x0380 //896
#define _KEYBOARD_8_ 0x03E8 //1000
//////PT1000 dividing line
#define _PT1K_1_ 0x35B //859
#define _PT1K_2_ 0x39E //926
#define _PT1K_3_ 0x3D1 //977
#define _PT1K_4_ 0x3FC //1020
#define _PT1K_5_ 0x41F //1055
#define _PT1K_6_ 0x442 //1090
#define _PT1K_7_ 0x461 //1121
#define _PT1K_8_ 0x464 //1124
/////PT1000 Temperature dividing line
#define _RoomTemp_1_ -36
#define _RoomTemp_2_ -19
#define _RoomTemp_3_ -6
#define _RoomTemp_4_ 5
#define _RoomTemp_5_ 14
#define _RoomTemp_6_ 23
#define _RoomTemp_7_ 31
#define _RoomTemp_8_ 32
const Word c_aucKeyboardCommand[_KEYBOARDLINE_NUM_][_KEYBOARDLEVEL_NUM_]=
{1,2,3,4,5,6,7,8}; //KEY CODE OF EACH LEVEL
const Byte c_KeyBoardLine[]={0,1,2};//define for ADC port
const Word c_aucKeyboardLevel[_KEYBOARDLEVEL_NUM_] =
{
_KEYBOARD_1_, _KEYBOARD_2_, _KEYBOARD_3_, _KEYBOARD_4_, _KEYBOARD_5_, _KEYBOARD_6_, _KEYBOARD_7_, _KEYBOARD_8_
};
const Word c_PT1KLine[_PT1KLEVEL_NUM_] =
{
_PT1K_1_, _PT1K_2_, _PT1K_3_, _PT1K_4_, _PT1K_5_, _PT1K_6_, _PT1K_7_, _PT1K_8_
};//pt1k
const Byte c_RoomTempLine[_PT1KLEVEL_NUM_] =
{
_RoomTemp_1_, _RoomTemp_2_, _RoomTemp_3_, _RoomTemp_4_, _RoomTemp_5_, _RoomTemp_6_, _RoomTemp_7_, _RoomTemp_8_
};
Word tdGetADCValue(Byte ucKeyLine)
{
static Byte ucOrgADCChannel;
Word wADCVal,wADCVal2;
wADCVal = 0;
//if(ucOrgADCChannel != ucKeyLine)
{/* change ADC channle */
ADCSRA &= ~0x40;
ucOrgADCChannel = ucKeyLine;
// ADMUX &= 0xE0;
ADMUX |= ucKeyLine;
ADCSRA |= 0x40;
//wait for conversion complete
while((ADCSRA & 0x10) == 0)
{
}
//read result
wADCVal = ADCL;
wADCVal2 = ADCH;
wADCVal += (wADCVal2<<8);
ADCSRA |= 0x10;//clear interrupt flag
return wADCVal;
//tdSleep(10);
//ADCSRA &= ~0x40;
}
#if 0
ADCSRA &= ~0x40; /* stop ADC and read back last value*/
wADCVal = ADCL;
wADCVal2 = ADCH;
wADCVal += (wADCVal2<<8);
wADCVal >>= 2; /* HIGH 8 BIT AS RETTURN VAL */
ADCSRA |= 0x40; /* prepare for next adc */
#endif
ADMUX = 0xC0;
ADCSRA=(1<<ADEN)|(1<<ADPS1)|(1<<ADPS0);
ADCSRA|=(1<<ADSC);//自由模式开始转换
tdSleep(100);
wADCVal = ADCL;
wADCVal2 = ADCH;
wADCVal += (wADCVal2<<8);
return (Byte)wADCVal;
}
Word tdGetADCKeyCode(Void)
{
Byte uc;
Byte uc2;
Word ucKeyBoardScan;
for (uc = 0; uc < _KEYBOARDLINE_NUM_; uc++)
{
ucKeyBoardScan = tdGetADCValue(c_KeyBoardLine[uc]);
DbPrintf2("%d ADC value is %x\n",uc,ucKeyBoardScan);
for (uc2 = 0; uc2 < _KEYBOARDLEVEL_NUM_; uc2++)
if (ucKeyBoardScan < c_aucKeyboardLevel[uc2])
return c_aucKeyboardCommand[uc][uc2];
}
// NO KEY GET
return _VK_NONE_;
}
/* 把实际扫描到的按键值转换为标准按键值 */
Un_Sizet_1 KeyConvert(Un_Sizet_1 ucScanValue)
{
}
Byte GetKeyCode()
{
}
Byte tdResToTemp(Word wRes, Byte bTempRef, Word wResRef)
{
return (bTempRef+(wRes-wResRef)/4);
}
Long dwWatch;
Byte bWatch;
Char tdGetRoomTemp(Void)
{
Word wSensorADC;
Word wSensorADC2;
Word dwSensorValue;
Byte cRoomTemp;
Byte uc;
ADMUX |= 0x41;
ADCSRA |= 0x40;
//wait for conversion complete
while((ADCSRA & 0x10) == 0)
{
}
//read result
wSensorADC = ADCL;
wSensorADC2 = ADCH;
wSensorADC += (wSensorADC2<<8);
ADCSRA |= 0x10;//clear interrupt flag
//conversion equation about wSensorADC to wSensorValue
//wSensorValue=(1023+wSensorADC)/(1023*2-wSensorADC)*1200
dwSensorValue=((long int)(1023 + wSensorADC)*1200)/(1023*2-wSensorADC);
//compute Room Temperature from Sensor Value according to pt1000 characteristic table
for (uc = 0; uc<_PT1KLEVEL_NUM_-1; uc++)
{
if (dwSensorValue<c_PT1KLine[uc])
{
cRoomTemp = c_RoomTempLine[uc]+(dwSensorValue-c_PT1KLine[uc])/4;
return cRoomTemp;
}
}
cRoomTemp = c_RoomTempLine[_PT1KLEVEL_NUM_-1]+(dwSensorValue-c_PT1KLine[_PT1KLEVEL_NUM_-1])/4;
return cRoomTemp;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -