Вы находитесь на странице: 1из 3

intrerupere

REFS1:REFS0=00
AREF;01AVcc;10Rezerv,11interior 2.56V;
Flagurile se instaleaza . 0 -
ADLAR=0 ADCH se scriu numai bitii 9 si
TCNT0 reg
10,restu ADCL;
OCR0.
ADLAR=1 ADCL se scriu numai ultimii 2 biti 6
TOV0 -1
si 7;
.
MUX3:0=alegem canalul analog:0000-
OCF0 - 1
ADC0;0001-ADC1;

0010;0011;0100-ADC4;0101-ADC5;0110- ,
ADC6;0111-ADC7 ICP1

ADEN-0 ADC disable;1 enable; 10-


,
ADSC-single converter;0-convert
0 1.
terminate;1start convert
PSR10
ADFR-free running;0-convertire single;1-
in 1.
convertire neintre
ADIF-Flag convertire.bitul se activeaza cind
termina conver
ADIE-permit convert.0-convert interzis 1
permis
ADPS2:0- ACD-1 interzice lucrul, 0 permite.
ACBG- 1 - , 0 .pitanie 1.23V
prescaler;000/2;001/2;010/4;011/8;100/16;101
ACO-
-32;110/64;111/128;

//
ACI in dependent de ACIS1
void ADC_init(){ ADMUX = 0x00; ADCSRA =
ACIS0.
0x8D;}
ACIE - ermite 1
//
( I SREG),
ACIC
unsigned int ADC_result(unsigned char 1. 1 on 0 of
adc_input)
{ADMUX=adc_input | (ADMUX &
0xF0);_delay_us(10);
// (ADSC = 1); ;
ADCSRA | = 0x40;while((ADCSRA & LDI R16,(1<<ACBG)|(1<<ACIE)|
0x10)==0); (1<<ACIS1)|(1<<ACIS0)
//, OUT ACSR,R16 ;
(ADIF = 0) IN R16,SFIOR ;
ADCSRA|=0x10;// ADIF SFIOR
return ADCW;}//ADCW - ADCH ORI R16,(1<<ACME) ;
ADCL ACME
OUT SFIOR,R16
Modulul TIMER
; ,

LDI R16,5 ;
000-nici o sursa de tact;001-ceasul intern;010- 5
prescaler8; OUT ADMUX,R16
011-64;100-256;101-1024;110-sursa externa
de tact la pin T0 fron decrescator;111-s.extern Timer 1
la T0 fron crescator; TCNT1H si L
unsigned char sreg;unsigned int i;
sreg = SREG;#asm
cli; opreste sistemul de intreruperi
TOIE0 -0- p , 1 -
#endasm
. i = TCNT1; //copiaza TCNT1 in variabila i
OCIE0 -0 , 1 SREG = sreg;/pornim sistemul de intreruperi
.
I SREG trebuie sa fie activat pu

(TIMSK=0x10)
TCNT1. .
WinAVR
CS1 Surs/Prescalare000- oprit;001- far prescalare;
010- 8;011- 64;100- 256;101- 1024;110-surs
extern a tactului la pinul T1,incrementare pe #include <iom8.h>#include <avr/io.h>#inclu
frontul descresctor; de <avr/irrt.h>
#define F_CPU 2048000ISR(TIMER1_COMPA_ve
ct)
//
Pentru ca timerul s genereze o ntrerupere la
{TCNT1H=0;//
suprancrcarea registrului TCNT1 trebuie s se permit TCNT1;TCNT1L=0;}
folosirea sistemului de ntreruperi i trebuie ca bitul 2 din int main(){DDRB=0x02;// OC1A
registru, bitul TOIE, s fie 1.Cererea de ntrerupere este
marcat n registrul TIFR prin bitul TOV1: PORTB=0x00;TCCR1A=0x40;//
OC1A

TCCR1B=0x05;//CLK/1024OCR1AH=0x03;//
OCR1A
Dac se genereaz o cerere de ntrerupere bitul 1000;bbbOCR1AL=0xE8;
TOV1 devine 0 el fiind automat setat cu valoarea TIMSK = 0x10;//
1.Dup ce este executat rutina de tratare a
ntreruperii bitul se seteaz automat 1 sei();//
;while(1);}
Lab7 ADC;
#de F_CPU #defDIV 64 #de F_T0 F_CPU/DIV
#F_INT 200#def TCNT0_init (256 - F_T0/F_INT)
#define ADC_MAX 1023#define VOLT_MAX 5
int ConvertDataToVoltage()
{int Voltage = (Colect_Data() * VOLT_MAX)/ADC_MAX;
return Voltage;}ISR(ADC_vect){
int Volt = ConvertDataToVoltage();
interrupt[TIM1_OVF]void timer1_ovf_isr(void) f (ind == 0){ADC_MUX_Select(1);ind = 1;V[0] =
Volt;}else{ADC_MUX_Select(0);ind = 0;V[7] = Volt;}
{// setarea valorilor NLC-ului#asm;cli ;#endasm ADCSRA |= (1 << ADSC);}
TCNT1H=0x4C; TCNT1L=0x4B;;sei//schimbarea void ADC_init(){ADC_Enable();ADC_AutoTrigEnble();
starii portului ADC_ISR_Enable();ADC_Prescaler_Select(0b00000011);
PORTB.0 = ~PORTB.0; n aceast rutin nu facem ADC_MUX_Ref (0b01000000);ADC_Start();}
altceva dect s initializm TCNT-ul i s ISR(TIMER0_OVF_vect){TCNT0 = TCNT0_init;Afisare();
}void TIMER0_init(){TCNT0 = TCNT0_init;TIMSK |=
schimbm val.portului B. (1<<TOIE0);TCCR0 |= (1 << CS01);}
ledul licareste. int main(void)
, {Port_init();ADC_init();TIMER0_init();sei();
2.048, , while(1){ asm("nop");
OC1A Lab 6
1. ? ISR(TIMER0_OVF_vect){TCNT0 = TCNT0_init;
OC1A - Determinare();Afisare();counter ++;
if (counter > 199){counter = 0;}asm("nop");}
0.5.

TCCR1A 0x40 (. 1). void Port_init(){DDRA = 0xf;PORTA = 0x00;iesir
void TIMER0_init(){
. .. 1 TCNT0 = TCNT0_init;TIMSK |= (1<<TOIE0);
TCCR0 |= (1 << CS01);}

int main(void)
1024, {Port_init();
TCCR1B 0x05 (. 2). TIMER0_init();unsigned char secunde = 22;
unsigned char minute = 49;unsigned char ore = 15;
2048000/1024=2000, .. 1 1 unsigned char zile = 05;
2000, TablouInitiere(secunde, minute,ore,zile);sei();
0.5. while(1) { asm("nop"); }}
2000/2=1000 (0x03E8). Lab5
OCR1A. 1 ISR(INT0_vect) {}
1000, void Port_init(){DDRD =0b100;PORTD = 0b01111111}
void INT0_init() {MCUCR |= (1<<ISC01);
OCR1A OC1A
GICR |= (1<<INT0);GIFR |= (1<<INTF0);}
,
void main(void){Port_init();INT0_init();sei
.
while(1){PORTD |= (1<<PD7); clipire void freqmeterPoll (void){ static u32
led_delay_ms(100);PORTD &= (1<<PD7); freqstamp;
_delay_ms(100);}} u16 CT1val; if (timestamp > freqstamp)
Time captured , {CT1val = TCNT1;TCNT1 = 0;reqstamp =
,
. timestamp +100;pmsg(CRLF); sprintf(txtbuf,
"%u", CT1val); msg(txtbuf); }}
#include <mega8.h> / 1
long x=0,y=0,z=0;interrupt [TIM1_CAPT] void TIM_Init(void){TIMSK = (1<<TICIE1);
void timer1_capt_isr(void){if(x==0) // TCCR1A=(0<<WGM11)|(0<<WGM10);
TCCR1B=(0<<ICNC1)|(1<<ICES1)|(0<<WGM13)|
(0<<WGM12)|(0<<CS12)|(0<<CS11)|(1<<CS10); TCNT1 =
{x=ICR1;} else//2 y, 0;}
{y=ICR1;z=y-x;#asm("cli")}}void main(void) PWM
#include <mega8.h> void main(void)
{PORTB=0x01;DDRB=0x00;TCCR1A=0x00; {PORTB=0x00;DDRB=0x08;
TCCR1B=0x43;TCNT1=0x00;ICR1=0x00; // Timer/Counter 2 initialization
TIMSK=0x20;#asm("sei") while (1){ } ASSR=0x00;TCCR2=0x6C;TCNT2=0x00;
OCR2=0x00;TIMSK=0x00; while(OCR2<0xff)
T1 {OCR2=OCR2+0x01; delay_ms(5);}
/ T/ 1 while(OCR2>0x00){OCR2=OCR2-0x01; delay_ms(5
. OCR2=0x00 30% (255/100)*30=77
void freqmeterInit (void){TCCR1B = TCCR2=0x6C 2:0 prescal
(1<<CS12)|(1<<CS11);