; AVR software UART demo by Randy Ott - 4/27/98 ; Reads a message in EEPROM and send out UART .nolist ;Suppress listing of include file .include "2313def.inc" ;Define chip particulars .list .equ BAUD =25 ;9600 bps at 4.00 MHz. .def temp =R16 ;temporary storage register .def EEard =R17 ;EEPROM address to read from .cseg ; Interrupt vectors .org 0 rjmp reset ;Reset Vector .org INT0addr ;External Interrupt0 Vector reti .org INT1addr ;External Interrupt1 Vector reti .org ICP1addr ;Input Capture1 Interrupt Vector reti .org OC1addr ;Output Compare1 Interrupt Vector reti .org OVF1addr ;Overflow1 Interrupt Vector reti .org OVF0addr ;Overflow0 Interrupt Vector reti .org URXCaddr ;UART Receive Complete Interrupt Vector reti .org UDREaddr ;UART Data Register Empty Interrupt Vector reti .org UTXCaddr ;UART Transmit Complete Interrupt Vector reti .org ACIaddr ;Analog Comparator Interrupt Vector reti ; Main program entry point on reset reset: ; Setup buffers and pointers ldi temp,RAMEND out SPL,temp ;Init Stack Pointer ; Configure onboard peripherals ldi temp,BAUD out UBRR,temp ;Set baud rate generator ldi temp,0b00001000 out UCR,temp ;Enable UART tx w/o interrupts ldi temp,0 out UDR,temp ldi temp,0xff out DDRB,temp ldi temp,0b00001101 ;Enable watchdog w/512 prescaler out WDTCR,temp forever: ldi EEard,0 ;set EEPROM address to 0 EERead: sbic EECR,EEWE ;if EEWE not clear rjmp EERead ; wait more out EEAR,EEard ;output address ;***** Issue EEPROM read strobe twice due to a bug in AVR! ; sbi EECR,EERE ;set EEPROM Read strobe ;This instruction takes 4 clock cycles since ;it halts the CPU for two clock cycles sbi EECR,EERE ;set EEPROM Read strobe 2nd time ;This instruction takes 4 clock cycles since ;it halts the CPU for two clock cycles in temp,EEDR ;get data tst temp ;see if at end of message breq stop ;if zero found, start over txwait: sbis USR,UDRE ;is UART transmitter ready? rjmp txwait out UDR,temp ;sent out char com temp ;invert data out PORTB,temp ;show on LEDs inc EEard ;point to next EE address rjmp EERead stop: rjmp stop .eseg .org 0 msg: .db 0x0d, 0x0a, 0x0a, "Hello world from AVR land!" .db 0x0d, 0x0a, "The quick brown fox jumped " .db "the lazy dog's back 1234567890 times.", 0