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

I have problem to use Interrupt RB pin4-7c in PIC16LF876

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Dec 25, 2010 2:51 pm     Reply with quote

PortB must be read inside the #int_RB routine, to clear the "Mismatch
condition". This is stated in the PIC data sheet. To do this, add the
code (shown in bold below) to your program.
Quote:

// This function reads Port B without changing the TRIS.

int8 input_state_b(void)
{
#byte PortB = getenv("SFR:PORTB")

return(PortB);
}


#int_RB
void RB_isr(void)
{
int8 temp;

PKC++;
if((Command!=Press_Key_First)||(Command!=Press_Key_Second)||(Command!=Press_Key_Third)){Pervius_Command=Command;}
switch (PKC){
case 1: Command=Press_Key_First;PK1=1;PK2=0;PK3=0;break;
case 2: command=Press_Key_Second;PK1=0;PK2=1;PK3=0;break;
default: command=Press_Key_Third;PK1=0;PK2=0;PK3=1;PKC=0;break;
}
OFC=0;
set_timer0(0);
enable_interrupts(INT_TIMER0);

temp = input_state_b(); // Clear mismatch condition on Port B
}


Quote:

#include <16F876.h>
#device ICD=TRUE
#device adc=10

#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES DEBUG //Debug mode for use with ICD

#use delay(clock=2000000)

Do you really have a 2 MHz crystal ? That's very unusual. Or is it
really supposed to be 20 MHz ? If so, edit the #use delay() statement
and also change the fuse from XT to HS.

Are you using the INT output pin of the pcf8563 ? If so, you need a
pull-up resistor on it. You can use 4.7K ohms.
HGHK



Joined: 29 Jun 2010
Posts: 33

View user's profile Send private message Yahoo Messenger

PostPosted: Tue Dec 28, 2010 7:08 am     Reply with quote

Dear PCM programmer
thanks
I test it, but noises make interrupt in another pin from B4-B7. I must pull-up Port B but I made my PCB and I don't know why when I use
Code:
port_b_pullups(1);

in my program the port doesn't pull up.
I used 1MHz crystal before but I don't find it in shops and I prefer 2MHz crystal for low consuming power requirements in PIC16LF876 series and I2C baud rate true setting. Also it find in shops!
If you have a better offer I very like to know.
I use PCF8563 Interrupt for wake up from sleep and I pull up it by 4.7K resistor. So I pull up Pin B5 and it connect with Push-pull bottom and noise reduction capacitor to GND.

Thanks for your help. Wink
_________________
My Gmail is:
HGholizadehK@Gmail.com
You can send pm for me in it
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 28, 2010 12:51 pm     Reply with quote

Quote:
I must pull-up Port B but I made my PCB and I don't know why when I use:
port_b_pullups(1);
in my program the port doesn't pull up.

Then make a small test program and study how to use the
port_b_pullups() function.


I looked in your program for the port_b_pullups() line, which you say
you have in there. I didn't find it. But I did see this problem:
Quote:

void ReportTSC(int32 inp){

int8 i,dig[4],temp;

dig[0]= make8(inp,0);
dig[1]= make8(inp,1);
dig[2]= make8(inp,2);
dig[3]= make8(inp,3);
temp=Sleep_Priod_Division_Reg;
putc(I_am_ready);
for(i=0;i=3;i++)putc(dig[i]); putc(temp);
}

What does that line do ? How can "i=3" work ?
Here is a test program to test that line of code:
Code:
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//==========================================
void main()
{
int8 i;

for(i=0;i=3;i++) putc('A');

while(1);
}


Here is the output:
Quote:
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

Your code does not work correctly.

You need to study "for loops" in the C language and learn how to make
a correct for() statement.
HGHK



Joined: 29 Jun 2010
Posts: 33

View user's profile Send private message Yahoo Messenger

PostPosted: Tue Jan 04, 2011 4:19 am     Reply with quote

Quote:
I looked in your program for the port_b_pullups() line, which you say
you have in there. I didn't find it.

I placed corrections that you offered in my program. Thanks for your attention. but in ccs c manual says that:
Quote:
for
For is also used as a loop/iteration statement.
The syntax is
for (expr1;expr2;expr3)
statement
The expressions are loop control statements. expr1 is the initialization, expr2 is the termination check and expr3 is re-initialization. Any of them can be omitted.
Example:
for (i=1;i<=10;++i)
printf("%u\r\n",i);

I think termination check means that when I come to expr2 this loop is end of screwing and when this loop were end next line go runs.
pleas help me that what of these:
Code:
for(i=0;i<=3;i++)putc(dig[i]);

or
Code:
for(i=0;i>3;i++)putc(dig[i]);

is ok?
_________________
My Gmail is:
HGholizadehK@Gmail.com
You can send pm for me in it
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jan 04, 2011 1:22 pm     Reply with quote

Make a test program. Test it with each of those lines of code.
Then you can see what each line does.

You can test it with the MPLAB simulator:

See this post for instructions on how to use the "UART1" feature of the
MPLAB simulator to display serial output in the MPLAB Output Window:
http://www.ccsinfo.com/forum/viewtopic.php?t=23408&start=1
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