Vous êtes sur la page 1sur 6

Question #01

CODE:
#define F_CPU 16000000UL

#include <avr/io.h>

#include <avr/interrupt.h>

int main(void)

{ DDRB = 0xFF;

DDRD &= ~(1 << DDRD);

DDRD &= (4<<DDRD);

EICRA |= (1<<ISC01);

EIMSK |= (1<<INT0);

sei();

while (1)

{ TCCR1A = 0x00;

TCCR1B |=(1<<CS12);

TCNT1H = 0x0B;

TCNT1L = 0xDC;

while((TIFR1&(0x1<<TOV1))==1){}

TCCR1B = 0;

TIFR1 = (0x1<<TOV1);

PORTB = ~PORTB; }}

ISR (INT0_vect) {

PORTD ^= (1<<4); }
Question #02
CODE:
#include<avr/io.h>

#include<avr/interrupt.h>

int main()

DDRD = 0xFF;

DDRB = (1<<1);

TCNT1 = 34106;

TCCR1A = 0x00;

TCCR1B |= (1<<CS12);

TIMSK1 |= (1 << TOIE1) ;

TCCR0A |= (1<<WGM01);

TCCR0B = 01;

OCR0A = 127;

TIMSK0 = (1<<OCIE0A);

sei();

while(1)

{ }}

ISR (TIMER1_OVF_vect) {

PORTD ++;

TCNT1 = 34106; }

ISR(TIMER0_COMPA_vect){

OCR0A = 127;

PORTB ^= (1<<1);}
Question #03
CODE:
MASTER:
#include <avr/io.h>

#define F_CPU 8000000UL

#include <util/delay.h>

int main(void)

{ DDRB = 0;

int UBBRValue = 832;

UBRR0H = (unsigned char) (UBBRValue >> 8);

UBRR0L = (unsigned char) UBBRValue;

UCSR0B = (1 << RXEN0) | (1 << TXEN0);

UCSR0C = (1 << USBS0) | (3 << UCSZ00);

while (1)

{ while (! (UCSR0A & (1 << UDRE0)) );

{UDR0 = PINB;} }}
SLAVE:
#include <avr/io.h>

#define F_CPU 8000000UL

#include <util/delay.h>

#include <avr/interrupt.h>

unsigned char receiveData=0;

int main(void)

{ DDRD |= (1 << PIND0);

DDRC=0xFF;

int UBRR_Value = 832;

UBRR0H = (unsigned char) (UBRR_Value >> 8);

UBRR0L = (unsigned char) UBRR_Value;

UCSR0B = (1 << RXEN0) | (1 << TXEN0);

UCSR0C = (1 << USBS0) |

sei();

while (1){

if (receiveData == 'O')

PORTC =0b00000010;}

else{

PORTC =0;}}}

ISR(USART_RX_vect){

receiveData = UDR0;}
Question #04
CODE:
#define F_CPU 1000000UL

#include <avr/io.h>

#include<util/delay.h>

#include <avr/interrupt.h>

void lcd_cmd(unsigned char cmd){

PORTD = cmd;

PORTB &=~(0x01);

PORTB &=~(0x02);

PORTB |= (0x04);

_delay_ms(10);

PORTB &=~(0x04);

void lcd_data(unsigned char data){

lcd_cmd(0x38);

lcd_cmd(0x0e);

lcd_cmd(0x06);

PORTD = data;

PORTB &=~(0x02);

PORTB |= (0x04);

_delay_ms(10);

PORTB &=~(0x04);

void lcd_init(){

lcd_cmd(0x38);

lcd_cmd(0x0e);

lcd_cmd(0x06);

lcd_cmd(0x01);

lcd_cmd(0x80); }

void lcd_write_string(char *a)

int i;

for(i=0;a[i]!='\0';i++)

lcd_data(a[i]);}

char x=0;

char y=0;

int main (void) {


sei();

TCCR1B |= (1<<CS10)|(1<<CS11)|(1<<WGM12);

TIMSK1 |= (1<<OCIE1A);

OCR1A = 15624;

DDRD=0xff;

DDRB=0xff;

DDRC = 0;

ADCSRA= 0x8f;

ADMUX= 0xC4;

sei();

ADCSRA |= (1<<ADSC);//start conversion

while(1){

lcd_write_string("Roll No: 6969");

_delay_ms(100);}}

ISR(ADC_vect){

char t = (ADCL|(ADCH<<8))*10/93;//PORTB = adc value/9.3

x = 48+(t/10);

y = 48+(t%10);

lcd_init();

lcd_data(x);

lcd_data(y);

lcd_write_string("oC 160515");

_delay_ms(2000);

ADCSRA |= (1<<ADSC);

Vous aimerez peut-être aussi