Here is some code to get you started...
Press the Button and LED will light. Release the Button and the LED will go out.Code:@ DEVICE pic16F628A, INTRC_OSC_NOCLKOUT @ DEVICE pic16F628A, WDT_ON @ DEVICE pic16F628A, PWRT_ON @ DEVICE pic16F628A, MCLR_OFF @ DEVICE pic16F628A, BOD_ON @ DEVICE pic16F628A, LVP_OFF @ DEVICE pic16F628A, CPD_OFF @ DEVICE pic16F628A, PROTECT_OFF ButtonA var PortA.0 ' Button connected between PIC pin and Vss ' Resistor (10K) connected between PIC pin and Vdd LEDA var PortA.1 ' LED connected between Vdd and PIC pin ' via 330R Resistor ' Anode end of LED towards Vdd and Kathode to PIC pin TRISA=%00000001 CMCON=%00000111 Loop: If ButtonA=0 then Low LEDA else High LEDA endif Goto Loop End
I have you shown with this piece of code how to read an INPUT from a press-button, and how to OUTPUT to control an LED. The @ DEVICE statements will configure your PIC for internal Oscillator and internal MCLR so it will work the moment you apply power to it.
Look-up each command/instruction I have used either in the PICBasicPro Manual or the Datasheet.
It is now UP TO YOU to logically design how your program will work. The PBP Manual and the PICs Datasheet are essential reading.




Bookmarks