|
|
View previous topic :: View next topic |
Author |
Message |
Max Lazarus Guest
|
USART on 16f876 |
Posted: Tue Dec 06, 2005 7:57 pm |
|
|
All I'm trying to do is get USART-received data to be output on the SPI. This code should display the contents of RCREG and the RCSTA register.
RCREG always equals zero, but the receive pin is obviously working, as when I use getch()s in the code I can use RS232 output from a computer and keyboard to trigger events. I am very frustrated with this, and have no clue why it is not working properly.
Here is the code, minus obvious #defines.
#if defined(__PCM__)
#include <16f876.h>
#device ICD=TRUE
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=4951200)
#use RS232(PARITY=N, BAUD=9600, BITS=8, XMIT=PIN_C6, RCV=PIN_C7)
#endif
#include <stdlib.h>
main() {
*setup, serial;
setup_spi(SPI_MASTER | SPI_CLK_DIV_64 | SPI_L_TO_H);
serial = 0;
setup = TRISC;
*setup = 0x80;
output_high(PIN_B2);
output_low(PIN_B1);
serial = 0;
setup = RCSTA;
*setup = 0x90;
while(TRUE)
{
setup = RCSTA;
serial = *setup;
spi_write(serial);
output_high(PIN_B0);
delay_ms(1);
output_low(PIN_B0);
delay_ms(1);
*setup = RCSTA;
*setup = 0x80;
*setup = 0x90;
getch();
setup = RCREG;
serial = *setup;
spi_write(serial);
output_high(PIN_B0);
delay_ms(1);
output_low(PIN_B0);
delay_ms(1);
setup = RCSTA;
*setup = 0x80;
*setup = 0x90;
}
} |
|
|
Max Lazarus Guest
|
Re: USART on 16f876 |
Posted: Tue Dec 06, 2005 7:59 pm |
|
|
Max Lazarus wrote: | *setup, serial;
|
Oops, this is actually
int *setup, serial;
Thanks. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Dec 06, 2005 9:22 pm |
|
|
Quote: | All I'm trying to do is get USART-received data to be output on the SPI |
Then keep everything as simple as possible. Try the following program
as a starting point. Also notice the NOLVP in the #fuses and the ERRORS
in the #use rs232(). Those are essential.
Code: | #include <16F876.H>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4951200)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//===============================
main(void)
{
char c;
setup_spi(SPI_MASTER | SPI_CLK_DIV_64 | SPI_L_TO_H);
while(1)
{
c = getc(); // Wait for a char from the UART
spi_write(c); // Then transmit it by SPI
}
} |
|
|
|
|
|
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
|