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

PB with gets() PICC port RS232

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



Joined: 11 Aug 2010
Posts: 12

View user's profile Send private message

PB with gets() PICC port RS232
PostPosted: Wed Aug 11, 2010 1:34 am     Reply with quote

Good morning,

I have a problem to use the port RS232 with pic.
I use ISIS to simulate my board and PICC compiler to develop my program. I just begin by reading the frame using RX, TX of the pic 18F2550.

This code is compiled but the simulation didn't work, means it just show me Password.

Could you please help me.

Thanks in advance.

Here below is the program:
Code:

#include <18F2550.h>
#include<stdio.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20M)
#use rs232(uart1,baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

void main()
{
   char string[30],password[30]="azerty";
   
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab

   // TODO: USER CODE!!
  //set_tris_B(0xff); 
 

while(1)
{
printf("Password: ");

gets(string);

if(strcmp(string, password))
   printf("OK");
else printf("NO");

}
 

}

Smile
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 11, 2010 1:46 pm     Reply with quote

Quote:
void main()
{
char string[30],password[30]="azerty";

setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);

The line in bold is wrong. It does not in fact disable the SPI. It enables
it, but it does so without the Slave Select option. This means the SDO
pin is set as an output. But that pin is used for the UART Rx on this PIC.
Therefore it's not going to work. Change the setup_spi() to use FALSE
as the parameter. Or better yet, just get rid of that line. It's not even needed.
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