logo elektroda
logo elektroda
X
logo elektroda

How to Change Color on Single Button Press in MPLab C for PIC18f45k22?

39 7
ADVERTISEMENT
  • #1 21668456
    Steve Lawson
    Anonymous  
  • ADVERTISEMENT
  • #2 21668457
    yp ng
    Anonymous  
  • ADVERTISEMENT
  • #3 21668458
    Steve Lawson
    Anonymous  
  • #4 21668459
    Mark Harrington
    Anonymous  
  • ADVERTISEMENT
  • #5 21668455
    yp ng
    Anonymous  
  • ADVERTISEMENT
  • #6 21668460
    Mark Harrington
    Anonymous  
  • #7 21668461
    yp ng
    Anonymous  
  • #8 21668462
    Steve Lawson
    Anonymous  

Topic summary

The discussion centers on implementing a single-button press color change functionality using MPLAB C for the PIC18f45K22 microcontroller. The original code lacks comments and proper input/output configuration, notably setting TRISB to 0x00, which configures Port B as output rather than input for push buttons. The code uses "goto" statements, leading to spaghetti code that complicates logic flow and debugging. Contributors emphasize the need for structured programming techniques, including functions and conditional loops instead of goto, and recommend creating clear flowcharts and schematics to clarify design intent. Concerns are raised about input pin configurations, floating inputs, and the absence of proper pull-up or pull-down resistors to ensure stable button readings. A key problem is the inability to change colors on a single button press without holding the button; the current implementation requires pressing and holding to select a color. An example of a debounce routine in Proton Basic is provided to illustrate proper switch input handling and toggling behavior. The discussion highlights the importance of debouncing, structured code, and hardware considerations such as input pin setup and pull-up resistors to achieve reliable single-press color changes on the PIC18f45K22.
Summary generated by the language model.
ADVERTISEMENT