Hi, I can't seem to make the Microchip stack works with a simple LED blinking program, I wish someone can give me an idea of what have I done wrong. Thank you.
Hardware:
PIC18F4620 with ENC28J60, the SPI is working fine, hardware components have no problem.
Compiler used:
C18, MPLAB deafult storage class is set to overlay.
Notes:
- Stack version: v5.31.
- The state constants are defined as 0x01, 0x02, etc. Tried '1', '2', etc, doesn't seem to be the problem.
- Everything works fine if I don't do it the cooperative multitasking way (no states) but it was too slow as tasks hogging the processor.
Code:
Code:
static unsigned char state;
static TICK time;
void main (void)
{
// ...... Initialize everything.
state = S_SET_DELAY;
while (1)
{
StackTask();
StackApplications();
MainApplication();
}
}
void MainApplication (void)
{
switch (state) {
case S_SET_DELAY:
time = TickGet();
state = S_DELAY_WAIT;
break;
case S_DELAY_WAIT:
if ( (TickGet() - time) >= 1*TICK_SECOND ) {
state = S_DELAY_DONE;
}
break;
case S_DELAY_DONE:
state = S_RUN_LED;
break;
case S_RUN_LED:
RUN_LED ^= 1;
state = S_SET_DELAY;
break;
default:
break;
}
}
By the way, I'm quite new in PIC microcntrollers as well as TCP/IP, is there any nice tutorial I can use? Especially about the Microchip TCP/IP stack. Thank you.