View previous topic :: View next topic |
Author |
Message |
ALPL
Joined: 29 Mar 2009 Posts: 30
|
|
Posted: Tue Mar 22, 2011 9:58 am |
|
|
you must enable the interrupts - I added this to the code |
|
|
stacey
Joined: 14 Jan 2011 Posts: 22 Location: MY
|
|
Posted: Tue Mar 22, 2011 10:10 am |
|
|
it cant work. I dont know why... |
|
|
stacey
Joined: 14 Jan 2011 Posts: 22 Location: MY
|
|
Posted: Tue Mar 22, 2011 10:11 am |
|
|
Ohh.. okie.. i go try agian.. |
|
|
stacey
Joined: 14 Jan 2011 Posts: 22 Location: MY
|
|
Posted: Tue Mar 22, 2011 10:16 am |
|
|
ya, its work!!! Thanks.. I am so happy right now.
Its a good beginning... But then more works to be comng up... I can create other function and try.. Thanks thanks
Really thanks so much. |
|
|
stacey
Joined: 14 Jan 2011 Posts: 22 Location: MY
|
|
Posted: Tue Mar 22, 2011 10:27 am |
|
|
hey, really thanks so much yea.. Tomorrow I gonna try the other way that is pic send signal to visual studio... Hopefully its work too..
I need the both way communication for my final year project..
thanks thanks thanks... |
|
|
ALPL
Joined: 29 Mar 2009 Posts: 30
|
|
Posted: Tue Mar 22, 2011 10:52 am |
|
|
just another tip: donĀ“t use any delays in the interrupt service routines - keep them as short as possible and do most of the work in the main-function |
|
|
stacey
Joined: 14 Jan 2011 Posts: 22 Location: MY
|
|
Posted: Wed Mar 23, 2011 7:29 am |
|
|
Can I know is that the reverse, to send data from PIC to Visual studio. We just use "putc" in the serial_isr function?
Quote: | #include <16F877A.h>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=20000000)
#use rs232 (baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
char rx;
#int_rda
void serial_isr()
{
rx=getch();
if (rx=='A')
{
output_high(PIN_C0);
putc('Y');
}
else
{
output_low(PIN_C0);
putch('N');
}
}
void main()
{
set_tris_c(0b10000000);
enable_interrupts(int_rda);
enable_interrupts(global);
while(1);
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19548
|
|
Posted: Wed Mar 23, 2011 8:12 am |
|
|
You use 'putc', _but preferably not in the receive ISR.
The ISR you have is for serial receive. It implies a character is waiting to be read. 'RDA', is 'Receive Data Available'.
You have two choices for sending:
1) Just send the data from your main. Your recieve ISR will still receive characters that arrive while this happens.
2) Have a transmit ISR. Look at ex_stisr.c. This stores the characters in a RAM buffer, and only sends them when the transmit circuitry signals it can take another character.
Now, what you do with just _one_ character, should work. However if you send anything more than this, the chip will start waiting to send, and if this happens you risk losing characters that are arriving....
Best Wishes |
|
|
stacey
Joined: 14 Jan 2011 Posts: 22 Location: MY
|
|
Posted: Wed Mar 23, 2011 8:59 am |
|
|
Can I know how to change my code?
Mean something like below?
Code: |
#include <16F877A.h>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=20000000)
#use rs232 (baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
char rx;
#int_rda
void serial_isr()
{
rx=getch();
if (rx=='A')
{
output_high(PIN_C0);
}
else
{
output_low(PIN_C0);
}
}
void main()
{
set_tris_c(0b10000000);
enable_interrupts(int_rda);
enable_interrupts(global);
if (rx=='A')
putc('Y);
while(1);
}
|
Is it you mean that? |
|
|
ALPL
Joined: 29 Mar 2009 Posts: 30
|
|
Posted: Wed Mar 23, 2011 10:36 am |
|
|
This will work for the beginning:
void main()
{
set_tris_c(0b10000000);
enable_interrupts(int_rda);
enable_interrupts(global);
while(1)
{
if (rx=='A')
{
putc('Y);
rx=0;
}
}
} |
|
|
|