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:
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);}".
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
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...
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...
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?.