Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC16F84A, Odd behavour...

Status
Not open for further replies.

bsodmike

New Member
Hello guys!

I was trying out some code to get the LCD to work and instead the PIC started acting quite strangely.

It was pretty much as follows:

Code:
int main()
{
TRISA = 0x00; 
TRISB = 0x00;
PORTA = 0x00;
PORTB = 0x00;

CLK=1;
DelayMs_100(1); // this is the delay to warm up the LCD
CLK=0;  
  
LCD_Init();
Mode_char(); // send this before sending chars to LCD
snd_char(atoi("------EVAC------")); 
DelayMs_100(5);
clr_snd(); // clears the screen and sets cursor back to home  
}

And the strangest thing happened. the LED was blinking...

I had the config bits set to HS, no WDT, with PUT enabled. I however suspect the WDT still being on. Tomorrow I'm gonna try and strip the code down to:

main{
led on
delay
led off}

and see if it does the SAME thing...

Also I can not compile the code with:

__CONFIG(HS & WDTDIS & UNPROTECT & PWRTEN); //Configuration Fuses

It gives an error saying ')' expected. I'm really confused why, picclite compiler.

--Mike
 
What do you use to program it? If you load up the file in Warp13, all the config bits from the hex file are interpreted and displayed on the user interface. They can also be manually reconfigured before programming.

But, after reading your code, it looks like the main will just run out of code. It MUST end in at least a "while(1);" or "while(1) CLRWDT();", or otherwise continue some functionality. Otherwise you eventually get a reset and you don't want that. Normally code will not lock up in an arbitrary loop like that but do something like "while(1){ if(buttonPressed) sendChar(++i);}".
 
But how can the code 'reset' if the WDT is off?

At the end of I'll put it in an infinite loop and make it go to sleep inside that :)
 
bsodmike said:
But how can the code 'reset' if the WDT is off?

The program counter loops back to zero, and the program runs again, it's not an actual 'reset', but it simply runs from the reset vector again. Bear in mind, the blank locations after you program read as NOP, so after your code you have a series of NOP's until the program counter overflows back to zero.

At the end of I'll put it in an infinite loop and make it go to sleep inside that :)

You don't need to make it sleep, just an endless loop will do.
 
Dear Nigel,

Thanks a lot - but one quick question:

main {

line 1
line 2
.
.
.
line N
}

Before it goes to the reset vector it must mean that it has reached the last line 'N' - of course this means that the LCD would have been re-initialized over and over and I just saw nothing on it...

Will try again :)

--Mike
 
bsodmike said:
Dear Nigel,

Thanks a lot - but one quick question:

main {

line 1
line 2
.
.
.
line N
}

Before it goes to the reset vector it must mean that it has reached the last line 'N' - of course this means that the LCD would have been re-initialized over and over and I just saw nothing on it...

Will try again :)

--Mike

It obviously depends what the C compiler actually generates?, but it's important to not allow the program to loop round - I would expect a compiler to automatically add the required code to prevent it?, and the BASIC compiler I was writing did just that, but I suspect C compilers may not?.
 
I'm thinking not. Actually this is the first time I've *forgotten* to loop in main (didn't have breakfast till 7pm yesterday lol!)...

Hopefully this should yield some insight into the problem, I'll be testing this tomorrow and let you know how it goes :)

Thanks, Mike

update: Woo that fixed it thanks!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top