PIC16F887.

Slides:



Advertisements
Similar presentations
Introduction to PIC Microcontrollers
Advertisements

Working with time: interrupts, counters and timers Chapter Six Dr. Gheith Abandah1.
م/محمد علي عطية حسين. Pin Diagram DescriptionPin Name Oscillator crystal input/external clock source input. OSC1/CLKIN Oscillator crystal output.OSC2/CLKOUT.
C Examples 1.
ECT 357 Ch 16 Output Control. Today’s Quote: The measure of a man is not how great his faith is bt how great his love is. The measure of a man is not.
5-1 Timer/Counters In many microprocessor systems we need to:  count logic pulses  measure the frequency of signals  measure the period of pulses 
Microcontroller Architecture— PIC18F Family
Microcontroller Architecture PIC18F Family
Microcontroller Programming How to make something almost do something else Raffi Krikorian MAS November 2003.
Department of Electronic & Electrical Engineering Embedded system Aims: Introduction to: Hardware. Software Ideas for projects ? Robotics/Control/Sensors.
Renesas Electronics Europe GmbH A © 2010 Renesas Electronics Corporation. All rights reserved. RL78 Clock Generator.
Parallel Ports, Power Supply and the Clock Oscillator Material to be covered  Parallel I/O ports  Interfacing external switches and LEDs  Clock Oscillator.
16F877A. Timer 0 The Timer0 module timer/counter has the following features: –8-bit timer/counter –Readable and writable –8-bit software programmable.
Timers ELEC 330 Digital Systems Engineering Dr. Ron Hayne
Interrupts, Counter and Timers. Interrupts (1) Interrupt-driven I/O uses the processor’s interrupt system to “interrupt” normal program flow to allow.
Timers The timers of the PIC16C7X microcontroller can be briefly described in only one sentence. There are three completely independent timers/counters.
Clock Options and Sleep Modes. Clock Sources Flash Fuse bits can be programmed to choose one of the following Clock sources: 1. External RC Osc. f = 1/(3RC).
I/O PORTS (Simplest Peripherals) PORT A: 6 bits wide (7th and 8th bit always read as 0) PORT B: 8 bits wide PORT C: 8 bits wide PORT D: 8 bits wide.
One of the most important feature of the microcontroller is a number of input/output pins used for connection with peripherals. In the case of PIC 167CX,
Microprocessors A practical approach Subjects Goals for this module Results Subjects of the module Plans Questions.
Prepared by Eng. Musa Alyaman1 Chapter Seven Chapter Seven PIC16F87x.
CCP MODULES  The CCP module (Capture/Compare/PWM) is a peripheral which allows the user to time and control different events.  Capture Mode provides.
ECS642U Embedded Systems Cyclic Execution and Polling William Marsh.
Teachers Name : Suman Sarker Telecommunication Technology Subject Name : Microcontroller & Embedded System Subject Code : 6871 Semester : 7th Department.
Architecture and instruction set. Microcontroller Core Features:  Operating speed: DC - 20 MHz clock input DC ns instruction cycle Up to 8K x.
Saxion University of Applied Sciences Advanced Microcontrollers A practical approach.
Interrupts  An interrupt is any service request that causes the CPU to stop its current execution stream and to execute an instruction stream that services.
DsPIC30F4011 Fall DIP Switches  The upper four switches of SW1 are used to enable LEDs connected to PORTB/C, PORTA/D, PORTE and PORTF. For example,
C Examples 1. Download Links MPLAB IDE dsPIC30F4011/4012 Data Sheet dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference.
Device Overview 1.  The advantages of all PIC18Fxxxx microcontrollers:  High computational performance  High-endurance  Enhanced Flash program memory.
C Examples 1. Download Links dsPIC30F4011/4012 Data Sheet dsPIC30F4013/3014 dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference.
Features of the PIC18 microcontroller - 8-bit CPU - 2 MB program memory space (internal 32KB to 128KB) bytes to 1KB of data EEPROM - Up to 4096 bytes.
Microcontrollers session. What is Microcontroller? Microcontroller is composed of microprocessor,ram, flash memory,EEPROM and some modules like timers,
PIC12F629/675. “Wide variety” 8-84 pin RISC core, 12/14/16bit program word USART/AUSART, I 2 C, ADC, ICSP, ICD OTP/UV EPROM/FLASH/ROM Families: PIC12,
Components of a typical full-featured microcontroller.
NAM S.B MDLAB. Electronic Engineering, Kangwon National University 1.
Programming PIC 16F84A in Assembly. PIC16F84 pin-out and required external components.
Introduction to Projects using Microcontroller Md. Khalilur Rhaman Credit: Interface Lab.
I/O PORTS. General purpose I/O pins can be considered the simplest of peripherals. They allow the PICmicro™ to monitor and control other devices. To add.
Special Features. Device Configuration bits Revision Device Configuration bits Revision On-chip Power-on Reset (POR) Revision On-chip Power-on Reset (POR)
One more PIC18F252 example and revision for exam B222L Branislav Vuksanovic, UoP, ECE.
Microprocessors A practical approach..
TIMERS.
Chapter 10 Interrupts. Basic Concepts in Interrupts  An interrupt is a communication process set up in a microprocessor or microcontroller in which:
Timer modules in PIC 16F877.  The PIC 16F877 basically has three independent timer modules,  denoted by the symbols, TIMER-0, TIMER1,andTIMER2. . These.
 Mini-Computer ◦ Microprocessor  The Brains  Arithmetic Logic Unit (ALU)  Control Unit  Program/ Data Storage  Peripherals (Input/Output)  Low-Cost.
USING TV REMOTE AS A CORDLESS MOUSE FOR THE COMPUTER
CORDLESS MOUSE FEATURES BY TV REMOTE USING PIC MICROCONTROLLER
16F877A.
Chapter 9 PIC18 Timer Programming in Assembly
Microprocessor Systems Design I
Microprocessors and Programming Department of Mechatronics Engineering
Microprocessor Systems Design I
INT. TO EMBEDDED SYSTEMS DEVELOPMENT
Microprocessor Systems Design I
Microprocessor Systems Design I
Interrupts, Counter and Timers
Microprocessor Systems Design I
Microprocessors Timers
Project Title EVM IN PIC Under the Guidance of Submitted by.
PIC 16F877.
Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EE Embedded Systems Fall 2015
PIC18 Timer Programming “Explain the assembly language programming for the timer and counter module”
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
PIC16F887.  1.Microcontroller introducton  2.MPLAB,Hi-tech compilers  3.LED  4.Switches/push buttons  5.7-Segment Display  6.Keypad  7.LCD  8.Timers.
PIC18 Interrupt Programming
Timers Chapter 2.
Presentation transcript:

PIC16F887

Main Features Only 35 instructions to learn: Operating speed: All single-cycle instructions except branches Operating speed: DC – 20 MHz oscillator/clock input DC – 200 ns instruction cycle Interrupt capability 8-level deep hardware stack Direct, Indirect and Relative Addressing modes

Main Features Precision Internal Oscillator: Power savings Factory calibrated to ±1% Software selectable frequency range of 8 MHz to 31 kHz Software tunable Two-Speed Start-up mode Crystal fail detect for critical applications Clock mode switching during operation for Power savings Power-Saving Sleep mode Wide operating voltage range (2.0V-5.5V) Industrial and Extended Temperature range Power-on Reset (POR) Power-up Timer (PWRT) and Oscillator Start-up Timer (OST) • Brown-out Reset (BOR) with software control Option

Main Features • Enhanced low-current Watchdog Timer (WDT) with on-chip oscillator (software selectable nominal 268 seconds with full prescaler) with software enable • Multiplexed Master Clear with pull-up/input pin • Programmable code protection • High Endurance Flash/EEPROM cell: 100,000 write Flash endurance 1,000,000 write EEPROM endurance Flash/Data EEPROM retention: > 40 years Program memory Read/Write during run time In-Circuit Debugger (on board)

Main Features Low-Power Features: Standby Current: 50 nA @ 2.0V, typical • Operating Current: 11 μ A @ 32 kHz, 2.0V, typical 220 μ A @ 4 MHz, 2.0V, typical • Watchdog Timer Current: 1 μ A @ 2.0V, typical

Pinout and Family Differences

Oscillator

FOSC REGISTER

Parallel I/O (PIO) Ports

Parallel I/O (PIO) Ports

Timer 0

OPTION_REG = 0x84;

INTCON = 0xA0; TMR0IF_bit = 0;

/* * Project name: LED_Blinking (Simple 'Hello World' project) * Copyright: (c) Mikroelektronika, 2009. * Revision History: 20080930: - initial release; - 20090720 - modified by Slavisa Zlatanovic; * Description: This is a simple 'Hello World' project. It turns on/off LEDs connected to PORTA, PORTB, PORTC and PORTD. * Test configuration: MCU: PIC16F887 http://ww1.microchip.com/downloads/en/DeviceDoc/41291F.pdf Dev.Board: EasyPIC6 http://www.mikroe.com/en/tools/easypic6/ Oscillator: HS, 08.0000 MHz Ext. Modules: - SW: mikroC PRO for PIC http://www.mikroe.com/en/compilers/mikroc/pro/pic/ * NOTES: - Turn ON the PORT LEDs at SW9. */

void main() { ANSEL = 0; // Configure AN pins as digital ANSELH = 0; C1ON_bit = 0; // Disable comparators C2ON_bit = 0; TRISA = 0x00; // set direction to be output TRISB = 0x00; // set direction to be output TRISC = 0x00; // set direction to be output TRISD = 0x00; // set direction to be output do { PORTA = 0x00; // Turn OFF LEDs on PORTA PORTB = 0x00; // Turn OFF LEDs on PORTB PORTC = 0x00; // Turn OFF LEDs on PORTC PORTD = 0x00; // Turn OFF LEDs on PORTD Delay_ms(1000); // 1 second delay PORTA = 0xFF; // Turn ON LEDs on PORTA PORTB = 0xFF; // Turn ON LEDs on PORTB PORTC = 0xFF; // Turn ON LEDs on PORTC PORTD = 0xFF; // Turn ON LEDs on PORTD } while(1); // Endless loop }

/* * Project name: Timer0_Interrupt (Using Timer0 to obtain interrupts) * Copyright: (c) Mikroelektronika, 2009. * Revision History: 20080930: - initial release; - 20090720 - modified by Slavisa Zlatanovic; * Description: This code demonstrates how to use Timer0 and it's interrupt. Program toggles LEDs on PORTB. * Test configuration: MCU: PIC16F887 http://ww1.microchip.com/downloads/en/DeviceDoc/41291F.pdf Dev.Board: EasyPIC6 http://www.mikroe.com/en/tools/easypic6/ Oscillator: HS, 08.0000 MHz Ext. Modules: - SW: mikroC PRO for PIC http://www.mikroe.com/en/compilers/mikroc/pro/pic/ * NOTES: - Turn on LEDs on PORTB (switch SW9.2). */

unsigned cnt; void interrupt() { if (TMR0IF_bit) { cnt++; // Increment counter TMR0IF_bit = 0; // Clear TMR0IF TMR0 = 96; } void main() { OPTION_REG = 0x84; // Assign prescaler to TMR0 ANSEL = 0; // Configure AN pins as digital ANSELH = 0; C1ON_bit = 0; // Disable comparators C2ON_bit = 0; TRISB = 0; // PORTB is output PORTB = 0xFF; // Initialize PORTB TMR0 = 96; // Timer0 initial value INTCON = 0xA0; // Enable TMRO interrupt cnt = 0; // Initialize cnt do { if (cnt >= 400) { PORTB = ~PORTB; // Toggle PORTB LEDs cnt = 0; // Reset cnt } while(1);

unsigned cnt; void interrupt() { if (TMR0IF_bit) { TMR0IF_bit = 0; // Clear TMR0IF TMR0 = 255; PORTB = ~PORTB; } void main() { OPTION_REG = 0x80; // Assign prescaler to TMR0 ANSEL = 0; // Configure AN pins as digital ANSELH = 0; C1ON_bit = 0; // Disable comparators C2ON_bit = 0; TRISB = 0; // PORTB is output PORTB = 0xFF; // Initialize PORTB TMR0 = 255; // Timer0 initial value INTCON = 0xA0; // Enable TMRO interrupt cnt = 0; // Initialize cnt

_interrupt: MOVWF R15+0 SWAPF STATUS+0, 0 CLRF STATUS+0 MOVWF ___saveSTATUS+0 MOVF PCLATH+0, 0 MOVWF ___savePCLATH+0 CLRF PCLATH+0 ;Timer0_Interrupt.c,28 :: void interrupt() { ;Timer0_Interrupt.c,29 :: if (TMR0IF_bit) { BTFSS TMR0IF_bit+0, BitPos(TMR0IF_bit+0) GOTO L_interrupt0 ;Timer0_Interrupt.c,31 :: TMR0IF_bit = 0; // Clear TMR0IF BCF TMR0IF_bit+0, BitPos(TMR0IF_bit+0) ;Timer0_Interrupt.c,32 :: TMR0 = 255; MOVLW 255 MOVWF TMR0+0 ;Timer0_Interrupt.c,33 :: PORTB = ~PORTB; COMF PORTB+0, 1 ;Timer0_Interrupt.c,34 :: } L_interrupt0: ;Timer0_Interrupt.c,35 :: } L_end_interrupt: L__interrupt2: MOVF ___savePCLATH+0, 0 MOVWF PCLATH+0 SWAPF ___saveSTATUS+0, 0 MOVWF STATUS+0 SWAPF R15+0, 1 SWAPF R15+0, 0 RETFIE ; end of _interrupt

CAPTURE/COMPARE/PWM MODULES (CCP1 AND CCP2) This device contains one Enhanced Capture/Compare/PWM (CCP1) and Capture/Compare/PWM module(CCP2). The CCP1 and CCP2 modules are identical in operation, with the exception of the Enhanced PWM features available on CCP1 only. CCPRx and CCPx refer to CCPR1 or CCPR2 and CCP1 or CCP2, respectively.

Pinout and Family Differences

/* * Project name: PWM (PWM library Demonstration) * Copyright: (c) MikroElektronika, 2008. * Revision History: - 2008. - initial release; - 20090720 - modified by Slavisa Zlatanovic; * Description: This is a simple demonstration of PWM library, which is being used for control of the PIC's CCP module. The module is initialized and started, after which the PWM1 and PWM2 Duty Ratios can be adjusted by means of 4 buttons connected to pins RA0, RA1, RA2 and RA3. The changes can be monitored on the CCP output pins (RC1 and RC2). * Test configuration: MCU: PIC16F887 http://ww1.microchip.com/downloads/en/DeviceDoc/41291F.pdf Dev.Board: EasyPIC6 http://www.mikroe.com/en/tools/easypic6/ Oscillator: HS, 08.0000 MHz Ext. Modules: - SW: mikroC PRO for PIC http://www.mikroe.com/en/compilers/mikroc/pro/pic/ * NOTES: - Pull-down PORTA and connect button jumper (J17) to Vcc. - Turn on LEDs on PORTC SW9.3. */

PWM2_Init(5000 seem to override PWM1_Init(5000 unsigned short current_duty, current_duty1; void InitMain() { ANSEL = 0; // Configure AN pins as digital ANSELH = 0; C1ON_bit = 0; // Disable comparators C2ON_bit = 0; PORTA = 255; TRISA = 255; // Configure PORTA pins as input PORTB = 0; // Set PORTB to 0 TRISB = 0; // Designate PORTB pins as output PORTC = 0; // Set PORTC to 0 TRISC = 0; // Designate PORTC pins as output PWM1_Init(5000); // Initialize PWM1 module at 5KHz PWM2_Init(5000); // Initialize PWM2 module at 5KHz } PWM2_Init(5000 seem to override PWM1_Init(5000

void main() { InitMain(); current_duty = 30; // Initial value for current_duty current_duty1 = 30; // Initial value for current_duty1 PWM1_Start(); // Start PWM1 PWM2_Start(); // Start PWM2 PWM1_Set_Duty(current_duty); // Set current duty for PWM1 PWM2_Set_Duty(current_duty1); // Set current duty for PWM2 while (1) { // Endless loop if (RA0_bit) { // Button on RA0 pressed Delay_ms(40); current_duty++; // Increment current_duty PWM1_Set_Duty(current_duty); } if (RA1_bit) { // Button on RA1 pressed current_duty--; // Decrement current_duty if (RA2_bit) { // Button on RA2 pressed current_duty1++; // Increment current_duty1 PWM2_Set_Duty(current_duty1); if (RA3_bit) { // Button on RA3 pressed current_duty1--; // Decrement current_duty1 if (RA5_bit) { // Button on RA3 pressed PORTC.B0 = ~ PORTC.B0; // current_duty = 255 - current_duty; Delay_ms(1000); Delay_ms(5); // Slow down change pace a little

/* * Project name: Button (Demonstration of using Button Library) * Copyright: (c) Mikroelektronika, 2009. * Revision History: 20080110: - initial release; - 20090720 - modified by Slavisa Zlatanovic; * Description: This program demonstrates usage on-board button as PORTB input. On every RB0 one-to-zero transition PORTC is inverted. * Test configuration: MCU: PIC16F887 http://ww1.microchip.com/downloads/en/DeviceDoc/41291F.pdf Dev.Board: EasyPIC6 http://www.mikroe.com/en/tools/easypic6/ Oscillator: HS, 08.0000 MHz Ext. Modules: - SW: mikroC PRO for PIC http://www.mikroe.com/en/compilers/mikroc/pro/pic/ * NOTES: - Turn ON the PORTC LEDs. - Put button jumper (J17) into VCC position and pull-down PORTB. */

bit oldstate; // Old state flag void main() { ANSEL = 0; // Configure AN pins as digital I/O ANSELH = 0; C1ON_bit = 0; // Disable comparators C2ON_bit = 0; TRISB0_bit = 1; // set RB0 pin as input TRISB = 0b00000011; PORTB = 0x00; TRISC = 0x00; // Configure PORTC as output PORTC = 0xAA; // Initial PORTC value oldstate = 0; do { if (Button(&PORTB, 0, 1, 1)) { // Detect logical one oldstate = 1; // Update flag } if (oldstate && Button(&PORTB, 0, 1, 0)) { // Detect one-to-zero transition PORTC = ~PORTC; // Invert PORTC oldstate = 0; // Update flag if (RB1_bit == 1) { // Detect one-to-zero transition } while(1); // Endless loop

Switch + LED (SWITCH12) void main () { ADPCFG = 0xFFFF; TRISF=0b000001; PORTF=0x00; while(1) if((PORTF&0b000001)==1) // Switch at PORTF Bit 0 {PORTF.F1=PORTF.F1^1;} // Toggles PORTF Bit 1 }

Key DEBOUNCING

Key DEBOUNCING – 1 (SWITCH2) void main () { int i; const int Tenms = 16667; ADPCFG = 0xFFFF; TRISF=0b000001; PORTF=0x00; while(1) i = 0; // Wait 10 ms for Button Up while (i < Tenms) if (1 == PORTF.F0) // Button Down/Start over i = 0; } else // Button Up/Increment Count i = i + 1; } // i = 0; // Wait 10 ms for Button Down if (0 == PORTF.F0 ) // Button Up/Start over else // Button Down/Increment Count PORTF.F1=PORTF.F1^1; // Toggle LED to Turn ON/OFF LED Adapted from 123 PIC Experiments for the EVIL GENIOUS by MYKE PREDKO

Key DEBOUNCING – 1 (SWITCH2) ;SWITCH2.c,24 :: while (i < Tenms) $0144 $ L_main_6: $0144 $470060 ADD W14, #0, W0 $0146 $780110 MOV [W0], W2 $0148 $4700E2 ADD W14, #2, W1 $014A $510011 SUB W2, [W1], W0 $014C $3D000D BRA GE L_main_7, L_main_7 ;SWITCH2.c,25 :: if (0 == PORTF.F0) // Button Up/Start over $014E $801700 MOV PORTF, W0 $0150 $6000E1 AND W0, #1, W1 $0152 $108060 SUBR W1, #0, W0 $0154 $3A0004 BRA NZ L_main_8, L_main_8 ;SWITCH2.c,26 :: i = 0; $0156 $200000 MOV #0, W0 $0158 $780F00 MOV W0, [W14] $015A $040164 GOTO L_main_9 $015E $ L_main_8: ;SWITCH2.c,28 :: i = i + 1; $015E $200011 MOV #1, W1 $0160 $470060 ADD W14, #0, W0 $0162 $408810 ADD W1, [W0], [W0] $0164 $ L_main_9: $0164 $040144 GOTO L_main_6 $0168 $ L_main_7: ;SWITCH2.c,30 :: PORTF.F1=PORTF.F1^1; // Toggle LED to Turn

Capture Mode

Compare Mode

PWM

Period in multiples of 4/fosc Resolution in multiples of 1/fosc Least significant bits of extended TMR2 Change at oscillator frequency

void InitMain() { ANSEL = 0; // Configure AN pins as digital ANSELH = 0; C1ON_bit = 0; // Disable comparators C2ON_bit = 0; PORTC = 0; // Set PORTC to 0 TRISC = 0; // Designate PORTC pins as output } void main() { InitMain(); PR2 = 0x65; T2CON = 0X04; CCP2CON = 0X3F; CCPR2L = 0X0F;

PWM