|
|
View previous topic :: View next topic |
Author |
Message |
mhjami Guest
|
PIC16F876 USART: Please Help |
Posted: Thu Feb 15, 2007 2:04 pm |
|
|
Hi all,
i am using a low power digital radio (ER400TRS) to send some character from PC to PIC. PIC will then decode the data and control peripheral devices. a small c program is running on computer which sends ASCII characters of key 2,4,6,8. the wireless link works fine and i can see decimal ASCII value 50 when i press key 2 from remote computer. now i have connected a PIC16F876 with the receiver end. an led is connected with pin c0 and c1. i have implemented a test program for pic which will receive this ascii value and turn led on if any key being press from remote computer. i have followed the example program to buffer the data and interrupt service. codes are as follows
# include <16F876.h>
# use delay (clock=4000000) // 4Mhz clock
# fuses XT,NOWDT, NOPROTECT, NOPUT, NOBROWNOUT
# use rs232(baud=9600, rcv=PIN_C7, parity=N, BITS=8, ERRORS) // initalizing usart
// for Buffer configaration
# define B_SIZE 32
int8 BUFFER[B_SIZE];
int8 B_IN = 0;
int8 B_OUT = 0;
# define out_pin PIN_C0
// Inturrept routine for receiveing serial data
#int_rda
int8 serial_isr()
{ // start of routine
int8 temp;
BUFFER [B_IN]=getc();
temp=B_IN;
B_IN=(B_IN+1)% B_SIZE;
if (B_IN==B_OUT)
B_IN=temp;
} // end of routine
#define BCOND (B_IN!=B_OUT)
int8 serial_data()
{ //start of serial_data
int8 temp_data;
while (!BCOND)
temp_data=BUFFER[B_OUT];
B_OUT=(B_OUT+1)% B_SIZE;
return (temp_data);
} // end of serial data
// main program
void main ()
{ //start of main function
int8 data;
enable_interrupts(global); // Global interrupt
enable_interrupts(int_rda); // interrupt for serial data
data=serial_data();
switch (data){ // start of switch
case 50:
output_high(out_pin);
delay_ms(100);
output_low(out_pin);
break;
case 52:
output_high(out_pin);
delay_ms(100);
output_low(out_pin);
break;
case 54:
output_high(out_pin);
delay_ms(100);
output_low(out_pin);
break;
case 56:
output_high(out_pin);
delay_ms(100);
output_low(out_pin);
break;
default: output_high(PIN_C1);
delay_ms(100);
output_low(PIN_C1);
break;
} // end of switch
} // end of main
but nothing is happening on the pic. if i press computer key 2,4,6,8 no led becomes on. pls help me. where i made mistake. looking for any kind advice.
with regards
mhjami |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Feb 15, 2007 6:11 pm |
|
|
Code: | # use rs232(baud=9600, rcv=PIN_C7, parity=N, BITS=8, ERRORS) // initalizing usart | Also add the Tx pin definition on PIN_C6. I haven't tested it, but I guess when either the Tx or Rx pin is missing the CCS compiler will generate a software UART. A software UART can't generate interrupts and hence your code is not working. |
|
|
|
|
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
|