Subversion Repositories svnkaklik

Compare Revisions

Ignore whitespace Rev 301 → Rev 302

/programy/Atmel_C/RS232toRS485/P232.c
14,19 → 14,21
#define POVOLOVAK_HIGH PORTB |= (1<<PB3)
#define DATA (PIND & (1<<PD1))
 
 
// ------------------------------------------------------------------
// Main
// ------------------------------------------------------------------
int main(void)
{
int delay;
int spozdeni;
int bit;
int last;
int preteceni;
long int cas;
 
DDRD |= (1<<DDD5);
DDRB |= (1<<DDB3);
 
TCCR1B |= (1 << CS10); // Set up timer
TCCR0B |= (1 << CS10); // Set up timer
 
while(1)
{
34,15 → 36,22
{
POVOLOVAK_HIGH; // zapni vysilani
for (spozdeni=8;spozdeni>=0;spozdeni --) // odpocitej dobu 8mi bitu
for (bit=7;bit>=0;bit--) // odpocitej dobu 8mi bitu
{
last = DATA;
TCNT1 = 0; // zacni znova merit cas
while (TCNT1 <= delay) // bit poznas tak, ze je to nejmensi nalezena delka trvaleho stavu
TCNT0 = 0; // zacni znova merit cas
preteceni =0;
while ((TCNT0+preteceni*0xFF) <= cas) // bit poznas tak, ze je to nejmensi nalezena delka trvaleho stavu
{
if(DATA != last)
if (!(TIFR << TOV0)) // protoze mame jenom 8mi bitovy casovac, zjisti, jestli nepreteka
{
if (TCNT1 < delay) delay = TCNT1;
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
break;
}
}
49,14 → 58,14
}
while (!DATA); // cekani na stop bit
 
for (spozdeni=2;spozdeni >= 0;spozdeni --)
{
TCNT1 = 0; // zacni znova merit cas zacatku stopbitu
while (TCNT1 <= delay) if(!DATA) break;
}
// for (spozdeni=2;spozdeni >= 0;spozdeni --)
// {
// TCNT0 = 0; // zacni znova merit cas zacatku stopbitu
// while (TCNT0 <= delay) if(!DATA) break;
// }
}
else POVOLOVAK_LOW; // kdyz je 1 prepni na prijem
delay = 60000;
cas = 0xFFFF;
}
return(0);
}
/programy/Atmel_C/RS232toRS485/default/Makefile
13,7 → 13,7
 
## Compile options common for all C compilation units.
CFLAGS = $(COMMON)
CFLAGS += -Wall -gdwarf-2 -DF_CPU=3686400UL -O3 -funsigned-char -funsigned-bitfields
CFLAGS += -Wall -gdwarf-2 -DF_CPU=3686400UL -O3 -funsigned-char -funsigned-bitfields
CFLAGS += -MD -MP -MT $(*F).o -MF dep/$(@F).d
 
## Assembly specific flags
/programy/Atmel_C/RS232toRS485/default/rs485.hex
1,15 → 1,22
:1000000012C02AC029C028C027C026C025C024C0CD
:1000100023C022C021C020C01FC01EC01DC01CC0E4
:100020001BC01AC019C011241FBECFEDCDBF10E0F8
:10003000A0E6B0E0E0EEF0E003C0C89531960D9286
:10003000A0E6B0E0EEE4F1E003C0C89531960D9281
:10004000A036B107D1F710E0A0E6B0E001C01D92E4
:10005000A036B107E1F701C0D3CF8D9ABB9A8EB518
:1000600081608EBD81993AC0C39A40E65AEE68E03D
:1000700070E080B3282F3327227030701DBC1CBC69
:100080008CB59DB54817590770F080B399278270D9
:10009000907028173907A1F38CB59DB58417950783
:1000A00010F44CB55DB5615070408FEF6F3F78072D
:1000B00001F7819BFECF22E030E01DBC1CBC8CB55B
:1000C0009DB54817590710F08199F9CF215030405C
:1000D0008FEF2F3F380789F7819BC6CFC398C2CFD8
:10005000A036B107E1F701C0D3CFBF92CF92DF92B4
:10006000EF92FF920F931F93CF93DF938D9ABB9ADA
:1000700083B7816083BF819968C0C39A27E0C22E8D
:10008000D12C9FEFE92E9FEFF92E012D112D82E04B
:10009000B82E80B3682F77276270707012BEC0E0F0
:1000A000D0E040E050E0E0E0F0E082B7242F352FD0
:1000B0002E0F3F1FB32FA22FA80FB11D8A2F9B2FEA
:1000C000AA2797FDA095BA2FE816F9060A071B077D
:1000D00074F188B7882359F4E051FF4F415F5F4FB7
:1000E000C051DF4FB8BE242F352F2C0F3D1F80B3DA
:1000F00099278270907068177907B9F282B7532FE9
:10010000422F480F511D952F842FAA2797FDA095A8
:10011000BA2F8E159F05A007B1074CF482B7280FA0
:10012000311DE22EF32E0027F7FC0095102F0894C6
:10013000C108D108BFEFCB16BFEFDB0609F0A9CF8E
:0E014000819999CF819BFCCF96CFC39894CF25
:00000001FF
/programy/Atmel_C/RS232toRS485/rs485.aws
1,0 → 0,0
<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>
<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>