Mình có chương trình sau, nhưng cái này chỉ nhận chứ ko có truyền từ PIC sang COM. Cho mình hỏi là nếu mình muốn truyền thông tin từ PIC sang COM thì phải làm như thế nào . Cảm ơn mọi người :
#include <16f877A.h>
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NO DEBUG,NOCPD
#use delay (clock=4000000)
#use rs232 (baud=9600, xmit=pin_c6, rcv=pin_c7, parity=N, stop=1, bits=8)
char received;
char right = 0x01;
#int_rda
void serial_interrupt()
{
disable_interrupts(int_rda);
received = getc();
if(received == right)
{
output_high(pin_c5); //green led
delay_ms(200);
output_low(pin_c5);
}
else
{
output_high(pin_c4); //red led
delay_ms(200);
output_low(pin_c4);
}
}
void main()
{
setup_psp(PSP_DISABLED);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_CCP1(CCP_OFF);
setup_CCP2(CCP_OFF);
output_low(pin_c4);
output_low(pin_c5);
enable_interrupts(GLOBAL);
while(1)
{
enable_interrupts(int_rda);
}
}
#include <16f877A.h>
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NO DEBUG,NOCPD
#use delay (clock=4000000)
#use rs232 (baud=9600, xmit=pin_c6, rcv=pin_c7, parity=N, stop=1, bits=8)
char received;
char right = 0x01;
#int_rda
void serial_interrupt()
{
disable_interrupts(int_rda);
received = getc();
if(received == right)
{
output_high(pin_c5); //green led
delay_ms(200);
output_low(pin_c5);
}
else
{
output_high(pin_c4); //red led
delay_ms(200);
output_low(pin_c4);
}
}
void main()
{
setup_psp(PSP_DISABLED);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_CCP1(CCP_OFF);
setup_CCP2(CCP_OFF);
output_low(pin_c4);
output_low(pin_c5);
enable_interrupts(GLOBAL);
while(1)
{
enable_interrupts(int_rda);
}
}