I don't think you have set the mssp port correctly and
PAUSEUS 10
SSP1BUF = TXDATA
PAUSEUS 10
is a dangerous way to wait for tx to complete before latching data
try this , it works perfectly for me
Code:
'****************************************************************
'* Name : SPI_74HC595.BAS *
'* Author : RICHARD *
'* Notice : *
'* : *
'* Date : 2/26/2018 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
#CONFIG
__config _CONFIG1, _FOSC_INTOSC & _CP_OFF & _WDTE_OFF & _PWRTE_ON & _MCLRE_ON & _CLKOUTEN_OFF
__config _CONFIG2, _PLLEN_OFF & _LVP_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 LATA.2 'Digital output
LED_RED var LATA.1
TRISA = %11101001
PORTA = 0 'make all pins low
ANSELA = 0
TRISC = %11111110 'digital output C.0
PORTC = 0 'make all pins low
ANSELC = 0
APFCON0 = %01000000 'set SPI pin alternative
SSP1CON1=$22
SSP1STAT=$40
pause 200 'prove LED function
LED_red = 1
pause 200
LED_red = 0
Main: 'set up sequence of signals for output
TxData = 0
Gosub Send_Data
TXDATA = 1
Gosub Send_Data
TxData = 2
Gosub Send_Data
TxData = 4
Gosub Send_Data
TxData = 15
Gosub Send_Data
goto main
end
Send_Data :
LED_RED=!LED_RED
pir1.3=0
SSP1BUF = TXDATA
while ! pir1.3 :wend ;WAIT TILL TX COMPLETES
HC_Latch=0 ;LATCH IN NEW DATA
;@ NOP ; IF NEEDED FOR HIGHER CLOCK SPEEDS
HC_Latch=1
pause 500
return
Bookmarks