View previous topic :: View next topic |
Author |
Message |
Dagaca
Joined: 05 Jul 2017 Posts: 4
|
#pin_select error pic16f18345 |
Posted: Thu Jul 06, 2017 7:02 am |
|
|
Hello.
My name is David Garcia, this is my first post but I have read your forum for a long time and it has been of great help to solve doubts and to learn more about the programming of microchip microcontrollers.
Today i've a problem and I don't find a solution in forum.
I'm using function #pin_select to remap T3CKI and T5CKI but the registers T3CKIPPS and T5CKIPPS don't change correctly.
If i use the next code the registers T3CKIPPS and T5CKIPPS change correctly:
#byte T3CKIPPS = getenv("sfr:T3CKIPPS")
T5CKIPPS = 0b00001110;
Thanks in advance. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Thu Jul 06, 2017 8:00 am |
|
|
First you should always tell us the compiler version.
Then please just post a basic example.
Then there is a problem. I'm very surprised your fix works...
It should not set the register.
Reason is the register should not allow you to set it!....
This is 'PPSLOCK', and it will be on when the chip boots. This is a hardware feature, so it shouldn't be working.
The sequence to write to a register like this is:
Code: |
#include <16F18345.h>
#device ADC=10
#fuses NOPPS1WAY, NOMCLR, NOLVP
#use delay(crystal=20000000)
#PIN_SELECT T3CKI=PIN_B6
#byte PPSLOCK=getenv("SFR:PPSLOCK")
#byte T3CKIPPS = getenv("sfr:T3CKIPPS")
#define PPSELECT(PPSregister, pattern) \
disable_interrupts(GLOBAL); \
PPSLOCK=0x55; \
PPSLOCK=0xAA; \
BIT_CLEAR(PPSLOCK,0); \
PPSregister=pattern; \
PPSLOCK=0x55; \
PPSLOCK=0xAA; \
BIT_SET(PPSLOCK,0); \
enable_interrupts(GLOBAL)
void main()
{
PPSELECT(T3CKIPPS,0x0E);
while(TRUE)
{
//Your code
}
}
|
If CCS is not correctly setting the PPS registers on this chip you should report it to them. They will fix something like this urgently. |
|
|
Dagaca
Joined: 05 Jul 2017 Posts: 4
|
|
Posted: Thu Jul 06, 2017 8:51 am |
|
|
Very thanks!
The compiler version is 5.070.
Your code works fine, but with one exception, If the code apears any #pin_select(...) PPSLOCK don't change.
i've tried your code and the next code, without #pin_select(...) works fine.
Code: | #include <16F18345.h>
#device ADC=10
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOPPS1WAY
#use delay(internal=8MHz)
#byte T0CKIPPS = getenv("sfr:T0CKIPPS")
#byte T1CKIPPS = getenv("sfr:T1CKIPPS")
#byte T3CKIPPS = getenv("sfr:T3CKIPPS")
#byte T5CKIPPS = getenv("sfr:T5CKIPPS")
void main()
{
disable_interrupts(GLOBAL);
#ASM
movlw 0x55
movwf 0xE0F
movlw 0xAA
movwf 0xE0F
bcf 0xE0F.0
#ENDASM
T0CKIPPS = 0b00010010; //T5CKI IN PIN_C2
T1CKIPPS = 0b00001100; //T5CKI IN PIN_B4
T5CKIPPS = 0b00001110; //T5CKI IN PIN_B6
T3CKIPPS = 0b00001101; //T3CKI IN PIN_B5
#ASM
movlw 0x55
movwf 0xE0F
movlw 0xAA
movwf 0xE0F
bsf 0xE0F.0
#ENDASM
enable_interrupts(GLOBAL);
while(TRUE)
{
}
}
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Thu Jul 06, 2017 10:46 am |
|
|
It's behaving as if the PPS1WAY fuse is set. However I've just checked, and the compiler is correctly turning the bit off...
Ugh.
I really would be talking to CCS straight away. |
|
|
|