list p=16f877a
#include "P16F877A.INC"
__CONFIG _LVP_OFF &_WDT_OFF &_PWRTE_OFF &_CP_OFF & _XT_OSC
;STATUS EQU 0x03 ; all system registers are specifield in the ".INC" file
;PORTC EQU 07H
;TRISC EQU 87H
;TXSTA EQU 98h
;RCSTA EQU 18H
;SPBRG EQU 99H
;TXREG EQU 19H
;PIR1 EQU 0CH
cblock 0x20 ; define work registers for delay
d1,d2,d3
endc
ORG 0x00
clrf PORTC
banksel TRISC
clrf TRISC ; make port C outputs
banksel SPBRG ; set up based on 4Mhz oscillator
MOVLW D'25'
MOVWF SPBRG
MOVLW B'00100100'
MOVWF TXSTA
banksel RCSTA
BSF RCSTA,SPEN
BANKSEL TRISC
BCF TRISC,6
clrw
again
MOVLW 'a'
here
banksel PIR1
btfss PIR1,TXIF
goto here
BANKSEL TXREG
MOVWF TXREG
call delay250 ; so you can see the characters being sent
goto again
;Delay sub routine
delay250 movlw d'250' ; delay 250 ms
movwf d1
dly250_1 movlw 0xC7
movwf d2
movlw 0x01
movwf d3
dly250_2
decfsz d2, f
goto dly250_3
decfsz d3, f
dly250_3 goto dly250_2
decfsz d1 ,f
goto dly250_1
retlw 0x00
END