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

can't find what's wrong

Maybe someone can help me out. I thought I solved the problem, but something else seems to be wrong.
I have a project using a 87C51RA+ using only on chip Ram and Rom. I have three _at_ definitions pointing at 0x2000, 0x4000, 0x6000. I have a DIP switch I connected to address 0x6000 which determines the program to run. The program runs OK in the simulator, but on board only parts of the program seem to run. eventhough they more or less use all the same variables. Unfortunately I havn't got a emulator to see what I'm going wrong. Any suggestions on (standard) things people seem to get wrong when things like this happen. I include a piece of code, this is really the only (big) difference between the part that works and the part that doesn't


void timer0(void) interrupt 1 using 3{
		d++;
		m++;
		TH0  = TH_temp;
		TL0  = TL_temp;
		}

	void delay(x, TH_temp, TL_temp){
		m = 0;
		TH0  = TH_temp;
		TL0  = TL_temp;
		while(m < x){}
		}

this works ok in the simulator and I think it shouldn't cause any trouble, just grasping at straws maybe.

Any help would be greatly appreciated

Regards

John

  • suggestions on (standard) things people seem to get wrong

    - not declaring the shared variables (m, perhaps d) <v>volatile

    - not initializing memory and/or the variables in question

    More description of the symptoms -- exactly what does and doesn't happen -- might help. It's hard to guess what your code does without seeing it.

    Unfortunately I havn't got a emulator to see what I'm going wrong

    Get an emulator :) Or at least a serial monitor debugger. You've got MON and uVision, right?

  • Thanks for your reply Drew.... Appreciated.

    Unfortunately I'm still stuck.
    I'll include some more code, maybe you'll see something I'm missing. Must be something completely stupid.

    uchar volatile selection = 0;
    volatile uchar k = 0;
    sbit deresens	= P1^3;
    
    
    		while(selection == 0x01){
    			deresens = 0;
    			modus();
    			op_mode = mode_all[k];
    			man_in();
    				}
    
    
    		while(selection == 0x02){
    			deresens = 1;
    			modus();
    			if(k == 1){
    			op_mode = 0x00;
    			}
    			if(k == 2){
    			op_mode = 0x02;
    			man_out();
    				}
    			}
    
    

    Well this is what it's supposed to do. Determined by an external DIP switch selection is set to a certain state, which in turn selects the program to run. Selection is only updated after a hard reset. This part works (I can see this on an external Led panel) When selection = 0x01 the output bit deresens P1^3 should be "0". When selection == 0x02 deresens should be "1". The later does not function for some reason, while I know for a fact that selection == 0x02.

    Somewhere else in the program the bit deresens is succesfully set and cleared. I guess it must be something with initialising the variables somewhere.
    variable "k" is set in the modus function. I could understand if this didn't work, but deresens hasn't any conditional jumps anymore so should functional (I think).... :)

    About your comment regarding using uV2 with monitor, this could of course be done, but I have never worked with "Mon51 or ISD51" and seeing as I'm a bit pressed for time I havn't the time right now to start the learning curve. Besides that, this application has quite a bit of data going over the Comm port and I not sure if this would work. But as I said, I've never worked with it.
    Up to now I've been very succesful using just the simulator. I think I said in my last posting, everything works fine in the simulator.

    Hoping you'll see something.... If it is something stupid, you have my permission to call me completely stupid :)

    Regards
    John

  • I thought I'd give some additional information, sorry for the fragmented post. As you can see, part of the listing file.

     111   2                      while(selection == 0x02){
     112   3                              deresens = 1;
     113   3                              modus();
     114   3                              if(k == 1){
     115   4                              op_mode = 0x00;
     116   4                              }
     117   3                              if(k == 2){
     118   4                              op_mode = 0x02;
     119   4                              man_out();
     120   4                                      }
     121   3                              }
    
    
    
                                               ; SOURCE LINE # 111
    002D E500        R     MOV     A,selection
    002F B4021F            CJNE    A,#02H,?C0013
                                               ; SOURCE LINE # 112
    0032 D293              SETB    deresens
                                               ; SOURCE LINE # 113
    0034 120000      E     LCALL   modus
                                               ; SOURCE LINE # 114
    0037 E500        R     MOV     A,k
    0039 B40105            CJNE    A,#01H,?C0011
                                               ; SOURCE LINE # 115
    003C 900000      E     MOV     DPTR,#op_mode
    003F E4                CLR     A
    0040 F0                MOVX    @DPTR,A
                                               ; SOURCE LINE # 116
    0041         ?C0011:
                                               ; SOURCE LINE # 117
    0041 E500        R     MOV     A,k
    0043 B402E7            CJNE    A,#02H,?C0009
                                               ; SOURCE LINE # 118
    0046 900000      E     MOV     DPTR,#op_mode
    0049 7402              MOV     A,#02H
    004B F0                MOVX    @DPTR,A
                                               ; SOURCE LINE # 119
    004C 120000      E     LCALL   man_out
                                               ; SOURCE LINE # 120
    
    004F         ?C0012:
                                               ; SOURCE LINE # 121
    

    It looks like deresens is "set" from here. I have already set the optimiser to "0 = costant folding". I read on the forum that this sometimes could cause a problem. But unfortunately not in my case.

    Regards
    John

  • Found it.... :)

    In the above op_mode is an output....
    In my code I was reading an output with an " if(op_mode == 0x20)" which apparantly can't be done. Altered the code somewhat and all is well. At least I don't feel completely stupid, I mean, I did find it myself. Anyway thanks for the backup

    Regards
    John