running MPLAB simulation

Discussion in 'General Electronics Chat' started by sanwa, Mar 16, 2009.

  1. sanwa

    Thread Starter Active Member

    Jan 18, 2009
    36
    0
    Well guys ....
    How do I run simulation in MPLAB for .asm code?
    I just have the one on make files and build...
    Sorry i am new to MPLAB...
     
  2. t_n_k

    AAC Fanatic!

    Mar 6, 2009
    5,448
    782
  3. sanwa

    Thread Starter Active Member

    Jan 18, 2009
    36
    0
    I was testing my code on UART:
    Code ( (Unknown Language)):
    1.     list            p=16F88, r=DEC
    2.     errorlevel        -302
    3.     #include         <p16f88.inc>
    4.  
    5.     __config         _CONFIG1, _BODEN_OFF & _WDT_OFF & _LVP_OFF & _MCLR_OFF & _PWRTE_ON & _INTRC_IO
    6.  
    7. ;----------------------
    8. ; DECLARE VARIABLES
    9. ;----------------------
    10.  
    11. cblock            0x20
    12. tmp1
    13. endc
    14.  
    15. ;----------------------
    16. ; START
    17. ;----------------------
    18.     org         0
    19. main
    20.     banksel        CMCON
    21.     movlw         7
    22.     movwf         CMCON                ; CMCON = 7 set comperators off
    23.  
    24.     banksel        ANSEL
    25.     clrf        ANSEL
    26.  
    27.     banksel        TRISA
    28.     clrf        TRISA
    29.     clrf        TRISB
    30.  
    31.     banksel        SPBRG
    32.     movlw        0x19                ; 0x19=9600 bps (0x0C=19200 bps)
    33.     movwf        SPBRG
    34.     movlw        b'00100100'            ; brgh = high (2)
    35.     movwf        TXSTA                ; enable Async Transmission, set brgh
    36.  
    37.     banksel        RCSTA
    38.     movlw         b'10010000'            ; enable Async Reception
    39.     movwf        RCSTA
    40.  
    41.  
    42.     ; Provide a settling time for startup
    43.     banksel        tmp1
    44.     clrf         tmp1
    45. settle
    46.     decfsz         tmp1, f
    47.     goto         settle
    48.  
    49.  
    50.     ; Send a character through the UART
    51. loop
    52.     movlw        'A'
    53.     call        send
    54.  
    55.     movlw        'B'
    56.     call        send
    57.  
    58.     goto        $
    59.  
    60. ;----------------------
    61. ; SEND function
    62. ;----------------------
    63. send
    64.     banksel        TXREG
    65.     movwf         TXREG                ; Send data which has been stored in W
    66.  
    67. trans_wt
    68.     banksel        TXSTA
    69.     btfss         TXSTA, TRMT            ; Loop until data is sent
    70.     goto        trans_wt        
    71.     return
    72.  
    73.     end
    I am refering to section 18.7 which using USART/UART. I followed the steps...I get this message when i build it:

    Code ( (Unknown Language)):
    1. UART-W0004: Attempt to receive data when Port pin direction for UART is set to an output (0).
    Am i correct or....?
     
  4. t_n_k

    AAC Fanatic!

    Mar 6, 2009
    5,448
    782
    From Section 11 of PIC16F88 user guide

    "Bit SPEN (RCSTA<7>) and bits TRISB<5,2> have to
    be set in order to configure pins, RB5/SS/TX/CK and
    RB2/SDO/RX/DT, as the Universal Synchronous
    Asynchronous Receiver Transmitter."

    From what I can see in your .asm code you've only cleared TRISB ....
     
  5. sanwa

    Thread Starter Active Member

    Jan 18, 2009
    36
    0
    well....becoz i juz wants to send data ONLY...;)
     
  6. t_n_k

    AAC Fanatic!

    Mar 6, 2009
    5,448
    782
    Maybe you have to set RB5 for transmit to happen ...?
     
  7. t_n_k

    AAC Fanatic!

    Mar 6, 2009
    5,448
    782
    One of the annoying things about PIC programming is the occasional imponderable - particularly with port lines.

    I am using a PIC18Fxxx to transmit data - no receive required.

    In the PIC18F case it is the TRISC register bits 6 & 7 that are equivalent to to TRISB bits 5 & 2.

    I normally just configure USART port TRISC to 0xC0 without much consideration.

    If I clear my TRISC [bits 6 & 7 low] - transmission stops altogether.

    If I set TRISC to 0x40 [bit 6 high] I don't get transmission.

    If I set TRISC to 0x80 or 0xC0 [bit 7 high - bit 6 don't care] transmission starts.

    It looks like the bit for RX/DT or RB2/SDO/RX/DT in your case must be set for transmit to occur.

    Go figure ...?:confused:
     
  8. t_n_k

    AAC Fanatic!

    Mar 6, 2009
    5,448
    782
    Sorry - ignore that last post. I was looking at the wrong code. The module involved does receive data. Disabling the receive line would cause it to stop anyway.

    I can't explain your problem.
     
Loading...