Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
мой выбор остановился на плате AVR-USB-MEGA16 с микроконтроллером ATmega32 на борту.
if (leftVolumeLevelPercent > 12) hundler.PORTA |= (1 << 0); else unchecked { hundler.PORTA &= ~(-1 << 0); }
if (leftVolumeLevelPercent > 24) hundler.PORTA |= (1 << 1); else unchecked { hundler.PORTA &= ~(-1 << 1); }
if (leftVolumeLevelPercent > 36) hundler.PORTA |= (1 << 2); else unchecked { hundler.PORTA &= ~(-1 << 2); }
if (leftVolumeLevelPercent > 48) hundler.PORTA |= (1 << 3); else unchecked { hundler.PORTA &= ~(-1 << 3); }
if (leftVolumeLevelPercent > 60) hundler.PORTA |= (1 << 4); else unchecked { hundler.PORTA &= ~(-1 << 4); }
if (leftVolumeLevelPercent > 72) hundler.PORTA |= (1 << 5); else unchecked { hundler.PORTA &= ~(-1 << 5); }
if (leftVolumeLevelPercent > 84) hundler.PORTA |= (1 << 6); else unchecked { hundler.PORTA &= ~(-1 << 6); }
if (leftVolumeLevelPercent > 96) hundler.PORTA |= (1 << 7); else unchecked { hundler.PORTA &= ~(-1 << 7); }for (int i = 0; i < 8; ++i)
if (leftVolumeLevelPercent > 12 * (i + 1)) hundler.PORTA |= (1 << i); else unchecked { hundler.PORTA &= ~(-1 << i); }
short int PortState = 0;
for (int i = 1; i <= 8; ++i)
{
if (leftVolumeLevelPercent > 12 * i)
{
PortState <<= 1;
PortState |= 0x01;
}
}
hundler.PORTA = PortState;
for (int i = 1; i <= 8; ++i)
{
for (int j = 1; j <= i; ++j) {
if (leftVolumeLevelPercent > 12 * (i + 1)) {
hundler.PORTA |= (1 << 1);
}
else {
unchecked {
hundler.PORTA &= ~(-1 << 1);
}
}
}
}
Разработка своего первого USB устройства. Маленький шаг вперед