Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

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 ? :cry:


#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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top