View previous topic :: View next topic |
Author |
Message |
ElectroNick
Joined: 10 Oct 2005 Posts: 4
|
I/O Problem |
Posted: Thu Feb 09, 2006 9:23 am |
|
|
Hello,
I'm trying to use PIC16F946, when I define ports as input that's ok, it works. But when I define ports as output that goes high automatically, I try to clear and change it in software but no way, output is always high! Previously I used 16f628, 16f785 etc. without problem. But i can't do it at this time. I also disable LCD module and A/D module like this:
Code: | SETUP_ADC(ADC_OFF);
setup_lcd(LCD_DISABLED);
SETUP_WDT(WDT_OFF); |
Can you help me?
Thank you.
I use PCWH Compiler
IDE Version 3.233
PCB Version 3.233
PCM Version 3.233
PCH Version 3.233 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 09, 2006 12:22 pm |
|
|
You need to post a test program that shows the problem. We need
to know what ports you are using when the problem occurs. |
|
|
ElectroNick
Joined: 10 Oct 2005 Posts: 4
|
test program |
Posted: Fri Feb 10, 2006 2:02 am |
|
|
This is my test program, but that doesn't work:
Code: | #include "16F946.h"
#fuses NOWDT, NOMCLR, PROTECT, INTRC_IO, NOBROWNOUT, NODEBUG, NOIESO, NOFCMEN, NOPUT
#use delay (clock=4000000)
#define ALL_OUT 0
#define ALL_IN 0xFF
void main ()
{
SETUP_ADC(ADC_OFF);
SETUP_ADC_PORTS(NO_ANALOGS);
setup_lcd(LCD_DISABLED);
SETUP_WDT(WDT_OFF);
SET_TRIS_A(0b10101011);
SET_TRIS_B(ALL_OUT);
SET_TRIS_C(0b01011000);
SET_TRIS_D(0b11010000);
SET_TRIS_E(0b00011111);
SET_TRIS_F(0b00001111);
SET_TRIS_G(ALL_IN);
while (TRUE)
{
output_toggle(PIN_B0);
output_toggle(PIN_B1);
delay_ms(1000);
}
} |
I can't change the port values in CCS but I wrote a simple program in asm and it changes. But I can't write program in asm, it is too difficult to do it.
Is there anyone who can understand the problem?
Thank you. |
|
|
Einstein Guest
|
|
Posted: Tue May 30, 2006 6:21 am |
|
|
I have the same problem with Ports F and G.
After controlling the generated ASM code from the compiler,
I noticed that the TRIS Register definition of Port F and G was
understood wrong from the compiler. He locates these ports into
register 0xA and 0xB, that is used by PCLATH and INTCON.
I tested it, written the TRIS definition in asm and it works.
I am still trying to understand where to change the memory location/definiton for this device in the compiler.
regards,
AE |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue May 30, 2006 12:04 pm |
|
|
You can write directly to the TRISF and TRISG registers in the 16F946
by using the following method:
Code: |
#byte TRISF = 0x185
#byte TRISG = 0x187
void main()
{
TRISF = 0xFF; // All inputs
TRISG = 0x00; // All outputs
while(1);
} |
|
|
|
Einstein Guest
|
|
Posted: Wed May 31, 2006 5:57 am |
|
|
I updated by compiler version to 3.249 and the problem was resolved.
THX,
AE |
|
|
|