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

PIC RS232 Routine "stops" after first loop.

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



Joined: 06 Sep 2006
Posts: 12

View user's profile Send private message

PIC RS232 Routine "stops" after first loop.
PostPosted: Wed Sep 24, 2008 12:29 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Sep 24, 2008 12:33 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Sep 24, 2008 12:44 pm     Reply with quote

Geeez, thanks!

Totally missed that.

Thanks again!
Steve
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Sep 24, 2008 12:45 pm     Reply with quote

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