PIC Assembly programming: Look-up Table with 7-Segment example (Tutorial 5).
Estimated read time: 1:20
Learn to use AI like a Pro
Get the latest AI workflows to boost your productivity and business performance, delivered weekly by expert consultants. Enjoy step-by-step guides, weekly Q&A sessions, and full access to our AI workflow archive.
Summary
This tutorial on PIC Assembly Language Programming, hosted by Ivan Party from Intelligent Electronic Systems Design Pty Ltd, focuses on utilizing lookup tables through a seven-segment display example. The video covers a step-by-step guide on setting up the microcontroller (PIC16F818) to read three-bit binary inputs from a switch and display their decimal values on a seven-segment display. Ivan explains the circuit configuration, assembly program writing for input processing, using lookup tables for value fetching, and the significance of minimizing program length with lookup tables. The tutorial emphasizes practical application through a comprehensive walkthrough of flowchart creation, coding with MPLAB, and real-time simulation verification.
Highlights
Learn how to configure a PIC16F818 microcontroller for reading binary inputs. 🛠️
Master the process of displaying decimal values on a seven-segment display using lookup tables. 🔢
Understand the importance of circuit setup, including switch configuration with pull-up resistors and common cathode displays. ⚡
Follow a detailed guide to writing the assembly program, from flowchart creation to coding in MPLAB. ✍️
Witness the power of lookup tables in minimizing program complexity and facilitating efficient value conversions. 🚀
Key Takeaways
Lookup tables are essential for efficiently converting binary inputs to decimal displays in microcontrollers. 🤓
Using a PIC16F818 microcontroller, the tutorial demonstrates reading binary inputs and displaying them on a seven-segment display. 🤖
The video provides detailed guidance on setting up circuit configurations and writing assembly programs to manipulate inputs and outputs. 💡
A hands-on demonstration with MPLAB shows how to simulate and verify the functioning of the assembly program. 🔌
The comprehensive explanation of lookup tables provides insights into reducing program complexity, making them valuable in various applications. 📉
Overview
In this in-depth tutorial, Ivan Party from Intelligent Electronic Systems Design Pty Ltd takes viewers through the process of using lookup tables in PIC Assembly programming. By focusing on a practical example involving a seven-segment display, the tutorial provides clear and engaging instructions on how to read and convert three-bit binary inputs into decimal outputs on the display.
The tutorial begins with a circuit overview, explaining the setup of the PIC16F818 microcontroller, input switches, and seven-segment display connections. Ivan details the assembly program writing process, highlighting how to mask unwanted bits and fetch values from lookup tables to display on the seven-segment. This approach simplifies the conversion process, making it efficient and less coding-intensive.
Throughout the video, Ivan emphasizes the utility of lookup tables in simplifying program logic, especially for applications like counters and real-time clocks. By offering a hands-on demonstration using MPLAB for program simulation, the tutorial ensures that viewers can confidently apply these techniques in their own projects.
Chapters
00:00 - 00:30: Introduction The chapter titled 'Introduction' starts with a greeting from Ivan Party, who is welcoming viewers to a video tutorial focused on programming in peak assembly language. The specific topic covered in this video is lookup tables, where the chapter aims to explore the creation and utilization of lookup tables within the context of peak assembly language programming.
00:30 - 01:00: Problem Statement In the 'Problem Statement' chapter, the task is to create a flowchart and write an assembly program. The program should be capable of reading three bits from 'part a0 to a2', and displaying the corresponding decimal value on a seven-segment display using a lookup table. Essentially, the challenge is to convert a three-bit binary number into its decimal equivalent for display purposes.
01:00 - 03:00: Circuit Explanation This chapter discusses the utilization of a lookup team for displaying a seven-segment circuit using an internal oscillator, eliminating the need for an external one. The focus is on the schematic design and implementation using the internal USB feature.
03:00 - 05:00: 7-Segment Display Explanation The chapter focuses on explaining the 7-segment display using the PIC16F818 microcontroller. Three inputs (A0, A1, and A2) are connected in a pull-up configuration with a switch to ground. Additionally, a 10k resistor is used to connect the MTR to VCC, and the VDD and VSS pins of the PIC are also connected.
05:00 - 13:00: Flowchart Creation This chapter outlines the process of connecting a seven-segment display to an electrical circuit. It uses 5 volts and ground as the power source and details the wiring configuration, specifically mentioning how connectors b1 to b7 link to the segments a through g of the display. It also notes the option of alternative wiring such as using b0 to b6, providing flexibility in the setup.
13:00 - 16:00: Program Initialization This chapter focuses on program initialization for a microcontroller. It provides a step-by-step explanation of connecting segments (c to b3, d to b4, e to b5, f to b6, and g to b7) on a common cathode seven-segment display, emphasizing that the common lead is connected to the ground. The importance of configuring the input/output settings for activating each LED segment is also discussed.
16:00 - 20:00: Reading and Masking Port A This chapter explains the concept of controlling an LED using an I/O pin. It describes the process of connecting the logic high voltage to ensure current flow through a resistor and LED to ground, which turns the LED on. To turn off the LED, the output needs to be cleared, which interrupts the current flow. The process is relevant when using a common anode LED setup.
20:00 - 26:00: Lookup Table Function Chapter titled 'Lookup Table Function' introduces the concept of controlling a common anode seven-segment display. It explains that for a common anode configuration, the common pin should be connected to VCC. To light up an LED segment, the corresponding IO pin must be set to low, effectively completing the circuit and allowing current to flow through the segment, turning it on. Conversely, setting the IO pin to high will switch off the LED segment by stopping the current flow.
26:00 - 43:00: Program Simulation The chapter focuses on program simulation, specifically using a common cathode seven-segment display. It explains the logic needed to control the LED display, where applying a high logic level to an output turns on the LED, and a low logic level turns it off. The explanation is applied to display numbers on the seven-segment, exemplifying with the digit '0.' The chapter helps understand the configuration and operation of the circuit involved.
43:00 - 60:00: Extending Lookup Table In this chapter, the focus is on configuring a seven-segment display to show the number zero. The method involves turning off segment 'g' while keeping the remaining segments active. Specifically, segment 'g' is controlled by the signal 'b7', which should be set low, while signals 'b1' through 'b6' are set high. This setup results in the display of the digit zero on the seven-segment display. The chapter also suggests a procedure to display numbers zero through seven.
60:00 - 60:00: Conclusion The conclusion chapter wraps up the discussion on configuring a seven-segment display, specifically focusing on the connections needed for displaying zero. The connections are detailed as follows: 'a' is connected to 'b1', 'b' to 'b2', 'c' to 'b3', 'd' to 'b4', 'e' to 'b5', 'f' to 'b6', and 'g' to 'b7'. Notably, 'b0' does not connect to anything. This setup allows for the appropriate visualization on the display.
PIC Assembly programming: Look-up Table with 7-Segment example (Tutorial 5). Transcription
00:00 - 00:30 hello once again guys ivan party here and welcome to another tutorial on peak assembly language programming now on this video we are going to look at lookup tables we're going to look at how we make use of lookup tables and let's get started right away let's consider this example here that
00:30 - 01:00 says draw the flowchart and write an assembly program to read part a0 to a2 and display the value on a seven segment using lookup table basically we have a three bit binary value we are supposed to read and display the decimal value corresponding to that binary on a seven second so it's a binary traditional
01:00 - 01:30 converter display one day seven segment right we need to do that using the lookup team it further says use the internal oscillator it means now on our circuit we don't need an external circuitry for that what's in it we're going to use the internal usb now let's have a look at how the schematic for this will look like for this example i'm also using i'm
01:30 - 02:00 still using the pic16f818 microcontroller and now you have your a0 and a2 a0 a1 and a2 your three inputs connected with pull up configuration we have a switch to ground those are three inputs we have the mtr connected vcc through a 10k resistor your vdd and vss of your pick are connected to
02:00 - 02:30 5 volts and ground respectively and we have our seven segment connect connected to point b i've chosen to use b1 up to b7 to connect from a up to g of our seven segment you can choose alternative you can choose b0 to b6 maybe for a up to g now in this case i've connected a of the seven segment to b1 b of the seventh segment to b2
02:30 - 03:00 c of the s7 segment to b3 this is on this is part b basically now d of the server segment to b4 e to b5 f to b6 and g to be seven on your peak microcontroller so we are using a common cathode seven segment the common lead of the seven segment is connected to ground now to switch any led of your seven segment your i o must be
03:00 - 03:30 um sent to logic one must be connected high so that current can flow from the output of that i o pin through the resistor through the led to ground and then that led will switch on will flow right to switch off that led you clear your output clearing your output switches of the led setting your output switches on the led right if you are using a common a node
03:30 - 04:00 seven segment the common won't be ground it would have to be vcc right and now to switch on your led the output must be set to low if the if the io pin is set to low and your common is vcc and this seven segment is a common anode switching your output low switches on the the led setting output high switches off the led
04:00 - 04:30 that's for common and but here we'll be using a common cathode seven segment so switching your logic high on the output you are switching on the led low on the output you are switching off the led for this configuration command custom configuration so basically that's our circuit right how how are we supposed to display 0 on a 17 for an example to display zero
04:30 - 05:00 on the seven segment we just have to switch off segment g if we switch off g and the rest of those seven segments are on that will display zero right now g is connected to what g is connected to b seven you take b7 low and b1 up to b6 you take them high that will display zero on your seven set let's look at how you'll display zero up to seven now
05:00 - 05:30 and with that configuration and this is what we need to do to display zero on our seven segment connected to point b and then specifically a connected to b one b connected to b two c b three d b 4 e b 5 f b 6 g b 7 b 0 is not connected to anything so the
05:30 - 06:00 whole of b b 0 b's i'm always going to make them zeros right now to display a zero only g must be off to display a zero on your seven segment only g must be off the rest from a up to f a up to f the rest must be on so for common cathode on is when you send logic
06:00 - 06:30 one i'm using a common cathode so i'm going to send logic one to all of them except g that will display zero on a seven second what is the value that i'm gonna send to point b now as a hexadecimal v zero one one one that's a seven and then one one one zero that's e sending seven e to part b will display zero on your seven segment right to display one b and c must be on the rest must be off
06:30 - 07:00 so b must be on c must be on to display one b must be on c must be on the rest should be off what is the v zero zero zero zero that is zero one one zero zero that's a c so sending zero c to pot b will display one on your seventh segment for two f and c must be off so to display two f is f
07:00 - 07:30 and then c is off and then a up to g must be on except that f and c so the value we get there it's one zero one one which is a b and then zero one one zero which is a six so sending b6 to part b will display two on your seven set you can get the rest of the values
07:30 - 08:00 for three four five six and seven looking at the picture that displays a value and how you configure your a up to g to display that and then the value you get you convert it to hexadecimal and then when you send this value to part b is going to display the corresponding digit on your seven second now these values are going to be very important and these values are the values that we're going to use in the lookup
08:00 - 08:30 table meaning in the lookup table when we want to display zero we're going to fetch this mean in the lookup table when we want to display one we're going to fetch this field in the lookup table when we want to display seven we are going to fetch that thing so we are going to show you how we use a lookup table to fetch and the values let's get back to the problem the problem says
08:30 - 09:00 draw the flowchart and write an assembly program to read port a0 to a2 and display the veil on the seven segment using lookup team right now let's start by drawing the function where we want to configure a0 to a2 as our inputs because we need to read them a0 to a2 as our inputs and then outputs on port p because the seven segment is connected to part b and we also want to disable analogs so that we can use those pins as digital
09:00 - 09:30 pins so let's know let's go create a flowchart we go to draw.io we're going to draw our flowchart let's create a flowchart and then under documents there let's create a folder where we will save this from chapter new folder i'll call this folder look up
09:30 - 10:00 and now i give my a file a name flowchart and then save a window appears there where we can draw a flowchart our flowchart always starts with an oval shape start and then the first thing we go to is initialize now at initialize
10:00 - 10:30 we want to set up our io pins ras0 up2ra 2s inputs we want to disable analogs and we want part b to be outputs those are the basic things we
10:30 - 11:00 want to do at initialize now after that what we want to do is we want to read a0 up to a2 use the lookup table to first the value and then display on the seven segment by writing to part b so the first thing we do is we now have to read our inputs our a0 to a2 now because we're only interested
11:00 - 11:30 on a0 to a2 we don't have an instruction or a way to read specifically only a02 we have to read the whole of part a right so we're going to read part a but remember when we read the whole of part a we're also reading other bits we are not interested in a3 a4 a5 up to a7 we are reading them but we are not interested in those
11:30 - 12:00 so we need to force the ones that we are interested we are not interested in we need to force them to be zeros so how do we do that we end with a value 0x 0 7 hexadecimal 7. why are we ending with 7 let me just explain a little bit um we are going to end with
12:00 - 12:30 a binary value or yeah if it fits in the binary then it's going to be 0 0 0 0 0 one one that's base seven now why are we ending with zero seven specifically when we end the value with or when we read port a and then we end with seven what are we doing whenever you end anything with a zero
12:30 - 13:00 what do you get the end operation whenever you end anything with a zero what do you get so what are we going to get we're going to get a binary value when we end anything with a 0 we get a c when we end with zero we get a zero and then we end with a zero we get a zero and we say zero we get a zero and we say zero we get a z
13:00 - 13:30 you end with one what do you get if you end with one if the input was 1 is going to remain 1 if the input was 0 is going to remain 0 right so if you end with 1 whatever you're ending with one it remains unchanged so i'm going to use u for that unchanged that is a2 is going to remain unchanged a1 is going to remain unchanged a0 is going to remain unchanged but the rest of the other bits are going to be zeros so we are ending
13:30 - 14:00 with this 0 7 to ensure that we have a0 a1 and a2 unchanged but the rest of the other bits we force them to be serums right that's the reason we are doing that and this step or this process is called masking we are actually asking our pets ensuring that they don't exceed or they conform to a certain rule we wish so mask
14:00 - 14:30 by ending with zero seven we are masking our bits by ending with zero seven after we read part a right now after doing that then we can use the value we read and end it with zero seven we can use it to fetch the value from there looks obtained
14:30 - 15:00 now the value that we're going to fetch on the lookup table will be a value which when we take that value and put it on part b it will display a number relating to the state of the input it will display under 7 segment and number relating to the state of the input we read on port a so we need to go and fetch that value fetch value from
15:00 - 15:30 loop update volt fetch a value from look up which value are we going to fetch we are going to fetch any of these groups we are going to fetch this value this value this value or that value depending on what is it that we read on port a when we put in go and fetch that win right now after fetching that v we want to write to a seven segment
15:30 - 16:00 using that name so to display on the seven segment we just put that value on what we write that value to part b write in that value to part b will actually display that number on a seventh segment and then after writing to the sound segment we want to keep on reading the state of the input ensuring that only three and a required bits are the ones useful the rest are zeros
16:00 - 16:30 we call the lookup table to fetch the value which will display the number on the seventh segment right now let me just add arrows on our flowchart and then when we get here we want to repeat the reading process
16:30 - 17:00 and now this is going to be where our main is right so this is our flowchart this is our flowchart now let's go and now write a problem let's go now and write a problem because this blood flows and the render assembly program to read part a0 to a2 and display on the
17:00 - 17:30 second segment using logarithm let's go create a project where we want now to start writing a program that will implement what we have in our future i'm still going to use the old version of mplab for this tutorial and then to create a project go to project select project wizard next select the device you wish to use for
17:30 - 18:00 this project in my case 16 f818 is selected click next we are going we are using assembly language in this tutorial so our tool suits will be mpasm assembler next now i need to browse and create a project so i'm going to browse and then go to look up under documents that folder where i saved my flowchart that's where i'm going to save my project as well
18:00 - 18:30 and then give you the name look up then click save that's the location of my project that's the name of my project click next nothing to add here click next i don't want to add anything still here or this is actually the summary of your project you just click finish that's your project created we now need to associate or to add a source file to the project shortcut
18:30 - 19:00 new file or you can go to file and then say new a new window pops up you want to save this file file save s under the very same folder documents look up i'm saving my asm file as luke app.asm and then add it to my project right and then click save this is where i'm going to
19:00 - 19:30 write my program start by writing the basics informing the compiler which micro controller are you writing this program for list p equals to 16 f 818 here i'm saying to the compiler that we are using peak16f818 now make use of
19:30 - 20:00 the file or include in your program the file p16f818 dot inc now this file contains the definitions of all special function register names to the addresses and then all the bits of those special function resources they are all defined in this
20:00 - 20:30 file so we are including this file in this program so that we can refer to the names without having to define them first because they are already defined in that file so we are saying through this file in the program or project or we can say import this as a file or essay you can regard the celebrant import the file import library
20:30 - 21:00 and then our program always has to end with end now that end it's not for a peak to execute that end is to inform the compiler that this is the end of the program merit that's the end of the programming already now with this basic instructions there if i build this and select absolute option there it should build successfully i haven't
21:00 - 21:30 started writing the pro just created a project and placed in that asm file the basic things you need to get started with your program now the program will be written in the middle then before the end there's no way you can write the program after the end because you are saying to the compiler this is the end of the program the program must come in here now start is our reset vector we say we are going to start here this is our
21:30 - 22:00 recent vector this is origin zero z and then from origin 0 0 we want to go to initial line so we go and do that for region 0 0 which is our reset vector we want to go to initial so go to initialize right and now initialize is a label so i'm going to copy that label and then i'm going to
22:00 - 22:30 have my initialize there at the magic the labels and the monitor now what is that i want to do at initialize i want to go and set up my i o pins and then i do that in bend one so i need to switch to bank one bit set five status comma rp0 this takes me to bank one now now that i'm in the one i want to make
22:30 - 23:00 a0 a1 up to a2 input so i'm saying move a little bit into w for now i'm going to do this fill in by now binary value bit 7 or r a7 must be an output because i'm not using it as an input all the pins are not using as inputs i'm configuring them as output so b7 v6 b5 b4 b3 b2 is an input b1 is an input b0 is
23:00 - 23:30 an input that's the binary value which i need to move to twist a move w to 5 press a that will configure my pins r a 0 2 r a two s inputs right r a zero to r a two s input now on part
23:30 - 24:00 b i don't have any inputs i can make the whole of part b outputs by clear entries b right make for b outputs all part b pins outputs right i still have to disable analogs as it is stated they disable analogs because part a 0 to a4
24:00 - 24:30 they are on default input analog pins so if you use those pieces inputs you need to disable analogs so i'm going to disable analogues by moving a value 0 6 into 8 corner i did explain where that number 0 6 comes from and moving 0 6 into 8.1 what it means basically it means disabled
24:30 - 25:00 analogs now because i'm using hexadecimal all and for my code i want to change this binary to this u it is still correct there is nothing wrong but i prefer using hexadecimal when writing the program so i want to change that binary to exactly small i only did binary to show you where the value comes from so what is
25:00 - 25:30 this value in hexadecimal zero zero zero that's a zero in hex and then that's a seven so the value that i'm moving into this is zero seven so i'm going to write now in hexadecimal that value is going to be 0x0 7 move it into press a right now after setting my inputs my outputs and disabling analogs
25:30 - 26:00 what i need to do next is to read part a at main there i'm going to start off by reading port a but now for me to read port a i must first be in bank 0 right so i'm going to switch to bank 0 btf i status rp 0 this takes me to bend zero
26:00 - 26:30 and then what i do now is beginning at main i need to read port a i need to read port a mask it by ending with 0 7 and then use the lookup theme so let me start off by reading port a move file point a into w here basically i'm reading for a
26:30 - 27:00 reading point a includes reading a0 a1 and a2 because those are the values or those are the inputs i'm interested in and because i'm only interested in those three i'm going to make sure that the rest of the other bits i'm not interested in and make them zeros by ending whatever i read there i end it with zero seven this ensures that a3 a4 a5 a6 and a7
27:00 - 27:30 will be forced to be zeros only a0 to a2 will stay unaffected they will remain unchanged now with only those three i'm interested in i want to now go and fetch a value from the lookup team after masking ending with zero seven i want to go fetch the value on a lookup table and then after fetching that value moving that value to part b will display on the seven segment first
27:30 - 28:00 i need to fetch that field so how do we fetch that video we call up i'm going to call a label called look update i'm going to explain and when i write what make up this so call look up we are just jumping to look up to fetch a value and then we have to return whenever you call you have to return right so i'm calling look up i'm going to jump to wherever lookup is
28:00 - 28:30 and then fetch a value return with that value that value when i return with it i need to write it to part b move that value that will when i return it will be in w right i will return with that value in w and then just moving that w into part b meaning i'm writing the value i returned with to part b this will be displaying on my seven second display on
28:30 - 29:00 seven segment yeah i'm fetching by pulling look up here i'm fetching the value to display on a seven segment this one is masking i am masking by ending with zero seven here now after displaying on my seven segment
29:00 - 29:30 after writing to part b it says here after writing to part b where do i do go back to me keep on repeating the process right so what happens is now we have go to hey this process will keep on repeating right read part a ensure that the unused bits are zeros
29:30 - 30:00 fetch a value to display on it on a hexadecimal or the value to display on a seven segment what the binary value on port a represents and then after facing that will display it on the seven segment by writing to part b repeat the process let's look at this lookup so this lookup i'm going to put it here you can put it under go to main there if you want it will still work but i'm going to put it in i'm putting
30:00 - 30:30 it here because i mean at origin zero zero after initial after power on this program is going to jump to initialize it's going to come directly to initialize it's going to skip whatever you have here so it's not a problem if i put my lookup here and i have another reason why i'm putting it here maybe i'll explain that reason later on but even if you put it down there it will still work right so on your lookup table
30:30 - 31:00 the first instruction that must be on your lookup table is add w with file and then the file is pcl comma file your lookup table always has to have the first instruction as add to file pcl comma file that has to always be the case now the first one is if we want to display zero we are going to
31:00 - 31:30 fetch the first value here return because we call that lookup table whenever you call you have to retain there are two returns which we can use a normal return which is written like that but now let's return it returns without fetching anything we want to return by fetching event so what we do is we use return with a value into w so this instruction it's still a retail
31:30 - 32:00 instruction but before it returns it loads the value into w which value do we want to load into w the first value here will be the value that's supposed to display zero on your seven segment this is the we want to return with now what's the value is going to display zero on your seven seconds the value that's going to display zero on your seven segment is seven e because when we take this seven e we move it to port b is going to display zero on here
32:00 - 32:30 seven seconds so we need to return with this value into w hence we did the whole thing so that we can get these views right now the first one we say let's return with ox 7 e now this is a value
32:30 - 33:00 that's going to display it's a value that's going to display zero on your seven segment this varies for displaying zero on your seven seven right the first value is for display 0 in your 7 segment the second value will be for displaying 1
33:00 - 33:30 so we have to get now the value that's going to display 1. the value is going to display 1 according to this it is 0 c so we write now on this one 0c and then we need another one for two three four five six seven right so but now we need to
33:30 - 34:00 change these two three four five six and seven and then we have to change those as well so let's do for the first three and for the last three two three four four two three four what are the vips v6 9e cc b6 9e cc so we're going to do b6
34:00 - 34:30 9e6 sorry b6 9 e cc right and now the next thing that we want to do is look for the newer ones
34:30 - 35:00 daf e d a f a 0 e d a f a 0p right so basically that's that's our lookup team now whenever you call look obtain it's going to jump to this and say add w
35:00 - 35:30 to file pcl and now if we had 0 we are going to add 0 to pcl and then if we add 0 to pcn we are going to return with this number now if w had 1 meaning we want to display one we're going to say one add with pcl we're going to return with this number but now how is that achieved how is that achieved that goes back to what we call a
35:30 - 36:00 pipeline instruction pipeline what instruction pipelining means let's look at this now the peak microcontroller does what we call instruction pipelining at the beginning remember now your program once once you program your microcontroller these instructions will be saved into the program memory right your cpu has to fetch those
36:00 - 36:30 instructions and execute right so what it says is at the beginning you're going to the first instruction cycle you're going to fetch the first instruction day now on the next cycle when that instruction because it was fetched on the first cycle when that instruction it is being executed the next one is automatically being fetched so fetching and execution of instruction they happen during one instruction cycle so when the
36:30 - 37:00 cpu executes this instruction the program counter fetches the next instruction that is going to be executed so the program counter that's our pca the program counter is a register that points to the address of the next instruction that's supposed to be executed so when we when the cpu is executing this instruction the program counter has this address in it meaning when this one is being executed one execution is happening here pcl has the address the next address
37:00 - 37:30 now the next instruction cycle when we execute this one which was first pcl already has the next one right so that's basically what we call instruction pipelining and that's the trick that the lookup table is used now with this instruction pipeline let's look at it here let's assume that we read port a
37:30 - 38:00 right and now part a was zero we ended with seven it's still zero we call look up so the time we call look up because we read point a and saved it into w w has zero in we can't look up now at lookup we say add w with pca when the cpu executes this ad pcl has the address of the next instruction meaning pcl has the value of the addressee
38:00 - 38:30 let me build this and demonstrate what i mean by address disassembly listing now this is a code which we have written and now at add there this is program memory address 1 when we execute instruction add add program memory address 1 pcl has program memory address 2 relating to the instruction which is this next one
38:30 - 39:00 when you execute the add w to file pc and pcl has the next instruction there which is it has the address of the next instruction which is true so if we had zero into w we add zero with two the next instruction is still at two because we say that to save into pcn so pcl still remains two meaning the next instruction it is still true because pcl holds the address of the
39:00 - 39:30 next instruction so we are going to return 81 and 2 at address 2 this address 2. now we return with 0 e because we added zero two please here and then when we return with seven e moving that seven e to part b displays zero on a seven segment we go back to main if we read part a again let's assume now point a has one in it
39:30 - 40:00 so we read for a we end with seven it is still one when we call loop up we have one in w when we say add w to file pcn one w has one pcl has the next the address of the next instruction the address of the next iteration will always be this next one when you execute this one this is the next instruction pcls address two right when we execute the add the address of this is true but now we have one in w you see say one
40:00 - 40:30 plus two becomes three save that in pcn pcl becomes three right and now remember pcl is purpose is to hold the address of the next instruction now if pcl has three what is the next strategy the next installation is at three so at three where are we it is here so instead of retaining with seven e we are now going to return at three continuing with zero c why because of that one that one
40:30 - 41:00 offset changes the pcl to go one instruction extra right so if we had two that two offset would have skipped the two come here for two if we had three in w is going to offset up to three retaining here so that's the idea of lookup table we modify in pcl because pcl holds that rest of the next instruction by
41:00 - 41:30 adding one we are going to skip one and then return there if we add zero it is still going to return on the next instruction right but if we add one it's going to return on just one under that one if we added two and so on and so on so our lookup table can be as long as we want but for our case our lookup table is up to seven hence we had to end with seven to ensure that the value which we use to add
41:30 - 42:00 to pcl mustn't exceed seven because the size of our gap table is seven right now that's basically what lookup tables are that's the principle on what or on which lookup tables are based on right so being successful let me simulate this and see if it's going to work which i believe it should right so that's my pic16f818 if you don't have
42:00 - 42:30 the seven segment shown on your sim simulator software you just go to tools the seven segment option there tools seven segment led display panel it shows you four seven segments we are just interested in one so i'm gonna just going to click set up there and now my a has to be connected to part b one if we want to change that just click that and say for b one in my case i've
42:30 - 43:00 already configured it that way a is connected to b one b is connected to b two c is connected to b three d before up until g is connected to b seven my seventh segment is always enabled to ensure that this is always enabled you can click it by we can change it by clicking there right always enabled that's what i want now um
43:00 - 43:30 let me load my program and i look up that's my lookup x and let me start simulation i have zero display on the seven segment okay let me hide setup zero displayed on my seven segment because the three inputs a0 l1 and a2 are off that binary value it is
43:30 - 44:00 zero now if i do this i make a zero one my seven segment becomes one i make a02 in binary this is two it is displayed on a seven segment it's a decimal two in binary that's a three it is displayed on a seven segment as a decimal three in binary that would be seven one one one is seven displayed on a seven segment as a
44:00 - 44:30 decimal seven so basically that's what lookup tables are and that's how we make use of them right that's how we make use of them now let me give you a task now to say your job will be now to extend your lookup table to include 8 9 a b c d e f
44:30 - 45:00 right so these are the values that you need to put in on your lookup table to extend it but also to do that you have to change the program you will have to change the program and say my inputs are no longer only three inputs but now there are four inputs meaning it's going to be a0 a1 a2 and a3 and to set those as inputs you will send zero f to this a and now you end with
45:00 - 45:30 zero f here you end with zero f you call lookup table now the length of your lookup table will be from zero up to f your table has to expand this so you need to have values for 8 9 a small case b c small case d
45:30 - 46:00 e and f right so you get the values you modify because these are this is still going to play 0 1 2 because i just copied it you change this let me just quickly do it because i already have the cm now f e c e e e f eight f e c e e e f eight and
46:00 - 46:30 fifth four f e c e e f eight go into my program f e c e e e f eight i think those are the correct ones
46:30 - 47:00 and then it's f e c e f e the the next four um 72bc f2 e2 72 bc f2 e2 72b c f2 2 7 2
47:00 - 47:30 bc f 2 e two so now that's the new size of my lookup table using four bits input now this is a zero to a three as my input some segments still connected to part b i just extended my lookup table and then a masking vein there changed as
47:30 - 48:00 well build this stop simulation let's load the updated hex file and then let's start simulation now we have a0 up to a3 now we have four inputs remember a5 can can only be an input but we're not using it if i if you're not using it even if i do anything on it nothing's going to change we're using a02 a4 if i do this that's a 1 that's a 2
48:00 - 48:30 that's a 3 that's a four five six seven now that's an eight nine a b c d
48:30 - 49:00 [Music] e f right so basically that's what lookup table is about and try and and do more examples on lookup tables maybe as an example let's say now you want to display
49:00 - 49:30 still a2 still four bit but now you want to read a1 up to a form you see now a0 is no longer the least significant bit now we have one e to set up these as inputs you cannot if this is the case you cannot read port a as it is because a0 will be the least significant bit
49:30 - 50:00 and then that will affect the length of your table that will affect the length of your team to get rid of that you need to shift your beats today right so that you get rid of a0 and you make a1 the least significant bit so instead of just reading point a as it is we're going to read it and shift it to them right by using the rotate write file rotate write file port a save into w
50:00 - 50:30 still once we have done that it means now we have made a0 the least significant this can still remain f and then the table can still remain that size right but if we didn't rotate we were supposed to change this to one e and then maybe modify our table to fit the length of that one right let's build this
50:30 - 51:00 and see how dust changes our simulation finally let's load the updated hex file simulation start you see now a0 is no longer an input a1 is the input but we can still write 0 1 3 up until f right we can still do that but what if
51:00 - 51:30 okay let me just end here for this video other things we'll discuss them later now the rotate right file what i wanted to show you is what if we decided to say a2 is our first input and then we're using a5 there it's still four inputs but that is a2 a2285 this makes it 3c right now for a2 to be the least significant
51:30 - 52:00 bit you have to shift twice to the right you have to shift twice to the right how do you how are you supposed to do that because this strategy shifts only once this instruction here shifts only once to the right but if a2 is the beat you wish to make the least significant you need to shift to the right two times before you can end with zero f how will you do that there's no
52:00 - 52:30 way that you will do this that will be wrong if you do it this way you say rotate right file port a and then you say part a or let's say you say put a comma file there and then you say for a comma w this is this will be wrong
52:30 - 53:00 it will be wrong because point a when you read it it's still going to read a0 in it still going to read a0 and a1 still there in it even if you rotate it once there so this is not going to help what you need to do is you need to rotate right port a save into w but now we need to rotate for the second time the value which we saved into w we need to rotate it for the second we don't have any instruction that
53:00 - 53:30 rotates w itself this rotates the rotate right file it has to be implemented against a file there so whatever we rotate it we read and rotate it on protein we need to temporarily save it somewhere so we need to make use of a temporary resistor now temporary resistor i'm giving it a nail and then i'm equating it to address in hexadecimal
53:30 - 54:00 and that is actually my temporary register it is part of the general purpose registers it's part of the general paper with registers which we get on our peak microcontroller if we look at this memory organization we have general proposed registers these registers are the registers we can use
54:00 - 54:30 to save any information we want to save right these are especially the names of special function registers these are the addresses say i said the include file specifies that point a it is address 5 for b it is after 6 but now these registers they don't have names because they are general people's resistance when we want to use them we can give them names so they start at two zero index that is small up to seven
54:30 - 55:00 f right so i'm saying the address at two zero let's give it a name temp the address at two zero let's give it a name temp given to a registered address to zero in hexadecimal and then that's where at intent that's where i'm going to save my information i'm going to rotate right for a save into w then move w to file them right so temp
55:00 - 55:30 is my general purpose register where i can save my information because it falls between that 2 0 and 7 f of the hexadecimal so temp is a registered address 20 so i'm just adding here on this table temp here but temp is a register that i can use to save my information it doesn't control anything of the microcontroller special function resistors are the ones that control and monitor
55:30 - 56:00 the aspects of the general people's resistance that's where you save your information you can move anything into a general people's resistance nothing is going to happen you are just saving your information in there right so in this case address 2 0 in hexadecimal i'm using this as my temp and i'm equating that register to temp and then i'm saving the information i read from port a i'm saving it into w and then move it
56:00 - 56:30 into temp temporarily right and now this value is the value which was rotated once but because i want to make a2 the least significant i need to rotate that twice so this time around i'm not going to rotate port a but i'm going to rotate temp temp is point a which was rotated once i want to rotate that put a for the second time so rotate right file
56:30 - 57:00 temp save into w now whatever is in w it is port a rotated twice this time and then after rotating for a twice i have a two as my least significant bit i can end with zero f call the lookup and display the value on part b let's build that and then simulate it
57:00 - 57:30 stop simulation load the new hex file start simulation you see now my inputs are a283 a4 up to a5 currently the seven segment has zero in when i do this some segment has one when i do this eight if all of them are high that's f
57:30 - 58:00 right but using a2 as the least significant bit i had to rotate it twice to the right to make this bit the least significant bit right okay guys that concludes our video on lookup tables and ensure that you understand this tutorial you can make use of lookup tables in your applications as well typical applications of lookup tables
58:00 - 58:30 uh specifically on seven segments is let's say for example you want to implement a counter something that counts from zero to nine or you have two seven segments it has to count from uh zero up to ninety nine in decimal and so on or you want to implement a um real-time clock with four seven segments you can make use of lookup table to be able to display any value between zero and nine right
58:30 - 59:00 because for a real-time clock you just need values between zero and nine abc those are for hexadecimal purposes they're not really necessary for your real-time club so look up tables find applications in a lot of situations and they help you minimize what would have been a very very long program right to ensure that you understand lookup tables be able to use yoga tables in your applications thank you guys i'll see you on the next