0% found this document useful (0 votes)
9 views7 pages

LR 8

microprocessor lab report 8

Uploaded by

ahmad hassaan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views7 pages

LR 8

microprocessor lab report 8

Uploaded by

ahmad hassaan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

MP

Lab # 08

Ahmad Hassaan
Name

FA18-BEE-230
Registration Number

Instructor’s Name Adeel Javed


In lab task 1:

Code:
/*
* la_b_8.c
*
* Created: 28/11/2020 10:16:25 pm
* Author: Junaid Computers
*/

#include <avr/io.h>
#include <avr/interrupt.h>
#define F_CPU 16000000UL
unsigned char counter=0;
ISR(INT0_vect)

{
counter++;
PORTB=counter;
}
ISR(INT1_vect)
{
counter=0x00;
PORTB=counter;
}
int main()
{
DDRB=0xff;
counter=0;
SREG|=(1<<7);
EIMSK|=(1<<INT1);
EIMSK|=(1<<INT0);
EICRA|=(1<<ISC11);
EICRA|=(1<<ISC10);
EICRA|=(1<<ISC00);
(1<<ISC01);
while (1)
{
}
}

Proteus simulation:
In lab task 2:

Code:
/*
* la_b_8.c
*
* Created: 28/11/2020 10:16:25 pm
* Author: Junaid Computers
*/

#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#define F_CPU 16000000UL
ISR(INT0_vect)

{
for (int i=0; i<20; i++)
{
PORTC=0x00;
_delay_ms(100);
PORTC=0xff;
_delay_ms(100);
}
}
int main()
{
DDRC=0xff;
PORTC=0;
SREG|=(1<<7);
EIMSK|=(1<<INT1);
EICRA|=(1<<ISC11);
EICRA|=(1<<ISC10);
EICRA|=(1<<ISC00);
(1<<ISC01);
while (1)
{
}
}

Proteus simulation:

In lab task 3:

Code:
/*
* la_b_8.c
*
* Created: 28/11/2020 10:16:25 pm
* Author: Junaid Computers
*/

#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#define F_CPU 16000000UL
#define ADC_channel0 0
#define ADC_channel1 1
#define ADC_channel2 2
unsigned char ADC_intialize();
unsigned int ADC_read(unsigned char channel);
#define DAC_DDR DDRD
#define DAC_PORT PORTD
ISR(ADC_vect)

{
DAC_PORT=ADCH;
}
int main(void)
{
ADC_intialize();
DIDR0=0xff;
DAC_DDR=0xff;
ADMUX &=~(0x07);
ADMUX|=ADC_channel1;
SREG |=(1<<7);
ADCSRA|=(1<<ADSC);
while (1);
{
}
}
unsigned char ADC_intialize()
{
ADMUX |=((1<<ADLAR)|(1<<REFS0));
ADCSRA |=(1<<ADEN);
ADCSRA |=((1<<ADPS0)|(1<<ADPS1)|(1<<ADPS2));
ADCSRA |=(1<<ADIE)|(1<<ADATE);
return 0;
}

unsigned int ADC_Read(unsigned char channel)


{
unsigned char ADC_lo;
unsigned char ADC_hi;
unsigned int result;
ADMUX &= ~(0x07);
ADMUX |= channel;
_delay_us(10);
while((ADCSRA & (1<<ADSC)) != 0);
ADCSRA |= (1 << ADSC);
while((ADCSRA & (1<<ADIF)) == 0);
ADCSRA |= (1<<ADIF);
ADC_lo = ADCL;
ADC_hi = ADCH;
result = (ADC_hi<<2)|(ADC_lo >> 6);
return result;
}

Proteus simulation:
POST LAB TASK:
What is switch debouncing? Explain software and hardware methods for switch
debouncing.

Switch bouncing is the non-ideal behavior of any switch, which


generates multiple transitions of a single input. Switch bouncing is not a
major problem when we deal with the power circuits, but it cause
problems while we are dealing with the logic or digital circuits. Hence,
to remove the bouncing from the circuit switch debouncing circuit is
used.
SOFTWARE:

Debouncing occurs in software also, while programming programmers


add delays to get rid of software debouncing. Adding a delay force the
controller to stop for a particular time period, but adding delays is not a
good option into the program, as it pause the program and increase the
processing time. The best way is to use interrupts in the code for
software bouncing.

HARDWARE:
In the hardware debouncing technique, we use an S-R flip-flop to
prevent the circuit from switch bounces. This is the best debouncing
method among all.

CRITICAL ANALYSIS AND CONCLUSION:


We have learnt how to use the avr studio to generate interrupts and use them for our lab tasks.
We have learnt how to simulate them on proteus software.

You might also like