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

redirecting input on output with PIC16F877A

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



Joined: 16 Oct 2008
Posts: 59

View user's profile Send private message

redirecting input on output with PIC16F877A
PostPosted: Fri Nov 14, 2008 2:36 am     Reply with quote

Hello to everybody,

I am trying a simple programm, which doesn't work as it should work.
In the main function, I just want :
PIN_D1 = PIN_C1.
PIN_D0 = PIN_C5.

Alone without the interrupt function, it works.

When I add the interrupt function (which just blink a led), the interrupt function works and the led blinks, but the DATA and CLOCK I/O doesn't work anymore.

When I invert the two functions (led blinking in the while and DATA/CLOCK in the interrupt function), nothing works...

Any ideas ?

Code:

#include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,NOPUT
#use delay(clock=20000000)
#use rs232(baud=115200,xmit=PIN_C4,bits=8,invert)

#define CLOCK_IN PIN_C2
#define DATA_IN  PIN_C5

#define CLOCK_OUT PIN_D1
#define DATA_OUT PIN_D0

int main()
{
   output_high(PIN_D7);
   output_high(PIN_D6);
   output_high(PIN_D5);
   output_high(PIN_D4);
 
    ext_int_edge(H_to_L);
    enable_interrupts(INT_EXT);
    enable_interrupts(GLOBAL);

    while(1)
    {
       OUTPUT_BIT(CLOCK_OUT,INPUT(CLOCK_IN));
   OUTPUT_BIT(DATA_OUT,INPUT(DATA_IN));
    }
   return 0;
}

#int_ext
void kbInterrupt()
{
    output_low(PIN_D6);
    delay_ms(200);
    output_high(PIN_D6);
    delay_ms(200);
    return;
}


Another example, if i write this :
Code:

    while(1)
    {
    OUTPUT_BIT(CLOCK_OUT,INPUT(CLOCK_IN));
    OUTPUT_BIT(DATA_OUT,INPUT(DATA_IN));
    output_low(PIN_D6);
    delay_ms(200);
    output_high(PIN_D6);
    delay_ms(200);
    }
   return 0;
}


The redirection doesn't work.
MarcosAmbrose



Joined: 25 Sep 2006
Posts: 38
Location: Adelaide, Australia

View user's profile Send private message

PostPosted: Fri Nov 14, 2008 11:15 pm     Reply with quote

Hi magestik,
Your ISR routine is taking 400mS to complete, so any changes in the Data and clock pins that you're trying to re-direct will get overlooked until the ISR routine has finished.

It has been stressed in several threads just recently, "Don't use delays in interrupt service routines!" Try using a timer interrupt to make your LED blink
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