microprocessor and microcontroller based systems
Post on 11-Jan-2016
72 Views
Preview:
DESCRIPTION
TRANSCRIPT
Microprocessor and Microcontroller Based Systems
Instructor: Eng.Moayed N. EL Mobaied
The Islamic University of GazaFaculty of EngineeringElectrical Engineering Department
الرحمن الله بسمالرحيم
EELE 4315 — Fall 2010
Lecture 8
Initial Program Design – Flow Diagram (chart)
Read Actual Temperature TA
Read DemandTemperature TD
TA > TD ?
ActivateCompressor
Switch offCompressor
TA >> TD ?
ActivateAlarm
Yes
Yes
No
No
An Alternative Program Visualisation - State Diagrams
Fillwater
Heatwater
WashRinse
Spin Fault
Ready
User initiates
Full leveldetected
Timeout
Requiredtemperature
reached
Out ofbalance
Out ofbalance
Motorfailure
Motorfailure
Functioncomplete
Functioncomplete
Functioncomplete
Faultcleared
Start!
Door closed
Timeout
Conditional Branching
Subtract A from B
Result = 0?
Add C to D
No
Yes
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,bbtfss f,b
Testing and Manipulating Single BitsTesting and Manipulating Single Bits
;The “main” program starts heremovlw 00 ;clear all bits in port A and Bmovwf portamovwf portb
loop bcf portb, 3 ;preclear port B, bit 3btfss porta, 3bsf portb, 3 ;but set it if button pressed
;bcf portb, 4 ;preclear port B, bit 4btfss porta, 4bsf portb, 4 ;but set it if button pressed
goto loopend
SubroutinesSubroutines
Do this
Do that
Do something else
Call SR1
Call SR2
Call SR1
Main Program
SR1
Return
SR2
Subroutine 1 Subroutine 2
Return
.......
.......
.......
.......
.......
.......
.......
.......
.......
.......
.......
.......
.......
.......
Do that
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.
A Subroutine Example: Software Time DelaysA 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.
Load Counter1
Decrement Counter1
(Padding, eg "No Ops.")
Is Counter1 Zero?No
Yes
Load Counter 2
Decrement Counter2
Is Counter2 Zero?No
Yes
(Disable all Interrupts)
Load Counter
Decrement Counter
(Padding, eg "No Ops.")
Is Counter Zero?No
Yes
(Disable all Interrupts)
Load Counter
Decrement Counter
Call Delay subroutine
Is Counter Zero?No
Yes
(Disable all Interrupts)
A Subroutine Example: Software Time DelaysA Subroutine Example: Software Time Delays
;Delay of 5ms approx. Instruction cycle time is 5us.delay5 movlw D'200' ;200 cycles called, each taking 5x5=25us movwf delcntr1del1 nop ;1 inst. cycle nop ;1 inst. cycle decfsz delcntr1,1 ;1 inst. cycle, when no skip goto del1 ;2 inst. cycles return
A Delay Subroutine
;500ms delay (approx) ;100 calls to delay5delay500 movlw D'100' movwf delcntr2del2 call delay5 decfsz delcntr2,1 goto del2 return
Nested Subroutines for Greater Delay
Time calculationTime 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,
Time calculationTime calculation
Time calculationTime calculation
Where Tc is the time of cycle in seconds.
Time calculationTime calculation
Where Tc is the time of cycle in seconds.
Time calculationTime calculation
Where Tc is the time of cycle in seconds.
OPCODEOPCODE
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.
ADDRESSING MODESADDRESSING 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 bitof direct address of an instruction with two bits (RP1, RP0) from STATUS register
Direct Addressing modeDirect Addressing mode
Direct Addressing modeDirect Addressing mode
Any access to SFR registers can be an example of direct addressing.
indirect Addressing modeindirect 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 GPRregisters. 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.
Example for indirect addressingExample for indirect addressing
Configuration registerConfiguration 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. Address2007h 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.
top related