1 / 20

Microprocessor and Microcontroller Based Systems

بسم الله الرحمن الرحيم. The Islamic University of Gaza Faculty of Engineering Electrical Engineering Department. Microprocessor and Microcontroller Based Systems. EELE 4315 — Fall 2010. Instructor: Eng.Moayed N. EL Mobaied. Lecture 8.

moe
Download Presentation

Microprocessor and Microcontroller Based Systems

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. بسم الله الرحمن الرحيم The Islamic University of Gaza Faculty of Engineering Electrical Engineering Department Microprocessor and Microcontroller Based Systems EELE 4315 — Fall 2010 Instructor: Eng.Moayed N. EL Mobaied Lecture 8

  2. Initial Program Design – Flow Diagram (chart)

  3. An Alternative Program Visualisation - State Diagrams

  4. Conditional Branching One of the most important features of any microprocessor or microcontroller program is its ability to make “decisions”, i.e. to act differently according to the state of logical variables. Many microprocessors have within their instruction sets a number of instructions which allow them to test a particular bit, and either continue program execution if the condition is not met, or branch to another part of the program if it is. Often these variables are bit values in the Status Registers. The PIC 16 Series microcontrollers have four conditional “skip” instructions. These test for a certain condition, and skip just one instruction if the condition is met, and continue normal program execution if it is not. The most versatile and general-purpose of these are: btfsc f,b btfss f,b

  5. Testing and Manipulating Single Bits ;The “main” program starts here 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

  6. Subroutines The subroutine is a program section structured in such a way that it can be called from anywhere in the program. Once it has been executed the program continues to execute from wherever it was before. The PIC 16 Series subroutine call and return instructions are call and return.. Subroutine Call and Return instructions must always work in pairs.

  7. A Subroutine Example: Software Time Delays As long as the microcontroller is driven by a stable clock oscillator, we know precisely how long any instruction takes to execute. We can therefore write time delays of very high accuracy.

  8. A Subroutine Example: Software Time Delays A Delay Subroutine ;Delay of 5ms approx. Instruction cycle time is 5us. delay5 movlw D'200' ;200 cycles called, each taking 5x5=25us movwf delcntr1 del1 nop ;1 inst. cycle nop ;1 inst. cycle decfsz delcntr1,1 ;1 inst. cycle, when no skip goto del1 ;2 inst. cycles return Nested Subroutines for Greater Delay ;500ms delay (approx) ;100 calls to delay5 delay500 movlw D'100' movwf delcntr2 del2 call delay5 decfsz delcntr2,1 goto del2 return

  9. Time calculation Instruction MOVLW .10 take one cycle and instruction MOVWF take one cycle. Instruction DECFSZ take one cycle when escape don’t make but it take 2cycle when escape is made ,so it repeat 9 times as one cycle and take two cycles for one time. NOP take one cycle but it repeat 10 times. GOTO take 2cycle but it repeat 9 time,

  10. Time calculation

  11. Time calculation Where Tc is the time of cycle in seconds.

  12. Time calculation Where Tc is the time of cycle in seconds.

  13. Time calculation Where Tc is the time of cycle in seconds.

  14. OPCODE The PIC 16 Series has four possible instruction word formats, The instruction word is made up of 14 bits. These appear as bits 0 to 13. The opcode, the actual instruction part of the instruction word, always occupies the highest bits of the instruction word. f (Register file) : f can specify an address from 0(00h) to 127(7Fh) because it is 7 bits. In case of PIC16F84A, because the register memory is 80 bytes including SFR, it is possible to be specified by f if being 7 bits.

  15. ADDRESSING MODES RAM memory locations can be accessed directly or indirectly. Direct Addressing is done through a 9-bit address. This address is obtained by connecting 7th bit of direct address of an instruction with two bits (RP1, RP0) from STATUS register

  16. Direct Addressing mode

  17. Direct Addressing mode Any access to SFR registers can be an example of direct addressing.

  18. indirect Addressing mode It does not take an address from an instruction, but it derives it from IRP bit of STATUS and FSR registers. Addressed location is accessed through INDF register which in fact holds the address indicated by the FSR. Indirect addressing is very convenient for manipulating data arrays located in GPR registers. In this case, it is necessary to initialize FSR register with a starting address of the array, and the rest of the data can be accessed by incrementing the FSR register.

  19. Example for indirect addressing

  20. Configuration register The configuration bits can be programmed (read as '0'),or left un programmed (read as '1'), to select various device configurations. These bits are mapped in program memory location 2007h. Address 2007h is beyond the user program memory space and it belongs to the special test/configuration memory space (2000h - 3FFFh). This space can only be accessed during programming.

More Related