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 CCS Technical Support

12f629 RS232

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







12f629 RS232
PostPosted: Thu Mar 01, 2007 11:53 am     Reply with quote

Hi Guys. I have 2 days stuck trying to get RS232 comunication with the 12f629.

My compiler version is 5.00.2195.6601 and I'm using a MAX232.
I'm sure that the hardware is working because I'm also making a code for the 16f877 and It works fine with it. Both the terminal and the code are set to baud=2400, parity=N,bits=8,hardware. By the way, before using the 12f629 for the first time, I saved the OSCAL, I have compared it and has not changed.

I get the correct number of bytes but they are corrupted. exaple, the pic should send 0x42 but gets 0xE2

By the way, I downloaded a demo version of a competitors compiler and the RS232 worked, so that means it is not hardare. So it reduces the posibility to a code error or a compiler error. I cannot use the competitors compiler since I have all code of all the projects in the CCS compiler.

I will apreciate if anybody can take a look at the code. Maybe you will have an opportunity to tell me how stupid I'm Very Happy

Thanks in advance
Code:
#if defined(__PCM__)
#include <12f629.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,PUT,NOMCLR
#use delay(clock=4000000)
#use rs232(baud=9600, parity=N, xmit=PIN_A2, RCV=PIN_A3, bits=8,RESTART_WDT)


void main()
{
 
   int16 i;    
   int8 D;
   setup_comparator(NC_NC_NC_NC);
   

   //Blink a LED to be sure that the pic start
   output_high(PIN_A4);
   delay_ms(400);
   output_low(PIN_A4);
   delay_ms(400);
   output_high(PIN_A4);
   delay_ms(400);
   output_low(PIN_A4);
   delay_ms(400);
   output_high(PIN_A4);
   delay_ms(400);
   output_low(PIN_A4);
   delay_ms(400);
   printf("HELLO");
   putchar(0X42);
   while(1)    
   {
      if (kbhit() )   
      {      
         putchar(0X42);
         D = getchar(); // wait for command char       
         putchar(D);

         if ( D == 'b' )    
         {
            putchar(0X55); // return test values
            delay_ms(16);
            putchar(0XAA);
         }
         D=0;
      }
   }
}
Guest








PostPosted: Thu Mar 01, 2007 12:10 pm     Reply with quote

Quote:
Both the terminal and the code are set to baud=2400
Code:
#use rs232(baud=9600, parity=N, xmit=PIN_A2, RCV=PIN_A3, bits=8,RESTART_WDT)
gdl_pro1
Guest







PostPosted: Thu Mar 01, 2007 12:22 pm     Reply with quote

Ooops. Yes you are right. I have been working with seral options of bauds, parity, reverse, ect. to try to make it work. without any luck

Actual code (same as terminal).
Code:
#use rs232(baud=2400, parity=N, xmit=PIN_A2, RCV=PIN_A3, bits=8)
Guest








PostPosted: Thu Mar 01, 2007 12:27 pm     Reply with quote

You have the RESTART_WDT option enabled in the #use rs232 statement, but have the watchdog timer disabled with the NOWDT fuse. Try remvoing the RESTART_WDT option.
gdl_pro1
Guest







PostPosted: Thu Mar 01, 2007 12:32 pm     Reply with quote

By the way, the correct version of the compiler is "Version 3.107, 15848" The version that I posted before was from the help file.
gdl_pro1
Guest







PostPosted: Thu Mar 01, 2007 12:38 pm     Reply with quote

Thanks I removed it, same issue only trash in Terminal
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 01, 2007 2:11 pm     Reply with quote

Your version doesn't support the 12F629 very well. The CCS start-up
code is incorrect, and the code for the setup_comparator() function is
incorrect. Change the first part of your program so it looks like this,
and it may start working.
Code:

#include <12F629.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,PUT,NOMCLR
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_A2, RCV=PIN_A3)

#byte OSCCAL = 0x90
#byte CMCON = 0x19

// If you erased the OSCCAL value, then un-comment this line.
// #rom 0x3FF = {0x3480}   

//======================
void main()
{
int8 D;

#asm
call  0x3FF    // Read the OSCCAL value
movwf OSCCAL   // Load it
#endasm

CMCON = 7;   // Comparator off

gdl_pro1
Guest







PostPosted: Thu Mar 01, 2007 3:02 pm     Reply with quote

It woooooorks!!!!

Thank you. I would had never figured it out myself.

Now I can stay with CCS.
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