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

Interface VB with PIC
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ALPL



Joined: 29 Mar 2009
Posts: 30

View user's profile Send private message

PostPosted: Tue Mar 22, 2011 9:58 am     Reply with quote

you must enable the interrupts - I added this to the code
stacey



Joined: 14 Jan 2011
Posts: 22
Location: MY

View user's profile Send private message

PostPosted: Tue Mar 22, 2011 10:10 am     Reply with quote

Sad it cant work. I dont know why...
stacey



Joined: 14 Jan 2011
Posts: 22
Location: MY

View user's profile Send private message

PostPosted: Tue Mar 22, 2011 10:11 am     Reply with quote

Ohh.. okie.. i go try agian..
stacey



Joined: 14 Jan 2011
Posts: 22
Location: MY

View user's profile Send private message

PostPosted: Tue Mar 22, 2011 10:16 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Mar 22, 2011 10:27 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Mar 22, 2011 10:52 am     Reply with quote

Wink

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

View user's profile Send private message

PostPosted: Wed Mar 23, 2011 7:29 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Mar 23, 2011 8:12 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Mar 23, 2011 8:59 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Mar 23, 2011 10:36 am     Reply with quote

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;
}

}

}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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