Sunteți pe pagina 1din 37

Microprocessor and Interfacing

ECX 4236 - Day School 1


G. S. Nadeera Meedin B.Tech (Hons), AMIE(SL)

WHY Microprocessor and Interfacing

?
About the Course

Why do we need to learn Microprocessor / Controllers ?


The microprocessor is the core of computer systems. Nowadays many communication, digital entertainment, portable devices, are controlled by them. A designer should know what types of components he needs, ways to reduce production costs and product reliable.

The necessary tools for a Microprocessor / controller


CPU: Central Processing Unit
I/O: Input /Output Bus: Address bus & Data bus Memory: RAM & ROM Timer Interrupt Serial Port Parallel Port

Microprocessors :
General-purpose microprocessor
CPU for Computers No RAM, ROM, I/O on CPU chip itself ExampleIntels x86, Motorolas 680x0
Data Bus Many chips on mother board

CPU GeneralPurpose Microprocessor

RAM

ROM

I/O Port

Timer

Serial COM Port

Address Bus General-Purpose Microprocessor System

Microcontroller :
A smaller computer On-chip RAM, ROM, I/O ports... ExampleMotorolas 6811, Intels 8051, Zilogs Z8 and PIC 16X
CPU RAM ROM

A single chip
I/O Port Timer Serial Port Microcontroller

Microprocessor vs. Microcontroller


Microprocessor CPU is stand-alone, RAM, ROM, I/O, timer are separate designer can decide on the amount of ROM, RAM and I/O ports. expansive versatility general-purpose Microcontroller CPU, RAM, ROM, I/O and timer are all on a single chip fix amount of on-chip ROM, RAM, I/O ports for applications in which cost, power and space are critical single-purpose

Lab Organization
Lab 1 :
Identify the basic functions available in the AES-51 development board. Run the self-test program and familiar with the each functions of the AES-51 development board. Familiar with the 8052 simulator Assemble the programs written in Assignment #1 and observe the results by using AES-51 development board.

Prerequisites
An understanding of decimal, hexadecimal and binary number systems. A general knowledge of hardware.

Software Use
Compiler : ASM 51
http://www.metaice.com/ASM51/ASM51.htm

Simulator : 8052
http://www.vaultbbs.com/sim8052/download.php

First Assembly Program

Write a simple Assembly Language Program (ALP) to perform simple arithmetic operations.

First Assembly Program


Assembly Language Source File

Builds a symbol table

Translation Process
Machine Language Object File Translates the source file Generates the listing

First Assembly Program : Source Code


ORG 0000H MOV R0, #5 MOV A, #6 ADD A,R0 END

First Assembly Program : Assemble

First Assembly Program .LST file


0000 0000 7805 0002 7406 0004 28 1 ORG 0000H 2 MOV R0, #5 3 MOV A, #6 4 ADD A,R0 5 END

VERSION 1.2h ASSEMBLY COMPLETE, 0 ERRORS FOUND

First Assembly Program : Simulate

Block Diagram
External interrupts Interrupt Control On-chip ROM for program code
Timer/Counter

On-chip RAM

Timer 1 Timer 0

Counter Inputs

CPU Serial Port

OSC

Bus Control

4 I/O Ports

P0 P1 P2 P3

TxD RxD

Address/Data

Pin Description of the 8051


P1.0 P1.1 P1.2 P1.3 P1.4 P1.5 P1.6 P1.7 RST (RXD)P3.0 (TXD)P3.1 (INT0)P3.2 (INT1)P3.3 (T0)P3.4 (T1)P3.5 (WR)P3.6 (RD)P3.7 XTAL2 XTAL1 GND 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 Vcc P0.0(AD0) P0.1(AD1) P0.2(AD2) P0.3(AD3) P0.4(AD4) P0.5(AD5) P0.6(AD6) P0.7(AD7) EA/VPP ALE/PROG PSEN P2.7(A15) P2.6(A14) P2.5(A13) P2.4(A12) P2.3(A11) P2.2(A10) P2.1(A9) P2.0(A8)

8051 (8031)

Types of Memory

On Chip Memory

Registers
A B R0 R1 R2 R3 R4 R5 R6 R7 Some 8-bit Registers of the 8051 Some 8051 16-bit Register PC PC DPTR DPH DPL

Stack in the 8051


7FH

The register used to access the stack is called SP (stack pointer) register. 30H
2FH

Scratch pad RAM

The stack pointer in the 8051 is only 8 bits wide, which means that it can take value 00 to FFH. When 8051 powered up, the SP register contains value 07.

Bit-Addressable RAM 20H 1FH 18H 17H 10H 0FH 08H 07H 00H

Register Bank 3 Register Bank 2 (Stack) Register Bank 1 Register Bank 0

Special Function Registers

Addressing Modes
Immediate Addressing Direct Addressing Indirect Addressing External Direct Code Indirect MOV A,#20h MOV A,30h MOV A,@R0 MOVX A,@DPTR MOVC A,@A+DPTR

LOOP and JUMP Instructions

Conditional Jumps :
JZ JNZ DJNZ CJNE A,byte CJNE reg,#data JC JNC JB JNB JBC Jump if A=0 Jump if A/=0 Decrement and jump if A/=0 Jump if A/=byte Jump if byte/=#data Jump if CY=1 Jump if CY=0 Jump if bit=1 Jump if bit=0 Jump if bit=1 and clear bit

Timers

Keeping time and/or calculating the amount of time between events, Counting the events themselves, or Generating baud rates for the serial port.

How does a timer count ?

A timer always counts up

How long does a timer take to count ?


Crystal Frequency : 11.059 MHz A single machine cycle consists of 12 crystal pulses A running timer will be incremented

11,059,000 / 12 = 921,583 times per second


If a timer has counted from 0 to 50,000 you may calculate:

50,000 / 921,583 = .0542 Seconds

Timer SFR
SFR Name Description SFR Address

TH0
TL0 TH1 TL1 TCON TMOD

Timer 0 High Byte


Timer 0 Low Byte Timer 1 High Byte Timer 1 Low Byte Timer Control Timer Mode

8Ch
8Ah 8Dh 8Bh 88h 89h

TMOD (89 H)
Bit 7 Name GATE1 Explanation of Function Timer When this bit is set the timer will only run when INT1 (P3.3) is high. When this bit is clear the timer will run 1 regardless of the state of INT1. When this bit is set the timer will count events on T1 (P3.5). When this bit is clear the timer will be 1 incremented every machine cycle. Timer mode bit (see below) 1 Timer mode bit (see below) 1 When this bit is set the timer will only run when INT0 (P3.2) is high. When this bit is clear the timer will run 0 regardless of the state of INT0. When this bit is set the timer will count events on T0 (P3.4). When this bit is clear the timer will be 0 incremented every machine cycle. Timer mode bit (see below) 0 Timer mode bit (see below) 0

6 5 4 3

C/T1 T1M1 T1M0 GATE0

2
1 0

C/T0
T0M1 T0M0

Timer Modes

TxM1 TxM0 0 0 1 1 0 1 0 1

Timer Mode 0 1 2 3

Description of Mode 13-bit Timer. 16-bit Timer 8-bit auto-reload Timer mode

TCON SFR
Bit Name 7 6 5 4 TF1 TR1 TF0 TR0 Bit Address 8Fh 8Eh 8Dh 8Ch Explanation of Function Timer 1 Overflow. This bit is set by the microcontroller when Timer 1 overflows. Timer 1 Run. When this bit is set Timer 1 is turned on. When this bit is clear Timer 1 is off. Timer 0 Overflow. This bit is set by the microcontroller when Timer 0 overflows. Timer 0 Run. When this bit is set Timer 0 is turned on. When this bit is clear Timer 0 is off. Time r 1 1 0 0

TCON SFR
Bit Name 7 6 5 4 TF1 TR1 TF0 TR0 Bit Address 8Fh 8Eh 8Dh 8Ch Explanation of Function Timer 1 Overflow. This bit is set by the microcontroller when Timer 1 overflows. Timer 1 Run. When this bit is set Timer 1 is turned on. When this bit is clear Timer 1 is off. Timer 0 Overflow. This bit is set by the microcontroller when Timer 0 overflows. Timer 0 Run. When this bit is set Timer 0 is turned on. When this bit is clear Timer 0 is off. Time r 1 1 0 0

Using Timers
Initializing a Timer Reading the value of a Timer Or Detecting Timer Overflow Timing the length of events

Port 0 with Pull-Up Resistors


Vcc 10 K

P0.0 DS5000 P0.1 P0.2 8751 P0.3 P0.4 8951 P0.5 P0.6 P0.7

Port 0

Course Summary
Learn a lot

and have fun doing it!

S-ar putea să vă placă și