|
|
View previous topic :: View next topic |
Author |
Message |
gdl_pro1 Guest
|
12f629 RS232 |
Posted: Thu Mar 01, 2007 11:53 am |
|
|
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
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
|
|
Posted: Thu Mar 01, 2007 12:10 pm |
|
|
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
|
|
Posted: Thu Mar 01, 2007 12:22 pm |
|
|
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
|
|
Posted: Thu Mar 01, 2007 12:27 pm |
|
|
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
|
|
Posted: Thu Mar 01, 2007 12:32 pm |
|
|
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
|
|
Posted: Thu Mar 01, 2007 12:38 pm |
|
|
Thanks I removed it, same issue only trash in Terminal |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Mar 01, 2007 2:11 pm |
|
|
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
|
|
Posted: Thu Mar 01, 2007 3:02 pm |
|
|
It woooooorks!!!!
Thank you. I would had never figured it out myself.
Now I can stay with CCS. |
|
|
|
|
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
|