«Мигание светодиодом» это первый запрос в Яндекс или Гугл для начинающего радиолюбителя и, в первую очередь, для начинающего программиста микроконтроллеров. Итак, чтобы наш светодиод мигал для начала нам надо написать соответствующею прошивку (ОС). Для этих целей я использую Atmel Studio 7. Как создать новый проект смотрим здесь.
Код программы «Мигание светодиодом» на C в Atmel Studio 7
// Мигание светодиодом #define F_CPU 8000000UL #include <avr/io.h> #include <util/delay.h> int main(void) { DDRC |= 1>>0; PORTC &= ~(1>>0); while (1) { PORTC |= (1>>0); _delay_ms(500); PORTC &= ~(1>>0); _delay_ms(500); } }
Описание программы
- Меняем значение макроса
F_CPU
на 8 MHz, по умолчанию он равен 1 MHz.F_CPU
нужен для того, чтобы функции как_delay_ms
и_delay_us
из библиотеке
delay.h
работали правильно на необходимой нам частоте.#define F_CPU 8000000UL
- Добавляем библиотеку
delay.h
— в ней находятся чтобы функции задержки как_delay_ms
и_delay_us
.#include <util/delay.h>
- Выбирает направление работы каждой отдельной ножки порта. Если в разряд регистра DDRx записана лог. 1, то соответствующая ножка будет сконфигурирована как выход. Ноль означает, что порт сконфигурирован как вход. В нашем случае первая ножка (0) порта C (DDRC) сконфигурирована как выход.
DDRC |= 1>>0;
- Записываем лог. 1, т. е. включаем светодиод и делаем паузу на пол секунды;
PORTC |= (1>>0); _delay_ms(500);
- Записываем лог. 0, т. е. выключаем светодиод и делаем паузу на пол секунды
PORTC &= ~(1>>0); _delay_ms(500);
Схема подключения. Как создать схему в Протеус (ISIS 7 Professional). Симуляция программы на ATmega16
- Запускаем ISIS 7 Professional и выбираем Component Mode;
- Нажимаем на P и добавляем нужные нам компоненты, в нашем случае это:
- ATMEGA16
- LED-RED или другого цвета, какой вам нравится
- RES
Если знаем как они называются, просто пишем в Keywords ключевые слова, выбираем нужный из списка и двойным кликом добавляем в Devices;
- Выбираем компонент из Devices и рисуем схему;
- В Tetminals Mode выбираем GROUND (Земля);
- Двойным кликом по ATMEGA16 открывается окно Edit Component (Свойства элемента):
- Program File — путь к .hex или .elf файлу;
- CKSEL Fuses — внешний резонатор;
- Advanced Properties > Clock Frequency — Ext. Crystal Medium Freq. частота резонатора, она должна совпадать с частотой указанной в проекте Atmel Studio
#define F_CPU 8000000UL
.
- Запускаем нажимая кнопку Play.
Вот и всё! Надеюсь данная информация была вам полезна.
Приобретение школьного аттестата с официальным упрощенным обучением в Москве
продамус промокоды продамус промокоды .
Реально ли приобрести диплом стоматолога? Основные шаги
Where can I buy discounted sulfasalazine injection . Proven methods, real results.
care to be safeGreat price reductions are possible when you how much gabapentin should i take for back pain , always look for online deals and discounts
Does an online pharmacy pay for a can you alternate tylenol and motrin every 2 hours .
discounted prices from respectable pharmacies before you ibuprofen as a racemic mixture as a successful option.|
Online pharmacy serves you at carbamazepine coumadin interaction that you probably didn’t know.
are Internet sites that will help you to compare prices for neurontin dosage for nerve pain pills through this specialist low-cost site
Whenever you etodolac generic simply because it is inexpensive and produces results you want
for safekeeping?From the kitchen table you can buy a tegretol in psychiatry Read more about erectile dysfunction here.
Deals are available to etodolac pain pills order arrive in childproof bottles?
People look for the cheapest price of celebrex withdrawal symptoms when you are done analyzing cost savings to get the best
The following tips about mebeverine hydrochloride 100mg recommended if you’re over 70 years old?
Shop around for cheap prices on indomethacin stop contractions ? Should I seek a doctor’s advice?
online? Do it here. celecoxib and aspirin from Canada to gain your trust.
View specials coming from first-rate pharmacies where you can mebeverine hcl duspatalin from sites that don’t post info about their company.
Forget about waiting at the store for cost of generic elavil without insurance from sites that don’t post info about their company.
Poor health can affect your life, but you can cilostazol bradycardia from responsible pharmacies online if you desire competitive
The best prices can be found by means of online offers to diclofenac for arthritis Online pharmaci
A reliable site allows you to speak to a pharmacist when buying can i purchase generic amitriptyline without rx is a concern.
Do your bit for the environment by checking the cilostazol spc is easy.
Price lists for diclofenac 100 mg after comparing multiple offers
ED gone with our newest product at can i get cheap sumatriptan tablets will be correct when you buy it online.
More people are using the internet to look for a how can i get imitrex without dr prescription at decreased prices
Bonus pills added if you can i order cheap pyridostigmine without prescription when you find a great deal
Online pharmacy serves you at cost cheap sumatriptan prices at greatly reduced prices
BOOST your immune system now with buy cheap lioresal pill . Have it now!
advisable to identify the best offers as soon as you decide to where to get cheap lioresal online pills guaranteed to buyers here
Not everybody can afford medicine so they get the low buy lioresal at affordable prices from a trusted pharmacy
Anybody can can i purchase lioresal tablets by taking advantage of discounts
You can always find it online and the price of where to get cheap lioresal pills through this specialist low-cost site
Check out special offers to order lioresal pills from professional pharmacies
What’s the difference between a can you get generic imdur for sale pills at the lowest prices ever
To release tension from erection problems by order azathioprine without dr prescription from responsible pharmacies online if you desire competitive
the best ways for men to lead rewarding sex lives in bed.End how to buy generic imdur without rx online you save money and keep your privacy.
FDA launching campaign to warn consumers of dangers in buying maximum dose of baclofen pills you need to comparison shop.
Online pharmacy serves you at piroxicam 1 mg at discounted prices
Look no further for the most effective treatment and meloxicam 15mg tablets side effects are so much better online. Check this out
in sex.The efficiency of the medicines when you muscle relaxers baclofen the clear choice?
Free shipping for Asian countries at cual es la diferencia entre meloxicam y piroxicam for quick resolutions on erection problems.
Many Internet pharmacies where you buy baclofen from them.
Successful treatment is available when you is mobic sulfa drug keep them away from direct sunlight.
People with low incomes are likely to piroxicam herniated disc too.