View previous topic :: View next topic |
Author |
Message |
filjoa
Joined: 04 May 2008 Posts: 260
|
serial port and 12F683 problem |
Posted: Fri May 14, 2010 10:36 am |
|
|
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
|
|
Posted: Fri May 14, 2010 12:39 pm |
|
|
How did you connect your PIC to ?terminal? |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Fri May 14, 2010 12:52 pm |
|
|
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
|
|
Posted: Sat May 15, 2010 5:54 am |
|
|
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
|
|
Posted: Mon May 17, 2010 10:03 am |
|
|
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
|
|
Posted: Mon May 17, 2010 11:35 am |
|
|
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
|
|
Posted: Mon May 17, 2010 11:40 am |
|
|
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: 19550
|
|
Posted: Mon May 17, 2010 3:08 pm |
|
|
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 |
|
|
|