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

Serial connecting problems.

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







Serial connecting problems.
PostPosted: Thu Apr 20, 2006 10:16 am     Reply with quote

I'm having a few rather stramge serial connecting problems. (and I simply don't know enough to solve them myself, though I do have some ideas).

I say strange because the code seems to work on one chip but not another.
it's driving me to despair, and even the simplest of programs now seems to just not work...

Anyway... I'll start with the working code.
this code is for a 16f628A, compils nicly using MPLAB and CCS
and runs ilke a charm sending back ascii chars to the terminal window...

Code:
#include <16f628.h>
#fuses intrc_io,nomclr,NOPROTECT,NOWDT,NOBROWNOUT,NOLVP
#use delay(clock=4000000)       
#use rs232(baud=9600,parity=N,xmit=PIN_A0,bits=8, INVERT)
unsigned char j;

void main(void)
{
    #define RIPPLE 100
    #byte PORTA = 5 /*Map ports*/
    #byte PORTB = 6
    set_tris_a(1); /*port A for input*/
    set_tris_b(0); /*port B for output*/

    while(TRUE)
    {
putc('H');
      delay_ms(1000);
puts("Hello");
      delay_ms(1000);
printf("string");
      delay_ms(1000);
    } /*close while statement*/
}


Now, I decided that I'd run the same code on a 16f877A... and thats where things started to go wrong.

heres the code
Code:

#include <16f877.h>
#fuses HS,NOPROTECT,NOWDT,NOBROWNOUT,NOLVP /*fuses, turn pretty much everything off!*/
#use delay(clock=4000000)       /*20meg xtal, makes delay_ type functions accurate*/
#use rs232(baud=9600,parity=N,xmit=PIN_C6,bits=8, INVERT, ERRORS)
unsigned char j;
void main(void)
{

    #define RIPPLE 100
    #byte PORTA = 5 /*Map ports*/
    #byte PORTB = 6
    set_tris_a(1); /*port A for input*/
    set_tris_b(0); /*port B for output*/

    while(TRUE)
    {
output_high(PIN_B0);
putc('H');
      delay_ms(1000);
puts("Hello");
      delay_ms(1000);
output_low(PIN_B0);
printf("string");
      delay_ms(1000);
         
    } /*close while statement*/
}

As you can see, the only things that change are the #include#rs232 (to change the pins) and the #fuses...

I'm using an 8Mhz external crystal with capacitors... (perhaps I need to change something with the timing to make sure that the timmings are set right?

Anyway, one of two things happen.
either the chip sits and does nothing, untill it ocasionally puts some serial data out,
(that's why i added the lines to make pin_b0 high and low because I put an LED there so I could visually see whether it was working or just sitting idle).

ANyway, on the times that the chip is not just sitting idle it's spewing rubbish (random chars) onto the Ascii terminal at a faster rate than then program before (on a different chip, even though they are both meant to be delayed for the same amount of time...

I'm sure someone must have some ideas somewhere...

cheers,
Danny.
Ttelmah
Guest







PostPosted: Thu Apr 20, 2006 10:29 am     Reply with quote

If you are using an 8MHz crystal, then the #use delay statement needs to reflect this.
'ERRORS', does nothing, unless you are using a hardware UART. You cannot use 'INVERT' with a hardware UART.....
As written, you should be getting the characters at 19200bps, since your delay statement says the clock is 4MHz, and it is actually 8MHz...

Best Wishes
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