1 / 16

Building Assembler Programs

Building Assembler Programs. Chapter Five. 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.

dylan
Télécharger la présentation

Building Assembler Programs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Building Assembler Programs Chapter Five Dr. Gheith Abandah

  2. 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 Abandah

  3. 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 Abandah

  4. Flow Diagrams Rectangle for process or action Diamond for decision Dr. Gheith Abandah

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

  6. 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 Abandah

  7. Subroutines Dr. Gheith Abandah

  8. 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 nop ;1T decfsz delcntr1,1 ;1T goto del1 ;2T return Dr. Gheith Abandah

  9. Indirect Addressing and PCL Dr. Gheith Abandah

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

  11. 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 Abandah

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

  13. 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 Abandah

  14. 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 Abandah

  15. 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 Abandah

  16. 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 Abandah

More Related