Hello,
I am developing a project on IR based remote control switch using 89C2051 uC. I am using Keil uV2 for compiling the code. I have tested my code on a different uC 89V51RD2 and it works fine. But when I am testing it on 89C2051, the uC behaves strangely, sometimes it works fine but sometimes it doesn't boot at all and nothing happens.
I want to know that is there any kind of special setting in Keil uv2 for 2051 uC, or is there something else which I should take care for 2051 uC.
My code is:
int main() { TCON = 0x01;// IE = 0x81; // For External Interrupt P3.2 EA = 1; EX0 = 1; led = 0; toggle = 0; delay(); #if MEM toggle = read(0x00); // Passing the addr #endif while(1) {} } void tsop_delay1() { #pragma asm mov R7,#255 ;1.728mS delay for each bit djnz R7,$ mov R7,#255 djnz R7,$ mov R7,#255 djnz R7,$ mov R7,#30 djnz R7,$ #pragma endasm } void tsop_delay2() { #pragma asm mov R7,#255 ;1.296ms delay for each bit djnz R7,$ mov R7,#255 djnz R7,$ mov R7,#87 djnz R7,$ #pragma endasm } void compare_and_set_cmd(int cmd) { if(cmd == 0x01) { /* Decimal 2*/ toggle = !toggle; #if MEM write(0x00, toggle); #endif led = !led; } } void ext_interrupt(void) interrupt 0 { int fieldbit=0, flip=0, addr=0, cmd=0; int i; if(!tsop) { // 1st bit = 1 tsop_delay2(); fieldbit = !tsop; // 2nd bit = 0 or 1 tsop_delay1(); flip = !tsop; // 3rd bit 0 or 1 tsop_delay1(); for(i=0; i<5; i++) { // 4th to 8th bit = address bits addr |= !tsop; addr = addr << 1; tsop_delay1(); } addr = addr >> 1; for(i=0; i<6; i++) { // 9th to 14th bit = command bits cmd |= !tsop; cmd = cmd << 1; tsop_delay1(); } cmd = cmd >> 1; compare_and_set_cmd(cmd); } }
Please help!
Thanks
Yes - it's just resting instead of resetting.
;-)
It was actually a reset issue. I have put a RC reset circuit on the reset pin of 2051 and things started working out properly..
Thanks ..
Did you select an RC reset because that was all you could afford? Or because everyone writes about how bad they are, and likely to fail in some situations?
Ooh, you sarky devil you.