Building Assembler Programs Chapter Five Dr. Gheith Abandah1.

Slides:



Advertisements
Similar presentations
振動スイッチを活用 振動(傾き)を検出 ボールが移動 a)オン時 b)オフ時 オンからオフ時の観察.
Advertisements

Assembler Exercises Chapters 4-6 Dr. Gheith Abandah1.
Control structures Hot to translate high level control structures to assembler.
Working with time: interrupts, counters and timers Chapter Six Dr. Gheith Abandah1.
Electronics Design Lab TUTORIAL PIC Microcontrollers Francesco Tenore 2/10/2006.
م/محمد علي عطية حسين. Pin Diagram DescriptionPin Name Oscillator crystal input/external clock source input. OSC1/CLKIN Oscillator crystal output.OSC2/CLKOUT.
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
Data acquisition and manipulation
Prof. Jorge A. Ramón Introducción a Microcontroladores.
The human and physical interfaces Chapter Eight 8.1 – 8.9 Dr. Gheith Abandah1.
Starting with serial Chapter Ten 10.1, 10.2,
SENIOR PROJECT PRESENTATION REMOTE CONTROL CAR MURAT DİNÇER.
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Fall 2013 Lecture 26: PIC microcontroller intro.
16.317: Microprocessor System Design I Instructor: Dr. Michael Geiger Spring 2012 Lecture 30: PIC data memory.
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
Chapter 4 Starting to Program – an Introduction to Assembler The aims of this chapter are to introduce: the essentials of Assembler programming; the Microchip.
Microcontroller Programming How to make something almost do something else Raffi Krikorian MAS November 2003.
Department of Electronic & Electrical Engineering Embedded system Aims: Introduction to: Hardware. Software Ideas for projects ? Robotics/Control/Sensors.
Two’s Complement Number wheel for 4 bit numbers
Microprocessor and Interfacing PIC Code Execution
George Mason University ECE 448 – FPGA and ASIC Design with VHDL Experiment 7 VHDL Modeling of Embedded Microprocessors and Microcontrollers.
PIC18F Programming Model and Instruction Set
EEE237 Introduction to Microprocessors Week x. SFRs.
Eng. Husam Alzaq The Islamic Uni. Of Gaza
Architecture and instruction set. Microcontroller Core Features:  Operating speed: DC - 20 MHz clock input DC ns instruction cycle Up to 8K x.
PIC Code Execution How does the CPU executes this simple program? void main() { int i; i = 1; i++; }
Department of Electronic & Electrical Engineering Template program. Input / Output (IO) ● Template program. ● Introduction to IO ● Setting up for IO ●
Department of Electronic & Electrical Engineering Lecture 2 ● Introduction to IO ● Using a subroutine ● Driving a 7seg display.
Working with Time: Interrupts, Counters and Timers
PIC12F629/675. “Wide variety” 8-84 pin RISC core, 12/14/16bit program word USART/AUSART, I 2 C, ADC, ICSP, ICD OTP/UV EPROM/FLASH/ROM Families: PIC12,
Chapter 5 Building Assembler Programs The aims of this chapter are to introduce: how to visualise a program, and represent it diagrammatically; how to.
Department of Electronic & Electrical Engineering Lecture 4. ➢ Loops ➢ Delays ➢ Conditional instructions ➢ Simple clock example.
Department of Electronic & Electrical Engineering Lecture 3. ● Template program. ● Introduction to IO ● PORTA PORTB TRISA TRISB ● Using a subroutine ●
Programming PIC 16F84A in Assembly. PIC16F84 pin-out and required external components.
5-2-1 PIC microcontroller. Learning objectives To aid revision, areas that are examinable are identified by a vertical line in the left margin. Where.
I/O PORTS. General purpose I/O pins can be considered the simplest of peripherals. They allow the PICmicro™ to monitor and control other devices. To add.
Applications examples. A binary count : stepped manually and reset with push buttons. Define ports Reset portd Reset =0? INCF portd no Step =0? yes.
1.  List all addressing modes of PIC18 uCs  Contrast and compare the addressing modes  Code PIC18 instructions to manipulate a lookup table.  Access.
Microprocessor Systems Design I
Chapter 9 PIC18 Timer Programming in Assembly
Microprocessor Systems Design I
Prof. Ahmad Abu-El-Haija
Microprocessor Systems Design I
Microprocessor Systems Design I
Micro-processor vs. Micro-controller
Microprocessor Systems Design I
INT. TO EMBEDDED SYSTEMS DEVELOPMENT
Microprocessor Systems Design I
Microprocessor Systems Design I
Microprocessor Systems Design I
PIC 16F877.
16.317: Microprocessor System Design I
Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
Projekt Anglicky v odborných předmětech, CZ.1.07/1.3.09/
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
INSTRUCTION SET.
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
Presentation transcript:

Building Assembler Programs Chapter Five Dr. Gheith Abandah1

Outline Building Structured Programs Conditional Branching and Working with Bits Subroutines Generating Time Delays and Intervals Indirect Addressing and PCL Using PCL Register for Lookup Table Flashing LEDs Example Dr. Gheith Abandah2

Building Structured Programs If you don’t watch it, assembly programs become spaghetti programs. It is better to develop structured programs; programs structured into routines with specific functions. Start by representing programs using: – Flow diagrams – State Diagrams Dr. Gheith Abandah3

4 Flow Diagrams Rectangle for process or action Diamond for decision

Dr. Gheith Abandah5 State Diagrams Some machines tend to move from one state to another when a time period is completed or a specific event occurs.

Conditional Branching and Working with Bits ; Testing and manipulating single bits movlw 00 ;clear all bits in port A and B movwf porta movwf portb loop bcf portb, 3 ;preclear port B, bit 3 btfss porta, 3 bsf portb, 3 ;but set it if button pressed ; bcf portb, 4 ;preclear port B, bit 4 btfss porta, 4 bsf portb, 4 ;but set it if button pressed goto loop end Dr. Gheith Abandah6

Subroutines Dr. Gheith Abandah7

Generating Time Delays and Intervals … call delay500 … ;500ms delay (approx) ;100 calls to delay5 delay500 movlw D'100' movwf delcntr2 del2 call delay5 decfsz delcntr2, 1 goto del2 return ;Delay of 5ms approx. ;Instr. Cycle T = 5us. ;200 iterations * 5T delay5 movlw D'200' movwf delcntr1 del1 nop ;1T decfsz delcntr1,1 ;1T goto del1 ;2T return Dr. Gheith Abandah8

Indirect Addressing and PCL Dr. Gheith Abandah9

Using PCL Register for Lookup Table.... movf sample_no,0 call table movwf portb.... tableaddwf pcl retlw 23 retlw 3f retlw 47 retlw 7f retlw 0a2 retlw 1f retlw 03 retlw 67 retlw 0c5 retlw 32 Dr. Gheith Abandah10 W = 5 W = 1f

Flashing LEDs Example – Page 1 ; ;specify SFRs pcl equ 02 status equ 03 porta equ 05 trisa equ 05 portb equ 06 trisb equ 06 ; pointer equ 10 delcntr1 equ 11 delcntr2 equ 12 ; Dr. Gheith Abandah11

Flashing LEDs Example – Page 2 org 00 ;Initialise start bsf status,5 ;select memory bank 1 movlw B' ' movwf trisa ;setup port A movlw 00 movwf trisb ;all port B bits output bcf status,5 ;select bank 0 ; Dr. Gheith Abandah12

Flashing LEDs Example – Page 3 ;The “main” program starts here movlw 00 ;clear all bits in port A movwf porta movwf pointer ;also clear pointer loop movf pointer,0 ;move pointer to W register call table movwf portb ;move W register to port B call delay incf pointer,1 btfsc pointer,3 ;test if pointer = 8 clrf pointer ;if yes, clear to start over goto loop Dr. Gheith Abandah13

Flashing LEDs Example – Page 4 ;Introduces delay of 500ms approx, for 800kHz clock delay movlw D'100' movwf delcntr2 outer movlw D'200' movwf delcntr1 inner nop nop decfsz delcntr1,1 goto inner decfsz delcntr2,1 goto outer return Dr. Gheith Abandah14

Flashing LEDs Example – Page 5 ;Lookup Table table addwf pcl retlw 23 retlw 3f retlw 47 retlw 7f retlw 0a2 retlw 1f retlw 03 retlw 67 ; end Dr. Gheith Abandah15

Summary It is important to devise good structures for programs as they are developed. Flow and state diagrams can help with this. A number of techniques assist in producing clear and well-structured programs. These include subroutines, look-up tables, macros and the use of Include files. The full 16F84A instruction set can be applied to build big and sophisticated programs. More complex programs require greater expertise in the use of simulation techniques. Dr. Gheith Abandah16