Increasing the number of software-SPI

General discussion on mikroC for dsPIC30/33 and PIC24.
Post Reply
Author
Message
oguzmısır
Posts: 1
Joined: 08 Feb 2014 19:40

Increasing the number of software-SPI

#1 Post by oguzmısır » 28 Jun 2014 18:02

HOW TO BE USED MORE THAN ONE programmatically. SOFTSPİ1, SOFTSPİ2 LIKE.

ONLY FOR 1 SINGLE ONE...

// DAC module connections
sbit Chip_Select at LATD0_bit;
sbit SoftSpi_CLK at LATD6_bit;
sbit SoftSpi_SDI at RD2_bit;
sbit SoftSpi_SDO at LATD3_bit;

sbit Chip_Select_Direction at TRISD0_bit;
sbit SoftSpi_CLK_Direction at TRISD6_bit;
sbit SoftSpi_SDI_Direction at TRISD2_bit;
sbit SoftSpi_SDO_Direction at TRISD3_bit;
// End DAC module connections

unsigned int value;

void InitMain() {
TRISB0_bit = 1; // Set RB0 pin as input
TRISB1_bit = 1; // Set RB1 pin as input
Chip_Select = 1; // Deselect DAC
Chip_Select_Direction = 0; // Set CS# pin as Output
Soft_SPI_Init(); // Initialize Soft_SPI
}

// DAC increments (0..4095) --> output voltage (0..Vref)
void DAC_Output(unsigned int valueDAC) {
char temp;

Chip_Select = 0; // Select DAC chip

// Send High Byte
temp = (valueDAC >> 8) & 0x0F; // Store valueDAC[11..8] to temp[3..0]
temp |= 0x30; // Define DAC setting, see MCP4921 datasheet
Soft_SPI_Write(temp); // Send high byte via Soft SPI

// Send Low Byte
temp = valueDAC; // Store valueDAC[7..0] to temp[7..0]
Soft_SPI_Write(temp); // Send low byte via Soft SPI

Chip_Select = 1; // Deselect DAC chip
}

void main() {

CHECON = 0x32;
AD1PCFG = 0xFFFF; // Configure AN pins as digital

InitMain(); // Perform main initialization

value = 2048; // When program starts, DAC gives
// the output in the mid-range

while (1) { // Endless loop

if ((RB0_bit) && (value < 4095)) { // If RB0 button is pressed
value++; // increment value
}
else {
if ((RB1_bit) && (value > 0)) { // If RB1 button is pressed
value--; // decrement value
}
}


DAC_Output(value); // Send value to DAC chip
Delay_ms(1); // Slow down key repeat pace
}
}

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Increasing the number of software-SPI

#2 Post by filip » 14 Aug 2014 13:12

Hi,

Please see the following post, it can be used as an idea :
http://www.mikroe.com/forum/viewtopic.php?f=88&t=49148

Regards,
Filip.

Post Reply

Return to “mikroC for dsPIC30/33 and PIC24 General”