Assembly code indexing problem?

Discussion in 'OT Technology' started by konrad109, May 9, 2008.

  1. konrad109

    konrad109 New Member

    Joined:
    Jan 6, 2006
    Messages:
    4,153
    Likes Received:
    0
    Location:
    Chicago, IL
    I've been at this for so long, my brain is fried, if you guys are interested in this stuff, maybe you can see a problem I simply cannot see. All it is is a microcontroller hooked up to a GPS module that spits out NMEA data over a serial line.

    All this device is supposed to do is determine if a hardcoded GPS coordinate is N,S,E, or W from your current position. North and South work perfectly, but West and East are weird, I think there is some indexing issue. The GPS continually sends data in ASCII, refreshing every second. I bring in the ASCII values 1 at a time (1 byte of data) using the ReadSCI command.

    Basically the way it works is it grabs data bytes from the GPS device, looking for the flag "GG" which indicates the start of the data that I want. I have a hardcoded "destination" in the RAM, which is then compare to the data as it flows in the from the GPS. This is what the GPS sends to the microcontroller, each letter or number is 1 byte of data brought in through 1 call of the READSCI routine:

    [​IMG]

    Basically I start from the most significant GPS coordinate (the one that changes the least), and work my way down, untill they coordinate coming from the GPS and the hardcoded one do not match, then I break out and simply write an "N" or an "S" to give a simple indication of where I am. Because the GPS values between destination and current position can be different at either 2 bytes after the decimal or 3 or other, I have to keep an index that continues to pull in data from the GPS to get me to the longitude coordinates afterwards. I think the problem lies somewhere here because I cannot get the microcontroller to determine the longitude (east-west) correctly, so the problem would lie somewhere in the WeAreS or WeAreN subroutine. Here is the output of the of the microcontroller:

    [​IMG]

    Code follows.
     
  2. konrad109

    konrad109 New Member

    Joined:
    Jan 6, 2006
    Messages:
    4,153
    Likes Received:
    0
    Location:
    Chicago, IL
    Code:
    ;start of code
     ;Destination N-S Hardcoded Lat
     LDAA #$34 ;4
     STAA $0040  
     LDAA #$31 ;1
     STAA $0041
     LDAA #$35 ;5
     STAA $0042 
     LDAA #$38 ;8
     STAA $0043
     LDAA #$2E ;.
     STAA $0044
     LDAA #$31 ;1
     STAA $0045
     LDAA #$33 ;3
     STAA $0046
     LDAA #$31 ;1
     STAA $0047
     LDAA #$36 ;6
     STAA $0048
     ;Destination E-W Hardcoded Long 
     LDAA #$30 ;0
     STAA $0050  
     LDAA #$38 ;8
     STAA $0051
     LDAA #$37 ;7
     STAA $0052 
     LDAA #$34 ;4
     STAA $0053
     LDAA #$37 ;7
     STAA $0054
     LDAA #$2E ;.
     STAA $0055
     LDAA #$38 ;8
     STAA $0056
     LDAA #$33 ;3
     STAA $0057
     LDAA #$37 ;7
     STAA $0058
     LDAA #$35 ;5
     STAA $0059
    B0:
    S0 
     LDAA #$54 
     JSR  WriteSCI
     NOP
    S1 LDX #$0040 ;index register for start of Hardcoded Latitude 
     LDY  #$0050 ;index register for start of Hardcoded Longitude
     JSR  ReadSCI ;take in one byte of data from GPS
     CMPA  #$47 l;compare it to ASCII value "G"
     BEQ  FOUNDG1 ;BRANCH IF EQUAL TO G
     BRA S1 ;else go back
    FOUNDG1 JSR  ReadSCI ;get next byte of data from GPS
     CMPA  #$47 ;compare it to ASCII value "G"
     BEQ  FOUNDG2 ;BRANCH IF EQUAL TO G
     BRA S1 ;else go back to the beginning
    FOUNDG2 JSR  ReadSCI ;A
     JSR  ReadSCI ;,
     JSR  ReadSCI ;h
     JSR  ReadSCI ;h
     JSR  ReadSCI ;m
     JSR  ReadSCI ;m ;skip the next 14 bytes 
     JSR  ReadSCI ;s ;to get to the first
     JSR  ReadSCI ;s ;latitude coordinate
     JSR  ReadSCI ;.
     JSR  ReadSCI ;s
     JSR  ReadSCI ;s
     JSR  ReadSCI ;s
     JSR  ReadSCI ;,
     JSR  ReadSCI ;first north coordinate is now in Register A
    NORTH JSR  WriteSCI ;display the latitude coordinate
     CMPA  $00,X ;compare it to the stored value for the Hardcoded latitude 
     BGT WeAreN  ;if current latitude > destination, we are north of it
     CMPA $00,X
     BLT WeAreS ;if current latitude < destination, we are south of it
     INX  ;increment the index to get to the next hardcoded coordinate 
     JSR  ReadSCI   ;get next north coordinate 
     CMPA #$4E ;NORTH STOP FLAG
     BNE NORTH ;still comparing latitude coordinates, go back
    W1 JSR  ReadSCI ;otherwise skip the next two bytes to get to the first
     JSR  ReadSCI ;Longitude coordinate
    WEST JSR  WriteSCI;display longitude coordinate
     CMPA  $00,Y ;comapare it with indexed Hardcoded longitude coordinate
     BGT WeAreW  ;if current long > destination, we are west of it
     CMPA $00,Y
     BLT WeAreE  ;if current long < destination, we are east of it
     INY  ;incrememtn the index to get to next hardcoded coordinate
     JSR  ReadSCI
     CMPA #$57 ;WEST STOP FLAG
     BNE WEST ;we are still reading longitude coordinates so go back
    Back BRA  S1 ;we are done here, go back to the very beginning
    ;--Pre-subroutines
    WeAreN
     LDAA #$4E ;ASCII value for "N"
     JSR WriteSCI ;display "N" to show that we are north of destination
     LDAA #$20 ;space
     JSR WriteSCI ;dispaly two spaces to make it more readable
     JSR WriteSCI 
    R1 JSR ReadSCI ;get the next coordinate 
     JSR WriteSCI ;write it
     INX  ;increment the index,
     CPX #$0050 ;we need to parse through the GPS bytes to get to the first Long coordinate
     BNE R1  ;we are not there yet so go back to the loop
     BRA W1  ;we are there, go back to compare the west coordinates
    WeAreS 
     LDAA #$53 ;S
     JSR WriteSCI
     LDAA #$20 ;space
     JSR WriteSCI
     JSR WriteSCI
    Z1 JSR ReadSCI
     JSR WriteSCI
     INX 
     CPX #$0050
     BNE Z1
     BRA W1
    WeAreW
     LDAA #$57 ;Display "W" to indicate we are west
     JSR WriteSCI
     JMP S1  ;go back to the very beginning
    WeAreE
     LDAA #$45 ;E
     JSR WriteSCI
     JMP S1
    ;end of code
    ;-----------------------------------------------------------
    ;BELOW ARE ALL THE SUBROUTINES
    ;-----------------------------------------------------------------
    ;Writregister sends data through the SPI system, it will send whatever is in Accumulator A
    WriteRegister:
            STAA SPDR; sends command to send out the data
            BRCLR SPSR, Y, $80, *;
            ;BSET PortA, Y, $10; sets PA4 to fire register enable
            NOP;
            ;BCLR PortA, Y, $10; clears PA4
            NOP;
            RTS
    ;-----------------------------------------------------------
    ;This subroutine loads Accumulator A from SCI input
    ReadSCI:
    TW BRCLR SCSR $20 TW;
            LDAA SCDR;
            RTS
    ;------------------------------------------------------
    ;WriteSCI takes what ever is in accumulator A and sends it throug the SCI
    WriteSCI:
     STAA SCDR 
    TR BRCLR SCSR $80 TR;break here if clear, so waiting for it to turn 1
     RTS
    
    crap this isnt gonna work with the indentations.
     
  3. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    It would help to see an example of what the output should look like.
     

Share This Page