Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 12 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
12
Dung lượng
543,25 KB
Nội dung
PIC and USB - French version/Version franỗaise - Forum: Microcontrollers and usb Electronicfr in english · Linux on Fujitsu stylistic 1200 · How-to builda webserver for 30Euros with ENC28J60 · A little autonomous robot · A new autonomous robot project (V2) · How-to buildausbdeviceawith18F4550or18F2550USB and PIC tutorial - Part - HowtobuildaUSBdevicewithaPIC18F4550or18F2550 - Part - Application: HowtobuildaUSB thermometer New: Discussion forum Part 1: HowtobuildaUSBdevicewithaPIC18F4550or18F2550 Electronicfr en francais · Fabriquer un serveur web avec un circuit Overview ENC28J60 · Un petit robot autonome picbasic 3B · Un nouveau robot autonome PICPIC18F4550 and 18F2550 are powerful microcontrollers including a full-speed USB V2.0 compliant interface With these MCU it's very easy for the hobbyist to design USB devices with very few components · Construire un périphérique USB avec un PIC18F4550 ou 18F2550 In this page, I will describe howto use theCDC firmware from Microchip It permits to emulate a serial port witha PC running Windows or Linux It's also very easy tobuild HID devices Nouveau: Forum de discussion The18F4550 experimentation board Search: Here is a picture of the experimentation board: www.electronicfr Web com Search www.policefr.com The following schematic is very simple, only few components are needed It's a self powered USBdevice Please note I'm using the Olimex tiny-ICSD programmer, if you want to use another PIC ICSP programmer, you should remove D1 and D2 and change the connector (You can click on the picture to get an high resolution picture) This device is compatible withthemicrochipUSB bootloader Please note C5 is 470nF (the datasheet recommend 220nF but more is better) and should be low ESR (for example a multi-layer ceramic) Don't forget the 100nF decoupling caps Here is a possible implementation Click on the picture to get a 300dpi PCB You can look at the wire's colour of your USB cable: Black=GND, Red=+5V, Green=Data+, White=Data- The software You can download MCHPFSUSB_Setup on theMicrochip website It's a windows exe :( The firmware we will use is written in C (for the C18 Microchip compiler) This code is (royaltyes) free, but it's not a free software, so it's not possible to redistribute modified source code In this archive, you will find: ● ● ● ● ● TheUSB bootloader and its source code in C18 A windows utility for the bootloader TheCDC firmware source code (serial emulation) in C18 It can be used withtheUSB bootloader without modification Another firmware for the HID deviceA windows driver for CDC (under linux CDC-ACM is natively supported) Some tips for your prototypes: Source code is in the fw/cdc/MCHPUSB.mcw directory You should comment the following lines in usbcfg.h for a self powered usb device: #define USE_SELF_POWER_SENSE_IO #define USE_USB_BUS_SENSE_IO On my schematic, LED's are connected on port B So you should modify io_cfg.h #define #define #define #define mLED_1 mLED_2 mLED_3 mLED_4 LATBbits.LATB0 LATBbits.LATB1 LATBbits.LATB2 LATBbits.LATB3 You can put your own code on user.c For example, look at Exercise_Example() in user.c Useful functions are getsUSBUSART() (get data) and putrsUSBUSART() (put data other the serial port) Don't forget to check mUSBUSARTIsTxTrfReady() before to send data They are some examples in the exercise directory For example, the following program (to put in user.c) toggle the LED number when you press the key "1" in the terminal They are some examples in the exercice directory For example, the following program (to put in user.c) toggle the LED number when you press the key "1" in the terminal void Exercise_03(void){ if(getsUSBUSART(input_buffer,1)) { if(input_buffer[0] == '1') mLED_4_Toggle(); } Under windows, you must install the provided driver and you can use the hyperterminal utility (19200bd witha 20MHz crystal) Under linux, check the cdc-acm module, a new device /dev/ttyACM0 should appear If you don't want to use the bootloader, you must remove the vector remapping section in main.c and change the linker script (look at important.readme.txt in the sources directory) Next part -> Application: HowtobuildaUSB thermometer PIC and USB - French version/Version franỗaise - Forum: Microcontrollers and usb Electronicfr in english · Linux on Fujitsu stylistic 1200 · How-to builda webserver for 30Euros with ENC28J60 · A little autonomous robot · A new autonomous robot project (V2) USB and PIC tutorial - Part - HowtobuildaUSBdevicewithaPIC18F4550or18F2550 - Part - Application: HowtobuildaUSB thermometer Part 2: HowtobuildaUSB thermometer withPIC18F4550or18F2550 · How-to build an usbdevicewith18F4550or18F2550 New: Discussion forum Electronicfr en francais · Fabriquer un serveur web avec un circuit ENC28J60 · Un petit robot autonome picbasic 3B · Un nouveau robot autonome PIC · Construire un périphérique USB avec un PIC18F4550 ou 18F2550 Nouveau: Forum de discussion Search: www.electronicfr Web Search com Sensor and schematic We will add a temperature sensor tothe circuit described in the first part of this tutorial You can use the very usual LM35 circuit (Datasheet), or many others circuits like MCP9701, TC1047 The following schematic show howto plug the sensor on our USB experimentation board: www.policefr.com The firmware We will add some code for analog to digital convertion and temperature calculation in the file user.x //Lets add includes for ADC and strings manipulations #include #include #include //[ ] // We will write output data in this string char input_buffer[64]; // [ ] void Exercise_Example(void) { int temp; // [ ] else if(start_up_state == 3) { if(mUSBUSARTIsTxTrfReady()) { //A0 set in input TRISAbits.TRISA0 = 1; memset(output_buffer, '\0', 64); output_buffer[(6*5)] = '\r'; output_buffer[(6*5)+1] = '\n'; OpenADC(ADC_FOSC_8 & ADC_RIGHT_JUST & ADC_0_TAD, ADC_CH0 & ADC_INT_OFF & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS, 0b1011); SetChanADC(ADC_CH0); Delay10TCYx( 50 ); ConvertADC(); // Start conversion while( BusyADC() ); // Wait for ADC conversion temp = ReadADC(); // Read result and put in temp CloseADC(); // Disable A/D converter temp=temp/7; //Convert in centigrad degrees itoa(temp, output_buffer); // Convert toa string mUSBUSARTTxRam((byte*)output_buffer,(6*5)+2); start_up_state=0; } } }//end Exercise_Example The value in Celsius degree will be sent threw theUSB bus when the button on RB4 will be pressed Under windows, you can use the hyperterminal utility (19200bd witha 20MHz cristal) to see the value Under linux you can use cat /dev/ ttyACM0 Howto use a18F2550 You can use the source code for 4550 with very few modifications Just select the appropriate device in the MPLAB configure menu Change the linker script, and set the configuration bits (like in this picture) Remove any references to port D in io_cfg.h Here is a picture of a small prototype using PIC 18F2550: Some links about USB Making sense of theUSB standard (Beyond logic) Understanding USB (usbdeveloper) USB 2.0 Specifications(usb.org) USB 1.1 specifications (pdf file) Getting help Ask your question tothe electronicfr community http://www.electronicfr.com/forum/phpBB2/viewforum.php?f=1 Disclaimer ANY CONTENT ON THIS WEBSITE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE Next Soon, you will find a schematic for aUSBto serial (RS232) converter ... - Application: How to build a USB thermometer Part 2: How to build a USB thermometer with PIC 18F4550 or 18F2550 · How- to build an usb device with 18F4550 or 18F2550 New: Discussion forum Electronicfr... webserver for 30Euros with ENC28J60 · A little autonomous robot · A new autonomous robot project (V2) USB and PIC tutorial - Part - How to build a USB device with a PIC 18F4550 or 18F2550 - Part - Application:... data) and putrsUSBUSART() (put data other the serial port) Don't forget to check mUSBUSARTIsTxTrfReady() before to send data They are some examples in the exercise directory For example, the following