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

Serial to SPI

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



Joined: 20 Nov 2008
Posts: 79
Location: white Plains, NY

View user's profile Send private message Yahoo Messenger

Serial to SPI
PostPosted: Thu Aug 19, 2010 12:10 pm     Reply with quote

Hi I have this code, but where the hex data is I want to make it a variable when I send serial data that will change, have anyone seen anything similar in the forum where I can look and find out how is done?
thank you


Code:

#include <16F887.h>       
#FUSES NOWDT               
#FUSES NOMCLR
#FUSES NOCPD
#FUSES NOBROWNOUT           
#FUSES XT

#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
/////////////////////////////////////////////////////////////////////////////////

#define SPI_MODE_0  (SPI_L_TO_H | SPI_XMIT_L_TO_H)


main(void)
{

setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_64);

while(1)
  {
   OUTPUT_LOW(PIN_D0);
   spi_write (0xff);          // How can I make this
   spi_write (0xff);       // seccion to be a variable
   spi_write (0xff);        // with the serial data?
   spi_write (0xff);      
   OUTPUT_HIGH(PIN_D0);
  }

pmuldoon



Joined: 26 Sep 2003
Posts: 218
Location: Northern Indiana

View user's profile Send private message

PostPosted: Thu Aug 19, 2010 12:49 pm     Reply with quote

maybe something like this?

Code:

main(void)
{
int beer;

setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_64);

while(1)
  {
   if(kbhit())
   {
       beer=getch();
   OUTPUT_LOW(PIN_D0);
   spi_write (beer);         
      OUTPUT_HIGH(PIN_D0);
  }




have you had any experience with C at all?
IceMetal



Joined: 20 Nov 2008
Posts: 79
Location: white Plains, NY

View user's profile Send private message Yahoo Messenger

PostPosted: Thu Aug 19, 2010 1:25 pm     Reply with quote

Thank you so much Smile , I have no idea where I put my brain this days, I feel so stupid Confused
IceMetal



Joined: 20 Nov 2008
Posts: 79
Location: white Plains, NY

View user's profile Send private message Yahoo Messenger

PostPosted: Thu Aug 19, 2010 1:52 pm     Reply with quote

one question pmuldoon, that will go to OUTPUT_HIGH(PIN_D0) after one character how can I make it so it will go after 4 characters?
pmuldoon



Joined: 26 Sep 2003
Posts: 218
Location: Northern Indiana

View user's profile Send private message

PostPosted: Fri Aug 20, 2010 5:24 am     Reply with quote

Here's one way:

Code:

#define BUD 0
#define BUDLITE 10
#define MILLER 2
#define MILLERLITE 8

main(void)
{
int beer[4];
 
beer[0] = MILLER;
beer[1] = BUDLITE;
beer[2] = MILLERLITE;
beer[3] = BUDLITE;

setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_64);

while(1)
{
       OUTPUT_LOW(PIN_D0);
       spi_write (beer[0]);         
       spi_write (beer[1]); 
       spi_write (beer[2]); 
       spi_write (beer[3]); 
      OUTPUT_HIGH(PIN_D0);
 




But you really shouldn't try to drive your output after four beers!
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