В данной статье пойдет речь о том, как подключить ультразвуковой дальномер HC-SR04 к ATtiny2313 и отображать данные на ЖКИ-дисплее 16×1 на базе HD44780. Также сделал пример программы для отправки результата по UART. Для приёма я использовал Terminal 1.9b и преобразователь USB-UART на базе PL2303HX. Для проверки работоспособности программы и схемы я использовал Proteus 7. Проект в Atmel Studio 7 целиком вы сможете скачать по ссылке в конце статьи. При прошивке микроконтроллера ATtiny2313 не забудьте менять фьюзы: CKSEL3…0 = 0100 – Внутренний тактовый генератор — частота 8 МГц и поставить галочку (т.е. отключить) на SCKDIV8 – деление тактовой частоты на 8.
- 1 Схема подключения TB378 и HC-SR04 к ATtiny2313
- 2 Пример программы в Atmel Studio 7
- 3 Схема подключения LCD HD44780 и HC-SR04 к ATtiny2313
- 4 Пример программы в Atmel Studio 7
- 5 Скачать файлы
- 6 Купить HC-SR04 на AliExpress
- 7 Купить ATTINY2313A на Aliexpress
- 8 Купить LCD1602 HD44780 на Aliexpress
- 9 Похожие записи
Схема подключения TB378 и HC-SR04 к ATtiny2313
Для начала сделал программу для получения данных по UART.
Пример программы в Atmel Studio 7
main.c
#define F_CPU 8000000UL #define BAUD 9600 #define MYUBRR F_CPU/16/BAUD-1 #include <avr/io.h> #include <util/delay.h> #include <string.h> #include <stdlib.h> #include "uart.h" #include "hcsr04.h" inline void prepareText(char * text, int distance) { char textDistance[5]; itoa(distance, textDistance, 10); strcat(text, "D = "); strcat(text, textDistance); strcat(text, "mm"); } int main(void) { int distance; char text[17]; USARTInit(MYUBRR); while (1) { text[0] = '\0'; distance = getDistance(); prepareText(text, distance); USARTTransmitStringLn(text); _delay_ms(333); } }
Краткое описание
Вместо функции sprintf()
сделал собственную функцию для преобразования числа в строку, потому что sprintf()
жрёт больше половины флеш памяти контроллера.
inline void prepareText(char * text, int distance)
Функция prepareText преобразует целое число distance
(расстояние) в строку и добавляет строку в text
.
itoa(distance, textDistance, 10);
Функция itoa
преобразует целое число distance
в строку textDistance
в формате 10
.
strcat(text, textDistance);
Объединение строк. Функция добавляет textDistance
строки srcptr в конец строки text
.
Результат
Так как в Протеус нету HC-SR04, я его просто нарисовал. На первой картинке результат в -1 означает что датчик HC-SR04 не подключён или Echo не отправил сигнал.
После прошивки реального ATtiny2313, подключил к компьютеру и вот результат.
Схема подключения LCD HD44780 и HC-SR04 к ATtiny2313
После того, как убедился, что датчик HC-SR04 и программа работают правильно, для вывода результата подключил однорядный ЖК на 16 символов — HD44780.
Пример программы в Atmel Studio 7
main.c
#define F_CPU 8000000UL #include <avr/io.h> #include <util/delay.h> #include <string.h> #include <stdlib.h> #include "hcsr04.h" #include "LCD.h" inline void prepareText(char * text, int distance) { char textDistance[5]; itoa(distance, textDistance, 10); strcat(text, "D="); strcat(text, textDistance); strcat(text, "mm"); } int main(void) { _delay_ms(100); lcdInit(); lcdClear(); lcdSetDisplay(LCD_DISPLAY_ON); lcdSetCursor(LCD_CURSOR_OFF); int distance; char text[17]; while (1) { text[0] = '\0'; distance = getDistance(); prepareText(text, distance); lcdClear(); lcdGotoXY(0, 0); lcdPuts(text); _delay_ms(333); } }
Результат
В Протеусе всё работает, текст отображается правильно.
Скачать файлы
ATtiny2313 + HC-SR04 + LCD — Atmel Studio 7 проект
ATtiny2313 + HC-SR04 + UART — ISIS Professional (Proteus) проект
ATtiny2313 + HC-SR04 + LCD — ISIS Professional (Proteus) проект
ATtiny2313 + HC-SR04 + UART — Atmel Studio 7 проект
ATtiny2313A даташит на Русском
ATtiny2313A datasheet (EN)
sildenafil citrate online canada viagra home remedy viagra
Don’t delay downloading your docs as it may affect your account.
my webpage; Red dog casino
You actually explained that really well!
Here is my web blog :: http://withncm.com/bbs/board.php?bo_table=free&wr_id=60720
Hi! I understand this is sort of off-topic but I had to ask.
Does building a well-established blog like yours require a massive amount work?
I am completely new to blogging however I do write in my journal on a daily basis.
I’d like to start a blog so I can easily share my experience and views
online. Please let me know if you have any kind
of recommendations or tips for new aspiring bloggers.
Appreciate it!
canadian pharmacy ezzz cialis canadian pharmacy cialis cialis 5mg best price
generic viagra online for sale viagra pills viagra sex
I think this is among the most vital info for me. And i
am glad reading your article. But wanna remark on some
general things, The web site style is wonderful, the articles is really excellent : D.
Good job, cheers
This post is actually a pleasant one it assists new net viewers,
who are wishing for blogging.
I know this if off topic but I’m looking into starting my own blog and was wondering what
all is needed to get set up? I’m assuming having
a blog like yours would cost a pretty penny? I’m not very web smart so I’m not 100% positive.
Any suggestions or advice would be greatly appreciated.
Cheers
ivermectin for cats dosage ivermectin for sale treating scabies with ivermectin
Fastidious answer back in return of this query with real arguments and telling the whole thing concerning that.
I seriously love your website.. Very nice colors & theme.
Did you create this website yourself? Please reply back as
I’m planning to create my own blog and would love to learn where you got this from or exactly what the
theme is named. Kudos!
I want to use my skills and talents to give back and
make a positive impact. When we share, we create a community of informed
individuals.
I am extremely impressed together with your writing skills and also with the layout to your blog.
Is that this a paid theme or did you modify it yourself?
Anyway stay up the excellent quality writing, it’s uncommon to look a nice
blog like this one today..
Wow, superb blog layout! How lengthy have you been running a blog
for? you make blogging look easy. The total look of your
web site is fantastic, as smartly as the content material!
I like this blog it’s a master piece! Glad I observed this on google.
Here is my site :: https://clients1.google.hr/url?q=https://tracotour.vn/vi/how-burn-fat-doctors-proven-weight-reduction-secret-1-1
Hey just wanted to give you a quick heads up. The text in your post seem to be running off the screen in Chrome.
I’m not sure if this is a format issue or something to do
with internet browser compatibility but I figured I’d post
to let you know. The layout look great though!
Hope you get the issue resolved soon. Thanks
non prescription
mail order drug store
venta de viagra a domicilio: sildenafilo 100mg sin receta — comprar viagra en espaГ±a envio urgente contrareembolso
viagra online spedizione gratuita: viagra online consegna rapida — alternativa al viagra senza ricetta in farmacia
cheap online pharmacy
comprar sildenafilo cinfa 100 mg espaГ±a: comprar viagra en espaГ±a envio urgente — viagra online cerca de toledo
viagra online consegna rapida: viagra 100 mg prezzo in farmacia — pillole per erezione in farmacia senza ricetta
comprar viagra sin gastos de envГo: comprar viagra online en andorra — viagra online cerca de bilbao
sildenafilo precio farmacia: comprar viagra en espaГ±a envio urgente — se puede comprar viagra sin receta
le migliori pillole per l’erezione: viagra acquisto in contrassegno in italia — pillole per erezione in farmacia senza ricetta
medicin without prescription
drugs canada
canadian meds viagra
Betting requirements are a 30x rollover prior to a payment can be requested, for a maximum reward cash out of $10,000.
my website: https://nerodirectory.com/listings12470567/where-to-find-best-betting-sites-in-korea-on-the-web
In person advertising and marketing is more vital than in the past as consumers demand personal links along with the brand names they trust. Picking the right show for your firm may be actually discouraging. Along with a lot of events to choose from, it can be tough to identify which show will reach your target market, https://storymaps.arcgis.com/stories/143b4ee226184e64b6f8b99d25d847ae.
how to get help with your resume cover letter for job resume descriptive words for customer service
canadian prescriptions online
Yet once https://sportstip.us/the-upside-to-best-online-betting-site/, this is another generous present from the on-line gaming system.
canadian pharmacy certified
Нимфоманка секс
Wonderful blog you have here but I was curious about if you knew of any discussion boards that cover the same topics
talked about in this article? I’d really like to be a part of group where I can get suggestions from other
experienced individuals that share the same interest.
If you have any recommendations, please let me know. Many thanks!
discount pharmacies
Hello would you mind stating which blog platform you’re using? I’m going to start my own blog in the near future but I’m having a difficult time making a decision between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design and style seems different then most blogs and I’m looking for something completely unique. P.S Apologies for being off-topic but I had to ask!
My website; http://l95392cd.bget.ru/user/AurelioBoi/
canadian pharmacy no rx needed
At this time I am ready to do my breakfast, after having my breakfast coming again to read more news.
my web blog; https://firsturl.de/00YdVml
Players simply enjoy to place wagers as well as try to win big rewards a lot of the time.
Have a look at my page; https://lukasi0c73.blogzag.com/62167868/how-much-you-ought-to-be-prepared-to-buy-a-great-korea-sports-gamble
OneMain Financial charges an origination charge that is deducted from the total amount of the loan.
Feel free to surf to mmy homepage Learn more
You made the point!
Feel free to visit my web-site … https://www.wiklundkurucuk.com/Turkish-Law-Firm-cz
В зависимости от статуса, вариативность бонусов на выбор возрастает.
Thanks! I like it!
WOW just what I was searching for. Came here by
searching for pragmatic play
legitimate canadian pharmacy online
order canadian drugs
Heya! I’m at work browsing your blog from my new iphone
4! Just wanted to say I love reading through your blog
and look forward to all your posts! Keep up the superb work!
Cheers, Awesome stuff.
Here is my website :: https://partner.bybit.com/b/CTLDPSCQ16906
I am no longer positive the place you’re getting your information, but great topic.
I needs to spend some time learning much more or figuring out more.
Thanks for wonderful info I used to be looking for this info for my mission.
Use thee Loopp with a cellpohone app like Endomondo for GPS monitoring annd you have each base lined on exercise tracking and analysis.
Here is my website — Ramona
Hi, its nice article about media print, we all
know media is a fantastic source of data.
Awesome blog! Do you have any helpful hints for aspiring writers?
I’m hoping to start my own website soon but I’m a little lost on everything.
Would you propose starting with a free platform
like WordPress or go for a paid option? There are so many
choices out there that I’m totally confused .. Any recommendations?
Appreciate it!
Greetings, I do believe your blog may be having
web browser compatibility issues. Whenever I take a look
at your site in Safari, it looks fine however, when opening in I.E., it has some overlapping issues.
I simply wanted to give you a quick heads up! Aside from that,
excellent website!
You actually explained that really well!
I used to be suggested this blog by my cousin. I’m not certain whether this publish is written via him as
no one else know such distinctive approximately my difficulty.
You are amazing! Thank you!
fue
[…]just beneath, are various totally not related web-sites to ours, nonetheless, they are certainly worth going over[…]
What’s up, all the time i used to check web
site posts here early in the break of day, since i
enjoy to find out more and more.
Online medicine home delivery indian pharmacies safe reputable indian pharmacies
http://indianpharmacy.pro/# buy prescription drugs from india
http://indianpharmacy.pro/# cheapest online pharmacy india
buy prescription drugs from india indian pharmacy online п»їlegitimate online pharmacies india
2003 Oct; 62 10 916- 9 is cialis generic The postsynaptic AChRs were also visualized by the application of rhodamine bungarotoxin to the fixed muscles Fig
http://indianpharmacy.pro/# top 10 online pharmacy in india
любительское порно видео
What’s Going down i am new to this, I stumbled upon this I
have discovered It positively helpful and it has aided me out loads.
I’m hoping to give a contribution & assist other customers like its aided me.
Great job.
I was reading through some of your posts on this internet site and I conceive this web site is very instructive! Keep putting up.
Also visit my blog: http://pro-tulu.ru/go/url=-aHR0cDovL2Jrci5rci9ib2FyZF9Cc3JLMjIvMjgwNTQzMQ==
http://edmeds.pro/# buy ed pills online
no prescription pharmacy paypal: online pharmacy without scripts — canadadrugpharmacy com
Highly energetic blog, I liked that bit. Will there be a part 2?
I have read some just right stuff here. Certainly price bookmarking
for revisiting. I wonder how a lot attempt you place to
make this sort of wonderful informative site.
my discount pharmacy — international pharmacies that ship to the usa online canadian pharmacy with prescription
canadian pharmacies online legitimate prescription drugs without prior prescription accredited canadian pharmacies
https://fastdeliverypill.com/# universal canadian pharmacy
http://fastdeliverypill.com/# buying drugs canada
rx online — international pharmacies that ship to the usa discount canadian drugs
https://fastdeliverypill.com/# canada drug store
canada online pharmacies order prescription medicine online without prescription best online pharmacy no prescription
I couldn’t refrain from commenting. Very well written!
https://fastdeliverypill.com/# non prescription
best price prescription drugs legitimate canadian mail order pharmacies list of safe online pharmacies
http://fastdeliverypill.com/# online pharmacies no prescription required pain medication
cialis 10mg generic buy Cialis online buy cialis online overnight shipping
I believe people who wrote this needs true loving because it’s
a blessing. So let me give back and with heart reach out change your life and if you
want to seriously get to hear I will share info about how
to find hot girls for free Don’t forget.. I am always here for yall.
Bless yall!
Online medicine home delivery: india pharmacy — indianpharmacy com
top 10 online pharmacy in india Online medicine home delivery top 10 pharmacies in india