CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

SPI 16F877A

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ph
Guest







SPI 16F877A
PostPosted: Thu Oct 20, 2005 1:59 pm     Reply with quote

Hello, I need some help. I need to write to SPI but when I do it nothing happens, the oscilloscope doesn�t show anything. I think I�m forgetting to put something in my code.


#include "D:\PF\CCS\CCS\PIC16F877A\projetofinal\main.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


void main() {
char ch[4]; // ch --> cont�m o n�mero
int8 j,total,i[96]; //i --> armazena a matriz com os valores para grava��o

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_4);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

i[0]=0;
j=0;
while(true)
{

gets(ch);

switch (ch[0])
{
case 'p':
{
gets(ch);
total=atoi(ch);

for (j=0;j<total;j++)
{
gets(ch);
i[j]=atoi(ch);
}

printf("Dados emitidos: %u\n ",total);

for (j=0;j<total;j++)
{
printf("PIC %u\n",i[j]);
}

for (j=0;j<total;j++)
{
spi_write(i[j]);
}

}
}
total=atoi(ch);
printf("Dados invalidos %u\n ",total);
}


}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 20, 2005 2:32 pm     Reply with quote

Try a very simple test program like the code below.
If your crystal or oscillator is running at a different frequency
than 4 MHz, then change the #use delay() statement.
Also, if your crystal is at a higher frequency than 4 MHz,
change the fuse from "XT" to "HS".

Then look at pins 18 and 24 (on the 40-pin DIP package)
and you should see SCLK and SDO pulses. It worked for
me with the PicDem2-Plus board, and PCM compiler vs. 3.236.
Code:

#include <16F877A.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)

//===============================
main(void)
{

setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_4);

while(1)
  {
   spi_write(0x55);
   delay_us(100);
  }

}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group