View previous topic :: View next topic |
Author |
Message |
FOUFOU Guest
|
send a string with RS232 |
Posted: Tue May 12, 2009 5:10 pm |
|
|
Hello,
I want to send a string from my PC to my PIC16F877. I have just send one character and it works perfectly but I haven't any idea how to send a string composed of three characters.
Please if any one has an idea help me and thank you so much. |
|
|
f Guest
|
|
Posted: Wed May 13, 2009 3:09 am |
|
|
I tried this code and it is not working. Please advise me how to do Code: | #include <16F877.h>
#include <string.h>
#use delay(clock=4000000)
#fuses hs, noprotect, nowdt,nolvp
#include <stdlib.h>
#include <stdio.h>
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7)
#define STRING_SIZE 40
#define BUFFER_SIZE 32
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
#int_rda
void serial_received()
{
int t;
do{
buffer[next_in]=getc();
t=next_in;
next_in=(next_in+1) % BUFFER_SIZE;
}while(next_in<=3);
}
void main()
{
int duty;
output_low(PIN_B1);
enable_interrupts(INT_RDA); //interrupt fires when the receive data is available, RS232 ON
enable_interrupts(GLOBAL); //activation de sinterruption
setup_timer_2(T2_DIV_BY_1,255, 1); //génération du PWM
setup_ccp1(CCP_PWM);
main_program:
do
{
duty=atoi(buffer);
set_pwm1_duty(duty);
}while(TRUE);
goto main_program;
}
|
Please if any one see my mistake???!! |
|
|
bungee-
Joined: 27 Jun 2007 Posts: 206
|
|
Posted: Wed May 13, 2009 4:09 am |
|
|
Instead of sending your string to PWM directly try to echo back to the RS232 to see what you are receiving to the PIC.
|
|
|
faffou
Joined: 12 May 2009 Posts: 2
|
|
Posted: Wed May 13, 2009 2:40 pm |
|
|
Hi, sorry , do you mean that I transmit what I receive from the PC to the PC to verify? _________________ GOOD LUCK |
|
|
|