I am writing a test program that will continuously transmit a byte of data using UART through pin RC6/TX only if RB0 is high. I won't have any access to any test equipment for a couple days so I was wondering, is it possible to simulate this in MPLAB/MPSIM?
Also here is the code, though I haven't tested it in hardware yet.
Also here is the code, though I haven't tested it in hardware yet.
Code:
databyte RES 1
count1 RES 1
counta RES 1
countb RES 1
main
start
call Init
call InitSer
movlw b'10010110'
movwf databyte
loop1
btfss PORTB, 0
goto loop1
bsf STATUS, RP0
bsf TXSTA, TXEN ;enable Transmit
bcf STATUS, RP0
movf databyte, W
movwf TXREG ;put data in register TXREG
call Delay255
call Delay255
call Delay255
call Delay255
goto loop1
;subroutines
Init
clrf PORTB
clrf PORTC
bsf STATUS, RP0
movlw 0x80
movwf TRISC ;RC7 - input, RC6 - output
movlw 0xFF
movwf TRISB ;PORTB - inputs
bcf STATUS, RP0
return
InitSer
bsf RCSTA, 7 ;enable RC6, RC7 for UART
bsf STATUS, RP0
movlw 0xC0
movwf TRISC ;enable RC6, RC7 for UART
movlw d'25'
movwf SPBRG ;2.4KBAUD, 0.17% ERROR
bcf TXSTA, BRGH ;Asynchronous mode: low speed
bcf TXSTA, SYNC ;USART mode: asynchronous
bcf TXSTA, TX9 ;eight bit transmission
bcf STATUS, RP0
return
Delay255
....
....
.... etc.
END ; directive 'end of program'
Last edited: