| ??? 11/24/03 13:20 Read: times |
#59298 - RE: Reading Port Issue Responding to: ???'s previous message |
be aware that the port reading may change between the first read and the second read as the user controlling the switch is not synchronised to the code. Also, if the code is running in a mad loop it is sampling the switch inputs extremely fast thus subject to contact 'bounce'.
Suggestions: sample input port say every 10mS. test to see the input value is stable for 5 consecutive samples. when stable, store the value into memory and have the rest of the code use this value. This technique (or similar) is normally used when switch inputs are to be read from external sources - the humble switch is not quite the tame beast you think it is! Many have fallen for it's apparent simplicity. By sampling the switch inputs at one point you can then introduce diagnostics that can show you what is happening - setup the serial port to output the switch value each time it is sampled. I have a core set of 'golden' routines to print hex, print string and to init the serial port - nothing magic - but code I know works. To debug I introduce code to print a value or a string so I can see what the code is doing. use a simulator make sure you have resistive pullups (~10k) on the switch inputs as relying on the 8051 input pullups is fraught with problems. moving your hand close to it may couple enough energy to change the input levels. |
| Topic | Author | Date |
| Reading Port Issue | 01/01/70 00:00 | |
| RE: Reading Port Issue | 01/01/70 00:00 | |
| RE: Reading Port Issue | 01/01/70 00:00 | |
| RE: Reading Port Issue | 01/01/70 00:00 | |
| RE: Reading Port Issue | 01/01/70 00:00 | |
| RE: Reading Port Issue | 01/01/70 00:00 | |
| RE: Reading Port Issue | 01/01/70 00:00 | |
| RE: Reading Port Issue | 01/01/70 00:00 | |
| RE: Reading Port Issue | 01/01/70 00:00 | |
| RE: Reading Port Issue | 01/01/70 00:00 | |
| RE: Reading Port Issue | 01/01/70 00:00 | |
Come back! | 01/01/70 00:00 |



