| ??? 05/28/05 19:34 Modified: 05/28/05 19:37 Read: times Msg Score: +1 +1 Good Question |
#94060 - Keil: getting input |
Hi everyone,
Till yesterday, I was writing codes in assembly. Though it gave the ultimate control of the code, developing large projects was cumbersome. Today, I started learning Keil and it is very useful. I wrote a small routine to scan four push-buttons connected to P0.7 - P0.4. The code is like this: sbit UP = 0x87; sbit DOWN = 0x86; sbit LEFT = 0x85; sbit RIGHT = 0x84; void main(void) {
else if(scan(DOWN)) {...}; ... } bit scan(bit x){
while(x==0); return(1); } Port 0 is pulled up externally. What I wanted was, only when I release the button after pressing, the action for the key should take place. So, I thought to put the condition in an while loop, and making it to run. The problem I got was simple: My keypad routine dint scan at all. I replaced while loop with 'if' statement, i.e. if(x==0) return(1); This one worked, but the action took place as soon as I pressed the key. At the end I put some delay and managed to have keyboard debouncing action. My previous assemble code for this one was: scan:JNB P0.7,scanup
... SJMP scan scanup:JNB P0.7,$ (...some codes...)
(...some codes...)
My questions are: 1. I think the problem may be due to the code scanning 'x' in the port latch rather than port pin. (Am I right?) 2. I have declared UP, DOWN as 'sbit' and collecting in scan routine as 'bit'. Can this be done? Caveats? I thought to have this scan routine replaced by assembly counterpart so I used #pragma ASM/ENDASM but this also in vain. What is happening? How to effectively use inline assembly functions with C routines in Keil? Regards, Vignesh. |
| Topic | Author | Date |
| Keil: getting input | 01/01/70 00:00 | |
| If it works in ASM it Works in C | 01/01/70 00:00 | |
| Why C?! | 01/01/70 00:00 | |
| Irrelevant | 01/01/70 00:00 | |
| Of Course | 01/01/70 00:00 | |
| key scan | 01/01/70 00:00 | |
| Delay.. | 01/01/70 00:00 | |
| Delay | 01/01/70 00:00 | |
| Software Delay Loops | 01/01/70 00:00 | |
| Software Delay Loops | 01/01/70 00:00 | |
| Learning 'C' | 01/01/70 00:00 | |
| to be precise.. | 01/01/70 00:00 | |
| Debounce | 01/01/70 00:00 | |
| completely missed it.. | 01/01/70 00:00 | |
| to be precise... | 01/01/70 00:00 | |
| Sorry Leo ! | 01/01/70 00:00 | |
| Inferences | 01/01/70 00:00 | |
| Right answer, wrong reason | 01/01/70 00:00 | |
| and therefore | 01/01/70 00:00 | |
| Congratulations | 01/01/70 00:00 | |
to: Raghu Sir | 01/01/70 00:00 | |
| BIts! | 01/01/70 00:00 |



