Das Open-Control-Projekt - Die Alternative zur C-Control-I


Das Forum zur C-Control-1
Welche C-Control-Varianten existieren?
Übersicht - Suchen - Neueste 50 Beiträge - Neuer Beitrag - Login - Registrieren
INFO - FAQ - CC2-Forum - CCPro-Forum 

 BYTES TO PCF8574 v1.2 for CCIMainU1.1 with CCISB Kategorie: C-Control I V1.1 (von Windt H.J. - 12.01.2005 13:57)
'----------------------------------------------------------------------------------------------------'
'***********************************************************************'
'*                         WINDT SYSTEMS                               *'
'*          BYTES TO PCF8574 v1.2 for CCIMainU1.1 with CCISB           *'
'*                           H.J. WINDT                                *'
'*                             2004                                    *'
'***********************************************************************'
'----------------------------------------------------------------------------------------------------'
'This program will demonstrate sending data to a PCF8574 using the I2C protocol.'
'pcf8574_i2c_address must contain the PCF8574 address/ &b0100(A2)(A1)(A0)0.'
'pcf8574_i2c_data must contain the byte to be sent.'
'The C-CONTROL Main Unit V1.1 is the master'
'Port 1 is the SDA line.'
'Port 2 is the SCL line.'
'Feel free to use and share this software!!'
'----------------------------------------------------------------------------------------------------'
'*************** INS and OUTS ***************'
define sda port[1]
define scl port[2]
'*******************************************'
'**************** VARIABLES ****************'
define i2c_byte byte[1]
define d7 bit[8]

define i2c_error bit[192]
define i2c_error_count byte[2]

define pcf8574_i2c_address byte[3]
define pcf8574_i2c_data byte[4]

define loop byte[23]

'*******************************************'
'**************** CONSTANTS ****************'

'*******************************************'
'****************** SETUP ******************'

'*******************************************'
'***************** PROGRAM *****************'
#start

print"Enter PCF8574 address (64/66/68/70/72/74/76/78)"
input pcf8574_i2c_address

print"Enter byte to be sent (0 to 255)"
input pcf8574_i2c_data

gosub send_data_via_i2c_to_pcf8574

goto start
'*******************************************'
'*************** SUBROUTINES ***************'
#send_data_via_i2c_to_pcf8574

#start_i2c
i2c_error = 0
sda = 0
scl = 0

i2c_byte = pcf8574_i2c_address 'Transmit address (pcf8574_i2c_address) over the I2C bus'
for loop = 1 to 8
sda = d7
gosub scl_pulse
i2c_byte = i2c_byte shl 1
next
gosub get_ack_i2c
if i2c_error then goto stop_i2c

i2c_byte = pcf8574_i2c_data 'Transmit byte (pcf8574_i2c_data) over the I2C bus'
for loop = 1 to 8
sda = d7
gosub scl_pulse
i2c_byte = i2c_byte shl 1
next
gosub get_ack_i2c

#stop_i2c
deact scl
deact sda

if i2c_error_count > 3 then goto no_ack_or_device
if i2c_error then goto send_data_via_i2c_to_pcf8574 'If I2C error then try again'

i2c_error_count = 0
return

#no_ack_or_device
print"No ACK from or no PCF8574 device on I2C address ";pcf8574_i2c_address
i2c_error_count = 0
return


#get_ack_i2c
deact sda
if sda then i2c_error = 1
if i2c_error then i2c_error_count = i2c_error_count + 1
#scl_pulse
deact scl
#clock_stretch
if scl = 0 then goto clock_stretch
deact scl
scl = 0
return

'*******************************************'
'****************** DATA *******************'

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



 Antwort schreiben

Bisherige Antworten: