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 CCS Technical Support

#INT_EXT help

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



Joined: 09 Sep 2003
Posts: 52

View user's profile Send private message MSN Messenger

#INT_EXT help
PostPosted: Wed Oct 20, 2004 9:50 am     Reply with quote

I just want to test a simple external interrupt. I couldn't get it to work.
If a key is pressed, it start to lid up RB0, else print Normal on the RS 232 line. Please help....

Here is my code:

Code:


#include <18f458.h>
#device ADC=10
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#int_ext
void display_isr()
{
   
    if(kbhit())
   {

      output_high(PIN_B0);

   
     
    }
}


void main()
{
   output_b(0x00);
   
   
   while(1)
   {
      if(!kbhit())
      {
         printf("Normal Mode\n\r");
      }
      else
      {
      enable_interrupts(int_ext);
         enable_interrupts(global);
      }
   }

   
   
}
ckielstra



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

View user's profile Send private message

PostPosted: Wed Oct 20, 2004 10:29 am     Reply with quote

what do you mean with 'If a key is pressed' ?
Is this a key on your PC that is transmitted through RS232 or the key that is connected to your int_ext line?

Now your program is first waiting for a character from RS-232, only after that it will respond to a key press on int_ext. Is this how you want your program to work?

Also: The function kbhit() will check for a received character on the RS232 line. You are using the hardware UART which will buffer a maximum of three characters. kbhit() will return TRUE until you have read all received characters from this hardware buffer. You never read the received characters from the RS232 buffer, so kbhit() is never cleared.

Note that the software RS232 driver works very different from the hardware one. The software RS232 has a blocking kbhit() which will wait for the first character to be received over RS232 where the hardware based RS232 will just test a flag in the hardware and then continue without waiting. Another difference is that the software version of kbhit() will not remember whether a character was received but not read from the buffer.
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Wed Oct 20, 2004 5:33 pm     Reply with quote

This line:

Code:

output_b(0x00);


Will change the PORTB pins to output because the compiler is in the "#use standard_io (B)" mode by default. Then when you enable the int_ext interrupt, RB0 is still set to output, so you won't receive any interrupts. Set it to input by using set_tris_b(0b00000001);

By the way, you may want to move this portion of the code:

Code:

if(!kbhit())
      {
         printf("Normal Mode\n\r");
      }
      else
      {
      enable_interrupts(int_ext);
         enable_interrupts(global);
      }


out of the while loop.
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