Ibrahim Dogan - Advanced PIC Microcontroller Projects in C

Здесь есть возможность читать онлайн «Ibrahim Dogan - Advanced PIC Microcontroller Projects in C» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Город: Burlington, Год выпуска: 2008, ISBN: 2008, Издательство: Elsevier Ltd, Жанр: Программирование, Компьютерное железо, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

Advanced PIC Microcontroller Projects in C: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Advanced PIC Microcontroller Projects in C»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

• The only project book on the PIC 18 series using the C programming language
• Features 20 complete, tried and test projects
• Includes a CD-ROM of all the programs, hex listings, diagrams, and data sheets

Advanced PIC Microcontroller Projects in C — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Advanced PIC Microcontroller Projects in C», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Figure 8.19 shows the final listing of the Visual Basic program. The program is in two parts: the form USB1.FRM and the module USB1.BAS. The programs should be loaded and used in the Visual Basic development environment. An installable version of this program (in folder USB1) comes with the CDROM included with this book for those who do not have the Visual Basic development environment. This program should be installed as a normal Windows software installation.

USB1.FRM

' vendor and product IDs

Private Const VendorID = 4660

Private Const ProductID = 1

' read and write buffers

Private Const BufferInSize = 8

Private Const BufferOutSize = 8

Dim BufferIn(0 To BufferInSize) As Byte

Dim BufferOut(0 To BufferOutSize) As Byte

Private Sub Command1_Click()

Form_Unload (0)

End

End Sub

Private Sub Command2_Click()

BufferOut(0) = 0 ' first by is always the report ID

BufferOut(1) = Asc("P") ' first data item (“P”)

BufferOut(2) = Asc("=") ' second data item (“-“)

BufferOut(3) = Val(txtno) ' third data item (to send over USB)

BufferOut(4) = Asc("T") ' fourth data item (“T”)

' write the data (don't forget, pass the whole array)...

hidWriteEx VendorID, ProductID, BufferOut(0)

lblstatus = "Data sent..."

End Sub

'***************************************************************************

' when the form loads, connect to the HID controller - pass

' the form window handle so that you can receive notification

' events...

'***************************************************************************

Private Sub Form_Load()

' do not remove!

ConnectToHID (Me.hwnd)

lblstatus = "Connected to HID..."

End Sub

'****************************************************************************

' disconnect from the HID controller...

'****************************************************************************

Private Sub Form_Unload(Cancel As Integer)

DisconnectFromHID

End Sub

'****************************************************************************

' a HID device has been plugged in...

'****************************************************************************

Public Sub OnPlugged(ByVal pHandle As Long)

If hidGetVendorID(pHandle) = VendorID And _

hidGetProductID(pHandle) = ProductID Then

lblstatus = "USB Plugged....."

End If

End Sub

'****************************************************************************

' a HID device has been unplugged...

'****************************************************************************

Public Sub OnUnplugged(ByVal pHandle As Long)

If hidGetVendorID(pHandle) = VendorID And _

hidGetProductID(pHandle) = ProductID Then

lblstatus = "USB Unplugged...."

End If

End Sub

'****************************************************************************

' controller changed notification - called

' after ALL HID devices are plugged or unplugged

'****************************************************************************

Public Sub OnChanged()

Dim DeviceHandle As Long

' get the handle of the device we are interested in, then set

' its read notify flag to true - this ensures you get a read

' notification message when there is some data to read...

DeviceHandle = hidGetHandle(VendorID, ProductID)

hidSetReadNotify DeviceHandle, True

End Sub

'****************************************************************************

' on read event...

'****************************************************************************

Public Sub OnRead(ByVal pHandle As Long)

' read the data (don't forget, pass the whole array)...

If hidRead(pHandle, BufferIn(0)) Then

' ** YOUR CODE HERE **

' first byte is the report ID, e.g. BufferIn(0)

' the other bytes are the data from the microcontrolller...

End If

End Sub

USB1.BAS

' this is the interface to the HID controller DLL - you should not

' normally need to change anything in this file.

'

' WinProc() calls your main form 'event' procedures - these are currently

' set to..

'

' MainForm.OnPlugged(ByVal pHandle as long)

' MainForm.OnUnplugged(ByVal pHandle as long)

' MainForm.OnChanged()

' MainForm.OnRead(ByVal pHandle as long)

Option Explicit

' HID interface API declarations...

Declare Function hidConnect Lib "mcHID.dll" Alias "Connect" (ByVal pHostWin As Long) As Boolean

Declare Function hidDisconnect Lib "mcHID.dll" Alias "Disconnect" () As Boolean

Declare Function hidGetItem Lib "mcHID.dll" Alias "GetItem" (ByVal pIndex As Long) As Long

Declare Function hidGetItemCount Lib "mcHID.dll" Alias "GetItemCount" () As Long

Declare Function hidRead Lib "mcHID.dll" Alias "Read" (ByVal pHandle As Long, ByRef pData As Byte) As Boolean

Declare Function hidWrite Lib "mcHID.dll" Alias "Write" (ByVal pHandle As Long, ByRef pData As Byte) As Boolean

Declare Function hidReadEx Lib "mcHID.dll" Alias "ReadEx" (ByVal pVendorID As Long, ByVal pProductID As Long, ByRef pData As Byte) As Boolean

Declare Function hidWriteEx Lib "mcHID.dll" Alias "WriteEx" (ByVal pVendorID As Long, ByVal pProductID As Long, ByRef pData As Byte) As Boolean

Declare Function hidGetHandle Lib "mcHID.dll" Alias "GetHandle" (ByVal pVendorID As Long, ByVal pProductID As Long) As Long

Declare Function hidGetVendorID Lib "mcHID.dll" Alias "GetVendorID" (ByVal pHandle As Long) As Long

Declare Function hidGetProductID Lib "mcHID.dll" Alias "GetProductID" (ByVal pHandle As Long) As Long

Declare Function hidGetVersion Lib "mcHID.dll" Alias "GetVersion" (ByVal pHandle As Long) As Long

Declare Function hidGetVendorName Lib "mcHID.dll" Alias "GetVendorName" (ByVal pHandle As Long, ByVal pText As String, ByVal pLen As Long) As Long

Declare Function hidGetProductName Lib "mcHID.dll" Alias "GetProductName" (ByVal pHandle As Long, ByVal pText As String, ByVal pLen As Long) As Long

Declare Function hidGetSerialNumber Lib "mcHID.dll" Alias "GetSerialNumber" (ByVal pHandle As Long, ByVal pText As String, ByVal pLen As Long) As Long

Declare Function hidGetInputReportLength Lib "mcHID.dll" Alias "GetInputReportLength" (ByVal pHandle As Long) As Long

Declare Function hidGetOutputReportLength Lib "mcHID.dll" Alias "GetOutputReportLength" (ByVal pHandle As Long) As Long

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «Advanced PIC Microcontroller Projects in C»

Представляем Вашему вниманию похожие книги на «Advanced PIC Microcontroller Projects in C» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «Advanced PIC Microcontroller Projects in C»

Обсуждение, отзывы о книге «Advanced PIC Microcontroller Projects in C» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x