Kieth the syntax you are using will not work. PCF8574Port is not register ( like porta.0) but a Constant ( like 0X7A ). So, you are trying to SET a CONSTANT to ON with a parameter of ( LED1).
Try adding this to give you something similar. You still need IC2 setup but you could use the following syntax by adding the new subroutine. Note you need the comma between the state and the LEDn, and, you + LEDs together to change the state.
Thank you so much. That WORKS !! Really long winded but hey, so what it works. Never in a month of Easter Sundays would I have come up with that.
One more thing. On the datasheet it looks like the device can be configured in different modes, you mention that above in "So, we have to tell the PCF8574 the configuration that you require - for that you use PCF8574_sendbyte( in PCF8574_device, in PCF8574_data ) where PCF8574_device is the device and PCF8574_data is the state you will be setting the output of the PCF8574 to either high or low"
I take it that "to either high or low" to be 0 or 1 but even with that, I cannot get that to work.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You needs to read the PCF8574. The following expands the concept to return the state of switches attached the PCF8574.
In this demo I have assumed something like it the following. Where the LEDs and SWs are number LED0..LED7 and the switches SW0..SW7. So, you can check the state of many SWs at the same time. And, you should be able to read the bit value of a specific chip.
I am not testing this here... you are. So, hopefully this new code works.
Replace the previous post entirely to make sure you get all the changes.
I have another annoying problem that I cannot resolve. A single instruction
PCF8574Port Off, LED0 (the logic is inverted)
Turns on the port 0 but then it begins to oscillate at almost 1 second. I have double checked that there is nothing else in the routine to make it turn on or off.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It doesn't do what I thought it would do change the output polarity, but instead all it does is to interfere with the port 1 output.
I'm beginning to get the feeling that this device is not going to do what I'm expecting it to do. I have stripped the program down to the bare minimum to where I thought I had established what was causing the On/ Off cycling. The stripped program is below:
Initially all four ports are turned on which extinguishes the four LED's and if you omit the 100ms wait statement it gives you the impression that LED 0 is on solid - success !!
but with the wait statement or in fact any other programming code causes LED 0 to flash on and off without being told to turn off anywhere in the routine.
I am minded to change tack and either use a 3 to 8 line decoder, start back at the beginning with another board reconfigured to give me 8 I/O ports or as a last resort cross over onto the Dark Side with an Arduino.
;;;;SpindleMotorCoolantTemperatureController.;;;;ProjectDate19:5929.01.2023#chip 16F18326, 32#option NoConfig#include<DS18B20.h>#include<I2CEEPROM.h>#INCLUDE <PCF8574.H>#include<Encoder.h>#option explicit#startup InitPPS, 85#define PPSToolPart 16lf18326'SDA1>RC1(bi-directional);-----DefineHardwaresettings'DefineI2Csettings-CHANGEPORTSifrequired#define HI2C_BAUD_RATE 400#define HI2C_DATA PORTC.1#define HI2C_CLOCK PORTC.0#define DQ PortC.2;----Encoder#define ENCODER_A PortA.4 ;sometimes called CLK#define ENCODER_B PortA.5 ;sometimes called DT#define ENCODER_SW PortC.5 ;the central switch;#define Pump PORTC.3#define Fan PORTC.4;-----Define24LC256or24LC512EEProm#define eepDev 0xA0 'Change this ADDRESS to suit#define EEpromPageSize 32 'Change this typical 16, 32, 64, or 128.'16F18326'-------'VDD-|114|-Vss'RA5-|213|-RA0-DAT'AN4INRA4-|312|-RA1-CLK'MCLRRA3-|411|-RA2'RC5-|510|-RC0-I2CCLK'modeButRC4-|69|-RC1-I2CDAT'setButRC3-|78|-RC2'-------#DEFINE USART_BAUD_RATE 19200#DEFINE USART_TX_BLOCKING;-----Define24LC256or24LC512EEProm;#defineeepDev0xA0'ChangethisADDRESStosuit;#defineEEpromPageSize32'Changethistypical16,32,64,or128.#define EEpromPageSize 32 'Change this typical 16, 32, 64, or 128.'InitialiseI2CMaster'I2CpinsneedtobeinputforSSPmoduleDirHI2C_DATAInDirHI2C_CLOCKIn'MASTERSecondPortHI2CModeMaster'''SetupLCD'''SetLCD_10to10fortheYwRobotLCD1602IICV1ortheSainsmartLCD_PICI2Cadapter'''SetLCD_10to12fortheYwmjkdzI2Cadapterwithpotbentovertopofchip#DEFINE LCD_IO 10'YoumayneedtouseSLOWorMEDIUMifyourLCDisaslowerdevice.#DEFINE LCD_SPEED FAST'Youmayneedtoinvertthesestates.DependentofLCDI2Cadapter.#DEFINE LCD_Backlight_On_State 1#DEFINE LCD_Backlight_Off_State 0#define LCD_I2C_Address_1 0x7E#DEFINE PCF8574_DEVICE_1 0X7ADimDSDATA,asByteDimTempC_100aswordDimWHOLE,FRACT,DIGasByteDimLEDStatusasByteDimPortStatusasByteDimTempasByteDimTargetTasByteDimTempTasByte;DimPumpasBytedimvalueasWordDimTargetasByteDimWhole_NumberasWordDimDecimal_ValueasByteDimledstatus,portstatusasByteInitialise'SPLASHSCREEN1CLSLocate0,3Print"SPINDLE MOTOR"Locate1,6Print"COOLING"Locate2,5Print"CONTROLLER"Locate3,2PrintChipNameStrLocate3,11Print"@"Locate3,13PrintChipMhzLocate3,15Print"Mhz"wait3SCLSMain:;-----startmainDeg_Symbol;CallDegreeSymbolRoutine//Locate 2,5//Print valueDo;HSerPrint"Send to PCF8574 0x";HserPrinthex(ledstatus);HSerSend9//! send a variable to the I2C device that sets the device ports// PCF8574_sendbyte(PCF8574_DEVICE_1, ledstatus )// PCF8574_sendbyte(PCF8574_DEVICE_1, 0 );PCF8574PortOff,LED0wait100msPCF8574PortOff,LED0LoopgotoMain;-----endmainSubEPReadWord(INEEAddress,OUTepWordVarasWord)EPREAD(EEAddress,epWordVar)EPREAD(EEAddress+1),epWordVar_HEndsubSubPCF8574Port(__state,__port)Dim__portstatusasByte//! read the status of the port into the variable __portstatusPCF8574_readbyte(PCF8574_DEVICE_1,__portstatus)#DEFINE LED0 1#DEFINE LED1 2#DEFINE LED2 4#DEFINE LED3 8#DEFINE LED4 16#DEFINE LED5 32#DEFINE LED6 64#DEFINE LED7 128If__state=Onthen__portstatus=__portstatusOR__portelse__portstatus=__portstatusXOR__portendif//! send to the I2C device that sets the PCF8574 portsPCF8574_sendbyte(PCF8574_DEVICE_1,__portstatus)EndSubSubInitialise;Readdatafrom24LC256EEPromPCF8574PortOn,LED0+LED1+LED2+LED3EndSubSubInitPPSUNLOCKPPS'Module:EUSARTRA0PPS=0x0014'TX>RA0RXPPS=0x0001'RA1>RX'Module:MSSP1RC1PPS=0x0019'SDA1>RC1SSP1DATPPS=0x0011'RC1>SDA1(bi-directional)RC0PPS=0x0018'SCL1>RC0SSP1CLKPPS=0x0010'RC0>SCL1(bi-directional)EndSub
Initially all four ports are turned on which extinguishes the four LED's and if you omit the wait
Last edit: Keith 2023-04-10
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What is inside <Encoder.h> - an interrupt?
What is going on the I2C bus? Other devices chattering? Check with a scope.
How are the LEDs attached the PCF? Are you pulling to much current?
Is the 18f18326 chattering in the I2C lines when in the wait? Check with a scope.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Kieth the syntax you are using will not work. PCF8574Port is not register ( like porta.0) but a Constant ( like 0X7A ). So, you are trying to SET a CONSTANT to ON with a parameter of ( LED1).
Try adding this to give you something similar. You still need IC2 setup but you could use the following syntax by adding the new subroutine. Note you need the comma between the
state
and theLEDn
, and, you+
LEDs together to change the state.See if this works for you.
Example usage:
~~~
Sub PCF8574Port ( __state, __port )
End Sub
~~~
Thank you so much. That WORKS !! Really long winded but hey, so what it works. Never in a month of Easter Sundays would I have come up with that.
One more thing. On the datasheet it looks like the device can be configured in different modes, you mention that above in "So, we have to tell the PCF8574 the configuration that you require - for that you use PCF8574_sendbyte( in PCF8574_device, in PCF8574_data ) where PCF8574_device is the device and PCF8574_data is the state you will be setting the output of the PCF8574 to either high or low"
I take it that "to either high or low" to be 0 or 1 but even with that, I cannot get that to work.
You needs to read the PCF8574. The following expands the concept to return the state of switches attached the PCF8574.
In this demo I have assumed something like it the following. Where the LEDs and SWs are number LED0..LED7 and the switches SW0..SW7. So, you can check the state of many SWs at the same time. And, you should be able to read the bit value of a specific chip.
I am not testing this here... you are. So, hopefully this new code works.
Replace the previous post entirely to make sure you get all the changes.
Evan
I have another annoying problem that I cannot resolve. A single instruction
PCF8574Port Off, LED0 (the logic is inverted)
Turns on the port 0 but then it begins to oscillate at almost 1 second. I have double checked that there is nothing else in the routine to make it turn on or off.
Attach the program. Else, I would be guessing.
This is a video of what is presented with the current code. It should be on solid but instead it oscillates
Last edit: Keith 2023-04-09
What does this do? and, what is the value of
low
PCF8574_sendbyte(PCF8574_DEVICE_1, low )
It doesn't do what I thought it would do change the output polarity, but instead all it does is to interfere with the port 1 output.
I'm beginning to get the feeling that this device is not going to do what I'm expecting it to do. I have stripped the program down to the bare minimum to where I thought I had established what was causing the On/ Off cycling. The stripped program is below:
Initially all four ports are turned on which extinguishes the four LED's and if you omit the 100ms wait statement it gives you the impression that LED 0 is on solid - success !!
but with the wait statement or in fact any other programming code causes LED 0 to flash on and off without being told to turn off anywhere in the routine.
I am minded to change tack and either use a 3 to 8 line decoder, start back at the beginning with another board reconfigured to give me 8 I/O ports or as a last resort cross over onto the Dark Side with an Arduino.
Initially all four ports are turned on which extinguishes the four LED's and if you omit the wait
Last edit: Keith 2023-04-10
What is inside
<Encoder.h>
- an interrupt?What is going on the I2C bus? Other devices chattering? Check with a scope.
How are the LEDs attached the PCF? Are you pulling to much current?
Is the 18f18326 chattering in the I2C lines when in the wait? Check with a scope.