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

serial port and 12F683 problem

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



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

serial port and 12F683 problem
PostPosted: Fri May 14, 2010 10:36 am     Reply with quote

hi

I try connect an 12F683 with terminal but it don't work...
Code:

#include <12F683.h>
#fuses NOWDT,INTRC_IO, NOCPD, NOPROTECT, MCLR, NOPUT, BROWNOUT, IESO, FCMEN
#use delay(clock=4000000)
#use rs232 (baud=9600, xmit=PIN_A5, rcv=PIN_A3, parity=N, bits=8)

void main (void)
{

while (TRUE)
{
printf("UM\n\r");
output_high(PIN_A0);
delay_ms(1000);
printf("DOIS\n\r");
output_low(PIN_A0);
delay_ms(1000);
}
}

on PIN_A0 I have an LED and it flash fine, but on terminal don't write anything.

Someone have an idea?

best regards
bungee-



Joined: 27 Jun 2007
Posts: 206

View user's profile Send private message

PostPosted: Fri May 14, 2010 12:39 pm     Reply with quote

How did you connect your PIC to ?terminal?
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Fri May 14, 2010 12:52 pm     Reply with quote

I have an USB to serial cable, with PL2303 where I don't need use max232...

I this interface direct with others PICs to comunicate between PC and hardware.

stay all correct with my program?

best regards
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Sat May 15, 2010 5:54 am     Reply with quote

hi

to help some one with same problem this is my worked example:

Read from ADC port an value and print it on terminal..
Code:

#include <12F683.h>
#FUSES NOWDT, INTRC_IO, NOCPD, NOPROTECT, NOMCLR, PUT, NOBROWNOUT, NOIESO, NOFCMEN
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_A2,rcv=PIN_A3,bits=8)

void main()
{
   int16 AdValue;
 
   setup_adc_ports(sAN0|VSS_VDD);
   setup_adc(ADC_CLOCK_INTERNAL);
   
   
while(TRUE)
   {
         AdValue=read_adc();
         delay_us(50);
         printf("ADC: %3lu\r",AdValue);
         delay_ms(500);
   }
}
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Mon May 17, 2010 10:03 am     Reply with quote

Hi

today I try use function getc() and getch() with this PIC but it don't work, someone know why?

I only add on my main function this:
Code:

c = getc();
if (c=='m') printf ("key press...");

PS: this PIC don't have serial interrupts, correct?

best regards
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon May 17, 2010 11:35 am     Reply with quote

Quote:
PS: this PIC don't have serial interrupts, correct?
Even worse... this PIC does not have a serial port!!

The compiler generates a software emulation of a UART, very heavy on computing power and sensitive for timing variations. If you use interrupts you have to disable these during transmission/reception.
I don't know how the receive routine is implemented, but it is very well possible that at 4MHz you can not receive data at 9600 baud. Try a lower baudrate first.
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Mon May 17, 2010 11:40 am     Reply with quote

hi

To transmit data to windows terminal all work fine, but to receive it don't work...

Wwhen I add this two codes lines if it stop write on terminal, I think error stay on getc() function and not on baudrate.

best regards
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Mon May 17, 2010 3:08 pm     Reply with quote

First thing to do, is put a scope on the RX line, at the PIC, and verify that it does go low, when you send data from the PC.
On the software UART, the code _must_ be sitting waiting for the character to arrive. There are delays in your original code, and if a character arrives while the code is in one of these, it'll be missed. The getc code will sit and wait for the RX line to drop. When it does, it'll count off the bit times, reading the input at each bit, then exit. Unless the line drops, while the code is sitting in the getc, it'll hang here for ever.

Best Wishes
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