An external 20 Mhz crystal is used to supply clock to microcontroller. Crystal is attached to microcontroller in parallel to two 33 pf capacitors. Push button is attached to Port-D Pin#7. 1 K ohm resistor is attached in series to a push button, other leg of push button is attached to +5v signal.
_XTAL_FREQ 20e6 statement is specifying the crystal frequency that is attached to the microcontroller. I am Using 20 Mhz external crystal with the controller so i specified 20e6(Equivalent to 20e6=20,000,000).
Statement #define Input RD7 is defining Port-D Pin#7 as Input. Now we can access Port-D Pin#7 with the name ‘Input’. TRISB=0x00; Statement is declaring Port-B as Output. TRISD=0x80; Statement is declaring Port-D Pin#7 as Input. (0x80=1000 00000
Push button to switch off led and release button to switch on led. You can also reverse the logic. Just change the statement if(Input==0) to if(Input==1). This will on led when Push button is pressed and off led when released. Pushing button and releasing it continuously will cause your led seem blinking.
Driving heavy Loads(using Transistor) with the same configuration given above
Some tutorials on driving heavy loads with microcontrollers are below.
Filed Under: Microcontroller Projects, PIC Microcontroller
Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.