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

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

Интервал:

Закладка:

Сделать

End Sub

Private Sub Command2_Click()

BufferOut(0) = 0 ' first byte 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 (data)

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

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

' Send command P=?? to the microcontroller to request its PORTB data

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

Private Sub Command3_Click()

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

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

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

BufferOut(3) = Asc("?") ' third data item ("?")

BufferOut(4) = Asc("?") ' fourth data item ("?")

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

hidWriteEx VendorID, ProductID, BufferOut(0)

lblstatus = "Data requested..."

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

' The data is received in the format: P=nT where the first byte

' is the report ID. i.e. BufferIn(0)=reportID, BufferIn(0)="P" and so on

' Check to make sure that received data is in correct format

If (BufferIn(1) = Asc("P") And BufferIn(2) = Asc("=") And _

BufferIn(4) = Asc("T")) Then

txtreceived = Str$(BufferIn(3))

lblstatus = "Data received..."

End If

End If

End Sub

картинка 285

Figure 8.33: Visual Basic program listing of the project

An installable version of the Visual Basic PC program is available in folder USB2 on the CDROM included with this book.

PROJECT 8.3 — USB-Based Ambient Pressure Display on the PC

In this project, an ambient atmospheric pressure sensor is connected to a PIC18F4550 microcontroller, and the measured pressure is sent and displayed on a PC every second using a USB link.

An MPX4115A-type pressure sensor is used in this project. This sensor generates an analog voltage proportional to the ambient pressure. The device is available in either a 6-pin or an 8-pin package.

The pin configuration of a 6-pin sensor is:

Pin Description

1 Output voltage

2 Ground

3 +5V supply

4–6 not used

and for an 8-pin sensor:

Pin Description

1 not used

2 +5V supply

3 Ground

4 Output voltage

5–8 not used

Figure 8.34 shows pictures of this sensor with both types of pin configurations.

Advanced PIC Microcontroller Projects in C - изображение 286

Figure 8.34: MPX4115A pressure sensors

The output voltage of the sensor is determined by:

V = 5.0 * (0.009 * kPa – 0.095) (8.1)

or

Advanced PIC Microcontroller Projects in C - изображение 287 (8.2)

where

kPa = atmospheric pressure (kilopascals)

V = output voltage of the sensor (V)

The atmospheric pressure measurements are usually shown in millibars. At sea level and at 15°C the atmospheric pressure is 1013.3 millibars. In Equation (8.2) the pressure is given in kPa. To convert kPa to millibars we have to multiply Equation (8.2) by 10 to give:

Advanced PIC Microcontroller Projects in C - изображение 288 (8.3)

or

Advanced PIC Microcontroller Projects in C - изображение 289 (8.4)

Figure 8.35 shows the variation of the output voltage of MPX4115A sensor as the pressure varies. We are interested in the range of pressure between 800 and 1100 millibars.

Figure 835 Variation of sensor output voltage with pressure The steps to - фото 290

Figure 8.35: Variation of sensor output voltage with pressure

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

Интервал:

Закладка:

Сделать

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