Subversion Repositories svnkaklik

Compare Revisions

No changes between revisions

Ignore whitespace Rev 304 → Rev 305

/programy/Atmel_C/RS232toRS485/P232.c
2,7 → 2,27
// Prevodnik RS232 <--> RS485
// pri startbitu na RS232 zapne okamzite vysilac pokud nejsou detekovana data z RS485.
//----------------------------------------------------------------------------------
//
//Algoritmus:
// Princip je zalozen na mereni nejkratsiho casoveho useku v osmi vzorcich, delka vzorku
// se odviji od velikosti prave nejmensiho zmereneho vzorku.
//
//
// Tento zpusob detekce neni imuni proti nahodnym chybovim sickam vzniklych v dusledku ruseni.
// Proto je nutene napajeni kvalitne stbilizovat, pouzivat blokovaci kondenzatory a
// zabezpecit, aby nedochazelo ke zvedani zeme.
/////////////////////////////////////////////////////////////////////////////////////
//
//TODO:
// Optimalizovat kod, (hlavne najit casove vyhodnejsi umisteni pro nastavovani defaultnich hodnot promennych)
// Bylo bydobre zavest uspavani pred prijetim bajtu.
// Vykouset program na ATtiny13
// program neni vyzkousen pri extremne nizkych rychlostech, kdy by teoreticky
// mohlo dochazet k preteceni promenne cas.
//////////////////////////////////////////////////////////////////////////////////////
//
 
 
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdlib.h>
12,13 → 32,12
 
#define POVOLOVAK_LOW PORTB &= ~(1<<PB3)
#define POVOLOVAK_HIGH PORTB |= (1<<PB3)
#define DATA (PIND & (1<<PD1))
#define DATA (PIND & (1<<PD3))
 
volatile unsigned int preteceni;
unsigned int bit;
unsigned int bitdelay;
unsigned int last;
unsigned int cas;
volatile unsigned int bit;
volatile unsigned int bitdelay;
volatile unsigned int cas;
 
ISR(TIMER0_OVF_vect) // interrupt od preteceni casovace
{
25,6 → 44,13
preteceni++; // kdyz pretece, poznamenej to.
}
 
ISR(INT1_vect)
{
if ((bitdelay=TCNT0+preteceni*0x0100) < cas) cas = bitdelay; //
TCNT0 = 0; // zacni znova merit cas zacatku stopbitu
preteceni=0;
bit++;
}
 
// ------------------------------------------------------------------
// Main
32,11 → 58,17
int main(void)
{
 
DDRD |= (1<<DDD5);
DDRB |= (1<<DDB3);
DDRD |= (1<<DDD5); // povoleni vystupu pro blikani ledkou (mozno odebrat)
 
TIMSK |= (1 << TOIE0); // Enable timer overflow interrupt
TCCR0B |= (1 << CS10); // Set up timer
DDRB |= (1<<DDB3); // povoleni vystupu na povolovak
 
TIMSK |= (1 << TOIE0); // Enable timer overflow interrupt
 
MCUCR |= (1 << ISC10); // nastaveni preruseni od zmeny vstupu pro interrupt INT0
GIMSK |= (1 << INT1); // povoleni interruptu INT0
TCCR0B |= (1 << CS00); // Set up timer
 
sei(); // enable interrupts
 
while(1)
45,32 → 77,25
{
POVOLOVAK_HIGH; // zapni vysilani
 
bitdelay = 0;
bit=0;
TCNT0=0;
preteceni=0;
cas = 0xFFFF;
bitdelay = 0;
for (bit=0;bit<=7;bit++) // odpocitej dobu 8mi bitu
while (bit <= 10) // odpocitej dobu 8mi bitu
{
last = DATA;
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 ((TCNT0+preteceni*0x0100) > cas)
{
bitdelay=TCNT0+preteceni*0x0100;
if(DATA != last) // zkontroluj, jestli se nezmenil stav dat.
{
if (bitdelay < cas) cas = bitdelay; //kdyz se zmenil a trvalo to kratsi dobu nez pred tim poznemenej, jak dlouho to trvalo
break;
}
}
TCNT0 = 0; // zacni znova merit cas zacatku stopbitu
preteceni=0;
bit++;
}
}
while (!DATA); // cekani na stop bit
while (!DATA); // cekani na stop bit (detekce pripadneho paritniho bitu)
 
/* 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;
/programy/Atmel_C/RS232toRS485/default/rs485.elf
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/programy/Atmel_C/RS232toRS485/default/rs485.hex
1,19 → 1,29
:1000000012C02AC029C028C027C026C026C024C0CC
:1000000012C02AC041C028C027C026C026C024C0B4
:1000100023C022C021C020C01FC01EC01DC01CC0E4
:100020001BC01AC019C011241FBECFEDCDBF10E0F8
:10003000A0E6B0E0E4E1F1E003C0C89531960D928E
:10003000A0E6B0E0E4EBF1E003C0C89531960D9284
:10004000A036B107D1F710E0A0E6B0E001C01D92E4
:10005000AA36B107E1F718C0D3CF1F920F920FB69F
:10005000A836B107E1F758C0D3CF1F920F920FB661
:100060000F9211248F939F9380916200909163006F
:10007000019690936300809362009F918F910F90FF
:100080000FBE0F901F9018958D9ABB9A89B782600A
:1000900089BF83B7816083BF7894819939C0C39A3F
:1000A000EFEFFFEFA0E0B0E080B3682F772762703A
:1000B000707012BE109263001092620022B780919D
:1000C000620090916300982F8827820F911DE81796
:1000D000F907A8F022B78091620090916300582F31
:1000E0004427420F511D80B3992782709070681782
:1000F000790721F34E175F0710F4F52FE42F1196BF
:10010000A830B10589F68199C8CF819BFCCFC5CFB6
:04011000C398C3CFFE
:100080000FBE0F901F9018951F920F920FB60F92F0
:1000900011242F933F938F939F9322B780916200F7
:1000A00090916300982F8827820F911D9093610093
:1000B0008093600020916000309161008091640025
:1000C000909165002817390740F480916000909165
:1000D0006100909365008093640012BE10926300EB
:1000E0001092620080916600909167000196909353
:1000F0006700809366009F918F913F912F910F90A1
:100100000FBE0F901F9018958D9ABB9A89B7826089
:1001100089BF85B7846085BF8BB780688BBF83B785
:10012000816083BF78946FEF7FEF839941C0C39A5A
:1001300010926100109260001092670010926600A9
:1001400012BE10926300109262007093650060937B
:10015000640080916600909167000B9720F582B74C
:1001600020916200309163004091640050916500DD
:10017000322F2227280F311D4217530750F712BE86
:100180001092630010926200809166009091670067
:10019000019690936700809366008091660090912D
:1001A00067000B97E0F28399C0CF839BFCCFBDCF54
:0401B000C398BBCF66
: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>30-May-2007 16:11:58</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><Variables>bit</Variables><Variables>bitdelay</Variables><Variables>last</Variables><Variables>cas</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>76 9</LineCol><State>Maximized</State></File00000></Workspace><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio>
<AVRStudio><MANAGEMENT><ProjectName>rs485</ProjectName><Created>22-May-2007 10:20:14</Created><LastEdit>31-May-2007 10:59:12</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><Variables>bit</Variables><Variables>bitdelay</Variables><Variables>cas</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>156 71 914 523</Position><LineCol>85 19</LineCol><State>Maximized</State></File00000></Workspace><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio>
/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><File00000 Name="C:\E240\ass3\program\Atmel_C\RS232toRS485\P232.c" Position="-2 71 1026 523" LineCol="87 32" State="Maximized"/></Files></AVRWorkspace>