现代单片机MC96FT1604的触摸怎么写?

2020-03-13 19:23发布

刚学现代单片机MC96FT1604,不知触摸怎么写,有没有DEMO代码?用代码生成器只能生成触摸的初始化代码。望各位指教一下,谢谢!
 

1条回答
男儿心中的梦
1楼-- · 2021-06-11 15:59

#i nclude

#define uchar unsigned char

#define uint unsigned int

#define nop() asm("nop")

#define Clrwdt() asm("clrg")

#define di() asm("DI")

uchar RefValue[8];

uint GetRefCount;

uint ErrTime;

void SysInt(void);

void Delayms(uint ms);

uint GetAd(uchar Ch);

void KeyProcess(void);

void GetRef(void);

main(void)

{

SysInt();

while(1)

{

KeyProcess();

}

}

void GetRef(void)

{

uchar i,j;

uint temp;

for(j=1;j<8;j++)

{

temp=0;

for(i=0;i<10;i++)

temp+=GetAd(j);

temp/=10;

temp-=4;

(uchar)(temp);

RefValue[j]=temp;

}

}

uint GetAd(uchar Ch)

{

ADEN=1;

ADCM&=0xC3;

ADCM|=(Ch<<2);

ADCK=0;

ADCRH=0x20;

ADST=1;

do{nop();}while(ADSF!=1);

return ADCRL;

}

void KeyProcess(void)

{

uchar j,i=0;

for(j=1;j<8;j++)

{

if(GetAd(j)<refvalue[j])< p="" style="overflow-wrap: break-word;">

{

while(1)

{

nop();

if(GetAd(j)<refvalue[j])< p="" style="overflow-wrap: break-word;">

{

i++;

if(i>=20)

{

R1=(j<<1);

GetRefCount=0;

return;

}

}

else break;

}

}

}

R1=0;

GetRefCount++;

if(GetRefCount>=1200)

{

GetRefCount=0;

GetRef();

}

}

void SysInt(void)

{

Clrwdt();

di();

nop();

CKCTLR=0;

R1IO=0;

R3IO=0;

PU1=0xFF;

PU3=0xFF;

Delayms(50);

R0IO=0x00;

PU0=0;

R0OD=0;

PSR0=0x40;

R1IO=0xFF;

PU1=0;

R1OD=0;

PSR1=0x00;

R1=0;

R3IO=0;

PU3=0x20;

R3OD=0;

R3=0xFF;

TM1=0xA0;

T1PPR=7;

T1PDR=4;

PWM1HR=0x00;

TM1=0xA3;

ErrTime=0;

GetRefCount=0;

Delayms(100);

GetRef();

//RefValue=(GetAd(7)-5);

}

void Delayms(uint ms)

{

uint i,j;

for(i=0;i<ms;i++)< p="" style="overflow-wrap: break-word;">

for(j=0;j<120;j++)

;

}