View previous topic :: View next topic |
Author |
Message |
IceMetal
Joined: 20 Nov 2008 Posts: 79 Location: white Plains, NY
|
Serial to SPI |
Posted: Thu Aug 19, 2010 12:10 pm |
|
|
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
|
|
Posted: Thu Aug 19, 2010 12:49 pm |
|
|
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
|
|
Posted: Thu Aug 19, 2010 1:25 pm |
|
|
Thank you so much , I have no idea where I put my brain this days, I feel so stupid |
|
|
IceMetal
Joined: 20 Nov 2008 Posts: 79 Location: white Plains, NY
|
|
Posted: Thu Aug 19, 2010 1:52 pm |
|
|
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
|
|
Posted: Fri Aug 20, 2010 5:24 am |
|
|
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! |
|
|
|