|
|
View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Aug 22, 2011 1:54 pm |
|
|
One immediate problem is that you don't have series resistors on your
LEDs. You should add a 470 ohm series resistor between each PIC pin
and each LED (4 resistors total). If you don't have the series resistors,
the current drain on the PIC pins will likely exceed the specification of
25 ma max per pin, and possibly the spec of 200 ma max for the i/o Ports.
I don't know what would happen, but it wouldn't be good.
The LED circuits should be changed to this:
Code: |
pin 470 ohms LED
B4 ---/\/\/\/------->|----
|
|
----- Ground
---
-
|
Also, since you're using the hardware UART, you need to add the ERRORS
parameter as shown below in bold:
Quote: |
#use rs232(baud=1200,rcv=PIN_B1, xmit=PIN_B2, ERRORS) |
Also, you still have several places in your program where you're doing
this, with the double-quotes:
Quote: |
else if(data == "D")
|
You're trying to compare an integer variable to a string. That's incorrect.
All places should be changed to use single quotes, like this:
Code: | else if(data == 'D')
|
Also, you're using pins B6 and B7 for your LEDs. Those pins are used by
the ICD Debugger/Programmer. They will probably interfere with
hardware debugging of your code, if you try to do that. You might want
to choose different PIC pins for those two LEDs.
Quote: |
output_high(PIN_B6);
output_high(PIN_B7);
output_low(PIN_B6);
output_low(PIN_B7);
|
|
|
|
nuno12345
Joined: 16 Jul 2008 Posts: 50
|
|
Posted: Tue Aug 23, 2011 1:06 am |
|
|
Remember at the beginning i had no LEDS but ok.. Since i hate using resistors ill remove all the LEDs and just printf something instead.
About the quotes I tryed to make different ways of comparing data since it was not working.
Ill try to add ERRORS parameter later, but this is just for debugging right? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Tue Aug 23, 2011 1:51 am |
|
|
No.
ERRORS, _must_ always be used with the hardware UART, unless you add your own code ro check for UART errors and clear them. If it is not used, and an error occurs, the UART _will_ be hung.
Best Wishes |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Aug 23, 2011 1:49 pm |
|
|
Quote: | Remember at the beginning i had no LEDS
|
Then remove all the LEDs from your board (the resistors are essential)
and remove all LED code from your program.
Remember I asked you for only 10 lines in main(). You posted much
more than that. If you can write code that shows the problem by only
testing for 'U', then do so. Strip the code down to the minimum.
Verify that it fails in hardware, and post it.
The shorter the code that you post, the easier it is for us to see the
problem (or to test it ourselves in hardware). |
|
|
nuno12345
Joined: 16 Jul 2008 Posts: 50
|
|
Posted: Tue Aug 23, 2011 2:53 pm |
|
|
OMG PCM it worked just with the simplest code.
Code: | #include <16F628A.h>
#fuses INTRC_IO, NOWDT, NOPUT, NOBROWNOUT, NOMCLR, NOLVP, NOPROTECT
#use delay (clock=4000000)
#use rs232(baud=1200,rcv=PIN_B1, xmit=PIN_B2, ERRORS)
void main()
{
char data;
delay_ms(1000);
while(True)
{
putc(data=getc());
if(data== 'U')
output_high(PIN_B0);
}
} |
Working, LED stays off until I send U chars.
I tried printf instead of turning the LED on but since I had no max the output was just junk.
Thank you all, you guys are definitely the best.
Cheers
Last edited by nuno12345 on Tue Aug 23, 2011 3:05 pm; edited 1 time in total |
|
|
nuno12345
Joined: 16 Jul 2008 Posts: 50
|
|
Posted: Tue Aug 23, 2011 3:04 pm |
|
|
OK since I like to simplify it all.
Code: | #include <16F628A.h>
#fuses INTRC_IO, NOWDT, NOPUT, NOBROWNOUT, NOMCLR, NOLVP, NOPROTECT
#use delay (clock=4000000)
#use rs232(baud=1200,rcv=PIN_B1, xmit=PIN_B2, ERRORS, INVERT, FORCE_SW)
void main()
{
char data;
delay_ms(1000);
while(1)
{
putc(data=getc());
if(data == 'U')
printf("Got U\n");
}
} |
No max required either on RF RX or from PIC to PC.
I tried to output_high PIN_B4 and it doesnt turn on only works on B0.
Strange with or without a max the only character I can compare is U tried replacing them in place both in TX and RX and it can only get U(0x55)?. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Sat Aug 27, 2011 3:21 pm |
|
|
You don't show current limiting resistors for the LEDs...hope you really have them as PICs can go 'funny' trying to run LEDs without them.
I also notice you have a MAX232 for the 'RF' interface so help yourself and use the leftover sections to put in a proper 'RS232' section to/from the PC. |
|
|
|
|
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
|