okayazu
Joined: 14 Feb 2011 Posts: 1
|
software uart with INT_RDA |
Posted: Mon Feb 14, 2011 11:28 am |
|
|
Hello!
I need to use uart 2 port so I will use software uart (I use 16F877A).
If xmit=PIN_C6, rcv=PIN_C7, this code can use
but when I use like this, it can't receive string so I want to ask everybody.
What can I do? and How to write the code?
Please give some example to me.
Thank you so much.
Code: |
#include <16F877A.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C4, rcv=PIN_C5, stream=COM)
#define relay_door PIN_B0
#define magnetic_elec PIN_B1
char close_e[5];
char open_e[5];
char order_e[5];
BOOLEAN rx_int = FALSE;
#INT_RDA
void RS232_isr(void)
{
gets(order_e);
rx_int = TRUE;
}
void main(char order_e)
{
int v;
int w;
set_tris_b(0x00);
set_tris_a(0x00);
output_b(0x00);
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
strcpy(close_e,"0100");
strcpy(open_e,"01FF");
printf("\r\n Hello");
while(TRUE)
{
printf("\r\n MOVE to WHILE TRUE");
printf("\r\n ENTERED ORDER is \"%s\"",order_e);
while(!rx_int)
{
output_toggle(PIN_A0);
delay_ms(1000);
}
if(rx_int) // True or False not 1 or 0
{
printf("\r\n RX_INT TRUE");
v = strcmp(order_e,open_e);
printf("\r\n V is %d",v);
if (v == 0)
{
printf("\r\n ENTERED ORDERE is \"%s\"",order_e);
output_high(PIN_B0);
}
else if(v != 0 )
{
w = strcmp(order_e,close_e);
printf("\r\n W is %d",w);
if (w == 0)
{
printf("\r\n ENTERED ORDERE is \"%s\"",order_e);
output_high(PIN_B1);
}
else
{
printf("\r\n read command or file name");
printf("\r\n ENTERED ORDERE is \"%s\"",order_e);
}
}
}
else
{
printf("\r\n End Process");
}
rx_int = FALSE;
}
}
|
|
|