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

18f458 and string

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



Joined: 05 Jan 2006
Posts: 105

View user's profile Send private message

18f458 and string
PostPosted: Mon Oct 16, 2006 12:35 am     Reply with quote

hello all;

im working on 16f877,,i try to send and Receive serial string.
then do some function and print on lcd.and its work fine;
i try now to do same but using 18f458,,but it dont work
here is my Receiver code:
Code:


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

#int_rda
void serial_isr()
{
         jj=1;
      delay_ms(100);     
}

void main()   {

      lcd_init();

      enable_interrupts(INT_RDA);// turn on interrupts
      enable_interrupts(GLOBAL);

      jj=0;

      output_low(PIN_A0);
      lcd_putc('\f');

   while(TRUE)
{
         output_low(PIN_A0);

         lcd_gotoxy( 1, 1);
         printf(lcd_putc("  WAIT"));
         delay_ms(1000);

      if(jj==1)
{

      output_high(PIN_A0);
      delay_ms(500);         
      output_low(PIN_A0);

          lcd_putc('\f');
         lcd_gotoxy( 1, 1);
         printf(lcd_putc(" interrupt"));
         delay_ms(1000);

   jj=0;
}
}
}

my transmitter code is simpley "printf" and delay time

any body can help,plz
Ttelmah
Guest







PostPosted: Mon Oct 16, 2006 2:46 am     Reply with quote

First thing, your 'receive' code, is going to physically hang the UART. You are not reading the received character, and you are then delaying. Result, the UART internal buffer _will_ overflow, and the UART will then be physically hung.
Change the code in the following ways:
Code:

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,ERRORS)
//This makes the compiler add code to _recover_ from the hung state...
char received;

#int_rda
void serial_isr()
{
   jj=1;
   //delay_ms(100);
   //Do _not_ delay in an interrupt. There are occassions, where _short_
   //delays, may be used, but delays inside interrupts, should be treated
   //as if they bought the 'black death' with them...
   received=getc();
   //You need to read the character, or the interrupt will keep recurring.
}

With these changes, it should start to work, and you can then solve the rest yourself.

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