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

RS-232, data not sending, PIC 16f876a using MPLAB

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







RS-232, data not sending, PIC 16f876a using MPLAB
PostPosted: Thu Oct 27, 2005 7:52 am     Reply with quote

Hello friends,

I am a new user of PIC 16f876a. I successfully received data from PICDEM 2 Plus DEMO Board (16f876a) using MPLAB/ICD 2 to PC but i am not able to send data to the PC. Could anybody, please help me out in this situation.
Should be very much thankful.

Please find the code as below:

Best Regards,

Fahad Jani



#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, PARITY=E, BITS=8, stream=HOSTPC)

void main(void)
{
char answer;

DISABLE_INTERRUPTS(global);
SETUP_ADC_PORTS(NO_ANALOGS);
SETUP_COMPARATOR(NC_NC_NC_NC);
SETUP_ADC( ADC_OFF );

//Sending data from PIC to PC
printf("New Program\n\r");
printf("1010\n\r");

printf("Continue (Y,N)?\n\r");
do { answer=getchar(); //PROBLEMATIC AREA
}while(answer!='Y' && answer!='N'); // NOT EXECUTING...
printf("Your answer was %c\n\r", answer);
// using hyperterminal for the data sending/receiving

}
Ttelmah
Guest







PostPosted: Thu Oct 27, 2005 9:16 am     Reply with quote

Hint: You are using 'streams', and then not using 'streams'. The command to write to a stream, is fprintf(stream_name.....), not 'printf'. If you don't want to use streams, remove this from the RS232 declaration.

Best Wishes
valemike
Guest







PostPosted: Thu Oct 27, 2005 9:28 am     Reply with quote

Code:
#include <18F448.h>
#device ADC=10
#fuses HS,NOWDT,NOPROTECT,NOLVP,PUT
#use delay(clock=4000000)
#case

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#ignore_warnings 202

void main(void)
{
    char answer;

    //Sending data from PIC to PC
    printf("New Program\n\r");
    printf("1010\n\r");

    printf("Continue (Y,N)?\n\r");
    do
    {
        answer=getchar(); //PROBLEMATIC AREA
    } while(answer!='Y' && answer!='N'); // NOT EXECUTING...
    getchar();
    printf("Your answer was %c\n\r", answer);
// using hyperterminal for the data sending/receiving

}


I tried the program above on my PICDEM2 unit. I am using the ICD2 to debug it. It seems to work ONCE, and when I try running it again, then it doesn't work. It seems a character is getting stuck in stdin (?), which i 'flush' out with the extra getchar() statement. But even then it still gets stuck. If only there was a function to flush stdin.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 27, 2005 12:03 pm     Reply with quote

Quote:
I am not able to send data to the PC.

Try a simple program, as shown below.
Get rid of the Even Parity in your PIC program, and in Hyperterminal.
Also get rid of the streams. When you make a test program, keep it simple.
Code:

#include <18F448.h>   
#fuses XT,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

void main()
{
char c;

while(1)
 {
  c = getc();   // Wait for a char from the PC
  putc(c);       // Then send it back to the PC
 }

}
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