Subversion Repositories svnkaklik

Compare Revisions

Ignore whitespace Rev 383 → Rev 380

/roboti/Robotour/SW/wdt/wdt.c
0,0 → 1,17
#include "C:\dokumenty\svn\Kaklik\roboti\Robotour\SW\wdt\wdt.h"
 
 
void main()
{
 
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL);setup_wdt(WDT_144MS);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(VREF_LOW|-2);
setup_oscillator(False);
 
}
/roboti/Robotour/SW/wdt/wdt.h
0,0 → 1,18
#include <16F88.h>
#device adc=8
 
#FUSES WDT //Watch Dog Timer
#FUSES INTRC //Internal RC Osc
#FUSES NOPUT //No Power Up Timer
#FUSES MCLR //Master Clear pin enabled
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOIESO //Internal External Switch Over mode disabled
 
#use delay(clock=8000000,RESTART_WDT)
 
/roboti/Robotour/SW/wdt/wdt.hex
0,0 → 1,13
:1000000000308A000428000084011F30830570300E
:1000100083168F001F129F121B0880399B00073028
:100020009C001F129F121B0880399B0083121F1017
:10003000941283160611861406120030831294005F
:10004000831694000108C03981000B30F700073097
:1000500083128101813084000008F0390738800064
:1000600064000008F739F719F0397704800090012F
:100070000030F800920000308316920007309C0098
:10008000050864000630F700F70B44281C088312AB
:100090000D13FE3083169D0005158F010F086300B8
:04400E003D3FFC3FF7
:00000001FF
;PIC16F88
/roboti/Robotour/SW/board/main.cpp
0,0 → 1,164
/*****************************************************************************/
/*
* Board.cpp - communication with NGW100 Board Controller and I2C
*
* Copyright (C) 2007 Karel Hojdar, KAKL
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
*
* Revision history
* 15.06.2007 1.0 Undertaken from KAHO
* 09.09.2007 2.0 I2C US Ranger
*/
/*****************************************************************************/
 
#include <iostream>
 
#include <getopt.h>
#include <errno.h>
#include <string.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "linux/i2c-dev.h"
#include "linux/i2c.h"
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
 
 
using namespace std;
 
#define BC_Addr 0x0B
#define US_Addr 0x70 // 0xE0 in fact
#define PIC_Addr 0x50 // 0xA0 in fact
 
char vystup[30];
pthread_t thread_id;
FILE *pRouraO,*pRouraI;
unsigned int vzdalenost;
char command,ble;
 
void *print_tele(void *unused);
 
void DoExit(int ex)
{
exit(ex);
}
 
unsigned char xfunc[5] = {0x99, 0x9A, 0x9B, 0x9E, 0x8D};
unsigned char xlen[5] = {8, 6, 1, 15, 2};
 
int main(int argc, char *argv[], char *envp[])
{
int Len;
int i2cbus = 0;
char filename[20],Buf[64];
int file;
 
 
fprintf(stdout, "Ble................");
 
sprintf(filename, "/dev/i2c-%d", i2cbus);
file = open(filename, O_RDWR);
 
if (file < 0)
{
cerr << "Could not open /dev/i2c-0." << endl;
return -1;
}
/*
if (ioctl(file, I2C_SLAVE, BC_Addr) == -1)
{
fprintf(stderr, "Failed to set address to 0x%02x.\n", BC_Addr);
DoExit(-2);
}
 
Buf[0] = xfunc[0];
if ( write(file, Buf, 1) != 1)
{
fprintf(stderr, "Failed to write byte to address to 0x%02x, errno %i.\n", BC_Addr, errno);
DoExit(-3);
}
 
if (read(file, Buf, 1) != 1)
{
fprintf(stderr, "Failed to read response length, errno %i.\n", errno);
DoExit(-4);
}
 
Len = Buf[0];
if (read(file, Buf, Len) != Len)
{
fprintf(stderr, "Failed to read response, errno %i.\n", errno);
DoExit(-5);
}
 
 
Buf[Len] = 0x00;
fprintf(stdout, "Board ID is %s.\n", Buf);
*/
//!------ US ---------------------------------------------------------------------------
 
pthread_create(&thread_id, NULL, print_tele, NULL);
 
while(true)
{
if (ioctl(file, I2C_SLAVE, US_Addr) == -1)
{
fprintf(stderr, "Failed to set address to 0x%02x.\n", US_Addr);
DoExit(-6);
}
Buf[0]=0x0;
Buf[1]=0x51;
write(file, Buf, 2);
usleep(80000);
read(file, Buf, 3);
vzdalenost=(Buf[1]*256+Buf[2]);
usleep(300000);
 
if (ioctl(file, I2C_SLAVE, PIC_Addr) == -1)
{
fprintf(stderr, "Failed to set address to 0x%02x.\n", US_Addr);
DoExit(-6);
}
Buf[0]=command;
write(file, Buf, 1);
read(file, Buf, 1);
ble=Buf[0];
 
//!--------
printf("Vzdalenost: %u cm Command: %x\n",vzdalenost,ble);
 
};
close(file);
pthread_join(thread_id, NULL);
fclose(pRouraO);
 
return 0;
}
 
void *print_tele(void *unused)
{
while(1)
{
pRouraI = fopen("/home/ble/pipe","r");
command=fgetc(pRouraI);
fclose(pRouraI);
pRouraO = fopen("/home/ble/pipe","w");
fprintf(pRouraO,"Vzdalenost: %u cm Command: %x\n",vzdalenost,ble);
fclose(pRouraO);
}
}
/roboti/Robotour/SW/board/board.cbp
0,0 → 1,45
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="board" />
<Option pch_mode="2" />
<Option compiler="atmel_gnu_gcc_compiler" />
<Build>
<Target title="Debug">
<Option output="bin\Debug\board" prefix_auto="0" extension_auto="0" />
<Option object_output="obj\Debug\" />
<Option type="1" />
<Option compiler="atmel_gnu_gcc_compiler" />
<Compiler>
<Add option="-g" />
</Compiler>
<Linker>
<Add option="-lpthread" />
</Linker>
</Target>
<Target title="Release">
<Option output="bin\Release\board" prefix_auto="1" extension_auto="1" />
<Option object_output="obj\Release\" />
<Option type="1" />
<Option compiler="atmel_gnu_gcc_compiler" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Unit filename="main.cpp" />
<Extensions>
<code_completion />
<envvars />
<debugger />
</Extensions>
</Project>
</CodeBlocks_project_file>
/roboti/Robotour/SW/board/workspace.workspace
0,0 → 1,6
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_workspace_file>
<Workspace title="Workspace">
<Project filename="board.cbp" active="1" />
</Workspace>
</CodeBlocks_workspace_file>
/roboti/Robotour/SW/pic_i2c_slave/test.PJT
0,0 → 1,40
[PROJECT]
Target=test.HEX
Development_Mode=
Processor=0x688F
ToolSuite=CCS
 
[Directories]
Include=C:\Program Files\PICC\devices\;C:\Program Files\PICC\Dr
Library=
LinkerScript=
 
[Target Data]
FileList=C:\Dokumenty\svn\Kaklik\roboti\Robotour\SW\pic\test.c
BuildTool=C-COMPILER
OptionString=+FM
AdditionalOptionString=
BuildRequired=1
 
[test.c]
Type=4
Path=
FileList=
BuildTool=
OptionString=
AdditionalOptionString=
 
[mru-list]
1=test.c
 
[Windows]
0=0000 test.c 0 0 796 451 3 0
 
[Opened Files]
1=C:\Dokumenty\svn\Kaklik\roboti\Robotour\SW\pic\test.c
2=C:\Dokumenty\svn\Kaklik\roboti\Robotour\SW\pic\test.h
3=C:\Program Files\PICC\devices\16F88.h
4=
[Units]
Count=1
1=C:\Dokumenty\svn\Kaklik\roboti\Robotour\SW\pic\test.c (main)
/roboti/Robotour/SW/pic_i2c_slave/test.c
0,0 → 1,73
#include "test.h"
 
#define H1 PIN_A1
#define L1 PIN_A2
#define H2 PIN_A3
#define L2 PIN_A4
 
char command;
 
int n;
 
#INT_SSP
void ssp_interupt ()
{
BYTE incoming, state;
output_low(H1);
output_low(L1);
output_low(H2);
output_low(L2);
 
state = i2c_isr_state();
 
if(state < 0x80) //Master is sending data
{
output_toggle(PIN_A0);
command = i2c_read();
}
if(state == 0x80) //Master is requesting data
{
i2c_write(command);
}
}
 
void main()
{
 
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_oscillator(False);
 
enable_interrupts(GLOBAL);
enable_interrupts(INT_SSP);
while(true)
{
if(command=='a')
{
output_high(H1);
output_low(H2);
output_low(L1);
output_high(L2);
}
else
{
output_low(H1);
output_high(H2);
output_high(L1);
output_low(L2);
};
delay_us(60);
output_low(H1);
output_low(H2);
output_low(L1);
output_low(L2);
}
}
/roboti/Robotour/SW/pic_i2c_slave/test.h
0,0 → 1,19
#include <16F88.h>
#device adc=8
 
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPUT //No Power Up Timer
#FUSES MCLR //Master Clear pin enabled
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOIESO //Internal External Switch Over mode disabled
 
#use delay(clock=4000000)
#use i2c(Slave,Fast,sda=PIN_B1,scl=PIN_B4,force_hw,address=0xA0)