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

RX interrupt of PIC18F46k22 is not working.

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



Joined: 25 Sep 2013
Posts: 18

View user's profile Send private message

RX interrupt of PIC18F46k22 is not working.
PostPosted: Wed Sep 25, 2013 5:41 pm     Reply with quote

I took 4 days to fix the problem of PIC UART. I am using PIC18f46k22.
when sending character to PC via TX , PC received character well.
But when sending character to PIC via TX, RX interrupt is not working.
I used rx interrupt with PIC16f877 before. Is different how to use rx interrupt in both of these PICs.
Help me . I am tired.

Code:
 
#include <18F46K22.h>
#device *=16 adc=10


#device ICD=TRUE
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
//#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES H4 //High speed osc with HW enabled 4X PLL
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //Reset when brownout detected
#FUSES BORV42 //Brownout reset at 4.2V
#FUSES PUT //Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES DEBUG //Debug mode for use with ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOPBADEN //PORTB pins are configured as digital I/O on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES MCLR //Master Clear pin enabled
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NOHFOFST //High Frequency INTRC waits until stable before clocking CPU



#use delay(internal=16Mhz,clock=64Mhz,RESTART_WDT,clock_out)
#use rs232(UART1,baud=19200,stop=1,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,restart_WDT,errors,stream=SER1)

#ZERO_RAM

#include <stdio.h>



#use fast_io(a)
#use fast_io(b)
#use fast_io(c)

#priority RDA,EXT



int32 gtemp1=1234567;
long int Delay_time=1000;
int Serial_1=0;
int Serial_2=0;
int RxFlag=0;
char RecvChar=null;



#int_rda
void rda_isr(void)
{
RecvChar = getc();
Delay_time = 100;
RxFlag = 1;

}


#int_ext
Void ext_isr(){

if(Delay_time==100)
Delay_time=1000;
else
Delay_time=100;
}


void main()
{
SET_TRIS_A(0b00000000);
SET_TRIS_B(0b10000001);
SET_TRIS_C(0b10000000);

Port_B_Pullups(TRUE);


ext_int_edge(0, L_to_H);

disable_interrupts(INT_TIMER0);
disable_interrupts(INT_TIMER1);
disable_interrupts(INT_TIMER2);
disable_interrupts(INT_TIMER3);
disable_interrupts(INT_EXT1);
disable_interrupts(INT_EXT2);
disable_interrupts(INT_RB);
disable_interrupts(INT_AD);
disable_interrupts(INT_TBE);
disable_interrupts(INT_RDA2);
disable_interrupts(INT_TBE2);
disable_interrupts(INT_CCP1);
disable_interrupts(INT_CCP2);
disable_interrupts(INT_EEPROM);

enable_interrupts(INT_EXT);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);



while(true){

delay_ms(500);
gtemp1+=1;
// fprintf(SER1,"UART1A4=%d \r\n", input_state(TESTA4));
// fprintf(SER1,"UART1B0=%d \r\n", input_state(TESTB0));
fprintf(SER1,"UART1=%lu \r\n", gtemp1);
fputs("----------------",SER1);

if(RxFlag==1)
{
fprintf(SER1,"%c \r\n",RecvChar);
RxFlag   = 0;
}



output_bit(pin_b1,1);
// led=0b000000010;
delay_ms(Delay_time);   
output_bit(pin_b1,0);
//   led=0b00000000;
delay_ms(Delay_time);   

//    Delay_time +=50;
}
}


Sad Sad
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 25, 2013 7:52 pm     Reply with quote

What's your compiler version ? Always post it.
hwryu



Joined: 25 Sep 2013
Posts: 18

View user's profile Send private message

PostPosted: Wed Sep 25, 2013 9:24 pm     Reply with quote

PCM programmer wrote:
What's your compiler version ? Always post it.


my compiler'version is 4.108
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 25, 2013 10:55 pm     Reply with quote

See the fix shown at the end of this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=43961
hwryu



Joined: 25 Sep 2013
Posts: 18

View user's profile Send private message

PostPosted: Wed Sep 25, 2013 11:46 pm     Reply with quote

PCM programmer wrote:
See the fix shown at the end of this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=43961


After following your advice, Rx interrupt is working well.

Thank you for your help. I am happy
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