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.

[SOLVED] Avr code to P89v51rd2 code..

Status
Not open for further replies.

tushki7

Full Member level 4
Joined
Jul 6, 2010
Messages
232
Helped
50
Reputation
100
Reaction score
47
Trophy points
1,318
Location
india
Activity points
2,789
Hello,
I need to run avr code into p89v51rd2, but i am not good in avr's, so need your help to convert it for P89v51rd2.
Here is the code :
Code:
/* code for packet mode communication */
#include <avr/io.h> // header file defining I/o operation
#define F_CPU 8000000 // CPU @ 8MHZ
#define USART_BAUDRATE 9600 // SERIAL Communication @ 9600 baud
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1) // baudrate formula
#include <util/delay.h>> // header file defining delay
int main(void) > // main code begins
{
DDRB = 0xff; // PORT D as output
DDRD = 0xfc; // PORT D PIN 2-7 as output.
UCSRB |= (1 << RXEN) | (1 << TXEN); // Enable Rx & Tx of USART
UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); // 8bit, 1 Stop bit, no parity
UBRRL = BAUD_PRESCALE; // setting baud rate @ 9600 baud
UBRRH = (BAUD_PRESCALE >> 8);
while(1) // loop forever
{

unsigned char s=0; // for use as a counter
unsigned char a[] = {0x23, 0x02, 0x30, 0x52, 0x00}; // Tx packet in the forrmat of //char array a[] = {0x23, 0x02, 0x30, 0x52, 0x00}, where 0x00 is not the part of ac-tual //tx packet but is rather used to indicate within this code the end of packet.
while (a[s] != '\0') // Loop to send tx packet through USART while scanning for ‘\0’
{
while ((UCSRA & (1 << UDRE)) == 0); // Loop until UDR buffer is ready to re-ceive // next byte to be transmitted.
UDR = a[s]; // Add next byte to be transmitted to the UDR buffer
s++; // Increment the counter
_delay_ms(50); // delay of .02ms
}
_delay_ms(2000); // delay of 2 sec
s=0; // reset counter
a[3] = 0x53; //modify char array to a[] = {0x23, 0x02, 0x30, 0x53, 0x00},
while (a[s] != '\0') // Loop to send tx packet through USART while scanning for ‘\0’
{ // While loop opened.
while ((UCSRA & (1 << UDRE)) == 0); // Loop until UDR buffer is ready to re-ceive // next byte to be transmitted.
UDR = a[s]; // Add next byte to be transmitted to the UDR buffer
s++; // Increment the counter
_delay_ms(50); // delay of .02ms
}
_delay_ms(2000); // delay of 2 sec

I would be very grateful to any who can guide me.. :roll:
 

AVR and 51 have lot of difference it is better to rewirte the code.
 

Try this

#include "reg51.h"
#include "stdio.h"

void main (void)
{
unsigned longint y;
unsigned char s;
unsigned char a[5] = {0x23, 0x02, 0x30, 0x52, 0x00};

SCON = 0x50; //init serial to be 9600 bps
TMOD |= 0x20;
TH1 = 253
TR1 = 1;
TI = 1;
RI = 0;

while(1)
{
s=0;
while(!a)
{
while(!TI);
TI=0;
putchar(a);
s++;
for (y=0;y<9216;y++); //delay 20 ms
};

a[3]=0x53;

s=0;
while(!a)
{
while(!TI);
TI=0;
putchar(a);
s++;
for (y=0;y<9216;y++); //delay 20 ms
};




for (y=0;y<921600;y++); //delay 2 s
};
}
 
Last edited:
  • Like
Reactions: tushki7

    tushki7

    Points: 2
    Helpful Answer Positive Rating
Thank you , but your code is not transmitting anything???
and i need to transmit those packets({0x23, 0x02, 0x30, 0x52, 0x00}) through uart!!!
 

Thank you , but your code is not transmitting anything???
and i need to transmit those packets({0x23, 0x02, 0x30, 0x52, 0x00}) through uart!!!

I see. If you use SDCC you need to add #include <serial_IO.h>
or change the line : putchar(a); with SBUF=a;
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top