Ardino taymerlari bilan ishlash Arduinoda ikki XIL uzilishlar mavjud. Ular apparat uzilishlari



Download 0,57 Mb.
bet11/13
Sana16.01.2022
Hajmi0,57 Mb.
#377220
1   ...   5   6   7   8   9   10   11   12   13
Bog'liq
Ardinio timer

Bir vaqtning o'zida ikkita ISR 

Ushbu uzilishlarni bir vaqtning o'zida bir nechta taymerlar bilan birlashtira olasiz. Masalan, quyidagi kod 1-taymerda har 100 ms va 2 taymerda har 8,12 ms da uzilishni amalga oshirish uchun o'rnatiladi. Har bir uzilishda biz D5 va D6 pin holatini o'zgartiramiz. Men ushbu kodni yuklayman va 6-pinda har 100ms va 5-pinda har bir 8.12ms pulsga ega bo'laman.



bool LED_STATE1 = true;

bool LED_STATE2 = true;

void setup() {

pinMode(5,OUTPUT);

pinMode(6,OUTPUT);

cli(); //stop interrupts for till we make the settings

//Timer 1 (interrupt each 100ms)

TCCR1A = 0; // Reset entire TCCR1A to 0

TCCR1B = 0; // Reset entire TCCR1B to 0

TCCR1B |= B00000100; //Set CS12 to 1 so we get prescalar 256

TIMSK1 |= B00000010; //Set OCIE1A to 1 so we enable compare match A

OCR1A = 6250; //Finally we set compare register A to this value

//Timer2 (interrupt each 8.128 ms)

// interrupt time = 1/(16Mhz/1024) * 127 = 8.128ms;

TCCR2A = 0; // Reset entire TCCR1A to 0

TCCR2B = 0; // Reset entire TCCR1B to 0

TCCR2B |= B00000111; //Set CS20, CS21 and CS22 to 1 so we get prescalar 1024

TIMSK2 |= B00000100; //Set OCIE1B to 1 so we enable compare match B

OCR2B = 127; //Finally we set compare register B to this value

sei(); //Enable back the interrupts

}

void loop() {

// put your main code here, to run repeatedly:

}

//With the settings above, this IRS will trigger each 8.128ms.

ISR(TIMER2_COMPB_vect){

LED_STATE1 = !LED_STATE1; //Invert LED state

digitalWrite(5,LED_STATE1); //Write new state to the LED on pin D5

}

//With the settings above, this IRS will trigger each 100ms.

ISR(TIMER1_COMPA_vect){

TCNT1 = 0; //First, set the timer back to 0 so it resets for next interrupt

LED_STATE2 = !LED_STATE2; //Invert LED state

digitalWrite(6,LED_STATE2); //Write new state to the LED on pin D5

}


Download 0,57 Mb.

Do'stlaringiz bilan baham:
1   ...   5   6   7   8   9   10   11   12   13




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish