I hope everyone who read the post about programming the PIC16F84A will now be savvy with downloading the program to the controller, and also check the working of the controller. In the previous post, we discussed about producing an output (switching on an led) using PIC16F84A. Here, I will tell you how to work with inputs – How will you provide inputs to your PIC and how to develop a response to it. As you all know, the controller has 13 I/O pins. These 13 pins can be configured either as input or output. Producing output on a pin is pretty easier as you all know. Just mark the pin as output and send a high signal to it. But how to make the PIC to accept input?
There are two ways in which a PIC(or any controller) can sense a digital input – low to high and high to low transitions.
Low to high:
Here in this method, select a pin, mark it as input, connect the input to ground with a large resistance (say 10K) then check the pin for a high voltage.The resistance connected between input and ground is called as “pull down resistance” because, it pulls down the voltage level of the connected pin when there is no input.
High to low:
In this method, select a pin, mark it as input, connect the input to Vcc with a large resistance(say 10K) and then check the pin for low voltage. Here, the resistance connected between the input pin and Vcc is called as “pull up resistance” because, it pulls up the voltage level of the connected pin when there is no input.
Program and circuit for getting an input and switching an LED:
START BSF STATUS,05H
LOOP BTFSS PORTB,4
This program does nothing but when you press a switch connected to RB4, an LED connected to RB0 is switched on. Here goes the explanation of the code presented above.
START BSF STATUS,05H – START is just a label. The next instruction BSF STATUS,05H sets the 5th bit of the STATUS register – to navigate to bank 1.
MOVLW B’11110000‘ – moves the value 11110000 to the w register.
MOVWF TRISB – moves the contents of w register to TRISB register. (i.e.,) Sets the first four pins of PORTB to input and last four pins of PORTB to output.
BCF STATUS,05H – Clears the 5th bit of the STATUS register. This clearly navigates back to bank 0
LOOP BTFSS PORTB,4 – LOOP is also a label. BTFSS is a new instruction (Bit test File skip if set) which means, test pin RB4(in this case), if it is set, then skip the next step.
GOTO LOOP – The explanation is obvious. This instruction tells the controller to goto the LOOP label. So, what happens here is, The instruction BTFSS checks the RB4 pin for a low to high transition and if it doesn’t find any changes in RB4, it goes on sequentially and since the next instruction is specified to go again to BTFSS, the program loops here until RB4 is set. When RB4 is set, then the BTFSS instruction skips the next line. Therefore GOTO LOOP is skipped. So, the program looses the loop and continues normally.
BSF PORTB,0 – This instruction sets RB0. So, connecting an LED to RB0 will drive the LED to high.
GOTO START – Again starts the program from the beginning.
Download the program to the controller and assemble the controller on a solderless bread board as shown above. On pressing the push button, the LED glows which is the flawless output.
Hi Nipuna, use oshon PIC simulator. You can easily compile and run your assembly code in that ide and also, setting up frequency and controller is also a layman work.
Wich Application Used to programme it? I’m Using Micro C for Pic programming its very easy than Mp Lab.