Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC integrated with a MAXQ3180

Status
Not open for further replies.

Ram Prasadh

Member level 2
Member level 2
Joined
Feb 16, 2011
Messages
51
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
1,725
Hi

I am Presently Interfacing a PIC16F72 with MAXQ3180.Before doing that I am now checking spi between two Pic16f72. I have not Yet connected two PICs . I don have an other. Have to buy. I Have written a code for master operation of 1 pic. I have initiated a timer and by having a count from that , I am sending that count to the slave. I will attach my code here. Please have a look . Might be I would have left out some needed lines in the program. It would be nice if you can tell me if there are any changes or problems in the code...



/*_ _ _ _ SPI MASTER-SLAVE COMMUNICATION_ _ _ _ */
/*_ _ _ _ MASTER COMMUNICATION_ _ _ _ */

#include<htc.h>
typedef unsigned int word;
word __at 0x2007 CONFIG = _HS_OSC & _WDT_OFF & _PWRTE_OFF & _CP_OFF & _BODEN_ON;
#define SS RA5
void spiconfigure();
void delay();
void send();
void timer0();


void main(void)
{
/*_ _ _ _ SPI SUPPORT CONFIGIRATION_ _ _ _*/
unsigned char count;
for(;;)
{
TRISA=0; //SETTING PORTA AS OUTPUT PINS
ADCON1=0b00000110; //SETTING PORT A AS DIGITAL
TRISC=0b00010000; //SDI IS INPUT,OTHERS ARE OUTPUT
spiconfigure();
delay();
send();
delay();
timer0();
delay();
}
}

void spiconfigure()
{
/*_ _ _ _ SPI CONFIGIRATION_ _ _ _*/

SSPSTAT=0b01000000; //DATA IS TRANSMITTED ON RISING EDGE OF CLOCK
SSPCON=0b00110001; //SPI MASTER MODE,Fosc/16
SS=0; //SLAVE SELECT IS ACTIVE LOW
delay();
}


void send()
{
/*_ _ _ _ SENDING THRO SSPBUF TO SLAVE_ _ _ _*/

SSPBUF=count;
while(BF==0);
WREG=SSPBUF;
SS=0;
delay();
}

void timer0()
{
/*TIMER FOR GENERATING A COUNT*/

T0CON=0x00;
TMR0H=0xFF;
TMR0L=0XFF;
T0CONbits.TMR0ON=1;
while(INTCONbits.TMR0IF==0);
T0CONbits.TMR0ON=0;
INTCONbits.TMR0IF=0;
count=++count;
delay();
}

void delay()
{

/*DELAY FUNCTION*/

unsigned char i,j;
for(i=0;i<255;i++)
for(j=0;j<255;j++);
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top