/programy/Atmel_C/RS232toRS485/P232.c |
---|
14,21 → 14,19 |
#define POVOLOVAK_HIGH PORTB |= (1<<PB3) |
#define DATA (PIND & (1<<PD1)) |
// ------------------------------------------------------------------ |
// Main |
// ------------------------------------------------------------------ |
int main(void) |
{ |
int bit; |
int delay; |
int spozdeni; |
int last; |
int preteceni; |
long int cas; |
DDRD |= (1<<DDD5); |
DDRB |= (1<<DDB3); |
TCCR0B |= (1 << CS10); // Set up timer |
TCCR1B |= (1 << CS10); // Set up timer |
while(1) |
{ |
36,22 → 34,15 |
{ |
POVOLOVAK_HIGH; // zapni vysilani |
for (bit=7;bit>=0;bit--) // odpocitej dobu 8mi bitu |
for (spozdeni=8;spozdeni>=0;spozdeni --) // odpocitej dobu 8mi bitu |
{ |
last = DATA; |
TCNT0 = 0; // zacni znova merit cas |
preteceni =0; |
while ((TCNT0+preteceni*0xFF) <= cas) // bit poznas tak, ze je to nejmensi nalezena delka trvaleho stavu |
TCNT1 = 0; // zacni znova merit cas |
while (TCNT1 <= delay) // bit poznas tak, ze je to nejmensi nalezena delka trvaleho stavu |
{ |
if (!(TIFR << TOV0)) // protoze mame jenom 8mi bitovy casovac, zjisti, jestli nepreteka |
if(DATA != last) |
{ |
preteceni++; // kdyz pretece, poznamenej to. |
TIFR = 1 << TOV0; // vynuluj flag preteceni |
} |
if(DATA != last) // zkontroluj, jestli se nezmenil stav dat. |
{ |
if ((TCNT0+preteceni*0xFF) < cas) cas = TCNT0+preteceni*0xFF; //kdyz se zmenil a trvalo to kratsi dobu nez pred tim poznemenej, jak dlouho to trvalo |
if (TCNT1 < delay) delay = TCNT1; |
break; |
} |
} |
58,14 → 49,14 |
} |
while (!DATA); // cekani na stop bit |
// for (spozdeni=2;spozdeni >= 0;spozdeni --) |
// { |
// TCNT0 = 0; // zacni znova merit cas zacatku stopbitu |
// while (TCNT0 <= delay) if(!DATA) break; |
// } |
for (spozdeni=2;spozdeni >= 0;spozdeni --) |
{ |
TCNT1 = 0; // zacni znova merit cas zacatku stopbitu |
while (TCNT1 <= delay) if(!DATA) break; |
} |
} |
else POVOLOVAK_LOW; // kdyz je 1 prepni na prijem |
cas = 0xFFFF; |
delay = 60000; |
} |
return(0); |
} |
/programy/Atmel_C/RS232toRS485/default/rs485.hex |
---|
1,22 → 1,15 |
:1000000012C02AC029C028C027C026C025C024C0CD |
:1000100023C022C021C020C01FC01EC01DC01CC0E4 |
:100020001BC01AC019C011241FBECFEDCDBF10E0F8 |
:10003000A0E6B0E0EEE4F1E003C0C89531960D9281 |
:10003000A0E6B0E0E0EEF0E003C0C89531960D9286 |
:10004000A036B107D1F710E0A0E6B0E001C01D92E4 |
:10005000A036B107E1F701C0D3CFBF92CF92DF92B4 |
:10006000EF92FF920F931F93CF93DF938D9ABB9ADA |
:1000700083B7816083BF819968C0C39A27E0C22E8D |
:10008000D12C9FEFE92E9FEFF92E012D112D82E04B |
:10009000B82E80B3682F77276270707012BEC0E0F0 |
:1000A000D0E040E050E0E0E0F0E082B7242F352FD0 |
:1000B0002E0F3F1FB32FA22FA80FB11D8A2F9B2FEA |
:1000C000AA2797FDA095BA2FE816F9060A071B077D |
:1000D00074F188B7882359F4E051FF4F415F5F4FB7 |
:1000E000C051DF4FB8BE242F352F2C0F3D1F80B3DA |
:1000F00099278270907068177907B9F282B7532FE9 |
:10010000422F480F511D952F842FAA2797FDA095A8 |
:10011000BA2F8E159F05A007B1074CF482B7280FA0 |
:10012000311DE22EF32E0027F7FC0095102F0894C6 |
:10013000C108D108BFEFCB16BFEFDB0609F0A9CF8E |
:0E014000819999CF819BFCCF96CFC39894CF25 |
:10005000A036B107E1F701C0D3CF8D9ABB9A8EB518 |
:1000600081608EBD81993AC0C39A40E65AEE68E03D |
:1000700070E080B3282F3327227030701DBC1CBC69 |
:100080008CB59DB54817590770F080B399278270D9 |
:10009000907028173907A1F38CB59DB58417950783 |
:1000A00010F44CB55DB5615070408FEF6F3F78072D |
:1000B00001F7819BFECF22E030E01DBC1CBC8CB55B |
:1000C0009DB54817590710F08199F9CF215030405C |
:1000D0008FEF2F3F380789F7819BC6CFC398C2CFD8 |
:00000001FF |
/programy/Atmel_C/RS232toRS485/rs485.aws |
---|
1,0 → 0,0 |
<AVRWorkspace><IOSettings><CurrentRegisters/></IOSettings><part name="ATTINY2313"/><Files><File00000 Name="C:\E240\ass3\program\Atmel_C\RS232toRS485\P232.c" Position="-2 71 1026 523" LineCol="51 66" State="Maximized"/></Files></AVRWorkspace> |
<AVRWorkspace><IOSettings><CurrentRegisters/></IOSettings><part name="ATTINY2313"/><Files><File00001 Name="C:\E240\ass3\SW\P232.c" Position="156 71 914 523" LineCol="62 0" State="Maximized"/></Files></AVRWorkspace> |