A2 After MID

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

MP

EEE342

Assignment # 02

Name Arslan Shabeer

Registration
Number FA20-BEE-033

Subject MP

Instructor’s Name Sir Sikender Gull SB


Q 1:
Write an Assembly program to implement the polynomial expression
Y = 𝑋2+𝑋+41 Code:
.ORG
.INCLUDE "M32DEF.INC"
LDI R16,0x00; //input
OUT DDRB,R16;
LDI R16,0xFF; //output
OUT DDRC,R16;

LDI ZH,HIGH(TABLE<<1); //high byte of addr


L1: LDI ZL,LOW(TABLE<<1); //low byte of addr
IN R16,PINB;
ANDI R16,0x0F; //mask upper bit
ADD ZL,R16;
LPM R18,Z; //get X^2 + X + 41 from the look_up table
OUT PORTC,R18;
RJMP L1;
.ORG 0x10

Q2:
Write a program for the Atmel AVR ATMega32 microcontroller which
continuously read the logic values on portB and write them to portC.
#include <avr/io.h>
#define F_CPU 16000000UL
#include <util/delay.h>
int main()
{ unsigned char
temp;
DDRB = 0x00;
DDRC = 0xFF;
while
(1)
{
temp = PINB;
PORTC = temp;
} return
0;
}
Qno3: Write description of each statement

Description

x[2] x is an array having value “2”

&x AND x
*p Pointer

x.age A variable “x” getting

delay_ms(250) Deley function is used

char x = 3;
x is a character having value “3”
(int) x

DDRA = 0x00; Declare PORTA is used as an input

DDRB = 0xFF; Declare PORTB is used as an output

Unsinged char I; i I is 8-bit register and


= PINA; Read data from PORTA and store in I register

Declare 1st 4-bit as an input (‘0’) and last 4-bit as an


DDRA = 0b11110000;
output(‘1’).

Q4: Compute the sum of 1 + 2 + … + 10.and sends final result to port-B.

CODE:
#include <avr/io.h>
#define F_CPU 16000000UL
#include <util/delay.h>
int
main()
{
DDRB =
0b11111111; int
ADD=0; int i=1;
while(i<11)
{
PORTB=ADD+i;
_delay_ms(1000);
i=i+1;
}
}
Q 5:
what is meant by Debouncing of switch and what are the method for removing
debouncing in switch( software as well as hardware).write code for removing Debouncing
for a circuit in with Switch is connected with Pin 2.
Electrical contact in mechanical push button switches often make and break contact several
times when the button is 1st pushed. A debouncing circuit removes the ripples in the signal and
provide a clean transition at its output.
Method of Debouncing:
There are three commonly used methd to remove debouncing.
• Hardware Debouncing
• RC Debouncing
• Switch Debouncing IC

CODE:
.INCLUDE "M32DEF.INC"

CBI DDRB,0;
AGAIN: SBIC PINB,0;

RJMP OVER;
LDI R16,0;
RJMP AGAIN;

OVER: LDI R16,0x1;


RJMP AGAIN;

You might also like