Strange thing with HItech code sample ...

Status
Not open for further replies.

SadE

Newbie level 4
Joined
May 26, 2003
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
73
Hi ,

I'm testing Hitech C with this little sample program that normally toggle A0 & A1 ... But PORTA never blinks ... When I look at the asm code , the XOR is well generated !!! Coud you explain me why it doesn't work please ?


#include <pic.h>
#define XTAL_FREQ 20MHZ
__CONFIG(WDTDIS & HS & PWRTDIS & BORDIS);

main(void)
{
unsigned int i;

PORTA=0x03;
TRISA=0x00;

for(;
{
for (i=0;i<1000;i++);
PORTA^=0x03;
}
}
 

main(void)
{
unsigned int i;

PORTA=0x03;
TRISA=0x00;

while(1)
{
for (i=0;i<1000;i++);
PORTA^=0x03;
}

}
 

main(void)
{
unsigned int i;

PORTA=0x03;
TRISA=0x00;

for(;
{
for (i=0;i<1000;i++);
PORTA^=0x03;
}
}
 

after some investigation I found that the the same code work on PORTB and not on PORTA, even in asm !!!

PORTA=0x00;
TRISA=0x00;
PORTB=0x00;
TRISB=0x00;

for(;
{
for (i=0;i<1000;i++);
asm("MOVLW 01");
asm("XORWF 05,F");
asm("MOVLW 01");
asm("XORWF 06,F");
}
 

It seems you forgot to disable some analog features on your chip !

Read carefully the default state of I/O pins on datasheet, then initialize correctly them !

Cheers

PicMan
 

Which cpu are you useing?

16F877 and 16F627 / 628 switch PORTA to analogue mode on reset, you have to switch to digital mode if you want to use PORTA as output ...

hope this helps
 

Yeahh you're right !
I have switched off the A/D but it seems you have to set the INTCON1 right .

It's funny that only the XOR operator doen't work when portA pins are in analog mode. AND and OR are working !

thx
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…