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», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

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

Интервал:

Закладка:

Сделать

The PC program, based on Visual Basic, is called PRESSURE. Subroutine OnRead receives the data arriving at the USB port of the PC and then displays it on the screen form. The program does not send any data to the USB bus. The program listing (except the global variable declarations) is given in Figure 8.40.

' 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

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

' 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)

Dim pressure As String

If hidRead(pHandle, BufferIn(0)) Then

' The first byte is the report ID. i.e. BufferIn(0)=reportID

pressure = Chr(BufferIn(1)) & Chr(BufferIn(2)) & Chr(BufferIn(3)) & _

Chr(BufferIn(4))

txtno = pressure

End If

End Sub

Figure 840 Visual Basic program of the project Figure 841 shows a typical - фото 295

Figure 8.40: Visual Basic program of the project

Figure 8.41 shows a typical output from the Visual Basic program, displaying the atmospheric pressure.

Figure 841 Typical output from the Visual Basic program An installable - фото 296

Figure 8.41: Typical output from the Visual Basic program

An installable version of the Visual Basic program is provided on the CDROM that comes with this book, in folder PRESSURE.

CHAPTER 9

Advanced PIC18 Projects — CAN Bus Projects

The Controller Area Network (CAN) is a serial bus communications protocol developed by Bosch (an electrical equipment manufacturer in Germany) in the early 1980s. Thereafter, CAN was standardized as ISO-11898 and ISO-11519, establishing itself as the standard protocol for in-vehicle networking in the auto industry. In the early days of the automotive industry, localized stand-alone controllers had been used to manage various actuators and electromechanical subsystems. By networking the electronics in vehicles with CAN, however, they could be controlled from a central point, the engine control unit (ECU), thus increasing functionality, adding modularity, and making diagnostic processes more efficient.

Early CAN development was mainly supported by the vehicle industry, as it was used in passenger cars, boats, trucks, and other types of vehicles. Today the CAN protocol is used in many other fields in applications that call for networked embedded control, including industrial automation, medical applications, building automation, weaving machines, and production machinery. CAN offers an efficient communication protocol between sensors, actuators, controllers, and other nodes in real-time applications, and is known for its simplicity, reliability, and high performance.

The CAN protocol is based on a bus topology, and only two wires are needed for communication over a CAN bus. The bus has a multimaster structure where each device on the bus can send or receive data. Only one device can send data at any time while all the others listen. If two or more devices attempt to send data at the same time, the one with the highest priority is allowed to send its data while the others return to receive mode.

As shown in Figure 9.1, in a typical vehicle application there is usually more than one CAN bus, and they operate at different speeds. Slower devices, such as door control, climate control, and driver information modules, can be connected to a slow speed bus. Devices that require faster response, such as the ABS antilock braking system, the transmission control module, and the electronic throttle module, are connected to a faster CAN bus.

Figure 91 Typical CAN bus application in a vehicle The automotive industrys - фото 297

Figure 9.1: Typical CAN bus application in a vehicle

The automotive industry’s use of CAN has caused mass production of CAN controllers. Current estimate is that 400 million CAN modules are sold every year, and CAN controllers are integrated on many microcontrollers, including PIC microcontrollers, and are available at low cost.

Figure 9.2 shows a CAN bus with three nodes. The CAN protocol is based on CSMA/CD.AMP (Carrier-Sense Multiple Access/Collision Detection with Arbitration on Message Priority) protocol, which is similar to the protocol used in Ethernet LAN. When Ethernet detects a collision, the sending nodes simply stop transmitting and wait a random amount of time before trying to send again. CAN protocol, however, solves the collision problem using the principle of arbitration, where only the highest priority node is given the right to send its data.

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

Интервал:

Закладка:

Сделать

Похожие книги на «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