hallo,
ik heb hier een stukje code dat ik probeer te doorgronden, ik heb dat niet zelf bedacht, maar dekees heeft dat voor mij gemaakt.
ik kan de topic waarin hij dat heeft gepost niet meer terug vinden, vandaar een nieuw topic.
prog. draait in een atmega32.
wat is de bedoeling v/d code:
- ik heb 24x een input verdeeld over 3 poorten (A B & C).
- iedere 4 mS word er naar 1 input gekeken.
- de status ("1" of "0") word in een byte geschreven.
- op het eind van die "scan" zijn er dus 3 bytes gevuld.
dat is het eigenlijk, later worden die 3 bytes verstuurd over RS485 naar een andere controller (atmega2560).
ISR(TIMER1_COMPA_vect)
{
static uint8_t PulseCounter = 150;
static uint8_t BitCounter = 0;
if(PulseCounter == 0)
{
PulseCounter = 150;
switch(BitCounter++)
{
case 0 : { byte_1 |= (PINC & 0x80); PORTD |= (1 << PIND3); break;}
case 1 : { byte_1 |= (PINC & 0x40); break; }
case 2 : { byte_1 |= (PINC & 0x20); break; }
case 3 : { byte_1 |= (PINC & 0x10); break; }
case 4 : { byte_1 |= (PINC & 0x08); break; }
case 5 : { byte_1 |= (PINC & 0x04); break; }
case 6 : { byte_1 |= (PINC & 0x02); break; }
case 7 : { byte_1 |= (PINC & 0x01);
columns_byte_1 [column_counter_byte_1] = byte_1;
column_counter_byte_1 += 1;
break;
}
case 8 : { byte_2 |= (PINA & 0x80); PORTD |= (1 << PIND4); PORTD &= ~(1 << PIND3); break; }
case 9 : { byte_2 |= (PINA & 0x40); break; }
case 10: { byte_2 |= (PINA & 0x20); break; }
case 11: { byte_2 |= (PINA & 0x10); break; }
case 12: { byte_2 |= (PINA & 0x08); break; }
case 13: { byte_2 |= (PINA & 0x04); break; }
case 14: { byte_2 |= (PINA & 0x02); break; }
case 15: { byte_2 |= (PINA & 0x01);
columns_byte_2 [column_counter_byte_2] = byte_2;
column_counter_byte_2 += 1;
break;
}
case 16: { byte_3 |= (PINB & 0x80); PORTD |= (1 << PIND7); PORTD &= ~(1 << PIND4); break; }
case 17: { byte_3 |= (PINB & 0x40); break; }
case 18: { byte_3 |= (PINB & 0x20); break; }
case 19: { byte_3 |= (PINB & 0x10); break; }
case 20: { byte_3 |= (PINB & 0x08); break; }
case 21: { byte_3 |= (PINB & 0x04); break; }
case 22: { byte_3 |= (PINB & 0x02); break; }
case 23: { byte_3 |= (PINB & 0x01);
columns_byte_3 [column_counter_byte_3] = byte_3;
column_counter_byte_3 += 1;
break;
}
// below: pulse counter = 0; needed so that TSAL & TSOP number 1 start on the same time.
case 24:
{
PORTD &= ~(1 << PIND7);
BitCounter = 0;
PulseCounter = 0;
start_scan = 0;
break;
}
} // from: switch
} // from: if(PulseCounter == 0)
else
{
PulseCounter -= 1;
}
} // from: ISR
ISR(TIMER1_COMPB_vect) // 38 khz
{
PORTB = 0;
PORTA = 0;
PORTC = 0;
}
welk deel begrijp ik dan o.a. niet goed:
case 1 : { byte_1 |= (PINC & 0x40); break; }
hier moet de status van een specifieke input pin in byte_1 worden gezet, zonder de overige bits te veranderen, gebeurt dat ook ?