1
• State the three main elements in any microprocessor system
• State the difference between a microprocessor and microcontroller • State the advantages of flash ROM,
compared with other memory types.
2
• The three main elements are: Processor, memory and I/O
• A microcontroller has processor, memory and I/O on one chip, while microprocessor needs separate memory and I/O chips to form a working system
• Flash ROM can be electrically re-written many times, but is non-volatile
Some Quick Exercises
• Microcontroller contains on chip memory, input/output (I/O) ports and the
processor CPU.
• State the main function of I/O ports • Name THREE (3) types of I/O
communication ports.
Answers
• communication between microcomputer and the outside world (external system) such as humans and machine
5
• How many bits does the
128k MCU program
memory contain?
6 • 128k = 128 x 1024 bytes • 128 x 1024 x 8 bits = 1,048,576 bitsSome Quick Exercises
• Why it’s a good practice to put all
hardware definitions into a common file? • State three PIC chip options, which are
determined by the configuration code. (#config … )
Answers
• Common File: Rewriting the hardware definitions for each and every programs to be used for the same board can be troublesome. All the
programs using the same hardware/circuit can just include the common hardware definitions file into the source code
• PIC Chip Options: Watchdog timer, High speed programming, Low voltage programming, In-circuit debugger, code protection, memory write, brown-out reset, power-up timer
9
• Why serial data communication is generally slower than parallel? • Why serial data communication can
achieve higher speed compared to parallel communication by being clocked at a greater rate?
10
• Serial vs Parallel: The data has to be converted to serial form in a shift register and transmitted one bit at a time on a single line, while parallel data is transferred 8 (or more) bits at a time.
• A number of factors allow serial to be clocked at a greater rate:
• Clock skewbetween different channels is not an issue (for unclocked asynchronous serial communicationlinks) • Serial connection requires fewer interconnecting cables,
occupies less space. The extra space allows for better isolation of the channel from surroundings
• Crosstalkis less of an issue compared to parallel, because fewer conductors in proximity.
Some Quick Exercises
• This function initializes the RS232… The oscillator frequency to be used is 10MHz. The baud rate required is 9600 bps. Calculate the value of X to obtain the required baud rate.
void init_rs232( ) {
BRGH = 1;
SPBRG = X; /* set baud rate */
TX9 = 0; /* ninebits?1:0,,,8- or 9-bit transmission */ SYNC = 0; /* asynchronous */
SPEN = 1; /* enable serial port pins */
TXEN = 1; /* enable the transmitter & (automatically)TXIF=1 */ CREN = 1; /* enable reception */
SREN = 0; /* no effect */ TXIE = 0; /* disable tx interrupts */ RCIE = 0; /* disable rx interrupts */ }
Answers
• Oscillator frequency = 10MHz. • Baud Rate = 9600 bpsX = (Fosc / Baud Rate / 16) – 1 = (10MHz / 9600 / 16) - 1 = 65 – 1
13
• What are the advantages of in-circuit programming and debugging over the corresponding conventional development process?
14
• The program can be run, single
stepped and paused in the actual target hardware
• allowing hardware and timing faults to be identified as well a the usual syntax and logical errors
• the chip does not need to be removed from the application hardware once fitted, preventing possible damage
Some Quick Exercises
• What are the advantages of using circuit simulation software such as Proteus over the corresponding conventional
development process?
Answers
• The conventional process is to build prototype hardware, download the
program to the microcontroller and test it in circuit.
• Simulation allows the design to be tested and debugged before building hardware. • The schematic can then be converted into
a netlist and a layout to produce the final PCB without prototyping.
17
• What is a compiler (for C programming) and what does a compiler do?
18
• Compiler is a program that processes statements written in a programming language and turns them into machine language that a computer's processor uses.
• The compiler gets the syntax error in the written program before turning the C statements into machine instructions
Some Quick Exercises
• PIC is a family of Harvard architecture microcontrollers. Sketch the block diagram of a Harvard architecture microcontroller.
Answers
21
• Von Neumann is another type of microcontroller architecture besides Harvard architecture. Sketch the block diagram of a von Neumann architecture microcontroller.
22
• Block diagram of a von Neumann architecture :
Some Quick Exercises
• What are the advantages of Harvard architecture compared to von Neumann architecture?
Answers
• In a system using von Neumann architecture, the CPU can be either reading an instruction or reading/writing data from/to the memory. Both cannot occur at the same time since the
instructions and data use the same bus system. • In a system using the Harvard architecture, the CPU can both read an instruction and perform a data memory access at the same time, can thus be faster for a given circuit complexity because instruction fetches and data access do not contend for a single memory pathway.
25
• EEPROM is a type of memory widely used in computers and other electronic devices. State the type of EEPROM.
• EEPROM is realized by using arrays of floating gate transistors. State one advantage of floating gate transistors that is useful in EEPROM. • Flash memory is one type of EEPROM which is
able to achieve faster erase/write speed compared to traditional EEPROM. Why?
26
• Non-volatile memory which can be
electrically re-written many times.
• The ability to store an electrical charge forextended periods of time even without a connection to a power supply.
• Flash memory works much faster than traditional EEPROMs because it writes data in chunks/blocks, usually 512 bytes in size, instead of 1 byte at a time.
Some Quick Exercises
#include <htc.h> #include <pic16f877a.h> #define _XTAL_FREQ 20000000 // Set the oscillator frequency to 20MHz void main( )
{ TRISC=0x00; //Port C as outputs T2CON = 0b01010000; // Timer 2 control register PR2 = 0b01111111;
CCP1CON = 0b00111100; //Set to PWM mode CCPR1L=63;
TMR2ON=1; //Turn on Timer 2 while(1)
{ } } //End of Program
Calculate the pulse width, duty cycle and frequency of the pulse generated in the program below. The circuit uses a 20MHz oscillator.
Answers
• Instruction clock frequency = 20/4 = 5MHz • Instruction clock period = 0.2 us
• Timer2 counts from 0 to 127 (0b01111111 ) • Pre-scaler set at 1
• Time for Timer 2 to reset = 127 x 0.2 us = 25.4 us • Post-scaler = 10, but unused in PWM mode • Pulse period = Time for Timer 2 to reset = 25.4 us
• Pulse frequency = 1/(pulse period) = 1/(25.4us) = 39.37kHz • Every time Timer2 counts until 63 (determined by CCPR1L) output
of CCP1 (Pin RC2 or C2) will turn from high to low, the time taken (Pulse width) is 63 x 0.2 us = 12.6us OR 1.26 x 10e-5 seconds • Duty cycle = 12.6us / 25.4us = 49.6%
29
• Describe TWO characteristics of an active-high switch.
30
• An active high switch pulls up the
logic level to HIGH when being
pressed/pushed.
• An active high switch requires a pull
down resistor to pull down the logic
level to LOW when the switch is
released.
The End
• That’s all for this time.
• Enjoy your time playing around with microcontroller and interfacing