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

Counting via rs232 displaying correctly but strangely

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







Counting via rs232 displaying correctly but strangely
PostPosted: Wed Oct 29, 2008 2:17 am     Reply with quote

Hi all,

I made a code that increment an int16 variable then send it to another PIC, using Rs232, and display it in LCD there. the simulation worked but with some delay for the next decimal (supper than those I made for the first PIC).


can anybody help me to figure out the problem.


Code:

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

#include "flex_lcd.c"



void main() {

int a1,a2;
int16 Number;

   enable_interrupts(global);
   
   lcd_init();

   lcd_putc("Running...");

   
 
 
 Number=1;
 


do {
     
     a2=(int8)(freq&0x00FF);
     putc(a2);   
     
     delay_ms(500);
     
     a1=(int8)(freq&0xFF00);
     putc(a1);
     
       
    Number=Number+1;
 
    delay_ms(200);
 
 
    }

while(TRUE);



}




in the other side:



Code:


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

#include <stdlib.h>
#include "flex_lcd2.c"



byte lo,hi;

inth2,i=0;
int16 Number_received;



#int_RDA
void RDA_isr ( )   
{
 while(kbhit())
  {
 
  if(i==1)
   {
   hi=getc();
   inth2=1;
   i=0;
   } 
   
  if(i==0)
   {
   lo=getc();
   i=1;
   }

   
 
  }


}




void main() {




   enable_interrupts(int_rda);

   enable_interrupts(global);
 


lcd_init();


 lcd_putc("Running...");



     
     lcd_putc("\fTransmission...\n");
 



 do
 
 {
   
   if(inth2)
   {
   freq = make16(hi,lo);
   inth2=0;
   }
   
   printf(lcd_putc,"\f%Lu",freq);
   
   
 }



thanks in advance,

Klas.
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Wed Oct 29, 2008 3:39 am     Reply with quote

I think the 2 lines
Code:

     a2=(int8)(freq&0x00FF);
     a1=(int8)(freq&0xFF00);


Should use Number NOT freq as freq is not defined anywhere!

You also need to shift the MSB to the right so
Code:

     a2=(int8)(Number & 0x00FF);
     a1=(int8)(Number >> 8); // No need to do the &


I don't think the
Code:

     delay_ms(500);

is needed either.

It is also nicer to do
Code:

    Number++;

instead of
Code:

    Number = Number + 1;
Klas
Guest







PostPosted: Wed Oct 29, 2008 6:54 am     Reply with quote

Wayne_ wrote:
I think the 2 lines
Code:

     a2=(int8)(freq&0x00FF);
     a1=(int8)(freq&0xFF00);


Should use Number NOT freq as freq is not defined anywhere!

You also need to shift the MSB to the right so
Code:

     a2=(int8)(Number & 0x00FF);
     a1=(int8)(Number >> 8); // No need to do the &


I don't think the
Code:

     delay_ms(500);

is needed either.

It is also nicer to do
Code:

    Number++;

instead of
Code:

    Number = Number + 1;



Hi Wayne,

with your help the code is working fine.

I also made a another changement that made my code better, I used

the EX_SISR.c and EX_STISR.C exemples that I found in my compiler (includes bgetc(), cgetc() and bkhit()), with that buffer, I no longer have to put a delay between the sending of the int8 variables.


the main of the PIC1:


Code:


void main() {

int a1,a2;
int16 Number;

   enable_interrupts(global);
   
   lcd_init();

   lcd_putc("Running...");



Number=0;
 


do {
     
     a1=(int8)(Number&0x00FF);
     bputc(a1);       
   

     a2=(int8)(Number>>8);
     bputc(a2);
     

       Number++;
 
    delay_ms(500); // without this delay the numbers will be displayed so fast that canĀ“t be seen

    }

while(TRUE);
   
   
   
}




the reciver PIC:



Code:


void main() {

   enable_interrupts(int_rda);

   enable_interrupts(global);

   lcd_init();

   lcd_putc("Running...");


   do {

     
     
      while(bkbhit)
     
      {
      if(i==1)
        {
         hi=bgetc();
         inth2=1;
         i=0;
         } 
   
      if(i==0)
        {
        lo=bgetc();
        i=1;
        }     
      }
     
   if(inth2)   
   {   
   Number = make16(hi,lo);
   inth2=0;
   printf(lcd_putc,"\f%Lu",Number);     
   }


   } while (TRUE);
}




thank you very much Wayne,


Any remark or suggestion is welcome by anyone ! Smile
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