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

Setting PIC Register

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



Joined: 08 Mar 2017
Posts: 40

View user's profile Send private message

Setting PIC Register
PostPosted: Sun May 21, 2017 7:57 pm     Reply with quote

I am trying to setup the register (PIE3) USART Received interrupt
but not using "enable_interrupts(INT_RDA)".
Information from datasheet of PIC16F18857
- Register PIE3 address: 719h
- Bit RCIE = USART Received interrupt enable bit (1 enable / 0 disable)

With information above...I setup.
Code:

#INT_RDA
void RDA_isr(void)
{
 x = getc();
printf("RDA working");

}

// different way of enable_interrupts(INT_RDA)" set up.
#byte PIE3=0x719
#bit PIE3BIT5 = PIE3.1

void main()
{
 enable_interrupts(GLOBAL);
}

Why its not printing "RDA working" when send a byte by serial com?
Using enable_interrupts(INT_RDA)" instead
#byte PIE3=0x719 works !

Regards, jpts
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sun May 21, 2017 11:25 pm     Reply with quote

First thing. Use the register names!...
Then you show no sign of setting the bit in your code.

The compiler supports things by name. So:

Code:

#BIT RCIE=getenv("BIT:RCIE)
//or for the register
#BYTE PIE3=getenv("SFR:PIE3")

//Then to set RCIE, just use

     RCIE=TRUE;


You have setup the bit, but never put a value into it. The bit once defined, is just a variable. It still needs a value written to it.
jpts



Joined: 08 Mar 2017
Posts: 40

View user's profile Send private message

PostPosted: Mon May 22, 2017 10:52 am     Reply with quote

Still not working. The USART Received interrupt not running.

There is a way to check status oF RCIEF ...like Printf(RCIE);

I used:
Code:
#BIT RCIE=getenv("BIT:RCIE")

void main()
{
 RCIE=TRUE;
 enable_interrupts(GLOBAL);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 22, 2017 11:10 am     Reply with quote

What's your compiler version ? In vs. 5.071, the two lines shown in main()
produce the same ASM code. Then you see that each line does a BSF
on the RCIE bit.

Code:

.................... enable_interrupts(INT_RDA);
0010:  MOVLB  0E  // Set the RAM bank

0011:  BSF    PIE3.RCIE

.................... RCIE = TRUE;
0012:  BSF    PIE3.RCIE
.................... 
.................... while(TRUE);     
0013:  GOTO   013
.................... }


Test program:
Code:

#include <16F18857.h>
#fuses XT, NOWDT
#use delay(clock=4M)

#BIT RCIE=getenv("BIT:RCIE")

//==========================
void main()     
{
enable_interrupts(INT_RDA);
RCIE = TRUE;

while(TRUE); 
jpts



Joined: 08 Mar 2017
Posts: 40

View user's profile Send private message

PostPosted: Mon May 22, 2017 11:49 am     Reply with quote

Still not working...following the program. Vs used: 5.071

Code:
int x;
#INT_RDA
void RDA_isr(void)
{  x = getc();
printf("RDA working");
}

#BIT RCIE=getenv("BIT:RCIE")

void main()
{       
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   RCIE=TRUE;

   while(TRUE)
   {
   
   }
}
alan



Joined: 12 Nov 2012
Posts: 349
Location: South Africa

View user's profile Send private message

PostPosted: Mon May 22, 2017 11:58 am     Reply with quote

Post a complete program with your #FUSES and serial setup.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon May 22, 2017 12:16 pm     Reply with quote

As a comment, yes, of course you can print the value of RCIE. It is just an int1 variable. So:

printf("%d",RCIE);

will print 0, or 1, according to whether it is clear or set.

It will be being set.

Given you print a lot of characters in the interrupt, your #use rs232 must have 'ERRORS' or the UART will become hung if more than one character arrives.

You need to post a complete program, so that we can compile it 'as is'. Showing all the fuses etc.. Otherwise there are so many other things it could be...
jpts



Joined: 08 Mar 2017
Posts: 40

View user's profile Send private message

PostPosted: Mon May 22, 2017 12:36 pm     Reply with quote

Code:
#include <16F18857.h>

#use delay(crystal=20MHz)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1,errors)

#FUSES NOBROWNOUT               
#FUSES NOLVP
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 22, 2017 1:13 pm     Reply with quote

There's your problem. Your #use rs232() is making a soft uart. Of course
there will be no #INT_RDA working with a soft uart. I wondered how you
were making it compile without #pin_select statements.

Do your setup like this, with the lines in this exact order:
Code:
#include <16F18857.h>
#FUSES NOBROWNOUT               
#FUSES NOLVP
#use delay(crystal=20MHz)

#pin_select U1TX=PIN_C6
#pin_select U1RX=PIN_C7

#use rs232(baud=9600, UART1, ERRORS)


Also, I noticed you have a stream specified in your #use rs232()
statement but you don't use fgetc() or fprintf(), etc., which require a
stream to be specified. So in the program above, I left out the stream
since it's not being used.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon May 22, 2017 1:21 pm     Reply with quote

On this chip the serial is controlled by PPS. 5.071, ought to be setting this, but I'd not assume it:
Code:

#include <16F18857.h>
#device ADC=10
#use delay(crystal=20000000)
//Fuses should be before UART setup etc..
#FUSES NOBROWNOUT
#FUSES NOLVP
#FUSES NOWDT
#FUSES NOPPS1WAY
#FUSES STVREN
#FUSES NOMCLR

//On this chip the UART uses PPS. This is how to setup PPS
#PIN_SELECT U1RX=PIN_C7
#PIN_SELECT U1TX=PIN_C6

#use rs232(baud=9600,parity=N,UART1,bits=8,stream=PORT1,errors)

#BIT RCIE=getenv("BIT:RCIE")

int8 x;
int1 have_chr=FALSE;

#INT_RDA
void RDA_isr(void)
{
   x = fgetc(PORT1); //If using streams, fetch from the stream
   have_chr=TRUE;
}

void main()
{
   enable_interrupts(GLOBAL);
   RCIE=TRUE;
 
   while(TRUE)
   {
      if (have_chr)
      {
         have_chr=FALSE;
         fprintf(PORT1,"CHAR %x\n",x);
      }
   }
}
jpts



Joined: 08 Mar 2017
Posts: 40

View user's profile Send private message

PostPosted: Mon May 22, 2017 6:29 pm     Reply with quote

Worked !!!!! you are amazing...thanks a lot !

Happy and same time concerned. I change my project MCU from PIC16F876 to 16F18857. Reason more program memory. I am not familiar with PPS and setups. I am not sure if i will face with more changes like that.

I still need test other functions that work well for 16F876 but not sure with 16F18857.

Thanks a lot !!!

Jpts
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Tue May 23, 2017 12:07 am     Reply with quote

The data sheet will tell you that 90% of the peripherals on this chip support PPS.
It's a great feature, since it allows you to move peripherals to other pins. Smile

If you look at the top of the processor header file, you will find about 20 lines down, a list of all the peripheral function signal names controlled by PPS.

Hopefully what I've posted, gives you the key 'idea'. You set the signal name, to the pin you want it on, and then configure the peripheral using the peripheral name (not the pin names). So the compiler then knows you want to talk to the hardware peripheral, and this is connected to the specified pins.
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