PIC PROGRAMMING START. The next stage is always the setting up of the PORTS, the symbol used to indicate this and all Processes is a Rectangle.

Size: px
Start display at page:

Download "PIC PROGRAMMING START. The next stage is always the setting up of the PORTS, the symbol used to indicate this and all Processes is a Rectangle."

Transcription

1 PIC PROGRAMMING You have been introduced to PIC chips and the assembly language used to program them in the past number of lectures. The following is a revision of the ideas and concepts covered to date. PLANNING USING A FLOWCHART The first stage of any program is to write a flowchart to plan the actions required. The first symbol in any flowchart is an Oval that indicates the Start of the program. START The next stage is always the setting up of the PORTS, the symbol used to indicate this and all Processes is a Rectangle. SET UP THE PORTS All Symbols have a connecting line with an arrow showing the direction of progress. Once the Ports have been set up the main section of the program follows. For example if we are controlling a set of traffic lights the first job after the setting of the PORTS is to OUTPUT the first light sequence on to the Lights connected to the output PORTS. OUTPUT FIRST LIGHT SEQUENCE TO THE TRAFFIC LIGHTS 1

2 The Processes continue in this fashion until a question or an INPUT is needed to be checked or a DECISION is required. The symbol for a DECISION is a diamond shape that has two possible output routes. Usually one route is when the answer to the question is YES and the other when the answer is NO. IS SWITCH ON PORTA BIT 0 ON? NO END YES After you have finished all Processes required the Flowchart either has an END oval symbol or the last Process symbols connecting line is directed back into the flowchart so the program continues indefinitely, see example below. OUTPUT SECOND LIGHT SEQUENCE TO THE TRAFFIC LIGHTS OUTPUT THIRD LIGHT SEQUENCE TO THE TRAFFIC LIGHTS 2

3 SETTING UP THE PORTS With any program we must communicate with the outside world, whether that is taking information IN to the PIC chip from inputs like switches and sensors or sending information OUT of the PIC chip via the outputs like lights and motors etc. Therefore, the first task of every program is to set up the PORTS of the PIC chip to set them up as either INPUTS or OUTPUTS as required by the particular program. In ET3 we are mainly concerned with the PIC16F84 PIC chip which has 2 PORTS, that is PORTA which has 5 bits or physical connections to the outside world (but we always write 8 bits to the PORT) and PORTB which has 8 bits or connections to the outside world. 4 3 PORTA PORTB The way we set up the PORTS is always the same the only difference between programs is which bits you require to be INPUTS and which bits you require to be OUTPUTS on PORTA and PORTB. Once we have decided on which bits are INPUTS and which are OUTPUTS we then begin to write the code or program or instructions required. The setting up of the PORTS is performed when the PIC chip is in PAGE1 of the memory. Moving to PAGE1 requires one instruction BSF STATUS,5. Once in PAGE1 a 1 or a 0 is written in each position of the PORTS to make them either an INPUT = 1 or an OUTPUT = 0. This is performed in two steps, first the 1 s or 0 s to set up the s of the PORTS are set up in the W register using the instruction MOVLW b

4 The second step is to write the information set up in the W register to the PORTS using the special names TRISA for PORTA and TRISB for PORTB, using the instruction - MOVWF TRISB. The special names are used to indicate that the PORTS are being set up as INPUTS or OUTPUTS. The binary number b used in this example would make PORTB have 4 INPUTS and 4 OUTPUTS. REMEMBER the two steps above are written to set up PORTA and then PORTB i.e. do it twice. The last step is to move back to PAGE0, which requires one instruction BCF STATUS,5. This is the end of the setting up of the PORTS the main program follows next. RECAP Set up PORTA as all OUTPUTS and then PORTB as 4 INPUTS then/and 4 OUTPUTS. STEP1 Write the instruction to move from PAGE0 to PAGE1 of the memory BSF STATUS,5 ; Move to PAGE1 STEP2 Set up the 1 s and or 0 s for INPUTS and or OUTPUTS in the W register, for PORTA. MOVLW b ; Set up 1 s and 0 s in W 4

5 STEP3 Write the information in W register to PORTA using the special names. MOVWF TRISA ; Write Wreg to TRISA STEP4 Set up the 1 s and or 0 s for INPUTS and or OUTPUTS in the W register, for PORTB. MOVLW b ; Set up 1 s and 0 s in W STEP5 Write the information in W register to PORTA using the special names. MOVWF TRISB ; Write Wreg to TRISB STEP6 Move back to PAGE0 in preparation for the remainder of the program. BCF STATUS,5 ; Move to PAGE0 5

6 EXERCISE 1 Write the instructions required in each STEP to set up PORTA as 3 INPUTS then 2 OUTPUTS and PORTB as 4 INPUTS then 3 OUTPUTS then 1 INPUTS, as in the picture below. 4 3 PORTA PORTB OUT OUT IN IN IN IN OUT OUT OUT IN IN IN IN 0 STEP1= STEP2= STEP3= STEP4= STEP5= STEP6= Write your instructions into the VPIC simulator and start at address 005. Once you have written all your instructions step through the program and see if the PORTS are as required. A blue arrow pointing in represents an INPUT PORT and a red arrow pointing out represents an OUTPUT PORT. 6

7 THE MAIN PROGRAM Once the PORTS have been set up correctly as required we turn our attention to the main section of the program. Once we have set up the PORTS we will have to either get information IN to the PIC chip from the outside world and/or get information OUT to the outside world via the PORTS. We will begin with getting information OUT of the PIC chip via the PORTS. Outputting Information from the PIC chip There are mainly three instructions we will use to Output information to the PORTS of the PIC chip. Outputs can be Lights or Motors for example. The first instruction is as follows: BSF PORTB,1 ; SET PORTB 1 ON = 1. This instruction Sets (makes it a 1) 1 of PORTB, so puts the Output device ON. This instruction can be used with any PORT or File in fact and any of the 8 bits of the PORTS or File. The second instruction is as follows; BCF PORTB,1 ; CLEAR PORTB 1 or put OFF = 0. This is the opposite of the first instruction in that it is used to CLEAR or put OFF = 0 a single bit of an Output Port at a time. This instruction can be used with any PORT or File in fact and any of the 8 bits of the PORTS or File. The two instructions above can only put ON or put OFF a single at a time. If we need to put more than one of the PORTS or a File ON or OFF at the same time we need to 7

8 use the following instruction. The third instruction is as follows: MOVWF PORTB ; Move the contents of W register to the File PORTB. The W is the one and only Working Register that exists in the PIC 16 series. This is an 8-bit width register (store for 8 bits) used for general operations. The W register will be used all the time and therefore you need to get used to it really quick. Again the instruction can be used with any PORT or File, but 8 bits are written at the same time with this instruction. When used with PORTA of the PIC16F84 PIC chip in ET3 only the 5 least significant bits are transferred to PORTA as PORTA has only 5 bits in this chip. Usually the third instruction is usually used in conjunction with another instruction used to set up the 8-bit sequence required on the Output PORT, the instruction is: MOVLW h 0F MOVWF PORTB ; Set up the sequence required on PORTB in W register. ;Write the sequence Out to PORTB. The MOVLW k instruction is the literal value loading instruction where k is the value to be loaded. Literal means a number so MOVLW k means Move or load the number k in to the W register. As you will see, there is no direct way of loading a literal value to the Ports or a File register. First, the value needs to be loaded to the W register and then the 8

9 W register is moved to the Port or File register. Even though PORTB for example may not have 8 Output s as shown in EXERCISE 1 above, we still always write 8 s to the Port. The MOVLW instruction can be used with Binary, Hex or Decimal numbers, as shown in the examples below. MOVLW b ; Set up the binary sequence in W register. MOVWF PORTB ;Write the sequence Out to PORTB. Or MOVLW h 3F MOVWF PORTB PORTB. ; Set up the hex sequence in W register. ;Write the sequence Out to Or MOVLW 0x3F MOVWF PORTB ; Set up the hex sequence in W register. ;Write the sequence Out to PORTB Or MOVLW d 63 ; Set up the decimal sequence in W register. MOVWF PORTB ;Write the sequence Out to PORTB. 9

10 Inputting Information Into the PIC chip The INPUTS could be from switches or sensors that give either a Logic 1 for ON and a Logic 0 for OFF. This is obviously Digital information but it is possible with some PIC chips to input Analogue information or a voltage that can vary anywhere from a Minimum value to a Maximum value. This could be from a Temperature sensor for example and the Analogue Input is then converted using an Analogue to Digital Converter inside the PIC chip to a Digital number. We will only be using Digital Inputs in ET3. We can either test if a certain INPUT is ON = 1 or OFF = 0 directly and then perform different sequences or steps depending on the answer to the test, or we can Input the information IN to the PIC chip and then manipulate or isolate the required bits before testing. Method 1 The first method where we test the Input directly has two instructions, one that tests if an Input is SET or ON=1, and one that tests if an Input is CLEAR or OFF=0. BTFSS PORTB,1 ; Test PORTB 1 Skip the next instruction if the bit is SET or ON=1. This instruction is easier to understand if we place address numbers before all the instructions in our program. 00B BTFSS PORTB,1 ; Test if PORTB 1 is ON=1. 00C GOTO SEQ2 ;NO, PORTB 1 is OFF=0 do SEQ2. 00D GOTO SEQ1 ; YES, PORTB 1 is ON=1 do SEQ1. Remember this corresponds to the Decision process or the diamond shape in our Flowchart. The question to test if the Input connected to PORTB 1 is SET or ON is at address 008. When PORTB 1 is OFF (or the answer to the question is NO) the program will go to address 009 and we then jump over 10

11 the next instruction at 00A by going to a different part of the program to do the second sequence (SEQ2) using the GOTO instruction. When PORTB 1 is SET or ON (the answer to the question is YES) the program will Skip or jump over the next address at 009 and go directly to address 00A and we then jump to a different part of the program to do the first sequence (SEQ1). We could have performed the first sequence in the addresses immediately following address 00A which is usually done, but the concept of going to two different locations depending on the answer to a question is sound. The instruction to test if an Input is Clear or OFF=0 is as follows: BTFSC PORTB,1 ; Test PORTB 1 Skip the next instruction if the bit is CLEAR or OFF=0. Again with the addresses we have: 00B BTFSC PORTB,1 ; Test if PORTB 1 is OFF=0. 00C GOTO SEQ2 ; NO, PORTB 1 is ON=1 do SEQ2. 00D GOTO SEQ1 ;YES,PORTB 1 is OFF=0 do SEQ1. The question to test if the Input connected to PORTB 1 is CLEAR or Off is at address 008. When PORTB 1 is ON (or the answer to the question is NO) the program will go to address 009 and we then jump over the next instruction at 00A by going to a different part of the program to do the second sequence (SEQ2) using the GOTO instruction. When PORTB 1 is CLEAR or OFF (the answer to the question is YES) the program will Skip or jump over the next address at 009 and go directly to address 00A and we then jump to a different part of the program to do the first sequence (SEQ1). 11

12 Before you write your Flowchart decide where the Inputs and Outputs will be connected to the PORTS of your PIC chip. This is best done with a picture or a table showing what is connected to where. RECAP Using the PORTS set up in Exercise1 as an example, and assuming that the code to set the PORTS up has been written start the program at address 00B. 4 3 PORTA PORTB OUT OUT IN IN IN IN OUT OUT OUT IN IN IN IN 0 Outside Light Motor1 Alarm On Switch Window Sensor Sensor Full Sensor Empty Sensor Motor2 Box Sensor Heater1 Off Switch Door Sensor The above is an example of Inputs and Outputs that are connected to a PIC chip to control a small production line. Write the program instructions required to turn ON Motor1 on PORTB 6, If the On Switch is pressed as sensed by the On Switch Sensor on PORTA 2. The program should continually check the On Switch and do nothing else until Motor1 is started. Assume that Motor1 has been switched OFF previously. On Switch Input = 0 if the On Switch has not been pressed. On Switch Input = 1 if the On Switch has been pressed. 12

13 Motor1 is OFF if a 0 is placed on the corresponding Output and ON if a 1 is placed on the Output. The Program The first step is to write the instructions to ask the question to see if the On Switch has been pressed or not by Testing the On Switch Input on PORTA 2. You set up the Program Labels in the VPIC simulator at the correct positions, by clicking on the required position of the Label then pressing the Edit program labels button then double clicking on <add new>, then enter the name of your Label (e.g. ON in the example below) and then press OK. ON 00B BTFSS PORTA,2 ;Is the On Switch ON? The next step is to write the instructions to direct the program back to the section of the program where the question is asked IF the On Switch is OFF or has not been pressed. The best way to do this is to have a program Label at the required address, the Label used will be ON. 00C GOTO ON ; NO, go back to the question. The next step is to write the instructions to turn on Motor1 IF the On Switch is ON or has been pressed. 00D BSF PORTB,6 ;YES, turn on Motor1 on PORTB 6. The program would then continue. The whole program would be: ON 00B BTFSS PORTA,2 ; Is the On Switch ON? 00C GOTO ON ; NO, go back to the question. 00D BSF PORTB,6 ;YES, turn on Motor1 PORTB 6. 13

14 EXERCISE 2 Firstly, make sure the ROADWORKS add on has been selected in VPIC so you can see the ROADWORKS simulation underneath PORTA and PORTB. Now read through the whole exercise below first and then complete a full Flowchart (in the space provided below) for the complete program, that is, the setting up of the PORTS and the program for the Traffic Lights with the ON/OFF Switch and the Change Request W and E switch inputs. START 14

15 Using your Flowchart as a guide, write the instructions required in each STEP to set up PORTA as 2 INPUTS then 3 OUTPUTS and PORTB as 6 OUTPUTS then 2 INPUTS then, as in the picture below. This will set up the ports for the ROADWORKS add on in VPIC. 4 3 PORTA PORTB OUT OUT OUT IN IN IN IN OUT OUT OUT OUT OUT OUT Not Used Not Used Not Used Not Used Change Request W ON/OFF Switch Red light E Change Request E Red light W 0 Amber light E Amber light W Green light E Green light W STEP1= STEP2= STEP3= STEP4= STEP5= 15

16 STEP6= Below is the light sequence required for the traffic lights on the West and East side of the road works, where a 1 represents the lights being ON and a 0 represents the light being OFF. TRAFFIC LIGHTS WEST TRAFFIC LIGHTS EAST Sequence RED AMBER GREEN RED AMBER GREEN HEX NUMBER C Now write the instructions required to put both Red Lights ON only, then check IF the ON/OFF Switch is ON or OFF. If the ON/OFF Switch is OFF = 0 go back and check again. If the ON/OFF Switch is ON = 1 then set Sequence 1 on the Traffic Lights. Remember that the ON/OFF Switch is connected to PORTB 7. The cars will now be moving East to West. Next we must look at the Change Request W input (PORTA 1) to see if there is a car waiting to go through the road works from the West side (You have to press the Change Request W switch with the mouse to activate the switch). If Change Request W input (PORTA 1) is OFF = 0 then we have to go back and check again. Remember this is done by setting up a Label on the Test instruction and then having a GOTO Label instruction in the position where the program goes if Change Request W input (PORTA 1) is OFF = 0. If Change Request W input (PORTA 1) is ON = 1 then we have to set Sequence 2 then Sequence 3 then Sequence 4 and finally Sequence 5 on the Traffic Lights. Now the cars will be moving from West to East. 16

17 Next we must do the same thing as above but with the Change Request E input (PORTA 0) to see if there is a car waiting to go through the road works from East to West. If Change Request E input (PORTA 0) is OFF = 0 then we have to go back and check again. Remember this is done by setting up a Label on the Test instruction and then having a GOTO Label instruction in the position where the program goes if Change Request E input (PORTA 0) is OFF = 0. If Change Request E input (PORTA 0) is ON = 1 then we have to set Sequence 6 then Sequence 7 then Sequence 8 and finally back to Sequence 1 on the Traffic Lights. Now the cars will be moving from East to West. In the final step to set up Sequence 1 we must jump back (using a GOTO Label instruction) to the start of the program where we set up Sequence 1 initially instead of setting it up for the second time. This is important because we want to keep using the same Traffic Light Sequences all the time that the ON/OFF Switch is ON A 00B 00C 00D 00E 00F

18 A 01B 01C 01D 01E 01F After you have completed the instructions write them into the VPIC simulator and start at address 005. Once you have written all your instructions step through the program and see if the PORTS are as required. Then check to see if Sequence1 comes ON only when the ON/OFF Switch (PORTB 7) is pressed, both Red Lights should be ON if the ON/OFF Switch is not pressed. Then press the Change Request W 18

19 and see if the Traffic Lights change so that the cars travel from East to West. Method 2 The second method where we Input the information IN to the PIC chip and then manipulate or isolate the required bits before testing. This method is used where we want to check more than one bit of information at a time, whether that is 2 bits or a full 8 bits. An example could be when we have a keypad connected to PORTB as in a safe door, where we would have to check if the correct code was entered into the keypad before the safe was opened. The instruction is as follows: MOVF PORTB,W ; Move file PORTB into the W register. When the instruction is written into an Assembler program the W is replaced with 0, which means move into the W register. If it is replaced with a 1 it means move the file back into the file, which at first looks strange but as the Zero flag is affected by this instruction it can be used to check if the file contains nothing or zero. Once the information is in the W register we usually save the information in a general purpose register we have set up previously, for this example we will have 3 set up registers Num1, Num2 and Num3. The instruction to save the W register in one of our registers is as follows: MOVWF NUM1 ; Move the W reg into register Num1. Once the information is saved in the new registers we can then do a number of tests or checks to see if the register contains a given number or the number is greater or less than a predefined number. 19

20 In this example we need to check if the number saved is equal to a predefined number as in a code. This is done using the following instructions. We will check if NUM1 is equal to the number 4 or said another way, has the number 4 been input into the keypad. TEST1 MOVLW 04 ; Move 04 into the W register. XORWF NUM1,W ; Exor NUM1 with the number 04. BTFSS STATUS,2 ; Was NUM1 = 04? GOTO LOCK ; NO, go to LOCK. GOTO TEST2 ; YES, go to TEST2 to check NUM2. The first instruction loads the number 04 into the W register. The second instruction EXOR s NUM1 with the W register which has been loaded with 04. Why use EXOR? The EXOR of two bits gives an output of 0 if the bits are the same, and an output of 1 if the bits are different. Example 1 When NUM1 has 07 stored inside. W reg = 04H = NUM1 = 07H = RESULT = 03H Example 2 When NUM1 has 04 stored inside. W reg = 04H = NUM1 = 04H = RESULT = 00H As can be seen from the two Examples above when the numbers are different the RESULT of EXORing is NOT ZERO, 20

21 when the numbers are the same the RESULT of EXORing is ZERO. Therefore, after EXORing the Zero Flag 2 of the STATUS register can be checked to see if the two numbers are equal or different. If the Zero Flag is 1 the two numbers are the same or equal. If the Zero Flag is 0 the two numbers are different. So the XORWF instruction in conjunction with the testing of the Zero Flag BTFSS STATUS,2 gives two possible outcomes, one where the numbers are Equal and one where the numbers are Different. The full set of instructions would then be: MOVF PORTB,W ; Move file PORTB into the W register MOVWF NUM1 ; Move the W reg into register Num1. TEST1 MOVLW 04 ; Move 04 into the W register. XORWF NUM1,W ; Exor NUM1 with the number 04. BTFSS STATUS,2 ; Was NUM1 = 04? GOTO LOCK ; NO, go to LOCK. GOTO TEST2 ; YES, go to TEST2 to check NUM2. EXERCISE 3 Write the instructions required to Input the information on PORTB and save this information in the register NUM2. Then Test to see if NUM2 is equal to 0AH and if it is Not equal to 0AH go back and keep Inputting the information on PORTB and Testing until NUM2 (the information on PORTB) is equal to 0Ah. Then put PORTA bit 0 ON, then go back to the START of the program. Start at address 00A. 00A 00B 00C 00D 21

22 00E 00F

23 THE DELAY ROUTINE In most programs we will need to either wait for a predetermined length of time before an action is required, or slow down a given set of outputs or sequences. Therefore, a Delay routine or sometimes called a subroutine is required. A routine is a separate program from the Main Program that is written once but can be used many times, without having to be written again. The Flowchart for a simple Delay Routine is as follows: START OF DELAY1 SET LENGTH OF THE DELAY IN DEL DEL = DEL - 1 NO YES IS DEL = 0? RETURN 23

24 We now are in a position to write the instructions required to perform the actions in the Flowchart. As you can see from the Flowchart the way we make a DELAY in software is to place a big number in a register then decrease it by 1, check if it is zero and if it is the DELAY is over and the program needs to Return back to where it was Called from, if it isn t zero the program loops back and decreases the register by 1 again. As every single instruction in programming takes a given amount of time to perform we can work out accurately the length of time to perform the steps described above. Then by performing the loop many times we can set the DELAY to a required length by increasing or decreasing the set number placed into the register at the start of the DELAY Routine. When a Delay is required in the main program the following instruction begins the Delay Routine. CALL DELAY1 ; Jump to the Delay Routine. The CALL Instruction is different from the GOTO instruction in that when a CALL instruction is encountered by the program, the address of the next instruction to the CALL is saved, in preparation for a RETURN instruction, when the address is recovered and the program will continue from the instruction immediately below the original CALL. This does not happen with a GOTO instruction so the program has no way of returning back to the next address below a GOTO instruction. The first instruction of the Delay routine would be: DELAY1 MOVLW h 0F ; Set the Length in W register. 24

25 The first thing to note is the Program Label before the instruction that is Called by the Main Program. Following the Label is the instruction that sets up the number that will correspond to the length of the Delay. A large number will give a long Delay and a small number will give a short Delay. However, this number in the W register has to be saved in to the DEL register that has been set up by the programmer for this specific use. The instruction that does this is: MOVWF DEL ;Save the Length of Delay number in the DEL register. The next step is to take 1 away from the number in the DEL register and save the result back into DEL register, or said another way decrease DEL register by 1. D1 DECF DEL,F ; Decrease DEL by 1. Next we have to check if the result of decreasing DEL register by 1 gives an answer of zero. Checking the Zero flag that is located in the STATUS register 2 does this. BTFSS STATUS,2 ; Is DEL = 0? There are two possibilities, the first is that DEL is NOT zero therefore we have to loop back to label D1 to decrease the DEL register by 1 again. GOTO D1 ;NO, DEL>0 loop back do again. The second possibility is that DEL register IS zero and the DELAY is over and the program needs to RETURN back to 25

26 where it was called. RETURN ; YES DEL=0 DELAY over, Return. As stated earlier when a RETURN instruction is encountered the program goes back to where it was Called by recovering the address that was saved when the CALL instruction occurred. So the full DELAY1 routine would be: DELAY1 MOVLW h 0F MOVWF DEL ; Set the Length in W register. ; Save the Length in DEL reg. D1 DECF DEL,F ; Decrease DEL by 1. (STEP3) BTFSS STATUS,2 ; Is DEL = 0? (STEP4) GOTO D1 ; NO,DEL>0 loop back do again. RETURN ;YES DEL=0, DELAY over, Return to Calling program. There are a number of alterations or changes we can do to the first DELAY routine seen here. The first change is a small change that replaces the two instructions at Step 3 and 4 with a single instruction that performs the two steps in one. The instruction is: DECFSZ DEL,F ;Decrease DEL by 1 and then check if DEL = 0? The action of this instruction is exactly the same as the two instructions it can be used to replace. The choice of which 26

27 technique to use is up to the programmers preference. The second change that can be made is related to the length of the DELAY possible. With the 8-bit W register and the DEL register we used in the delay example previously the largest number possible is 0xFF Hex which is Binary or 255 Decimal. So this limits the Maximum size of the DELAY we can produce with this method. With clock frequencies of the PIC 16F84 in the 1 to 4MHz range, this would give a relatively small DELAY in the range of a few milliseconds or a few thousandths of a second. Therefore, if we require a longer DELAY we have to do more. Longer or NESTED Delays If we wanted a minutes DELAY using a watch, for example, we would count 60 seconds using the second hand of the watch. So each click of the second hand provides a DELAY of length one second. We then count 60 of these 1 second DELAYs to give us a minutes DELAY. This is the technique we are going to use to provide longer DELAYs than is possible with the original technique shown on the previous pages. The technique is called NESTED DELAYS, which is a method of having many DELAYs within another DELAY Routine. The Flowchart on the following page shows the steps required to perform a NESTED DELAY Routine with 2 stages. The only real difference to the original DELAY Routine seen previously is the inclusion of the CALL DELAY1 instruction in between the Set the Length of the Delay Block and the DEL = DEL 1 Block. So in effect we are having DEL2 x DELAY1 delays in this Nested Delay Routine called DELAY2. 27

28 START OF DELAY2 SET NUMBER OF DELAY1 s REQUIRED SAVE IN DEL2 CALL DELAY1 DEL2 = DEL2-1 RETURN IS DEL2 = 0? NO YES 28

29 The instructions for this NESTED DELAY Routine called DELAY2 would begin with the Main Program Calling the DELAY. CALL DELAY2 ;Jump to the DELAY2 Routine. The DELAY2 then begins in a similar way to DELAY1. DELAY2 MOVLW h 04 MOVWF DEL2 ;Set the number in W register. ;Save the number of DELAY1 s required in the DEL2 register. Then DELAY2 Calls DELAY1 to delay for a certain amount of time. CALL DELAY1 ;Jump to the DELAY1 Routine. After DELAY1 has finished control returns to the next instruction which is: D2 DECF DEL2,F ;Decrease DEL2 by 1. We then check if DEL2 is equal to zero. BTFSS STATUS,2 ;Is DEL2 = 0? Then both possibilities are encoded. GOTO D2 RETURN ;NO, DEL2>0 loop back to do again. ;YES,DEL2=0 DELAY2 is over Return to Calling program 29

30 So the full DELAY2 routine would be: DELAY2 MOVLW h 04 MOVWF DEL2 CALL DELAY1 ;Set the number in W register. ;Save the number of DELAY1 s required in the DEL2 register. ;Jump to the DELAY1 Routine. D2 DECF DEL2,F ;Decrease DEL2 by 1. BTFSS STATUS,2 ;Is DEL2 = 0? GOTO D2 RETURN ;NO, DEL2>0 loop back to do again. ;DELAY2 is over, Return to Call -ing program. DELAY2 is an example of a 2 stage Nested Delay Routine, this technique can be continued as many times as needed to provide the Delay Length required. So to make a Delay of 1 Hour we could have a 3 stage Nested Delay Routine, that is have 60 x 1 Second Delays to give 1 Minute, then 60 x 1 Minute Delays to give 1 Hour. As you can see we could extend this idea to give longer Delays. The registers DEL1, DEL2, NUM1 and NUM2 used in the previous examples and pages, must be set up by the programmer. This is done at the beginning of the program using an equate statement as shown below. DEL1 EQU 0CH DEL2 EQU 0DH NUM1 EQU 0EH 30

31 NUM2 EQU 0FH There are specific addresses/locations used for these General Purpose Registers (GPRs) in the PIC chip memory. When using the VPIC simulation program, these registers are made by clicking on the Set up program Registers icon, then double clicking on the first address under the GPR table, (usually 0C) then insert the Name then the description. The register is then available for use. 31

32 The next Stage within our program is to count: 32

Embedded Systems. PIC16F84A Sample Programs. Eng. Anis Nazer First Semester

Embedded Systems. PIC16F84A Sample Programs. Eng. Anis Nazer First Semester Embedded Systems PIC16F84A Sample Programs Eng. Anis Nazer First Semester 2017-2018 Development cycle (1) Write code (2) Assemble / compile (3) Simulate (4) Download to MCU (5) Test Inputs / Outputs PIC16F84A

More information

Flow Charts and Assembler Programs

Flow Charts and Assembler Programs Flow Charts and Assembler Programs Flow Charts: A flow chart is a graphical way to display how a program works (i.e. the algorithm). The purpose of a flow chart is to make the program easier to understand.

More information

CONNECT TO THE PIC. A Simple Development Board

CONNECT TO THE PIC. A Simple Development Board CONNECT TO THE PIC A Simple Development Board Ok, so you have now got your programmer, and you have a PIC or two. It is all very well knowing how to program the PIC in theory, but the real learning comes

More information

Jordan University of Science and Technology Electrical Engineering Department Microcontrollers and Embedded Systems Spring 2011

Jordan University of Science and Technology Electrical Engineering Department Microcontrollers and Embedded Systems Spring 2011 Jordan University of Science and Technology Electrical Engineering Department Microcontrollers and Embedded Systems Spring 2011 Microcontrollers andembedded Systems and and EE445 Embedded Embedded Microcontrollers

More information

Lesson 14. Title of the Experiment: Introduction to Microcontroller (Activity number of the GCE Advanced Level practical Guide 27)

Lesson 14. Title of the Experiment: Introduction to Microcontroller (Activity number of the GCE Advanced Level practical Guide 27) Lesson 14 Title of the Experiment: Introduction to Microcontroller (Activity number of the GCE Advanced Level practical Guide 27) Name and affiliation of the author: N W K Jayatissa Department of Physics,

More information

Lecture (04) PIC16F84A (3)

Lecture (04) PIC16F84A (3) Lecture (04) PIC16F84A (3) By: Dr. Ahmed ElShafee ١ Central Processing Unit Central processing unit (CPU) is the brain of a microcontroller responsible for finding and fetching the right instruction which

More information

Chapter 5 Sections 1 6 Dr. Iyad Jafar

Chapter 5 Sections 1 6 Dr. Iyad Jafar Building Assembler Programs Chapter 5 Sections 1 6 Dr. Iyad Jafar Outline Building Structured Programs Conditional Branching Subroutines Generating Time Delays Dealing with Data Example Programs 2 Building

More information

Dept. of Computer Engineering Final Exam, First Semester: 2016/2017

Dept. of Computer Engineering Final Exam, First Semester: 2016/2017 Philadelphia University Faculty of Engineering Course Title: Embedded Systems (630414) Instructor: Eng. Anis Nazer Dept. of Computer Engineering Final Exam, First Semester: 2016/2017 Student Name: Student

More information

16.317: Microprocessor Systems Design I Fall 2013 Exam 3 Solution

16.317: Microprocessor Systems Design I Fall 2013 Exam 3 Solution 16.317: Microprocessor Systems Design I Fall 2013 Exam 3 Solution 1. (20 points, 5 points per part) Multiple choice For each of the multiple choice questions below, clearly indicate your response by circling

More information

PIC Discussion. By Eng. Tamar Jomaa

PIC Discussion. By Eng. Tamar Jomaa PIC Discussion By Eng. Tamar Jomaa Chapter#2 Programming Microcontroller Using Assembly Language Quiz#1 : Time: 10 minutes Marks: 10 Fill in spaces: 1) PIC is abbreviation for 2) Microcontroller with..architecture

More information

The University of Texas at Arlington Lecture 5

The University of Texas at Arlington Lecture 5 The University of Texas at Arlington Lecture 5 CSE 3442/5442 LCD Discussed in Chapter 12 RS, R/W, E Signals Are Used to Send/Receive Data on D0-D7 2 PIC PROGRAMMING IN C CHAPTER 7 Chapter 7 discusses the

More information

Binary Outputs and Timing

Binary Outputs and Timing Binary Outputs and Timing Each of the I/O pins on a PIC can be inputs or ourputs As an input, the pin is high impedance (meaning it is passive and draws very little current). If you apply 0V to that pin,

More information

UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS : 2001/2002 RESIT. Year 2 MICROCONTROLLER SYSTEMS. Module Code: EEE305J1. Time allowed: 3 Hours

UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS : 2001/2002 RESIT. Year 2 MICROCONTROLLER SYSTEMS. Module Code: EEE305J1. Time allowed: 3 Hours UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS : 2001/2002 RESIT Year 2 MICROCONTROLLER SYSTEMS Module Code: EEE305J1 Time allowed: 3 Hours Answer as many questions as you can. Not more than TWO questions

More information

Chapter 4 Sections 1 4, 10 Dr. Iyad Jafar

Chapter 4 Sections 1 4, 10 Dr. Iyad Jafar Starting to Program Chapter 4 Sections 1 4, 10 Dr. Iyad Jafar Outline Introduction Program Development Process The PIC 16F84A Instruction Set Examples The PIC 16F84A Instruction Encoding Assembler Details

More information

Assembly Language Instructions

Assembly Language Instructions Assembly Language Instructions Content: Assembly language instructions of PIC16F887. Programming by assembly language. Prepared By- Mohammed Abdul kader Assistant Professor, EEE, IIUC Assembly Language

More information

LAB WORK 2. 1) Debugger-Select Tool-MPLAB SIM View-Program Memory Trace the program by F7 button. Lab Work

LAB WORK 2. 1) Debugger-Select Tool-MPLAB SIM View-Program Memory Trace the program by F7 button. Lab Work LAB WORK 1 We are studying with PIC16F84A Microcontroller. We are responsible for writing assembly codes for the microcontroller. For the code, we are using MPLAB IDE software. After opening the software,

More information

University of Jordan Faculty of Engineering and Technology Department of Computer Engineering Embedded Systems Laboratory

University of Jordan Faculty of Engineering and Technology Department of Computer Engineering Embedded Systems Laboratory University of Jordan Faculty of Engineering and Technology Department of Computer Engineering Embedded Systems Laboratory 0907334 6 Experiment 6:Timers Objectives To become familiar with hardware timing

More information

CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT. Spring 2006

CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT. Spring 2006 CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT Spring 2006 Recitation 01 21.02.2006 CEng336 1 OUTLINE LAB & Recitation Program PIC Architecture Overview PIC Instruction Set PIC Assembly Code Structure 21.02.2006

More information

ECE Test #1: Name

ECE Test #1: Name ECE 376 - Test #1: Name Closed Book, Closed Notes. Calculators Permitted. September 23, 2016 20 15 10 5 0

More information

EEE111A/B Microprocessors

EEE111A/B Microprocessors EEE111A/B Microprocessors Revision Notes Lecture 1: What s it all About? Covers the basic principles of digital signals. The intelligence of virtually all communications, control and electronic devices

More information

PIC 16F84A programming (II)

PIC 16F84A programming (II) Lecture (05) PIC 16F84A programming (II) Dr. Ahmed M. ElShafee ١ Introduction to 16F84 ٣ PIC16F84 belongs to a class of 8-bit microcontrollers of RISC architecture. Program memory (FLASH) EEPROM RAM PORTA

More information

TOPIC 3 INTRODUCTION TO PIC ASSEMBLY LANGUAGE. E4160 Microprocessor & Microcontroller System. Prepared by : Puziah Yahaya JKE, POLISAS / DEC 2010

TOPIC 3 INTRODUCTION TO PIC ASSEMBLY LANGUAGE. E4160 Microprocessor & Microcontroller System. Prepared by : Puziah Yahaya JKE, POLISAS / DEC 2010 TOPIC 3 INTRODUCTION TO PIC ASSEMBLY LANGUAGE Prepared by : Puziah Yahaya JKE, POLISAS / DEC 2010 E4160 Microprocessor & Microcontroller System Learning Outcomes 2 At the end of this topic, students should

More information

Input/Output Ports and Interfacing

Input/Output Ports and Interfacing Input/Output Ports and Interfacing ELEC 330 Digital Systems Engineering Dr. Ron Hayne Images Courtesy of Ramesh Gaonkar and Delmar Learning Basic I/O Concepts Peripherals such as LEDs and keypads are essential

More information

16.317: Microprocessor-Based Systems I Summer 2012

16.317: Microprocessor-Based Systems I Summer 2012 16.317: Microprocessor-Based Systems I Summer 2012 Exam 3 Solution 1. (20 points, 5 points per part) Multiple choice For each of the multiple choice questions below, clearly indicate your response by circling

More information

SOLAR TRACKING SYSTEM USING PIC16F84A STEPPER MOTOR AND 555TIMER

SOLAR TRACKING SYSTEM USING PIC16F84A STEPPER MOTOR AND 555TIMER SOLAR TRACKING SYSTEM USING PIC16F84A STEPPER MOTOR AND 555TIMER Amey Arvind Madgaonkar 1, Sumit Dhere 2 & Rupesh Ratnakar Kadam 3 1. Block diagram International Journal of Latest Trends in Engineering

More information

Timer2 Interrupts. NDSU Timer2 Interrupts September 20, Background:

Timer2 Interrupts. NDSU Timer2 Interrupts September 20, Background: Background: Timer2 Interrupts The execution time for routines sometimes needs to be set. This chapter loops at several ways to set the sampling rate. Example: Write a routine which increments an 8-bit

More information

UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS : 2001/2002. Semester 2. Year 2 MICROCONTROLLER SYSTEMS. Module Code: EEE305J2. Time allowed: 3 Hours

UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS : 2001/2002. Semester 2. Year 2 MICROCONTROLLER SYSTEMS. Module Code: EEE305J2. Time allowed: 3 Hours UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS : 2001/2002 Semester 2 Year 2 MICROCONTROLLER SYSTEMS Module Code: EEE305J2 Time allowed: 3 Hours Answer as many questions as you can. Not more than TWO questions

More information

Chapter 3: Further Microcontrollers

Chapter 3: Further Microcontrollers Chapter 3: Further Microcontrollers Learning Objectives: At the end of this topic you will be able to: recall and describe the structure of microcontrollers as programmable assemblies of: memory; input

More information

ECE Homework #3

ECE Homework #3 ECE 376 - Homework #3 Flow Charts, Binary Inputs, Binary Outputs (LEDs). Due Monday, January 29th The temperature sensor in your lab kits has the temperature-resistance relationship of R = 1000 exp 3965

More information

Learning Objectives:

Learning Objectives: Topic 5.2.1 PIC microcontrollers Learning Objectives: At the end of this topic you will be able to; Recall the architecture of a PIC microcontroller, consisting of CPU, clock, data memory, program memory

More information

Figure 1: Pushbutton without Pull-up.

Figure 1: Pushbutton without Pull-up. Chapter 7: Using the I/O pins as Inputs. In addition to working as outputs and being able to turn the I/O pins on and off, these same pins can be used as inputs. In this mode the PIC is able to determine

More information

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 5 Solution

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 5 Solution For each of the following complex operations, write a sequence of PIC 16F1829 instructions that performs an equivalent operation. Assume that X, Y, and Z are 16-bit values split into individual bytes as

More information

Physics 335 Intro to MicroControllers and the PIC Microcontroller

Physics 335 Intro to MicroControllers and the PIC Microcontroller Physics 335 Intro to MicroControllers and the PIC Microcontroller May 4, 2009 1 The Pic Microcontroller Family Here s a diagram of the Pic 16F84A, taken from Microchip s data sheet. Note that things are

More information

D:\PICstuff\PartCounter\PartCounter.asm

D:\PICstuff\PartCounter\PartCounter.asm 1 ;********************************************************************** 2 ; This file is a basic code template for assembly code generation * 3 ; on the PICmicro PIC16F84A. This file contains the basic

More information

When JP1 is cut, baud rate is Otherwise, baud rate is Factory default is that JP1 is shorted. (JP1 is jumper type in some model)

When JP1 is cut, baud rate is Otherwise, baud rate is Factory default is that JP1 is shorted. (JP1 is jumper type in some model) ELCD SERIES INTRODUCTION ALCD is Serial LCD module which is controlled through Serial communication. Most of existing LCD adopts Parallel communication which needs lots of control lines and complicated

More information

/ 40 Q3: Writing PIC / 40 assembly language TOTAL SCORE / 100 EXTRA CREDIT / 10

/ 40 Q3: Writing PIC / 40 assembly language TOTAL SCORE / 100 EXTRA CREDIT / 10 16.317: Microprocessor-Based Systems I Summer 2012 Exam 3 August 13, 2012 Name: ID #: Section: For this exam, you may use a calculator and one 8.5 x 11 double-sided page of notes. All other electronic

More information

Done 1 NVB THF TLF T/R POL 1SHOT. Figure 1: Status register

Done 1 NVB THF TLF T/R POL 1SHOT. Figure 1: Status register Introduction to Microprocessors Feisal Mohammed 12th January 2001 Mini-project This project is to implement a temperature monitor using the PicStic4, the DS1821 temperature sensor and a LCD display. The

More information

CHAPTER 6 CONCLUSION AND SCOPE FOR FUTURE WORK

CHAPTER 6 CONCLUSION AND SCOPE FOR FUTURE WORK 134 CHAPTER 6 CONCLUSION AND SCOPE FOR FUTURE WORK 6.1 CONCLUSION Many industrial processes such as assembly lines have to operate at different speeds for different products. Process control may demand

More information

Chapter 11: Interrupt On Change

Chapter 11: Interrupt On Change Chapter 11: Interrupt On Change The last two chapters included examples that used the external interrupt on Port C, pin 1 to determine when a button had been pressed. This approach works very well on most

More information

Performance & Applications

Performance & Applications EE25M Introduction to microprocessors original author: Feisal Mohammed updated: 15th March 2002 CLR Part VI Performance & Applications It is possible to predict the execution time of code, on the basis

More information

Mechatronics and Measurement. Lecturer:Dung-An Wang Lecture 6

Mechatronics and Measurement. Lecturer:Dung-An Wang Lecture 6 Mechatronics and Measurement Lecturer:Dung-An Wang Lecture 6 Lecture outline Reading:Ch7 of text Today s lecture: Microcontroller 2 7.1 MICROPROCESSORS Hardware solution: consists of a selection of specific

More information

Interfacing PIC Microcontrollers. ADC8BIT2 Schematic. This application demonstrates analogue input sampling

Interfacing PIC Microcontrollers. ADC8BIT2 Schematic. This application demonstrates analogue input sampling Interfacing PIC Microcontrollers ADC8BIT2 Schematic This application demonstrates analogue input sampling A manually adjusted test voltage 0-5V is provided at AN0 input A reference voltage of 2.56V is

More information

SOLUTIONS!! DO NOT DISTRIBUTE PRIOR TO EXAM!!

SOLUTIONS!! DO NOT DISTRIBUTE PRIOR TO EXAM!! THE UNIVERSITY OF THE WEST INDIES EXAMINATIONS OF APRIL MID-TERM 2005 Code and Name of Course: EE25M Introduction to Microprocessors Paper: MidTerm Date and Time: Thursday April 14th 2005 8AM Duration:

More information

PIC Architecture & Assembly Language Programming. Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

PIC Architecture & Assembly Language Programming. Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan PIC Architecture & Assembly Language Programming Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan chanhl@mail.cgu.edu.tw ALU with working register (WREG) and literal value 2 MOVLW

More information

Weekly Report: Interactive Wheel of Fortune Week 4 02/014/07-02/22/07 Written by: Yadverinder Singh

Weekly Report: Interactive Wheel of Fortune Week 4 02/014/07-02/22/07 Written by: Yadverinder Singh Work Completed: Weekly Report: Interactive Wheel of Fortune Week 4 02/014/07-02/22/07 Written by: Yadverinder Singh Last week started with the goal to complete writing the overall program for the game.

More information

EXPERIMENT 4: Parallel Input/Output. Objectives Introduction to the Parallel Input/Output (I/O) Familiarization to Interfacing

EXPERIMENT 4: Parallel Input/Output. Objectives Introduction to the Parallel Input/Output (I/O) Familiarization to Interfacing EXPERIMENT 4: Parallel Input/Output Objectives Introduction to the Parallel Input/Output (I/O) Familiarization to Interfacing Components' List: 1. Protoboard 2. 4 x pushbutton 3. 4 x 330Ω resistor 4. 4

More information

Instuction set

Instuction set Instuction set http://www.piclist.com/images/www/hobby_elec/e_pic3_1.htm#1 In PIC16 series, RISC(Reduced Instruction Set Computer) is adopted and the number of the instructions to use is 35 kinds. When

More information

ALU and Arithmetic Operations

ALU and Arithmetic Operations EE25M Introduction to microprocessors original author: Feisal Mohammed updated: 6th February 2002 CLR Part IV ALU and Arithmetic Operations There are several issues connected with the use of arithmetic

More information

Lesson 4 Fun with W and F

Lesson 4 Fun with W and F Elmer 160 Lesson 4 Overview Lesson 4 Introduction In this section This lesson introduces the first few PIC instructions. The following is a list of topics in this section: Description See Page Writing

More information

Application Note - PIC Source Code v1.1.doc

Application Note - PIC Source Code v1.1.doc Programmable, RGB-backlit LCD Keyswitches APPLICATION NOTE PIC SOURCE CODE 2004-2006 copyright [E³] Engstler Elektronik Entwicklung GmbH. All rights reserved. PIC Source Code The following Assembler source

More information

Micro II and Embedded Systems

Micro II and Embedded Systems 16.480/552 Micro II and Embedded Systems Introduction to PIC Microcontroller Revised based on slides from WPI ECE2801 Moving Towards Embedded Hardware Typical components of a PC: x86 family microprocessor

More information

Embedded Systems Programming and Architectures

Embedded Systems Programming and Architectures Embedded Systems Programming and Architectures Lecture No 10 : Data acquisition and data transfer Dr John Kalomiros Assis. Professor Department of Post Graduate studies in Communications and Informatics

More information

Arithmetic and Logic Instructions. Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

Arithmetic and Logic Instructions. Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan Arithmetic and Logic Instructions Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan chanhl@mail.cgu.edu.tw Find the sum of the values from 40H to 43H. Put the sum in filereg locations

More information

ME 515 Mechatronics. A microprocessor

ME 515 Mechatronics. A microprocessor ME 515 Mechatronics Microcontroller Based Control of Mechanical Systems Asanga Ratnaweera Department of Faculty of Engineering University of Peradeniya Tel: 081239 (3627) Email: asangar@pdn.ac.lk A microprocessor

More information

Week1. EEE305 Microcontroller Key Points

Week1. EEE305 Microcontroller Key Points Week1 Harvard Architecture Fig. 3.2 Separate Program store and Data (File) stores with separate Data and Address buses. Program store Has a 14-bit Data bus and 13-bit Address bus. Thus up to 2 13 (8K)

More information

16.317: Microprocessor-Based Systems I Spring 2012

16.317: Microprocessor-Based Systems I Spring 2012 16.317: Microprocessor-Based Systems I Spring 2012 Exam 3 Solution 1. (20 points, 5 points per part) Multiple choice For each of the multiple choice questions below, clearly indicate your response by circling

More information

Laboratory Exercise 5 - Analog to Digital Conversion

Laboratory Exercise 5 - Analog to Digital Conversion Laboratory Exercise 5 - Analog to Digital Conversion The purpose of this lab is to control the blinking speed of an LED through the Analog to Digital Conversion (ADC) module on PIC16 by varying the input

More information

SOLUTIONS!! DO NOT DISTRIBUTE!!

SOLUTIONS!! DO NOT DISTRIBUTE!! THE UNIVERSITY OF THE WEST INDIES EXAMINATIONS OF FEBRUARY MID-TERM 2005 Code and Name of Course: EE25M Introduction to Microprocessors Paper: Date and Time: Duration: One Hour INSTRUCTIONS TO CANDIDATES:

More information

LPTCOM. Bruce Misner Lakehead University h d3 RD2 pin 21. RD3 pin h d4. RD4 pin 27 RD5 pin h d5. RD6 pin 29 RD7 pin H d6

LPTCOM. Bruce Misner Lakehead University h d3 RD2 pin 21. RD3 pin h d4. RD4 pin 27 RD5 pin h d5. RD6 pin 29 RD7 pin H d6 LPTCOM By Bruce Misner Lakehead University LPTCOM is a demonstration of a robust bi-directional communcation between the PIC microcontroller and the printer port of your PC. Incorporating more handshaking

More information

Locktronics PICmicro getting started guide

Locktronics PICmicro getting started guide Page 2 getting started guide What you need to follow this course 2 Using the built-in programs 3 Create your own programs 4 Using Flowcode - your first program 5 A second program 7 A third program 8 Other

More information

The University of Texas at Arlington Lecture 3

The University of Texas at Arlington Lecture 3 The University of Texas at Arlington Lecture 3 CSE 3442/5442 Tuesday, We Began Chapter 2, Architecture & Assembly Language Programming, Introduced the PIC WREG (Working Register) 8 bit register in PIC

More information

Arithmetic,logic Instruction and Programs

Arithmetic,logic Instruction and Programs Arithmetic,logic Instruction and Programs 1 Define the range of numbers possible in PIC unsigned data Code addition and subtraction instructions for unsigned data Perform addition of BCD Code PIC unsigned

More information

Hardware Interfacing. EE25M Introduction to microprocessors. Part V. 15 Interfacing methods. original author: Feisal Mohammed

Hardware Interfacing. EE25M Introduction to microprocessors. Part V. 15 Interfacing methods. original author: Feisal Mohammed EE25M Introduction to microprocessors original author: Feisal Mohammed updated: 18th February 2002 CLR Part V Hardware Interfacing There are several features of computers/microcontrollers which have not

More information

Outlines. PIC Programming in C and Assembly. Krerk Piromsopa, Ph.D. Department of Computer Engineering Chulalongkorn University

Outlines. PIC Programming in C and Assembly. Krerk Piromsopa, Ph.D. Department of Computer Engineering Chulalongkorn University PIC ming in C and Assembly Outlines Microprocessor vs. MicroController PIC in depth PIC ming Assembly ming Krerk Piromsopa, Ph.D. Department of Computer Engineering Chulalongkorn University Embedded C

More information

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING. EE6008 Microcontroller based system design

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING. EE6008 Microcontroller based system design Year: IV DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING EE6008 Microcontroller based system design Semester : VII UNIT I Introduction to PIC Microcontroller

More information

APPLICATION NOTE 2361 Interfacing an SPI-Interface RTC with a PIC Microcontroller

APPLICATION NOTE 2361 Interfacing an SPI-Interface RTC with a PIC Microcontroller Maxim/Dallas > App Notes > REAL-TIME CLOCKS Keywords: DS1305, SPI, PIC, real time clock, RTC, spi interface, pic microcontroller Aug 20, 2003 APPLICATION NOTE 2361 Interfacing an SPI-Interface RTC with

More information

PART TWO LISTING 8 PROGRAM TK3TUT8 MOVF PORTA,W ANDLW B ADDWF COUNT,F MOVF COUNT,W MOVWF PORTB GOTO LOOP

PART TWO LISTING 8 PROGRAM TK3TUT8 MOVF PORTA,W ANDLW B ADDWF COUNT,F MOVF COUNT,W MOVWF PORTB GOTO LOOP EPE PIC TUTORIAL V2 JOHN BECKER PART TWO Quite simply the easiest low-cost way to learn about using PIC Microcontrollers! EPE PIC TUTORIAL In this part we play with switches, make noises, count times,

More information

DERTS Design Requirements (1): Microcontroller Architecture & Programming

DERTS Design Requirements (1): Microcontroller Architecture & Programming Lecture (5) DERTS Design Requirements (1): Microcontroller Architecture & Programming Prof. Kasim M. Al-Aubidy Philadelphia University 1 Lecture Outline: Features of microcomputers and microcontrollers.

More information

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING. EE Microcontroller Based System Design

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING. EE Microcontroller Based System Design DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING EE6008 - Microcontroller Based System Design UNIT III PERIPHERALS AND INTERFACING PART A 1. What is an

More information

Programmable Control. Name Class Teacher. Ellon Academy Technical Faculty

Programmable Control. Name Class Teacher. Ellon Academy Technical Faculty Programmable Control Name Class Teacher Ellon Academy Technical Faculty Learning Intentions o Gain the ability to design and evaluate solutions to engineering problems in a range of contexts o I will gain

More information

ME 6405 Introduction to Mechatronics

ME 6405 Introduction to Mechatronics ME 6405 Introduction to Mechatronics Fall 2006 Instructor: Professor Charles Ume Microchip PIC Manufacturer Information: Company: Website: http://www.microchip.com Reasons for success: Became the hobbyist's

More information

DISCONTINUED. SPI Communication with AMT bit Absolute Encoder

DISCONTINUED. SPI Communication with AMT bit Absolute Encoder ApplicAtion note An-1001 SPI Communication with AMT203 12-bit Absolute Encoder introduction This application note is designed to provide guidelines on how to properly interface with the AMT 203 Absolute

More information

CENG-336 Introduction to Embedded Systems Development. Timers

CENG-336 Introduction to Embedded Systems Development. Timers CENG-336 Introduction to Embedded Systems Development Timers Definitions A counter counts (possibly asynchronous) input pulses from an external signal A timer counts pulses of a fixed, known frequency

More information

EE6008-Microcontroller Based System Design Department Of EEE/ DCE

EE6008-Microcontroller Based System Design Department Of EEE/ DCE UNIT- II INTERRUPTS AND TIMERS PART A 1. What are the interrupts available in PIC? (Jan 14) Interrupt Source Enabled by Completion Status External interrupt from INT INTE = 1 INTF = 1 TMR0 interrupt T0IE

More information

Explanation of PIC 16F84A processor data sheet Part 1: overview of the basics

Explanation of PIC 16F84A processor data sheet Part 1: overview of the basics Explanation of PIC 16F84A processor data sheet Part 1: overview of the basics This report is the first of a three part series that discusses the features of the PIC 16F94A processor. The reports will refer

More information

EEE111A/B Microprocessors

EEE111A/B Microprocessors EEE111A/B Microprocessors Lecture 10: C for Microcontroller Programmers 1 Objectives To understand the differences between a high-level language and assembly language. To review the elements of programming

More information

A Better Mouse Trap. Consumer Appliance, Widget, Gadget APPLICATION OPERATION: Ontario, Canada

A Better Mouse Trap. Consumer Appliance, Widget, Gadget APPLICATION OPERATION: Ontario, Canada A Better Mouse Trap Author: APPLICATION OPERATION: My application uses a PIC12C508 to produce realistic sounding mouse-like coos that all mice are sure to find seductive. The entire circuit should be imbedded

More information

movwf prevcod ; a new button is pressed - rcnt=3 movwf (mtx_buffer+1) movlw 3 movwf rcnt

movwf prevcod ; a new button is pressed - rcnt=3 movwf (mtx_buffer+1) movlw 3 movwf rcnt movlw 0x20 #endif call scan movlw 0xfd tris PORTB ; select colb (RB1) #ifdef MODE_CH8 movlw 0x04 #endif #ifdef MODE_CH4 movlw 0x30 #endif call scan movf cod, W bz loop2 ; if no buton is pressed, skip subwf

More information

Lesson 7 Multiple Precision Arithmetic

Lesson 7 Multiple Precision Arithmetic Elmer 160 Lesson 7 Overview Lesson 7 In this section The PIC stores data as 8-bit bytes. Up until now, we have only used values of 8 bits or less. But what if we have a greater range of values? In this

More information

Embedded Systems Design (630470) Lecture 4. Memory Organization. Prof. Kasim M. Al-Aubidy Computer Eng. Dept.

Embedded Systems Design (630470) Lecture 4. Memory Organization. Prof. Kasim M. Al-Aubidy Computer Eng. Dept. Embedded Systems Design (630470) Lecture 4 Memory Organization Prof. Kasim M. Al-Aubidy Computer Eng. Dept. Memory Organization: PIC16F84 has two separate memory blocks, for data and for program. EEPROM

More information

More (up a level)... Connecting the Nokia 3510i LCD to a Microchip PIC16F84 microcontroller

More (up a level)... Connecting the Nokia 3510i LCD to a Microchip PIC16F84 microcontroller 1 von 8 24.02.2010 21:53 More (up a level)... Connecting the Nokia 3510i LCD to a Microchip PIC16F84 microcontroller As with the FPGA board previously, the connections are made by soldering standard IDC

More information

Outline. Micriprocessor vs Microcontroller Introduction to PIC MCU PIC16F877 Hardware:

Outline. Micriprocessor vs Microcontroller Introduction to PIC MCU PIC16F877 Hardware: HCMIU - DEE Subject: ERTS RISC MCU Architecture PIC16F877 Hardware 1 Outline Micriprocessor vs Microcontroller Introduction to PIC MCU PIC16F877 Hardware: Program Memory Data memory organization: banks,

More information

/* PROGRAM FOR BLINKING LEDs CONEECTED TO PORT-D */

/* PROGRAM FOR BLINKING LEDs CONEECTED TO PORT-D */ /* PROGRAM FOR BLINKING LEDs CONEECTED TO PORT-D */ CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF ;***** VARIABLE DEFINITIONS COUNT_L EQU 0x01 ;**********************************************************************

More information

which means that writing to a port implies that the port pins are first read, then this value is modified and then written to the port data latch.

which means that writing to a port implies that the port pins are first read, then this value is modified and then written to the port data latch. Introduction to microprocessors Feisal Mohammed 3rd January 2001 Additional features 1 Input/Output Ports One of the features that differentiates a microcontroller from a microprocessor is the presence

More information

APPLICATION NOTE Wire Communication with a Microchip PICmicro Microcontroller

APPLICATION NOTE Wire Communication with a Microchip PICmicro Microcontroller Maxim > App Notes > 1-Wire DEVICES BATTERY MANAGEMENT Keywords: 1-wire, PICmicro, Microchip PIC, 1-Wire communication, PIC microcontroller, PICmicro microcontroller, 1 wire communication, PICs, micros,

More information

EE 367 Introduction to Microprocessors Homework 6

EE 367 Introduction to Microprocessors Homework 6 EE 367 Introduction to Microprocessors Homework 6 Due Wednesday, March 13, 2019 Announcements: Midterm on March 27 th The exam will cover through Lecture notes, Part 6; Lab 3, Homework 6, and readings

More information

Chapter 3 BRANCH, CALL, AND TIME DELAY LOOP

Chapter 3 BRANCH, CALL, AND TIME DELAY LOOP Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 3022: Embedded Systems Discussion Chapter 3 BRANCH, CALL, AND TIME DELAY LOOP Eng. Eman R. Habib February, 2014 2 Embedded

More information

Introduction. Embedded system functionality aspects. Processing. Storage. Communication. Transformation of data Implemented using processors

Introduction. Embedded system functionality aspects. Processing. Storage. Communication. Transformation of data Implemented using processors Input/Output 1 Introduction Embedded system functionality aspects Processing Transformation of data Implemented using processors Storage Retention of data Implemented using memory Communication Transfer

More information

Chapter 5. Problems All programming problems should include design pseudo code either as a separate design document on embedded comments in the code.

Chapter 5. Problems All programming problems should include design pseudo code either as a separate design document on embedded comments in the code. Chapter 5. Problems All programming problems should include design pseudo code either as a separate design document on embedded comments in the code. 1S. Prior to execution of the following code segment,

More information

ECE 354 Introduction to Lab 2. February 23 rd, 2003

ECE 354 Introduction to Lab 2. February 23 rd, 2003 ECE 354 Introduction to Lab 2 February 23 rd, 2003 Fun Fact Press release from Microchip: Microchip Technology Inc. announced it provides PICmicro field-programmable microcontrollers and system supervisors

More information

Professor E. Ambikairajah UNSW Sydney

Professor E. Ambikairajah UNSW Sydney ELEC2117 Chapter 3a: PIC16F886 Instruction set Professor Eliathamby Ambikairajah Head of School of Electrical Engineering and Telecommunications, UNSW, Sydney 06 March 2017 Prof E Ambikairajah Instruction

More information

AN587. Interfacing to an LCD Module. Interfacing to an LCD Module INTRODUCTION OPERATION CONTROL SIGNAL FUNCTIONS TABLE 2: CONDITIONAL ASSEMBLY FLAGS

AN587. Interfacing to an LCD Module. Interfacing to an LCD Module INTRODUCTION OPERATION CONTROL SIGNAL FUNCTIONS TABLE 2: CONDITIONAL ASSEMBLY FLAGS Interfacing to an LCD Module AN587 INTRODUCTION TABLE 1: CONTROL SIGNAL FUNCTIONS This application note interfaces a PIC16CXX device to the Hitachi LM02L LCD character display module. This module is a

More information

PIC16F87X 13.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS

PIC16F87X 13.0 INSTRUCTION SET SUMMARY INSTRUCTIONS DESCRIPTIONS PIC6F87X 3.0 INSTRUCTION SET SUMMARY Each PIC6F87X instruction is a 4bit word, divided into an OPCODE which specifies the instruction type and one or more operands which further specify the operation of

More information

Laboratory: Introduction to Mechatronics. Instructor TA: Edgar Martinez Soberanes Lab 2. PIC and Programming

Laboratory: Introduction to Mechatronics. Instructor TA: Edgar Martinez Soberanes Lab 2. PIC and Programming Laboratory: Introduction to Mechatronics Instructor TA: Edgar Martinez Soberanes (eem370@mail.usask.ca) 2015-01-12 Lab 2. PIC and Programming Lab Sessions Lab 1. Introduction Read manual and become familiar

More information

Interrupts. ELEC 330 Digital Systems Engineering Dr. Ron Hayne. Images Courtesy of Ramesh Gaonkar and Delmar Learning

Interrupts. ELEC 330 Digital Systems Engineering Dr. Ron Hayne. Images Courtesy of Ramesh Gaonkar and Delmar Learning Interrupts ELEC 330 Digital Systems Engineering Dr. Ron Hayne Images Courtesy of Ramesh Gaonkar and Delmar Learning Basic Concepts of Interrupts An interrupt is a communication process A device Requests

More information

ECE 354 Computer Systems Lab II. Interrupts, Strings, and Busses

ECE 354 Computer Systems Lab II. Interrupts, Strings, and Busses ECE 354 Computer Systems Lab II Interrupts, Strings, and Busses Fun Fact Press release from Microchip: Microchip Technology Inc. announced it provides PICmicro field-programmable microcontrollers and system

More information

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet... 4

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet... 4 Overview of the PIC 16F648A Processor: Part 1 EE 361L Lab 2.1 Last update: August 1, 2016 Abstract: This report is the first of a three part series that discusses the features of the PIC 16F648A processor,

More information

Getting Started Guide

Getting Started Guide Introduction Flowcode is an Integrated Development Environment (IDE) for programming microcontrollers such as 8, 16 and 32bit PIC, Arduino and ARM devices. It achieves this by using flowcharts instead

More information

How Stuff Works: Processors

How Stuff Works: Processors How Stuff Works: Processors Principles and Examples Joe Finney joe@comp.lancs.ac.uk Aims Today we re going to Discuss the purpose for Assembly Language Review the common principles on which Assembly Languages

More information

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet Example Application...

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet Example Application... Overview of the PIC 16F648A Processor: Part 1 EE 361L Lab 2.1 Last update: August 19, 2011 Abstract: This report is the first of a three part series that discusses the features of the PIC 16F684A processor,

More information