Upload
others
View
12
Download
0
Embed Size (px)
Citation preview
CENG 314Embedded Computer Systems
Lecture 6BProgramming PIC Microcontrollers
Asst. Prof. Tolga Ayav, Ph.D.
Department of Computer Engineeringİzmir Institute of Technology
Developing a Simple Project
Inside 16 series
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:
Assembler Directives
Number Representation
MPLAB ToolSuite
Create a Simple
Program:
Data Move
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.
SimulationDownload and open first.mcpCompileSimulate from menu:− Debugger− Stimulus− Open …
Building Assembly Programs
Flow diagram of simple refrigerator
controller
Here the program will loop indefinitely. This is called super-loop.Why do we need this loop?
Washing Machine Control Program:Using State Machine Approach
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
Data Move program with Bit Manipulations
Generating Time Delays (using subroutines: call - return)
Look-up Tables
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.
Use least square error method to fit a parabola tothe given three points…Write down the convert_temperature() function