; ************************************ ; *********************************** ; ** SERIAL COMMUNICATION ROUTINES ; ** BY PEK ´2000 ; ** Changes: ; ** 2002-05 - Transmit interrupt ; *********************************** ; ************************************ .cseg ; ************************************ ; * Register and Constant Definitions ; ************************************ .def temp =R16 .def send_s =R17 ; Status register holding type of sequence to send .def numb_b =R18 ; Number of bytes to send in a sequence ; More used registers are R0, ZL and ZH ; ************************************ ; * Definitions ; ************************************ .equ SEND_BYTE =0x00 .equ SEND_RAM =0x01 .equ SEND_FLASH =0x02 ; ************************************ ; ************************************ ; * START OF USER FUNCTIONS ; ; ************************************ ; * Initiate the UART ; * ; * temp = UBRR ; ************************************ UART_Init: out UBRR,temp ldi temp,0xD8 out UCR,temp ; Rx INT, Tx INT, Rx Enable, Tx Enable ret ; ************************************ ; * Send a Byte ; * ; * temp = byte to send ; ************************************ UART_Send_Byte: rcall UART_Disable_RxINT ; Disable further Rx interrupts ldi send_s,SEND_BYTE rcall UART_Send_B ret ; ************************************ ; * Send Sequence of Bytes from RAM ; * ; * Z = start of sequence ; * numb_b = number of bytes ; ************************************ UART_Send_Sequence_RAM: rcall UART_Disable_RxINT ; Disable further Rx interrupts ldi send_s,SEND_RAM rcall UART_Send_Sequence ret ; ************************************ ; * Send Sequence of Bytes from Flash ; * ; * Z = start of sequence ; * numb_b = number of bytes ; ************************************ UART_Send_Sequence_Flash: rcall UART_Disable_RxINT ; Disable further Rx interrupts ldi send_s,SEND_FLASH rcall UART_Send_Sequence ret ; ; * END OF USER FUNCTIONS ; ************************************ ; ************************************ ; ************************************ ; * UART Rx ISR ; * ; * Call for the function rxISR ; ************************************ UART_Rx_Comp: in temp,UDR ; Get byte from UART Data Register rcall rxISR reti ; ************************************ ; * UART Tx ISR ; * ; * ; ************************************ UART_Tx_Comp: cpi send_s,SEND_BYTE breq UART_Tx_Comp_Fin tst numb_b breq UART_Tx_Comp_Fin dec numb_b rcall UART_Send_Sequence reti UART_Tx_Comp_Fin: rcall UART_Enable_RxINT ; Enable Rx interrupts reti ; ************************************ ; * Disable Rx interrupt ; * ; ************************************ UART_Disable_RxINT: cbi UCR,RXCIE ret ; ************************************ ; * Enable Rx interrupt ; * ; ************************************ UART_Enable_RxINT: sbi UCR,RXCIE ret ; ************************************ ; * Send Sequence of Bytes ; * ; ************************************ UART_Send_Sequence: cpi send_s,SEND_RAM breq UART_Send_From_RAM cpi send_s,SEND_FLASH breq UART_Send_From_Flash ret UART_Send_From_RAM: ld temp,Z+ rcall UART_Send_B ; Send next byte in sequence ret UART_Send_From_Flash: lpm mov temp,R0 rcall UART_Send_B ; Send next byte in sequence adiw ZL,1 ; Point to next byte ret ; ************************************ ; * Send a Byte ; * ; * temp = byte to send ; ************************************ UART_Send_B: sbis USR,UDRE ; Loop if transmit not complete rjmp UART_Send_B out UDR,temp ret