View previous topic :: View next topic |
Author |
Message |
Steve_Kos
Joined: 06 Sep 2006 Posts: 12
|
PIC RS232 Routine "stops" after first loop. |
Posted: Wed Sep 24, 2008 12:29 pm |
|
|
All,
I have been searching the forums for an answer to my simple
question, but nothing has worked yet. All want to do is read the
RS232 from Hyperterminal (1 character) using a PIC16F877A
(running on 4MHz) and save it and re-display it out the serial port.
Sounds easy, not sure why I can't get it to work. This code will work once and then stop working, any suggestions on getting this to work in a loop? Basic code is below:
Code: |
void main()
{
set_tris_a(0xFF); // Set PORTA to all INPUTS.
set_tris_b(0x00); // Set PORTB to all OUTPUTS.
set_tris_c(0x00); // Set PORTC to all OUTPUTS.
set_tris_d(0xFF); // Set PORTD to all INPUTS.
set_tris_e(0x00); // Set PORTE to all OUTPUTS.
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(AN0_AN1_AN3);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
output_b(0x00); // Set all port B I/O low.
do
{
rx_flag = kbhit();
if (rx_flag == 1)
{
data_in = getc();
if ((data_in == 'v') || (data_in =='V'))
{
printf("VEH\n\r");
delay_us(10);
}
if ((data_in == 'b') || (data_in =='B'))
{
printf("BATT\n\r");
delay_us(10);
}
if ((data_in == 's') || (data_in =='S'))
{
printf("SHUTDOWN\n\r");
delay_us(10);
}
}
}
while (test_loop == 1);
}
|
I checked to make sure the data is on the PIC lines.
Is it something simple or am I completely lost?
Thanks,
Steve |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Sep 24, 2008 12:33 pm |
|
|
Quote: | set_tris_a(0xFF); // Set PORTA to all INPUTS.
set_tris_b(0x00); // Set PORTB to all OUTPUTS.
set_tris_c(0x00); // Set PORTC to all OUTPUTS.
set_tris_d(0xFF); // Set PORTD to all INPUTS.
set_tris_e(0x00); // Set PORTE to all OUTPUTS. |
You're setting the incorrect TRIS for the hardware UART's receive pin
(pin C7). You have set it to an output. My advice:
Don't set the TRIS. With CCS, you don't need to. The default mode of
the compiler is "Standard i/o" mode. In that mode, the compiler
automatically inserts code to setup the correct TRIS for you, provided
that you use CCS built-in functions, and CCS library routines.
It's absolutely best for newbies to let the compiler handle the TRIS. |
|
|
Steve_Kos
Joined: 06 Sep 2006 Posts: 12
|
|
Posted: Wed Sep 24, 2008 12:44 pm |
|
|
Geeez, thanks!
Totally missed that.
Thanks again!
Steve |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed Sep 24, 2008 12:45 pm |
|
|
Where does test_loop come from? What is its type and value? Show us your includes and declarations including your use_rs232 statement. Also the PIC type and compiler version are sometimes relevant. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
|