My thanks goes to Richard for his help. But as a benefit to anybody else struggling with this, my corrections to my code are as follows:
I can confirm that CLKOUT configuration line was the largest issue, as this was blocking the output of the SDO1 therefore the signal to the SN74HC595 was not being sent.
I have taken Richard's advice to implement using the interrupt flag to check when the signal had been sent to the SN74HC595, though the my next step is to have this trigger as interrupt to control the latch while performing another routine.
Finally changed the clock edge bit such that the signal is sent on the correct edge of the clock signal for the serial data output so the data arrives at the SN74HC595 correctly.
This is my modified code based on my initial code:
Code:
#CONFIG
__config _CONFIG1, _CLKOUTEN_OFF
#ENDCONFIG
TxData var BYTE
define OSC 4
OSCCON = %01101010
HC_Data var PORTA.4 'SDO
HC_Clk var PORTC.0 'SCK
HC_latch var PORTA.2 'Digital output
LED_YELLOW var PORTA.1
LED_GREEN var PORTC.3
LED_RED var PORTA.0
SSP1IF VAR PIR1.3 'SPI interrupt flag
TRISA = 0 'all digital outputs
PORTA = 0 'make all pins low
ANSELA = 0
TRISC = %00000010 'all digital outputs except port 1
PORTC = 0 'make all pins low
ANSELC = 0
APFCON0 = %01000000 'set SPI pin alternative
SSP1STAT = %01000000
SSP1CON1 = %00100010
'prove LED function
LED_YEllow = 1
LED_Green = 1
LED_red = 1
pause 200
LED_YEllow = 0
LED_Green = 0
LED_red = 0
Main: 'set up sequence of signals for output
LED_Yellow = 1
TXDATA = %00000000
Gosub Send_Data
TxData = %10101010
Gosub Send_Data
TxData = %01010101
Gosub Send_Data
TXDATA = %00000000
Gosub Send_Data
TxData = %10000000
Gosub Send_Data
TxData = %01000000
Gosub Send_Data
TxData = %00100000
Gosub Send_Data
LED_Yellow = 0
LED_gREEN = 1
TxData = %00010000
Gosub Send_Data
TxData = %00001000
Gosub Send_Data
TxData = %00000100
Gosub Send_Data
TXDATA = %00000010
Gosub Send_Data
TXDATA = %00000001
Gosub Send_Data
TXDATA = %11111111
Gosub Send_Data
LED_GREEN = 0
goto main
end
Send_Data :
toggle LED_RED
SSP1IF = 0
SSP1BUF = TXDATA
while ! SSP1IF :wend ;WAIT TILL TX COMPLETES
HC_Latch=1
'could need a delay here on high processor speeds or no operation commands
HC_Latch=0
pause 500
return
Bookmarks