Click here to see the previous part.


We know that the TRIS Register fixes which pins of any port of the Micro controller will act as input or output. So first we need to use the PIN as input to configure them through the TRIS Register. After that we will check whether the pin is High (Set) or low (Clear) i.e. the pin has 5V or 0V. We can use BTFSC and BTFSS to check the status of any bit. BTFSC means that if the micro controller tests a bit and finds it clear, it will skip the next instruction. We can say BTFSC, Bit Test that Follows, Skip if Clear. BTFSC stands for Bolded Letters. In the same way we can say to BTFSS, Bit Test that Follows, Skip if Set, that is, if the micro controller tests a bit and gets the set, he will skip the next instruction. Let's write a program through which if a switch is ON the LED will be ON and if the switch is OFF the LED will be OFF.


We will use the RA0 pin of PortA as input and the RA2 pin of PortA as OUTPUT.


Let's write CODE.


First let's configure INPUT / OUTPUT,


BANKSEL TRISA


MOVLW B'00001 '


MOVWF TRISA


BANKSEL PORTA


Notice the CODE above. For BANK SELECTION I have used a new INSTRUCTION BANKSEL and selected the RA0 pin of PORTA as INPUT and the rest of the pins as OUTPUT.



 

Now let's check if the pin is HIGH or LOW. If the pin is HIGH we will set the RA2 pin. And if the pin is low, we will clear the RA2 pin.


START BTFSS PORTA, 0


GOTO $ + 3


BSF PORTA, 2


GOTO START


BCF PORTA, 2


GOTO START


In the first line above, BTFSS has checked whether the BIT number 0 of the micro controller PORTA i.e. RA0 pin is HIGH. If HIGH, the micro controller will SXIP NEXT INSTRUCTION and EXECUTE the third line. In the third line, instruction "BSF PORTA, 2" will set or HIGH the 2nd BIT of PORTA i.e. RA2 pin. The micro controller will return to the first line via the "GOTO START" INSTRUCTION on the next line and will continue to check the status of the RA0 pin.


And what happens if the RA0 pin is low i.e. clear? If clear, the micro controller will not skip the second line. In the second line, the micro controller has been asked to skip 3 lines and go to the fifth line. In the fifth line, BIT number 2 of PORTA i.e. RA2 pin has been asked to be cleared. Then the micro controller will return to the first line via "GOTO START".


Now if you supply 5 volts through the switch in the RA0 pin of PORTA and if you put the led in the RA2 pin of PORTA, if you switch ON / OFF the LED will be ON / OFF. See circuit diagram below.



 



R1 is used in the diagram above so that the RA0 pin does not become high in any way until SW1 is pressed. This means that the RA0 pin has been lowered (Pull Low) through this R1 resistor. The R2 resistor is used to limit the current of the LED. The MCLR pin of the micro controller is active low (the bar above the MCLR is inverted) which means that if this pin is lowered, the Micro controller will be reset. In any way so that the pin can not be low, so the pin has been pulled high through the R3 resistor (pull high). X1 is the crystal oscillator (2oMHz), c1, c2 to stabilize the crystal. Oscillation of Crystal Oscillator may not start if C1, C2 is not given. The power supply is not shown in the circuit but in reality you must give 5V supply to the VDD (PIN 14) pin. Needless to say VSS (PIN 5) is the Ground PIN of the micro controller.


Writing all the code together,


BANKSEL TRISA


MOVLW B'00001 '


MOVWF TRISA


BANKSEL PORTA


START BTFSS PORTA, 0


GOTO $ + 3


BSF PORTA, 2



 

GOTO START


BCF PORTA, 2


GOTO START


Now let's run on PIC Simulator IDE.


Open the assembler from the Tools of the Main Window, write the above code in the assembler and assembled and load it.




Then open Micro Controller View from Tools.




If the Micro controller View does not open like above and a different type of window appears, remove the tick mark from the Option on top of the Compact Micro Controller View.





 

Now start Simulation at Extremely Fast Rate.


When Simulation Start, Toggle the Toggle button next to the RA0 pin.




Here RA0 is ON when RA0 is ON and RA2 is OFF when RA0 is OFF.




If you want, you can open the LED window and connect the LED to the RA2 pin.


We could also do the above using BTFSC Command. In that case the codes had to be changed a little. The modified part is as follows-


START BTFSC PORTA, 0


GOTO $ + 3


BCF PORTA, 2



 

GOTO START


BSF PORTA, 2


GOTO START


In the last tutorial, I talked about Proteus 7 Professional. I hope you have downloaded it. Even then I tried to upload to Mediafire but sadly I have failed. If a kind person uploads and gives the link, it is very good.


But so far no one was able to send in the perfect solution, which is not strange. Although I have seen whether it is downloaded from different PCs. I had no problem.


Those who have not downloaded it, download it from the link below.


Proteus 7 Professional


How to install is given in the Help folder. Hopefully there won't be any problems. If there is a problem, the comment house is at the bottom.


Proteus is the best simulation software I've ever seen. With Proteus you can also design PCB. Two parts of Proteus. One is ISIS and the other is ARES. ISIS for Schematic design and Simulation and ARES for PCB design.


Open ISIS 7 Professional Administrator from All Programs.



 



In the View Sample Design dialog box, actually put NO in it.


Clicking on the left P will bring up a new window called pick device. Enter the name of the device you need in the keywords box of this window. You can see if the device is in the library of ISIS. We can type PIC16F84A in keywords. You can see the description of the micro controller in the Results box. If you double click on it, the device can be found in the Devices cell of the main window.




Then close the PICK DEVICES window. You will see the name of pic16f84a below P in the Devices cell. From here, select the device and click on the left mouse button once in place of Drawing. You will see a shape of the component under your mouse. Now click again with the shape where you want to place it and you will see that the device has been set up nicely.




Now it's time to switch. Click on P as before and type in the keywords of pick devices Switch. Select the category and subcategory as below and double click on the desired Switch.




Now select the name of the switch in the device cell and place the switch in its place. If you move the mouse over any pin, you will see a light red box. Clicking this time you will see the wire on the mouse head. Wherever you take the mouse, the wire will go there. Now take the mouse with the pin you will attach and you will see the box will come again as before. Click again to see the wire is connected.





 



Now let's give power to the other end of the switch. For this you need to go to Terminal mode. So far we have been in Component Mode. Click below to go to Terminal mode, see below. Select Power from within Terminal mode. Then place the Power Terminal in the same way as the Component was placed.




Connect the other end of the switch with the power terminal wire.




Let's install a resistor of 10k Ohms. For this you have to go to Component Mode again. Shown below.




Select 10k Ohms Resistor from Pick Device. Subcategory There is no such thing as having to choose like me. If the value of the component is correct.




Place the resistor in the design. If you want to rotate the resistor, you can get the option of Rotate clockwise and anti clockwise by right clicking the mouse on its body. It is better not to use Mirror to rotate 180 degrees.



 



Now one end of the resistor should be connected to the micro controller and the other end to the ground. Ground Terminal is below Power Terminal in the same place as Power Terminal was selected from Terminal Mode.


Complete the connection by putting the rest of the components as shown below. In case of LED selection, if you select Animated LED, it will be useful to see. The LED should be red or green, not multicolored.




Now it's time to insert the source code inside the micro controller. Double click on the micro controller to see if the following window appears. In fact Clock Frequency 20MHz input. And browse the source code and show the .HEX file. Where to get source code !! Guys have to be a little patient brother. You are reading, my hand became sore while writing. Take a look at the edit box first.


Where the source code will come from. You need to create a program. PIC Simulator IDE will help you with this. Assemble and load a program in the assembler of PIC Simulator IDE. When assembled and loaded, the software must have asked you to save the program. Keep track of what name and where you are saving. At that location the software will create a .HEX file with your given name. Suppose you gave the name Switch, then he will get a file named Switch.hex. This is your desired source code.


Now it's time to simulate. Click the play button below ISIS. Simulation has started. Now click on the Up and Down buttons with two arrow marks next to the Switch, then the Switch will be Open and Close.




Since the clock frequency has been separated in Proteus, there is no need to connect crystal to OSC1 and OSC2 pins. Proteus does not need to keep the MCLR pin pull high. The software has hidden VCC and Ground PIN of different devices. No worries, these two pins are internally connected to Power and Ground Terminal.


Until today. I am going to write another episode about Assembly. So in the next part of the next episode I will discuss analog input and LCD display in the assembly.