Académique Documents
Professionnel Documents
Culture Documents
CODE:
#define F_CPU 16000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
int main(void)
{ DDRB = 0xFF;
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);
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>
#include <util/delay.h>
int main(void)
{ DDRB = 0;
while (1)
{UDR0 = PINB;} }}
SLAVE:
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
int main(void)
DDRC=0xFF;
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>
PORTD = cmd;
PORTB &=~(0x01);
PORTB &=~(0x02);
PORTB |= (0x04);
_delay_ms(10);
PORTB &=~(0x04);
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); }
int i;
for(i=0;a[i]!='\0';i++)
lcd_data(a[i]);}
char x=0;
char y=0;
TCCR1B |= (1<<CS10)|(1<<CS11)|(1<<WGM12);
TIMSK1 |= (1<<OCIE1A);
OCR1A = 15624;
DDRD=0xff;
DDRB=0xff;
DDRC = 0;
ADCSRA= 0x8f;
ADMUX= 0xC4;
sei();
while(1){
_delay_ms(100);}}
ISR(ADC_vect){
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);