Thanks to everyone for helping on it. Gabriel.- ----- Original Message ----- From: Tony Nixon To: Sent: Tuesday, December 04, 2001 7:24 PM Subject: Re: Sample code for 16F627=B4s USART > Gabriel Caffese wrote: > > > > Hello everyone, > > > > Does anynoe have sample code for learning to use 16F627=B4s USART = ?? > > Any help//code would be appreciated. > > > > Thanks.- > > ; > Title "RS232 TEST" > ; > list P =3D 16F628 > ; > include "P16F628.inc" > > ; > ; CRYSTAL SPEED =3D 4000000Hz > ; > errorlevel -(305), -(302), -(306) > ; > ; ------------------ > ; CONFIGURATION FUSE > ; ------------------ > ; > __CONFIG _CP_OFF & _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & > _BODEN_OFF & _LVP_ON & _MCLRE_ON > > ; > ; -------------------- > ; USER RAM DEFINITIONS > ; -------------------- > ; > CBLOCK 0x20 > > RxHold > > ENDC > ; > ; probably not needed, but I do it anyway > ; > ; RX RB1 IN > ; TX RB2 OUT HI > > org 0000h > > Start movlw b'00000000' > movwf PORTA > movlw b'00000100' > movwf PORTB > bsf STATUS,RP0 > movlw b'00000000' > movwf TRISA > movlw b'00000010' > movwf TRISB > bcf STATUS,RP0 > ; > ; ----------------------- > ; DISABLE THE COMPARATORS > ; ----------------------- > ; > movlw b'00000111' ; disable comparators > movwf CMCON > ; > ; ---------------- > ; INITIALISE USART > ; ---------------- > ; Boot Baud Rate =3D 9600, No Parity, 1 Stop Bit > ; > bsf STATUS,RP0 > movlw d'25' ; 9600 baud > movwf SPBRG > movlw b'00100100' ; brgh =3D high (2) > movwf TXSTA ; enable Async Transmission, set brgh > movlw b'10010000' ; enable Async Reception > clrf STATUS ; RAM Page 0 > movwf RCSTA > > ; wait a short while before using > > call Receive ; wait for incoming byte > > movlw '1' ; send "16F628" > movwf TXREG > movlw '6' > movwf TXREG > call TransWt > movlw 'F' > movwf TXREG > movlw '6' > movwf TXREG > call TransWt > movlw '2' > movwf TXREG > movlw '8' > movwf TXREG > > Here goto Here > > ; > ; ------------------------------------ > ; WAIT UNTIL RS232 IS FINISHED SENDING > ; ------------------------------------ > ; > TransWt bsf STATUS,RP0 > WtHere btfss TXSTA,TRMT ; TX complete if hi > goto WtHere > > bcf STATUS,RP0 ; RAM Page 0 > return > ; > ; --------------------------- > ; RECEIVE CHARACTER FROM UART > ; --------------------------- > ; This routine does not return > ; until a character is received. > ; > Receive nop > btfss PIR1,RCIF ; check for received data > goto Receive > > movf RCREG,W > movwf RxHold ; tempstore data > return > > > > -- > Best regards > > Tony > > mICros > http://www.bubblesoftonline.com > mailto:sales@bubblesoftonline.com > > -- > http://www.piclist.com hint: The list server can filter out subtopics > (like ads or off topics) for you. See http://www.piclist.com/#topics > > -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.