asp1987
New Member
Hi..
I am trying to initialise PIC UART at 115200 baud rate.I wrote a small program for that purpose and used oshonsoft simulator's Oscilloscope tool for viewing the output of the TRANSMIT pin. Two problems..
1. It always remain low. 'U' is 01010101.so there should be HIGHs and LOWs,right?
2. It takes about 1000uS to transmit character 'U' at 20 Mhz(16F877A).Shouldn't it be around 86.8 uS(8 data+1 stop+1 start bit)?
Plz tell me if there is any mistakes in the code.
;--------------------------------------------------------
begin
bcf STATUS,RP1
bcf STATUS,RP0
;Interrupts
bcf INTCON,GIE ;turn gie off
btfsc INTCON,GIE
goto begin
;----------------------------------------------------
bsf STATUS,RP0 ;bank1
movlw 0x00
movwf TRISA
movwf TRISB
movwf TRISD
movwf TRISE
;----------------------------------------------------
;asynchronous-settings
movlw 0xC0 ; rc7 and rc6 as inputs
movwf TRISC ; 11000000 to trisc
movlw 0x0A ;(0x0A=115200 bps)
movwf SPBRG
movlw b'00100100' ;brgh = high
movwf TXSTA ;enable Async Transmission, set brgh
bcf STATUS, RP0 ;select bank 0
movlw b'10010000' ;enable Async Reception
movwf RCSTA
;-----------------------------------------------------
;PIE1,RCIE
bsf STATUS, RP0 ;select bank 1
bsf PIE1, RCIE ;enable interups on USART receive
bcf STATUS, RP0 ;select bank 0
;------------------------------------------------------
bsf INTCON, PEIE ;enable Peripheral interupts
bsf INTCON, INTE ;enable RB0/INT interupts
bsf INTCON, GIE ;global interrupt enable
;--------------------------------------------------
; code starts
movlw d'3'
movwf 0x20
abcd
movlw 0x55
call Send
decfsz 0x20,1
goto abcd
eh
nop ;so that i can see the transmission stopped
goto eh
;--------------------------------------------------------------------
Send
movwf TXREG
TransmitWait
bsf STATUS,RP0 ; bank1
WaitHere
btfss TXSTA,TRMT ;transmission is complete if high
goto WaitHere
bcf STATUS,RP0 ;bank0
return
;--------------------------------------------------------------------
I am trying to initialise PIC UART at 115200 baud rate.I wrote a small program for that purpose and used oshonsoft simulator's Oscilloscope tool for viewing the output of the TRANSMIT pin. Two problems..
1. It always remain low. 'U' is 01010101.so there should be HIGHs and LOWs,right?
2. It takes about 1000uS to transmit character 'U' at 20 Mhz(16F877A).Shouldn't it be around 86.8 uS(8 data+1 stop+1 start bit)?
Plz tell me if there is any mistakes in the code.
;--------------------------------------------------------
begin
bcf STATUS,RP1
bcf STATUS,RP0
;Interrupts
bcf INTCON,GIE ;turn gie off
btfsc INTCON,GIE
goto begin
;----------------------------------------------------
bsf STATUS,RP0 ;bank1
movlw 0x00
movwf TRISA
movwf TRISB
movwf TRISD
movwf TRISE
;----------------------------------------------------
;asynchronous-settings
movlw 0xC0 ; rc7 and rc6 as inputs
movwf TRISC ; 11000000 to trisc
movlw 0x0A ;(0x0A=115200 bps)
movwf SPBRG
movlw b'00100100' ;brgh = high
movwf TXSTA ;enable Async Transmission, set brgh
bcf STATUS, RP0 ;select bank 0
movlw b'10010000' ;enable Async Reception
movwf RCSTA
;-----------------------------------------------------
;PIE1,RCIE
bsf STATUS, RP0 ;select bank 1
bsf PIE1, RCIE ;enable interups on USART receive
bcf STATUS, RP0 ;select bank 0
;------------------------------------------------------
bsf INTCON, PEIE ;enable Peripheral interupts
bsf INTCON, INTE ;enable RB0/INT interupts
bsf INTCON, GIE ;global interrupt enable
;--------------------------------------------------
; code starts
movlw d'3'
movwf 0x20
abcd
movlw 0x55
call Send
decfsz 0x20,1
goto abcd
eh
nop ;so that i can see the transmission stopped
goto eh
;--------------------------------------------------------------------
Send
movwf TXREG
TransmitWait
bsf STATUS,RP0 ; bank1
WaitHere
btfss TXSTA,TRMT ;transmission is complete if high
goto WaitHere
bcf STATUS,RP0 ;bank0
return
;--------------------------------------------------------------------