18F4550 microcontroller ile USB denemeleri için bir pic basic pro
derlemesi örneği altta görülüyor.
18F4550 yerine 18F2550 de kullanılabilir. 18F2550 yi kullanırken
derlemede ve chip device seçeneğinde değiştirmeyi unutmayın.
' Name : USBCDC.pbp
' Compiler : PICBASIC PRO Compiler 2.6
' Assembler : MPASM
' Target PIC : PIC18F4550 or similar type
' Hardware : LAB-XUSB Experimenter Board
' Oscillator : 20MHz external
' Keywords : USBSERVICE, USBINIT, USBIN, USBOUT
' Description : PICBASIC PRO program for PIC18F4550 CDC serial port emulation.
' Compilation of this program requires that specific support files be available
' in the source directory. You may also need to modify the file USBDESC.ASM so
' that the proper descriptor files are included. For detailed information, see
' the file PBP\USB18\USB.TXT.
'
Include "cdc_desc.bas" ' Include the HID descriptors
buffer Var Byte[16]
cnt Var Byte
LED Var PORTB.0
Define OSC 48
USBInit
Low LED ' LED off
' Wait for USB input
idleloop:
USBService ' Must service USB regularly
cnt = 16 ' Specify input buffer size
USBIn 3, buffer, cnt, idleloop
' Message received
Toggle LED
buffer[0] = "M"
buffer[1] = "e"
buffer[2] = "r"
buffer[3] = "h"
buffer[4] = "a"
buffer[5] = "b"
buffer[6] = "a"
buffer[7] = ""
buffer[8] = "U"
buffer[9] = "S"
buffer[10] = "B"
buffer[11] = 13
buffer[12] = 10
buffer[13] = 0
outloop:
USBService ' Must service USB regularly
USBOut 3, buffer, 14, outloop
Goto idleloop ' Wait for next buffer
End
Hiç yorum yok:
Yorum Gönder
Yorum yazın