Muhammad al-Xorazmiy nomidagiToshkent axbarot texnologiyalari unversiteti Farg’ona Filali Telekonikatsiya texnologiyalari va kasb ta’limi fakulteti Telekomunikatsiyalari



Yüklə 307,91 Kb.
səhifə4/4
tarix20.07.2023
ölçüsü307,91 Kb.
#136989
1   2   3   4
O\'rnatilgan tizimlar M.ish.18.nomer

Ish haqida tushuntirish:


Uskuna va dasturiy ta'minotni tayyorlaganingizdan so'ng, kodni PIC16F877A qurilmangizga yuklang. Agar siz PIC uchun mutlaqo yangi bo'lsangiz , dasturni PIC16F877A mikrokontrolleriga qanday yuklashni bilish bo'yicha bir nechta qo'llanmalarni o'qib chiqishingiz kerak bo'ladi.
Namoyish maqsadida Dvigatel tezligini sozlash uchun o'zgaruvchan POTdan foydalandim. Haqiqiy vaqtda topish ilovasidan ham foydalanishingiz mumkin. Agar hamma narsa kutilganidek ishlayotgan bo'lsa, quyidagi videoda ko'rsatilganidek, siz Km/soatdagi Tezlikni va metrlarda bosib o'tilgan masofani olishingiz kerak.

Umid qilamanki, sizga loyiha yoqdi va u ishladi. Agar yo'q bo'lsa, shubhangizni joylashtirish uchun quyidagi sharh bo'limidan yoki forumdan foydalanishingiz mumkin. 
Kod
/*

PIC16F877A uchun tezlik o'lchagich va odometr

* Kod muallifi: B.Aswinth Raj

* Sana: 2017-07-27

* Batafsil ma'lumot: www.CircuitDigest.com

*/


# _XTAL_FREQ 20000000 ni aniqlang

#define RS RD2

#define EN RD3

#D4 RD4ni aniqlang

#D5 RD5ni aniqlang

#define D6 RD6

#D7 RD7ni aniqlang

#o'z ichiga


#pragma konfiguratsiyasi FOSC = HS // Osilatorni tanlash bitlari (HS osilatori)

#pragma config WDTE = OFF // Watchdog taymerini yoqish biti (WDT o'chirilgan)

#pragma config PWRTE = ON // Quvvat taymerini yoqish biti (PWRT yoqilgan)

#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR yoqilgan)

#pragma config LVP = OFF // Past kuchlanishli (Yagona ta'minot) In-Connew-da ketma-ket dasturlashni yoqish biti (RB3 raqamli I/U, MCLR da HV dasturlash uchun ishlatilishi kerak)

#pragma config CPD = OFF // Ma'lumotlar EEPROM xotira kodini himoya qilish biti (Ma'lumotlar EEPROM kodini himoya qilish o'chirilgan)

#pragma config WRT = OFF // Flash dastur xotirasini yozishni yoqish bitlari (Yozishdan himoyalanish o'chirilgan; barcha dastur xotirasi EECON boshqaruvi orqali yozilishi mumkin)

#pragma config CP = OFF // Flash dasturi xotira kodini himoya qilish biti (Kod himoyasi o'chirilgan)

int tezligi =0;

int milli_sec=0;

int rpm = 0;

int c1,c2,c3;

int d1, d2, d3;

int masofa;

// Circuit Digest tomonidan ishlab chiqilgan LCD funktsiyalari.

void Lcd_SetBit(char data_bit) //Hex qiymatiga asoslanib Ma'lumotlar liniyalarining bitlarini o'rnating

{

agar(ma'lumotlar_bit va 1) 



D4 = 1;

boshqa


D4 = 0;

agar(ma'lumotlar_bit va 2)

D5 = 1;

boshqa


D5 = 0;

agar(ma'lumotlar_bit va 4)

D6 = 1;

boshqa


D6 = 0;

agar (ma'lumotlar_bit va 8) 

D7 = 1;

boshqa


D7 = 0;

}


void Lcd_Cmd(char a)

{

RS = 0;



Lcd_SetBit(a); //Incoming Hex value

EN = 1;


__delay_ms(4);

EN = 0;


}

void Lcd_Clear()

{

Lcd_Cmd(0); //Clear the LCD



Lcd_Cmd(1); //Move the curser to first position

}


void Lcd_Set_Cursor(char a, char b)

{

char temp,z,y;



if(a== 1)

{

temp = 0x80 + b - 1; //80H is used to move the curser



z = temp>>4; //Lower 8-bits

y = temp & 0x0F; //Upper 8-bits

Lcd_Cmd(z); //Set Row

Lcd_Cmd(y); //Set Column

}

else if(a== 2)



{

temp = 0xC0 + b - 1;

z = temp>>4; //Lower 8-bits

y = temp & 0x0F; //Upper 8-bits

Lcd_Cmd(z); //Set Row

Lcd_Cmd(y); //Set Column

}

}


void Lcd_Start()

{

Lcd_SetBit(0x00);



for(int i=1065244; i<=0; i--) NOP();

Lcd_Cmd(0x03);

__delay_ms(5);

Lcd_Cmd(0x03);

__delay_ms(11);

Lcd_Cmd(0x03); 

Lcd_Cmd(0x02); //02H is used for Return home -> Clears the RAM and initializes the LCD

Lcd_Cmd(0x02); //02H is used for Return home -> Clears the RAM and initializes the LCD

Lcd_Cmd(0x08); //Select Row 1

Lcd_Cmd(0x00); //Clear Row 1 Display

Lcd_Cmd(0x0C); //Select Row 2

Lcd_Cmd(0x00); //Clear Row 2 Display

Lcd_Cmd(0x06);

}


void Lcd_Print_Char(char data) //Send 8-bits through 4-bit mode

{

char Lower_Nibble,Upper_Nibble;



Lower_Nibble = data&0x0F;

Upper_Nibble = data&0xF0;

RS = 1; // => RS = 1

Lcd_SetBit(Upper_Nibble>>4); //Send upper half by shifting by 4

EN = 1;

for(int i=2130483; i<=0; i--) NOP(); 

EN = 0;

Lcd_SetBit(Lower_Nibble); //Send Lower half

EN = 1;

for(int i=2130483; i<=0; i--) NOP();

EN = 0;

}


void Lcd_Print_String(char *a)

{

int i;



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

Lcd_Print_Char(a[i]); //Split the string using pointers and call the Char function 

}

/*****End of LCD Functions*****/


/****Interrupt function ****/

void interrupt speed_isr()

{

if(TMR0IF==1) // Timer has overflown



{

TMR0IF=0; // Clear timer interrupt flag

milli_sec++;




if (INTF==1)

{

rpm = (1000/milli_sec) * 60;



speed = 0.3 * rpm * 0.37699; // (Assuming the wheel radius to be 30cm)

INTF = 0; // clear the interrupt flag

milli_sec=0;

distance= distance+028.2;

}

}

/****End of Interrupt Function****/


int main()

{

TRISD = 0x00; //PORTD declared as output for interfacing LCD



TRISB0 = 1; //DEfine the RB0 pin as input to use as interrupt pin

OPTION_REG = 0b00000101; // Timer0 with external freq and 64 as prescalar // Also Enables PULL UPs

TMR0=100; // Load the time value for 1ms; delayValue can be between 0-256 only

TMR0IE=1; //Enable timer interrupt bit in PIE1 register

GIE=1; //Enable Global Interrupt

PEIE=1; //Enable the Peripheral Interrupt

INTE = 1; // RB0 ni tashqi uzilish pin sifatida yoqing

Lcd_Start();


while(1)


c1 = (tezlik/100)%10;

c2 = (tezlik/10)%10;

c3 = (tezlik/1)%10;

d1 = (masofa/100)%10;

d2 = (masofa/10)%10;

d3 = (masofa/1)%10;

agar (milli_sek>1000)

{

tezlik=0;



}

Lcd_Set_Cursor(1,1);

Lcd_Print_String("Tezlik(km/soat): ");

Lcd_Print_Char(c1+'0');

Lcd_Print_Char(c2+'0');

Lcd_Print_Char(c3+'0');

Lcd_Set_Cursor(2,1);

Lcd_Print_String("Dist_Cov(m): ");

Lcd_Print_Char(d1+'0');

Lcd_Print_Char(d2+'0');

Lcd_Print_Char(d3+'0');

}

qaytish 0;



}
Yüklə 307,91 Kb.

Dostları ilə paylaş:
1   2   3   4




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin