This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

problem with loop counter

I have just switched to KEIL from SDCC (it just wouldn't do what I needed!). I have a startup loop that allows some sleep time while some outboard sensors warm up. While they are doing this, I'm in a loop, printing "."'s to the uart:

Byte i = 0; //loop counter
	printf("Calibrating Sensors");
	for (i=0; i<10; i++){
		toggle_led(1,250); // delay and flash LED
		printf(".");
	}
	printf("Loop Complete \r\n");
	calibrate_sensors();
	delay(3000);
...
The problem is that i is being incremented while the toggle_led() delay routine is running. toggle_led calls delay(ms), which is based is based on a 1ms timer, using timer0's interrupt. Any reason why i is 231 (vs. 2) when delay() returns the first time through the loop?

I'm using 4.51a of cx51.

Parents
  • a general statement on register banks:
    My method (that works) is
    main at RB0
    low IP priority interrupts at RB1
    high IP priority interrupts at RB2
    on derivatives with more than 2 IP priorities (e.g. Philips Rx2), I only use one more which is the highest and uses RB3.
    also NO subroutine is used at more than one level.

    There is no reason, whatsoever, to use different RBs for interrupts at the same IP priority.

    Erik

    IP priority: priority as define by the IP (and extensions) SFR(s). NOT the priority of concurrent ints, that is irrelevant in this respect.

Reply
  • a general statement on register banks:
    My method (that works) is
    main at RB0
    low IP priority interrupts at RB1
    high IP priority interrupts at RB2
    on derivatives with more than 2 IP priorities (e.g. Philips Rx2), I only use one more which is the highest and uses RB3.
    also NO subroutine is used at more than one level.

    There is no reason, whatsoever, to use different RBs for interrupts at the same IP priority.

    Erik

    IP priority: priority as define by the IP (and extensions) SFR(s). NOT the priority of concurrent ints, that is irrelevant in this respect.

Children
No data