Dasturimizning blok-sxemasini tasvirlaymiz




Download 0,85 Mb.
bet7/8
Sana05.07.2024
Hajmi0,85 Mb.
#266659
1   2   3   4   5   6   7   8
Bog'liq
Djanzakov

2.2 Dasturimizning blok-sxemasini tasvirlaymiz:



2.3 Mikrokontrollerga C dasturlash tilida dastur yozish
#include
#include
#include
#include

#include "lcd.h"


unsigned int ADCdata, voltage_0, voltage, voltage_2, voltage_3, voltage_4, range;
//прерывание
ISR(ADC_vect)
{
ADCdata = ADCW; // В ADCW хранится напряжение в двоичном коде
voltage_0 = ADCdata * 48875 / 10000; // 5 вольт / 1023 = 4.8875
voltage = voltage_0 % 10000 / 1000;
voltage_2 = voltage_0 % 1000 / 100;
voltage_3 = voltage_0 % 100 / 10;
voltage_4 = voltage_0 % 10;

if (ADCdata > 3)


{
range = (6787 / (ADCdata - 3)) - 4;
}

ADCSRA = ADCSRA | 0x40;// Регистр для начала нового преобразования 0b01000000


}

void show_numbers()


{
lcd_gotoxy(0,0); // move cursor
lcd_puts("Voltage "); // displays the string on lcd

char buffer[12];


itoa(voltage, buffer, 10);


lcd_puts(buffer);

lcd_puts(",");


itoa(voltage_2, buffer, 10);


lcd_puts(buffer);

itoa(voltage_3, buffer, 10);


lcd_puts(buffer);

itoa(voltage_4, buffer, 10);


lcd_puts(buffer);

lcd_puts(" V");


lcd_gotoxy(0,1);


lcd_puts("Distance ");


itoa(range, buffer, 10);


lcd_puts(buffer);

lcd_puts(" cm");


_delay_ms(100);


}

int main (void)


{

DDRC = 0xFF; // Exit


DDRD = 0xFF;

ADMUX = 0x00; // PA0


ADCSRA = 0b11001110;

PORTB = 0x00;


PORTD = 0x00;
PORTC = 0x00;

lcd_init(LCD_DISP_ON); // initialize display, cursor off


sei();
while(1)


{
show_numbers();
};
}


Download 0,85 Mb.
1   2   3   4   5   6   7   8




Download 0,85 Mb.

Bosh sahifa
Aloqalar

    Bosh sahifa



Dasturimizning blok-sxemasini tasvirlaymiz

Download 0,85 Mb.