Cov txheej txheem:

Kev ntsuas kub thiab teeb pom kev zoo nrog rau ntawm LCD NOKIA 5110: 4 Cov Kauj Ruam
Kev ntsuas kub thiab teeb pom kev zoo nrog rau ntawm LCD NOKIA 5110: 4 Cov Kauj Ruam

Video: Kev ntsuas kub thiab teeb pom kev zoo nrog rau ntawm LCD NOKIA 5110: 4 Cov Kauj Ruam

Video: Kev ntsuas kub thiab teeb pom kev zoo nrog rau ntawm LCD NOKIA 5110: 4 Cov Kauj Ruam
Video: HTV NEWS: HMOOB PUAS PAUB KEV NCAJ NCEE YOG DAB TSI? 2024, Kaum ib hlis
Anonim
Image
Image

Nyob zoo sawv daws!

Hauv ntu no peb ua cov cuab yeej siv hluav taws xob yooj yim los saib xyuas qhov kub thiab txias. Kev ntsuas ntawm cov ntsuas no tau muab tso rau ntawm LCD NOKIA 5110. Cov cuab yeej siv raws li lub microcontroller AVR ATMEGA328P. Cov cuab yeej saib xyuas tau teeb tsa DS18B20 tus pas ntsuas kub digital thiab photoresistor txhawm rau ntsuas qib teeb.

Kauj Ruam 1: Cov Txheej Txheem Qhia

Nqe Lus Qhia
Nqe Lus Qhia
Nqe Lus Qhia
Nqe Lus Qhia

Cov hauv paus tseem ceeb ntawm cov cuab yeej saib xyuas:

  • Microcontroller AVR «ATMEGA328P»
  • Monochrome Graphic LCD «NOKIA 5110»
  • Programmable Resolution 1-Wire Digital Thermometer «DS18B20»
  • Lub teeb nyob ntawm tus tiv thaiv
  • Hlau

Microcontroller AVR «ATMEGA328P»

Cov cuab yeej saib xyuas siv cov yam ntxwv hauv qab no ntawm microcontroller:

  1. 16-ntsis Timer/Counter cuam tshuam
  2. 8-channel 10-ntsis ADC
  3. Tswv/qhev SPI serial interface

Monochrome Graphic LCD «NOKIA 5110»

Kev qhia tshwj xeeb:

  1. 48 x 84 Dot LCD Zaub
  2. Serial Bus Interface nrog qhov siab tshaj plaws ceev 4 Mbits/S.
  3. Internal Controller/Driver «PCD8544»
  4. LED Back-Light
  5. Khiav ntawm Voltage 2.7-5 Volt
  6. Tsawg zog siv; nws haum rau kev siv roj teeb
  7. Kub ntau ntawm -25˚C txog +70˚C
  8. Txhawb Kev Teeb Meem CMOS

Kev tuav ntawm LCD Chaw Nyob (Chaw Nyob):

Qhov chaw nyob ntawm kev nco uas tau qhia ntawm LCD Zaub (DDRAM) yog Matrix uas muaj 6 kab (Y Chaw Nyob) los ntawm Y-Chaw Nyob 0 mus rau Y-Chaw Nyob 5 thiab 84 kab (X Chaw Nyob) los ntawm X-Chaw Nyob 0 txog X- Chaw Nyob 83. Yog tias tus neeg siv xav nkag mus rau txoj haujlwm ntawm kev ua kom pom ntawm LCD Zaub, yuav tsum hais txog kev sib raug zoo ntawm X-Chaw Nyob thiab Y-Chaw Nyob.

Cov ntaub ntawv uas yuav xa mus rau tso tawm yog 8 ntsis (1 Byte) thiab nws yuav raug teeb tsa ua kab ntsug; qhov no, Bit MSB yuav qis dua thiab Bit LSB yuav siab dua li qhia hauv daim duab.

Programmable Resolution 1-Wire Digital Thermometer DALLAS «DS18B20»

Nta:

  1. Cim 1-Wire® Kev Sib Tham Yuav Tsum Muaj Ib Lub Nkoj Pin rau Kev Sib Txuas Lus
  2. Txo Cov Cheeb Tsam suav nrog Kev Ntsuas Kub thiab EEPROM
  3. Ntsuas Kub los ntawm -55 ° C txog +125 ° C (-67 ° F txog +257 ° F)
  4. ± 0.5 ° C Qhov tseeb ntawm -10 ° C txog +85 ° C
  5. Programmable Resolution los ntawm 9 Bits mus rau 12 Bits
  6. Tsis Xav Tau Cov Txheej Txheem Sab Nraud
  7. Parasitic Power Mode Yuav Tsum Muaj 2 Tus Pins rau Kev Ua Haujlwm (DQ thiab GND)
  8. Yooj Yim Tshaj Tawm Cov Kev Ntsuas Kub-Pom Kev Pom Zoo nrog Muaj Peev Xwm Muaj Peev Xwm
  9. Txhua Lub Ntaus Ntawv muaj qhov tshwj xeeb 64-ntsis Serial Code khaws cia hauv On-Board ROM
  10. Saj zawg zog Cov Neeg Siv Tau-Tsis Siv Tau (NV) Tswb Chaw nrog Tswb Tshawb Nrhiav Hais Qhia Cov cuab yeej nrog Kub Sab Nraud Txoj Haujlwm Txwv

Cov ntawv thov:

  1. Thermostatic Tswj
  2. Muaj Tshuab
  3. Khoom Siv Khoom
  4. Cov ntsuas kub
  5. Thermally Sensitive Systems

Lub teeb nyob ntawm tus tiv thaiv

Lub Teeb Ntsuas Tus Kws Tiv Thaiv (LDR) yog tus hloov pauv uas hloov nws qhov kev tiv thaiv thaum lub teeb ntog ntawm nws qhov kev hloov pauv.

Feem ntau LDR yuav muaj los ntawm ib megaOhms mus rau ob megaOhms ntawm qhov tsaus ntuj, los ntawm kaum rau nees nkaum kiloOhms ntawm kaum LUX, los ntawm ob rau tsib kiloohms ntawm 100 LUX. Kev tiv thaiv nruab nrab ntawm ob qhov kev sib cuag ntawm lub ntsuas hluav taws xob txo nrog lub teeb pom kev zoo lossis kev coj ua ntawm ob qhov kev sib txuas ntawm lub sensor nce.

Siv hluav taws xob faib hluav taws xob hloov pauv hloov pauv hauv kev tiv thaiv kom hloov pauv qhov hluav taws xob.

Kauj ruam 2: Microcontroller Firmware Code

#ifndef F_CPU #txhais F_CPU 16000000UL // qhia tswj cov zaus siv (16 MHz AVR ATMega328P) #endif

// SPI INTERFACE DEFINES #define MOSI 3 // MOSI nws yog PORT B, PIN 3 #define MISO 4 // MISO nws yog PORT B, PIN 4 #define SCK 5 // SCK nws yog PORT B, PIN 5 #define SS 2 // SS nws yog PORT B, PIN 2

// RESET DISPLAY #define RST 0 // RESET nws yog PORT B, PIN 0

// DISPLAY MODE SELECT - Cov tswv yim los xaiv cov lus txib/chaw nyob lossis cov ntaub ntawv nkag mus. #define DC 1 // DC nws yog PORT B, PIN 1

// codes array of negative signstatic const unsigned char neg [4] = {0x30, 0x30, 0x30, 0x30};

// codes array of digits [0..9] static const unsigned char font6x8 [10] [16] = {{0xFC, 0xFE, 0xFE, 0x06, 0x06, 0x06, 0xFE, 0xFE, 0xFC, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01}, // 0 {0x00, 0x00, 0x18, 0x1C, 0xFE, 0xFE, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00}, // 1 { 0x0C, 0x8E, 0xCE, 0xE6, 0xE6, 0xBE, 0x9E, 0x0C, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01}, // 2 {0x00, 0x04, 0x06, 0x26, 0x76, 0xFE, 0xDE, 0x8C, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01}, // 3 {0x3C, 0x3E, 0x7C, 0x60, 0x60, 0xFC, 0xFE, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x01}, // 4 {0x1C, 0x3E, 0x3E, 0x36, 0x36, 0xF6, 0xF6, 0xE4, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01}, // 5 {0xFC, 0xFE, 0xFE, 0x36, 0x36, 0xF6, 0xF6, 0xE4, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01}, // 6 {0x04, 0x06, 0x06, 0x86, 0xE6, 0xFE, 0x7E, 0x1C, 0x00, 0x00, 0x00, 0x01, 0x03, 0x01, 0x00, 0x00}, // 7 {0xCC, 0xFE, 0xFE, 0x36, 0x36, 0x36, 0xFE, 0xFE, 0xCC, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x0 ua 3, 0x01}, // 8 {0x3C, 0x7E, 0x7E, 0x66, 0x66, 0xFE, 0xFE, 0xFC, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01} // 9};

// codes array of word "TEMP:" static const unsigned char TEMP_1 [165] = {0x02, 0x06, 0x06, 0xFE, 0xFE, 0xFE, 0xFE, 0x06, 0x06, 0x02, 0x00, 0xFC, 0xFE, 0xFE, 0x26, 0x26, 0x24, 0x00, 0xFC, 0xFE, 0xFE, 0xFE, 0x1C, 0x38, 0x70, 0x38, 0x1C, 0xFE, 0xFE, 0xFC, 0xFC, 0x00, 0xFC, 0xFE, 0xFE, 0x66, 0x66, 0x7E, 0x7E, 0xx3, 0x00, 0x8C, 0x8C, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x01, 0x00, 0x01, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x0C, 0x1E, 0x33, 0x33, 0x1E, 0x0C, 0x00, 0xF8, 0xFC, 0x0C, 0x9C, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x01,};

// codes array of word "LUX:" const unsigned char TEMP_2 [60] = {0xFC, 0xFE, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFE, 0xFC, 0x00, 0x00, 0xFC, 0xFE, 0xFE, 0xFC, 0x00, 0x04, 0x8E, 0xDE, 0xFC, 0xF8, 0xFC, 0xDE, 0x8E, 0x04, 0x00, 0x8, 0x8C, 0x8C, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x01, 0x01, 0x03,, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x01, 0x03, 0x03, 0x03, 0x01, 0x00, 0x01, 0x03, 0x03, 0x01, 0x00, 0x01, 0x01, 0x01};

#suav nrog

#ncig #ncig

// Port Initializationvoid Port_Init () {DDRB = (1 << MOSI) | (1 << SCK) | (1 << SS) | (1 << RST) | (1 << DC); // Set MOSI, SCK, SS, RST, DC raws li tso tawm, txhua lwm tus tawm tswv yim PORTB | = (1 << RST); // Teeb RST tus pin kom siab PORTB | = (1 << SS); // Teeb SS tus pin kom siab - Zaub yog Lov tes taw DDRC = 0xFFu; // Teeb txhua tus pin ntawm PORTC li tso tawm. DDRC & = ~ (1 << 0); // Ua thawj tus pin ntawm PORTC ua cov tswv yim PORTC = 0x00u; // Teeb txhua tus pin ntawm PORTC qis uas tig nws tawm. }

// ADC Initialization void ADC_init () {// Enable ADC, sampling freq = osc_freq/128 set prescaler to max value, 128 ADCSRA | = (1 << ADEN) | (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0); ADMUX = (1 << REFS0); // Xaiv qhov ntsuas hluav taws xob rau ADC // Xaiv channel xoom los ntawm kev siv ADC Multiplexer Xaiv sau npe (ADC0). }

// Muaj nuj nqi los nyeem qhov tshwm sim ntawm analog rau digital hloov uint16_t get_LightLevel () {_delay_ms (10); // Tos qee lub sijhawm rau cov channel kom tau txais kev xaiv ADCSRA | = (1 << ADSC); // Pib ADC hloov dua siab tshiab los ntawm teeb tsa ADSC me ntsis. sau 1 rau ADSC thaum (ADCSRA & (1 << ADSC)); // tos kom hloov pauv kom tiav // ADSC dhau 0 rov txog thaum ntawd, khiav voj tsis tu ncua _delay_ms (10); rov qab (ADC); // Rov qab 10-ntsis tshwm sim}

// SPI Initialization void SPI_Init () {SPCR = (1 << SPE) | (1 << MSTR) | (1 << SPR0); // Enable SPI, Set as Master, Set Prescaler as Fosc/16 in SPI control sau npe}

// initialize 16 ntsis Timer1, cuam tshuam thiab hloov pauv tsis tau TIMER1_init () {// teeb tsa lub sijhawm nrog prescaler = 256 thiab CTC hom TCCR1B | = (1 << WGM12) | (1 << CS12); // initialize counter TCNT1 = 0; // initialize sib piv tus nqi - 1 sec OCR1A = 62500; // pab kom sib piv cuam tshuam TIMSK1 | = (1 << OCIE1A); // pab kom thoob ntiaj teb cuam tshuam sei (); }

// Display Enable void SPI_SS_Enable () {PORTB & = ~ (1 << SS); // Pab kom tus pin SS nkag siab 0}

// Zaub Disable void SPI_SS_Disable () {PORTB | = (1 << SS); // Lov tes taw SS tus pin rau logic 1}

// Muaj nuj nqi xa cov ntaub ntawv rau hauv cov zaub tsis muaj qhov khoob SPI_Tranceiver (cov ntaub ntawv tsis kos npe) {SPDR = cov ntaub ntawv; // Thauj cov ntaub ntawv mus rau qhov tsis thaum (! (SPSR & (1 << SPIF)))); // Tos kom txog thaum kis tau tiav}

// Pib dua Cov Zaub thaum pib ntawm qhov pib ua tsis muaj dab tsi Display_Reset () {PORTB & = ~ (1 << RST); _delay_ms (100); PORTB | = (1 << RST); }

// Hais kom sau tsis muaj nuj nqis Display_Cmnd (cov ntaub ntawv tsis tau kos npe) {PORTB & = ~ (1 << DC); // ua DC tus pin rau logic 0 rau kev ua haujlwm SPI_Tranceiver (cov ntaub ntawv); // xa cov ntaub ntawv ntawm cov ntaub ntawv sau npe PORTB | = (1 << DC); // ua DC tus pin rau logic siab rau cov ntaub ntawv ua haujlwm}

// Initialization of Display void Display_init () {Display_Reset (); // rov pib dua cov zaub Display_Cmnd (0x21); // hais kom ua teeb nyob rau hauv hom ntxiv Display_Cmnd (0xC0); // teeb qhov hluav taws xob los ntawm kev xa C0 txhais tau tias VOP = 5V Display_Cmnd (0x07); // teem caij. coefficient rau 3 Display_Cmnd (0x13); // teeb tsa tus nqi ntawm Voltage Bias System Display_Cmnd (0x20); // hais kom ua teeb tsa hauv hom yooj yim Display_Cmnd (0x0C); // tso tawm cov txiaj ntsig hauv hom qub}

// Tshem tawm qhov tsis pom Zaub Display_Clear () {PORTB | = (1 << DC); // ua DC tus pin rau logic siab rau cov ntaub ntawv ua haujlwm rau (int k = 0; k <= 503; k ++) {SPI_Tranceiver (0x00);} PORTB & = ~ (1 << DC); // ua DC tus pin rau logic xoom rau kev hais kom ua haujlwm}

// teeb tsa kab thiab kab rau txoj haujlwm ntawm kev tso tawm tshwm sim ntawm LCD Zaub void Display_SetXY (kos npe x, tsis kos npe y) {Display_Cmnd (0x80 | x); // kem (0-83) Display_Cmnd (0x40 | y); // kab (0-5)}

// Muaj nuj nqi los tso tawm qhov tsis zoo kos npe Display_Neg (kos npe tsis zoo) {Display_SetXY (41, 0); // Teeb tsa qhov chaw nyob ntawm txoj haujlwm ntawm cov zaub rau (int index = 0; index0) {SPDR = 0x30;} // Thauj cov ntaub ntawv mus rau qhov tsis zoo ntawm cov zaub (tso tawm cov cim tsis zoo) lwm yam {SPDR = 0x00;} // Thauj cov ntaub ntawv rau hauv qhov tsis zoo ntawm cov zaub (pom qhov tsis zoo kos npe) thaum (! (SPSR & (1 << SPIF)))); // Tos kom txog thaum kis tiav _delay_ms (100); }}

// Ua haujlwm kom tshem tawm cov cim kos npe tsis muaj nuj nqis Off_Dig (tsis kos npe x, tsis kos npe y) {Display_SetXY (x, y); // Teeb tsa qhov chaw nyob ntawm txoj haujlwm ntawm cov zaub (kab saum toj kawg nkaus) rau (int index = 0; index <8; index ++) {SPI_Tranceiver (0);} // Load cov ntaub ntawv rau hauv qhov tsis zoo ntawm cov zaub (tshem tawm sab saum toj ntawm cov cim digital) y ++; Display_SetXY (x, y); // Teem qhov chaw nyob ntawm txoj haujlwm ntawm cov zaub (kab hauv qab) rau (int index = 0; index <8; index ++) {SPI_Tranceiver (0);} // Load cov ntaub ntawv rau hauv qhov tsis zoo ntawm cov zaub (tshem tawm ib nrab ntawm cov cim digital)}

// Muaj nuj nqi los tso saib cov cim digital tsis muaj dab tsi Display_Dig (nkag khawb, tsis kos npe x, tsis kos npe y) {Display_SetXY (x, y); // Teeb tsa qhov chaw nyob ntawm txoj haujlwm ntawm cov zaub (kab saum toj kawg nkaus) rau (int index = 0; index <16; index ++) {if (index == 8) {y ++; Display_SetXY (x, y);} // Teem qhov chaw nyob ntawm txoj haujlwm ntawm zaub (kab hauv qab) SPI_Tranceiver (font6x8 [dig] [index]); // Thauj cov lej ntau ntawm cov lej cov ntaub ntawv rau hauv qhov tsis pom _delay_ms (10); }}

// Initialization of DS18B20 unsigned char DS18B20_init () {DDRD | = (1 << 2); // Teeb PD2 tus pin ntawm PORTD li tso tawm PORTD & = ~ (1 << 2); // Teeb PD2 tus pin li qis _delay_us (490); // Initialization Timing DDRD & = ~ (1 << 2); // Teeb PD2 tus pin ntawm PORTD li kev nkag mus _delay_us (68); // Sijhawm OK_Flag = (PIND & (1 << 2)); // tau txais sensor mem tes _delay_us (422); rov OK_Flag; // rov qab 0-ok sensor yog ntsaws, 1-sensor tsis raug tshem tawm}

// Muaj nuj nqi los nyeem byte los ntawm DS18B20 unsigned char read_18b20 () {unsigned char i, data = 0; rau (i = 0; i <8; i ++) {DDRD | = (1 << 2); // Teeb PD2 tus pin ntawm PORTD li tso tawm _delay_us (2); // Sijhawm DDRD & = ~ (1 1; // Ntxiv me ntsis yog (PIND & (1 << 2)) cov ntaub ntawv | = 0x80; // muab ntsis rau hauv byte _delay_us (62);} xa cov ntaub ntawv;}

// Muaj nuj nqi los sau byte rau DS18B20 tsis muaj dab tsi sau_18b20 (cov ntaub ntawv tsis tau kos npe) {tsis kos npe char i; rau (i = 0; i <8; i ++) {DDRD | = (1 << 2); // Teeb PD2 tus pin ntawm PORTD li tso tawm _delay_us (2); // Sijhawm yog (cov ntaub ntawv & 0x01) DDRD & = ~ (1 << 2); // yog tias peb xav sau 1, tso kab ntxiv DDRD | = (1 1; // Tom ntej ntsis _delay_us (62); // Sijhawm DDRD & = ~ (1 << 2); // Teeb PD2 tus pin ntawm PORTD raws li cov tswv yim _delay_us (2);}}

// Muaj nuj nqi los tso saib teeb pom kev tsis muaj teeb meem Read_Lux () {uint16_t tsis; unsigned int temp_int_1, temp_int_2, temp_int_3, temp_int_0; // ib tus lej, ob tus lej, tus lej peb npaug, peb lub hlis tus lej tsis = get_LightLevel (); // nyeem qhov tshwm sim ntawm analog rau digital hloov pauv lub teeb theem temp_int_0 = tsis % 10000 /1000; // quarter-digit temp_int_1 = tsis % 1000/100; // triple-digit temp_int_2 = tsis % 100/10; // ob-tus lej temp_int_3 = tsis % 10; // single-digit if (temp_int_0> 0) // if result is quarter-digit number {Display_Dig (temp_int_0, 32, 2); // tso saib 1 tus lej ntawm theem teeb Display_Dig (temp_int_1, 41, 2); // tso saib 2 tus lej ntawm theem teeb Display_Dig (temp_int_2, 50, 2); // tso saib 3 tus lej ntawm theem teeb Display_Dig (temp_int_3, 59, 2); // tso saib 4 tus lej ntawm qib qib} lwm {yog (temp_int_1> 0) // yog qhov tshwm sim yog tus lej thib peb tus lej {Off_Dig (32, 2); // tshem 1 kos npe ntawm tus lej Display_Dig (temp_int_1, 41, 2); // tso saib 1 tus lej ntawm theem teeb Display_Dig (temp_int_2, 50, 2); // tso saib 2 tus lej ntawm theem teeb Display_Dig (temp_int_3, 59, 2); // tso saib 3 tus lej ntawm qib qib} lwm {yog (temp_int_2> 0) // yog qhov tshwm sim yog ob tus lej zauv {Off_Dig (32, 2); // tshem 1 kos npe ntawm tus lej Off_Dig (41, 2); // tshem 2 kos npe ntawm tus lej Display_Dig (temp_int_2, 50, 2); // tso saib 1 tus lej ntawm theem teeb Display_Dig (temp_int_3, 59, 2); // tso saib 2 tus lej ntawm qib qib} lwm yam // yog qhov tshwm sim yog tus lej ib tus lej {Off_Dig (32, 2); // tshem 1 kos npe ntawm tus lej Off_Dig (41, 2); // tshem 2 kos npe ntawm tus lej Off_Dig (50, 2); // tshem 3 kos npe ntawm tus lej Display_Dig (temp_int_3, 59, 2); // tso saib 1 tug lej ntawm qib pom kev}}}}

// Muaj nuj nqi los tso tawm qhov ntsuas kub tsis muaj tseeb Read_Temp () {unsigned int buffer; unsigned int temp_int_1, temp_int_2, temp_int_3; // ib tus lej, ob tus lej, triple tus lej, peb lub hlis twg tus lej tsis tau kos npe Temp_H, Temp_L, OK_Flag, temp_flag; DS18B20_init (); // Kev pib ua DS18B20 sau_18b20 (0xCC); // Sensor code kos sau_18b20 (0x44); // Pib hloov pauv kub _delay_ms (1000); // Sensor pov npav ncua DS18B20_init (); // Kev pib ua DS18B20 sau_18b20 (0xCC); // Sensor code kos sau_18b20 (0xBE); // Hais kom nyeem cov ntsiab lus ntawm Sensor RAM Temp_L = read_18b20 (); // Nyeem thawj ob byte Temp_H = read_18b20 (); temp_flag = 1; // 1-qhov ntsuas kub zoo, 0-qhov kub tsis zoo // Tau txais qhov kub tsis zoo yog (Temp_H & (1 << 3)) // Kos Npe Qhov Tseeb (yog tias tau teeb tsa me ntsis-qhov kub tsis zoo) {kos npe rau hauv qhov kub; temp_flag = 0; // chij tau teeb tsa 0 - qhov ntsuas kub tsis zoo = (Temp_H << 8) | Temp_L; temp = -cov; // Hloov cov cai ntxiv ncaj qha Temp_L = temp; Temp_H = temp >> 8; } tsis = ((Temp_H 4); temp_int_1 = tsis % 1000/100; // triple-digit temp_int_2 = buffer % 100/10; // ob-digit temp_int_3 = buffer % 10; // ib leeg-tus lej

// Yog tias qhov kub tsis zoo tso tawm qhov ntsuas kub, lwm qhov tseeb

yog (temp_flag == 0) {Display_Neg (1);} ntxiv {Display_Neg (0);} yog (temp_int_1> 0) // yog qhov tshwm sim yog tus lej peb tus lej {Display_Dig (temp_int_1, 45, 0); // tso saib 1 tus lej ntawm qhov kub Display_Dig (temp_int_2, 54, 0); // tso saib 2 tus lej ntawm Display_Dig (temp_int_3, 63, 0); // tso saib 3 tus lej ntawm qhov kub} ntxiv {yog (temp_int_2> 0) // yog qhov tshwm sim yog ob tus lej zauv {Off_Dig (45, 0); // tshem 1 kos npe ntawm tus lej Display_Dig (temp_int_2, 54, 0); // tso saib 1 tus lej ntawm qhov kub Display_Dig (temp_int_3, 63, 0); // tso saib 2 tus lej ntawm qhov kub} ntxiv // yog qhov tshwm sim yog tus lej ib tus lej {Off_Dig (45, 0); // tshem 1 kos npe ntawm tus lej Off_Dig (54, 0); // tshem 2 kos npe ntawm tus lej Display_Dig (temp_int_3, 63, 0); // tso saib 1 tus lej ntawm qhov sov}}}

// Qhov ISR no raug rho tawm thaum twg muaj kev sib tw tshwm sim ntawm cov timer suav nrog tus nqi sib piv (txhua 1 thib ob) ISR (TIMER1_COMPA_vect) {// Nyeem ntawv, ua kom pom qhov kub thiab lub teeb Read_Temp (); Nyeem_Lux (); }

// Muaj nuj nqi los tso saib cov lus "TEMP" thiab "LUX" tsis muaj dab tsi Display_label () {// Lo lus "TEMP" Display_SetXY (0, 0); // Teeb tsa qhov chaw nyob ntawm txoj haujlwm ntawm cov zaub (nce kab) rau (int index = 0; index <105; index ++) {if (index == 40) {Display_SetXY (0, 1);} // Teem qhov chaw nyob ntawm txoj haujlwm ntawm cov zaub (kab hauv qab) yog (ntsuas == 80) {Display_SetXY (72, 0);} // Teeb tsa qhov chaw nyob ntawm txoj haujlwm ntawm cov zaub (nce kab) yog (ntsuas == 92) {Display_SetXY (72, 1); } // Teeb tsa qhov chaw nyob ntawm txoj haujlwm ntawm kab lus (kab hauv qab) SPDR = TEMP_1 [index]; // Thauj cov lej cov ntaub ntawv tso rau hauv qhov tsis pom ntawm (thaum (! (SPSR & (1 << SPIF)))); // Tos kom txog thaum kis tiav _delay_ms (10); } // Lo lus "LUX" Display_SetXY (0, 2); // Teem qhov chaw nyob ntawm txoj haujlwm ntawm cov zaub (nce kab) rau (int index = 0; index <60; index ++) {if (index == 30) {Display_SetXY (0, 3);} // Teem qhov chaw nyob ntawm txoj haujlwm ntawm cov zaub (kab hauv qab) SPDR = TEMP_2 [index]; // Thauj cov lej cov ntaub ntawv tso rau hauv qhov tsis pom ntawm (thaum (! (SPSR & (1 << SPIF)))); // Tos kom txog thaum kis tiav _delay_ms (10); }}

int main (tsis muaj dab tsi)

{Chaw_Init (); // Chaw Pib Pib ADC_init (); // ADC Initialization SPI_Init (); // SPI Initialization SPI_SS_Enable (); // Zaub Enable DS18B20_init (); // Kev pib ua haujlwm ntawm DS18B20 Display_init (); // Zaub pib pib Display_Clear (); // Zaub meej Display_label (); // Tso cov lus "TEMP" thiab "LUX" TIMER1_init (); // Timer1 Initialization. Pib saib xyuas. Tau txais qhov ntsuas txhua ib ob. // Infinity voj thaum (1) {}}

Kauj Ruam 3: Flashing Firmware rau Microcontroller

Kev xa cov ntaub ntawv HEX rau hauv microcontroller flash nco. Saib cov vis dis aus nrog cov lus piav qhia ntxaws txog lub microcontroller flash memory burning: Microcontroller flash memory burning…

Kauj Ruam 4: Saib Xyuas Cov Khoom Siv Hluav Taws Xob

Saib Xyuas Cov Khoom Siv Hauv Circuit Court
Saib Xyuas Cov Khoom Siv Hauv Circuit Court
Saib Xyuas Cov Khoom Siv Hauv Circuit Court
Saib Xyuas Cov Khoom Siv Hauv Circuit Court

Txuas cov khoom siv raws li daim duab qhia chaw.

Plug lub zog thiab nws ua haujlwm!

Pom zoo: