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 support@ccsinfo.com

printf(""); problem

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



Joined: 01 Oct 2008
Posts: 1

View user's profile Send private message

printf(""); problem
PostPosted: Thu Oct 02, 2008 11:32 am     Reply with quote

Hi,
I have a problem with sending a msg through the RS-232. Here is the detail of my program:
1-When the PIC16F916 is powered on: the 2 LED (Passed and Failed) will flash 1 time
2-If the Switch is pressed and released: The 2 LEDs will flash 3 times, after that the msg "Hello!" will be displayed on the screen - And then the 2 LEDs will flash 2 other times and it will turn OFF

Problem:
After the 2 LEDs have flashed 3 times, then the line of code: "printf("Hello!");" should be executed but somehow this line of code is not executed, nothing is displayed and the program is stuck there.

I did put “#use delay(clock=4000000) and #use rs232(baud=9600, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8)" at the beginning of the program.

Any help will be appreciated, thanks

Here is my program:
Code:

#include <16F916.h>

#FUSES NOWDT
#FUSES INTRC_IO
#FUSES PUT
#FUSES NOPROTECT
#FUSES NOMCLR
#FUSES NOCPD
#FUSES BROWNOUT
#FUSES IESO
#FUSES FCMEN
#FUSES NODEBUG

#use delay(clock=4000000)

#define SetPortA 0x2F

#define SetPortB 0x82

#define poLED_Failed PIN_B5
#define poLED_Passed PIN_B6
#define piSwitch_In PIN_B7

#define SetPortC 0x98
#define poTx PIN_C6
#define piRx PIN_C7

#define SetPortE 0x08


#use fast_io(a)
#use fast_io(b)
#use fast_io(c)

#byte PORTA =0x05
#byte PORTB =0x06
#byte PORTC =0x07
#byte PORTE =0X09
#byte STATUS =0x03
#byte INTCON =0x0B
#byte ANSEL =0x91
#byte ADRESH =0x1E
#byte ADCON0 =0x1F
#byte ADRESL =0x9E
#byte ADCON1 =0x9F
#byte OPTION =0x81
#byte WPU =0x95
#byte TXSTA =0x98
#byte RCSTA =0x18
#byte SPBRG =0x99
#byte TRISE =0x89
#byte OSCCON =0x8F
#byte OSCTUNE =0x90

//=============================================
void main()
{
#use rs232(baud=9600, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8)
int i;

SETUP_TIMER_0(RTCC_INTERNAL|RTCC_DIV_1);
SETUP_TIMER_1(T1_DISABLED);
SETUP_TIMER_2(T2_DISABLED,0,1);
SETUP_COMPARATOR(NC_NC_NC_NC);
SETUP_VREF(FALSE);

SETUP_SPI(FALSE);
SETUP_LCD(LCD_DISABLED);

SET_TRIS_A(SetPortA);
SET_TRIS_B(SetPortB);
SET_TRIS_C(SetPortC);
TRISE = SetPortE;

RCSTA = 0x00;

//Clear PortA, PortB, PortC and PortE
PORTA = 0;
PORTB = 0;
PORTC = 0;
PORTE = 0;

delay_ms(100);
     for(;;)
     {

//-------------------------------------------------------------------
      output_High(poLED_Failed);
      output_High(poLED_Passed);
_Wait:
          while (input(piSwitch_In)); //---------If the Switch is not pressed, keep waiting
          delay_ms(100);
          if (input(piSwitch_In))
               goto _Wait;

_Test0:
          while (!input(piSwitch_In)); //---------If the Switch is pressed but not released, keep waiting

          if (input(piSwitch_In)) //---------If the Switch is released, start the test
         {
               delay_ms(100);
               if (input(piSwitch_In))
               {
                 goto _Test1;
               }
          }
          goto _Test0;
//------------------------------------------------------------------------

_Test1:

          for(i=0; i<5;i++)
          {
             output_Low(poLED_Passed);
             delay_ms(500);
             output_High(poLED_Passed);
             output_Low(poLED_Failed);
             delay_ms(500);
             output_High(poLED_Failed);

             if(i==2)
            {
               printf("Hello!");
            }

           }


      }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 02, 2008 9:26 pm     Reply with quote

You need to fix your code so it doesn't use "goto" statements. Most
people do not want to look at code that has goto statements. That's
probably why you have not received any replies so far.

Also, remove all unnecessary lines of code from your test program.
We don't want to look at all the #byte statements that are not used by
the program.
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