The document provides information about PIC microcontrollers including their history, architecture, features, and programming. It discusses that PIC was developed in 1975 to improve I/O performance. Key points include:
- PIC uses Harvard architecture with separate memory for program and data.
- Features include baseline, mid-range, enhanced mid-range, and PIC18 models with varying complexity and peripherals.
- Programming involves setting I/O ports and individual pins as input or output using SFR registers like PORT, TRIS, and LAT.
- Timers can generate delays or count external events using internal or external clocks. Serial communication transfers data one bit at a time through a single pin.
2. Contents
❖ History and Features
❖ Architecture
❖ Pipelining
❖ Pin Diagram of PIC18F458
❖ I/O port pins and their functions
❖ PIC18 Configuration Registers
3. History and Development
❖ PIC stands for Peripheral Interface Controller.
❖ The PIC microcontroller was developed by General Instruments in 1975.
PIC was developed when Microelectronics Division of General Instruments
was testing its 16- bit CPU CP1600. Although the CP1600 was a good CPU
but it had low I/O performance.The PIC controller was used to offload the
I/O tasks from CPU to improve the overall performance of the system.
❖ In 1985, General Instruments converted their Microelectronics Division to
MicrochipTechnology.The General Instruments used the acronyms
Programmable Interface Controller and Programmable Intelligent
Computer for the initial PICs (PIC1640 and PIC1650).
❖ In 1993, MicrochipTechnology launched the 8-bit PIC16C84 with EEPROM
which could be programmed using serial programming method.The
improved version of PIC16C84 with flash memory (PIC18F84 and
PIC18F84A) hit the market in 1998.
4. History and Development
❖ Since 1998, MicrochipTechnology continuously developed new
high performance microcontrollers with new complex architecture
and enhanced in-built peripherals
❖ PIC microcontroller is based on Harvard architecture.
❖ At present PIC microcontrollers are widely used for industrial
purpose due to its high performance ability at low power
consumption.
❖ It is also very famous among hobbyists due to moderate cost and
easy availability of its supporting software and hardware tools like
compilers, simulators, debuggers etc.
5. Features of PIC Microcontrollers
The 8-bit PIC microcontroller is divided into following four
categories on the basis of internal architecture:
1. Baseline PIC
2. Mid-Range PIC
3. Enhanced Mid-Range PIC
4. PIC18
6. Features of PIC Microcontrollers
1. Baseline PIC
❖ Base Line PICs are the least complex PIC microcontrollers.
❖ These microcontrollers work on 12-bit instruction
architecture which means that the word size of instruction
sets are of 12 bits for these controllers.
❖ These are smallest and cheapest PICs, available with 6 to 40
pin packaging.
❖ The small size and low cost of Base Line PIC replaced the
traditional ICs like 555, logic gates etc. in industries.
7. Features of PIC Microcontrollers
2. Mid-Range PIC
❖ Mid-Range PICs are based on 14-bit instruction architecture
and are able to work up to 20 MHz speed.
❖ These controllers are available with 8 to 64 pin packaging.
These microcontrollers are available with different
peripherals like ADC, PWM, Op-Amps and different
communication protocols like USART, SPI, I2C (TWI), etc.
which make them widely usable microcontrollers not only
for industry but for hobbyists as well.
8. Features of PIC Microcontrollers
3. Enhanced Mid-Range PIC
❖ These controllers are enhanced version of Mid-Range core.
❖ This range of controllers provides
➢ additional performance,
➢ greater flash memory
➢ high speed
➢ very low power consumption.
❖ This range of PIC also includes multiple peripherals and
supports protocols like USART, SPI, I2C and so on.
9. Features of PIC Microcontrollers
4. PIC18
❖ PIC18 range is based on 16-bit instruction architecture
incorporating advanced RISC architecture which makes it
highest performer among the all 8-bit PIC families.
❖ The PIC18 range is integrated with new age communication
protocols like USB, CAN, LIN, Ethernet (TCP/IP protocol) to
communicate with local and/or internet based networks.
❖ This range also supports the connectivity of Human Interface
Devices like touch panels etc.
10.
11. ❖ Besides 8-bit microcontrollers, Microchip also
manufactures 16-bit and 32-bit
microcontrollers.
❖ Recently Microchip developed XLP (Extreme
Low Power) series microcontrollers which are
based on NanoWatt technology.
❖ These controllers draw current in order of
nanoamperes(nA).
12. Memory variations:
The PIC microcontrollers are available with different memory options
which are mask ROM, EPROM and flash memory.They are denoted with
different symbols as given in the following table:
13. Architecture:
❖ Advanced RISC Architecture
➢ RISC stands for Reduced Instruction Set Computing.
● the instruction set of hardware gets reduced
● increases the execution rate (speed) of system.
❖ Harvard Architecture
➢ There are two separate memories for program and data.
➢ These two memories are accessed through different buses for
data communication between memories and CPU core.
➢ This architecture improves the speed of system over Von
Neumann architecture in which program and data are fetched
from the same memory using the same bus.
15. PIC18 Harvard Architecture
● The above process occurs in a single machine cycle.
● In PIC microcontroller, a single machine cycle consists of 4 oscillation
periods.
● Thus an instruction needs 4 clock periods to be executed.
● This makes it faster than other 8051 microcontrollers.
16. Pipelining:
❖ Early processors and controllers could fetch or execute a single
instruction in a unit of time.
❖ The PIC microcontrollers are able to fetch and execute the instructions in
the same unit of time thus increasing their instruction throughput.
❖ This technique is known as instruction pipelining where the processing of
instructions is split into a number of independent steps.
19. I/O Port Pins : Functions
❖ Port pins vary, depending upon CHIP
❖ e.g. 18pin PIC18 has Ports A and B only
20. Not all ports have 8 pins
❖ Port A has 7 pins
❖ Ports B,C and D each have 8 pins
❖ Port E has only 3 pins
I/O Functions of PIC18
21. Each Port has 3 SFRs
❖ PORTx,TRISx, LATx
❖ TRIS stands forTRIState
❖ LAT stands for Latch
I/O Functions of PIC18
22. ❖ Input / output to be programmed
❖ Each PORT has some other function, ADC,Timers etc
❖ Each PORT has three SFRs (PORTx,TRISx, LATx)
❖ TRIS: TRIState; LAT: LATch
❖ Upon “RESET”,TRIS is ‘1’ i.e. all input port
I/O Port Pins : Functions
TRIS register: Role in outputting DATA
❖ Each PORT can be input/output
❖ TRIS used to define port input/output
❖ output data:TRIS is ‘0’; input data:TRIS is ‘1’
❖ WithoutTRIS, no DATA is processed at PORT
23.
24. Write a C18 program to send values 00-FF to PORT B
#include<PIC18F458.h>
Void main(void)
{
Unsigned char z;
TRISB =0; // make Port B an output
While (1)
{
For(z=0;z<=255;z++)
PORTB = z;
}
}
25. Write a C18 program to toggle all the bits
of Port B continuously
#include<PIC18F458.h>
Void main (void)
{
TRISB =0; // make Port B as output
While(1)
{
PORTB = 0x55;
PORTB = 0xAA;
}
}
26. Write a C18 program to toggle all the bits
of Port B continuously with some delay
#include<PIC18F458.h>
Void main (void)
{
unsigned int x;
TRISB =0;
while(1)
{_
PORTB = 0x55;
for(x=0;x<50000;x++);
PORTB = 0xAA;
for(x=0;x<50000;x++);
}
}
27. Write a C18 program to toggle all the bits
of Port B continuously with a 250 ms delay.
#include<PIC18F458.h>
Void MSDelay (unsigned int);
Void main (void)
{
TRISB =0;
While(1)
{
PORTB = 0x55;
MSDELAY (250);
PORTB = 0xAA;
MSDELAY (250);
}
}
Void MSDelay (unsigned int itime)
{
Unsigned int i,j;
For(i=0;i<itime;i++)
For (j=0;j<165;j++);
}
28. Write a C18 program to toggle all the bits
of Port B 50000 times.
#include<PIC18F458.h>
Void MSDelay (unsigned int);
Void main (void)
{
unsigned int z;
TRISB =0;
for(z=0;z<50000;z++)
{
PORTB = 0x55;
PORTB = 0xAA;
}
}
29. Write a C18 program to get a byte of data from
Port B, wait ½ second, and send it to Port C.
#include<PIC18F458.h>
Void MSDelay (unsigned int);
Void main (void)
{
Unsigned char mybyte;
TRISB =0xFF; //make PORT B an input port
TRISC = 0; // make PORT C an output port
While(1)
{
mybyte= PORTB;
MSDELAY (500);
PORTC = mybyte;
MSDELAY (500);
}
}
Void MSDelay (unsigned int itime)
{
Unsigned int i,j;
For(i=0;i<itime;i++)
For (j=0;j<165;j++);
}
31. Bit- addressable I/O programming
PORTxbits.Rxy,
x is the PORT, y is the bit of that port
eg PORTAbits.RA7 denotes PORTA.7
#define name PORTxbits.Rxy
For making input or output bits
TRISAbits.TRISA7 indicates the D7 ofTRISA
32. Write a C18 program to toggle only
bit RB4 continuously without
disturbing the rest of the bits of
PORT B
33. #include<PIC18F458.h>
#define mybit PORTBbits.RB4 //declare single bit
Void main(void)
{
TRISBbits.TRISB4 =0; // make Port pin RB4 an output
While (1)
{
Mybit =0; //turn off RB4
Mybit= 1; // turn off RB4
}
}
34. A door sensor is connected to the RB1 pin and a buzzer is
connected to RC7. Write a C18 program to monitor the door
sensor, when it opens, sound the buzzer by sending a
square wave of a few hundred Hz frequency to it.
35. #include<PIC18F458.h>
Void MSDelay (unsigned int);
#define Dsensor = PORTBbits.RB1
#define buzzer = PORTCbits.RC7
Void main (void)
{
TRISBbits.TRISB1 =1; //make PORT B.1 an input bit
TRISCbits.TRISC7= 0; // make PORT C.7 an output bit
While(1)
{
while( Dsensor==1);
{
buzzer = 1;
MSDELAY (500);
buzzer = 0;
MSDELAY (500);
}
}
Void MSDelay (unsigned int itime)
{
Unsigned int i,j;
For(i=0;i<itime;i++)
For (j=0;j<165;j++);
}
36. Write a C18 program to toggle all bits of Port B
100000 times.
Hint- short long (0 to 16777215)
37. #include<PIC18F458.h>
Void main (void)
{
Unsigned short long z;
TRISB =0; // make Port B as output port
For (z=0;z<100000;z++)
{
PORT B = 0x55; // assign value 55 H to port B
PORT B= 0xAA; // assign value AA H to port B to
toggle it
}
}
38. Logic Operations in C
▪ Bitwise operators are special operator set
provided by 'C.'
▪ They are used in bit level programming.
▪ These operators are used to manipulate bits
of an integer expression.
▪ Logical, shift and complement are three
types of bitwise operators.
▪ Bitwise complement operator is used to
reverse the bits of an expression.
39.
40. Write a C18 program to toggle all the bits of PORT b
And PORT C continuously with a 250 ms delay. Use the
EX-OR operator
#include<PIC18F458.h>
Void MSDelay (unsigned int);
Void main (void)
{
TRISB =0; // make Port B and output port 0 0 0
TRISC =0; // make Port C and output port 0 1 1
PORTB = 0x55; 1 0 1
PORTC = 0x55; 1 1 0
While(1)
{
PORTB = PORTB ^ 0xFF; // 01010101 ^ 11111111 = 10101010
MSDELAY (250);
PORTC = PORT C^0xFF; // 01010101 ^ 11111111 = 10101010
MSDELAY (250);
}
}
Void MSDelay (unsigned int itime)
{
Unsigned int i,j;
For(i=0;i<itime;i++)
For (j=0;j<165;j++);
}
41. Write a C18 program to get RB0 and send it to
RC7 after inverting it
#include <PIC18F458.h>
#define mybit1 PORTBbits.RB0
#define mybit2 PORTCbits.RC7
Void main (void)
{
TRISBbits.TRISB0 =1; // make RB0 an input bit
TRISCbits.TRISC7 =0; //make RC7 a output bit
While (1)
{
mybit2 = ~ mybit1;
}
}
42.
Every timer needs a clock pulse
to tick
Clock source can be
◦ Internal- 1/4th of the frequency of the
crystal oscillator on OSC1 and OSC2 pins
(Fosc/4) is fed into timer. Therefore, it is
used for time delay generation and hence
called timer.
◦ External-pulses are fed through one of the
PIC18’s pins and is known as Counter.
43. Serializing data is a way of sending a byte of
data one bit at a time through a single pin of a
microcontroller.
DATA Serialization in C
44. Two ways to transfer a byte
of data Serially
▪ Using Serial Port
Limited control over sequence of data transfer
▪ Transfer data one bit a time
Control of sequence of data and spaces between
them
46. PIC 18 has two to five timers depending on the
family member- Timers 0, 1, 2, 3 and 4
▪ Can be either used as timers to generate a
time delay
▪ Or as counters to count events happening
outside the microcontroller
47. Basics Registers of the
timer
▪Timers are 16-bit wide
◦Can be accessed as two
separate reg.
◦Low Byte(TMRxL) & High Byte
TMRxH)
◦Each timer also has TCON (timer
Control) reg for setting modes of
operation.