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.

Interrupt Problem 16f877a

Status
Not open for further replies.

Zwilorg

Member level 5
Joined
Oct 13, 2010
Messages
89
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Activity points
1,906
Hello all,

I am having a problem although my programs works in Proteus it will not work on my breadboard

the config i believe are OK because i can make a led blink without any problem.

I am trying to read double byte data from a max6675.

pic2.png


i think that the problem is on the routine init_spi() but i am not sure

i have left SSPCON and SSPSTAT as 0 because i tryed many ways and couldnt get it to work, i think that it maybe be something about WCOL or SSPOV

Code:
#include <stdio.h>
#include <htc.h>
#include <pic.h>
#include "lcd.h"
#include "usart.h"
#ifndef _XTAL_FREQ
 #define _XTAL_FREQ 4000000
#endif


#define SPI_CLOCK RC3			//  Define the Max6675 pins
#define SPI_CS RC5				
#define SPI_DATA RC4
#define SPI_SS RA5



void display_value1(short long value);




/**************************
MAX6675
***************************/


short long GetTemp(void){
unsigned char address;
int highbyte=0;
int lowbyte=0;
int lowbyte1=0;
int value=0;
int dummy=0;


RC5=0;

__delay_ms(220);

SSPBUF=0X03;
while(!BF){};
dummy=SSPBUF;
SSPBUF=address<<8;
while(!BF){};
lowbyte=SSPBUF;
SSPBUF=address;
while(!BF){};
highbyte=SSPBUF;

dummy=(lowbyte<<5|highbyte>>3);
RC5=1;

return dummy;
}

void init_spi(void){

	TRISC5=0;	// SDO
	TRISC4=1;	// SDI
	TRISC3=0;	// SCK


	SSPSTAT=0b00000000;
    SSPCON= 0b00000000;
                  
	CKE=0;
	CKP=0;
	SMP=0;
	SSPEN=1;
             
	SPI_CS=0;
	SPI_CS=1;

SSPIF=0;

}
void System_init(void){
TRISB = 0b00000000;	//set B1-B7 as output, B0 as input
PORTB=0;
}

void main(void)
{

int CurrentTemp = 0.0;
int CurrentTemp1=0.0;

System_init();
init_spi();

SSPIF	= 0;	// Synchronous Serial Port Interrupt Flag bit

	init_comms();
	INTCON=0;					// purpose of disabling the interrupts.
	lcd_init();					// Calling lcd_init defined in lcd.h
	lcd_goto(0);				// select first line in LCD
	lcd_puts("Encoder:");		// display text in first line
	lcd_goto(0x40);				// Select second line
	lcd_puts("Tempera: ");		// display text in second line

	
	while(1)
{

CurrentTemp = GetTemp();
CurrentTemp2=CurrentTemp *0.25;

		lcd_goto(0x48);	// Select second line
		display_value1(CurrentTemp);
		lcd_putch('C');
		lcd_goto(0x08);	
		display_value1(CurrentTemp1);
		lcd_putch('m');
__delay_ms(5);

RB0=0;
__delay_ms(10);
RB0=1;
printf("U\n%04d%%%04d\nQ", CurrentTemp2,CurrentTemp);
__delay_ms(400);


}					//end of while(1)
}				//end of void(main)


Hope some can help me, i have been all day banging my head on this problem...

Thank you

Best regards,
Zwi
 

If i take out the

Code:
while(!bf){}

everything on the rest of the program works properly, but i can't read from SPI...

Dunno what is wrong with it, i read all the datasheets and it seems it is proper
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top