Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Is the 8051 assembly code compatible with AVR code?

Status
Not open for further replies.

qh2_2000

Newbie level 4
Joined
Jan 27, 2005
Messages
7
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Activity points
112
AVR and 8051

Hi and good day,

Is AVR a family of 8051?

Is the 8051 assembly code is compatible with AVR code? Can I just use 8051 code and apply it to AVR Microcontroller? If not, is there any software that can convert it?

I have codes that works well with At89s51 but i would like to use it for ATmega8515.

Thanks for your help.
 

Re: AVR and 8051

hi,
No they are different their instruction set is also different.If your code is in c u might be able to port to anyone of them with minor modifications. If code is in assembly i guess u have to rewrite the code by urself.
regards
pimr
 

    qh2_2000

    Points: 2
    Helpful Answer Positive Rating
Re: AVR and 8051

Hi,

Thanks to pimr for your reply. You had clarified all my doubts and confusion. What I intend to do is to send data (character 'A') through the rs232 with my ATmega8515. However, what I receive from the hyperterminal is weird character such as

À@@@€ÀÀÀÀÀÀ€À€ÀÀ€ÀÀÀÀ

May i know where goes wrong? here is my assembly code:-

-----------------------------------------------------------------------
.include "8515def.inc"

.def temp = r16

.cseg
.org $00
rjmp reset ;reset handle

reset: rjmp init ;start init

init: ldi temp,low(ramend)
out spl,temp ;set spl
ldi temp,high(ramend)
out sph,temp ;set sph
ldi temp,7 ;57.6 kbps for 7.3728 MHz
out ubrr,temp ;load baudrate
ldi r17, 0x00
out DDRB, r17
ldi r17, 0xFF
out PORTB, r17

rcall main ;start sending

main:
sbi PINB, 0
sbic PINB, 0
rjmp main
rcall loop

rs_send:
sbi ucr,txen ;set sender bit
sbis usr,udre ;wait till register is cleared
rjmp rs_send
out udr,temp ;send the recived value
cbi ucr,txen ;clear sender bit
rjmp main ;go back

loop:
ldi temp, 'A'
rcall rs_send ;send to comX
----------------------------------------------------------------------

Does anyone have any example to send data from Atmega8515 through rs232?
Does I need any flow control code and are there any examples?

Hope someone can help me out. I had been trying this for almost two weeks...

Thanks for your help and I appreciate it.
 

Re: AVR and 8051

Hi qh2_2000,

It doesn't matter if you work with 8051 or AVR as long as you end up the subroutine with a RET.
Look at your code and tell me how many time did you used rcall ? How many RET ?
Even if you set the stack at ramend you got problems this way(jumping and calling).

Bellow you'll find an ordinary code take it from the web where a character sent by the hyperterminal it's received and sent back by AVR.
If you like to send a character continously just replace the code inside rs_rec subroutine with the one you like:
ldi temp, 'A'
ret ;yes don't forget that.

;*********************************
;SER.ASM
;
;this program does read a value
;from the comX, and write it as an
;echo back to the pc-screen.
;*********************************

.include "c:\avrtools\appnotes\8515def.inc"

.equ clock = 4000000 ;clock frequency
.equ baudrate = 9600 ;choose a baudrate

.equ baudkonstant = (clock/(16*baudrate))-1

.def temp = r16

.cseg
.org $00
rjmp reset ;reset handle

reset: rjmp init ;start init

init: ldi temp,low(ramend)
out spl,temp ;set spl
ldi temp,high(ramend)
out sph,temp ;set sph

ldi temp,baudkonstant
out ubrr,temp ;load baudrate

rjmp loop ;let's go...

rs_rec: sbi ucr,rxen ;set reciver bit...
sbis usr,rxc ;wait for a value
rjmp rs_rec
in temp,udr ;read value
cbi ucr,rxen ;clear register
ret ;go back

rs_send:
sbi ucr,txen ;set sender bit
sbis usr,udre ;wait till register is cleared
rjmp rs_send
out udr,temp ;send the recived value
cbi ucr,txen ;clear sender bit
ret ;go back

loop: rcall rs_rec ;read from comX
rcall rs_send ;send to comX
rjmp loop ;repeat

You don't need any flow control as long as you're able to handle the stream of bytes sent by PC, or the PC can handle as well, what you send to.

Regards.
 

    qh2_2000

    Points: 2
    Helpful Answer Positive Rating
Re: AVR and 8051

Hi and good day,

Special thanks to silvio for your tips and reply. I am very confident you can help me but it just couldn't work...:(

This time i can even receive any input from the microcontroller. I try to edit the code to the one as below. since i afraid my microcontroller couldn't receive data from my data, i just try to send data to the computer. however, i couldn't receive any input from the microcontroller.

rs_rec: sbi ucr,rxen ;set reciver bit...
sbis usr,rxc ;wait for a value
rjmp rs_rec
in temp,udr ;read value
cbi ucr,rxen ;clear register
ret ;go back

rs_send:
sbi ucr,txen ;set sender bit
sbis usr,udre ;wait till register is cleared
rjmp rs_send
out udr,temp ;send the recived value
cbi ucr,txen ;clear sender bit
ret ;go back

loop:
;rcall rs_rec ;read from comX
ldi temp, 'A'
rcall rs_send ;send to comX
rjmp loop ;repeat

---------------------

I just couldn't solve where is the problem. I had try using new microcontroller and new RS232. it seem like that is not the source of the problem. i had also try taking out all the component and putting it back.

Does anyone know where is my problem? Can anyone help me to solve this problem? I just can't proceed without solving this problem and i had been trying this for weeks now...:(

thanks

regards
 

Re: AVR and 8051

Hi qh2_2000

My advice: Try to use the development tools that the manufacturer provides.
I call this the AVRStudio. Inside you'll find a nice simulator. Learn to use it.
It's your's nearest fellow.
If you want something much confident and closest to the real world, buy a emulator.
If this seems too expensive try using a AVR micro with JTAG interface.
However, for your small application try first the simulator and if it's going perfect, but on real world not are you expected to, then try to insert some line of codes with the only purpose to know where the program counter is and what's the AVR micro is doing.
That line of code is to clear an output port bit which goes toward a LED. If you see the LED lit, then you know you pass up to that point.
It's exactly the same as you procceed with r17 out to port B in your first example.

As I understand well you don't see something coming from AVR micro to PC (hyperterminal).
First of all check that the baudrate inside hyperterminal match the one set into AVRmicro.
Then disable the handshake (set to none).
Let's cut some lines from the program and keep only what we need to proove.

.include "8515def.inc"

.def temp = r16

.cseg
.org $00
rjmp init ;reset handle
;jump over interrupt vector table for 8515
.org $0d
init: ldi temp,low(ramend)
out spl,temp ;set spl
ldi temp,high(ramend)
out sph,temp ;set sph
ldi temp,7 ;57.6 kbps for 7.3728 MHz
out ubrr,temp ;load baudrate
ldi temp, 'A'
sbi ucr,txen ;set sender bit

loop:
sbis usr,udre ;wait till register is cleared
rjmp loop
out udr,temp ;send the 'A'
rjmp loop ;send forever;

The program will send forever the 'A' character. Nothing else.
Try and come back with results.
 

    qh2_2000

    Points: 2
    Helpful Answer Positive Rating
Re: AVR and 8051

Hi again.

this time i have the good news. first of all, thanks to all that had helped me including providing me with the source code. special thanks for that...:)

i had solve the problem. the main problem is that the default clock source is IMhz from the internal clock. thus, the baud rate is always different from what i want. that is why i kept getting weird character.

thus, in order to change the clock source to external crystral, i need to write the fuse setting of CKOPT, CKSEL and SUT.

i had done that and its working...Thanks..

I can now proceed further..

qh2_2000
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top