100% found this document useful (3 votes)
244 views64 pages

Pic 16f

The document discusses microcontrollers and the PIC16F877 microcontroller. It describes how a microcontroller contains a processor, memory, and input/output on a single chip. It explains the different types of memory in a microcontroller and how the PIC16F877 uses Flash ROM for program memory. It provides details on the architecture and instruction set of the PIC16F877 microcontroller.

Uploaded by

Dhanesh Murali
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
244 views64 pages

Pic 16f

The document discusses microcontrollers and the PIC16F877 microcontroller. It describes how a microcontroller contains a processor, memory, and input/output on a single chip. It explains the different types of memory in a microcontroller and how the PIC16F877 uses Flash ROM for program memory. It provides details on the architecture and instruction set of the PIC16F877 microcontroller.

Uploaded by

Dhanesh Murali
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 64

Dept.

of ECE RSET

Rajagiri School of Engineering & Technology

8th Feb 2013

The microcontroller is simply a computer on a chip. It is one of the most important developments in electronics since the invention of the microprocessor itself. It is essential for the operation of devices such as mobile phones, DVD players, video cameras, and most self-contained electronic systems

Rajagiri School of Engineering & Technology

8th Feb 2013

The microcontroller contains the same main elements as any computer system: Processor Memory Input/output Block diagram of a basic microprocessor system

Rajagiri School of Engineering & Technology

8th Feb 2013

In a PC, these are provided as separate chips, linked together via bus connections on a printed circuit board, but under the control of the microprocessor (CPU).

Rajagiri School of Engineering & Technology

8th Feb 2013

In the microcontroller, all these elements are on one chip. In any given circuit, the microcontroller also tends to have a single dedicated function (in contrast to the PC).

Rajagiri School of Engineering & Technology

8th Feb 2013

The processor cannot operate without a program, which is a list of instructions that is held in memory. The program consists of a sequence of binary codes that are fetched from memory by the CPU in sequence, and executed.

Rajagiri School of Engineering & Technology

8th Feb 2013

There are two types of memory: volatile and non-volatile. Volatile memory loses its data when switched off, but can be written by the CPU to store current data; this is RAM (Random Access Memory). ROM (Read Only Memory) is non-volatile, and retains its data when switched off. Flash ROM, as used in memory sticks and MP3 players, is closest to the ideal, having the advantages of being nonvolatile and rewritable. This is why it is used as program memory in microcontrollers which need to be reprogrammed, such as the PIC 16F877.

Rajagiri School of Engineering & Technology

8th Feb 2013

Without some means of getting information and signals in and out, a data processing or digital control system would not be very useful. Ports are based on a data register, and set of control registers, which pass the data in and out in a controlled manner, often according to a standard protocol (method of communication). Parallel and serial data ports: (a) parallel; (b) serial

Rajagiri School of Engineering & Technology

8th Feb 2013

Rajagiri School of Engineering & Technology

8th Feb 2013

PIC stands for Peripheral Interface Controller A family of Harvard architecture microcontrollers made by Microchip Technology Derived from the PIC1650 originally developed by General Instrument Microelectronics Division. The name PIC was originally an acronym for "Programmable Intelligent Computer".

Rajagiri School of Engineering & Technology

8th Feb 2013

10

PIC follows a Harvard Architecture It also has a RISC (Reduced Instruction Set Computer) CPU.

Rajagiri School of Engineering & Technology

8th Feb 2013

11

12bit cores with 33 instructions: 12C50x, 16C5x 14bit cores with 35 instructions: 12C67x,16Cxxx 16bit cores with 58 instructions: 17C4x,17C7xx Enhanced 16bit cores with 77 instructions: 18Cxxx PIC 16F877 is now used widely as a more advanced teaching device. chip covers most of the features that higher level students need for project work with microcontrollers

Get PICing!
Rajagiri School of Engineering & Technology 8th Feb 2013 12

The chip can be obtained in different packages, such as conventional 40pin DIP (Dual In-Line Package),square surface mount or socket format. The DIP version is recommended for prototyping, and is shown in Figure

Rajagiri School of Engineering & Technology

8th Feb 2013

13

The chip has two pairs of power pins (VDD5 V nominal and Vss 0 V), and either pair can be used. The chip can actually work down to about 2 V supply, for battery and power-saving operation. A low-frequency clock circuit using only a capacitor and resistor to set the frequency can be connected to CLKIN, or a crystal oscillator circuit can be connected across CLKIN and CLKOUT. MCLR is the reset input; when cleared to 0, the MCU stops, and restarts when MCLR 1. This input must be tied high allowing the chip to run if an external reset circuit is not connected, but it is usually a good idea to incorporate a manual reset button in all but the most trivial applications

Rajagiri School of Engineering & Technology

8th Feb 2013

14

Rajagiri School of Engineering & Technology

8th Feb 2013

15

The main program memory is flash ROM, which stores a list of 14-bits instructions. These are fed to the execution unit, and used to modify the RAM file registers. These include special control registers, the port registers and a set of general purpose registers which can be used to store data temporarily. A separate working register (W) is used with the ALU (Arithmetic Logic Unit) to process data. Various special peripheral modules provide a range of I/O options

Rajagiri School of Engineering & Technology

8th Feb 2013

16

There are 512 RAM File Register addresses (01FFh), which are organized in 4 banks (03), each bank containing 128 addresses. The default (selected on power up) Bank 0 is numbered from 0 to 7Fh, Bank 1 from 80h to FFh and so on. These contain both Special Function Registers (SFRs), which have a dedicated purpose, and the General Purpose Registers (GPRs). Deducting the SFRs from the total number of RAM locations, and allowing for some registers which are repeated in more than one bank, leaves 368 bytes of GPR (data) registers.
Rajagiri School of Engineering & Technology

8th Feb 2013

17

Rajagiri School of Engineering & Technology

8th Feb 2013

18

MPLAB Assembler-MPASM

Rajagiri School of Engineering & Technology

8th Feb 2013

19

_CONFIG(address 2007h) 1. Code Protection 2.In circuit debugging 3.Low voltage programming 5.Power up timer 6.Brown out timer 7. watchdog timer 8.RC Oscillator 9. Crystal Oscillator
Rajagiri School of Engineering & Technology

8th Feb 2013

20

Rajagiri School of Engineering & Technology

8th Feb 2013

21

Status Register
The status register records the result of certain operations, MCU power status and includes the bank selection bits.

Rajagiri School of Engineering & Technology

8th Feb 2013

22

ZERO FLAG (Z) This is set when the result of a register operation is zero, and cleared when it is not zero. CARRY FLAG (C) This flag is only affected by add, subtract and rotate instructions. If the result of an add operation generates a carry out, this flag is set; that is, when two 8-bitnumbers give a 9-bit sum.

Rajagiri School of Engineering & Technology

8th Feb 2013

23

Rajagiri School of Engineering & Technology

8th Feb 2013

24

DIGIT CARRY (DC) The digit carry records a carry from the most significant bit of the low nibble (bit 3). POWER STATUS BITS There are two read only bits in the status register which indicate the overall MCU status. The Power Down (PD) bit is clear to zero when SLEEP mode is entered. The Time Out (TO) bit is cleared when a watchdog time out has occurred.

Rajagiri School of Engineering & Technology

8th Feb 2013

25

Rajagiri School of Engineering & Technology

8th Feb 2013

26

4 cycles per instruction on the PIC 16F87x microcontrollers. T1 Clock Read Instruction Decode Instruction Execute Instruction Store Result Oscillator circuits generate signal. Rajagiri Schoola of clock Engineering &
Technology

T2

T3

T4

8th Feb 2013

27

Each PIC16 instruction is a 14-bit word divided into OPCODE OPERAND


PIC16 instruction set is comprised of three basic categories: 1.Byte-oriented operations 2.Bit-oriented operations 3.Literal and control operations
Rajagiri School of Engineering & Technology 8th Feb 2013 28

For byte-oriented instructions, f represents a file register designator and d represents a destination designator. For bit-oriented instructions, b represents a bit field designator while f represents the address of the file in which the bit is located. For literal and control operations, k represents an eight or eleven-bit constant

Rajagiri School of Engineering & Technology

8th Feb 2013

29

Byte-oriented file register operations

Rajagiri School of Engineering & Technology

8th Feb 2013

30

Rajagiri School of Engineering & Technology

8th Feb 2013

31

Rajagiri School of Engineering & Technology

8th Feb 2013

32

BYTE ORIENTED INSTRUCTIONS


ADDWF f, d

BIT ORIENTED INSTRUCTIONS


BCF PORTB,7

LITERAL OR CONTROL INSTRUCTION


ADDLW 02 GOTO LOOP

Rajagiri School of Engineering & Technology

8th Feb 2013

33

DATA TRANSFER REGISTER INSTRUCTIONS ARITHMETIC INSTRUCTIONS LOGICAL INSTRUCTIONS BRANCH INSTRUCTIONS CONTROL INSTRUCTIONS

Rajagiri School of Engineering & Technology

8th Feb 2013

34

Move data from File register - MOVF f, d Move data from W to F - MOVWF f Move literal into W - MOVLW 02

Rajagiri School of Engineering & Technology

8th Feb 2013

35

list p=16f877a ; list directive to define processor #include <p16f877a.inc> ; processor specific variable definitions X EQU 20H Y EQU 21H TEMP EQU 22H ORG 00H MOVF X, 0 MOVWF TEMP MOVF Y, W MOVWF X MOVF TEMP, W MOVWF Y END
Rajagiri School of Engineering & Technology 8th Feb 2013 36

Clear W (reset all bits and value to 0) Clear F (reset all bits and value to 0) Decrement F (reduce by 1) Increment F (increase by 1) Swap the upper and lower four bits in F Complement F value (invert all bits) Rotate bits Left through carry flag Rotate bits Right through carry flag Clear ( 0) the bit specified Set ( 1) the bit specified

- CLRW - CLRF f - DECF f,d - INCF f,d - SWAPF f - COMF f,d - RLF f,d - RRF f,d - BCF f, b - BSF f, b

Rajagiri School of Engineering & Technology

8th Feb 2013

37

list p=16f877a ; list directive to define processor #include <p16f877a.inc> ; processor specific variable definitions

TOGGLE EQU 20H ORG 00H B1 COMF TOGGLE ,1 GOTO B1 END

Rajagiri School of Engineering & Technology

8th Feb 2013

38

Add W to F Subtract W from F Add k to W Subtract W from k

- ADDWF f, d - SUBWF f, d - ADDLW k - SUBLW k

Rajagiri School of Engineering & Technology

8th Feb 2013

39

list p=16f877a ; list directive to define processor #include <p16f877a.inc> ; processor specific variable definitions A EQU 20H B EQU 21H RESULT EQU 23H ORG 00H MOVF A,0 ADDWF B,0 MOVWF RESULT END
Rajagiri School of Engineering & Technology 8th Feb 2013 40

Write a program to subtract F6-0A

Rajagiri School of Engineering & Technology

8th Feb 2013

41

AND the bits of W and F, result in W


AND the bits of L and W, result in W OR the bits of W and F, result in W OR the bits of L and W, result in W

- ANDWF f,d
- ANDLW k - IORWF f,d - IORLW k

Exclusive OR the bits of W and F, result in W - XORWF f,d Exclusive OR the bits of L and W - XORLW k

Rajagiri School of Engineering & Technology

8th Feb 2013

42

Test a bit in F and Skip next instruction if it is Clear ( 0) :BTFSC f,b

Test a bit in F and Skip next instruction if it is Set ( 1) :BTFSS f,b


Decrement F and Skip next instruction if F =0: DECFSZ f,d

Increment F and Skip next instruction if F =0 : INCFSZ f,d

Rajagiri School of Engineering & Technology

8th Feb 2013

43

Go to a labelled line in the program Jump to the label at the start of a subroutine

- GOTO start - CALL delay

Return at the end of a subroutine to the next instruction


Return at the end of a subroutine with k in W

-RETURN

-RETLW k

Return From Interrupt service routine

-RETFIE

Rajagiri School of Engineering & Technology

8th Feb 2013

44

No Operation - delay for 1 cycle - NOP Go into standby mode to save power -SLEEP
Clear watchdog timer to prevent automatic reset -CLRWDT

Rajagiri School of Engineering & Technology

8th Feb 2013

45

list p=16f877a ; list directive to define processor #include <p16f877a.inc> ; processor specific variable definitions

COUNT EQU 25H ; Count be the file register at 25H RESULT EQU 26H ; Result be the file register at 26H ORG 00H MOVLW d10 ;WREG =10 MOVWF COUNT ; Load the counter MOVLW 0 ;WREG=0 AGAIN ADDLW 3 ;WREG=WREG+3 DECF COUNT,1 ;Decrement counter BTFSS STATUS,Z ;Check whether COUNT =0 GOTO AGAIN MOVWF RESULT ;Sum at RESULT END
Rajagiri School of Engineering & Technology 8th Feb 2013 46

NUM EQU 24H EVEN EQU 25H ODD EQU 26H MOVF NUM,0 RRF NUM,1 BTFSC STATUS C GOTO LOOP1 GO TO LOOP2 MOVWF ODD GO TO LOOP3 MOVWF EVEN NOP
Rajagiri School of Engineering & Technology 8th Feb 2013 47

LOOP1 LOOP2 LOOP3

list p=16f877a ; list directive to define processor #include <p16f877a.inc> ; processor specific variable definitions

CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF &_PWRTE_ON & _RC_OSC & _WRT_OFF & _LVP_ON & _CPD_OFF ORG 00 ; Program begins at 00 R1 EQU 0x20 ; R1 as file register at 20h R2 EQU 0x21 ; R2 as file register at 21h NUM EQU 0x22 ; NUM as file register at 22h MOVF R1,0 ; WREG= R1 SUBWF R2,0 ; WREG= WREG-R2 BTFSC STATUS, C ;Is C flag is clear skip the next instruction GOTO LOOP ;Unconditional branch MOVF R1,0 ;WREG=R1,Biggest number MOVWF NUM ;NUM =WREG GOTO LP ; Unconditional branch LOOP MOVF R2,0 ;WREG=R2,Biggest number MOVWF NUM ;NUM =WREG LP NOP END Rajagiri School of Engineering &
Technology

8th Feb 2013

48

list p=16f877a ; list directive to define processor #include <p16f877a.inc> ; processor specific variable definitions _CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _RC_OSC & _WRT_OFF & _LVP_ON & _CPD_OFF ORG 00 MULTIPLIER EQU 0x20 MULTIPLICAND EQU 0x21 RESULT EQU 0x22 MOVLW 0 AGAIN ADDWF MULTIPLICAND,0 DECF MULTIPLIER,1 BNZ AGAIN MOVWF RESULT END
Rajagiri School of Engineering & Technology

8th Feb 2013

49

list p=16f877a ; list directive to define processor #include <p16f877a.inc> ; processor specific variable definitions __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _RC_OSC & _WRT_OFF & _LVP_ON & _CPD_OFF ORG 00 NUME EQU D'4' DENO EQU D'3' NUM EQU 0x20 QUOTIENT EQU 0x22 REMAINDER EQU 0x23 CLRF QUOTIENT ; CLEAR QUOTIENT MOVF NUME,0 ;WREG=4 MOVWF NUM ;NUMERATOR =4 MOVF DENO,0 ;WREG =3 INCF QUOTIENT,1 ; INCREMENT QUOTIENT SUBWF NUM,1 ;NUM= WREG-NUM BTFSS STATUS,C GOTO B1 GOTO AGAIN DECF QUOTIENT,1 Rajagiri School of Engineering & ADDWF NUM,1;TO GET REMAINDER
Technology

AGAIN

B1 END

8th Feb 2013

50

list p=16f877a ; list directive to define processor #include <p16f877a.inc> ; processor specific variable definitions __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _RC_OSC & _WRT_OFF & _LVP_ON & _CPD_OFF ORG 00 NUM EQU 0x20 RESULT EQU 0x21 COUNT EQU 0x22 MOVF NUM,0 AGAIN RLF NUM,1 BTFSC STATUS,C GOTO LOOP1 GOTO LOOP LOOP1 INCF RESULT,1 LOOP DECF COUNT,1 BTFSS STATUS,Z GOTO AGAIN NOP END
Rajagiri School of Engineering & Technology 8th Feb 2013 51

The PIC 16F877 file register RAM is divided into four banks of 128 locations, banks 03 At power on reset, bank 0 is selected by default. To access the others, these register bank select bits must be changed, as shown in Table

Rajagiri School of Engineering & Technology

8th Feb 2013

52

The register banks are selected by setting and clearing the bits RP0 and RP1in the status register. More conveniently, the pseudo-operation BANKSEL can be used instead. The operand for BANKSEL is any register in that bank, or its label. In effect, BANKSEL detects the bank bits in the register address and copies them to the status register bank select bits.

Rajagiri School of Engineering & Technology

8th Feb 2013

53

There are five parallel ports in the PIC 16F877, labeled AE. All pins can be used as bit- or byte-oriented digital input or output. Their alternate functions are summarized in Table

Rajagiri School of Engineering & Technology

8th Feb 2013

54

PORTA is a 6-bit wide, bidirectional port. The corresponding data direction register is TRISA. Setting a TRISA bit (= 1) will make the corresponding PORTA pin an input Clearing a TRISA bit (= 0) will make the corresponding PORTA pin an output SUMMARY OF REGISTERS ASSOCIATED WITH PORTA

Rajagiri School of Engineering & Technology

8th Feb 2013

55

PORTB is an 8-bit wide, bidirectional port. The corresponding data direction register is TRISB.
SUMMARY OF REGISTERS ASSOCIATED WITH PORTB

Rajagiri School of Engineering & Technology

8th Feb 2013

56

PORTC is an 8-bit wide, bidirectional port. The corresponding data direction register is TRISC.
SUMMARY OF REGISTERS ASSOCIATED WITH PORTC

Rajagiri School of Engineering & Technology

8th Feb 2013

57

PORTD is an 8-bit port. PORTD can be configured as an 8-bit wide microprocessor port (Parallel Slave Port) by setting control bit, PSPMODE (TRISE<4>). SUMMARY OF REGISTERS ASSOCIATED WITH PORTD

Rajagiri School of Engineering & Technology

8th Feb 2013

58

PORTE has three pins (RE0/RD/AN5, RE1/WR/AN6 and RE2/CS/AN7) which are individually configurable as inputs or outputs.
SUMMARY OF REGISTERS ASSOCIATED WITH PORTE

Rajagiri School of Engineering & Technology

8th Feb 2013

59

Rajagiri School of Engineering & Technology

8th Feb 2013

60

list p=16f877a ; list directive to define processor #include <p16f877a.inc> ; processor specific variable definitions __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_OFF & _LVP_ON & _CPD_OFF R0 EQU 20H R1 EQU 21H COUNT0 EQU 22H COUNT1 EQU 23H ORG 00H CLRW BANKSEL TRISB MOVWF TRISB

Rajagiri School of Engineering & Technology 8th Feb 2013 61

BANKSEL PORTB AGAIN1 MOVLW 0FFH MOVWF PORTB CALL DELAY COMF PORTB CALL DELAY GOTO AGAIN1

Rajagiri School of Engineering & Technology

8th Feb 2013

62

DELAY MOVLW 0ffh MOVWF COUNT0 FLOOP NOP NOP MOVLW 0ffh MOVWF COUNT1 NOP F1LOOP DECFSZ COUNT1,F GOTO F1LOOP DECFSZ COUNT0,F GOTO FLOOP RETURN END

Rajagiri School of Engineering & Technology

8th Feb 2013

63

Thank You

Rajagiri School of Engineering & Technology

8th Feb 2013

64

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy