; term.asm ; Program to talk to the Raven serial port monitor. When run, it sends a message to the ; monitor, and then will echo any characters or strings sent and display the characters ; on the led bar. ; ; This is pretty crude, and would be much better if transmit data were double buffered ; to increase speed (probably not much advantage at 9600 baud) and using interrupts would ; make it much more flexible. LIST P=16F877, R=DEC INCLUDE "P16F877.inc" ; Definitions for the PIC RX EQU 7 ; PORT C bit for SDA TX EQU 6 ; PORT C bit for SCL RAM EQU 0x20 Temp EQU RAM+0 Counter EQU RAM+1 DTemp1 EQU RAM+2 DTemp2 EQU RAM+3 DTemp3 EQU RAM+4 Char EQU RAM+5 ; Start of the Program ORG 3 goto Start ORG 0x20 ; Message Msg addwf PCL,F DT "Hi Hal" ; Simple ASCII conversion table GetASCII movwf Temp movlw 65 subwf Temp,W addwf PCL,F retlw 0x41 ; A retlw 0x42 ; B retlw 0x43 ; C retlw 0x44 ; D retlw 0x45 ; E retlw 0x46 ; F retlw 0x47 ; G retlw 0x48 ; H retlw 0x49 ; I retlw 0x4A ; J retlw 0x4B ; K retlw 0x4C ; L retlw 0x4D ; M retlw 0x4E ; N retlw 0x4F ; O retlw 0x50 ; P retlw 0x51 ; Q retlw 0x52 ; R retlw 0x53 ; S retlw 0x54 ; T retlw 0x55 ; U retlw 0x56 ; V retlw 0x57 ; W retlw 0x58 ; X retlw 0x59 ; Y retlw 0x5A ; Z Start ; Initialize the TRIS registers. Importantly, SDA and SCL must be inputs bsf STATUS, RP0 clrf TRISA ; for led bar clrf TRISD ; for led bar bsf TRISC,RX bcf TRISC,TX bcf STATUS, RP0 ; Initialize the USART call URTConfig ; The main loop just sends a few characters to the USART and displays what comes back on ; the led bar mainloop movlw 6 movwf Counter movlw 0 movwf Temp send_loop movf Temp,W call Msg call URTSend incf Temp,F decfsz Counter,F goto send_loop ; Read characters, put on led bar and echo back forever recv_loop call URTReceive call DispLedBar goto recv_loop ; --------------------------------------------------------- ; Routines for managing USART communications ; Configure the interface ; Use 9600 baud, no parity asynchronous mode URTConfig bsf STATUS,RP0 movlw b'10100100' ; master clock, 8-bit, xmit enabled, asynch, high baud rate movwf TXSTA movlw 129 ; 9600 divisor for a 20 MHz clock movwf SPBRG bcf STATUS,RP0 movlw b'10010000' ; enable serial port (necessary) movwf RCSTA return ; Slow send. Put the byte into TXREG and wait for transfer to shift register to complete. URTSend ; Make sure the previous send is gone btfss PIR1,TXIF goto $-1 movwf TXREG return ; Wait for byte to arrive and then return it. URTReceive ; Make sure that previous receive is done btfss PIR1,RCIF goto $-1 ; Got a byte in the receive buffer - echo it and return movf RCREG,W call URTSend return ; ---------------------------------------------------------- ; Display routines ; Routine to display something on the LED bank DispLedBar ; Enable the led bar and put the value in W there. movwf Temp ; save W movlw 0x12 movwf PORTA comf Temp,W movwf PORTD return ; Display something on the Led Bar and wait for one second - ; handy for debugging DisplayDebug call DispLedBar movlw 1 call Delay_sec END