| 1 |
;; The purpose of this program is to test gpsim's ability to simulate |
| 2 |
;; USART in the 14bit core. |
| 3 |
|
| 4 |
|
| 5 |
list p=16f877 |
| 6 |
__config _wdt_off |
| 7 |
|
| 8 |
|
| 9 |
include "p16f877.inc" |
| 10 |
|
| 11 |
#define RX_BUF_SIZE 0x10 |
| 12 |
|
| 13 |
cblock 0x20 |
| 14 |
|
| 15 |
temp1 |
| 16 |
temp2 |
| 17 |
|
| 18 |
w_temp |
| 19 |
status_temp |
| 20 |
fsr_temp |
| 21 |
|
| 22 |
tx_ptr |
| 23 |
rx_ptr |
| 24 |
rx_buffer : RX_BUF_SIZE |
| 25 |
|
| 26 |
|
| 27 |
endc |
| 28 |
org 0 |
| 29 |
|
| 30 |
goto start |
| 31 |
|
| 32 |
org 4 |
| 33 |
;; Interrupt |
| 34 |
;; |
| 35 |
movwf w_temp |
| 36 |
swapf status,w |
| 37 |
movwf status_temp |
| 38 |
|
| 39 |
bcf status,rp0 |
| 40 |
|
| 41 |
btfsc intcon,peie |
| 42 |
btfss pir1,rcif |
| 43 |
goto int_done |
| 44 |
|
| 45 |
;;; |
| 46 |
movf fsr,w |
| 47 |
movwf fsr_temp |
| 48 |
incf rx_ptr,w |
| 49 |
andlw 0x0f |
| 50 |
movwf rx_ptr |
| 51 |
addlw rx_buffer |
| 52 |
movwf fsr |
| 53 |
movf rcreg,w |
| 54 |
movwf indf |
| 55 |
movf fsr_temp,w |
| 56 |
movwf fsr |
| 57 |
|
| 58 |
int_done: |
| 59 |
swapf status_temp,w |
| 60 |
movwf status |
| 61 |
swapf w_temp,f |
| 62 |
swapf w_temp,w |
| 63 |
retfie |
| 64 |
|
| 65 |
;; ---------------------------------------------------- |
| 66 |
;; |
| 67 |
;; start |
| 68 |
;; |
| 69 |
start |
| 70 |
|
| 71 |
|
| 72 |
;; USART Initialization |
| 73 |
;; |
| 74 |
;; Turn on the high baud rate (BRGH), disable the transmitter, |
| 75 |
;; disable synchronous mode. |
| 76 |
;; |
| 77 |
|
| 78 |
clrf status |
| 79 |
|
| 80 |
bsf status,rp0 |
| 81 |
|
| 82 |
movlw (1<<BRGH) |
| 83 |
|
| 84 |
movwf txsta |
| 85 |
clrf spbrg ;Highest possible baud rate. |
| 86 |
|
| 87 |
movlw 0x80 ; Make rc7 input (RX pin). |
| 88 |
movwf trisc |
| 89 |
|
| 90 |
bcf status,rp0 |
| 91 |
|
| 92 |
;; Turn on the serial port |
| 93 |
movlw (1<<SPEN) | (1<<CREN) |
| 94 |
movwf rcsta |
| 95 |
|
| 96 |
movf rcreg,w |
| 97 |
bsf intcon,gie |
| 98 |
bsf intcon,peie |
| 99 |
|
| 100 |
bsf status,rp0 |
| 101 |
bsf pie1,rcie |
| 102 |
bcf status,rp0 |
| 103 |
|
| 104 |
rx_loop: |
| 105 |
|
| 106 |
bsf rcsta,cren |
| 107 |
btfss pir1,rcif |
| 108 |
goto $-1 |
| 109 |
|
| 110 |
bcf pir1,rcif |
| 111 |
|
| 112 |
goto rx_loop |
| 113 |
|
| 114 |
goto $ |
| 115 |
|
| 116 |
end |