#define LM85_REG_TEMP(nr) (0x25 + (nr))................data->temp[i] = lm85_read_value(client, LM85_REG_TEMP(i));
When reading data from a register, there are two possibilities:1. If the ADT7463’s Address Pointer Register value is unknownor not the desired value, it is first necessary to set it tothe correct value before data can be read from the desireddata register. This is done by performing a write to theADT7463 as before, but only the data byte containing theregister address is sent as data is not to be written to theregister.
C++ (Qt)#include <windows.h>#include <stdio.h>#include <conio.h>#include "winio.h" byte configPort[4]={0x87, 0x01, 0x55, 0x55};WORD indexPort = 0x2e;WORD dataPort = 0x2f;WORD addressPortEC = 0, dataPortEC = 0; DWORD readFromPort(WORD index) { bool result = false; DWORD portValue = 0; result = SetPortVal(indexPort, index, 1); if (result) { result = GetPortVal(dataPort, &portValue, 1); if (result) { return portValue; } printf("Ошибка при чтении значения из порта.\n"); return 0; } else { printf("Ошибка при записи значения в порт.\n"); return 0; }} bool writeToPort(WORD index, DWORD value, byte numBytes=1) { bool result = false; short a = 0; a = outp(indexPort, index); if (result) { result = SetPortVal(dataPort, value, 1); if (result) { return true; } printf("Ошибка при записи значения в порт.\n"); return false; } else { printf("Ошибка при записи значения в порт.\n"); return false; }} void main(){ bool bResult; DWORD res; bResult = InitializeWinIo(); if (bResult) { for (int i=0; i<4; i++) { SetPortVal(0x2e, configPort[i], 1); } res = readFromPort(0x20); if ((byte)res==0x87) { res = readFromPort(0x21); if ((byte)res==0x12) { printf("Initialize ITE-8712 - OK.\n"); } else { printf("Error during initialize ITE-8712.\n"); } } else { printf("Error during initialize ITE-8712.\n"); } ShutdownWinIo(); } else { printf("Error during initialization of WinIo.\n"); exit(1); }}
C++ (Qt)/* !ПСЕВДОКОД! */int v = readbyte(0x40);cout << "v = " << v;if ( !(v & 0x01) ) { cout << "ok, " << v; writebyte(0x40, v | 0x01);}if ( v & 0x02 ) { cout << "locked";}if ( v & 0x04 ) { cout << "ready";}