lecture 6b programming pic...
TRANSCRIPT
![Page 1: Lecture 6B Programming PIC Microcontrollersweb.iyte.edu.tr/~tolgaayav/courses/ceng314/lecture6B.pdf · PIC16 Instructions z 35 instructions −f for file (i.e. memory location in](https://reader034.vdocuments.mx/reader034/viewer/2022050121/5f510750dd25a02aea6f2b7d/html5/thumbnails/1.jpg)
CENG 314Embedded Computer Systems
Lecture 6BProgramming PIC Microcontrollers
Asst. Prof. Tolga Ayav, Ph.D.
Department of Computer Engineeringİzmir Institute of Technology
![Page 2: Lecture 6B Programming PIC Microcontrollersweb.iyte.edu.tr/~tolgaayav/courses/ceng314/lecture6B.pdf · PIC16 Instructions z 35 instructions −f for file (i.e. memory location in](https://reader034.vdocuments.mx/reader034/viewer/2022050121/5f510750dd25a02aea6f2b7d/html5/thumbnails/2.jpg)
Developing a Simple Project
![Page 3: Lecture 6B Programming PIC Microcontrollersweb.iyte.edu.tr/~tolgaayav/courses/ceng314/lecture6B.pdf · PIC16 Instructions z 35 instructions −f for file (i.e. memory location in](https://reader034.vdocuments.mx/reader034/viewer/2022050121/5f510750dd25a02aea6f2b7d/html5/thumbnails/3.jpg)
Inside 16 series
![Page 4: Lecture 6B Programming PIC Microcontrollersweb.iyte.edu.tr/~tolgaayav/courses/ceng314/lecture6B.pdf · PIC16 Instructions z 35 instructions −f for file (i.e. memory location in](https://reader034.vdocuments.mx/reader034/viewer/2022050121/5f510750dd25a02aea6f2b7d/html5/thumbnails/4.jpg)
PIC16 Instructions
35 instructions− f for file (i.e. memory location in RAM), a 7-bit number− b for bit, to be found within a file also specified, a 3-bit number− d for destination, as described above, a single bit− k for literal, an 8-bit number if data or 11-bit if address.
Assembler format:
![Page 5: Lecture 6B Programming PIC Microcontrollersweb.iyte.edu.tr/~tolgaayav/courses/ceng314/lecture6B.pdf · PIC16 Instructions z 35 instructions −f for file (i.e. memory location in](https://reader034.vdocuments.mx/reader034/viewer/2022050121/5f510750dd25a02aea6f2b7d/html5/thumbnails/5.jpg)
Assembler Directives
![Page 6: Lecture 6B Programming PIC Microcontrollersweb.iyte.edu.tr/~tolgaayav/courses/ceng314/lecture6B.pdf · PIC16 Instructions z 35 instructions −f for file (i.e. memory location in](https://reader034.vdocuments.mx/reader034/viewer/2022050121/5f510750dd25a02aea6f2b7d/html5/thumbnails/6.jpg)
Number Representation
![Page 7: Lecture 6B Programming PIC Microcontrollersweb.iyte.edu.tr/~tolgaayav/courses/ceng314/lecture6B.pdf · PIC16 Instructions z 35 instructions −f for file (i.e. memory location in](https://reader034.vdocuments.mx/reader034/viewer/2022050121/5f510750dd25a02aea6f2b7d/html5/thumbnails/7.jpg)
MPLAB ToolSuite
![Page 8: Lecture 6B Programming PIC Microcontrollersweb.iyte.edu.tr/~tolgaayav/courses/ceng314/lecture6B.pdf · PIC16 Instructions z 35 instructions −f for file (i.e. memory location in](https://reader034.vdocuments.mx/reader034/viewer/2022050121/5f510750dd25a02aea6f2b7d/html5/thumbnails/8.jpg)
Create a Simple
Program:
Data Move
![Page 9: Lecture 6B Programming PIC Microcontrollersweb.iyte.edu.tr/~tolgaayav/courses/ceng314/lecture6B.pdf · PIC16 Instructions z 35 instructions −f for file (i.e. memory location in](https://reader034.vdocuments.mx/reader034/viewer/2022050121/5f510750dd25a02aea6f2b7d/html5/thumbnails/9.jpg)
Assembly Commands used in Data Move Application
clrf f – this clears to zero the value in memory location fmovwf f – this moves the contents of the W register to the memory location fmovf f,d – this instruction moves the contents of the memory location f to the W register, if the d bit is set to 0; if it is set to 1,then the contents of f are just returned to fmovlw k – this instruction moves the literal value k, an 8-bit number which accompanies the instruction, into the W registerbcf f,b – this clears (i.e. sets to Logic 0) the bit b in memory location fbsf f,b – this sets to Logic 1 the bit b in memory location fgoto k – this transfers program execution to the instruction in memory location k.
![Page 10: Lecture 6B Programming PIC Microcontrollersweb.iyte.edu.tr/~tolgaayav/courses/ceng314/lecture6B.pdf · PIC16 Instructions z 35 instructions −f for file (i.e. memory location in](https://reader034.vdocuments.mx/reader034/viewer/2022050121/5f510750dd25a02aea6f2b7d/html5/thumbnails/10.jpg)
SimulationDownload and open first.mcpCompileSimulate from menu:− Debugger− Stimulus− Open …
![Page 11: Lecture 6B Programming PIC Microcontrollersweb.iyte.edu.tr/~tolgaayav/courses/ceng314/lecture6B.pdf · PIC16 Instructions z 35 instructions −f for file (i.e. memory location in](https://reader034.vdocuments.mx/reader034/viewer/2022050121/5f510750dd25a02aea6f2b7d/html5/thumbnails/11.jpg)
Building Assembly Programs
![Page 12: Lecture 6B Programming PIC Microcontrollersweb.iyte.edu.tr/~tolgaayav/courses/ceng314/lecture6B.pdf · PIC16 Instructions z 35 instructions −f for file (i.e. memory location in](https://reader034.vdocuments.mx/reader034/viewer/2022050121/5f510750dd25a02aea6f2b7d/html5/thumbnails/12.jpg)
Flow diagram of simple refrigerator
controller
Here the program will loop indefinitely. This is called super-loop.Why do we need this loop?
![Page 13: Lecture 6B Programming PIC Microcontrollersweb.iyte.edu.tr/~tolgaayav/courses/ceng314/lecture6B.pdf · PIC16 Instructions z 35 instructions −f for file (i.e. memory location in](https://reader034.vdocuments.mx/reader034/viewer/2022050121/5f510750dd25a02aea6f2b7d/html5/thumbnails/13.jpg)
Washing Machine Control Program:Using State Machine Approach
![Page 14: Lecture 6B Programming PIC Microcontrollersweb.iyte.edu.tr/~tolgaayav/courses/ceng314/lecture6B.pdf · PIC16 Instructions z 35 instructions −f for file (i.e. memory location in](https://reader034.vdocuments.mx/reader034/viewer/2022050121/5f510750dd25a02aea6f2b7d/html5/thumbnails/14.jpg)
Flow ControlConditional Branching and Working with Bits
We use status register’s bits for conditional branching.
Or any other bits:btfsc f,b : Tests bit b in memory location f and skips just one instruction if the bit is set
btfss f,b : Skips if the tested bit is clearWe use two commands to set and clear bits:− bsf f,b− bcf f,b
![Page 15: Lecture 6B Programming PIC Microcontrollersweb.iyte.edu.tr/~tolgaayav/courses/ceng314/lecture6B.pdf · PIC16 Instructions z 35 instructions −f for file (i.e. memory location in](https://reader034.vdocuments.mx/reader034/viewer/2022050121/5f510750dd25a02aea6f2b7d/html5/thumbnails/15.jpg)
Data Move program with Bit Manipulations
![Page 16: Lecture 6B Programming PIC Microcontrollersweb.iyte.edu.tr/~tolgaayav/courses/ceng314/lecture6B.pdf · PIC16 Instructions z 35 instructions −f for file (i.e. memory location in](https://reader034.vdocuments.mx/reader034/viewer/2022050121/5f510750dd25a02aea6f2b7d/html5/thumbnails/16.jpg)
Generating Time Delays (using subroutines: call - return)
![Page 17: Lecture 6B Programming PIC Microcontrollersweb.iyte.edu.tr/~tolgaayav/courses/ceng314/lecture6B.pdf · PIC16 Instructions z 35 instructions −f for file (i.e. memory location in](https://reader034.vdocuments.mx/reader034/viewer/2022050121/5f510750dd25a02aea6f2b7d/html5/thumbnails/17.jpg)
Look-up Tables
![Page 18: Lecture 6B Programming PIC Microcontrollersweb.iyte.edu.tr/~tolgaayav/courses/ceng314/lecture6B.pdf · PIC16 Instructions z 35 instructions −f for file (i.e. memory location in](https://reader034.vdocuments.mx/reader034/viewer/2022050121/5f510750dd25a02aea6f2b7d/html5/thumbnails/18.jpg)
Case Study: Thermocouple Linearization
The room temperature is read using J type thermocouple. The temperature will be shown on 7-segment displays. Write the appropriate program in C. Assume that read_sensor() returns 0-4096 for 0-2mV and write_display(num) updates 7-segments.
![Page 19: Lecture 6B Programming PIC Microcontrollersweb.iyte.edu.tr/~tolgaayav/courses/ceng314/lecture6B.pdf · PIC16 Instructions z 35 instructions −f for file (i.e. memory location in](https://reader034.vdocuments.mx/reader034/viewer/2022050121/5f510750dd25a02aea6f2b7d/html5/thumbnails/19.jpg)
![Page 20: Lecture 6B Programming PIC Microcontrollersweb.iyte.edu.tr/~tolgaayav/courses/ceng314/lecture6B.pdf · PIC16 Instructions z 35 instructions −f for file (i.e. memory location in](https://reader034.vdocuments.mx/reader034/viewer/2022050121/5f510750dd25a02aea6f2b7d/html5/thumbnails/20.jpg)
Use least square error method to fit a parabola tothe given three points…Write down the convert_temperature() function