;****************************************************************************** ;*** ;*** Vorlage ;*** ;*** (c) by Gonzo ;*** ;****************************************************************************** .include "8515def.inc" ;****************************************************************************** ;*** Definitionen ;****************************************************************************** ;****************************************************************************** ;*** Konstanten ;****************************************************************************** ;****************************************************************************** ;*** Variablen ;****************************************************************************** .def temp = r16 ; Register 16 dient als temporaere Variable .def count1 = r17 .def count2 = r18 ;****************************************************************************** ;*** Interrupt Vektoren ;****************************************************************************** .org 0x00 rjmp RESET ; Reset Handler .org URXCaddr rjmp UART_RXC ; RS232 RX Handler ;****************************************************************************** ;*** Reset Routine ;*** Initialisierung des Stackponters ;****************************************************************************** RESET: ldi temp,low(RAMEND) ;init Stack Pointer out SPL,temp ldi temp,high(RAMEND) out SPH,temp rjmp MAIN ;****************************************************************************** ;*** Initalisierung ;****************************************************************************** INIT: rcall PORT_INIT rcall RS232INIT ; Initialisierung der RS232 rcall SRAM_INIT ret ;****************************************************************************** ;*** Initalisierung ;****************************************************************************** PORT_INIT: ldi temp,0x00 out DDRB,temp ; set Port B as input PB0 -> Switch1 ldi ZH,0x03 ldi ZL,0x00 ; Set SRAM Pointer to 0x0300 ldi count1,0x00 ldi count2,0x00 ret ;****************************************************************************** ;*** RS232 Intitialisierung ;****************************************************************************** RS232INIT: ldi temp,4000000/(9600*16)-1 ;Set Baudrate Generator out UBRR,temp ; load UART Baud Rate Register ; for 9600 Baud ldi temp,0x98 out UCR,temp ; load UART Control Register ; RX Complete Interrupt enable ; RX/TX enable ; 8Bit Characters ret ;****************************************************************************** ;*** SRAM INIT ;****************************************************************************** SRAM_INIT: ldi temp,0xC0 out MCUCR,temp ret ;****************************************************************************** ;*** Service Routine for UART Receive Complete Interrupt ;****************************************************************************** UART_RXC: in temp,UDR ; read received data out UDR,temp ; st Z+,temp ; store data in external RAM and increment pointer reti ;****************************************************************************** ;*** Hauptprogramm ;****************************************************************************** MAIN: rcall INIT sei ; enable Interrupts WAIT_SW: in temp,PINB ; read PortB andi temp,0x01 ; mask Bit0 breq TRANSMIT rjmp WAIT_SW TRANSMIT: ldi ZH,0x03 ldi ZL,0x00 ; Set SRAM Pointer to 0x0300 SEROUT: sbis USR,UDRE ;Warten, bis UDR für das nächste Byte bereit ist rjmp SEROUT ld temp,Z+ out UDR,temp inc count1 breq NEXT rjmp SEROUT NEXT: inc count2 cpi count2,10 brne SEROUT MAINLOOP: rjmp MAINLOOP