CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Problem with pic and serial port!

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
karimpain



Joined: 15 Feb 2012
Posts: 39
Location: italia

View user's profile Send private message AIM Address MSN Messenger ICQ Number

Problem with pic and serial port!
PostPosted: Mon Feb 20, 2012 3:35 pm     Reply with quote

Hello Everyone!
I want to receive characters from my serial port using matlab. I connect the tx of the serial port to my max232 and then to rx of my pic 16f877a.
Using Proteus I saw that if I send for example '1' after the max232 it becomes 'g'. But putting a not on the output of the max232 I obtain the '1'.
My code is :
Code:

#include <16f877a.h>
#Fuses HS,NOPROTECT,NOWDT,NOLVP
#use delay(Clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

void main()
{
int u;

set_tris_b(0x00);
set_tris_d(0x00);

output_b(0x00);
output_d(0x04);

while(1)
{
if (kbhit())
 {
  u=getch();
  if (u=='1')
    output_b(0x10);
  }
}
}

Do I have to put something else in my code ? Because it doesn't work. My Proteus simulation works good but I soldered everything without results. Even if my pic and max232 are working good.
Thanks for reading!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 20, 2012 3:52 pm     Reply with quote

Your program is too complicated. Try a more simple program that
sends back to the PC the same character that it receives:
Code:

#include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=8M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//============================
void main()
{
char c;

while(1)
  {
   c = getc();
   putc(c);
  }


 
temtronic



Joined: 01 Jul 2010
Posts: 9102
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Feb 20, 2012 3:53 pm     Reply with quote

first. Get RID of Proteus ! It is a very poor 'simulator', full of bugs, errors and faulty DRCs !!

second: Try the CCS examples in the Examples folder before you try your own code. In the FAQ they have detailed both a circuit and code that WORKS! ALSO be sure to add 'errors' to the USE RS232().. if using the hardware UART !

third: Be sure to setup MATLAB correctly.Try using Hyperterminal ,RealTerm, or another 'terminal ' program and be sure the PIC code works fine and that the PC side is correct. A simple 'loopback' will prove all is good.

fourth: If using a USB<-> RS232 'adapter' is is very, very important to check it out using a loopback test.Not ALL adapters will work properly.
karimpain



Joined: 15 Feb 2012
Posts: 39
Location: italia

View user's profile Send private message AIM Address MSN Messenger ICQ Number

PostPosted: Tue Feb 21, 2012 6:55 am     Reply with quote

Really, ook it 's not that great software simulation but do u have one better?!?!?
i downloaded the hyper terminal bt i can't send data my keyboard doesn't respond maybe cuz i ve win7!!!.. don't know!!!
i 'm going to use 'errors'..I'm going Crazy..cuz this is the first step of my project.
Thanks 4 responding Smile
dyeatman



Joined: 06 Sep 2003
Posts: 1912
Location: Norman, OK

View user's profile Send private message

PostPosted: Tue Feb 21, 2012 7:57 am     Reply with quote

Did you try PCMs program? If so, what happened?

Quote:
Your program is too complicated. Try a more simple program that
sends back to the PC the same character that it receives:

Code:
Code:
#include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=8M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//============================
void main()
{
char c;

while(1)
  {
   c = getc();
   putc(c);
  }

}
 

_________________
Google and Forum Search are some of your best tools!!!!
temtronic



Joined: 01 Jul 2010
Posts: 9102
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Feb 21, 2012 8:07 am     Reply with quote

After 30 years, I found there isn't ANY simulator that will work correctly.

Use real hardware in the real world.

I use Realterm in XP Pro,check and see if it'll work under 7.

Simple test is to connect pin 2 to 3 of the comport and see if KBD data is echoed onto the Screen.That will confirm the PC terminal program is working.

Then run PCM's program. Just be sure you've set comport options right(baudrate, no flowcontrol,etc.)
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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