Subversion Repositories svnkaklik

Compare Revisions

Regard whitespace Rev 299 → Rev 300

/programy/Atmel_C/RS232toRS485/P232.c
1,5 → 1,5
//----------------------------------------------------------------------------------
// Prevodnik RS232 <--> RS485 s prodlevou pri prevodu smerem do RS485
// Prevodnik RS232 <--> RS485
// pri startbitu na RS232 zapne okamzite vysilac pokud nejsou detekovana data z RS485.
//----------------------------------------------------------------------------------
 
10,20 → 10,10
#include <avr/eeprom.h>
#include <avr/pgmspace.h>
 
#define POVOLOVAK_LOW PORTB &= ~(1<<PB3)
#define POVOLOVAK_HIGH PORTB |= (1<<PB3)
#define DATA (PIND & (1<<PD1))
 
#define F_CPU 3686400UL
#include <util/delay.h>
 
void delay_ms(unsigned int ms)
{
while(ms)
{
_delay_ms(0.96);
ms--;
}
}
 
 
// ------------------------------------------------------------------
// Main
// ------------------------------------------------------------------
34,24 → 24,23
int last;
 
DDRD |= (1<<DDD5);
// DDRB |= (1<<DDB3);
DDRB |= (1<<DDB3);
 
TCCR1B |= (1 << CS10); // Set up timer
 
// PORTB |= (1<<PB3);
 
while(1)
{
if(!(PIND & (1<<PD1))) // kdyz je 0 na datech
if(!DATA) // kdyz je 0 na datech
{
PORTD &= ~(1<<PD5); // zapni vysilani
for (spozdeni=0;spozdeni<=8;spozdeni ++)
POVOLOVAK_HIGH; // zapni vysilani
for (spozdeni=8;spozdeni>=0;spozdeni --) // odpocitej dobu 8mi bitu
{
last = (PIND & (1<<PD1));
last = DATA;
TCNT1 = 0; // zacni znova merit cas
while (TCNT1 <= delay)
while (TCNT1 <= delay) // bit poznas tak, ze je to nejmensi nalezena delka trvaleho stavu
{
if((PIND & (1<<PD1)) != last)
if(DATA != last)
{
if (TCNT1 < delay) delay = TCNT1;
break;
58,9 → 47,16
}
}
}
while (!(PIND & (1<<PD1)));
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;
}
else PORTD |= (1<<PD5); // kdyz je 1 prepni na prijem
}
else POVOLOVAK_LOW; // kdyz je 1 prepni na prijem
delay = 60000;
}
return(0);
}
/programy/Atmel_C/RS232toRS485/default/Makefile
0,0 → 1,77
###############################################################################
# Makefile for the project rs485
###############################################################################
 
## General Flags
PROJECT = rs485
MCU = attiny2313
TARGET = rs485.elf
CC = avr-gcc.exe
 
## Options common to compile, link and assembly rules
COMMON = -mmcu=$(MCU)
 
## Compile options common for all C compilation units.
CFLAGS = $(COMMON)
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
ASMFLAGS = $(COMMON)
ASMFLAGS += $(CFLAGS)
ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2
 
## Linker flags
LDFLAGS = $(COMMON)
LDFLAGS +=
 
 
## Intel Hex file production flags
HEX_FLASH_FLAGS = -R .eeprom
 
HEX_EEPROM_FLAGS = -j .eeprom
HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load"
HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings
 
 
## Libraries
LIBS = -lc -lm -lprintf_flt -lprintf_min -lscanf_flt -lscanf_min
 
## Objects that must be built in order to link
OBJECTS = P232.o
 
## Objects explicitly added by the user
LINKONLYOBJECTS =
 
## Build
all: $(TARGET) rs485.hex rs485.eep size
 
## Compile
P232.o: ../P232.c
$(CC) $(INCLUDES) $(CFLAGS) -c $<
 
##Link
$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) -o $(TARGET)
 
%.hex: $(TARGET)
avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@
 
%.eep: $(TARGET)
-avr-objcopy $(HEX_EEPROM_FLAGS) -O ihex $< $@ || exit 0
 
%.lss: $(TARGET)
avr-objdump -h -S $< > $@
 
size: ${TARGET}
@echo
@avr-size -C --mcu=${MCU} ${TARGET}
 
## Clean target
.PHONY: clean
clean:
-rm -rf $(OBJECTS) rs485.elf dep/* rs485.hex rs485.eep
 
## Other dependencies
-include $(shell mkdir dep 2>/dev/null) $(wildcard dep/*)
 
/programy/Atmel_C/RS232toRS485/default/rs485.hex
0,0 → 1,15
:1000000012C02AC029C028C027C026C025C024C0CD
:1000100023C022C021C020C01FC01EC01DC01CC0E4
:100020001BC01AC019C011241FBECFEDCDBF10E0F8
:10003000A0E6B0E0E0EEF0E003C0C89531960D9286
:10004000A036B107D1F710E0A0E6B0E001C01D92E4
:10005000A036B107E1F701C0D3CF8D9ABB9A8EB518
:1000600081608EBD81993AC0C39A40E65AEE68E03D
:1000700070E080B3282F3327227030701DBC1CBC69
:100080008CB59DB54817590770F080B399278270D9
:10009000907028173907A1F38CB59DB58417950783
:1000A00010F44CB55DB5615070408FEF6F3F78072D
:1000B00001F7819BFECF22E030E01DBC1CBC8CB55B
:1000C0009DB54817590710F08199F9CF215030405C
:1000D0008FEF2F3F380789F7819BC6CFC398C2CFD8
:00000001FF
/programy/Atmel_C/RS232toRS485/rs232.aps
0,0 → 1,0
<AVRStudio><MANAGEMENT><Created>22-May-2007 10:20:14</Created><LastEdit>22-May-2007 12:52:02</LastEdit><ProjectType>0</ProjectType><Created>22-May-2007 10:20:14</Created><Version>4</Version><Build>4, 13, 0, 528</Build><Created>22-May-2007 12:49:57</Created><LastEdit>22-May-2007 12:49:57</LastEdit><ProjectType>0</ProjectType><Created>22-May-2007 12:49:57</Created><Version>4</Version><Build>4, 13, 0, 528</Build><ProjectTypeName>AVR GCC</ProjectTypeName><ICON>241</ICON><ProjectName>rs232</ProjectName><Created>22-May-2007 12:50:51</Created><LastEdit>22-May-2007 12:50:51</LastEdit><ICON>241</ICON><ProjectType>0</ProjectType><Created>22-May-2007 12:50:51</Created><Version>4</Version><Build>4, 13, 0, 528</Build><ProjectTypeName>AVR GCC</ProjectTypeName></MANAGEMENT><CODE_CREATION><ObjectFile>default\rs485.elf</ObjectFile><EntryFile></EntryFile><ObjectFile></ObjectFile><EntryFile></EntryFile><ObjectFile></ObjectFile><EntryFile></EntryFile><SaveFolder>C:\E240\ass3\SW\</SaveFolder></CODE_CREATION><DEBUG_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><CURRENT_PART>ATtiny2313.xml</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND></IO_EXPAND><REGISTERNAMES></REGISTERNAMES><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_PART>ATtiny2313.xml</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND></IO_EXPAND><REGISTERNAMES></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><Triggers></Triggers></Debugger><AVRGCCPLUGIN><FILES><SOURCEFILE>Delay.c</SOURCEFILE><SOURCEFILE>P232.c</SOURCEFILE><SOURCEFILE>Uart.c</SOURCEFILE><HEADERFILE>Delay.h</HEADERFILE><HEADERFILE>Uart.h</HEADERFILE></FILES><CONFIGS><CONFIG><NAME>default</NAME><USESEXTERNALMAKEFILE>NO</USESEXTERNALMAKEFILE><EXTERNALMAKEFILE></EXTERNALMAKEFILE><PART>attiny2313</PART><HEX>1</HEX><LIST>0</LIST><MAP>1</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 -O3 -funsigned-char</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></Files><Workspace></Workspace><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio>
/programy/Atmel_C/RS232toRS485/rs232.aws
0,0 → 1,0
<AVRWorkspace><IOSettings><CurrentRegisters/></IOSettings><part name="ATTINY2313"/><Files/></AVRWorkspace>
/programy/Atmel_C/RS232toRS485/rs485.aps
0,0 → 1,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>
/programy/Atmel_C/RS232toRS485/rs485.aws
0,0 → 1,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>