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

USART on 16f876

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







USART on 16f876
PostPosted: Tue Dec 06, 2005 7:57 pm     Reply with quote

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;

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