![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
karimpain
Joined: 15 Feb 2012 Posts: 39 Location: italia
|
receive data from rs232 |
Posted: Wed Mar 07, 2012 11:14 am |
|
|
hello to all!
I wrote this code thanks to some topics here in this forum.
Code: |
#include <16F877a.H>
#Fuses HS,NOPROTECT,NOWDT,NOLVP
#use delay(clock = 20000000)
#use rs232(baud=2400, xmit=PIN_c6, rcv=PIN_c7, BITS =8, PARITY=n, stop=1)
#include <string.h>
char string[30];
char pass1[30];
char pass2[30];
char pass3[30];
char pass4[30];
char pass5[30];
char pass6[30];
char pass7[30];
char pass8[30];
char pass9[30];
void main()
{ set_tris_b(0x00);
set_tris_d(0x00);
output_b(0x00);
output_d(0x04);
delay_ms(10);
strcpy(pass1,"mike1");
strcpy(pass2,"mike2");
strcpy(pass3,"mike3");
strcpy(pass4,"mike4");
strcpy(pass5,"mike5");
strcpy(pass6,"mike6");
strcpy(pass7,"mike7");
strcpy(pass8,"mike8");
strcpy(pass9,"mike9");
while(true)
{
printf("Password: ");
string=get_string();
if(string(1)))
{
output_b(0x10);
}
if(!strcmp(string, pass2))
{
output_b(0x20);
}
if(!strcmp(string, pass3))
{
output_b(0x30);
}
if(!strcmp(string, pass4))
{
output_b(0x40);
}
if(!strcmp(string, pass5))
{
output_b(0x50);
}
if(!strcmp(string, pass6))
{
output_b(0x60);
}
if(!strcmp(string, pass7))
{
output_b(0x70);
}
if(!strcmp(string, pass8))
{
output_b(0x80);
}
if(!strcmp(string, pass9))
{
output_b(0x90);
}
}
}
|
I want to send a string from my pc to the pic... if for example the data is "mike1".. put high the pin b4...but i interfaced the pic with the serial port using matlab and isis proteus.. when i used the virtual terminal to send data i have to press enter to activate this pin .but using matlab doesn't work.
Can anyone help me how i resolve this problem.!??!?
+++++++++++++++++++++
5-6 chat posts removed.
Reason: It's a support forum not a chat forum.
Stay on Topic !
- Forum Moderator
+++++++++++++++++++++ |
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Wed Mar 07, 2012 2:32 pm |
|
|
1- add "ERRORS to your #USE RS232 directive
2-consider instead a single 2 dim array
CHAR PASS [30][8]
3-get REAL!!
proteus is a buggy buggy thing - i am only able to answer questions about actual HARDWARE running on a PHYSICAL PIC -simulations mean nothing to this fellow - and you should NOT trust Proteus!!! |
|
![](templates/subSilver/images/spacer.gif) |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
Forget Proteus |
Posted: Wed Mar 07, 2012 2:37 pm |
|
|
Nobody here is going to debug Proteus or other simulator problems for you.
They're so full of bugs as to be worth a candle.
Work with real hardware, follow the CCS forum guide and we WILL try to help.
Otherwise your wasting your time and ours.
Mike |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Mar 07, 2012 3:29 pm |
|
|
I'm not a fan of Proteus either but what I consider worse is that the program as posted doesn't compile!
The function get_string can't be found, most likely he is using the one from <input.c>, but that I'm not sure of because the parameters don't match.
Code: | string=get_string(); | This code construction suggests that get_string returns a pointer to a string. If true, then it makes no sense to declare string as an array of 30 characters. The pointer to the allocated 30 characters will be overwritten as soon as this line is executed.
This is invalid C code as well.
With bugs like this I'm sure we are not seeing the same code as being tested with. A waste of our time. |
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Wed Mar 07, 2012 3:34 pm |
|
|
with or without proteus - i think you need to go review the RULES for how
get_string() works and WHERE it works ;-))
you see i can't make it compile at ALL under CCS.
were you thinking of the function in INPUT.C perhaps ???
take a close look and see if you don't see a problem ( or 2)
with what you coded .
and be sure it actually COMPILES before complaining - ok ?? |
|
![](templates/subSilver/images/spacer.gif) |
karimpain
Joined: 15 Feb 2012 Posts: 39 Location: italia
|
|
Posted: Wed Mar 07, 2012 4:36 pm |
|
|
Thanks guys. I know that Proteus is lot of bugs, but I talked to it just to make a clear vision of my problem. And I've done mistakes in the code because I posted the wrong one. Because instead of get_string() there is gets(string) // Here I don't need <input.c>
and the first if // if(!strcmp(string, pass1))
...etc.
I've done the circuit hardware and do well when I send one character, everything goes perfectly thanks to your help in an old post. Now I am facing this problem to send more than one character.
Thanks for reading and sorry for errors. |
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Wed Mar 07, 2012 4:46 pm |
|
|
post the code you have to that compiles
to get more help |
|
![](templates/subSilver/images/spacer.gif) |
karimpain
Joined: 15 Feb 2012 Posts: 39 Location: italia
|
|
Posted: Wed Mar 07, 2012 4:52 pm |
|
|
Code: | #include <16F877a.H>
#Fuses HS,NOPROTECT,NOWDT,NOLVP
#use delay(clock = 20000000)
#use rs232(baud=2400, xmit=PIN_c6, rcv=PIN_c7, BITS =8, PARITY=n, stop=1,errors)
#include <string.h>
#include <input.c>
char string[30];
char pass1[30];
char pass2[30];
char pass3[30];
char pass4[30];
char pass5[30];
char pass6[30];
char pass7[30];
char pass8[30];
char pass9[30];
void main()
{
set_tris_b(0x00);
set_tris_d(0x00);
output_b(0x00);
output_d(0x04);
delay_ms(10);
strcpy(pass1,"mike1");
strcpy(pass2,"mike2");
strcpy(pass3,"mike3");
strcpy(pass4,"mike4");
strcpy(pass5,"mike5");
strcpy(pass6,"mike6");
strcpy(pass7,"mike7");
strcpy(pass8,"mike8");
strcpy(pass9,"mike9");
while(true)
{
printf("Password: ");
gets(string) ;
if(!strcmp(string, pass1))
{
output_b(0x10);
}
if(!strcmp(string, pass2))
{
output_b(0x20);
}
if(!strcmp(string, pass3))
{
output_b(0x30);
}
if(!strcmp(string, pass4))
{
output_b(0x40);
}
if(!strcmp(string, pass5))
{
output_b(0x50);
}
if(!strcmp(string, pass6))
{
output_b(0x60);
}
if(!strcmp(string, pass7))
{
output_b(0x70);
}
if(!strcmp(string, pass8))
{
output_b(0x80);
}
if(!strcmp(string, pass9))
{
output_b(0x90);
}
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Wed Mar 07, 2012 5:40 pm |
|
|
I'll take one item at a time:
First off- if there is no ascii 13 CR received,
the gets() call will hang the program.
Better to BUILD the string one character at a time using
KBHIT and single GETC() calls to add to your string, ignoring Linefeed ascii10 etc till the CR is found. Then instead of the CR - add and ascii Z , char 0 -to properly terminate your string and off you go to comparison land.
This takes more code but will NEVER hang waiting for a character or from bad baud rate etc. And allows you to do other things in your main "while" loop OTHER than stand on the UART - while hoping for that completed entry. |
|
![](templates/subSilver/images/spacer.gif) |
karimpain
Joined: 15 Feb 2012 Posts: 39 Location: italia
|
|
Posted: Fri Mar 09, 2012 11:49 am |
|
|
Thanks, i built string one character at time using getc() inside a for loop. and everything works . sending data from serial port to tws434 then rws434 to my pic. Thanks this is the working code:
Code: |
#include <16F877a.H>
#Fuses HS,NOPROTECT,NOWDT,NOLVP
#use delay(clock = 20000000)
#use rs232(baud=2400, xmit=PIN_c6, rcv=PIN_c7, BITS =8, PARITY=n, stop=1,errors)
#include <string.h>
#include <input.c>
int i;
char string[6];
char pass1[6];
char pass2[6];
char pass3[6];
char pass4[6];
char pass5[6];
char pass6[6];
char pass7[6];
char pass8[6];
char pass9[6];
void main()
{
set_tris_b(0x00);
set_tris_d(0x00);
output_b(0x00);
output_d(0x04);
delay_ms(10);
strcpy(pass1,"mike1");
strcpy(pass2,"mike2");
strcpy(pass3,"mike3");
strcpy(pass4,"mike4");
strcpy(pass5,"mike5");
strcpy(pass6,"mike6");
strcpy(pass7,"mike7");
strcpy(pass8,"mike8");
strcpy(pass9,"mike9");
while(true)
{ for(i=0;i<5;i++)
{
string[i]=getc();
}
if(!strcmp(string, pass1))
{
output_b(0x10);
}
if(!strcmp(string, pass2))
{
output_b(0x20);
}
if(!strcmp(string, pass3))
{
output_b(0x30);
}
if(!strcmp(string, pass4))
{
output_b(0x40);
}
if(!strcmp(string, pass5))
{
output_b(0x50);
}
if(!strcmp(string, pass6))
{
output_b(0x60);
}
if(!strcmp(string, pass7))
{
output_b(0x70);
}
if(!strcmp(string, pass8))
{
output_b(0x80);
}
if(!strcmp(string, pass9))
{
output_b(0x90);
}
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|