LIST P=16F883,r=hex ;Set the radix as hex or decimal as needed, defualt is HEX
#include p16f883.inc
__config _CONFIG1, _FOSC_XT& _WDTE_OFF& _PWRTE_OFF& _MCLRE_OFF& _CP_OFF& _CPD_OFF& _BOR_OFF& _IESO_OFF& _FCMEN_OFF& _LVP_OFF& _DEBUG_OFF
__config _CONFIG2, _BOR21V& _WRT_OFF
;thach anh 3.686400 MHz
c1 equ 0x20
c2 equ 0x21
c3 equ 0x22
org 0x0000
goto start
start
banksel TRISC
movlw b'11000000' ;RC6=TX RC7=RX TRISC must be set to 1 for each bit
movwf TRISC
banksel ANSEL
clrf ANSEL
clrf ANSELH
banksel 0
call ser_init ; set up Usart 9600,8,1,none at with 4 Mhz osc
main_loop
movlw 'K' ; send out K
call tx_rs232
call rx_rs232 ; wait for any returned character
goto main_loop ; once a character received , loop again
tx_rs232 btfss PIR1, TXIF ; xmit buffer empty?
goto tx_rs232 ; no, wait
movwf TXREG ; now send
return
rx_rs232 btfss PIR1, RCIF ;check for received data
goto rx_rs232
movf RCREG,W
return
ser_init movlw d'5' ; 9600 baud @ 4 Mhz Fosc 8 bit Async
;ban dau 25 sua lai thanh 5
banksel SPBRG
movwf SPBRG ; BRGH=1
movlw b'00100000'
;ban dau 00100100 sua thanh 00100000
movwf TXSTA ;enable Async Transmission, set brgh
banksel 0
movlw b'10010000'
movwf RCSTA ;enable Async Reception
return
;--------------------------------------------------------------
delay
banksel 0
movlw .100 ;100 is declared in decimal. or use RADIX in LIST
movwf c1
loop2
movlw .50 ;50 is declared in decimal.
movwf c2
loop1
movlw .3 ;3 is declared in decimal.
movwf c3
decfsz c3, 1
goto $-1
decfsz c2, 1
goto loop1
decfsz c1, 1
goto loop2
return
;==============================================================
END