| ??? 10/23/04 01:41 Read: times Msg Score: +1 +1 Good Answer/Helpful |
#79745 - Some more refinements... Responding to: ???'s previous message |
Dear Jacob,
Noted your comments. The solution that I suggested was a generic one to send the status of the P0 port via RS232. But after posting it I remembered that our friend needed to handle multiple key presses also - so lets try and put together some code for it ? One option as you said can be a look up table. Another could be as below :
SCAN_P0: JNB TICK100ms, $ ; Wait for the 100ms tick
CLR TICK100ms ; Ticked ON. Clear it
CASE_P0: MOV P0, #0FFH ; All pins as input
JNB P0.0, SND_30H
...
...
JNB P0.7, SND_37H
NO_INPT: JMP SCAN_P0 ; No input active. Go wait
SND_30H: MOV A, #30H
CALL SND232 ; 30H to PC
JMP SCAN_P0 ; Current state sent. Go wait for next.
...
...
SND_37H: MOV A, #37H
CALL SND232
JMP SCAN_P0
SND232: JNB SCON.1, $ ; wait for previous character to go..
CLR SCON.1 ; and send current character to COMM
MOV SBUF, A
RET
;================================
The above code will do the following : 1. Wait for 100ms flag to be set ( maybe inside of an ISR) 2. Once the 100ms tick flag is set, scans all pins of P0. 3. The first pin of P0 that is low, causes a branch out to the routine to send the relevant data to RS232. 4. After this, it does not scan any other pin and waits for another 100ms to start all over. Multiple entries are avoided. Warnings : 1. The scheme will work if the input pulses are more than 100ms in duration. If you find that this is too long then you can reduce it to about 50ms. But no smaller - we are not debouncing the switches and hence will need some delay to avoid false signals. 2. It also assumes that inputs are pulses and not state changes. Like if P0.1 is connected to a SPDT switch, then no input from P0.2 to P0.3 can be read as long as P0.1 is active. 3. If you need to act based on the state of multiple switches, then this scheme will not suit. You have to use the scheme as posted earlier ( send the port status to PC once every 100ms and do the decision there). Improvements : 1. We depend on the loop delay for debouncing. Works for most cases. But an even better implementation would be this : A. Get a snap shot of P0 port. B. Complement the snap shot. Save it as PREV_IMG C. Wait 20 or 30ms D. Get next snap shot of P0 port. E. Complement the snap shot and AND it with PREV_IMG. F. Use the resulting accumulator value for deciding which value (30H to 37H) to send to RS232. Since you are using the synthesised image for decision making, no change of state of pins, as and when the decision is being made, will affect the result. Raghu |
| Topic | Author | Date |
| uC to VBfront end | 01/01/70 00:00 | |
| RE: uC to VBfront end | 01/01/70 00:00 | |
| RE: uC to VBfront end | 01/01/70 00:00 | |
| RE: uC to VBfront end | 01/01/70 00:00 | |
| RE: uC to VBfront end | 01/01/70 00:00 | |
| RE: uC to VBfront end | 01/01/70 00:00 | |
| RE: uC to VBfront end | 01/01/70 00:00 | |
| RE: uC to VBfront end | 01/01/70 00:00 | |
| RE: uC to VBfront end | 01/01/70 00:00 | |
| RE: uC to VBfront end | 01/01/70 00:00 | |
| RE: uC to VBfront end | 01/01/70 00:00 | |
| RE: uC to VBfront end | 01/01/70 00:00 | |
| Some more refinements... | 01/01/70 00:00 | |
RE: uC to VBfront end | 01/01/70 00:00 |



