??? 01/12/13 22:10 Read: times |
#189142 - To avoid problems Responding to: ???'s previous message |
Your CLEAR: function sets each bit of an output port sequentially and could cause problems. The 8051 ports are all READ-MODIFY-WRITE which means that when you write to the port all the PINS, not the latches, are read, then changed, then written back to the port latches. Problems arise when you modify multiple bits individually one after another on the same port. For example, you SETB L4 (which is port pin P1.7) and because of loading the port pin might be slow to rise to Vcc. Before it has a chance to rise very much the next instruction (SETB L5) will set port pin P1.6 to 1, but first all of port P1 is read again, then P1.6 is set to 1, but P1.7 might still be too low to be considered a 1 and so a 0 is written to port P1.7 latch. This problem is very pronounced in the PIC16F series and users are advised against setting the bits as you have in the CLEAR: function.
You would realize much more reliability if you change the whole port with one instruction, MOV P1,#0xFF and MOV P3, #0x13. Also the same with your ALLON: function. Use MOV P1, #0x00 and ANL P3, #0xEC. To use a variable resistor for any kind of control you are going to need a device with ADC or else provide an external ADC. Hal |