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); ...
No, the problem was with the UART ISR overwriting the accumulator, which is where th eloop counter is. Moving the UART's ISR to register bank 2 solved the problem.
No, the problem was with the UART ISR overwriting the accumulator, which is where th eloop counter is. Moving the UART's ISR to register bank 2 solved the problem HUH? there is no accumulator in the register banks. Erik
Yeah, my terminology is probably off, but i is pushed onto some register r(something or other), and then something else is put there in the uart_isr, overwriting the loop counter
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.
"Moving the UART's ISR to register bank 2 solved the problem." Did you originally declare the ISR with 'using 0'?
No, no routines had using in the declaration, but I assumed that because of that, they all automatically used bank 0.
"No, no routines had using in the declaration, but I assumed that because of that, they all automatically used bank 0." Yes, they do, but an ISR that uses bank zero by default will restore the content of any registers it trashes. I'm trying to understand why specifying 'using 2' has fixed your problem, or rather, I'm trying to understand why you had the problem in the first place. The 'using' directive tells a function not only to use a specific register bank but also that it doesn't need to preserve the contents of the registers in that bank.
Is there something I could post that would clear up what problem I was having? My ASM skills are extremely limited, so I made an assumption based on what I saw, and moving the uart interrupt routine over to register bank 2 fixed it. I'll be glad to post the .lst files if it helps.
"I'll be glad to post the .lst files if it helps." Yes, I'd be interested. If you're using the LX51 linker you can generate a .cod file which would be even more useful.
You stated that you use timer0 interrupt for your delay. Are you sure, that your program is waiting inside delay() and continues after the interrupt occures?