






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







The PIC16C57 is an EEPROM/ROM based 8-bit CMOS Microcontroller. It contains a Reduced Instruction Set Computer (RISC) based Central Processing Unit (CPU) with only 33 single word instructions. All instructions are fetched and executed within a single cycle except for program branches which take up 2 cycles. The maximum operating frequency is 40MHz.
The PIC15C57 microcontroller uses a 2 stage pipelined Harvard architecture in which program and data are accessed using independent buses. This architecture enables instructions to be fetched in one cycle. While program memory is being accessed, data memory is on an independent bus and can be read and written. This improves bandwidth over the traditional von Neumann architecture where program and data are fetched on the same bus. The von Nuemann architecture requires more accesses across the bus to fetch the instruction and the data will then need to be operated on and possibly written back. This makes the bus extremely conjested. With the Harvard architecture, instruction opcodes are 12 bits wide while data word is 8-bits wide. With the addition of the pipeline stages, the fetch and execution cycle are allowed to overlap.
The microcontroller contains an 8-bit Arithmetic Logic Unit (ALU) and working register. This device is an accumulator-based architecture whereby one of the operands is implicitly in the accumulator (also called the working register, W). The ALU performs arithmetic and boolean functions between the data in the working (W) register and any register file. The W register is an 8-bit working register used for ALU operations and is not an addressable register. Figure 1 shows the block diagram of the PIC16C57.
The clock for the system is obtained from an external memory component called an “oscillator”. The clock enters the microcontroller and will be then divided into four non- overlapping clocks which make up one instruction cycle, during which one instruction is executed. With the pipeline stages, the execution of instructions start by calling an instruction that is next in line. Fetching, decoding and execution of this instruction will then be done during the next instruction cycle. Figure 2 shows the Clock/Instruction cycle for the microcontroller.
FIGURE 1. PIC16C57 architecture block diagram.
FIGURE 2. Clock/Instruction cycle.
The following diagram (Figure 4) shows the comparison between an unpipelined proces- sor and a pipelined one:
FIGURE 4. Unpipelined vs Pipelined processor
1 instruction in 2 clock periods have been reduced to 1 instruction in 1 clock period. Therefore throughput have been increased from :
Computer Operation Codes (Opcode)
The first step of a design of a microcontroller is to determine the type of operations it has to perform. The operation code is part of the instruction set and essentially encodes all the functions of the microcontroller, thus providing a unique code for each necessary operation. Figure 5 shows the instruction set (opcodes + operands) and the operations that the PIC16C57 can perform.
throughput instructions time
CPI ( Clocks cycles per instruction ) = 2
throughput ( unpipelined ) 1 2 T
CPI ( Clocks cycles per instruction ) = 1
throughput ( pipelined ) 1 T
instruction number
clock period number
1 2 3 i i+
Fetch (i) Decode + Execute(i) Fetch (i+1) unpipelined
instruction number
i
i+
Fetch (i) Decode + Execute (i)
Fetch (i+1)
pipelined
Fetch (i+1) (^) Decode + Execute(i+1)
FIGURE 5. Instruction set (opcode+operands) for the PIC16C
Central Processing Unit (CPU)
The CPU is the brain of the microcontroller which is responsible for locating and fetching the correct instruction, decoding it and executing it. This unit connects all parts of the microcontroller through an 8-bit data bus and a 5-bit address bus and determines the transfer of data from one location to another within the microcontroller via the controller. The main components of the CPU are the Program Counter (PC), the Instruction Register (IR) , the Register File and the Arithmetic Logic Unit (ALU).
The Arithmetic Logic Unit (ALU) is the ‘core’ of any processor which performs the calcula- tions (arithmetic, boolean and shifts) on the operands. The ALU is bascially a number- crunching mechanicsm which computes the results based on the control signals provided to it by the opcode part of the instruction set. The opcode is used to select between the the arithmetic, boolean or shift operations. Figure 8 shows the block diagram of the ALU. Depending on the type of operation performed by the ALU, the status register will be affected.
FIGURE 8. Block diagram of ALU.
Register File
Highest level of the memory hierarchy which is determined by the data memory. The data memory is actually divided into 2: Special Function Registers (SPRs) and General Pur- pose Registers (GPRs). In the case of the PIC16C57, there are 8 SPRs and 24 GPRs which are 8-bits wide. SPRs are registers used by the CPU and peripheral functions to control the operation of the device.
The Register File for the PIC16C57 is a single port memory device which is implemented using Static Random Access Memory (SRAM) technology. Figure 9 shows the register file block diagram for the PIC16C57.
FIGURE 9. Register file block diagram
INDF TMR PCL STATUS FSR PORT A PORT B
24 GPRs
8 SPRs
PORT C
ALU
to and from W register from register
to status register
I/O Ports
Ports refer to a group of pins on a microcontroller which can be accessed simultaneously, or on which we set the desired combination of zeros and ones, or read from them an existing status. They represent the connection of the CPU and the outside world. The ports are basically I/O registers which can be read and written under program control. There are 16 fully programmable I/O’s on the PC16C57 which can be used interchange- bly for both input and output. Figure 10 shows the equivalent circuit for a single I/O pin.
The Output Driver Control Registers are loaded with the contents of the W register by executing the TRIS f instruction. A ‘1’ from a TRIS register bit puts the corresponding out- put driver in a hi-impedance state (input mode). A ‘0’ puts the contents of the output data latch on the selected pins, enabling the output buffer.
FIGURE 10. I/O pin
Memory organization
The micrcontroller is divided into program memory and data memory. The PIC16C57 has 2K x 12 program memory space and is accessed using a paging scheme. The program memory pages are accessed using one or two STATUS register bits. Figure 5 shows the program memory map for the microcontroller. The data memory consists of 32 registers (8 SPRs and 24 GPRs).
For bit-oriented instructions, ‘b’ represents a bit field designator which selects the number of the bit affected by the operation, while ‘f’ represents the number of the file in which the bit is located. Figure 6 shows the general format for a bit-oriented instruction.
FIGURE 13. Bit-oriented file register operations
For literal and control operations, ‘k’ represents an 8 or 9-bit constant or literal value. Fig- ure 7 shows the general format for literal and control instructions.
FIGURE 14. Literal and control operations
Instruction Examples
Consider the instruction to add the contents of the W register with the contents of the ‘f’ register. If ‘d’ = ‘0’, then the result will be stored in the W register. If ‘d’=’1’, then the results will be stored back in the register designated by ‘f’.
1) ADDWF f, d
Operation: (W) + (f) --> (dest)
Encoding: 0001 11df ffff
Example: ADDWF TEMP_REG, 0
Before instruction: W = 0x17 h
TEMP_REG = 0xC2 h
After instruction: W = 0xD9 h
TEMP_REG = 0xC2 h
In example 2 below, the contents of the W register are AND’ed with the eight-bit literal ‘k’. The result is then placed in the W register.
2) ANDLW k
Operation: (W).AND.(k) --> (W)
Encoding: 1110 kkkk kkkk
Example: ANDLW H’ 5F’
Before instruction: W = 0xA3 h
After instruction: W = 0x03 h
In example 3 below, the contents of the W register are AND’ed with register ‘f’. If ‘d’ = ‘0’, the result is stored in the W register. If ‘d’ = ‘1’, the result is stored back in register ‘f’.
3) ANDWF f,d
Operation: (W) .AND. (f) --> (dest)
Encoding: 0001 01df ffff
Example: ANDWF TEMP_REG, 1
Before instruction: W = 0x17 h
TEMP_REG = 0xC2 h
After instruction: W = 0x17 h
TEMP_REG = 0x02 h