Shop OBEX P1 Docs P2 Docs Learn Events
Problem With Code Terry Can you Help — Parallax Forums

Problem With Code Terry Can you Help

SailerManSailerMan Posts: 337
edited 2009-05-28 17:19 in General Discussion
I was working with Jonny Mac on some code He wrote and I am have a problem getting it to work correctly. I am attaching the code.

Everything runs fine until I Change the pins...

The Unaltered Code block...
Sio             PIN     RD.7  INPUT  TTL    ' I/O to host (10K pull-up)

M2Pwm           PIN     RC.2  OUTPUT
M2InA           PIN     RC.1  OUTPUT
M2InB           PIN     RC.0  OUTPUT





And now my changes to accomidate a circuit board I designed.

Sio             PIN     RD.7  INPUT  TTL    ' I/O to host (10K pull-up)

M2Pwm           PIN     RC.2  OUTPUT
M2InA           PIN     RD.1  OUTPUT
M2InB           PIN     RD.0  OUTPUT





We can't figure out why when M2InA and M2InB are changed to port D pins the program does not transmit serial properly.

Transmit:
  ASM
    MOV   FSR, #serial                          ' (2)
    TEST  txCount                               ' (1)   transmitting now?
    JZ    TX_Done                               ' (2/4) if txCount = 0, no
    DEC   txDivide                              ' (1)   update bit timer
    JNZ   TX_Done                               ' (2/4) time for new bit?
    MOV   txDivide, #Baud1x0                    ' (2)   yes, reload timer
    STC                                         ' (1)   set for stop bit
    RR    txHi                                  ' (1)   rotate TX buf
    RR    txLo                                  ' (1)
    DEC   txCount                               ' (1)   update the bit count
    MOV   W, #$0F                               ' (1)   read TRIS_A
    MOV   M, W                                  ' (1)
    MOV   !RD, W                                ' (1)
    MOV   tmpTris, W                            ' (1)   copy to tmpTris
    MOVB  tmpTris.7, txLo.6                     ' (4)   new bit to tris
    MOV   W, #$1F                               ' (1)   update TRIS_A
    MOV   M, W                                  ' (1)
    MOV   !RD, tmpTris                          ' (1)

TX_Done:
  ENDASM



Can you help?

Comments

  • JonnyMacJonnyMac Posts: 9,213
    edited 2009-05-28 02:38
    Terry,

    I can vouch for this the program runs fine until you try to change the status of the RD.1 and RD.0 bits, and this makes absolutely no sense at all.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2009-05-28 06:50
    I don't think the error is this

    · PLP_C = %0000_0111
    · PLP_D = %1000_0000

    but port C and port D have different pullup settings on pins 0 and 1.

    regards peter


    Post Edited (Peter Verkaik) : 5/28/2009 7:09:54 AM GMT
  • BeanBean Posts: 8,129
    edited 2009-05-28 11:54
    I'm not sure if this is the problem, but I suspect it is.

    Try adding a "CLRB Sio" after the "MOV !RD,tmpTris" in the transmit routine.

    Try this program below to show the cause of this problem.



    DEVICE SX28, OSCXT1 
    FREQ 10_000_000 
    
     
    OUT1 PIN RB.0 OUTPUT PULLUP 
    OUT2 PIN RB.1 OUTPUT PULLUP 
    
    PROGRAM Start NOSTARTUP 
    
     
    Start: 
      OUTPUT OUT1  ' Make OUT1 an output 
      OUT1 = 0     ' Set OUT1 output latch to low 
      INPUT OUT1   ' Make OUT1 an input (pullup will make OUT1 high) 
    
     
      OUT2 = 0 ' Here is what causes the problem. 
               ' To make OUT2 low, the controller reads the WHOLE port, when it does this OUT1 will read as high because of the pullup. 
               ' Now it sets the OUT2 bit to zero, and writes the WHOLE port back (this causes OUT1 output latch to be set to a 1) 
    
     
      OUTPUT OUT1 ' When we make OUT1 an output, it is high now. 
    END
    

    Bean.

    P.S. "MOV !RD,tmpTris" is a 2 cycle instruction "MOV W,tmpTris", "MOV !RD,W"






    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There is a fine line between arrogance and confidence. Make sure you don't cross it...



    Post Edited (Bean (Hitt Consulting)) : 5/28/2009 12:31:29 PM GMT
  • JonnyMacJonnyMac Posts: 9,213
    edited 2009-05-28 16:58
    Okay, I think I get it now... when the Sio pin is in an input state (reading incoming serial) the output bit can RD.7 can be set to a "1" because of the pull-up and the stop bit ("1" in true mode). D'oh!

    Eric, the version attached uses your original connections and I've verified that the code is now talking back (to a Stamp).

    Post Edited (JonnyMac) : 5/28/2009 5:03:18 PM GMT
  • SailerManSailerMan Posts: 337
    edited 2009-05-28 17:19
    Bean,

    Thanks.. for picking though out.

    Jon,

    Thanks for all of your help and your code. I'll be playing with this when I get home tonight.

    Best Regards to Both,
    Eric
Sign In or Register to comment.