;;*************************************** ;;***** RS-232 test on 8515 ;;*************************************** ;Polled -- no interrrupts ;Strings can come from flash or RAM. ;input a string, then output it again .include "d:\bruce\eedocs\atmel\asm src\8515def.inc" .device AT90S8515 .def char =r0 ;character to send/receive .def temp =r16 ;temporary register .def TXflash =r17 ;text to be sent is in flash if <>0 .equ baud96 =25 ;9600 baud constant for 4Mhz crystal .equ azero ='0' ;0x30 ascii '0' ;************************************** .dseg ;define variable string to be stored/transmitted in RAM StrBuffer: .byte 32 ;a string buffer ;************************************** ;print and read string macros .macro PrintFlashStr ;use: PrintFlashStr flashaddress ldi TXflash, 1 ldi ZL, low(@0<<1) ldi ZH, high(@0<<1) rcall putString .endmacro .macro PrintRamStr ;use: PrintRamStr ramaddress ldi TXflash, 0 ldi ZL, low(@0) ldi ZH, high(@0) rcall putString .endmacro .macro ReadStr ;use: ReadStr ramaddress ldi ZL, low(@0) ldi ZH, high(@0) rcall getString .endmacro ;************************************** .cseg .org $0000 rjmp RESET ;reset entry vector reti reti reti reti reti reti reti reti reti reti reti reti ;define fixed strings to be tranmitted from flash- zero terminated prompt: .db "Enter a string>",0x00 echo: .db "The string was>",0x00 crlf: .db 0x0d, 0x0a, 0x00 ;carrage return/line feed RESET: ldi temp, LOW(RAMEND) ;setup stack pointer out SPL, temp ldi temp, HIGH(RAMEND) out SPH, temp ;setup UART -- enable RX, TX pins ldi temp, 0b00011000 out UCR, temp ;set baud rate to 9600 ldi temp, baud96 out UBRR, temp sei ;now print a prompt and wait for incoming string with loop: PrintFlashStr crlf PrintFlashStr prompt ReadStr StrBuffer PrintFlashStr echo PrintRamStr StrBuffer PrintFlashStr crlf rjmp loop ;********************************************* ;string soubroutines ;********************************************* ;routine to output one char ;enter with char in char putc: sbis USR, UDRE ;wait until clear then send one char rjmp putC out UDR, char ret ;routine to input one char ;exit with char in char getc: sbis USR, RXC ;wait until ready then get one char rjmp getc in char, UDR ret ;routine to send a string putString: tst TXflash ;is it flash? breq _txram lpm ;char ;if so get a char rjmp _tstend _txram: ld char, Z ;if mem get a char _tstend:tst char ;is it string end marker? breq _TXend rcall putc ;emit a char adiw ZL, 1 ;set up next pointer rjmp putString _TXend: ret ;routine to read a string getString: rcall getc rcall putc ;echo it ldi temp, 0x0d ;a cp char, temp ;carriage return? breq _RXend st Z+, char ;store the char rjmp getString _RXend: ldi temp, 0 ;append a 0x00 to string st Z, temp ldi temp, 0x0a ;line feed makes terminal nicer mov char, temp rcall putc ret ;*****************************************************