/Designs/Tools/I2C-PIC-USB/PrjInfo.txt
0,0 → 1,13
[InfoShortDescription.en]
Simple IR reflexive sensor.
 
[InfoShortDescription.cs]
Jednoduche reflexivni cidlo.
 
[InfoLongDescription.en]
 
 
[InfoLongDescription.cs]
Čidlo obsahuje pouze reflexní optron s odporovým trimrem a slouží k rozlišování tmavého a světlého povrchu. Dá se použít jak pro detekci čáry pro čárového robota tak i pro snímání otáčení pohonných kol.
 
[End]
/Designs/Tools/I2C-PIC-USB/SW/PIC18F4550/main.c
0,0 → 1,174
#include "main.h"
 
#define USB_CON_SENSE_PIN PIN_D4
 
#include <pic18_usb.h>
#include "usbconfig.h"
#include <usb.h>
 
#include <usb.c>
 
 
/* commands from USB, must e.g. match command ids in kernel driver */
#define CMD_ECHO 0
#define CMD_GET_FUNC 1
#define CMD_SET_DELAY 2
#define CMD_GET_STATUS 3
 
#define CMD_I2C_IO 4
#define CMD_I2C_BEGIN 1 // flag fo I2C_IO
#define CMD_I2C_END 2 // flag fo I2C_IO
 
/* linux kernel flags */
#define I2C_M_TEN 0x10 /* we have a ten bit chip address */
#define I2C_M_RD 0x01
#define I2C_M_NOSTART 0x4000
#define I2C_M_REV_DIR_ADDR 0x2000
#define I2C_M_IGNORE_NAK 0x1000
#define I2C_M_NO_RD_ACK 0x0800
 
/* To determine what functionality is present */
#define I2C_FUNC_I2C 0x00000001
#define I2C_FUNC_10BIT_ADDR 0x00000002
#define I2C_FUNC_PROTOCOL_MANGLING 0x00000004 /* I2C_M_{REV_DIR_ADDR,NOSTART,..} */
#define I2C_FUNC_SMBUS_HWPEC_CALC 0x00000008 /* SMBus 2.0 */
#define I2C_FUNC_SMBUS_READ_WORD_DATA_PEC 0x00000800 /* SMBus 2.0 */
#define I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC 0x00001000 /* SMBus 2.0 */
#define I2C_FUNC_SMBUS_PROC_CALL_PEC 0x00002000 /* SMBus 2.0 */
#define I2C_FUNC_SMBUS_BLOCK_PROC_CALL_PEC 0x00004000 /* SMBus 2.0 */
#define I2C_FUNC_SMBUS_BLOCK_PROC_CALL 0x00008000 /* SMBus 2.0 */
#define I2C_FUNC_SMBUS_QUICK 0x00010000
#define I2C_FUNC_SMBUS_READ_BYTE 0x00020000
#define I2C_FUNC_SMBUS_WRITE_BYTE 0x00040000
#define I2C_FUNC_SMBUS_READ_BYTE_DATA 0x00080000
#define I2C_FUNC_SMBUS_WRITE_BYTE_DATA 0x00100000
#define I2C_FUNC_SMBUS_READ_WORD_DATA 0x00200000
#define I2C_FUNC_SMBUS_WRITE_WORD_DATA 0x00400000
#define I2C_FUNC_SMBUS_PROC_CALL 0x00800000
#define I2C_FUNC_SMBUS_READ_BLOCK_DATA 0x01000000
#define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA 0x02000000
#define I2C_FUNC_SMBUS_READ_I2C_BLOCK 0x04000000 /* I2C-like block xfer */
#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 0x08000000 /* w/ 1-byte reg. addr. */
#define I2C_FUNC_SMBUS_READ_I2C_BLOCK_2 0x10000000 /* I2C-like block xfer */
#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2 0x20000000 /* w/ 2-byte reg. addr. */
#define I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC 0x40000000 /* SMBus 2.0 */
#define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC 0x80000000 /* SMBus 2.0 */
 
#define I2C_FUNC_SMBUS_BYTE I2C_FUNC_SMBUS_READ_BYTE | \
I2C_FUNC_SMBUS_WRITE_BYTE
#define I2C_FUNC_SMBUS_BYTE_DATA I2C_FUNC_SMBUS_READ_BYTE_DATA | \
I2C_FUNC_SMBUS_WRITE_BYTE_DATA
#define I2C_FUNC_SMBUS_WORD_DATA I2C_FUNC_SMBUS_READ_WORD_DATA | \
I2C_FUNC_SMBUS_WRITE_WORD_DATA
#define I2C_FUNC_SMBUS_BLOCK_DATA I2C_FUNC_SMBUS_READ_BLOCK_DATA | \
I2C_FUNC_SMBUS_WRITE_BLOCK_DATA
#define I2C_FUNC_SMBUS_I2C_BLOCK I2C_FUNC_SMBUS_READ_I2C_BLOCK | \
I2C_FUNC_SMBUS_WRITE_I2C_BLOCK
 
#define I2C_FUNC_SMBUS_EMUL I2C_FUNC_SMBUS_QUICK | \
I2C_FUNC_SMBUS_BYTE | \
I2C_FUNC_SMBUS_BYTE_DATA | \
I2C_FUNC_SMBUS_WORD_DATA | \
I2C_FUNC_SMBUS_PROC_CALL | \
I2C_FUNC_SMBUS_WRITE_BLOCK_DATA | \
I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC | \
I2C_FUNC_SMBUS_I2C_BLOCK
 
/* ------------------------------------------------------------------------- */
#define DEFAULT_DELAY 10 // default 10us (100khz)
static unsigned clock_delay = DEFAULT_DELAY;
static unsigned clock_delay2 = DEFAULT_DELAY/2;
 
static unsigned short expected;
static unsigned char saved_cmd;
 
unsigned int8 control_data[8];
 
struct i2c_cmd {
unsigned char type;
unsigned char cmd;
unsigned short flags;
unsigned short addr;
unsigned short len;
};
 
#define STATUS_IDLE 0
#define STATUS_ADDRESS_ACK 1
#define STATUS_ADDRESS_NAK 2
 
unsigned int8 status = STATUS_IDLE;
 
void main()
{
 
unsigned int8 replyBuf[4];
 
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_ccp1(CCP_OFF);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
 
usb_init();
 
 
 
while (TRUE) {
if (usb_enumerated())
{
usb_gets(0,control_data,8,100);
 
switch(control_data[1])
{
case CMD_ECHO: // echo (for transfer reliability testing)
replyBuf[0] = control_data[2];
replyBuf[1] = control_data[3];
usb_puts(0,replyBuf,2,50);
break;
case CMD_GET_FUNC:
usb_puts(0,(I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL),32,50);
break;
case CMD_SET_DELAY:
/* The delay function used delays 4 system ticks per cycle. */
/* This gives 1/3us at 12Mhz per cycle. The delay function is */
/* called twice per clock edge and thus four times per full cycle. */
/* Thus it is called one time per edge with the full delay */
/* value and one time with the half one. Resulting in */
/* 2 * n * 1/3 + 2 * 1/2 n * 1/3 = n us. */
clock_delay = *(unsigned short*)(control_data+2);
if(!clock_delay) clock_delay = 1;
clock_delay2 = clock_delay/2;
if(!clock_delay2) clock_delay2 = 1;
break;
case CMD_I2C_IO:
case CMD_I2C_IO + CMD_I2C_BEGIN:
case CMD_I2C_IO + CMD_I2C_END:
case CMD_I2C_IO + CMD_I2C_BEGIN + CMD_I2C_END:
// these are only allowed as class transfers
// return i2c_do((struct i2c_cmd*)data);
break;
case CMD_GET_STATUS:
replyBuf[0] = status;
usb_puts(0,replyBuf,1,50);
break;
default:
// must not happen ...
break;
}
 
delay_ms(10);
}
}
}
/Designs/Tools/I2C-PIC-USB/SW/PIC18F4550/main.h
0,0 → 1,36
#include <18F4550.h>
#device adc=8
 
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HSPLL //High Speed Crystal/Resonator with PLL enabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOPBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES MCLR //Master Clear pin enabled
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL5 //Divide By 12(48MHz oscillator input)
#FUSES CPUDIV4 //System Clock by 4
#FUSES USBDIV //USB clock source comes from PLL divide by 2
#FUSES VREGEN //USB voltage regulator enabled
#FUSES ICPRT //ICPRT enabled
 
#use delay(clock=24000000)
#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_B7)
 
/Designs/Tools/I2C-PIC-USB/SW/PIC18F4550/main.hex
0,0 → 1,320
:100000003BEF09F06896000C046ED8CF05F0E0CF06
:1000100006F00001E9CF0CF0EACF07F0E1CF08F0DD
:10002000E2CF09F0D9CF0AF0DACF0BF0F3CF12F01C
:10003000F4CF13F0FACF14F0F5CF15F0F6CF16F099
:10004000F7CF17F000C00EF001C00FF002C010F0A3
:1000500003C011F0A0AA30EF00F0A1BA5DEF06F0E6
:100060000EC000F00FC001F010C002F011C003F08C
:100070000CC0E9FF07C0EAFF078E08C0E1FF09C016
:10008000E2FF0AC0D9FF0BC0DAFF12C0F3FF13C0B2
:10009000F4FF14C0FAFF15C0F5FF16C0F6FF17C035
:1000A000F7FF045006C0E0FF05C0D8FF1000F76A54
:1000B000BE0FF66E000EF7220900F5501200000385
:1000C000FFFFFFFFFFFFFFFFFFFFFFFFFFFFF76ADD
:1000D000DE0FF66E000EF7220900F550120000FF49
:1000E000FFFFFFFFFFFFFFFFFFFFFFFFFFFFF76ABD
:1000F000FE0FF66E000EF7220900F55012004000C8
:1001000008000000000000000000000000000000E7
:100110000000000000000000000000000000F76A7E
:100120002E0FF66E010EF7220900F5501200400066
:1001300000000000000000000000000000000000BF
:100140000000000000000000000000000000F76A4E
:100150005E0FF66E010EF7220900F5501200050140
:100160000902A1010901A1000509190129031500CE
:100170002501950375018102950175058101050130
:100180000930093109381581257F750895038106E5
:10019000C0C0F76AA20FF66E010EF7220900F550F3
:1001A00012000000F76AB40FF66E010EF722090084
:1001B000F55012003400F76AC60FF66E010EF722F2
:1001C0000900F550120009022200010100C03209A5
:1001D0000400000103010200092100010001223492
:1001E000000705810308000AF76AF80FF66E010E92
:1001F000F7220900F55012000100F76A0A0FF66EA7
:10020000020EF7220900F55012001200F76A1C0FC7
:10021000F66E020EF7220900F550120012011001CD
:10022000FF000040030431C6050201020001F76A25
:100230003E0FF66E020EF7220900F5501200000480
:100240000C00F76A520FF66E020EF7220900F55005
:1002500012000403090408035500530054001C0352
:100260006900320063002D005000490043002D005A
:10027000550053004200200020006D92699468A44C
:1002800002D06894FCD769EF06F0400E0401016FBC
:10029000040E036F100E026F880E006F046B040EC5
:1002A000076F500E066F0001000C70A002D0EDDF4A
:1002B0007090689A72EF06F06A6A689278EF06F0BA
:1002C000679166BF6781669F6651100803E2000E62
:1002D000016E17D067A10BD0036A6651E8DEFF08F4
:1002E00002E1000E01D0010E016E0BD00AD0036AAC
:1002F0006651EDDEFF0802E1000E01D0010E016E35
:1003000000D0000C036A6551700FE96E0F0E0320D8
:10031000EA6EEF6A65C066F0D3DF015218E06551FE
:10032000080DF350676BE96E040E6725EA6EEF6AFD
:100330006551080DF350676B666F040E6627000E5B
:10034000672366C0E9FF040E6725EA6EEF6A000CBA
:10035000010E646F64510F0805E364C065F0D2DFDD
:10036000642BF8D7000C5A6A5A520AE1036A5A50B1
:10037000240FE96E000E0320EA6EEF6A5A2AF4D7C2
:100380001B6A010E1C6E1A6A000C6A6A686A9F0E6C
:100390006B6E3D0E696E6E6ADBDFE5DF160E706E0A
:1003A00068A602D02FDEFCD76D986FDF030E1F6E9C
:1003B0007EEF06F0698468986D8284EF06F0689C91
:1003C0008AEF06F05FC020F0000CFF0E206E000CDC
:1003D0005D6A23522AE05D503F0827E31D50FC0F61
:1003E00017E2040F1FEF02F0036A2250E4DE5E6E94
:1003F0000FD0036A2250ABDE5E6E0AD0036A225031
:1004000020DF5E6E05D0036A225000DF5E6E00D0F2
:10041000222A23065D505D2A036A500FE96E040EFE
:100420000320EA6E5EC0EFFFD4D7235204E15D5093
:10043000400801E01A6A5DC05FF0C4DF000CE824E8
:10044000F76AF736590FF66E040EF7220A00F550D8
:10045000FA6E0800F550F96EE803F203FC03060497
:10046000226A1D6A04011351010A000109E0030A0E
:100470000CE0010A0DE0220A18E0030A2BE047D045
:10048000120E236E030E1D6E44D0220E236E41D039
:10049000020E1D6E036A040112510001C8DE226EB5
:1004A000036A2250CEDE236E34D0D8900401123578
:1004B000036A0001A2DE0900F5CF03F0226E223CA0
:1004C00001D006D0036A225076DE236E22D002D0FD
:1004D0007CDF2BD0D89004011435036A000159DE6B
:1004E0000900F5CF03F0226E223C01D00ED0010EA0
:1004F0001D6ED89004011435036A000153DE090013
:10050000F5CF03F0236E05D002D05FDF0ED05DDFA4
:100510000CD00401175305E12350165D02E216C406
:1005200023F0010E1A6E000153DF000C5C5204E14F
:10053000040E1F6E0DDFB1D0050E1F6E040E5F6E30
:10054000900E5E6E010E5D6E5D500F08D8A0A5D0B6
:100550005DC065F0D7DE606B036A5D50B8DDFF08F3
:100560004DE0040E606FD8905D34036AD8DD090059
:10057000F5CF03F0616F03C062F05D50080DF350DA
:10058000656B646F010E6425016E000E6521036EBC
:1005900001C0E9FF040E0324EA6E61C0EFFF5D5065
:1005A000080DF350656B646F020E6425016E000E3A
:1005B0006521036E01C0E9FF040E0324EA6E5FC0EB
:1005C000ECFFED525EC0EFFFD8905D34036AA7DD0B
:1005D0000900F5CF03F05E2603505F22880E636F9B
:1005E00062B1638162B363835D50080DF350656B44
:1005F000E96E040E6525EA6E63C0EFFF036A5D5085
:1006000056DDFF0834E060835D50080DF350656BE4
:10061000646F040E6427000E6523020E6425016ECC
:10062000000E6521036E01C0E9FF040E0324EA6E8B
:100630005FC0ECFFED525EC0EFFFD8905D34036AFF
:1006400056DD0900F5CF03F05E2603505F225D50B2
:10065000080DF350656B646F040E6427000E65236C
:1006600064C0E9FF040E6525EA6E400EEF6E60512E
:10067000060802E10E0E606F036A5D5018DD010886
:10068000D8A46089036A5D50700FE96E0F0E0320D5
:10069000EA6E60C0EFFF5D2A57D79AEF03F00401BE
:1006A0001151000A00010DE0010A14E0020A1EE0E7
:1006B000060A27E0030A2CE00E0A2CE0010A30E0CB
:1006C0003DD01CC050F40401516B020E5F6E00015E
:1006D00079DE36D00401122D06D0010E1C165F6A99
:1006E000000170DE02D0000170DE2AD00401122D5C
:1006F00005D01C825F6A000165DE02D0000165DE64
:100700001FD0020E1A6E12C421F05F6A5BDE18D091
:10071000A7DE16D01BC050F4010E5F6E53DE10D062
:1007200004011251010808E312C41BF012C45CF06A
:100730000001FCD65F6A46DE000102D046DE00D032
:10074000ADEF04F01BC05CF004011151000A000180
:1007500007E00A0A0DE0010A28E00D0A38E039D066
:100760000401506B516B020E5F6E00012BDE33D023
:100770005C5219E0010E5C5C036A36DD016E040117
:10078000145DD8A002D000010ED0036A1451240FCA
:10079000E96E000E0320EA6EEFCF50F4010E5F6E9B
:1007A000000110DE01D011DE16D05C520EE0036AAB
:1007B00004011451240FE96E000E0320EA6E12C4E6
:1007C000EFFF5F6A0001FEDD01D0FFDD04D048DEEF
:1007D00002D0FBDD00D0ADEF04F05D905CBE5D802B
:1007E0005C9E5DA011D05C50080DF3505F6A5E6E98
:1007F000040E5E26000E5F225EC0E9FF040E5F2439
:10080000EA6E880EEF6E09D05C50080DF3505F6AF7
:10081000E96E040E5F24EA6EEF6A6FEF04F05D90FC
:100820005CBE5D805C9E5DA011D05C50080DF350F5
:100830005F6A5E6E040E5E26000E5F225EC0E9FFF8
:10084000040E5F24EA6E840EEF6E0AD05C50080D31
:10085000F3505F6AE96E040E5F24EA6E840EEF6E59
:1008600075EF04F05D905CBE5D805C9E5DA011D074
:100870005C50080DF350606B5F6E040E5F26000E37
:1008800060235FC0E9FF040E6025EA6EEFCF5EF0E3
:100890000AD05C50080DF350606BE96E040E6025C1
:1008A000EA6EEFCF5EF05EAE02D05EB402D0000E14
:1008B00001D0010E016E7FEF04F014C466F000DD7C
:1008C000015229E004011151010A000105E0020A68
:1008D00009E0030A0DE01DD014C45CF07ED75F6A06
:1008E00071DD19D014C45CF09AD75F6A6BDD13D048
:1008F0000401506B516B14C45CF00001B3D701527A
:1009000004E0010E0401506F0001020E5F6E5ADD1B
:1009100002D05BDD00D0ADEF04F00401115100D036
:10092000000153DD00D0ADEF04F01A6A040110514C
:100930007F0B000A000107E0010A07E0030A07E055
:10094000230A07E008D0ABD608D0FCD606D0B5D72E
:1009500004D0E3D702D039DD00D0CCEF05F05C50F5
:10096000080DF350626BE96E040E6225EA6EEFCF5C
:100970005EF05D50020806E15EAC02D05D6A02D016
:10098000010E5D6E5D50030813E1840E5E6E5C50D7
:10099000080DF350626B616F040E6127000E622335
:1009A00061C0E9FF040E6225EA6E840EEF6E07D087
:1009B0005D2C03D0C80E5E6E02D0880E5E6ED8909D
:1009C0005C34036A8FEC00F00900F5CF03F05F6E32
:1009D00003C060F05C50080DF350626B616F010E54
:1009E0006125016E000E6221036E01C0E9FF040E55
:1009F0000324EA6E5FC0EFFF60B15E8060B35E8289
:100A00005C50080DF350626BE96E040E6225EA6ECD
:100A10005EC0EFFF000C036A6151700FE96E0F0EAC
:100A20000320EA6EEF5212E06151080DF350636B40
:100A3000626F040E6227000E632362C0E9FF040E9A
:100A40006325EA6EEFCF62F062AF02D0000E01D0F4
:100A5000010E016E000C5CC061F0DDDF015262E04E
:100A60005C50080DF350626B616F040E6127000E3D
:100A70006223010E6125016E000E6221036E01C02A
:100A8000E9FF040E0324EA6E5DC0EFFF5F50020829
:100A900017E15C50080DF350626B616F040E612723
:100AA000000E622361C0E9FF040E6225EA6EEFCFFB
:100AB00060F060AD02D05F6A02D0010E5F6E13D0AD
:100AC0005F50040810E15C50080DF350626BE96E52
:100AD000040E6225EA6EEFCF60F060AD03D0010E28
:100AE0005F6E01D05F6A5F2C03D0C80E606F02D0CA
:100AF000880E606F5EB060815EB260835C50080DEE
:100B0000F350626B616F040E6127000E622361C0B7
:100B1000E9FF040E6225EA6E60C0EFFF010E016E70
:100B200003D000D0000E016E000C5C5200E1000CFE
:100B30005DC06EFF5D5203E0040E1F6E02D0020E18
:100B40001F6EA8EF05F01B6A1A6A21C05DF0F0D78E
:100B5000B4EF05F05C5208E11A2C02D039DC04D065
:100B60001A50020801E1EFD7000C1E305A6E5A32BB
:100B70005A321F0E5A161E5242E1040100513C0B1C
:100B80005B6E430E00175B5034081EE10451800B6E
:100B900001E0046B0001C9D66D98203C05D05C6A69
:100BA000030E5D6EDCDE0ED05C6A020E5D6ED7DE7B
:100BB0002050FE0807E05C6A5E6A20C05DF0040E0B
:100BC0005F6E49DF19D004015B50040816E15C6ACE
:100BD0000001ABDF5C6A020E5D6EC1DE2050FE08D4
:100BE0000AE0203C01D007D05C6A5E6A20C05DF05C
:100BF000010E5F6E30DF00D004015CD000011E509A
:100C0000040814E1430E04010417FF0E206E5C6A11
:100C10000001A0DF203C01D008D05C6A5E6A20C0E1
:100C20005DF0020E5F6E17DF00D043D01EB41BD004
:100C30005A50080DF3505D6A016E040E5D24036E78
:100C40005A50080DF3505F6AE96E040E5F24EA6E95
:100C5000EF50430B03C0EAFF01C0E9FFEF6E5AC03B
:100C60005CF063DF26D05A50080DF3505D6A5C6E6D
:100C7000040E5C26000E5D225CC001F0040E5D24B3
:100C8000036E5A50080DF3505F6A5E6E040E5E26C6
:100C9000000E5F225EC0E9FF040E5F24EA6EEF5093
:100CA000430B03C0EAFF5CC0E9FFEF6E5AC05CF083
:100CB00051DF0401000194EF06F0A19A1F5201E1F7
:100CC00039D0685237E068A404D069A402D03DEF5F
:100CD00001F06DA201D02ED068AA04D069AA02D07A
:100CE00055EF01F068A204D069A202D05CEF01F0D8
:100CF00068A004D069A002D0C5EF01F068A804D0B4
:100D000069A802D0DAEF01F068AC04D069AC02D077
:100D1000DFEF01F0596A68A608D069A606D06CCF4B
:100D20001EF002EC00F021D701D004D05950592A0E
:100D30000308F1E230EF00F06D6A696A080E6F6E29
:100D400094503009946E1F6A196AF2BE198EF29E91
:100D5000B3EC01F019BEF28E000CEEDFDBEF06F013
:100D6000196AF2BE198EF29EB3EC01F019BEF28E32
:100D70006D6A140E6F6E696A6D86010E1F6EC7EF85
:100D800006F0958883A804D06DB601D0E9D703D0CA
:100D90006DA601D0D1DF1F2C0BD06DBA09D0686AC7
:100DA000696AA08AC00EF212110E696E020E1F6EE1
:100DB000DCEF06F0D2D7E5D71F500208FCE173EF55
:100DC00009F01B50016E74EF09F0036A4750700F71
:100DD000E96E0F0E0320EA6EEF520DE04750080D4A
:100DE000F350496A486EE96E040E4924EA6EEFCF6B
:100DF00048F048AE02D0000E01D0010E016EBAEFED
:100E000007F04C50080DF350576A566E020E5624E8
:100E1000016E000E5720036E01C0E9FF040E03248B
:100E2000EA6EECCF03F0ED52EFCF51F003C052F079
:100E30004C50080DF350576A566E010E5624016E41
:100E4000000E5720036E01C0E9FF040E0324EA6E72
:100E5000EF50036A546E03C055F04C50080DF35028
:100E6000576AE96E040E5724EA6EEFCF53F053B081
:100E7000558053B255825550505C08E303E14F5002
:100E8000545C04E255C050F054C04FF04EC0EAFF2D
:100E90004DC0E9FF52C0E2FF51C0E1FF50C002F077
:100EA0004FC001F0015202E0022A02D0025206E0D5
:100EB000E6CFEEFF012EFCD7022EFAD74FC001F08D
:100EC00050C002F06FEF07F047C04CF049C04EF041
:100ED00048C04DF04BC050F04AC04FF092D702C00E
:100EE0004BF001C04AF0196AF2BE198EF29E47C05B
:100EF0005CF0020E5D6E33DD19BEF28E4AC001F069
:100F00004BC002F0C7EF07F0EA6A470EE96EEF50F8
:100F10000EE0070E016E006A002EFED7012EFBD7F1
:100F2000C70E006E002EFED70000EF2EF2D7000C89
:100F30003E6A3D6AD8903634036A8FEC00F00900AF
:100F4000F5CF03F0436E03C044F044503A5C09E32C
:100F500003E13950435C05E244C046F043C045F02C
:100F600004D03AC046F039C045F0406A3F6A36C006
:100F700047F02BD701521DE036C047F038C049F08A
:100F800037C048F046C04BF045C04AF09DD702C07C
:100F900042F001C041F041503726425038224150C2
:100FA000395E42503A5A41503D2642503E220DD0C1
:100FB00006D03F2AD8B4402A010E476EA5DF3B5029
:100FC0003F5CD5E13C50405CD2E14350415C0CE1D8
:100FD0004450425C09E13B503F5C03E13C50405CC3
:100FE00003E039503A10B1E13DC001F03EC002F0DB
:100FF00081EF09F0536A546A010E556EDA6AD96AB4
:10100000586A4B0E576EEA6A4F0EE96E58C0E2FFFF
:1010100057C0E1FF55C056F0D890E550EE02F350AE
:101020005322F4505422562EF7D753C0DEFF54C03B
:1010300053F0546AD8B0542A572AD8B4582A552A9B
:1010400055500508E0E1000C196AF2BE198EF29EB7
:1010500049C061F0E0DC19BEF28E015245E0495012
:10106000080DF350526A516E040E5126000E5222A2
:10107000020E5124016E000E5220036E01C0E9FFE2
:10108000040E0324EA6EECCF03F0ED52EFCF4FF0E5
:1010900003C050F050C0EAFF4FC0E9FF4BC0E2FF71
:1010A0004AC0E1FF4DC002F04CC001F0015202E025
:1010B000022A02D0025206E0E6CFEEFF012EFCD754
:1010C000022EFAD7196AF2BE198EF29E49C05CF060
:1010D0004DC05EF04CC05DF04EC05FF0BCDC19BE90
:1010E000F28E015003D000D0000E016E000C3D6A5C
:1010F0003C6AD8903634036A77EC00F00900F5CFEB
:1011000003F0416E03C042F03D503A5CD8A069D074
:1011100003E139503C5C65E24A6A496A486A3BC06F
:1011200047F04AC04EF049C04DF048C04CF03BC0BB
:101130004BF0526A516A030E506EE80E4F6E5ADF42
:1011400003C046F002C045F001C044F000C043F0C7
:101150003C50395C476E3D503A58486E4250485CAE
:1011600009E303E14750415C05E242C040F041C061
:101170003FF006D03C50395C3F6E3D503A58406ECF
:101180003C503724476E3D503820486E36C049F0F9
:101190004B6E47C04AF040C04DF03FC04CF0020ECD
:1011A0004E6E52DF3E9001B03E803EB00BD000D07C
:1011B00000D000D0FF0E4326D8A04426D8A0452654
:1011C000D8A046263EB008D04352DAE14452D8E1D6
:1011D0004552D6E14652D4E141503C2642503D2290
:1011E00093D739503C5C42E13A503D5C3FE14A6A5A
:1011F000496A486A3BC047F04AC04EF049C04DF0CA
:1012000048C04CF03BC04BF0526A516A030E506E1E
:10121000E80E4F6EEFDE03C046F002C045F001C09D
:1012200044F000C043F036C049F04B6A4A6A4D6A48
:101230004C6A020E4E6E08DF3E9001B03E803EB01A
:101240000BD000D000D000D0FF0E4326D8A04426FB
:10125000D8A04526D8A046263EB008D04352E3E1A8
:101260004452E1E14552DFE14652DDE1000E3EB07D
:10127000010E016E000CF86AD09E078EEA6AE96AD8
:101280001F6A236A0A0E256E050E266E316AC1504A
:10129000C00B0F09C16E070EB46E2790286AC150AB
:1012A000C00B0F09C16EC090C092C094C09EC28096
:1012B0009698D190800ED56ECD6A000ECA6E000E43
:1012C000CB6EB16A9484BD6AB76AB66A070EB46E13
:1012D0009250926E130E006E002EFED700D0B450C6
:1012E000A19CB56A67D56DD501525CE0366A386A53
:1012F000290E376E3A6A080E396E3C6A640E3B6EF0
:1013000017D62A500FE0010A1CE0030A25E0060A5E
:1013100037E0010A35E0030A33E0010A31E0040A4C
:1013200030E03CD02BC032F02CC033F0366A386A43
:10133000320E376E3A6A020E396E320E3B6ED7DECF
:101340002ED0366A386A010E376E3A6A200E396E30
:10135000320E3B6ECCDE23D0376A2B0EE96E37C0DF
:10136000EAFF256AEFB0252A255202E1010E256E1B
:10137000D8902530266E265202E1010E266E0FD03F
:101380000ED031C032F0366A386A320E376E3A6AA1
:10139000010E396E320E3B6EAADE01D000D00A0E6D
:0813A000476EB2DDA0D7030087
:020000040030CA
:0E0000003CCE390E0085A1000FC00FE00F406E
:00000001FF
;PIC18F4550
;CRC=6CBE CREATED="29-IX-13 00:37"
/Designs/Tools/I2C-PIC-USB/SW/PIC18F4550/main.pjt
0,0 → 1,30
[PROJECT]
Target=Z:\home\kaklik\svnMLAB\Designs\Tools\I2C-PIC-USB\SW\PIC18F4550\main.hex
Development_Mode=
Processor_Text=PIC18F4550
ToolSuite=CCS
Processor=0x4550
[Z:\home\kaklik\svnMLAB\Designs\Tools\I2C-PIC-USB\SW\PIC18F4550\main]
Type=4
Path=
FileList=
BuildTool=
OptionString=
AdditionalOptionString=
[mru-list]
1=Z:\home\kaklik\svnMLAB\Designs\Tools\I2C-PIC-USB\SW\PIC18F4550\main.c
[Windows]
0=0000 %S 0 0 796 451 3 0
[Units]
Link=0
Count=1
1=Z:\home\kaklik\svnMLAB\Designs\Tools\I2C-PIC-USB\SW\PIC18F4550\main
[Opened Files]
1=main.c
2=
3=C:\Program Files (x86)\PICC\devices\18F4550.h
4=C:\Program Files (x86)\PICC\drivers\pic18_usb.h
5=C:\Program Files (x86)\PICC\drivers\usb_hw_layer.h
6=usbconfig.h
7=C:\Program Files (x86)\PICC\drivers\usb.h
8=
/Designs/Tools/I2C-PIC-USB/SW/PIC18F4550/usbconfig.h
0,0 → 1,293
///////////////////////////////////////////////////////////////////////////
/// usbconfig.h ////
//// ////
//// An example set of device / configuration descriptors. ////
//// This set works exclusively with ex_usb_mouse.c example. ////
//// ////
///////////////////////////////////////////////////////////////////////////
//// ////
//// Version History: ////
//// ////
//// March 5th, 2009: ////
//// Cleanup for Wizard. ////
//// PIC24 Initial release. ////
//// ////
//// June 20th, 2005: ////
//// Initial 18Fxx5x release ////
//// ////
//// March 21st, 2005: ////
//// EP 0x81 now uses USB_EP1_TX_SIZE to define max packet size, to ////
//// make it easier for dynamically changed code. ////
//// EP 0x81 will now use 1ms polling interval if using a full speed ////
//// device. ////
//// ////
//// June 24th, 2002: Cleanup ////
//// ////
///////////////////////////////////////////////////////////////////////////
//// (C) Copyright 1996,2005 Custom Computer Services ////
//// This source code may only be used by licensed users of the CCS ////
//// C compiler. This source code may only be distributed to other ////
//// licensed users of the CCS C compiler. No other use, ////
//// reproduction or distribution is permitted without written ////
//// permission. Derivative programs created using this software ////
//// in object code form are not restricted in any way. ////
///////////////////////////////////////////////////////////////////////////
 
#IFNDEF __USB_DESCRIPTORS__
#DEFINE __USB_DESCRIPTORS__
 
///////// config options, although it's best to leave alone for this demo /////
#define USB_CONFIG_PID 0xc631
#define USB_CONFIG_VID 0x0403
#define USB_CONFIG_BUS_POWER 100 //100mA (range is 0..500)
#define USB_CONFIG_VERSION 0x0205 //01.00 //range is 00.00 to 99.99
//////// end config ///////////////////////////////////////////////////////////
 
 
 
#DEFINE USB_HID_DEVICE TRUE //Tells the CCS PIC USB firmware
//to include HID handling code.
 
//turn on EP1 for IN interrupt transfers. (IN = PIC -> PC)
#define USB_EP1_TX_ENABLE USB_ENABLE_INTERRUPT
 
#define USB_EP1_TX_SIZE 8 //max packet size of this endpoint
 
#include <usb.h>
 
//////////////////////////////////////////////////////////////////
///
/// HID Report. Tells HID driver how to handle and deal with
/// received data. HID Reports can be extremely complex,
/// see HID specifcation for help on writing your own.
///
/// This examples configures HID driver to take received data
/// as mouse x, y and button data.
///
//////////////////////////////////////////////////////////////////
 
const char USB_CLASS_SPECIFIC_DESC[] =
{
0x05, 0x01, // usage page (generic desktop Choose the usage page "mouse" is on
0x09, 0x02, // usage (mouse) Device is a mouse
0xA1, 0x01, // collection (application) This collection encompasses the report format
0x09, 0x01, // usage (pointer) Choose the key code usage page
0xA1, 0x00, // collection (physical) Physical collection
0x05, 0x09, // usage page (buttons) Choose the “button” usage page
0x19, 0x01, // usage minimum (1) There are three buttons
0x29, 0x03, // usage maximum (3)
0x15, 0x00, // logical minimum (0) Each button is represented by one bit
0x25, 0x01, // logical maximum (1)
0x95, 0x03, // report count (3) Three reports, one bit each
0x75, 0x01, // report size (1)
0x81, 0x02, // input (data, variable, absolute) Defined bits above are data bits
0x95, 0x01, // report count (1) One report, five bits in length
0x75, 0x05, // report size (5)
0x81, 0x01, // input (constant) Bit stuff to fill byte
0x05, 0x01, // usage page (generic desktop) Choose the usage pare “X” and “Y” are on
0x09, 0x30, // usage (X) X direction of pointer
0x09, 0x31, // usage (Y) Y direction of pointer
0x09, 0x38 // usage (wheel)
0x15, 0x81, // logical minimum (-127) Range of report data is -127 to 127
0x25, 0x7F, // logical maximum (127)
0x75, 0x08, // report size (8) Two reports, eight bits each
0x95, 0x03, // report count (3)
0x81, 0x06, // input (data, variable, absolute) Defined bits above are data bits
0xC0, // end collection End physical collection
0xC0 // end collection End application collection
};
 
//if a class has an extra descriptor not part of the config descriptor,
// this lookup table defines where to look for it in the const
// USB_CLASS_SPECIFIC_DESC[] array.
//first element is the config number (if your device has more than one config)
//second element is which interface number
//set element to 0xFFFF if this config/interface combo doesn't exist
const int16 USB_CLASS_SPECIFIC_DESC_LOOKUP[USB_NUM_CONFIGURATIONS][1] =
{
//config 1
//interface 0
0
};
 
//if a class has an extra descriptor not part of the config descriptor,
// this lookup table defines the size of that descriptor.
//first element is the config number (if your device has more than one config)
//second element is which interface number
//set element to 0xFFFF if this config/interface combo doesn't exist
const int16 USB_CLASS_SPECIFIC_DESC_LOOKUP_SIZE[USB_NUM_CONFIGURATIONS][1] =
{
//config 1
//interface 0
sizeof(USB_CLASS_SPECIFIC_DESC)
};
 
 
 
//////////////////////////////////////////////////////////////////
///
/// start config descriptor
/// right now we only support one configuration descriptor.
/// the config, interface, class, and endpoint goes into this array.
///
//////////////////////////////////////////////////////////////////
 
#DEFINE USB_TOTAL_CONFIG_LEN 34 //config+interface+class+endpoint
 
const char USB_CONFIG_DESC[] = {
//IN ORDER TO COMPLY WITH WINDOWS HOSTS, THE ORDER OF THIS ARRAY MUST BE:
// config(s)
// interface(s)
// class(es)
// endpoint(s)
 
//config_descriptor for config index 1
USB_DESC_CONFIG_LEN, //length of descriptor size ==1
USB_DESC_CONFIG_TYPE, //constant CONFIGURATION (CONFIGURATION 0x02) ==2
USB_TOTAL_CONFIG_LEN,0, //size of all data returned for this config ==3,4
1, //number of interfaces this device supports ==5
0x01, //identifier for this configuration. (IF we had more than one configurations) ==6
0x00, //index of string descriptor for this configuration ==7
#if USB_CONFIG_BUS_POWER
0xC0, //bit 6=1 if self powered, bit 5=1 if supports remote wakeup (we don't), bits 0-4 unused and bit7=1 ==8
#else
0x80, //bit 6=1 if self powered, bit 5=1 if supports remote wakeup (we don't), bits 0-4 unused and bit7=1 ==8
#endif
USB_CONFIG_BUS_POWER/2, //maximum bus power required (maximum milliamperes/2) (0x32 = 100mA) ==9
 
//interface descriptor 1
USB_DESC_INTERFACE_LEN, //length of descriptor =10
USB_DESC_INTERFACE_TYPE, //constant INTERFACE (INTERFACE 0x04) =11
0x00, //number defining this interface (IF we had more than one interface) ==12
0x00, //alternate setting ==13
1, //number of endpoints, except 0 ==14
0x03, //class code, 03 = HID ==15
0x01, //subclass code //boot ==16
0x02, //protocol code ==17
0x00, //index of string descriptor for interface ==18
 
//class descriptor 1 (HID)
USB_DESC_CLASS_LEN, //length of descriptor ==19
USB_DESC_CLASS_TYPE, //dscriptor type (0x21 == HID) ==20
0x00,0x01, //hid class release number (1.0) (try 1.10) ==21,22
0x00, //localized country code (0 = none) ==23
0x01, //number of hid class descrptors that follow (1) ==24
0x22, //report descriptor type (0x22 == HID) ==25
USB_CLASS_SPECIFIC_DESC_LOOKUP_SIZE[0][0], 0x00, //length of report descriptor ==26,27
 
//endpoint descriptor
USB_DESC_ENDPOINT_LEN, //length of descriptor ==28
USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05) ==29
0x81, //endpoint number and direction (0x81 = EP1 IN) ==30
USB_ENDPOINT_TYPE_INTERRUPT, //transfer type supported (0x03 is interrupt) ==31
USB_EP1_TX_SIZE,0x00, //maximum packet size supported ==32,33
10 //polling interval, in ms. (cant be smaller than 10 for slow speed devices) ==34
};
 
 
//****** BEGIN CONFIG DESCRIPTOR LOOKUP TABLES ********
//since we can't make pointers to constants in certain pic16s, this is an offset table to find
// a specific descriptor in the above table.
 
//NOTE: DO TO A LIMITATION OF THE CCS CODE, ALL HID INTERFACES MUST START AT 0 AND BE SEQUENTIAL
// FOR EXAMPLE, IF YOU HAVE 2 HID INTERFACES THEY MUST BE INTERFACE 0 AND INTERFACE 1
#define USB_NUM_HID_INTERFACES 1
 
//the maximum number of interfaces seen on any config
//for example, if config 1 has 1 interface and config 2 has 2 interfaces you must define this as 2
#define USB_MAX_NUM_INTERFACES 1
 
//define how many interfaces there are per config. [0] is the first config, etc.
const char USB_NUM_INTERFACES[USB_NUM_CONFIGURATIONS]={1};
 
//define where to find class descriptors
//first dimension is the config number
//second dimension specifies which interface
//last dimension specifies which class in this interface to get, but most will only have 1 class per interface
//if a class descriptor is not valid, set the value to 0xFFFF
const int16 USB_CLASS_DESCRIPTORS[USB_NUM_CONFIGURATIONS][USB_NUM_HID_INTERFACES][1]=
{
//config 1
//interface 0
//class 1
18
};
 
 
#if (sizeof(USB_CONFIG_DESC) != USB_TOTAL_CONFIG_LEN)
#error USB_TOTAL_CONFIG_LEN not defined correctly
#endif
 
 
//////////////////////////////////////////////////////////////////
///
/// start device descriptors
///
//////////////////////////////////////////////////////////////////
 
const char USB_DEVICE_DESC[] = {
//starts of with device configuration. only one possible
USB_DESC_DEVICE_LEN, //the length of this report ==1
0x01, //the constant DEVICE (DEVICE 0x01) ==2
0x10,0x01, //usb version in bcd (pic167xx is 1.1) ==3,4
0xff, //class code ==5
0x00, //subclass code ==6
0x00, //protocol code ==7
USB_MAX_EP0_PACKET_LENGTH, //max packet size for endpoint 0. (SLOW SPEED SPECIFIES 8) ==8
USB_CONFIG_VID & 0xFF, ((USB_CONFIG_VID >> 8) & 0xFF), //vendor id ==9, 10
USB_CONFIG_PID & 0xFF, ((USB_CONFIG_PID >> 8) & 0xFF), //product id, don't use 0xffff ==11, 12
USB_CONFIG_VERSION & 0xFF, ((USB_CONFIG_VERSION >> 8) & 0xFF), //device release number ==13,14
0x01, //index of string description of manufacturer. therefore we point to string_1 array (see below) ==15
0x02, //index of string descriptor of the product ==16
0x00, //index of string descriptor of serial number ==17
USB_NUM_CONFIGURATIONS //number of possible configurations ==18
};
 
#if (sizeof(USB_DEVICE_DESC) != USB_DESC_DEVICE_LEN)
#error USB_DESC_DEVICE_LEN not defined correctly
#endif
 
 
//////////////////////////////////////////////////////////////////
///
/// start string descriptors
/// String 0 is a special language string, and must be defined. People in U.S.A. can leave this alone.
///
//////////////////////////////////////////////////////////////////
 
//the offset of the starting location of each string. offset[0] is the start of string 0, offset[1] is the start of string 1, etc.
const char USB_STRING_DESC_OFFSET[]={0,4,12};
 
//number of strings you have, including string 0.
#define USB_STRING_DESC_COUNT sizeof(USB_STRING_DESC_OFFSET)
 
// Here is where the "CCS" Manufacturer string and "CCS USB Mouse" are stored.
// Strings are saved as unicode.
char const USB_STRING_DESC[]={
//string 0
4, //length of string index
USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
0x09,0x04, //Microsoft Defined for US-English
//string 1
8, //length of string index
USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
'U',0,
'S',0,
'T',0,
//string 2
28, //length of string index
USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
'i',0,
'2',0,
'c',0,
'-',0,
'P',0,
'I',0,
'C',0,
'-',0,
'U',0,
'S',0,
'B',0,
' ',0,
' ',0
};