![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
aydi
Joined: 11 Aug 2010 Posts: 12
|
PB with gets() PICC port RS232 |
Posted: Wed Aug 11, 2010 1:34 am |
|
|
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](images/smiles/icon_smile.gif) |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Aug 11, 2010 1:46 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|