Cov txheej txheem:

Clap-on Hloov: 7 Cov Kauj Ruam (nrog Duab)
Clap-on Hloov: 7 Cov Kauj Ruam (nrog Duab)

Video: Clap-on Hloov: 7 Cov Kauj Ruam (nrog Duab)

Video: Clap-on Hloov: 7 Cov Kauj Ruam (nrog Duab)
Video: Lil Nas X, Jack Harlow - INDUSTRY BABY (Official Video) 2024, Kaum ib hlis
Anonim
Image
Image

Ib tus txheeb ze nug kuv ib zaug yog tias kuv tuaj yeem tsim qhov hloov pauv uas cuam tshuam rau npuaj koj ob txhais tes. Yog li kuv tau xaj qee yam khoom los tsim ib qhov haujlwm thiab txiav txim siab los ua cov lus qhia kom txhua tus tuaj yeem muaj qhov hloov pauv zoo li ntawd.

Lub microcontroller yog lub hlwb ntawm txoj haujlwm no. Lub suab sensor txuas nrog lub microcontroller, lub sensor xa cov ntaub ntawv analog thaum pom lub suab. Lub microcontroller tau teeb tsa kom pom qhov sib txawv loj hauv lub suab. Thaum pom qhov sib txawv txaus txaus, txhais tau tias npuaj teg, lub microcontroller xa lub teeb liab mus rau qhov txuas. Lub relay hloov thiab lub teeb tig rau. Thaum npuaj teg zaum ob, lub teeb yuav kaw dua.

Khoom siv

Lub cev

  • 1x ATmega328P Xplained Mini nrog cable rau kev ua haujlwm
  • 1x 5v relay module 1-channel (KY-019 lossis zoo sib xws)
  • 1x Suab sensor module (KY-038 lossis zoo sib xws)
  • 1 x Breadboard
  • 6x Txiv neej-Txiv neej jumper hlau
  • 1x lub qhov (socket) nrog qaum (lossis lwm yam cuab yeej koj xav qhib)
  • 1 x lub teeb
  • 1x resistor* (Kuv siv 220 Ohm)
  • 1 x LEDs*

Software (rub tawm):

  • AtmelStudio 7.0 (https://www.microchip.com/mplab/avr-support/atmel-studio-7)
  • Puab (www.putty.org)*

* Rau kev ntsuas lub hom phiaj

Kauj ruam 1: Kev sib txuas

Tsim Txoj Haujlwm
Tsim Txoj Haujlwm

Txuas tag nrho cov xov hlau raws li qhia hauv daim duab.

Kauj Ruam 2: Tsim Txoj Haujlwm

Tsim Txoj Haujlwm
Tsim Txoj Haujlwm
Tsim Txoj Haujlwm
Tsim Txoj Haujlwm

Kuv nyiam cov cai hauv C yog li qhov haujlwm no tau sau hauv C.

Yog tias koj tseem tsis tau rub tawm thiab teeb tsa cov software xav tau, rub tawm thiab teeb tsa nws tam sim no.

Tam sim no ua raws cov theem tom ntej no:

  1. Qhib AtmelStudio.
  2. Nyem rau "File" -> "New" -> "Project".
  3. Nyem rau ntawm "GCC C Txoj Haujlwm Ua Haujlwm". Muab koj lub npe lub npe thiab qhov chaw khaws cia. Nyem "Ok".
  4. Tshawb nrhiav ATmega328P. Nyem "ATmega328P" -> "Ok".
  5. Nyem rau hauv Kev Tshawb Fawb Kev Tshawb Fawb ntawm "main.c" txhawm rau qhib txoj haujlwm tseem ceeb.

Kauj ruam 3: Ntxiv Code

Rho tawm cov cai twb muaj tam sim no hauv main.c

Luam thiab paste cov cai hauv qab no hauv main.c

#define F_CPU 16000000

#include #include #include #include "usart.h" #define MINIMALVALUE 5 void InitADC (); uint16_t Nyeem ADC (uint8_t ADCchannel); ob npaug 1, nqi 2; int lub ntsiab (tsis muaj dab tsi) {// Initialise USART USART_init (9600); USART_putstr ("#USART pib / n"); // Pib ADC InitADC (); USART_putstr ("#ADC pib / n"); // PC1 tus pin ntawm PORTC cov zis, cov khoom siv ntxiv. DDRC = 0b00000010; // teeb tsa thawj qhov tseem ceeb rau PORTC qis. PORTC = 0b00000000; thaum (1) {// nyeem tus nqi potentiometer // nyeem tus nqi thiab khaws hauv val1 val1 = ReadADC (0); _delay_ms (1); // nyeem tus nqi tom ntej en khaws hauv val2 val2 = ReadADC (0); kab ntawv [10]; // the ReadADC () muab tus nqi rov qab rau hauv cov lej. Yog tias peb xav kom debug lossis pom tus nqi ntawm putty, // tus nqi yuav tsum tau hloov pauv mus rau cov cim kom USART tuaj yeem luam nws. nws (val1, str, 10); USART_putstr (str); USART_putstr ("\ n"); // yog 2 qhov tseem ceeb muaj qhov sib txawv. Lub suab tau pom thiab hloov chaw nres nkoj. // MINIMALVALUE tuaj yeem hloov pauv, nce ntxiv yuav ua rau nws tsis nkag siab. Kev txo qis yuav ua rau nws nkag siab ntau dua yog tias (val1-val2> MINIMALVALUE || val2-val1> MINIMALVALUE) {PORTC ^= 0b00000010; // LIGHT ON UC _delay_ms (200); }}} void InitADC () {// Xaiv Vref = AVcc ADMUX | = (1 << REFS0); // teeb tsa prescaller rau 128 thiab pab kom ADC ADCSRA | = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0) | (1 << ADEN); } uint16_t ReadADC (uint8_t ADCchannel) {// xaiv ADC channel nrog daim npog ntsej muag kev nyab xeeb ADMUX = (ADMUX & 0xF0) | (ADCchannel & 0x0F); // ib hom kev hloov pauv ADCSRA | = (1 << ADSC); // tos kom ADC hloov dua siab tshiab tiav thaum (ADCSRA & (1 << ADSC)); rov qab ADC; }

Kauj Ruam 4: Ntxiv USART

Ntxiv USART
Ntxiv USART

USART yog cov txheej txheem kev sib txuas lus sib txuas uas tuaj yeem siv rau ntawm lub microcontroller. Kuv siv nws ntawm lub microcontroller kom pom cov ntaub ntawv analog los ntawm lub ntsuas.

USART twb tau teeb tsa kom raug, muaj lub taub hau (.h) thiab cov ntaub ntawv (.c). Rub tawm 2 cov ntawv thiab ntxiv lawv rau koj qhov program hauv AtmelStudio.

Txoj cai-nyem rau ntawm lub npe project hauv Solution Explorer. Nyem "Ntxiv" -> "Yam khoom uas muaj …" thiab xaiv 2 daim ntawv rub tawm.

Kauj ruam 5: Khiav Txoj Cai

Khiav Txoj Cai
Khiav Txoj Cai
Khiav Txoj Cai
Khiav Txoj Cai

Txuas lub microcontroller mus rau lub khoos phis tawj. Tshawb nrhiav hauv koj lub computer rau "tus thawj tswj ntaus ntawv" thiab qhib nws. Saib rau "Ports (COM & LPT)" thiab nco ntsoov COM-chaw nres nkoj microcontroller nyob.

Qhib PuTTY thiab nyem rau ntawm "Serial" ntaus COM-chaw nres nkoj koj tau pom ntawm lub microcontroller thiab nyem "Qhib". Lub davhlau ya nyob twg tshwm tuaj, tawm tam sim no.

Rov qab mus rau AtmelStudio los xaiv lub cuab yeej raug rau kev tsim lub microcontroller.

  1. Nyem rau ntawm lub cuab yeej rauj.
  2. Xaiv "mEDBG*ATML" debugger/programmer.
  3. Xaiv interface "debugWIRE".
  4. Nyem "pib yam tsis muaj debugging".

Qhov program yuav tsim thiab sau.

Thaum qhov kev zov me nyuam ua haujlwm raug koj yuav pom qhov muaj nuj nqis hauv puTTY. Siv tus ntsia hlau kuv tuaj yeem hloov tus nqi pom hauv puTTY los ntawm kev xa cov ntsia hlau rau ntawm lub ntsuas. Kuv lub ntsuas ntsuas muab qhov tseem ceeb ntawm 0 txog 1000 thaum tig cov ntsia hlau txhua txoj kev. Kuv tig cov ntsia hlau rau 100 (10%) ntawm tus nqi tag nrho. Kuv tau pom tias qhov no ua haujlwm rau kuv.

Kauj Ruam 6: Hloov Siab Zoo

Txhawm rau kho qhov kev nkag siab thaum lub teeb tig rau koj tuaj yeem siv 2 txoj kev xaiv, tab sis xaiv ib qho tsis yog ob qho:

  1. Hloov sensor ntsia hlau;
  2. Hloov tus nqi tus nqi.

Kuv siv qhov kev xaiv 2. Ua kom MINIMALVALUE wil ua rau nws tsis nkag siab, txo qis ua rau nws nkag siab ntau dua.

#Txheeb xyuas qhov tsawg kawg 5

Kauj Ruam 7: Hloov Txhua Yam Koj Nyiam

Hloov Txhua Yam Koj Nyiam!
Hloov Txhua Yam Koj Nyiam!
Hloov Txhua Yam Koj Nyiam!
Hloov Txhua Yam Koj Nyiam!

CEEB TOOM: Saib xyuas thaum hloov qhov hluav taws xob ntau dua

Thaum koj zoo siab nrog kev nkag siab ntawm lub sensor koj tuaj yeem hloov pauv hauv Circuit Court. Hloov lub Circuit Court zoo li daim duab saum toj no. Tam sim no koj tuaj yeem hloov txhua yam uas koj nyiam!

Pom zoo: