LR 8
LR 8
Lab # 08
Ahmad Hassaan
Name
FA18-BEE-230
Registration Number
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;
}
Proteus simulation:
POST LAB TASK:
What is switch debouncing? Explain software and hardware methods for switch
debouncing.
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.