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

PCM Compiler Giving Me Junk

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








PCM Compiler Giving Me Junk
PostPosted: Thu Apr 21, 2005 1:22 am     Reply with quote

Hi

I am a newbee. I just got my PCM compiler Smile . I tried the RS232 example, and had it working through RealTerm ( Hyperterminal didn't work), it displayed the status of output pin RB0 OK.

Now when I compile the code through PCM/MBLAB, all I get is junk characters. I have output this code through THREE different terminal programs, and they are all displaying junk. I tried a different program from the mikroC compiler (on the same chip, test board, programmer), and it works fine. I have set all fuses through MPLAB, and programatically.

Also, the first printf()'s don't print out properly.

This is some of the output from the terminal



Connected to COM1
Sent: 4
Received: >
Received: >0
Received: 0>
Received: >
Received: 0
Received: 0
Received: >
Received:
Received: 0
Received: 00
Received:
Received:
Received: 00
Received: 0
Received: 0
Received:
Received: 00
Received: 0
Received: 00
Received:
Received: 00
Received: 0
Received: 0
Disconnected from COM1

Here is the CCS C example code, with a couple of printf() I put in:

Code:
/////////////////////////////////////////////////////////////////////////
////                             EX_SQW.C                                                   ////
////                                                                                                ////
////  This program displays a message over the RS-232 and waits for  ////
////  any keypress to continue.  The program will then begin a 1khz    ////
////  square wave over I/O pin B0.                                                  ////
////                                                                                                ////
////  Comment out the printf's and getc to eliminate the RS232 and   ////
////  just output a square wave.                                                      ////
////                                                                                                ////
////  Change both delay_us to delay_ms to make the frequency 1 hz.   ////
////  This will be more visable on a LED.                                         ////
////                                                                                               ////

////                                                                                               ////
////  This example will work with the PCB, PCM and PCH compilers.    ////
////  The following conditional compilation lines are used to                ////
////  include a valid device for each compiler.  Change the device,  ////
////  clock and RS232 pins for your hardware if needed.              ////





#if defined(__PCM__)
#include <16F876A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)                                       

#elif defined(__PCB__)
#include <16C56.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_A3, rcv=PIN_A2) 

#elif defined(__PCH__)
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) 
#endif


void main() {
 
   printf("Press any key to begin\n\r"); 
   getc();
   printf("1 khz signal activated\n\r");

   while (TRUE) {
      
    printf( "Pin RB0 HIGH\n\r" );
     output_high(PIN_B0);
     delay_ms(500);
     
     printf( "Pin RB0 LOW\n\r" );
     output_low(PIN_B0);
     delay_ms(500);
   }
}


I have searched through the archives, and have spent several hours trying to get my first program going. Mad

Cheers

Dale
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 21, 2005 1:34 am     Reply with quote

1. What PIC are you using ?

2. What is the crystal frequency ?

3. Are you using a MAX232 chip between the PIC and the PC ?

4. What baud rate is the terminal program set for ?
Guest








PCM Compiler Giving Me Junk
PostPosted: Thu Apr 21, 2005 1:48 am     Reply with quote

Hi

Thanks for your reply.

Well I am using an easyPIC2 Development board from

http://www.mikroelektronika.co.yu/english/product/tools/easypic2.htm

Chip: 16F876A

XT: 8 MHz

The board uses a MAX232N, and like I said, I tried another C program using their compiler, and it worked OK.

And at one stage the CCS C example worked too.

The THREE terminal programs were all set @ 9600 bps.

With the CCS C program, all the LEDs connected to the respective ports light up or blink, including the RC7/TX when it sends a HI/LO.

Cheers

Dale
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 21, 2005 2:01 am     Reply with quote

The example program that you're using is set for a 20 MHz crystal.
You need to change the #use delay () statement in the section for
the 16F876A so it's set for 8 MHz. Example:
Code:
#use delay(clock=8000000)

Re-compile after you make that change and see if it works.
Dale Stewart



Joined: 21 Apr 2005
Posts: 8
Location: Wollongong, AUSTRALIA

View user's profile Send private message Send e-mail

Thanks Heaps
PostPosted: Thu Apr 21, 2005 3:31 am     Reply with quote

Hi PCMP

Guess what? it worked - COOL! Thanks Very Happy

Now I know why it worked before, because I must have tried 8MHz for XT. I got confused when I checked out the manual (p 61)

Quote:
#USE DELAY

Purpose: Tells the compiler the speed of the processor...


Maybe I am just dumb, but it seems a little ambiguous?
Once again many thanks for your help.

Cheers

Dale
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Apr 21, 2005 6:19 am     Reply with quote

Quote:
Maybe I am just dumb, but it seems a little ambiguous?


Not at all. The compiler doesn't know the clock speed unless you tell it. It uses that value to set up the baud rate, delays and such.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Apr 21, 2005 7:44 am     Reply with quote

Quote:
Maybe I am just dumb, but it seems a little ambiguous?
Yes, it is ambigious. The setting of the clock speed here is not only used for the delay functions but also for baudrate etc. This is confusing because now you expect separate directives for delay, baudrate, etc. In my opinion it would have been better to have a general '#clock' directive and forget about the #delay.

Yes, you are a little dumb. Even when you think the directive is not used in your program, because you are not calling the delay function, specifying an obvious wrong clock speed is asking for troubles.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Apr 21, 2005 7:45 am     Reply with quote

Quote:
Yes, you are a little dumb


Harsh Smile
Guest








PostPosted: Thu Apr 21, 2005 9:02 am     Reply with quote

Clearly not that dumb, he tried the things he knew of, then rather than banging his head, he asked here. Nice to see someone thinking for themselves - don't knock that. Also he asked the right question & provided the right information leading to the answer. Dumb is those who post the one liners asking people here to do their work for them.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Apr 21, 2005 10:04 am     Reply with quote

Sorry, no offense please. I tried to be not too serious and forgot to add the smiley. Smile
Dale Stewart



Joined: 21 Apr 2005
Posts: 8
Location: Wollongong, AUSTRALIA

View user's profile Send private message Send e-mail

Dumby
PostPosted: Thu Apr 21, 2005 7:12 pm     Reply with quote

Hi

Thankyou to everone who posted their helpful comments. I prefer to find the answer by research first by looking at the manual, search the posts, WWW, etc. Then if I am stuck its good to know there are people who are generous with their time and efforts.

(Maybe I am a little dumb Wink )

Cheers

Dale
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