Erwin_Macaraig
New Member
I am programming a PIC16F877 serial port. I am trying to send to the serial port the character 'e'. I am using hyperterminal to view the said character. I use 9600 baud rate, one stop bit,no parity and no hardware control settings. But the character I am trying to send to the hyperterminal does not seem to appear, mostly the its just a series of 1's and s.
here is my code. Your comments and suggestiions will be appreciated! Thank you in advance!!!
;source code(firmaware fragment) for the PIC16F877 serial communications
#include "P16f877.inc"
__config _wdt_off & _pwrte_on & _xt_osc & _boden_on & _wrt_enable_on & _lvp_off & _cpd_off
errorlevel -302
#define transmitEnable portc,5
cblock h'20'
temp
char
endc
org h'0000'
init
bcf STATUS,RP1
bsf STATUS,RP0 ;selects bank1
movlw b'10000000'
movwf TRISC ;makes pin7<RX> of portC input
movlw b'1000000' ;Fosc = 12Mhz
movwf SPBRG ;9600 baud rate hispeed
bsf TXSTA,BRGH ;bit2: High speed
bcf TXSTA,SYNC ;bit4: Asynchronous mode
bcf TXSTA,TX9 ;bit6: 8-Bit Transmit Enable bit
bcf PIE1,TXIE ;bit4: USART transmit Interrupt Enable bit
bsf TXSTA,TXEN ;bit5: Transmit enable bit
bcf STATUS,RP0 ;selects bank0
movlw b'10010000'
movwf RCSTA ;bit7: Serial Port Enable bit
bsf transmitEnable
main
call message_one
goto main
message_one
movlw d'101'
call sendit
call delay
call delay
call delay
return
sendit
btfss PIR1,TXIF ;poll bit4: Transmit Interrupt Flag
goto sendit
movwf TXREG
return
delay
movlw d'255'
movwf char
movwf temp
delayloop
decfsz char
goto delayloop
decfsz temp
goto delayloop
return
end
here is my code. Your comments and suggestiions will be appreciated! Thank you in advance!!!
;source code(firmaware fragment) for the PIC16F877 serial communications
#include "P16f877.inc"
__config _wdt_off & _pwrte_on & _xt_osc & _boden_on & _wrt_enable_on & _lvp_off & _cpd_off
errorlevel -302
#define transmitEnable portc,5
cblock h'20'
temp
char
endc
org h'0000'
init
bcf STATUS,RP1
bsf STATUS,RP0 ;selects bank1
movlw b'10000000'
movwf TRISC ;makes pin7<RX> of portC input
movlw b'1000000' ;Fosc = 12Mhz
movwf SPBRG ;9600 baud rate hispeed
bsf TXSTA,BRGH ;bit2: High speed
bcf TXSTA,SYNC ;bit4: Asynchronous mode
bcf TXSTA,TX9 ;bit6: 8-Bit Transmit Enable bit
bcf PIE1,TXIE ;bit4: USART transmit Interrupt Enable bit
bsf TXSTA,TXEN ;bit5: Transmit enable bit
bcf STATUS,RP0 ;selects bank0
movlw b'10010000'
movwf RCSTA ;bit7: Serial Port Enable bit
bsf transmitEnable
main
call message_one
goto main
message_one
movlw d'101'
call sendit
call delay
call delay
call delay
return
sendit
btfss PIR1,TXIF ;poll bit4: Transmit Interrupt Flag
goto sendit
movwf TXREG
return
delay
movlw d'255'
movwf char
movwf temp
delayloop
decfsz char
goto delayloop
decfsz temp
goto delayloop
return
end