/programy/Atmel_C/RS232toRS485/P232.c |
---|
14,21 → 14,30 |
#define POVOLOVAK_HIGH PORTB |= (1<<PB3) |
#define DATA (PIND & (1<<PD1)) |
volatile unsigned int preteceni; |
unsigned int bit; |
unsigned int bitdelay; |
unsigned int last; |
unsigned int cas; |
ISR(TIMER0_OVF_vect) // interrupt od preteceni casovace |
{ |
preteceni++; // kdyz pretece, poznamenej to. |
} |
// ------------------------------------------------------------------ |
// Main |
// ------------------------------------------------------------------ |
int main(void) |
{ |
int bit; |
int last; |
int preteceni; |
long int cas; |
DDRD |= (1<<DDD5); |
DDRB |= (1<<DDB3); |
TIMSK |= (1 << TOIE0); // Enable timer overflow interrupt |
TCCR0B |= (1 << CS10); // Set up timer |
sei(); // enable interrupts |
while(1) |
{ |
35,37 → 44,40 |
if(!DATA) // kdyz je 0 na datech |
{ |
POVOLOVAK_HIGH; // zapni vysilani |
for (bit=7;bit>=0;bit--) // odpocitej dobu 8mi bitu |
cas = 0xFFFF; |
bitdelay = 0; |
for (bit=0;bit<=7;bit++) // 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 |
TCNT0 = 0; // vynuluj citac pred tim, ne smazes preteceni, protoze jinak by se mohlo stat, ze se nastavi preteceni driv, nez ma |
preteceni = 0; |
while ((TCNT0+preteceni*0x0100) <= cas) // bit poznas tak, ze je to nejmensi nalezena delka trvaleho stavu |
{ |
if (!(TIFR << TOV0)) // protoze mame jenom 8mi bitovy casovac, zjisti, jestli nepreteka |
{ |
preteceni++; // kdyz pretece, poznamenej to. |
TIFR = 1 << TOV0; // vynuluj flag preteceni |
} |
bitdelay=TCNT0+preteceni*0x0100; |
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 (bitdelay < cas) cas = bitdelay; //kdyz se zmenil a trvalo to kratsi dobu nez pred tim poznemenej, jak dlouho to trvalo |
break; |
} |
} |
} |
while (!DATA); // cekani na stop bit |
// 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 (bit=2;bit >= 0;bit--) // odpocitej dva stopbity |
{ |
TCNT0 = 0; // zacni znova merit cas zacatku stopbitu |
preteceni=0; |
while ((TCNT0+preteceni*0x0100) <= cas) |
{ |
if(!DATA) break; |
} |
}*/ |
} |
else POVOLOVAK_LOW; // kdyz je 1 prepni na prijem |
cas = 0xFFFF; |
} |
return(0); |
} |
/programy/Atmel_C/RS232toRS485/default/rs485.hex |
---|
1,22 → 1,18 |
:1000000012C02AC029C028C027C026C025C024C0CD |
:1000000012C02AC029C028C027C026C026C024C0CC |
:1000100023C022C021C020C01FC01EC01DC01CC0E4 |
:100020001BC01AC019C011241FBECFEDCDBF10E0F8 |
:10003000A0E6B0E0EEE4F1E003C0C89531960D9281 |
:10003000A0E6B0E0EEE0F1E003C0C89531960D9285 |
:10004000A036B107D1F710E0A0E6B0E001C01D92E4 |
:10005000A036B107E1F701C0D3CFBF92CF92DF92B4 |
:10006000EF92FF920F931F93CF93DF938D9ABB9ADA |
:1000700083B7816083BF819968C0C39A27E0C22E8D |
:10008000D12C9FEFE92E9FEFF92E012D112D82E04B |
:10009000B82E80B3682F77276270707012BEC0E0F0 |
:1000A000D0E040E050E0E0E0F0E082B7242F352FD0 |
:1000B0002E0F3F1FB32FA22FA80FB11D8A2F9B2FEA |
:1000C000AA2797FDA095BA2FE816F9060A071B077D |
:1000D00074F188B7882359F4E051FF4F415F5F4FB7 |
:1000E000C051DF4FB8BE242F352F2C0F3D1F80B3DA |
:1000F00099278270907068177907B9F282B7532FE9 |
:10010000422F480F511D952F842FAA2797FDA095A8 |
:10011000BA2F8E159F05A007B1074CF482B7280FA0 |
:10012000311DE22EF32E0027F7FC0095102F0894C6 |
:10013000C108D108BFEFCB16BFEFDB0609F0A9CF8E |
:0E014000819999CF819BFCCF96CFC39894CF25 |
:10005000AA36B107E1F718C0D3CF1F920F920FB69F |
:100060000F9211248F939F9380916200909163006F |
:10007000019690936300809362009F918F910F90FF |
:100080000FBE0F901F9018958D9ABB9A89B782600A |
:1000900089BF83B7816083BF7894819936C0C39A42 |
:1000A000EFEFFFEFA0E0B0E080B3682F772762703A |
:1000B000707012BE109263001092620022B780919D |
:1000C000620090916300982F8827820F911DE81796 |
:1000D000F907A8F022B78091620090916300582F31 |
:1000E0004427420F511D80B3992782709070681782 |
:1000F000790721F34E175F0710F4F52FE42F1196BF |
:0E010000A830B10589F6819BCACFC398C6CF3F |
:00000001FF |
/programy/Atmel_C/RS232toRS485/rs485.aps |
---|
1,0 → 0,0 |
<AVRStudio><MANAGEMENT><ProjectName>rs485</ProjectName><Created>22-May-2007 10:20:14</Created><LastEdit>29-May-2007 11:08:44</LastEdit><ICON>241</ICON><ProjectType>0</ProjectType><Created>22-May-2007 10:20:14</Created><Version>4</Version><Build>4, 13, 0, 528</Build><ProjectTypeName>AVR GCC</ProjectTypeName></MANAGEMENT><CODE_CREATION><ObjectFile>default\rs485.elf</ObjectFile><EntryFile></EntryFile><SaveFolder>C:\E240\ass3\SW\</SaveFolder></CODE_CREATION><DEBUG_TARGET><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_PART>ATtiny2313</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND><HIDE>false</HIDE></IO_EXPAND><REGISTERNAMES><Register>R00</Register><Register>R01</Register><Register>R02</Register><Register>R03</Register><Register>R04</Register><Register>R05</Register><Register>R06</Register><Register>R07</Register><Register>R08</Register><Register>R09</Register><Register>R10</Register><Register>R11</Register><Register>R12</Register><Register>R13</Register><Register>R14</Register><Register>R15</Register><Register>R16</Register><Register>R17</Register><Register>R18</Register><Register>R19</Register><Register>R20</Register><Register>R21</Register><Register>R22</Register><Register>R23</Register><Register>R24</Register><Register>R25</Register><Register>R26</Register><Register>R27</Register><Register>R28</Register><Register>R29</Register><Register>R30</Register><Register>R31</Register></REGISTERNAMES><COM>Auto</COM><COMType>0</COMType><WATCHNUM>0</WATCHNUM><WATCHNAMES><Pane0></Pane0><Pane1></Pane1><Pane2></Pane2><Pane3></Pane3></WATCHNAMES><BreakOnTrcaeFull>0</BreakOnTrcaeFull></DEBUG_TARGET><Debugger><modules><module></module></modules><Triggers></Triggers></Debugger><AVRGCCPLUGIN><FILES><SOURCEFILE>P232.c</SOURCEFILE></FILES><CONFIGS><CONFIG><NAME>default</NAME><USESEXTERNALMAKEFILE>NO</USESEXTERNALMAKEFILE><EXTERNALMAKEFILE></EXTERNALMAKEFILE><PART>attiny2313</PART><HEX>1</HEX><LIST>0</LIST><MAP>0</MAP><OUTPUTFILENAME>rs485.elf</OUTPUTFILENAME><OUTPUTDIR>default\</OUTPUTDIR><ISDIRTY>0</ISDIRTY><OPTIONS/><INCDIRS/><LIBDIRS/><LIBS><LIB>libc.a</LIB><LIB>libm.a</LIB><LIB>libprintf_flt.a</LIB><LIB>libprintf_min.a</LIB><LIB>libscanf_flt.a</LIB><LIB>libscanf_min.a</LIB></LIBS><LINKOBJECTS/><OPTIONSFORALL>-Wall -gdwarf-2 -DF_CPU=3686400UL -O3 -funsigned-char -funsigned-bitfields</OPTIONSFORALL><LINKEROPTIONS></LINKEROPTIONS><SEGMENTS/></CONFIG></CONFIGS><LASTCONFIG>default</LASTCONFIG><USES_WINAVR>1</USES_WINAVR><GCC_LOC>C:\Program Files\WinAVR\bin\avr-gcc.exe</GCC_LOC><MAKE_LOC>C:\Program Files\WinAVR\utils\bin\make.exe</MAKE_LOC></AVRGCCPLUGIN><IOView><usergroups/></IOView><Files><File00000><FileId>00000</FileId><FileName>verze\P232_rozpoznani_ryclosti1223.c</FileName><Status>2</Status></File00000><File00001><FileId>00001</FileId><FileName>P232.c</FileName><Status>3</Status></File00001></Files><Workspace><File00001><Position>156 71 914 523</Position><LineCol>62 0</LineCol><State>Maximized</State></File00001></Workspace><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio> |
<AVRStudio><MANAGEMENT><ProjectName>rs485</ProjectName><Created>22-May-2007 10:20:14</Created><LastEdit>30-May-2007 13:07:25</LastEdit><ICON>241</ICON><ProjectType>0</ProjectType><Created>22-May-2007 10:20:14</Created><Version>4</Version><Build>4, 13, 0, 528</Build><ProjectTypeName>AVR GCC</ProjectTypeName></MANAGEMENT><CODE_CREATION><ObjectFile>default\rs485.elf</ObjectFile><EntryFile></EntryFile><SaveFolder>C:\E240\ass3\program\Atmel_C\RS232toRS485\</SaveFolder></CODE_CREATION><DEBUG_TARGET><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_PART>ATtiny2313</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND><HIDE>false</HIDE></IO_EXPAND><REGISTERNAMES><Register>R00</Register><Register>R01</Register><Register>R02</Register><Register>R03</Register><Register>R04</Register><Register>R05</Register><Register>R06</Register><Register>R07</Register><Register>R08</Register><Register>R09</Register><Register>R10</Register><Register>R11</Register><Register>R12</Register><Register>R13</Register><Register>R14</Register><Register>R15</Register><Register>R16</Register><Register>R17</Register><Register>R18</Register><Register>R19</Register><Register>R20</Register><Register>R21</Register><Register>R22</Register><Register>R23</Register><Register>R24</Register><Register>R25</Register><Register>R26</Register><Register>R27</Register><Register>R28</Register><Register>R29</Register><Register>R30</Register><Register>R31</Register></REGISTERNAMES><COM>Auto</COM><COMType>0</COMType><WATCHNUM>0</WATCHNUM><WATCHNAMES><Pane0><Variables>preteceni</Variables></Pane0><Pane1></Pane1><Pane2></Pane2><Pane3></Pane3></WATCHNAMES><BreakOnTrcaeFull>0</BreakOnTrcaeFull></DEBUG_TARGET><Debugger><modules><module></module></modules><Triggers></Triggers></Debugger><AVRGCCPLUGIN><FILES><SOURCEFILE>P232.c</SOURCEFILE></FILES><CONFIGS><CONFIG><NAME>default</NAME><USESEXTERNALMAKEFILE>NO</USESEXTERNALMAKEFILE><EXTERNALMAKEFILE></EXTERNALMAKEFILE><PART>attiny2313</PART><HEX>1</HEX><LIST>0</LIST><MAP>0</MAP><OUTPUTFILENAME>rs485.elf</OUTPUTFILENAME><OUTPUTDIR>default\</OUTPUTDIR><ISDIRTY>0</ISDIRTY><OPTIONS/><INCDIRS/><LIBDIRS/><LIBS><LIB>libc.a</LIB><LIB>libm.a</LIB><LIB>libprintf_flt.a</LIB><LIB>libprintf_min.a</LIB><LIB>libscanf_flt.a</LIB><LIB>libscanf_min.a</LIB></LIBS><LINKOBJECTS/><OPTIONSFORALL>-Wall -gdwarf-2 -DF_CPU=3686400UL -O3 -funsigned-char -funsigned-bitfields</OPTIONSFORALL><LINKEROPTIONS></LINKEROPTIONS><SEGMENTS/></CONFIG></CONFIGS><LASTCONFIG>default</LASTCONFIG><USES_WINAVR>1</USES_WINAVR><GCC_LOC>C:\Program Files\WinAVR\bin\avr-gcc.exe</GCC_LOC><MAKE_LOC>C:\Program Files\WinAVR\utils\bin\make.exe</MAKE_LOC></AVRGCCPLUGIN><ProjectFiles><Files><Name>C:\E240\ass3\program\Atmel_C\RS232toRS485\P232.c</Name></Files></ProjectFiles><IOView><usergroups/></IOView><Files><File00000><FileId>00000</FileId><FileName>P232.c</FileName><Status>259</Status></File00000></Files><Workspace><File00000><Position>-2 71 1026 523</Position><LineCol>101 6</LineCol><State>Maximized</State></File00000></Workspace><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio> |