INTRODUCTION
The high performance of PIC can be attributed to a number of architectural features found in RISC microprocessor.
Harvard architecture
Long word instruction Single word instruction
INTRODUCTION
Long word instruction-These instructions have a wider instruction bus than the 8 bit Data memory bus.This is possible because the two busses are separate .This allows instructions to be sized differently that 8 bit wide data word, which allows a more efficient use f the program memory, since program memory width is optimized to the architectural requirements. Single word instruction-Single word instructions are 14 bit wide.A 14bit wide program memory access bus fetches a 14 bit instruction in a single cycle.with single word instruction ,the no.of words of program memory location equals the number of instructions for the device,hence all locations are valid instructions.
13/12/04 Accel Software &Technologies Limited 3
INTRODUCTION
Instruction pipeline-The instruction pipeline is two stage pipeline,which overlaps the fetch and execution of instructions.The fetch takes one TCY and execution takes on TCY,but due to overlap the fetch of one instruction and execution of previous instruction is done in one TCY. Single cycle instruction-with the program memory bus being 14 bits wide the entire instruction is fetched in a single TCY.the instruction contains all the information required and is executed in a single cycle.There may be one cycle delay if the results of the instruction modifies the contents of the program counter.This requires the pipelined to be fetched and a new instruction to be fetched.
13/12/04 Accel Software &Technologies Limited 4
INTRODUCTION
Reduced instruction set-When the instruction set is well designed and highly symmetric fewer instructions are required to perform all needed tasks. Register file architecture-The register files/data memory can be directly or indirectly addressed.All special functions registers,including program counter are mapped in the data memory. Orthogonal(Symmetric)instructions-Orthogonal instructions make it possible to carry out any operation on any register using addressing mode.This makes programming simpler yet efficient.
13/12/04 Accel Software &Technologies Limited 5
INTRODUCTION
The mid range instruction set uses only two nonregister oriented instruction,which are used for two of the cores feature.one is SLEEP instruction ,which places the device into the lowest power use mode and the other is CLRWDT which verifies the chip is operating properly by preventing the on-chip WDT from overflowing and resetting the device.
13/12/04
INTRODUCTION
PIC-Peripheral interface controller Why PIC? PIC is very popular micro controller worldwide. Microchip(2nd largest chip manufacture) is one of the manufactures of 8 bit RISC processor. Focus on high performance cost effective,field programmable embedded control solutions Variety of end user application specific standard product(ASSP)& application specific integrated circuit(ASIC) Global network of manufacturing and customer support facilities.
13/12/04 Accel Software &Technologies Limited 7
FEATURES
High performance RISC CPU Only 35 single word instructions. All single cycle instructions except for program branches which are two cycles. Operating speed DC- 20MHz clock input; DC-200ns instruction cycle. 2Kx14 words of flash program memory 128x8 bytes of data memory(RAM) 68x8 bytes of EEPROM Data memory No of pins ranges from 28 to 40 Interrupt capabilities (upto 11 sources).
13/12/04 Accel Software &Technologies Limited 8
FEATURE
Eight level deep hardware stack Direct ,indirect and relative addressing modes Power on reset(POR) Power up timer(PWRT) and oscillator start up timer(OST) WDT with its own on-chip RC oscillator for reliable operation Programmable code protection Power saving sleep modes Selector oscillator options Low power high speed CMOS FLASH/EEPROM technologies
13/12/04 Accel Software &Technologies Limited 9
FEATURES
Fully static design In circuit serial programming(ICSP) through two pins. Single 5V ICSP capabilities In circuit debugging through two pins Processor read /write access to program memory. Wide operating range 2.0V to 5.5V High sink/source current:25mA Low power consumption
13/12/04 Accel Software &Technologies Limited 10
PERIPHERIAL FEATURES
Timer0:8 bit timer/counter with 8 bit prescaler Timer1:16 bit timer/counter with prescaler, can be incremented during sleep via external crystal/clock Timer2:8bit timer/counter with 8 bit period register, prescaler and postscaler. One capture, compare, PWM module 10 bit multi channel ADC USART/SCI with 9 bit address detection Parallel slave port with 8 bit wide, with external RD,WR and CS controls (40/44 pins) Brown out circuitry detection for brown out reset (BOR).
13/12/04 Accel Software &Technologies Limited 11
13/12/04
13
Dig
13/12/04
14
13/12/04
15
BLOCK DIAGRAM
13/12/04
16
13/12/04
17
ALU
PIC contains 8 bit ALU and 8-bit working register. Arithmetic operation are twos compliment in nature. In two operands instruction, one operand is the Working register (W register an 8 bit working register used for ALU operation, it is not a addressable register). The other operand is a file register or an immediate constant. In Single operand instruction, the operand is either the W register or a File register.
13/12/04 Accel Software &Technologies Limited 18
STATUS REGISTER
The STATUS register contains the arithmetic status of the ALU, the RESET status and the bank select bits for Data memory. Since the selection of the data Memory bank is controlled by this register, it is required to be present in every bank. This register can be the destination for any instruction. If the STATUS register is the destination for an instruction that affects the Z, DC, C bits, then write to these bits is disabled.TO & PD bits are not writeable.
13/12/04 Accel Software &Technologies Limited 19
STATUS REGISTER
IRP
7 IRP
RP1
RP0
TO
PD
DC
6, RP1,R Register bank select bits(direct addressing) 5 P0 11=Bank 3(180h-1ffh) 10=Bank 2(100-17fh)
01=Bank 1(80h-ffh) 4 TO 00=Bank 0(00-7fh)
Time to live 1=After power up,CLRWDT or SLEEPinstruction 0=A WDT time out occurred
13/12/04
20
STATUS REGISTER
3 PD Power down bit 1=After power up or by CLRWDT instruction 0=By execution of the SLEEP instruction Zero bit 1=if arithmetic and logical instruction result is zero Digit carry/borrow (polarity is reverse) bit (ADDWF,ADDLW,SUBLW,SUBWF instructions) 1=carry out from the 4th LSB of the result occurred.
2 1
Z DC
Carry/borrow bit (ADDWF,ADDLW,SUBLW,SUBWF instruction) 1=A carry out from the MSB of the result occurred.
13/12/04
21
OPTION REGISTER
RBUP INTEDG TOCS TOSE PSA PS2 PS1 PS0
Bit 7
Symbol Function RBPU PORTB pull-up enable bit 1=PORTB pull ups are disabled 0=PORTB pull ups are enabled by individual port latch values
13/12/04
22
OPTION REGISTER
Bit 6 Symbol Function INTEDG Interrupt edge select bit 1=Interrupt on rising edge of INT pin 0= Interrupt on falling edge of INT pin 5 TOCS TMR0 clock source select bit 1=Transition on TOCKL pin 0=Internal instruction cycle clock(CLKOUT) 4 TOSE TMR0 source edge select bit 1=Increment on High to low transition on TOCKL pin 0=Increment on low to high transition on TOCKL pin
13/12/04 Accel Software &Technologies Limited 23
OPTION REGISTER
Bit 3 Symbol Function PSA Prescalar assignment bit 1=prescalar is assigned to the WDT 0=prescalar is assigned to the Timer 0 module 2-0 PS2:PS0 Prescalar rate select bits
Bit value 000 001 010 011 100 101 110 111
13/12/04 Accel Software &Technologies Limited
TMR0 rate 1:2 1:4 1:8 1:16 1:32 1:64 1:128 1:256
WDT rate 1:1 1:2 1:4 1:8 1:16 1:32 1:64 1:128
24
PCON REGISTER
MPEEN
7
6 3 2 PER
MPEEN
PER
POR
BOR
POR
BOR
13/12/04
MEMORY ORGANIZATION
Three memory blocks
Program memory Data memory - general purpose RAM - Special function Register(SFR) control the peripheral modules. EEPROM data memory
which is used to
The program and data memory have separate buses so that access to each block can occur During the same oscillator cycle.
13/12/04 Accel Software &Technologies Limited 26
PROGRAM MEMORY
The PIC devices have a 13 bit program counter capable of addressing an 8Kx14 program memory space. The PIC16F870/71 devices has 2K x 14 words of FLASH program memory. Accessing a location above the physically implemented address will cause a wraparound. The Reset vector is at 0000h and the interrupt vector is at 0004h.Since all instruction are a single word, a device with an 8Kx14 program memory has space for 8K of instructions. This makes it much easier to determine if a device has sufficient program memory for the desired application. The program memory is divided into four pages of 2K words each (0h-7ffh, 800h-fffh,1000h -17ffh, 1800h-1fffh).
13/12/04 Accel Software &Technologies Limited 27
PROGRAM MEMORY(dig)
13/12/04
28
PROGRAM COUNTER
The program counter (PC) specifies the Address of the instruction to fetch for execution. PC is 13 Bit wide. The lower byte is called the PCL Register which is readable and writeable. The high Byte is called PCH and is not directly readable or writeable. All updates to the PCH register goes through the PCLATH register.
13/12/04
29
PROGRAM COUNTER(dig)
13/12/04
30
DATA MEMORY
The data memory is made up of the general purpose register GPR (upper location) area and the special function register SFR (lower location) area. The SFRs control the operation of the device while the GPRs are the general area of the data storage and scratch pad operation. The data memory is banked for both the GPRs and SFRs areas.The GPR area is banked to allow greater than 96 bytes of general purpose RAM to be addressed. SFRs are for the registers that control the peripheral and core functions. The entire data memory can be accessed either directly or indirectly.
13/12/04 Accel Software &Technologies Limited 31
BANKING
The data memory is partitioned into four banks. Each bank contains GPRs and SFRs. Switching between these tasks requires the RP0 and RP1 bits in the status register to be configured for the desired bank when using direct addressing. The IRP bit in the status register is used for Indirect addressing. Each bank Extends up to 7Fh (128bytes).
Accessed Banks RP<1:0> Indirect(IRP) 0 00 0
1
2 3
13/12/04
01
10 11
0
1 1
34
13/12/04
35
13/12/04
36
13/12/04
37
13/12/04
38
13/12/04
39
I/O PORTS-INTRODUCTION
General purpose I/O pins can be considered the simplest of peripherals. They allow PIC to monitor and control other devices. To add flexibility and functionality to a device, some pins are multiplexed with an alternate functions that depend on which peripheral features are on the device. In general when a peripheral is functioning that pin may not be used as a general purpose I/O pin.
13/12/04 Accel Software &Technologies Limited 40
I/O PORT
For most ports, the I/O pins direction is controlled by the data direction register called the TRIS register. A1 in the TRIS bit corresponds to the port being an input while a 0 corresponds to that pin being output. The port register is the latch for the data to be output. when port is read the device reads the level present on the I/O pins (not the latch). Reading the port register reads the status of the pins whereas writing to it will write to the port latch.all write operation are read modify write operations. Therefore a write to a port implies that the port pins are read ,this value is modified and then written to the port data latch.
13/12/04 Accel Software &Technologies Limited 41
Dig-gen
13/12/04
42
Adig
13/12/04
45
13/12/04
48
Bdig
13/12/04
49
Cdig
13/12/04
51
PORTD/PORTE
PORTD, PORTE and its registers TRISD, TRISE register are made up of an 8 bit port with Schmitt trigger input buffers.Each pin is individually configurable as an input or output
13/12/04
52
Dig
13/12/04
54
13/12/04
55
dig
13/12/04
56
dig
13/12/04
57
dig
13/12/04
60
13/12/04
61
Dig
13/12/04
62
13/12/04
63
INTERRUPTS
PIC can have many sources of interrupt. These sources generally include one interrupt source for each peripheral module, though some module may generate multiple interrupts (USART). The interrupts are
-INT pin interrupt (external interrupt) -TMR0 overflow interrupt -PORTB change interrupt (pins RB7:RB4)
13/12/04 Accel Software &Technologies Limited 64
INTERRUPTS
Comparator change interrupt Parallel slave port interrupt USART interrupt Receive interrupt Transmit interrupt A/D conversion complete interrupt LCD interrupt Data EEPROM write complete interrupt Timer1 overflow interrupt Timer2 Overflow interrupt CCP interrupt SSP interrupt
Accel Software &Technologies Limited 65
13/12/04
INTERRUPTS
There is one register used in the control and status of the interrupt. The register is INTCON If the device has peripheral interrupt, then it will have registers to enable the peripheral interrupts and registers to hold the interrupt flag bits.
13/12/04
66
INTERRUPTS
Depending on the devices, the registers are:
PIE1 PIR1 PIE2 PIR2 (PIR3,PIE3 could be used for future use)
13/12/04
67
Control Registers
Generally devices have a minimum of three registers associated with interrupts.The INTCON register which contains GIE bit, PEIE bit and the PIE/PIR register pair which enable the peripheral interrupts and display the interrupt flag status. INTCON register
The INTCON register is readable and writeable register which contains various enable and flag bits
13/12/04 Accel Software &Technologies Limited 68
INTCON REGISTER
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
GIE
7 GIE
PEIE(3) TOIE
INTF(2)
RBIF(1,2)
Global Interrupt Enable Bit 1=Enable all unmasked interrupt 0=Disable all interrupts
6 PEIE
Peripheral interrupt enable bit 1=Enable all un-masked peripheral interrupts 0=Disables all peripheral interrupts
TMR0 overflow interrupt enable bit 1=Enable the TMR0 overflow interrupt 0=Disable the TMR0 overflow interrupt
5 TOIE
13/12/04
69
INTCON REGISTER
4 INTE INT External interrupt enable bit 1=Enable the INT external interrupt 0=Disable the INT external interrupt RB Port change interrupt Enable bit 1=Enable the RB port change interrupt 0=Disable the RB port change interrupt TMR0 overflow interrupt flag bit 1=TMR0 register has overflowed(cleared In s/w) 0=TMR0 register did not overflow INT External Interrupt Flag bit 1=The INT external interrupt occurred(cleared in S/W) 0=The INT external interrupt did not occur RB port change interrupt flag bit 1=At least one of the RB7:RB4 pins changed state 0=None of theRB7:RB4 pins have changed state
Accel Software &Technologies Limited 70
3 RBIE(1)
2 T0IF
1 INTF
0 RBIF(1)
13/12/04
PIE REGISTER
Depending on the number of peripheral interrupt sources,there may be multiple PIE registers (PIE1,PIE2) which contains the individual enable bits for the peripheral interrupts. If the device has a PIE register, the PEIE bit must be set to enable any of these peripheral interrupts.
13/12/04
71
PIE1 REGISTER
R/W-0 R/W-0 R/W-0 R/W-0 U-0 R/W-0 PSPIE ADIE
7
6 5 4 3 2 1 0
R/W-0
R/W-0 TMR1IE
RCIE
TXIE
CCP1IE TMR2IE
PSPIE
ADIE RCIE TXIE Un-impl CCP1IE TMR2IE TMR1IE
Parallel Slave Port Read/write interrupt enable bit 1=Enable the PSP read/write interrupt
A/D converter interrupt enable bit 1=Enable the A/D interrupt USART Receive interrupt enable bit 1=Enable the USART receive interrupt USART Transmit interrupt enable bit 1=Enable the USART transmit interrupt Read as 0 CCP1 interrupt enable bit 1=Enable the CCP1 interrupt TMR2 to PR2 match interrupt enable bit 1=Enable the TMR2 to PR2 match interrupt TMR1 Overflow interrupt enable bit 1=Enable the TMR1 overflow interrupt Accel Software &Technologies Limited
13/12/04
72
PIE2 REGISTER
U-0 U-0 U-0 R/W-0 U-0 U-0 U-0 U-0
EEIE
7-5,3-0 Un-impl Read as 0 4 EEIE EEPROM Write operation Interrupt Enable 1=Enable EE write Interrupt
13/12/04
73
PIR1 REGISTER
R/W-0 R/W-0 R-0 PSPIF ADIF
7 PSPIF
R-0
U-0 R/W-0
R/W-0
R/W-0
RCIF TXIF -
Parallel slave port read/write interrupt flag bit 1=A read or a write operation has taken place 0=No read or write occurred
A/D converter Interrupt flag 1=An A/D conversion completed 0=An A/D conversion is not complete USART Receive interrupt enable bit 1=Enable the USART receive interrupt USART Transmit interrupt enable bit 1=Enable the USART transmit interrupt
ADIF
5 4
RCIE TXIE
13/12/04
74
PIR1 REGISTER
3 Un-impl Read as 0 CCP1 Interrupt Flag bit Capture mode 1=A TMR1 Register capture occurred Compare Mode 1=A TMR1 register compare match occurred PWM mode Unused in this mode 2 CCP1IF
1 TMR2I F
TMR2 To PR2 match interrupt flag bit 1=TMR2 to PR2 match occurred
13/12/04
75
PIR2 REGISTER
U-0 7-5,3-0 4 U-0 U-0 Un-impl EEIF R/W-0 EEIF U-0 U-0 U-0 U-0 -
Read as 0 EEPROM Write operation Interrupt Flag bit 1=The write operation is completed
13/12/04
76
INTERRUPT LATENCY
Interrupt latency is defined as the time from the interrupt event (the interrupt flag bit gets set) to the time that the instruction at address 0004h starts execution (when that interrupt is enabled). For synchronous interrupts (internal), the latency is 3TCY and for asynchronous (external) such as the INT or PORT RB change interrupt,the latency is 3-3.75 TCY. The exact latency depends upon when the interrupt event occurs in relation to the instruction cycle.The latency is the same for both 1 and 2 instruction cycle. CONTEXT SAVING DURING INTERRUPT During the interrupt only the return PC value is saved on the stack. POP and PUSH are not instruction mnemonics, but are conceptual actions.
13/12/04 Accel Software &Technologies Limited 77
13/12/04
78
TIMER 0
Features:
8
bit timer/counter Readable and writeable 8 bit software programmable prescaler Clock source selectable to be external or internal Interrupt on overflow from FFh to 00h Edge select for external clock for incrementing the timer. 0-Rising edge.
13/12/04
79
dig
13/12/04
80
TIMER0
Timer mode is selected by clearing bit T0CS (OPTION_REG<5>). In timer mode, Timer0 module will increment every instruction cycle. Counter mode is selected by setting bit T0CS (OPTION_REG<5>). In counter mode, Timer0 will increment either on every rising or falling edge of pin RA4/T0CK1. The incrementing edge is determined by Timer0 source edge select bit T0SE(OPTION_REG<4>). Clearing bit T0SE selects the rising edge.
13/12/04 Accel Software &Technologies Limited 81
TIMER0 Interrupt
The TMR0 interrupt is generated when the TMR0 register overflows from FFh to 00h. This overflow sets bit T0IF (INTCON<2>). The interrupt can be masked by clearing bit T0IE (INTCON<5>). Bit T0IF must be cleared by Timer0 interrupt service routine before re-enabling this interrupt. The TMR0 interrupt cannot awaken the processor from SLEEP since the timer is shut of during SLEEP.
13/12/04
82
Prescaler
A prescaler assignment for Timer0 module means that there is no prescaler for watchdog timer and vice versa. This prescaler is not readable or writeable. The PSA and PS2-PS0 bits (OPTION_REG<3:0) determine the prescaler assignment and prescaler ratio. When assigned to timer0 module, all instructions writing to TMR0 register will clear the prescaler. When assigned to WDT, a CLRWDT instruction will clear prescaler along with watchdog timer.
13/12/04 Accel Software &Technologies Limited 84
RBPU INTEDG
7 RBPU(1)
T0CS
T0SE
PSA
PS2
PS1
PS0
Weak pull up enable bit 1=Weak pull-ups are disabled 0=Weak pull ups are enabled by individual port latch values
Interrupt Edge Select Bit 1= Interrupt on rising edge of INT pin 0=Interrupt on Falling Edge of INT pin TMR0 Clock source Select bit 1=Transition on T0CK1 pin 0=Internal instruction cycle clock(CLKOUT) TMR0 source edge select bit 1=increment on high to low transition on T0CK1 pin 0=increment on low to high transition on T0CK1 pin Prescaler assignment bit 1=Prescaler is assigned to the WDT 0=Prescaler is Accel Software &Technologies assigned to the TIMER0 module
Limited
6 INTEDG
5 T0CS
4 T0SE
3 PSA
13/12/04
85
CONTROL REGISTER
Bit 2:0 Symbol Function PS2:PS0 Prescaler rate select bits Bit value 000 001 010 011 100 101 110 111
13/12/04
TMR0 rate 1:2 1:4 1:8 1:16 1:32 1:64 1:128 1:256
WDT rate 1:1 1:2 1:4 1:8 1:16 1:32 1:64 1:128
86
TIMER1
The Timer1 is a 16-bit timer/counter consisting of two 8-bit registers (TMR1H & TMR1L), which are readable and writeable. The TMR1 register pair increments from 0000h to FFFFh and rolls over to 0000h. The TMR1 interrupt if enabled is generated on overflow latched in interrupt flag bit TMR1F (PIR1<0>). This interrupt can be enabled/disabled by setting/clearing TMR1 interrupt enable bit TMR1E (PIE1<0>).
13/12/04 Accel Software &Technologies Limited 87
TIMER1
Timer1 can operate in two modes: As a timer. As a counter. The operating mode is determined by the clock select bit, TMR1CS (T1CON<1>). In timer mode, Timer1 increments every instruction cycle. In counter mode, Timer1 increments on every rising edge of the external clock input. Timer1 can be enabled/disabled by setting/clearing control bit TMR1ON (T1CON<0>). Timer1 also has an internal reset input.
13/12/04 Accel Software &Technologies Limited 88
T1CON Register
U-0 7-6 5-4 3 2 1
U-0 -
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
R/W-0
TMR1ON
13/12/04
TIMER1
Timer mode: Timer mode is selected by clearing the TMR1CS (T1CON<1>) bit. In this mode, the input clock to timer is Fosc/4. Counter mode: Timer1may operate in asynchronous or synchronous mode depending on the setting of TMR1CS bit.After Timer1 is enabled in counter mode, the module must have a falling edge before the counter begins to increment. Synchronized counter mode: Counter mode is selected by setting bit TMR1CS. In this mode,the timer increments on every rising edge of clock input on pin RC1/T1OSI.If T1SYNC is cleared,then external clock input is synchronized with internal phase clocks.
13/12/04 Accel Software &Technologies Limited 90
TIMER1
Synchronization is done after the prescaler stage.The prescaler stage is an asynchronous ripple counter. A synchronized counter mode: If control bit T1Sync is set,the external clock input is not synchronized.the timer continues to increment asynchronous to the internal phase clocks.the timer will continue to run during SLEEP and can generate an interrupt on overflow,which will wake up the processor.Reading TMR1H or TMR1L while the timer is running from external asynchronous clock will guarantee a valid read.for writes,it is recommended that the user simply stop the timer and write the desired values.
13/12/04
91
TIMER1
Timer1 Oscillator: A crystal oscillator circuit is built in between pins T1OSI and T1OSO.it is enabled by setting control bit T1OSCEN.the oscillator is a low power oscillator rated up to 200khz.It will continue to run during SLEEP.It is primarily intended for use with a 32 kHz crystal.The Timer1 oscillator is identical to the LP oscillator. Resetting timer 1 using CCP1 Trigger Output: If the CCP1 module is configured in compare mode to generate a special event trigger,that will reset Timer1.Timer1 must be configured for either timer or synchronized counter mode to take advantage of this feature.If running in asynchronous counter mode,reset will not work.
13/12/04 Accel Software &Technologies Limited 92
TIMER1
Resetting of Timer1 register pair(TMR1H,TMR1L): TMR1H and TMR1L register are not reset to 00h on a POR or any other reset except by the CCP1 special event trigger.T1CON register is reset to 00h on a POR or a BOR,which shuts off the timer and leaves a 1:1 prescaler.In all other resets,the register is unaffected.
13/12/04
93
TIMER2
Timer2 is an 8-bit timer with a prescaler and a postscaler .it can be used as the PWM time-base for the PWM mode of the CCP modules.The TMR2 register is readable and writable,and is cleared on any device reset.The input clock has a prescale option of 1:1,1:4or 1:16 selected by control bits T2CKPS1:T2CKPS0. The Timer2 module has an 8 bit period register PR2.Timer2 increments from 00h until it matches PR2 and then resets to 00h on the next increments cycle.PR2 is a readable and writable register.
13/12/04 Accel Software &Technologies Limited 94
T2CON register
U-0 R/W-0 TOUTPS3 R/W-0 TOUTPS2 R/W-0 TOUTPS1 R/W-0 TOUTPS0 R/W-0 TMR2ON R/W-0 T2CKPS1 R/W-0 T2CKPS0
7-6 6-3
Unimplemented TOUTPS3-0
Read as 0 Timer 2 output post scale select bits 0000 1:1; 0001 1:2;0010- 1:3..1111-1:16 post scale Timer 2 on bit 0 Timer2 off Timer 2 clock Prescale select bits source select bit 00=Prescaler is 1;01-prescaler is 4,1x=prescaler is 16
T1SYNC
1-0
T2CKPS1-0
13/12/04
95
TIMER2
Timer2 Prescaler and Postscaler: The prescaler and postscaler counter are cleared when any of the following occurs: A write to the TMR2 register A write to the T2COn register Any device reset TMr2 is not cleared when T2CON is written Output of TMR2 The output of TMR2 is fed to the SSPort module,which is optionally used it to generate shift clock.
13/12/04 Accel Software &Technologies Limited 96
dig
13/12/04
97
CAPTURE/COMPARE/PWM MODULE
The capture/compare/PWM module(CCP) contains a 16 bit register which can operate as a : 16 bit Capture register 16 bit compare register PWM master/slave duty cycle register CCP1 module: The CCPR1 is comprised of two 8 bit registers:CCPR1L and CCPR1H.The CCP1CON register controls the operation of CCP1.The special event trigger is generated by a compare match and will reset Timer1 and start A/d conversion
13/12/04 Accel Software &Technologies Limited 98
CCP1CON register
U-0 U-0 R/W-0 7-6 5-4
R/W-0 CCP1Y
R/W-0 CCP1M3
R/W-0 CCP1M2
R/W-0 CCP1M1
R/W-0 CCP1M0
CCP1X
Unimplemented CCP1<X:Y>
Read as 0 PWM least significant bits Capture mode &Compare mode-unused PWM mode-These bits are the two LSBs of the PWM duty cycle.the eight MSBs are found in CCPR1L CCPx mode select bits 0000-CCP off 0100-capture mode,every falling edge 0101- capture mode,every rising edge 0110- capture mode,every 4th rising edge 0111- capture mode,every 16th rising edge 1000-CCP1IF bit is set 1001-CCP1IF bit is set 1010-CCP1IF bit is set,CCP pin is unaffected 1011-CCP1IF bit is set,CCP pin is unaffected(A/D module is enabled) 11xx-PWM mode Accel Software &Technologies 99 Limited
3-0
CCP1M<3:0>
13/12/04
13/12/04
CAPTURE/COMPARE/PWM MODULE
An event is selected by control bits CCP1M<3:0>.when a capture is made the interrupt request flag bit CCP1F is set.The interrupt flag must be cleared in software.If another capture occurs before the value in register CCPR1 is read ,the old capture value will be lost. CCP pin configuration In capture mode the RC2/CCP1pin should be configured as an input by setting the TRISC<2> bit. dig
13/12/04
101
CAPTURE/COMPARE/PWM MODULE
Timer1 mode selection Timer1 must be running in timer mode or synchronized counter mode for the CCP module to use the capture feature.In asynchronous counter mode the capture mode doesnt work. Software interrupt When the capture mode is changed a false capture interrupt may be generated.the user should keep CCP1E(PIE<2>) bit clear to avoid false interrupts and should clear the flag bit CCP1F following any such change in operating mode.
13/12/04 Accel Software &Technologies Limited 102
CAPTURE/COMPARE/PWM MODULE
CCP prescaler
There are 4 prescaler Settings (CCP1M<3:0>).Whenever the CCP module is turned off or the CCP module is not in capture mode,the prescaler counter is cleared.Switching between capture prescaler generates interrupts.
Compare mode
In compare mode the 16 bit CCPR1 register value is constantly compared against the TMR1 register pair value.when a match occurs the RC2/CCp1 pins are:
Driver high Driven Low Remains unchanged
13/12/04 Accel Software &Technologies Limited 103
CAPTURE/COMPARE/PWM MODULE
CCP pin configuration The user must configure the RC2/CCp1 pin as an output byclearing the TRISC<2>bit. Timer1 mode selection Timer1 must be running in timer mode or synchronized counter mode. Software interrupt mode When generate software interrupt mode is chosen,the CCp1 pin is not affected.The CCP1F bit is set causing a CCP interrupt. Special event trigger Here internal hardware trigger is generated.special event trigger output of CCP1 resets the TMR1 register pair and starts A/D conversion.
13/12/04 Accel Software &Technologies Limited 104
CAPTURE/COMPARE/PWM MODULE
PWM mode In pulse width modulation the CCP1 pin produces upto a 10bit resolution PWM output.Since the CCP1 pin is multiplexed with the PORTC data latch,the TRISC<2> bit must be cleared to make CCP1 pin an output. PWM output PR2=Fosc /4*Fpwm*TMR2Prescale value 1 PWM duty cycle =(CCPR1L:CCP1CON<5:4>*Tosc*(TMR2 prescale value) Resolution=Log(Fosc/Fpwm)/Log(2) bits
13/12/04 Accel Software &Technologies Limited 105
dig
13/12/04
106
dig
13/12/04
107
USART
The USART is one of the two serial I/O module and is also know n as serial communication interface or SCI. The USART can be configured as a full duplex asynchronous system that can communicate with peripheral devices such as CRT terminals and personal computers or it can be configured as a half duplex synchronous system that can communicate with peripheral devices such as A/D or D/A integrated circuits, serial EEPROMs.
13/12/04 Accel Software &Technologies Limited 108
USART
The USART can be configured in the following modes: -Asynchronous(full duplex) -Synchronous-master(half duplex) -Synchronous-slave(half duplex) The USART module also has a multiprocessor communication capabilities using 9-bit address detection.
13/12/04 Accel Software &Technologies Limited 109
CONTROL REGISTERS
RCSTA-Receive status and control registers(add-98h)
R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R-1 R/W-0
SPEN
7 SPEN 6 RX9
RX9
SREN
CREN ADDEN
FERR
OERR
RX9D
Serial port Enable bit 1=Serial port enabled 9-bit Receive Enable bit 1=Select 9-bit reception 0=Select 8-bit reception
5 SREN
Single receive Enable bit Asynchronous mode,dont care, Synchronous master 1=Enable single receiver This bit is cleared after reception is complete Synchronous mode-slave unused in this mode
4 CREN Continuous Receive enable bit Asynchronous mode 1=Enable continuous receive Synchronous mode 1=Enable continuous receive until enable bit CREN iscleared
13/12/04 Accel Software &Technologies Limited 110
CONTROL REGISTERS
3
ADDEN Address detect enable bit Asynchronous mode 9-bit (RX9=1) 1=Enable address detection,enable interrupt and load of the receive buffer when RSR<8> is set 0=Disable address detection,all the bytes are received and 9th bit can be used as parity bit FERR Framing Error bit 1=Framing error 0=NoFraming error 0=No overrun error
2 1
0
OERR
RX9D
13/12/04
111
CONTROL REGISTERS
TXSTA-Transmit status and control registers(add 98h) R/W-0 R/W-0 R/W-0 R/W-0 R-0 CSRC
7 CSRC
R-0 TRMT
R-X TX9D
TX9
TXEN
SYNC
BRGH
Clock source select bit Asynchronous mode dont care Synchronous 1=Master mode(clock generated internally from BRG) 0=Slave mode(Clock from external source)
6
5 4 3 2 1 0
TX9
TXEN SYNC Unimpl BRGH TRMT 13/12/04 TX9D
0=Low speed
Transmit shift register status bit 1=TSR empty 0=TSR full Accel Software &Technologies 9th bit of transmit data,can be a parity bit Limited
112
0 1
(ASYN)BR=Fosc/64(X+1)) (SYN)BR=Fosc/4(X+1))
BR=Fosc/16(X+1)) NA
13/12/04
dig
13/12/04
116
dig
13/12/04
117
dig
13/12/04
119
Dig
13/12/04
120
13/12/04
122
13/12/04
123
Dig
13/12/04
124
dig
13/12/04
125
dig
13/12/04
126
dig
13/12/04
128
dig
13/12/04
129
dig
13/12/04
131
A/D module
The A/D converter module has five to eight inputs depending on the PIC. The A/D converter has a unique feature of being able to operate while the device is in SLEEP mode The A/D module has four registers are: A/D Result High Register(ADRESH) A/D Result Low Register(ADRESL) A/D Control Register0 (ADCON0) A/D Control Register1 (ADCON1) The ADCON0 register controls the operation of A/D module. The ADCON1 register configures the functions of port pins. The ADRESH/ADRESL registers contain the 10-bit result of A/D conversion. When the conversion is complete the result is loaded in A/D result register pair, the GO/DONE bit is cleared and the A/D interrupt flag is set.
13/12/04 Accel Software &Technologies Limited 134
ADCON0 Register
R/W-0 ADCS1 7-6 R/W-0 ADCS0 R/W-0 CHS2 R/W-0 CHS1 R/W-0 CHS0 R/W-0 GO/DONE U-0 R/W-0 ADON ADCS1-ADCS0 A/D conversion clock selection bits 00=Fosc/2 01=Fosc/8 10=Fosc/32 11=FRC(clock derived from an RC oscillation) 5-3 2 CHS2-CHS0 GO/DONE Analog Channel select bits A/D conversion status bit 1=A/D conversion in progress 0=A/D conversion not in progress Read as 0 A/D On bit 1=A/D converter module is operating 0=A/D converter module is shutoff and consumes no operating current.
Accel Software &Technologies Limited 135
1 0
Unimpl ADON
13/12/04
ADCON1 REGISTER
U-0 ADFM U-0 R/W-0 U-0 R/W-0 PCFG3 R/W-0 PCFG2 R/W-0 PCFG1 R/W-0 PCFG0
ADFM
A/D Result format select 1=Right justified.6 most significant bits of ADRESH are read as 0.
13/12/04
136
A/D conversion
Configure the A/D module Configure analog pins / voltage reference / and digital I/O (ADCON1). Select A/D input channel(ADCON0). Select A/D conversion clock(ADCON0) Turn on A/D module(if desired). Configure A/D interrupt(if desired) Clear ADIF bit Set ADIE bit Set GIE bit Wait the required acquisition time
13/12/04 Accel Software &Technologies Limited 137
A/D conversion
Start conversion: -Set GO/DONE bit (ADCON0) Wait for A/D conversion to complete , by either -Polling for the GO/DONE bit to be cleared Or Waiting for the A/D interrupt. Read A/D result register pair (ADRESH - ADRESL), clear bit ADIF if required. For next conversion, go to step1 or step 2 as required. The A/D conversion time per bit is defined as TAD. A minimum wait of 2TAB is required before next acquisition starts.
13/12/04 Accel Software &Technologies Limited 138
CONFIGURATION WORD
CP1 CP0 DEBUG WRT CPD LVP BODEN CP1 CP0 PWRTE WDTE FOSC1 FOSC0
13-12 5-4 CP1:0 Flash Program Memory code protection 11-Code protection off 10-Not Supported 01-Not supported 00-Code Protection In circuit Debugger mode 1-In circuit debugger disabled,RB6 and RB7 are general purpose I/O pins 0-In circuit debugger disabled,RB6 and RB7 are general purpose I/O pins Read as 1 Flash Program Memory Write Write Enable 1=Unprotected program memory may be written to by EECON control
11
DEBUG
10 9
Unimple WRT
13/12/04
141
CONFIGURATION WORD
8 CPD Data EE Memory Code protection 1=Code protection off 0=Data EEPROM memory code protected. Low voltage in circuit serial programming enable bit 1=RB3/PGM pin has PGM function ,low voltage program enabled 0=RB3 is digital I/O,HV on MCLR must be used for programming Brown out reset enable bit 1= BOR enabled 0= BOR disabled Power up timer enable bit 1= PWRT disabled 0=PWRT Enabled
LVP
6 3 2
BODEN PWRTE
WDTE
watch dog timer enable bit 1=WDT enabled 0=WDT disabled 11-RC oscillator 01=XT oscillator 10=HS oscillator 00=LP oscillator
142
13/12/04
OSCILLATOR CONFIGURATION
Oscillator types: It can be operated in four different oscillator Modes. The user can program two configuration bits (FOSC1, FOSC0), to Select one of these modes.
LP- low power crystal XT-Crystal /resonator HS-High speed crystal/resonator RC-Resistor/Capacitor
In XT, LP or HS modes a crystal or ceramic resonator is connected to the OSC1/CLKIN and OSC2/CLKOUT pins to establish oscillation.
13/12/04 Accel Software &Technologies Limited 143
Dig
13/12/04
144
RC OSCILLATOR
RC oscillator frequency is a function of supply voltage, the resistor (REXT) and Capacitor (CEXT) values and the operating temperature. The user need to take account variation due to tolerance of external R and C components used.
13/12/04
145
dig
13/12/04
146
RESET
Kinds of RESET:
Power on reset (POR) MCLR reset during normal operation MCLR reset during SLEEP WDT reset (during normal operation) WDT wakeup (during SLEEP) Brown out reset (BOR)
13/12/04
147
RESET
Some registers are not affected in any reset conditions. Their status is unknown on POR and unchanged in any other reset. Most other registers are reset to a reset state on POR, on the MCLR and WDT reset, on MCLR reset during SLEEP, and BOR. They are not affected by a WDT wakeup which is viewed as the resumption of normal operation. The TO and PD bits are set or cleared differently in different resets. These devices have a MCLR noise filter in the MCLR reset path. The filter will detect and ignore small pulses. WDT reset does not drive MCLR pin low.
13/12/04 Accel Software &Technologies Limited 148
POR
A POR pulse is generated on-chip when VDD rise is detected. POR pin ties MCLR directly to VDD that would eliminate external RC components usually needed to create a POR. When the device starts normal
PWRT
The PWRT provides a fixed 72ms nominal timeout on power up only from POR The chip is kept active as long as the PWRT is active. A configuration bit is provides to enable/disable the PWRT. The PWRT time delay will vary from chip to chip due to VDD, temperature and process variation.
13/12/04 Accel Software &Technologies Limited 150
OST
The OST provides 1024 oscillator cycle delay after the PWRT delay is over. This ensures that the crystal oscillator or resonator has started and stabilized. The OST time-out is involved only for XT, LP and HS modes and only on power on reset or wake up from SLEEP.
13/12/04
151
BOR
The configuration bit BODEN can enable or disable the BOR.
13/12/04
152
DATA EEPROM
The data EEPROM and FLASH program memory are readable and writeable during normal operation over the entire VDD range. The data memory is not directly mapped in the register file space.
13/12/04
153
DATA EEPROM
There are six SFRs used to read and write the program and data EEPROM memory.
EECON1 EECON2 EEDATA EEDATH EEADR EEADRH
13/12/04
154
DATA EEPROM
The EEPROM data memory allows bytes read and write. When interfacing to the data memory block, EEDATA holds the 8-bit data for read/write and EEADR holds the address of the EPROM location being accessed. The registers EEDATH and EEADRH are not used for data EEPROM access. These devices have 64bytes of data EEPROM with an address range from 0h to 3Fh.
13/12/04 Accel Software &Technologies Limited 155
DATA EEPROM & FLASH PROGRAM MEMORY The PIC16F870/871 devices have 2K words of program FLASH with an address range from 0h to 7FFh. The unused upper bits in both the EEDATH and EEDATA registers all read as 0s. The value written to program memory does not need to be a valid instruction.
13/12/04
158
EEADR
The address registers can address up to a maximum of 256 bytes of data EEPROM or up to a maximum of 8K words of program FLASH. When selecting a program address value, the MSB byte of the address is in EEADRH register and LSB byte register is in EEADR register. When selecting a data address value, only the LSByte of the address is written to the EEADR register
13/12/04 Accel Software &Technologies Limited 159
13/12/04
161
EECON1 REGISTER
R/W-X U-0 U-0 U-0 R/W-X R/W-0 R/W-0 R/W-0 RD EEPGD 7 EEPGD
WRERR WREN WR
Program/ Data EEPROM select bit 1=Accesses Program memory 0=Accesses data memory EEPROM Error Flag Bit 1=A write operation is prematurely terminated 0=The write operation is complete EEPROM write enable bit 1=Allow write cycle 0= Inhibits write to the EEPROM Write control bit 1=Initialize a write cycle0=Write cycle to the EEPROM is complete Read control bit 1=Initialize an EEPROM read RD is cleared in H/W.The RD bit can only be set in S/W 0=Does not initialize an EEPROM read
Accel Software &Technologies Limited 162
2 1 0
WREN WR RD
13/12/04
INSTRUCTIONS
ADDLW add literal and W Syntax [label] ADDLW K Operands: 0<=k<=255 Operation: (w)+k->(w) Status affected: C,DC,Z Description: The contents of the W register are added to the eight bit literal k and the result is placed in the w register. ADDWF add W and F Syntax [label] ADDWF f,d Operands: 0<=f<=127 ; d[0,1] Operation: w+f->destination Status affected: C,DC,Z Description: The contents of the W register are added to register f.If d is 0 the result is stored in W register else in F register.
13/12/04 Accel Software &Technologies Limited 167
INSTRUCTIONS
ANDLW and literal and W Syntax [label] ANDLW K Operands: 0<=k<=255 Operation: (w) AND k->(w) Status affected: C,DC,Z Description: The contents of the W register are ANDed to the eight bit literal k and the result is placed in the w register. ANDWF and W and F Syntax [label] ANDWF f,d Operands: 0<=f<=127 ; d[0,1] Operation: w AND f->destination Status affected: C,DC,Z Description: The contents of the W register are ANDed to register f.If d is 0 the result is stored in W register else in F register.
13/12/04 Accel Software &Technologies Limited 168
INSTRUCTIONS
BCF Bit clear F Syntax [label]BCF f,b Operands 0<=f<=127 ;0<=b<=7 Operation: 0->(f<b>) Status affected none Description: bit b in register f is cleared BSF Bit set F Syntax [label]BSF f,b Operands 0<=f<=127 ;0<=b<=7 Operation: 0->(f<b>) Status affected none Description: bit b in register f is set
13/12/04
169
INSTRUCTIONS
BTFSS bit test f,Skip if Set Syntax: [label]BTFSS f,b Operands: 0<=f<=127 ;0<=b<7 Operation: skip if (f<b>)=1 Status affected none Description: If b in register f is 0,next instruction is executed.if b is 1 the next instruction is discarded and a NOP is executed instead making this a 2TCY instruction. BTFSC bit test f,Skip if Clear Syntax: [label]BTFSC f,b Operands: 0<=f<=127 ;0<=b<7 Operation: skip if (f<b>)=1 Status affected none Description: If b in register f is 0,next instruction is executed.if b is 1 the next instruction is discarded and a NOP is executed instead making this a 2TCY instruction
13/12/04 Accel Software &Technologies Limited 170
INSTRUCTIONS
CALL Syntax: operands Operation: Status affected Description: the stack. CLRF Syntax: Operands: Operation: Status affected: Description:
13/12/04
call subroutine [label] call k 0<=k<=2047 (PC)+1->TOS;k->PC<10:0>;(PCLATH<4:3>)>PC<12:11> none call subroutine,First return address(PC+1) is pushed onto clear F [label]CLRF f 0<=f<=127 00h->f 1->Z Z the contents of register f are cleared and the Z bit is set.
Accel Software &Technologies Limited 171
INSTRUCTIONS
CLRW clear W Syntax: [label]CLRW Operands: 0<=f<=127 Operation: 00h->f 1->Z Status affected: Z Description: the contents of register W are cleared and the Z bit is set. CLRWDT clear Watch dog timer Syntax: [label]CLRWDT Operands: none Operation: 00h->WDT,0->WDT prescaler,1->TO,1->PD Status affected: TO,PD Description: this resets the WDT and its prescaler of the WDT.Status bits TO & PD are set.
13/12/04 Accel Software &Technologies Limited 172
INSTRUCTIONS
COMF Complement f Syntax [label] COMF f Operands: 0<=f<=127 ; d[0,1] Operation: f->destination Status affected: Z Description: The contents of the f register are complemented.If d is 0 the result is stored in W register else in F register. DECF Decrement f Syntax [label] DECF f,d Operands: 0<=f<=127 ; d[0,1] Operation: f 1 ->destination Status affected: Z Description: The contents of the f register are decremented.If d is 0 the result is stored in W register else in F register.
13/12/04 Accel Software &Technologies Limited 173
INSTRUCTIONS
DECFSZ Decrement f,skip if 0 Syntax [label] DECFSZ f,d Operands: 0<=f<=127 ; d[0,1] Operation: f 1 ->destination;skip if result=0 Status affected: none Description: The contents of the f register are decremented.If d is 0 the result is stored in W register else in F register.If the result is 1 the next instruction is executed,if 0 and a NOP is executed instead making this a 2TCY instruction. GOTO Unconditional branch Syntax: [label] GOTO k operands 0<=k<=2047 Operation: k->PC<10:0>;(PCLATH<4:3>)>PC<12:11> Status affected none Description: The eleven bit immediate value is loaded into PC bits<10:0>The upper bits of PC are loaded from PCLATH <4:3>.GOTO is a two cycle instruction.
13/12/04 Accel Software &Technologies Limited 174
INSTRUCTIONS
INCF increment f, Syntax [label] INCF f,d Operands: 0<=f<=127 ; d[0,1] Operation: f 1 ->destination Status affected: Z Description: The contents of the f register are incremented.If d is 0 the result is stored in W register else in F register. INCFSZ Increment f,skip if 0 Syntax [label] INCFSZ f,d Operands: 0<=f<=127 ; d[0,1] Operation: f 1 ->destination;skip if result=0 Status affected: none Description: The contents of the f register are incremented.If d is 0 the result is stored in W register else in F register.If the result is 1 the next instruction is executed,if 0 and a NOP is executed instead making this a 2TCY instruction.
13/12/04 Accel Software &Technologies Limited 175
INSTRUCTIONS
IORLW Inclusive OR literal with W Syntax [label] IORLW K Operands: 0<=k<=255 Operation: (w) OR k->(w) Status affected: Z Description: The contents of the W register are ORed to the eight bit literal k and the result is placed in the w register. IORWF Inclusive OR W with F Syntax [label] IORWF f,d Operands: 0<=f<=127 ; d[0,1] Operation: w OR f->destination Status affected: Z Description: The contents of the W register are ORed to register f.If d is 0 the result is stored in W register else in F register
13/12/04 Accel Software &Technologies Limited 176
INSTRUCTIONS
MOVF move f Syntax [label] MOVF f,d Operands: 0<=f<=127 ; d[0,1] Operation: f->destination Status affected: Z Description: The contents of the f register are moved to destination dependent upon the status of d. If d is 0 the result is stored in W register else in F register.
MOVLW move literal and W Syntax [label] MOVLW K Operands: 0<=k<=255 Operation: k->(w) Status affected: C,DC,Z Description: the eight bit literal k is loaded into W register .Dont cares are treated as zero.
13/12/04 Accel Software &Technologies Limited 177
INSTRUCTIONS
MOVWF move W to F Syntax [label] MOVWF f Operands: 0<=f<=127 Operation: (w)->f Status affected: none Description: move data from W register to register f. NOP NO operation Syntax [label] NOP Operands: none Operation: none Status affected: none Description: NO operation
13/12/04
178
INSTRUCTIONS
RETFIE Return from interrupt Syntax [label] RETFIE Operands: none Operation: TOS->PC,1->GIE Status affected: none RETLW Return with literal in W Syntax [label] RETLW k Operands: 0<=k<=255 Operation: k->W; TOS->PC Status affected: None Description: The W register is loaded with the eight bit literal k.The program counter is loaded from the top of the stack(the return address ) this is two cycle instruction.
13/12/04 Accel Software &Technologies Limited 179
INSTRUCTIONS
RETURN Return from subroutine Syntax [label] RETURN Operands: None Operation: TOS->PC Status affected: None Description: Return from subroutine.the stack is POPed and the top of the stack (TOS) is loaded into the program counter.this is two cycle instruction. RLF Rotate left through carry Syntax [label] RLF f,d Operands: 0<=f<=127 ;d[0,1] Status affected: C Description: the contents of register f are rotated one bit to the left through the carry Flag.If d is 0 the result is placed in W register or in f register
13/12/04 Accel Software &Technologies Limited 180
INSTRUCTIONS
RRF Rotate right through carry Syntax [label] RRF f,d Operands: 0<=f<=127 ;d[0,1] Status affected: C Description: The contents of register f are rotated one bit to the right through the carry Flag.If d is 0 the result is placed in W register or in f Register. SLEEP Return from subroutine Syntax [label] SLEEP Operands: None Operation: 00h->WDT;0->WDT prescaler;1->TO;0->PD; Status affected: TO,PD Description: The power down status bit,PD is cleared.Time out status bit TO Is set.WDT and its prescaler are cleared.The processor is put into SLEEP mode with the oscillator stopped.
13/12/04
181
INSTRUCTIONS
SUBLW subtract literal and W Syntax [label] SUBLW K Operands: 0<=k<=255 Operation: k-w->(w) Status affected: C,DC,Z Description: The contents of the W register are subtracted to the eight bit literal k and the result is placed in the w register. SUBWF Subtract W and F Syntax [label]SUBWF f,d Operands: 0<=f<=127 ; d[0,1] Operation: f-W->destination Status affected: C,DC,Z Description: The contents of the W register are subtracted to register f.If d is 0 the result is stored in W register else in F register.
13/12/04 Accel Software &Technologies Limited 182
INSTRUCTIONS
XORLW Exclusive OR literal with W Syntax [label] XORLW K Operands: 0<=k<=255 Operation: (w) XOR k->(w) Status affected: Z Description: The contents of the W register are XORed to the eight bit literal k and the result is placed in the w register. XORWF Exclusive OR W with F Syntax [label] XORWF f,d Operands: 0<=f<=127 ; d[0,1] Operation: w XOR f->destination Status affected: Z Description: The contents of the W register are XORed to register f.If d is 0 the result is stored in W register else in F register.
13/12/04 Accel Software &Technologies Limited 183
INSTRUCTIONS
SWAPF Swap Nibbles in f Syntax [label] SWAPF f,d Operands: 0<=k<=127; d[0,1] Operation: (f<3:0>->(destination<7:4>);(f<7:4>)->(destination<3:0>) Status affected: none Description: The upper and lower nibbles of register f are exchanged. If d is 0 the result is stored in W register else in F register.
13/12/04
184