Embedded Controller Programming

Similar documents
MASSEY UNIVERSITY PALMERSTON NORTH CAMPUS

Microcontroller Intel [Instruction Set]

Q. Classify the instruction set of 8051 and list out the instructions in each type.

Microprocessors 1. The 8051 Instruction Set. Microprocessors 1 1. Msc. Ivan A. Escobar Broitman

Instruction Set Of 8051

80C51 family programmer s guide and instruction set. 80C51 Family. PROGRAMMER S GUIDE AND INSTRUCTION SET Memory Organization. Philips Semiconductors

INSTRUCCIONES ARITMETICAS ERROR! MARCADOR NO DEFINIDO.

Dodatak. Skup instrukcija

Programming of 8085 microprocessor and 8051 micro controller Study material

Module Contents of the Module Hours COs

DR bit RISC Microcontroller. Instructions set details ver 3.10

Digital Blocks Semiconductor IP

Digital Blocks Semiconductor IP

8051 Overview and Instruction Set

Introduction to uc & Embedded Systems

UNIT 2 THE 8051 INSTRUCTION SET AND PROGRAMMING

Dragonchip. Instruction Set Manual

Memory organization Programming model - Program status word - register banks - Addressing modes - instruction set Programming examples.

SN8F5000 Family Instruction Set

Architecture & Instruction set of 8085 Microprocessor and 8051 Micro Controller

Digital Blocks Semiconductor IP

8051 Microcontroller

Legacy documentation refer to the Altium Wiki for current information. TSK51x MCU


Microcontroller. Instruction set of 8051

Application Brief D-005

C51 Family. Architectural Overview of the C51 Family. Summary

UNIT THE 8051 INSTRUCTION SET AND PROGRAMMING

Programming Book Microcontroller Kit. Rev 3.0 January, Wichit Sirichote

8051 Microcontroller Assembly Programming

Chapter Family Microcontrollers Instruction Set

8051 Core Specification

MCS -51 Programmer s Guide and Instruction Set

AL8051S 8-BIT MICROCONTROLLER Application Notes

EEE3410 Microcontroller Applications Department of Electrical Engineering Lecture 4 The 8051 Architecture

VRS550-8kB Flash, 256B RAM, 25~40MHz, 8-Bit MCU VRS560-16kB Flash, 256B RAM, 40MHz, 8-Bit MCU

VRS540-4kB Flash, 128B RAM, 25~40MHz, 8-Bit MCU

Y51 Microcontroller. Technical Manual

MASSEY UNIVERSITY PALMERSTON NORTH CAMPUS

CS 320. Computer Architecture Core Architecture

Principle and Interface Techniques of Microcontroller

C51 Family. C51 Family Programmer s Guide and Instruction Set. Summary

8051 Microcontrollers

Application Brief D-002

Introduction To MCS-51

EE6502- MICROPROCESSOR AND MICROCONTROLLER

Microcontroller and Applications

UNIT MICROCONTROLLER AND ITS PROGRAMMING

Question Bank Microprocessor and Microcontroller

TUTORIAL Assembly Language programming (2)

Timer-1 can be run using the internal clock, fosc/12 (timer mode) or from any external source via pin T1 (P3.5) (Counter mode).

Core8051. Advanced v0.1

Lecture Instruction Set

TUTORIAL. Donal Heffernan University of Limerick May Tutorial D.Heffernan 2000,

What Registers are available? Programming in Assembler. Assembler Programming - like early Basic. Assembler Data Movement Instructions

Assembly Language programming (3)

UNIT-III ASSEMBLY LANGUAGE PROGRAMMING. The CPU can access data in various ways, which are called addressing modes

MCS-51 Serial Port A T 8 9 C 5 2 1

NAME as31 - An Intel 8031/8051 assembler. SYNOPSIS as31 [-h] [-l] [-s] [-v] [-Aarg] [-Ffmt] [-Ofile] infile.asm

8051 Single Board Monitor Programming. Minmon - Yeralan & Ahluwalia. PaulMon1 & PaulMon2 - Paul Stoffregen

Highlights. FP51 (FPGA based 1T 8051 core)

The Timers/Counters The Serial Interface The Interrupt System Reset P0.0-P0.7 P2.0-P2.7. Port 2 Drivers. Port 2 Latch

Legacy documentation refer to the Altium Wiki for current information. TSK52x MCU

VRS570 32K Flash, 1kB RAM, 25~40MHz, 8-Bit MCU VRS580 64K Flash, 1kB RAM, 25~40MHz, 8-Bit MCU

IA8044/IA8344 Variants IA8044 4kB internal ROM with R0117 version 2.3 firmware, 192 byte internal RAM, 64kB external program and data space.

Chapter 6 Interrupts. (I. Scott Mackenzie) By: Masud-ul-Hasan

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

8051 Programming using Assembly

CPEG300 Embedded System Design. Lecture 6 Interrupt System

Mod-3: Interrupts,Timer operation,serial communication 1

Assembly Language programming (2)

CoE3DJ4 Digital Systems Design. Chapter 5: Serial Port Operation

Interrupts. EE4380 Fall 2001 Class 9. Pari vallal Kannan. Center for Integrated Circuits and Systems University of Texas at Dallas

MODULE-1. Short Answer Questions

MICROPROCESSORS AND MICROCONTROLLERS MATERIAL. Features of 8051:

8051 Instruction Set

Interrupt Programming: Interrupts vs. Polling Method:

Chapter 3. Bit Addressable Area. By DeccanRobots


SUMMER 13 EXAMINATION

CPEG300 Embedded System Design. Lecture 3 Memory

Principle and Interface Techniques of Microcontroller

UNIT MICROCONTROLLER

CPEG300 Embedded System Design. Lecture 8 Timer

MODEL ANSWER SUMMER 17 EXAMINATION Subject Title: Microcontroller Subject Code:

Vidyalankar T.E. Sem. V [ETRX] Microprocessors and Microcontrollers I Prelim Question Paper Solution

University of Toronto at Scarborough CSC CSSF - Microprocessor Systems

~: Simple Programs in 8051 assembly language :~

MICROPROCESSOR LABORATORY MANUAL

Chapter 9. Programming Framework

MODEL ANSWER WINTER 17 EXAMINATION Subject Title: Microcontroller and applications

8XC51RA RB RC Hardware Description

INTEGRATED CIRCUITS P89C669 USER MANUAL. Preliminary Supersedes data of 2003 Jul Sep 16

WINTER 14 EXAMINATION

MAHALAKSHMI ENGINEERING COLLEGE TIRUCHIRAPALLI UNIT- IV

Embedded Controller Programming II. I/O Device Programming in C Part 1: Input and Interrupts

Arithmetic and Logic

Control Transfer Instructions Jump, Loop, and Call. ECE473/573 Microprocessor System Design, Dr. Shiue

CHAPTER 3 JUMP, LOOP, AND CALL INSTRUCTIONS

UNIT IV MICROCONTROLLER

Transcription:

Embedded Controller Programming Counters, Timers and I/O in Assembly Language Ken Arnold Copyright 2000-2004 Ken Arnold 1 Outline Timer/Counters Serial Port More 8051 Instructions Examples Copyright 2000-2004 Ken Arnold 2 Copyright 2000-2004 Ken Arnold 1

Timer/Counters Control Register Modes: (Timers 0,1) Counting, Timing One shot 16 bit (mode 1) Auto reload 8 bit (mode 2) Timer 2 Enhanced modes: 16 bit auto reload Capture/compare Copyright 2000-2004 Ken Arnold 3 8051 Timer Mode 1 16 bit counter Copyright 2000-2004 Ken Arnold 4 Copyright 2000-2004 Ken Arnold 2

Timer Control TCON 088h 7 6 5 4 3 2 1 0 TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0 TFx Timer x Overflow Flag (input) TRx Timer x Run Enable (control) IEx Ext Int Detect Flag (input) ITx Ext Int Edge Sensitive 1=Edge 0=Level Copyright 2000-2004 Ken Arnold 5 Timer Flags Timers set flag on overflow Count increments every 12 clock cycles Mode 1 used for a single 16 bit delay One-shot delay, then it must be reloaded Mode 2 reloads automatically, 8 bit delay TLx reloaded with THx when TLx overflows Results in constant interrupt frequency Load timer with 2 s complement of count! Copyright 2000-2004 Ken Arnold 6 Copyright 2000-2004 Ken Arnold 3

8051 Timer Mode 2 8 bit counter Copyright 2000-2004 Ken Arnold 7 Serial Data Synchronous (clocked): Separate data and clock signals Shift register serial mode 0 Also I 2 C, SPI, Microwire, One-Wire Asynchronous (unclocked like COM port): Data signal only, serial modes1-3 Independent clock in receiver UART: Universal Async Receiver Transmitter Copyright 2000-2004 Ken Arnold 8 Copyright 2000-2004 Ken Arnold 4

Async Serial Data Format Copyright 2000-2004 Ken Arnold 9 Serial Data Example Serial data 4DH: ASCII code for upper case M Binary 0100 1101 - LSB is sent first Copyright 2000-2004 Ken Arnold 10 Copyright 2000-2004 Ken Arnold 5

Serial Port Modes Serial Modes: 0: Ext shift register data on RxD, Clk on TxD 1: 8 bit UART (like the PC s serial COM port) 2: 9 bit, UART fixed clock freq X/64 or X/32 3: 9 bit, UART variable clock frequency Mode 1 most commonly used for RS-232 Timer 1 Used for Data Bit Rate, Mode 2 Copyright 2000-2004 Ken Arnold 11 Serial Control SCON 098h 7 6 5 4 3 2 1 0 SM0 SM1 SM2 REN TB8 RB8 TI RI RI=1 when Serial Receive Buffer is Full TI=1 when Serial Transmit Buffer is Empty MUST be cleared using CLR TI or CLR RI Copyright 2000-2004 Ken Arnold 12 Copyright 2000-2004 Ken Arnold 6

SCON cont d 7 6 5 4 3 2 1 0 SM0 SM1 SM2 REN TB8 RB8 TI RI SM0, SM1 Select Modes 0..3 SM2=1: Multiprocessor RI set if RB8=1 REN=1 Enables Receiver RB8, TB8 Ninth bit received or transmitted Copyright 2000-2004 Ken Arnold 13 Assembler Overview of asm51.pdf Manual Syntax Notation Pseudo-Ops Directives Copyright 2000-2004 Ken Arnold 14 Copyright 2000-2004 Ken Arnold 7

SDK Monitor Commands Review Monitor Commands? Or Help Command: lists commands Reserved Names / SFRs Assemble/Disassemble PS: Through/over Calls Go vs. Execute Copyright 2000-2004 Ken Arnold 15 Example Programs Simple P1 I/O Counters: counter1.asm, counter2.asm Timers: timer0.asm, timer1.asm, timer2.asm Serial I/O: serial1.asm, serial2.asm, serial3.asm Copyright 2000-2004 Ken Arnold 16 Copyright 2000-2004 Ken Arnold 8

8052 Pin Definitions Copyright 2000-2004 Ken Arnold 17 Port I/O for the 8051 family Ports are SFRs in Internal Data Memory Port is 0ffh (same as 0xff in C) after Reset Port 1 is uncommitted - location 90h Bit addressable from bits 90h to 97h LSB address = 90h, MSB address = 97h SDK Port 1 on DIP plug pins 1..8 Access with monitor command P1 Copyright 2000-2004 Ken Arnold 18 Copyright 2000-2004 Ken Arnold 9

Driving an LED directly 8051 Port IOL >> IOH Drive LED from 5V LED OFF when bit= 1 LED ON when bit= 0 For LED with Vf=~2V voltage across R is: +5V - 2V = 3V current in R and LED: 3V/330 ohms = 9 ma Copyright 2000-2004 Ken Arnold 19 8051 Programming Model General Architecture Harvard - Separate Program and Data Memory Accumulator Based Memory Spaces and Data Paths Multilevel Data Access: Byte and Bit Level Instruction Set CISC - Complex Instruction Set Copyright 2000-2004 Ken Arnold 20 Copyright 2000-2004 Ken Arnold 10

Programmer s CPU Model Address Mode Notation Types of Operands Memory Addresses Access Methods Copyright 2000-2004 Ken Arnold 21 Address Notation Rn range: R0..R7 Register Rn of the current Register Bank. direct range: 00-FFh 8-bit internal data location s address. Internal Data RAM location (0-7Fh) or SFR (80-FFh) SFRs are usually referenced by symbolic name, e.g. P1 rather than 90h. Copyright 2000-2004 Ken Arnold 22 Copyright 2000-2004 Ken Arnold 11

Address Notation 2 @Ri range: @R0 or @R1 only 8-bit internal data location (0-FFh) addressed indirectly through register R1 or R0. #data range: 0-FFh 8-bit constant included in the instruction #data 16 range: 0-FFFFh 16-bit constant included in the instruction Copyright 2000-2004 Ken Arnold 23 Address Notation 3 addr 16 range: 0-FFFFh 16-bit destination address. Used by LCALL and LJMP. A branch can be anywhere within the 64k-byte Program Memory address space. addr 11 range: 0-7FFh 11-bit destination address. Used by ACALL and AJMP. The branch will be within the same 2k-byte page of program memory as the first byte of the following instruction. Copyright 2000-2004 Ken Arnold 24 Copyright 2000-2004 Ken Arnold 12

Address Notation 4 rel (RELative) Range: -128 to +127 bit Signed (two s complement) 8-bit offset byte. Used by SJMP and all conditional jumps Range is 128 to +127 bytes relative to first byte of the following instruction Range: 0-FFh Bit in Internal Data RAM (bit address 0-7Fh) Special Function Register bits (address 80-FFh) Copyright 2000-2004 Ken Arnold 25 Data Pointer dptr: 16 bit address pointer Initialize with MOV dptr,#data16 Upper and lower bytes are also SFRs: High and low byte of dptr are dph and dpl Used for references to Address Spaces: External Data MOVX a,@dptr or MOVX @dptr,a Code Memory MOVC a,@a+dptr note address is @[a+dptr] Copyright 2000-2004 Ken Arnold 26 Copyright 2000-2004 Ken Arnold 13

External Data Access External Data - Indirect Only Address range 0000-FFFFh Using 16 Bit Data Pointer (dptr) MOVX a,@dptr ; load a from xdata MOVX @dptr,a ; store a in xdata Address range 00-FFh using 8 bit pointers @R0/@R1 MOVX a,@r0 ; indirect from xdata MOVX a,@r1 ; range 0-FFh MOVX @R0, a MOVX @R1, a Copyright 2000-2004 Ken Arnold 27 Using DPTR (Data Pointer) mov dptr,#uartsr movx a,@dptr ; Address of uart status reg ; Get status byte from uart etc... uartsr equ 0fff9h uartd equ 0fffbh rxrdy equ 01h txrdy equ 04h ; code continues ; Memory mapped I/O ; UART status register ; UART data register ; receive buffer full ; transmit buffer empty Copyright 2000-2004 Ken Arnold 28 Copyright 2000-2004 Ken Arnold 14

Data Memory Access Internal Data Range 00-7Fh Direct address, 8 bits: 0-7Fh MOV a,nnh where nn<80h MOV a,@r0 where R0<80h Range 80-FFh Indirect Access ONLY Addresses 80-FFh MOV a,@ri Examples: MOV a,@r0 MOV direct, @R0 Direct addr >=80h is SFR Example MOV a,90h ; get Port1 Copyright 2000-2004 Ken Arnold 29 Internal Data Memory Registers R0..R7 8 registers per bank 4 Banks available Bit Addressable 20-2Fh General Purpose 30-7Fh SFRs: Accumulator, I/O PSW, B, Counter/Timer Misc. Registers Copyright 2000-2004 Ken Arnold 30 Copyright 2000-2004 Ken Arnold 15

SFR Addresses SFRs 80-FFh Some are Bit Addressable (if last 3 bits of SFR address =0) ex:p1.3 is bit 93h Available SFRs Depend on CPU variant used Copyright 2000-2004 Ken Arnold 31 Control Transfer JMP addr Go to address JMP @a+dptr Indirect Jump Address @(a+dptr) JZ rel if Accumulator is Zero JNZ rel if Acc. is Non-Zero CALL addr Save PC on stack Go to subroutine address RET return Pop PC from stack RETI Return from ISR Allows Interrupts Copyright 2000-2004 Ken Arnold 32 Copyright 2000-2004 Ken Arnold 16

Control Transfer 2 CJNE DJNZ Compare and jump if Not Equal CJNE @Ri,#data,rel CJNE a,#data,rel CJNE a,direct,rel CJNE Rn,#data,rel Decrement and Jump if Not Zero Loop counter: DJNZ counter,address DJNZ direct,rel DJNZ Rn,rel Copyright 2000-2004 Ken Arnold 33 Data Path: Logic CLR A clears A CPL A one s complement of A Rotate Accumulator: RR A lsb -> msb RL A msb -> lsb RRC A lsb -> c -> msb RLC A msb -> c -> lsb Bit-wise Logical Destination is A: ANL A, x ORL A, x XRL A, x x Operands can be: #data, Rn, @Ri, direct Destination is Direct ANL direct, #data ANL direct, a Copyright 2000-2004 Ken Arnold 34 Copyright 2000-2004 Ken Arnold 17

Bit Operations MOV (c is carry bit) MOV c,bit MOV bit,c CLR clear bit CLR c CLR bit SETB set bit SETB c SETB bit CPL complement bit CPL c CPL bit ANL Logical AND ANL c,bit ; c AND bit ANL c,/bit ; c AND NOT bit ORL Logical OR ORL c,bit ; c OR bit ORL c,/bit ; c OR NOT bit Copyright 2000-2004 Ken Arnold 35 Bit Conditional Jumps JB jump if bit = 1 JB bit,rel JNB jump if bit = 0 JNB bit,rel JC jump if carry = 1 JC rel JNC jump if carry = 0 JNC rel JBC jump on bit & clr JBC bit,rel jump if bit = 1, clear bit Can be used for semaphore operations Indivisible test and clear a.k.a. mutex Copyright 2000-2004 Ken Arnold 36 Copyright 2000-2004 Ken Arnold 18

Conditional Branching low: ; waits until external jb P1.0, low ; switch pulls P1.0 low call delay ; debounce delay... high: ; waits until external jnb P1.0, high; switch is opened. Copyright 2000-2004 Ken Arnold 37 Summary Timer/Counters Serial Port More 8051 Instructions Examples Copyright 2000-2004 Ken Arnold 38 Copyright 2000-2004 Ken Arnold 19