View previous topic :: View next topic |
Author |
Message |
simoes.lc
Joined: 04 Mar 2007 Posts: 8
|
Problems with PIC16F767 |
Posted: Sun Mar 04, 2007 2:09 pm |
|
|
Hi, i�m just starting to work with PICs microcontrolers. I�m using the PIC16F767, but i�m having some problems that i dont undrestand. I'm trying to comunicate this PIC with a computer using the serial port. And doing this using the serial interruption. But the interruption just doesnt work.
What�s happening??? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Sun Mar 04, 2007 4:05 pm |
|
|
Quote: |
I'm trying to comunicate this PIC with a computer using the serial port.
And doing this using the serial interruption. But the interruption just doesnt work.
What�s happening???
|
How do you expect that we know what�s happening if we didn�t see a single line of code
nor any other info of your project.
Humberto |
|
|
simoes.lc
Joined: 04 Mar 2007 Posts: 8
|
|
Posted: Mon Mar 05, 2007 7:33 am |
|
|
Well, i alread tested this routine and dont receive any answer. I alread tested the max232, connecting the RX with the TX pins and its working normaly.
#include <16F767.h>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
void main()
{
char c;
while(1)
{
c = getc();
putc(c);
}
} |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 05, 2007 9:43 am |
|
|
Post your compiler version. |
|
|
simoes.lc
Joined: 04 Mar 2007 Posts: 8
|
|
Posted: Mon Mar 05, 2007 9:55 am |
|
|
version CCS 4.023 |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Mon Mar 05, 2007 9:59 am |
|
|
1)Does your circuit is alive?
2)If you are using a 4000000 Mhz crystal, #FUSES should be XT
Try this code:
Code: |
#define LED PIN_xx // !!! Select a pin to connect a LED
void main()
{
char c;
delay_ms(100); // Time to charge the capacitors in the MAX232
output_toggle(LED);
delay_ms(300); // The LED must toggle after power up !!!
output_toggle(LED);
printf("Test in progress...\r\n");
while(1)
{
c = getc();
putc(c);
output_toggle(LED);
delay_ms(200);
output_toggle(LED);
}
}
|
a) If the LED do not blink after power up, the PIC is not running at all.
b) If the LED blink once at power up but never blink after send a char, the program
is stuck in getc() waiting for a char that never come. You have a problem un Rx side.
c) If the LED blink after receive a char, but you doesn�t get any response,
you have a problem in Tx side.
Humberto |
|
|
simoes.lc
Joined: 04 Mar 2007 Posts: 8
|
|
Posted: Mon Mar 05, 2007 10:28 am |
|
|
Well I tryed to use the up code and nothing happend, but when I comment the line
Code: | printf("Test in progress...\r\n"); |
The program starts to work, waiting to the first character. When reaceive it, start to send it and dont stoping to wait the next character. |
|
|
simoes.lc
Joined: 04 Mar 2007 Posts: 8
|
|
Posted: Mon Mar 05, 2007 12:44 pm |
|
|
but this code work right
Code: |
#include <16F767.h>
#fuses XT,NOWDT,NOPROTECT
#use delay(clock=4000000)
#use rs232(baud=4800, xmit=PIN_C6, rcv=PIN_C7)
#use standard_io(B)
void main()
{
while(true)
{
output_high(PIN_B3);
delay_ms(500);
output_low(PIN_B3);
delay_ms(500);
putc('c');
}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 05, 2007 1:08 pm |
|
|
I compiled the code in post #4, and I don't see any problems in the
.LST file. Since transmit works ( putc('c') ), I think you may have
a hardware problem with the receive side. Look at the wire between
the PC's transmit pin and the receive pin on the MAX232. Make sure
the wire is connected to the correct pins. Also, the MAX232 has two
receiver sections in it. Make sure you are using the same receiver
section on the PC side and the PIC side of the MAX232. |
|
|
simoes.lc
Joined: 04 Mar 2007 Posts: 8
|
|
Posted: Mon Mar 05, 2007 1:57 pm |
|
|
I tried again the code in post #4, but now i changed the max232 that i was using. And I got the same for both. The microcontroller waits the first character, get it e then starts to send it by tx and don�t stop for wait the next characters. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 05, 2007 2:20 pm |
|
|
I don't have a 16F767, so I compiled the program in post #4 for
a 16F877A with compiler vs. 4.023. I tested it on a PicDem2-Plus
board. It works. I can type characters in a terminal window on
my PC, and the PIC echoes them back.
I then compiled the program for the 16F767 and compared the .LST
file with the 16F877A. They are very similar. There's just a little
difference in the setup of the ADCON1 register, but that's because
the 16F767 has slightly different settings.
So I think you have a hardware problem. Something is not connected
correctly. You may be missing one or more capacitors on the MAX232
chip. Or, a connection could be missing somewhere. I can't really do
any more on this. You have to check the hardware. |
|
|
simoes.lc
Joined: 04 Mar 2007 Posts: 8
|
|
Posted: Mon Mar 05, 2007 2:55 pm |
|
|
Well, to test this i make the following:
1. In the same breadboard a mount another microcontroller, the PIC16F628A.
2. Put almost the same code on it
3. Make it Run
And then it works perfet. Now I just don't know what to do.
Another thing that i didn't undrestand, looking at the same code for both PICs the size of then are very diferent, the size of the code for the 16f767 is bigger then the other one. Is it became the compiler is using software RS232? How can i force my compiler to use hardware RS232?
Thanks for the help given until now. |
|
|
|