📄 key_cntrl_ad_30avg.c
字号:
/////////////////////////////////////
// COPYRIGHT RESERVED BY DU //
/////////////////////////////////////
#include "c8051F020.h"
#include "intrins.h"
#include "CH452CMD.H" // 定义常用命令码及外部子程序
#include "pin.h"
#include "math.h"
#include "key_display.h"
//定义端口
sbit LEDG = P3^4;
ulong xdata data0[15]={
0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,};
ulong avge=0;
// Peripheral specific initialization functions,
// Called from the Init_Device() function 系统设置,020初始化 DA_OUT AD_IN
void Port_IO_Init()
{
XBR2 = 0x40;
}
void Interrupts_Init()
{
IE = 0x80;
EIE2 = 0x20;
}
// Initialization function for device,
// Call Init_Device() from your main program
void Init_Device(void)
{
Reset_Sources_Init();
ADC_Init();
Voltage_Reference_Init();
Port_IO_Init();
Interrupts_Init();
}
//主函数main
void main(void)
{
//unsigned char key;
//ulong avgad1=0,avgad=0,state=0;
//uchar i;
Init_Device();
CH452_Init(); /* CH452初始化 */
LEDG=0;
while(1)
{
DELAY_1US;
DELAY_1US;
//key = CH452_Read()
LEDG=~LEDG;
//delayms(2);
//AMX0SL = 0x03;
//state=(AD_IN(1,1));
//result=(int)state;
//BCDdisplay(result);
//delayms(20);
}
}
void led(void) interrupt 19
{
uchar i,key;
ulong avgad1=0,avgad=0,state=0; //fore=0,num=0,result=0;
EA=0;
state=AD_IN();
key=CH452_Read();
if(0x63==key)
{
delayms(2);
for(i=0;i<15;i++)
{
data0[i]=state;
avgad+=data0[i];
delayms(1);
}
avgad=avgad/15;
for(i=0;i<15;i++)
{
data0[i]=state;
avgad1+=data0[i];
delayms(1);
}
avgad1=avgad1/15;
avge=(avgad+avgad1)/50;
//CH452_Write(CH452_DIG1|b);
//CH452_Write(CH452_DIG0|c);
BCDdisplay(avge);
}
EA=1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -