150 likes | 401 Views
PIC 16F877 and Serial communication. Serial communication. movlw d’129’ ; 9600 @20Mhz movwf SPBRG. movlw b'00100100' ; brgh = 1 movwf TXSTA ; enable Async Transmission, set brgh banksel RCSTA ; bank0 movlw b'10010000' movwf RCSTA ; enable Async Reception. RecLoop nop
E N D
PIC 16F877 and Serial communication Serial communication
movlw d’129’ ; 9600 @20Mhz movwf SPBRG movlw b'00100100' ; brgh = 1 movwf TXSTA ; enable Async Transmission, set brgh banksel RCSTA ; bank0 movlw b'10010000' movwf RCSTA ; enable Async Reception
RecLoop nop btfss PIR1,RCIF ; check for received data goto RecLoop movf RCREG,w return TxLoop nop btfss PIR1,TXIF ;xmit buffer empty? goto TxLoop ;no, wait movwf TXREG return Reception and transmit loops
Subroutine for reading and Writing Reading int c; int PORT1=0x2F8; c = inp(PORT1 + 5); If (c & 1==1) { myvalue = inp(PORT1); } …… Writing: c = inp(PORT1 + 5); If (((c&0x20)>>5)==1) {outp(PORT1,value)};