Documente Academic
Documente Profesional
Documente Cultură
Review on Lecture-2
Branching and Looping Loop inside loop Different types of JMP Instructions Different types of CALL Instructions Stack and Stack Pointer The PUSH and POP Instruction The Subroutine Call and Returning From it Pipelining Instruction Cycle Time for the AVR Calculation of Delay Time
IICT, BUET
IICT, BUET
IICT, BUET
SBIC Rd, K ; Rd = Rd - K - C
SBIW Rd:Rd+1, K ; Rd + 1 : Rd = Rd + 1 : Rd - K S In AVR, SBC and SBCI are subtraction with borrow. In AVR we use Carry flag for borrow and so SBC (SuB with Carry)
IICT, BUET
IICT, BUET
IICT, BUET
IICT, BUET
Notice that you should use SBIW Rd+1:Rd, K format If you type SWIB Rd:Rd+1, K the assembler will assemble your code as if you typed SBIW Rd+1:Rd, K
IICT, BUET
IICT, BUET
Multiplication Summary
------------------------------------------------------------------------------------------------------Multiplication Application Byte1 Byte2 High byte Low byte of result of result ------------------------------------------------------------------------------------------------------MUL Rd, Rr Unsigned numbers Rd Rr R1 R0 MULS Rd, Rr MULSU Rd, Rr Signed numbers Rd Rr R1 R0
IICT, BUET
IICT, BUET
An example of Division
.DEF NUM=R20 .DEF DENOMINATOR = R21 .DEF QUOTIENT = R22 LDI NUM, 95 LDI DENOMINATOR, 10 CLR QUOTIENT L1: INC QUOTIENT SUB NUM, DENOMINATOR BRCC L1 DEC QUOTIENT ADD NUM, DENOMINATOR HERE: JMP HERE
IICT, BUET
Assignment
Analyze the example 5-8 of page 168
IICT, BUET
In other words, the overflow flag is set the overflow flag is set to 1 if there is a carry from D6 to D7 or from D7 out but not the both It means that if there are carry both from D6 to D7 and from D7 out, V=0
IICT, BUET
IICT, BUET
Logical OR instruction
OR Rd, Rr ; Rd = Rd OR Rr This instruction will perform a logical OR operation on two operands and keep the result is left hand operator There are also ORI instruction to perform OR operation between the content of a register and an immediate value, the format is ORI Rd, K ; Rd = Rd OR K OR instructions affects the Z, S and N flags The OR instructions can be used to set certain bits of an operand to 1, for example LDI R20, 0x04 ORI R20, 0x30 ; now R20 will be 34H
IICT, BUET
EX-OR instruction
EOR Rd, Rs ; Rd = Rd XOR Rs This instruction performs EX-OR between two operands and keeps the result is the left operand The EX-OR will affect the Z, S and N flags EX-OR can be used to check whether the values in two registers are equal or not OVER : IN R20, PORTB LDI R21, 0x45 EOR R20, R21 BRNE OVER Another widely used application of EX-OR is to toggle the bits of an operand; EOR R0, R20, and R20 is initialized with 0xFF
IICT, BUET
IICT, BUET
Branch Instruction
Instruction Meaning BREQ BRNE BRSH BRLO Branch if equal Branch if not equal Branch if same or higher Branch if lower Condition Z=1 Z=0 C=0 C=1
BRLT
BRGE BRVS BRVC
S=1
V=1 V=0
MSB
LSB
MSB
LSB
IICT, BUET
Serializing Data
Serializing data is a way of sending a byte of data one bit at a time through a single pin of microcontroller There are two ways to transfer a byte of data serially
Using one serial port. In using the serial port, programmers have very limited control over the sequence of data transfer The second method of data transfer is to transfer one bit at a time and control the sequence of data and space between them in many new generation of devices such as LCD, ADC, ROM and the serial versions are becoming popular because they take less space on a printed circuit board
IICT, BUET
AGAIN:
ROR R20 BRCS ONE CBI PORTB, 1
Write a program to bring a byte of data serially through pin PC7 and save it in R20 register. The byte comes in LSB first
JMP HERE
Swap Instruction Nibble swapping left nibble goes to right and right to left
IICT, BUET
End of Lecture 3
IICT, BUET