Hello,
A few weeks ago I started learning to program an AVR risc processor. A baught myself a book an copied the examples in my ATtiny2313.
Now I have this problem. The next example in my book is designed for a 8515 processor. Because I use a Attiny2313, this doen’t work properly.
Can somebody help me to explain and change the assembler code untill it works in my environnement, for the 2313 ?
This example is about a commnucation with the RS232 serial port of my computer and my AVR. The link between serial port and processor is established with an MAX232 chip. Goal of the assembler code is to send a character from computer to processor. The processor will put the ASCII value on port B (8 leds will light up). Also the processor increments this value and send it back to the computer. To send a character to the AVR I use a Terminal Emulator Test program.
Who can help me.
Thanks in advance,
Best regards,
Geert Claes.
Ps. You can also answer in Dutch.
;aruna and mazhalai
;4 dec 99
;uart prog for 8515 ver1...and it worked!!!
;prog recieves a data and outputs it to port B and echoes it
;back by incrementing the same
;transmission and reception is done at 9600 bps
.include"..\..\8515def.inc"
.def rtemp=r17 ;temporary register
.def rreg=r18 ;register for recieving data
.def treg=r19 ;register for transmitting
.equ baudrate=$33 ;baud rate of 9600 bps for a clock frequency of 8 Mhz
.equ RXC=7 ;UART recieve complete flag( 7th bit of USR register)
.equ UDRE=5 ;UART data register empty flag(5th bit of USR register)
.cseg
.org 0
rjmp RESET ;reset handle
rjmp RESET
rjmp RESET
RESET: ldi r16, low(RAMEND) ;initialising stack
out SPL,r16
ldi r16,HIGH(RAMEND)
out SPH,r16
ldi r16,255 ;initialising port B for output
out DDRB,r16
rcall init_uart ;initialising 8515 for transmit and recieve
up: rcall rxcomp ;recieving data
out portb,rreg ;outputting data at port B
inc rreg ;incrementing recieved data
mov treg, rreg
rcall txcomp ;transmitting data
rjmp up
;subroutine for initialising baudrate and UART control register
init_uart:
ldi rtemp, baudrate ;setting baud rate
out UBRR,rtemp
ldi rtemp, $18 ;initialising UART control register
out UCR, rtemp
ret
;subroutine for recieving data
rxcomp: sbis USR,RXC ;poll to check if char received
rjmp rxcomp
in rreg,UDR ;put received data in rreg
ret
;subroutine for transmitting data
txcomp: sbis USR,UDRE ;poll to check end of transmission
rjmp txcomp
out UDR, treg
ret
RES
RES
The problem is do you have an ATtiny2313 definition file?
I had the same problem. So I had to find one, I found none so I made one from another program called (AVRstudio)
Every AVR has different definitions for registers, timers, pins, etc.
Then compare the datasheets of the ATtiny2313 and the AT90S8515. Compare all the bitnames and registernames.
And rename to the right ones. (must be done by hand)
Also a problem can be some instructions the ATtiny2313 can't accept. Check everything. Or rewrite the whole code from scratch. (you have an example code)