This commit is contained in:
WarL0ck 2013-11-18 21:27:01 +07:00
parent 7047bc7fa2
commit d132f803d9
5 changed files with 54 additions and 34 deletions

View File

@ -1 +1 @@
<AVRStudio><MANAGEMENT><ProjectName>Rmodule</ProjectName><Created>14-Nov-2013 11:48:57</Created><LastEdit>17-Nov-2013 15:50:59</LastEdit><ICON>241</ICON><ProjectType>0</ProjectType><Created>14-Nov-2013 11:48:57</Created><Version>4</Version><Build>4, 19, 0, 730</Build><ProjectTypeName>AVR GCC</ProjectTypeName></MANAGEMENT><CODE_CREATION><ObjectFile>default\Rmodule.elf</ObjectFile><EntryFile></EntryFile><SaveFolder>c:\Hard\Rmodule\</SaveFolder></CODE_CREATION><DEBUG_TARGET><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_PART>ATmega8.xml</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><Triggers></Triggers></Debugger><AVRGCCPLUGIN><FILES><SOURCEFILE>main.c</SOURCEFILE><SOURCEFILE>uart\uart.c</SOURCEFILE><SOURCEFILE>onewire\onewire.c</SOURCEFILE><SOURCEFILE>C:\Hard\Rmodule\uart\uart_addon.c</SOURCEFILE><HEADERFILE>uart\uart.h</HEADERFILE><HEADERFILE>res\strings.h</HEADERFILE><HEADERFILE>onewire\onewire.h</HEADERFILE><HEADERFILE>C:\Hard\Rmodule\uart\uart_addon.h</HEADERFILE><OTHERFILE>default\Rmodule.lss</OTHERFILE><OTHERFILE>default\Rmodule.map</OTHERFILE></FILES><CONFIGS><CONFIG><NAME>default</NAME><USESEXTERNALMAKEFILE>NO</USESEXTERNALMAKEFILE><EXTERNALMAKEFILE></EXTERNALMAKEFILE><PART>atmega8</PART><HEX>1</HEX><LIST>1</LIST><MAP>1</MAP><OUTPUTFILENAME>Rmodule.elf</OUTPUTFILENAME><OUTPUTDIR>default\</OUTPUTDIR><ISDIRTY>1</ISDIRTY><OPTIONS><OPTION><FILE>main.c</FILE><OPTIONLIST></OPTIONLIST></OPTION></OPTIONS><INCDIRS/><LIBDIRS/><LIBS/><LINKOBJECTS/><OPTIONSFORALL>-Wall -gdwarf-2 -std=gnu99 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums</OPTIONSFORALL><LINKEROPTIONS></LINKEROPTIONS><SEGMENTS/></CONFIG></CONFIGS><LASTCONFIG>default</LASTCONFIG><USES_WINAVR>1</USES_WINAVR><GCC_LOC>C:\Program Files\Atmel\AVR Tools\AVR Toolchain\bin\avr-gcc.exe</GCC_LOC><MAKE_LOC>C:\Program Files\Atmel\AVR Tools\AVR Toolchain\bin\make.exe</MAKE_LOC></AVRGCCPLUGIN><ProjectFiles><Files><Name>c:\Hard\Rmodule\uart\uart.h</Name><Name>c:\Hard\Rmodule\res\strings.h</Name><Name>c:\Hard\Rmodule\onewire\onewire.h</Name><Name>c:\Hard\Rmodule\main.c</Name><Name>c:\Hard\Rmodule\uart\uart.c</Name><Name>c:\Hard\Rmodule\onewire\onewire.c</Name></Files></ProjectFiles><IOView><usergroups/><sort sorted="0" column="0" ordername="0" orderaddress="0" ordergroup="0"/></IOView><Files><File00000><FileId>00000</FileId><FileName>main.c</FileName><Status>1</Status></File00000><File00001><FileId>00001</FileId><FileName>onewire\onewire.h</FileName><Status>1</Status></File00001></Files><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio>
<AVRStudio><MANAGEMENT><ProjectName>Rmodule</ProjectName><Created>14-Nov-2013 11:48:57</Created><LastEdit>18-Nov-2013 21:18:20</LastEdit><ICON>241</ICON><ProjectType>0</ProjectType><Created>14-Nov-2013 11:48:57</Created><Version>4</Version><Build>4, 19, 0, 730</Build><ProjectTypeName>AVR GCC</ProjectTypeName></MANAGEMENT><CODE_CREATION><ObjectFile>default\Rmodule.elf</ObjectFile><EntryFile></EntryFile><SaveFolder>c:\Hard\Rmodule\</SaveFolder></CODE_CREATION><DEBUG_TARGET><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_PART>ATmega8.xml</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><Triggers></Triggers></Debugger><AVRGCCPLUGIN><FILES><SOURCEFILE>main.c</SOURCEFILE><SOURCEFILE>uart\uart.c</SOURCEFILE><SOURCEFILE>onewire\onewire.c</SOURCEFILE><SOURCEFILE>C:\Hard\Git\Rmodule\uart\uart_addon.c</SOURCEFILE><HEADERFILE>uart\uart.h</HEADERFILE><HEADERFILE>res\strings.h</HEADERFILE><HEADERFILE>onewire\onewire.h</HEADERFILE><HEADERFILE>C:\Hard\Git\Rmodule\uart\uart_addon.h</HEADERFILE><OTHERFILE>default\Rmodule.lss</OTHERFILE><OTHERFILE>default\Rmodule.map</OTHERFILE></FILES><CONFIGS><CONFIG><NAME>default</NAME><USESEXTERNALMAKEFILE>NO</USESEXTERNALMAKEFILE><EXTERNALMAKEFILE></EXTERNALMAKEFILE><PART>atmega8</PART><HEX>1</HEX><LIST>1</LIST><MAP>1</MAP><OUTPUTFILENAME>Rmodule.elf</OUTPUTFILENAME><OUTPUTDIR>default\</OUTPUTDIR><ISDIRTY>1</ISDIRTY><OPTIONS><OPTION><FILE>main.c</FILE><OPTIONLIST></OPTIONLIST></OPTION></OPTIONS><INCDIRS/><LIBDIRS/><LIBS/><LINKOBJECTS/><OPTIONSFORALL>-Wall -gdwarf-2 -std=gnu99 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums</OPTIONSFORALL><LINKEROPTIONS></LINKEROPTIONS><SEGMENTS/></CONFIG></CONFIGS><LASTCONFIG>default</LASTCONFIG><USES_WINAVR>1</USES_WINAVR><GCC_LOC>C:\Program Files\Atmel\AVR Tools\AVR Toolchain\bin\avr-gcc.exe</GCC_LOC><MAKE_LOC>C:\Program Files\Atmel\AVR Tools\AVR Toolchain\bin\make.exe</MAKE_LOC></AVRGCCPLUGIN><ProjectFiles><Files><Name>c:\Hard\Rmodule\uart\uart.h</Name><Name>c:\Hard\Rmodule\res\strings.h</Name><Name>c:\Hard\Rmodule\onewire\onewire.h</Name><Name>C:\Hard\Git\Rmodule\uart\uart_addon.h</Name><Name>c:\Hard\Rmodule\main.c</Name><Name>c:\Hard\Rmodule\uart\uart.c</Name><Name>c:\Hard\Rmodule\onewire\onewire.c</Name><Name>C:\Hard\Git\Rmodule\uart\uart_addon.c</Name></Files></ProjectFiles><IOView><usergroups/><sort sorted="0" column="0" ordername="0" orderaddress="0" ordergroup="0"/></IOView><Files><File00000><FileId>00000</FileId><FileName>main.c</FileName><Status>1</Status></File00000><File00001><FileId>00001</FileId><FileName>res\strings.h</FileName><Status>1</Status></File00001></Files><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio>

View File

@ -55,7 +55,7 @@ uart.o: ../uart/uart.c
onewire.o: ../onewire/onewire.c
$(CC) $(INCLUDES) $(CFLAGS) -c $<
uart_addon.o: ../uart/uart_addon.c
uart_addon.o: ../../Git/Rmodule/uart/uart_addon.c
$(CC) $(INCLUDES) $(CFLAGS) -c $<
##Link

View File

@ -5,13 +5,12 @@
#include <avr/interrupt.h>
#include "uart/uart.h"
#include "uart/uart_addon.h"
#include "res/strings.h"
#include "onewire/onewire.h"
#include "res/strings.h"
#define UART_BAUD_RATE 19200
unsigned char getcmd(void){
unsigned char get_uart_char(void){
unsigned int res;
do{
res = uart_getc();
@ -19,29 +18,41 @@ unsigned char getcmd(void){
return (unsigned char) res;
}
static int get_uart_line(char *pbuf, int len_ln){
int i = 0;
unsigned char c;
len_ln=len_ln-1;
while((c=get_uart_char()) != 0x0D && i<len_ln){
uart_putc(c);
pbuf[i] = c;
i=i+1;
}
pbuf[i] = '\0';
return i;
}
void getListDevices(void){
uint8_t i;
uint8_t id[OW_ROMCODE_SIZE];
uint8_t diff, nSensors;
char buffer[40];
uart_puts("\r\nScanning 1-wire bus\r\n");
uart_puts_p(ScanStr);
ow_reset();
nSensors = 0;
diff = OW_SEARCH_FIRST;
while ( diff != OW_LAST_DEVICE) {
diff = ow_rom_search( diff, &id[0] );
//if ( diff != OW_PRESENCE_ERR && diff != OW_DATA_ERR && diff != OW_LAST_DEVICE ) {
if ( diff != OW_PRESENCE_ERR && diff != OW_DATA_ERR) {
for ( i=0; i < OW_ROMCODE_SIZE; i++ ){
sprintf(buffer,"%02X ",id[i]);
uart_puts(buffer);
uart_puthex_byte(id[i]);
uart_putc(' ');
}
uart_puts("\r\n");
//}
uart_puts(CRLF);
}
nSensors++;
}
sprintf(buffer,"Found %d devices",nSensors);
uart_puts(buffer);
uart_put_int(nSensors);
}
int main(void){
@ -52,19 +63,21 @@ int main(void){
#endif
sei();
char cmd = '0';
while (cmd != 'q'){
uart_puts_p(MainMenuItemTitle);
uart_puts_p(MainMenuItem1);
uart_puts_p(MainMenuItem2);
uart_puts_p(MainMenuItemQuit);
uart_puts_p(MainMenuItemPrompt);
cmd = getcmd();
if (cmd == '1'){
getListDevices();
char cmd[5];
unsigned int len_line=0;
while(1){
uart_puts_p(CmdPrompt);
len_line=get_uart_line(&cmd[0],sizeof(cmd));
if (len_line>0){
if (strcmp_P(cmd, CmdLD)==0){
getListDevices();
}
if (strcmp_P(cmd, CmdHelp)==0){
uart_puts_p(HelpTitle);
uart_puts_p(HelpItem1);
uart_puts_p(HelpItem2);
}
}
}
while(1){ }
}

View File

@ -1,10 +1,17 @@
#include <avr/pgmspace.h>
// Ãëàâíîå ìåíþ
const char MainMenuItemTitle[] PROGMEM = "\r\n---==== Main menu ---";
const char MainMenuItem1[] PROGMEM = "\r\n1) List devices";
const char MainMenuItem2[] PROGMEM = "\r\n2) Selected device : ";
const char MainMenuItemQuit[] PROGMEM = "\r\nq) Quit";
const char MainMenuItemPrompt[] PROGMEM = "\r\n# ";
#define CRLF "\r\n"
//
const char CmdLD[] PROGMEM = "ld";
const char CmdHelp[] PROGMEM = "h";
// Ñïèñîê êîìàíä
const char HelpTitle[] PROGMEM = CRLF "Command list:";
const char HelpItem1[] PROGMEM = CRLF "ld - List devices";
const char HelpItem2[] PROGMEM = CRLF "h - Show this help";
const char CmdPrompt[] PROGMEM = CRLF "$ ";
// Ðàçíûå íóæíûå ñòðîêè
const char ScanStr[] PROGMEM = CRLF "Scanning 1-wire bus" CRLF;

View File

@ -1 +1 @@
<AVRWorkspace><IOSettings><CurrentRegisters><EEPROM><register register="EEAR" group="EEPROM" display="1" locked="0"/></EEPROM><EEPROM><register register="EECR" group="EEPROM" display="1" locked="0"/></EEPROM><EEPROM><register register="EEDR" group="EEPROM" display="1" locked="0"/></EEPROM></CurrentRegisters></IOSettings><part name="ATMEGA8"/><Files><File00000 Name="c:\Hard\Rmodule\main.c" Position="262 96 1079 813" LineCol="33 0" State="Maximized"/><File00001 Name="c:\Hard\Rmodule\onewire\onewire.h" Position="288 145 895 613" LineCol="20 0" State="Maximized"/></Files></AVRWorkspace>
<AVRWorkspace><IOSettings><CurrentRegisters/></IOSettings><part name="ATMEGA8"/><Files><File00000 Name="c:\Hard\Rmodule\main.c" Position="262 96 1079 803" LineCol="18 1" State="Maximized"/><File00001 Name="c:\Hard\Rmodule\res\strings.h" Position="288 145 895 613" LineCol="12 40" State="Maximized"/></Files></AVRWorkspace>