1 Mikrokontrollerlar va isis proteus dasturi haqida asosiy tushunchalar


Issiqxona xaroratini aftomatik boshqaruvchi tizim dasturini ishlab chiqish



Download 1,92 Mb.
bet10/12
Sana10.07.2022
Hajmi1,92 Mb.
#768141
1   ...   4   5   6   7   8   9   10   11   12
Bog'liq
1 Mikrokontrollerlar va isis proteus dasturi haqida asosiy tushu

Issiqxona xaroratini aftomatik boshqaruvchi tizim dasturini ishlab chiqish.

#include
#include
#include
#define F_CPU 1000000UL // Mikrokontrollerni sinxronizatsiya chasotasi1МГц
#define DQ 0
#define RS 1
#define RW 2
#define E 3
//*******************************************************************
void count_termo(uint16_t counter);
void display_init(void);
void display_write(uint8_t reg, uint8_t bit, uint8_t display_data);
void display_write_word(uint8_t data[], uint8_t counter);
uint16_t sensor_write(uint8_t function_cmd, uint8_t scratchpad);
void sensor_write_1_0(uint8_t bit);
uint8_t sensor_read_1_0(void);
//****************************************************************
int main(void)
{
// kirish\chiqish liniyasini sozlash
uint16_t counter; // taymer o'zgaruvchilar
DDRB=254; // 7 liniya boshqarish displeyi, 1-liniya o`lchov
PORTB=0; // PB1-PB7 liniyalari va rezistr PB0 ni qayta o'rnatish
// tashqi qo`shimcha qurilmaarni sozash
display_init(); // initializatsia displeyi
sensor_write(0x4E, 0x1F); // 9-bitli o`zgartirish natijasi
while(1)
{
sensor_write(0x44, 0x00); // temperaturani o`zgarishi
_delay_ms(200);
counter=sensor_write(0xBE, 0x00); // temperature ma`lumotlarini o`qish
display_write(0, 0, 0x1);
_delay_ms(20); // xizmni bajarish uchun ketadigan vaqt
count_termo(counter);
}
}
//*******************************************************************
void count_termo(uint16_t counter)
{
uint16_t buffer;
uint8_t doli=0; // ulush
uint8_t edin=0; // yagona
uint8_t des=0; // o`nlik
uint8_t sot=0; // yuzlik
counter=counter>>3;
buffer=counter;
if ((counter & 256)==256)
{
;
}

else if ((counter & 256)==0)


{
counter=buffer;
while(counter>0)
{
++doli;
if (doli>1)
{
doli=0;
++edin;
if (edin>9)
{
edin=0;
++des;
if (des>9)
{
des=0;
++sot;
}
}
}
--counter;
}
if (sot==1)
{
display_write_word("1", 1);
if (des==0)
display_write_word("0", 1);
else if (des==1)
display_write_word("1", 1);
else if (des==2)
display_write_word("2", 1);
else if (des==3)
display_write_word("3", 1);
else if (des==4)
display_write_word("4", 1);
else if (des==5)
display_write_word("5", 1);
else if (des==6)
display_write_word("6", 1);
else if (des==7)
display_write_word("7", 1);
else if (des==8)
display_write_word("8", 1);
else if (des==9)
display_write_word("9", 1);
if (edin==0)
display_write_word("0", 1);
else if (edin==1)
display_write_word("1", 1);
else if (edin==2)
display_write_word("2", 1);
else if (edin==3)
display_write_word("3", 1);
else if (edin==4)
display_write_word("4", 1);
else if (edin==5)
display_write_word("5", 1);
else if (edin==6)
display_write_word("6", 1);
else if (edin==7)
display_write_word("7", 1);
else if (edin==8)
display_write_word("8", 1);
else if (edin==9)
display_write_word("9", 1);
display_write_word(",", 1);
if (doli==0)
display_write_word("0", 1);
else if (doli==1)
display_write_word("5", 1);
return;
}
else if (des>0)
{
if (des==1)
display_write_word("1", 1);
else if (des==2)
display_write_word("2", 1);
else if (des==3)
display_write_word("3", 1);
else if (des==4)
display_write_word("4", 1);
else if (des==5)
display_write_word("5", 1);
else if (des==6)
display_write_word("6", 1);
else if (des==7)
display_write_word("7", 1);
else if (des==8)
display_write_word("8", 1);
else if (des==9)
display_write_word("9", 1);
if (edin==0)
display_write_word("0", 1);
else if (edin==1)
display_write_word("1", 1);
else if (edin==2)
display_write_word("2", 1);
else if (edin==3)
display_write_word("3", 1);
else if (edin==4)
display_write_word("4", 1);
else if (edin==5)
display_write_word("5", 1);
else if (edin==6)
display_write_word("6", 1);
else if (edin==7)
display_write_word("7", 1);
else if (edin==8)
display_write_word("8", 1);
else if (edin==9)
display_write_word("9", 1);
display_write_word(",", 1);
if (doli==0)
display_write_word("0", 1);
else if (doli==1)
display_write_word("5", 1);
return;
}
else if (edin==0)
display_write_word("0", 1);
else if (edin==1)
display_write_word("1", 1);
else if (edin==2)
display_write_word("2", 1);
else if (edin==3)
display_write_word("3", 1);
else if (edin==4)
display_write_word("4", 1);
else if (edin==5)
display_write_word("5", 1);
else if (edin==6)
display_write_word("6", 1);
else if (edin==7)
display_write_word("7", 1);
else if (edin==8)
display_write_word("8", 1);
else if (edin==9)
display_write_word("9", 1);
display_write_word(",", 1);
if (doli==0)
display_write_word("0", 1);
else if (doli==1)
display_write_word("5", 1);
return;
}
}
//funksiya
// display_init – funksiyani qayta ko`rib chiqish displeyi
void display_init(void)
{
// ko`rib chiqish displeyi
_delay_ms(20); // pitaniyani o`rnaish uchun 20 ms kutish
display_write(0, 1, 0x3); // 8 bitli razryadni sozlash
display_write(0, 1, 0x3); // 8 bitli razryadni sozlash
display_write(0, 1, 0x3); // 8 bitli razryadni sozlash
display_write(0, 1, 0x2); // 4 bitli razryadni sozlash
display_write(0, 0, 0x28); // o`zgarilivchilarni o`rnatish
display_write(0, 0, 0x8); //displeyni o`chirish
display_write(0, 0, 0x1); // displeyni tozalash
_delay_ms(20); // pitaniyani o`rnaish uchun 20 ms kutish
display_write(0, 0, 0x6); // m`lumotlarni o`rnatish rejimi
display_write(0, 0, 0xC); // displeyni oqish
}
// display_write – displeydagi ma`lumotlarni funksiyasini yozish
// reg - 0/1 => buyruq\ma`lumot
// bit - 0/1 => joriy bit ko`rsatkichlar shinasi 4\8
// display_data - 0xXX => qiymati, ekranda yozilgan
void display_write(uint8_t reg, uint8_t bit, uint8_t display_data)
{
// buyruq\ma`lumotlarini yozish
// o`zgaruvchilarni `lon qilish
uint8_t buffer; // bir oraliq ma'lumotlar buferi
// buyruq\ma`lumotlarini yozish
if (bit==1)
{
// 8-bit holati foydalanayotgan bo'lsangiz
display_data=(display_data & 0xF0) | (0< PORTB=display_data; // yozish buyruqi
display_data=(display_data & 0xF0) | (0< PORTB=display_data; // yozish buyruqi
_delay_us(100); // malumotlar bazani o`rnatgandan keying xolat
}
else if (bit==0)
{
// 4-bit rejimini foydalanayotgan bo'lsangiz
buffer=display_data; // ma'lumotlarni nusxasini buferi display_data=(display_data & 0xF0) | (reg< PORTB=display_data; // yozish buyruqi
display_data=(display_data & 0xF0) | (reg< PORTB=display_data; // yozish buyruqi
display_data=buffer; // ma`lumotlarni nusxalash buferi
display_data=(display_data<<4); // chap 4 bit orqali banddir
display_data=(display_data & 0xF0) | (reg< PORTB=display_data; // yozish buyruqi
display_data=(display_data & 0xF0) | (reg< PORTB=display_data; // yozish komandasi
_delay_us(100); // yozish buyrug'i / ma'lumotlar keyin kechiktirib
}
}
// display_write_word - displey funksiyasi satri
// data[] – simvol massivi
// counter – xisoblash simvaoli
void display_write_word(uint8_t data[], uint8_t counter)
{
// o'zgaruvchilar e'lon qilish
uint8_t i; // umumiy oraliq
for(i=0; i {
display_write(1, 0, data[i]); // Ekrandagi belgi satrni yozib
}
}
// sensor_write - ro'yxatga olish vazifasi buyruq / ma'lumot sensori
// function_cmd – funksiyanalni komanda
// scratchpad –ma`lumot
uint16_t sensor_write(uint8_t function_cmd, uint8_t scratchpad)
{
// o'zgaruvchilar e'lon qilish
uint8_t i; // xisoblagich 8\16 bit
uint8_t logic_level; // liniyasi DQ MANTIQ darajasi
uint8_t rom_cmd; // ROM xotira
uint8_t buffer; // xotira buferi
uint16_t response; // ikki-bayt harorat ma'lumotlar
rom_cmd=0xCC; //xar doim Skip ROM
response=0x0; // o'zgaruvchan harorat ma'lumotlar sıfırlanması
// reset ipulsi va mavjudligi impulsi
DDRB=DDRB | (1< _delay_us(960); // kechikish 480мкс
DDRB=DDRB & 0xFE; // yozish 1
_delay_us(960); // kechikish 480мкс
// yozish buyruqi ROM xotira
for(i=0; i<8; ++i)
{
buffer=rom_cmd; //ma`lumotlar buyrugi
buffer=buffer & 0x1; // 1-bitli ajratish
if(buffer==0x1)
{
sensor_write_1_0(1); // yozish 1
}
else if (buffer==0x0)
{
sensor_write_1_0(0); // yozish 0
}
rom_cmd=(rom_cmd>>1); // o'ng raqamda qo'llanma so'z mazmunini ko'chirish }
_delay_ms(20); // buyruqlar o'rtasidagi kechikish
rom_cmd=function_cmd; tayinlash buyruq nusxa
for(i=0; i<8; ++i)
{
buffer=function_cmd; // ma`lumotlarni nusxalash
buffer=buffer & 0x1; // 1-bitli ajratish
if(buffer==0x1)
{
sensor_write_1_0(1); // yozish 1
}
else if (buffer==0x0)
{
sensor_write_1_0(0); // yozish 0
}
function_cmd=(function_cmd>>1); // o'ng raqamda qo'llanma so'z mazmunini ko'chirish
}
_delay_ms(20); // buyruqlar o'rtasidagi kechikish
function_cmd=rom_cmd; funktsional jamoasi tayinlash nusxa
if (function_cmd==0x4E)
{
// agar buyruqdan foydalansa Write_Scratchpad
for(i=0; i<16; ++i)
{
sensor_write_1_0(0); // запись 0
}
for(i=0; i<8; ++i)
{
buffer=scratchpad; // ma`lumotlarni nusxalash
buffer=buffer & 0x1; // 1-biti ajratish
if(buffer==0x1)
{
sensor_write_1_0(1); // yozish 1
}
else if (buffer==0x0)
{
sensor_write_1_0(0); // ozish 0
}
scratchpad=(scratchpad>>1); // o'ng raqam ma'lumotlar so'zlarning mazmunini ko'chirish
}
_delay_ms(20); // ma'lumotlar kechikishidan, yozib keyin
return; // возврат из функции
}
else if (function_cmd==0xBE)
{
// agar buyruqdan foydalansa Write_Scratchpad
for(i=0; i<16; ++i)
{
logic_level=sensor_read_1_0(); // liniyani oqish DQ
if(logic_level==1)
{
response=response | (1<}
}
_delay_ms(20); // ma'lumotlar kechikishidan, yozib keyin
return response; // javoban, harorat ma'lumotlarni beradi
}
else return; // chiqraish
}
// sensor_write_1_0 – funksiya yozish 1/0
// bit - 0/1 => yozish 0/1
void sensor_write_1_0(uint8_t bit)
{
if (bit==0)
{
DDRB=DDRB | (1< _delay_us(100); // задержка 100мкс
DDRB=DDRB & 0xFE; // yozish 1
}
else if (bit==1)
{
DDRB=DDRB | (1< DDRB=DDRB & 0xFE; // yozish 1
_delay_us(100); // kechikish 100мкс
}
}
// sensor_read_1_0 – o`qish fuksiyasai 1/0
uint8_t sensor_read_1_0(void)
{
// объявление переменных
uint8_t bit; // данные DQ
DDRB=DDRB | (1<DDRB=DDRB & 0xFE; // yozish 1
_delay_us(8); // kechikish
bit=PINB & 0x1; // liniya xolatini tekshirish DQ
_delay_us(100); // kechikish100мкс
if (bit==0x1)
{
return 1; // qaytarish 1
}
else if (bit==0x0)
{
return 0; // qaytarsih 0
}
}
//********************************************************************************

Download 1,92 Mb.

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




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2025
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