1 Introduction To Microcontrollers
1 Introduction To Microcontrollers
Roland Fernandez
Software Hardware
v[k] = v[k+1];
v[k+1] = temp;
An Overview
The Aims:
Basics of Microprocessor-based systems Programmers view of Computer Architecture Interaction between hardware and software, i.e. Interfacing.
PIC MICROCONTROLLER
PIC microcontrollers
The microcontrollers played revolutionary role in embedded industry after the invention of Intel 8051. The steady and progressive research in this field gave the industry more efficient, high-performance and lowpower consumption microcontrollers.
PIC microcontrollers
PIC stands for Peripheral Interface Controller. The General Instruments used the acronyms Programmable Interface Controller and Programmable Intelligent Computer for the initial PICs (PIC1640 and PIC1650).
PIC microcontrollers
The AVR, PIC and ARM are the prime examples. The new age microcontrollers are getting smarter and richer by including latest communication protocols like USB, I2C, SPI, Ethernet, CAN etc.
History
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.
History
The PIC controller was used to offload the I/O the tasks from CPU to improve the overall performance of the system. In 1985, General Instruments converted their Microelectronics Division to Microchip Technology.
History
In 1993, Microchip Technology 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.
Development:
Since 1998, Microchip Technology continuously developed new high performance microcontrollers with new complex architecture and enhanced in-built peripherals. At present PIC microcontrollers are widely used for industrial purpose due to its high performance ability at low power consumption.
Development:
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.
The small size and low cost of Base Line PIC replaced the traditional ICs like 555, logic gates etc. in industries.
Mid-Range PIC
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.
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.
PIC18
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.
Market Share
1990 Rank
Motorola Mitsubishi NEC Intel Hitachi Philips Matsushita National Siemens
1991 Rank
Motorola Mitsubishi NEC Intel Hitachi Philips Matsushita
SGS-Thomson
1992 Rank
Motorola Mitsubishi Intel NEC Philips Hitachi Matsushita
SGS-Thomson
1993 Rank
Motorola Mitsubishi NEC Hitachi Philips Intel SGSThomson
1994 Rank
Motorola Mitsubishi NEC Philips Intel
1995-96 Rank
Motorola Mitsubishi SGS-Thomson NEC
97-PRESENT
Motorola
Microchip
ST-Micro NEC Mitsubishi Philips Siemens Toshiba Hitachi
Microchip
Philips Zilog Hitachi Fujitsu
Microchip
Zilog
SGS-Thomson
Microchip
Matsushita
Siemens
National
Matsushita
10
11 12 13 14 15 16 17 18
TI
Sharp Oki Toshiba
SGS-Thomson
TI
National Toshiba Sony Sharp Oki Zilog Microchip
Matra MHS
TI
Zilog Toshiba Siemens Microchip Sharp Sanyo
Matra MHS
Toshiba
National Zilog TI Siemens Sharp Oki Sony Sanyo
Hitachi
Toshiba National TI Ricoh Fujitsu Siemens Sharp Oki
Intel
Siemens Toshiba Matsushita TI National Temic Sanyo Ricoh
Zilog
Fujitsu Atmel National Sanyo Matsushita TI Sony Intel
Zilog
Matra MHS
Sony Fujitsu
Sony
19
AMD
Fujitsu
Oki
Fujitsu
Sony
Oki
LG Semicon
Amplifiers
Filters
A/D
AC Power Battery
PICmicro Microcontroller
SRAM
LED Drivers
Complete Compatibility
Microcontroller vs Microprocessor
Microcontroller has the Memory and IO onchip while as opposed the microprocessor.
Microcontrollers are microprocessors with an onchip Memory and IO
Microprocessor are intended for high performance applications where COST and SIZE is not the most critical selection criteria Microcontrollers on the other hand are designed to minimize chip count and cost with application specialization at the expense of flexibility
Microcontroller vs Microprocessor
Microprocessors are the most flexible Microcontrollers are the most compact
PICmicro Architecture
Harvard Architecture
Von Neumann
CPU
Fetches instructions and data from one memory. Limits Operating Bandwidth
CPU
Increases throughput
Different program and data bus widths are possible
Advantages
Fewer chips are required since most functions are already present on the processor chip Lower cost and simpler size result from a simpler design Overall reliability is higher, since there are fewer components and interconnections
Advantages
Lower
power requirements because on-chip power requirements are smaller than external loads More pins are available for user IO (no pin is used for the bus) Fewer external connections are required
Disadvantages
Reduced flexibility, since you cant easily change the functions designed into the chip Expansion of memory or IO is limited or impossible Limited data transfer rates due to practical size and limits for a single chip Lower performance IO because of design compromises IO to fit everything in one chip
CPU
Memory
IO
Others
uP Functions
Microcontroller Functions
APPLICATIONS
HUNDREDS OF APPLICATIONS
CONSUMER
TV/VCR EQUIPMENT STEREO RECEIVER
AUTOMOTIVE
AUTO SECURITY SYSTEM KEYLESS ENTRY
OFFICE AUTOMATION
COMPUTER MOUSE LAPTOP TRACKBALL
TELECOM
CELLULAR PHONE CORDLESS TELEPHONE
INDUSTRIAL
MOTOR CONTROL THERMOSTAT
CD PLAYER
REMOTE CONTROLS CABLE TV CONVERTER VIDEO GAMES CAMERA GARAGE OPENER MICROWAVE OVEN WASHER/DRYER KITCHEN APPLIANCES
RADAR DETECTOR
CRUISE CONTROL ANTI-LOCK BRAKING SPEEDOMETER CLIMATE CONTROL TURN SIGNALS ACTIVE SUSPENSION FUEL PUMP CONTROL FUEL INJECTION
HANHELD SCANNER
COMPUTER KEYBOARD LASER PRINTER INTERFACE BOARD PC LAN SYSTEM X/Y PLOTTER COPIER BAR CODE READER DISK DRIVE TAPE BACK-UP UNIT
ANSWERING MACHINE
PAY PHONE PAGER MODEM CREDIT CARD VERIFICATION
SECURITY SYSTEM
POSTAGE METRE UTILITY METER ROBOTICS PROCESS CONTROL GAS PUMP SMOKE DETECTOR CARBON MONOXIDE DETECTOR X/Y TABLE
CORDLESS TOOLS
VACCUM CLEANER ELECTRIC BLANKET
SERIAL BUS
FACSIMILE MACHINE
PIC16F84
SCOREBOARDS QUEUING SYSTEM
MOVING SIGNS
TIMER
INDUSTRIAL CONTROLLER
PIC16F84
TIMER
MOVING SIGNS
TACHOMETER
PIC12C508
PAROL SEQUENCER
PEDDLERS
PIC12C671
REF-MATE
TRAFFIC LIGHT
LIGHT DIMMER
Automotive Applications
PIC 16F84A
15 Special Function Hardware registers Eight-level deep hardware stack Direct, indirect and relative addressing modes Four interrupt sources:
External RB0/INT pin TMR0 timer overflow PORTB<7:4> interrupt-on-change Data EEPROM write complete
Peripheral Features
13 I/O pins with individual direction control High current sink source for LED drive 8-bit counter with 8-bit programmable prescaler
Special Features
10,000 erase/write cycles Enhanced FLASH Program memory typical 10,000,000 typical erase/write cycles EEPROM Data memory typical EEPROM Data Retention > 40 years In-Circuit Serial Programming (ICSP) via two pins
Special Features
Power-on Reset (POR), Power-up Timer (PWRT), Oscillator Start-up Timer (OST) Watchdog Timer (WDT) with its own OnChip RC Oscillator for reliable operation Code protection Power saving SLEEP mode Selectable oscillator options
Low power, High speed Fully static design Wide operating voltage range:
2.0 V to 6.0 V Commercial 2.0 V to 6.0 V Industrial
Basic Circuit
MEMORY ORGANIZATION
There are two memory blocks in the PIC16F84A. These are the program memory and the data memory. Each block has its own bus, so that access to each block can occur during the same oscillator cycle.
Program Memory Organization The PIC16FXX has a 13-bit program counter capable of addressing an 8K x 14 program memory space. For the PIC16F84A, the first 1K x 14 (0000h03FFh) are physically implemented (Figure 2-1).
1) Special Function Registers (SFR) area. The SFRs control the operation of the device.
2) General Purpose Registers (GPR) area. is 8-bits wide and is accessed either directly or indirectly through the FSR.
I/O PORTS
Are external registers that sre used to communicate to external devices. Some pins for these I/O ports are multiplexed with an alternate function for the peripheral features on the device. In general, when a peripheral is enabled, that pin may not be used as a general purpose I/O pin. PORTA and TRISA Registers
PORTA is a 5-bit wide, bi-directional 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.
Crystal operation
Capacitor selection for crystal operation:
Resonator operation
Resonators are available from 4 to about 8 MHz. They are not as accurate as crystal-based oscillators. Resonators are usually 3-pin devices and the two pins at either sides are connected to OSC1 and OSC2 inputs of the microcontroller. The middle pin is connected to the ground.
RC oscillator
For applications where the timing accuracy is not important we can connect an external resistor and a capacitor to the OSC1 input of the microcontroller
Reset circuit
Reset is used to put the microcontroller into a known state. Normally when a PIC microcontroller is reset execution starts from address 0 of the program memory. This is where the first executable user program resides.
Exercise 1
Diagram 1:
Activity # 1:
Activity # 2:
Exercise II
Diagram 2-a:
Delay_ms(100);
}
else { PORTB = 0x00; Delay_ms(100);
Diagram 2-b:
Exercise III
KEYPAD OPERATION
Diagram 3:
Source Code 3:
void main() { TRISB = 0; TRISA = 0x1f; PORTB = 0; while(1) { if(PORTA==0x10) PORTB = 0x06; else if(PORTA==0x11) PORTB = 0x5b; else if(PORTA==0x12) PORTB = 0x4f; else if(PORTA==0x14) PORTB = 0x66; else if(PORTA==0x15) PORTB = 0x6d; //5 //4 //3 } } //2 //1 else if(PORTA==0x16) PORTB = 0x7d; else if(PORTA==0x18) PORTB = 0x07; else if(PORTA==0x19) PORTB = 0x7f; else if(PORTA==0x1A) PORTB = 0x6f; else if(PORTA==0x1C) PORTB = 0x77; else if(PORTA==0x1E) PORTB = 0x58; else if(PORTA==0x1d) PORTB = 0x3f; //6 //7 //8 //9 //* //#
MM74C922 / MM74C923
16-Key Encoder / 20-Key Encoder
MM74C922 / MM74C923
16-Key Encoder / 20-Key Encoder
Connection Diagrams
Block Diagram
Exercise IV
LCD OPERATION
LCD
LCD Routines
Lcd_Config Lcd_Init Lcd_Out Lcd_Out_Cp Lcd_Chr Lcd_Chr_Cp Lcd_Cmd
Lcd_Cmd Options
Diagram 4:
void main() {
TRISB = 0; Lcd_Init(&PORTB); PORTB // PORTB is output // Initialize LCD connected to
Lcd_Cmd(Lcd_CLEAR);
Lcd_Cmd(Lcd_CURSOR_OFF); Lcd_Out(1, 1, text); column }
// Clear display
// Turn cursor off // Print text to LCD, 2nd row, 1st
Lcd_Init(&PORTB);
Lcd_Cmd(Lcd_CLEAR);
Lcd_Cmd(Lcd_CURSOR_OFF); // Turn cursor off Lcd_Out(2, 5, text); Lcd_Out(3, 8, "******"); Delay_ms(500); Lcd_Cmd(Lcd_CLEAR); // Clear display Lcd_Out(2, 4, "kEYPRESSED: ");
while(1) { if(PORTA==0x10) { Lcd_Chr(2,16,'1'); Delay_ms(50); } else if(PORTA==0x11) { Lcd_Chr(2,16,'2'); Delay_ms(50); } else if(PORTA==0x12) { Lcd_Chr(2,16,'3'); Delay_ms(50); } else if(PORTA==0x14) { Lcd_Chr(2,16,'4'); Delay_ms(50); } else if(PORTA==0x15) { Lcd_Chr(2,16,'5'); Delay_ms(50); } //5 //4 //3 //2 //1
//6
//7
//8
{
Lcd_Chr(2,16,'8'); Delay_ms(50); } else if(PORTA==0x1A) { Lcd_Chr(2,16,'9'); Delay_ms(50); //9
}
else if(PORTA==0x1C) { Lcd_Chr(2,16,'*'); Delay_ms(50); } else if(PORTA==0x1E) { Lcd_Chr(2,16,'#'); Delay_ms(50); } else if(PORTA==0x1d) { Lcd_Chr(2,16,'0'); Delay_ms(50); } } //END OF WHILE //0 //# //*