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;
}
} |
|