I feel completely retarded not being able to figure out what went wrong. Here's the code, it's just meant to send a repeating pulse out of SDO by using the MSSP module in Master mode.
Code:
list p=16f876A
#include <p16f876a.inc>
main: BSF STATUS,RP0
MOVLW 0x07
MOVWF ADCON1
BCF TRISC,5
BCF TRISC,3
BSF TRISC,4
BSF SSPCON,5
BCF STATUS,RP0
ser: BTFSS SSPSTAT,BF
GOTO ser
MOVLW 0x66
MOVWF SSPBUF
GOTO ser
END
The first few lines make sure that all the ports on the device are digital (Lest I want to expand the code to somehow use PortA). I use the bit setting to set up the direction of the serial pins to what the datasheet says to use (Clear bit 5 and 3, set 4), and I set the SPI enable bit in SSPCON. (Switch back to Bank 0)
I check the SSPSTAT<BF> bit to check if the serial shift register is done outputting, goes back to wait for it if it's not ready, or puts 0x66 in to send if it is done. As far as the datasheet says, as soon as there is data in the SSPBUF, it's supposed to shift it out, but it just sits there with the pins high. I must've made an obvious mistake that someone can point out, right?
Hahah, now that you mention it, I maybe should've used BTFSC. I also noticed that I was trying to read from SSPSTAT in the wrong bank. I'll fix these and see what happens.
Hahah, now that you mention it, I maybe should've used BTFSC. I also noticed that I was trying to read from SSPSTAT in the wrong bank. I'll fix these and see what happens.
list p=16f876A
#include <p16f876a.inc>
main: BSF STATUS,RP0 ;Initializing stuff in Bank 1
MOVLW 0x07
MOVWF ADCON1
BCF TRISC,5
BCF TRISC,3
BSF TRISC,4
BSF SSPCON,5 ;Set the SSP Enable bit
BCF STATUS,RP0 ;Back to Bank 0
ser: CALL cond
BTFSC 0x20,0
GOTO ser
MOVLW 0x66
MOVWF SSPBUF
GOTO ser
cond: BSF STATUS,RP0
MOVF SSPSTAT,W
BCF STATUS,RP0
MOVWF 0x20
RETURN
END
This time I use the cond routine to go into Bank 1, copy the SSPSTAT register to W, go back to Bank 0, and put W into a general purpose register. I BTFSC the BF bit to see if it's not set, if it's all fine, it goes and writes into SSBUF. In the simulator I'm using, it actually gets to writing 0x66 to SSPBUF, but for some reason, the simulator doesn't/can't properly execute the BSF SSPCON,5 instruction. (Using Oshonsoft's PIC Simulator) In the space where it usually says the instruction, when I step through, the BSF SSPCON,5 instruction just appears as "BSF". Could just be a problem with the simulator now, I'll have to test the program on the real hardware when I get my ICD2.