📄 i2cbus.cpp
字号:
/******************************************************************************/
/* @F_NAME: i2cbus.cpp */
/* @F_PURPOSE: c++ I2c bus control manager (on parallel port) */
/* @F_CREATED_BY: D. KOCH (david.koch@libertysurf.fr) */
/* @F_CREATION_DATE: 21/04/00 */
/* @F_MODIFIED_BY: D. KOCH (david.koch@libertysurf.fr) */
/* @F_MODIFICATION_DATE: 05/06/01 - programmersheaven special version */
/* @F_LANGUAGE : ANSI C++ */
/* @F_MPROC_TYPE: ALL COMPUTER WITH PC-LIKE MAPPED PARALLEL DATA PORT */
/***** (C) Copyright 2001 Programmer's Heaven (info@programmersheaven.com) ****/
/*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/
/*\ INFORMATIONS (SOME KINDA) /*/
/*/ \*/
/*\ ======================================================================== /*/
/*/ \*/
/*\ ETUDE DU PORT PARALLELE SUR PC ET DU CONVERTISSEUR /*/
/*/ \*/
/*\ | LPT1 | LPT2 WRITE D7 D6 D5 D4 D3 D2 D1 D0 /*/
/*/ -----+------+------ x x x x x /SCL /SDA '1' \*/
/*\ WRITE| 378h | 278h /*/
/*/ -----+------+------ READ D7 D6 D5 D4 D3 D2 D1 D0 \*/
/*\ READ | 379h | 279h x x SCL SDA x x x x /*/
/*/ \*/
/*\ ======================================================================== /*/
/*/ \*/
/*\ ETUDE DU BUS I2C de PHILIPS /*/
/*/ \*/
/*\ TRAME : {Start} SDA --, /*/
/*/ . |_____ \*/
/*\ . SCL -----, /*/
/*/ . |__ \*/
/*\ {Adresse.7bits}{R/W.1bit} /*/
/*/ {Ackowledge.1bit} \*/
/*\ ... /*/
/*/ {Donnee.8bits} \*/
/*\ {Ackowledge.1bit} /*/
/*/ . \*/
/*\ . /*/
/*/ . \*/
/*\ {Stop} SDA ,-- /*/
/*/ _____| \*/
/*\ SCL ,----- /*/
/*/ __| \*/
/*\ /*/
/*/ FONCTIONNEMENT DE 'ACKNOWLEDGE' \*/
/*\ /*/
/*/ 1. Mise a '1' de SDA par le Maitre \*/
/*\ 2. Passage d'un SCL /*/
/*/ 3. Si SDA est mis a '0' par l'Esclave \*/
/*\ OK, tout s'est bien passe ! /*/
/*/ Si SDA est laisse a '1' par l'Esclave \*/
/*\ Une ERREUR est survenue /*/
/*/ En emission, c'est l'Esclave qui repond... \*/
/*\ En reception, le Maitre repond 'toujours' OK ! /*/
/*/ \*/
/*\ ======================================================================== /*/
/*/ \*/
/*\ STRUCTURE DES TRAMES /*/
/*/ \*/
/*\ Module | Addr | Data1 | Data2 | Data3 | Data4 | Data5 | Data6 | Data7 /*/
/*/ -------+------+-------+-------+-------+-------+-------+-------+------ \*/
/*\ Affich W 0x70 | 0 | 77 | Digi1 | Digi2 | Digi3 | Digi4 | /*/
/*/ -------+------+-------+-------+-------+-------+-------+-------+------ \*/
/*\ Horlog W 0xA2 | Addr | Data0 | Data1 | ... | | | /*/
/*/ R 0xA3 | D@00h | D@01h | ... | | | | \*/
/*\ /*/
/*/ \*/
/*\ ======================================================================== /*/
/*/ \*/
/*\ AFFICHEUR (ADRESSE 0x070) /*/
/*/ \*/
/*\ bit0 /*/
/*/ ---- \*/
/*\ bit5| |bit1 /*/
/*/ |bit6| \*/
/*\ ---- /*/
/*/ bit4| |bit2 \*/
/*\ | | /*/
/*/ ---- bit7 \*/
/*\ bit3 /*/
/*/ \*/
/*\ ======================================================================== /*/
/*/ Get more informations about the I2C bus on http://www.philips.com \*/
/*\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
/*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/
/*\ CODE OVERVIEW /*/
/*/ \*/
/*\ INCLUDES /*/
/*/ DEFINES (CONSTANTS, ...) \*/
/*\ CLASS FluxI2C DEFINITION /*/
/*/ CONSTRUCTORS AND DESTRUCTORS \*/
/*\ LEVEL 0 METHODS (LOW LEVEL) /*/
/*/ InitI2C \*/
/*\ PowerOffI2C /*/
/*/ TestBusI2C \*/
/*\ SetBitI2C /*/
/*/ ClearBitI2C \*/
/*\ TestBitI2C /*/
/*/ LEVEL 1 METHODS (LOGIC LEVEL) \*/
/*\ StartI2C /*/
/*/ StopI2C \*/
/*\ SAcknowledgeI2C /*/
/*/ RAcknowledgeI2C \*/
/*\ LEVEL 2 METHODS (MACRO LEVEL) /*/
/*/ SendI2C \*/
/*\ ReceiveI2C /*/
/*/ CharConvert \*/
/*\ LEVEL 3 METHODS (FUNCTIONNAL LEVEL) /*/
/*/ SendI2CFlux \*/
/*\ ReceiveI2CFlux /*/
/*/ \*/
/*\ MAIN PROGRAM /*/
/*/ \*/
/*\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
/*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/
/*\ 'INCLUDE/DEFINE' /*/
/*/ \*/
/*\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
#include <conio.h>
#include <stdio.h>
#include <dos.h> // Pour 'delay'
#include <iostream.h>
/*** CNST_ADDR_BASE_WLPT ******************************************************/
/* Purpose : Base address of the LPT 1 port for writing */
/* Unit : None */
/* Range : Mem ADDR - FREE selection */
/* List : 0x0378 -> LPT1 */
/* 0x0278 -> LPT2 */
/* Example : #define CNST_ADDR_BASE_WLPT 0x0378 /* Writing addr of LPT1 */ */
/* WARNING : Due to the code structure, keep here >ALWAYS< 0x0378. */
/******************************************************************************/
#define CNST_ADDR_BASE_WLPT 0x0378
/*** CNST_ADDR_BASE_RLPT ******************************************************/
/* Purpose : Base address of the LPT 1 port for reading */
/* Unit : None */
/* Range : Mem ADDR - FREE selection */
/* List : 0x0379 -> LPT1 */
/* 0x0279 -> LPT2 */
/* Example : #define CNST_ADDR_BASE_RLPT 0x0379 /* Reading addr of LPT1 */ */
/* WARNING : Keep here >ALWAYS< CNST_ADDR_BASE_WLPT+1 (code structure) */
/******************************************************************************/
#define CNST_ADDR_BASE_RLPT CNST_ADDR_BASE_WLPT+1
/*** CNST_DATA_LOOP_TRY *******************************************************/
/* Purpose : Number of times the Receice routine will try to fetch the datas */
/* Unit : None */
/* Range : [0-3-...] - FREE selection */
/* List : 0 -> Only 1 try, else error */
/* 3 -> Will try 3 times before generating an error */
/* Example : #define CNST_DATA_LOOP_TRY 3 */
/******************************************************************************/
#define CNST_DATA_LOOP_TRY 3
/*** CNST_DATA_TIME_TEMPO *****************************************************/
/* Purpose : Time between two I2C clock cycles */
/* Unit : 1/1000 s */
/* Range : [...-10-100-...] - FREE selection */
/* List : 10 -> 100 Bauds */
/* 100 -> 10 Bauds */
/* Example : #define CNST_DATA_TIME_TEMPO 1 /* 1000 Bauds */ */
/* WARNING : 0 works fine ! */
/******************************************************************************/
#define CNST_DATA_TIME_TEMPO 0
/*** CNST_BITN_LPTP_ALIM ******************************************************/
/* Purpose : Bit number of the Power line of the I2C Converter card */
/* Unit : Bit Number */
/* Range : [0-7] - LIMITED selection */
/* List : Depend of the conversion card plugged on the parallel data port */
/* Example : #define CNST_BITN_LPTP_ALIM 0 */
/******************************************************************************/
#define CNST_BITN_LPTP_ALIM 0
/*** CNST_BITN_LPTP_WSDA ******************************************************/
/* Purpose : Bit number of the SDA line on the write port */
/* Unit : Bit Number */
/* Range : [0-7] - LIMITED selection */
/* List : Depend of the conversion card plugged on the parallel data port */
/* Example : #define CNST_BITN_LPTP_WSDA 1 */
/******************************************************************************/
#define CNST_BITN_LPTP_WSDA 1
/*** CNST_BITN_LPTP_WSCL ******************************************************/
/* Purpose : Bit number of the SCL line on the write port */
/* Unit : Bit Number */
/* Range : [0-7] - LIMITED selection */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -