=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Date: Thu, 27 Jan 2000 06:46:44 From: Nikolai Golovchenko To: pic microcontroller discussion list Subject: Re: pic c compiler -------------------------------------------------------------------------------- Hello Tom, I use one routine all the time and it has always suited me. It is called every 20 ms or so and ensures that the button pressing causes return of 1 only if two consecutive reads were the same. Also, it implements auto-repeat. Here it is: #define KEYPORT PORTA #define PAUSE 20 #define REPEAT 3 #define KEYMASK 0b00001000 //RA3 static unsigned char Keys; /**************** KEYS POLLING ROUTINE ***************** Low active level assumed Should be called every about 20 ms (T) PAUSE * T - delay after first click REPEAT * T - delay between clicks after KEYPORT - PORT register (e.g. PORTA) KEYMASK - mask for port register (1 for every button) Returns TRUE if a key is pressed and on auto-repeat */ unsigned char KeysPoll(void) { static unsigned char KeysOld; static unsigned char KeyCnt; static unsigned char KeyCntLim; Keys = KEYPORT; //read port if (((Keys ^ KeysOld) & KEYMASK) == 0) { //Nothing changed if (--KeyCnt == 0) { KeyCnt = KeyCntLim; KeyCntLim = REPEAT; KeysOld = Keys; if (((Keys ^ KEYMASK) & KEYMASK) != 0) return 1; } } else { KeyCnt = 1; KeyCntLim = PAUSE; } KeysOld = Keys; return 0; } Bye, Nikolai On Wednesday, January 26, 2000 Tom Weber wrote: > Hello > I've got the download version from the ht-soft pic c demo. > I'm searching for a function, which reads the status of a button/key and > considers the bouncing. Has someone already written a such function? > And has already someone realised something with an TDA7318. > Tom > -- > Sent through Global Message Exchange - http://www.gmx.net