+ All Categories
Home > Documents > Lecture 6B Programming PIC...

Lecture 6B Programming PIC...

Date post: 17-Jul-2020
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
20
CENG 314 Embedded Computer Systems Lecture 6B Programming PIC Microcontrollers Asst. Prof. Tolga Ayav, Ph.D. Department of Computer Engineering İzmir Institute of Technology
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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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
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

Use least square error method to fit a parabola tothe given three points…Write down the convert_temperature() function


Recommended