Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

assembally code register addressing

  • 21-01-2005 5:54pm
    #1
    Closed Accounts Posts: 35


    dunno if anyone here does embedded programming, if ya do Ive a little knot I need some help with
    Im working with a 87C552, an 8051 derivative, and am reading a number from a keypad to use as an Id to select a servo motor to run PWM to.
    1) I have the keypad scan function saving the kay value to the accumulator.
    2) I have the current PWM value for each of the 5 motors stored in registers 1 to 5

    How do I use the number in the accumulator to select the information in the relevant register?
    IE
    if A = 3
    then
    move data from R3 to PWM0


Comments

  • Hosted Moderators Posts: 7,486 ✭✭✭Red Alert


    think you might have a prob here. you sure you need to use the registers as you could use indexed addressing on the main memory much easier.


  • Closed Accounts Posts: 35 toblerone


    for anyone interested this is how I did it, the code needed overall restructre and I still didnt get around to working out the exact PWM values, but theese will be XTAL and servo specific (I used a 16MHz XTAL)

    Well it was gonna go hear but board post size restrictions stopped me, cos its to long.
    If ya wanna know post to that effect and I'll split it up to vbulletin freindly bitesize chunks!


  • Closed Accounts Posts: 1,541 ✭✭✭finnpark


    Maybe I am missing something but can you not do this:

    MOV B,A ; Stores ACC in B reg

    ANL A,#03H ; Puts everything else to 0

    CJNE A,#03H,NOT_THREE ;Compares acc to 3(hex and dec the same for 3)-;COMPARE JUMP TO LABEL IF NOT EQUAL ELSE GO TO NEXT LINE IF EQUAL

    MOV PWM0,R3

    MOV A,B ;Puts value back in A

    ;rest of program
    -
    -
    -
    -
    -

    NOT_THREE: MOV A,B

    ;rest of program
    -
    -
    -
    -
    -


  • Closed Accounts Posts: 35 toblerone


    i actually did something very like that here is one of the subroutines that used a checking matrix:
    loadValue:
    /********************************************************
    *	This function uses the keyID in the ACC, to	*
    *select the correct register from which it obtains the 	*
    *corresponding current motor's PWM value and loads it to*
    *the PWM0. Then returns					*
    ********************************************************/
    	
    	CJNE A, #01H, mov1skip	/*IF 1 COPY FROM R1*/
    	MOV PWM0, R1		/*MOV CURRENT M1 VALUE TO PWM0*/
    	JMP endSkip		/*JUMP TO END OF FUNCTION*/
    mov1skip:
    	CJNE A, #02H, mov2skip	/*IF 2 COPY FROM R2*/
    	MOV PWM0, R2		/*MOV CURRENT M2 VALUE TO PWM0*/
    	JMP endSkip		/*JUMP TO END OF FUNCTION*/
    mov2skip:
    	CJNE A, #03H, mov3skip	/*IF 3 COPY FROM R3*/
    	MOV PWM0, R3		/*MOV CURRENT M3 VALUE TO PWM0*/
    	JMP endSkip		/*JUMP TO END OF FUNCTION*/
    mov3skip:
    	CJNE A, #04H, mov4skip	/*IF 4 COPY FROM R4*/
    	MOV PWM0, R4		/*MOV CURRENT M4 VALUE TO PWM0*/
    	JMP endSkip		/*JUMP TO END OF FUNCTION*/
    mov4skip:
    	CJNE A, #05H, mov5skip	/*IF 5 COPY FROM R5*/
    	MOV PWM0, R5		/*MOV CURRENT M5 VALUE TO PWM0*/
    	JMP endSkip
    mov5skip:
    	CJNE A, #06H, mov6skip	/*IF 6 COPY FROM R1*/
    	MOV PWM0, R1		/*MOV CURRENT M1 VALUE TO PWM0*/
    	JMP endSkip		/*JUMP TO END OF FUNCTION*/
    mov6skip:
    	CJNE A, #07H, mov7skip	/*IF 7 COPY FROM R2*/
    	MOV PWM0, R2		/*MOV CURRENT 2 VALUE TO PWM0*/
    	JMP endSkip		/*JUMP TO END OF FUNCTION*/
    mov7skip:
    	CJNE A, #08H, mov8skip	/*IF 8 COPY FROM R3*/
    	MOV PWM0, R3		/*MOV CURRENT M3 VALUE TO PWM0*/
    	JMP endSkip		/*JUMP TO END OF FUNCTION*/
    mov8skip:	
    	CJNE A, #09H, mov9skip	/*IF 9 COPY FROM R4*/
    	MOV PWM0, R4		/*MOV CURRENT M4 VALUE TO PWM0*/
    	JMP endSkip		/*JUMP TO END OF FUNCTION*/
    mov9skip:
    	CJNE A, #10H, endSkip	/*IF 10 COPY FROM R5*/
    	MOV PWM0, R5		/*MOV CURRENT M5 VALUE TO PWM0*/
    	JMP endSkip		/*JUMP TO END OF FUNCTION*/
    endSkip:RET			/*RETURN TO MAIN*/
    


Advertisement