nikhilthunderlion
Newbie level 1
cellphone operated robot
i am doing a project in which Vehicle will be controller using a cellphone,for this i have to program the 89C51 microcontroller.i have the C program for ATmega16 which i got from one of my friend but i dont have ATmega16 so i need to convert the C program written for ATmega16 to C program for 89C51. can some one convert it for. my email ID is "nikhilthunderlion(at)gmail.com"
THE C program for ATmega 16 is as follows.
#define F_CPU 12000000ul //F_CPU value to that we're using in our hardware
#include <avr/io.h> //Header file for AVR family microcontrollers
#include <util/delay. h> //Header file for using delay functions
#include <avr/delay.h> //Header file for using delay functions
#define dataport PORTA //Defining Data port for LCD
#define commport PORTD //Defining Command port for LCD
#define rs PD4 //Defing RS control line to pin 4 of PORT-D
#define wr PD5 //Defing WR control line to pin 5 of PORT-D
#define en PD6 //Defing EN control line to pin 6 of PORT-D
/******* <<Declaration of the functions>> ********/
int LCD_init1(void) ;
int LCD_init2(void) ;
int LCD_SendData1(void);
int LCD_SendData2(void);
int LCD_SendData3(void);
int LCD_SendData4(void);
int LCD_SendData5(void);
int LCD_SendData6(void);
int LCD_SendData7(void);
int LCD_SendData8(void);
int LCD_SendData9(void);
int LCD_SendData10(void);
int LCD_SendData11(void);
int LCD_SendData12(void);
int LCD_SendData13(void);
int LCD_SendData14(void);
int LCD_SendData15(void);
int LCD_SendData16(void);
int LCD_SendData17(void);
int LCD_SendData18(void);
int LCD_SendData19(void);
int LCD_SendData20(void);
int LCD_SendData21(void);
int wrcomm(void);
int wrdata(void);
/******* <<Main Function of the program begins>> ********/
int main(void)
{
unsigned int k, h;
DDRA=0xFF; //Setting PORT A as output port
PORTA=0x00;
DDRB=0x00; //Setting PORT B as input port
PORTB=0x00;
DDRD=0X7F; //Setting and Masking PORT D pins for output
PORTD=0x00;
LCD_init1();
LCD_SendData20();
LCD_init2();
LCD_SendData21();
while (1)
{
k =~PINB;
h=k & 0x0F;
switch (h)
{
case 0x0D: //Forward (KEY Pressed - 2)
{
PORTD=0x89;
LCD_init1();
LCD_SendData5();
LCD_init2();
LCD_SendData6();
break;
}
case 0x07: //Backward (KEY Pressed -
{
PORTD=0x86;
LCD_init1();
LCD_SendData7();
LCD_init2();
LCD_SendData8();
break;
}
case 0x0B: //Sharp Left Turn (KEY Pressed - 4)
{
PORTD=0x85;
LCD_init1();
LCD_SendData3();
LCD_init2();
LCD_SendData4();
break;
}
case 0x09: //Sharp Right Turn (KEY Pressed - 6)
{
PORTD=0x8A;
LCD_init1();
LCD_SendData1();
LCD_init2();
LCD_SendData2();
break;
}
case 0x0A: //Stop (KEY Pressed - 5)
{
PORTD=0x00;
LCD_init1();
LCD_SendData13();
LCD_init2();
LCD_SendData14();
break;
}
case 0x0E: //Smooth Left turn Forward (KEY Pressed - 1)
{
PORTD=0x81;
LCD_init1();
LCD_SendData11();
LCD_init2();
LCD_SendData12();
break;
}
case 0x0C: //Smooth Right turn Forward (KEY Pressed - 3)
{
PORTD=0x88;
LCD_init1();
LCD_SendData9();
LCD_init2();
LCD_SendData10();
break;
}
case 0x08: //Smooth Right turn Backward (KEY Pressed – 7)
{
PORTD=0x82;
LCD_init1();
LCD_SendData15();
LCD_init2();
LCD_SendData16();
break;
}
case 0x06: //Smooth Left turn Backward (KEY Pressed - 9)
{
PORTD=0x84;
LCD_init1();
LCD_SendData17();
LCD_init2();
LCD_SendData18();
break;
}
case 0x05: // Robo Dance (KEY Pressed - 0)
{
PORTD=0x89;
_delay_loop_2(50000);
PORTD=0x86;
_delay_loop_2(50000);
PORTD=0x85;
_delay_loop_2(50000);
PORTD=0x8A;
_delay_loop_2(50000);
PORTD=0x00;
_delay_loop_2(50000);
PORTD=0x81;
_delay_loop_2(50000);
PORTD=0x88;
_delay_loop_2(50000);
PORTD=0x82;
_delay_loop_2(50000);
PORTD=0x88;
LCD_init1();
LCD_SendData19();
//LCD_init2();
//LCD_SendData2();
break;
}
}
}
}
int LCD_init1()
{
dataport = 0x38; //init. LCD 2 lines, 5x7 matrix
wrcomm(); //Right the command byte to command register
dataport = 0x01; //Clear LCD
wrcomm(); //Right the command byte to command register
dataport = 0x0F; //Display on Cursor Blinking
wrcomm(); //Right the command byte to command register
dataport = 0x80; //Cursor at line 1, position 1
wrcomm(); //Right the command byte to command register
return 1;
}
int LCD_init2()
{
dataport = 0x38; //initialize LCD 2 lines, 5x7 matrix
wrcomm(); //Right the command byte to command register
dataport = 0x0F; //Display on Cursor Blinking
wrcomm(); //Right the command byte to command register
dataport = 0xC0; //Cursor at line 2, position 1
wrcomm(); //Right the command byte to command register
return 1;
}
/*********** **** <<Sending Data to LCD Display>> ************ ***/
int LCD_SendData1(void)
{
unsigned char j[] = "MOVING...";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata(); //Right the data byte to data register
}
return 1;
}
int LCD_SendData2(void)
{
unsigned char j[] = "RIGHT...";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData3(void)
{
unsigned char j[] = "MOVING...";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData4(void)
{
unsigned char j[] = "LEFT...";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData5(void)
{
unsigned char j[] = "MOVING...";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData6(void)
{
unsigned char j[] = "FWD...";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData7(void)
{
unsigned char j[] = "MOVING..";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData8(void)
{
unsigned char j[] = "BACK..";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData9(void)
{
unsigned char j[] = "TURNING..";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData10(void)
{
unsigned char j[] = "RIGHT...";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData11(void)
{
unsigned char j[] = "TURNING..";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData12(void)
{
unsigned char j[] = "LEFT...";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData13(void)
{
unsigned char j[] = "ROBO..";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData14(void)
{
unsigned char j[] = "STOPPED..";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData15(void)
{
unsigned char j[] = "REVERSE..";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData16(void)
{
unsigned char j[] = "RIGHT..";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData17(void)
{
unsigned char j[] = "REVERSE..";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData18(void)
{
unsigned char j[] = "LEFT..";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData19(void)
{
unsigned char j[] = "DANCING..";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData20(void)
{
unsigned char j[] = "CALL ME..";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData21(void)
{
unsigned char j[] = "09612541318";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
/******* <<Righting the command byte to command register>> ********/
int wrcomm(void)
{
commport &= ~(1 << rs);
commport &= ~(1 << wr);
commport |= (1 << en);
commport &= ~(1 << en);
_delay_ms(10) ;
return 1;
}
/********** <<Righting the Data byte to Data register>> **********/
int wrdata(void)
{
commport |= (1 << rs);
commport &= ~(1 << wr);
commport |= (1 << en);
commport &= ~(1 << en);
_delay_ms(2) ;
return 1;
}
i am doing a project in which Vehicle will be controller using a cellphone,for this i have to program the 89C51 microcontroller.i have the C program for ATmega16 which i got from one of my friend but i dont have ATmega16 so i need to convert the C program written for ATmega16 to C program for 89C51. can some one convert it for. my email ID is "nikhilthunderlion(at)gmail.com"
THE C program for ATmega 16 is as follows.
#define F_CPU 12000000ul //F_CPU value to that we're using in our hardware
#include <avr/io.h> //Header file for AVR family microcontrollers
#include <util/delay. h> //Header file for using delay functions
#include <avr/delay.h> //Header file for using delay functions
#define dataport PORTA //Defining Data port for LCD
#define commport PORTD //Defining Command port for LCD
#define rs PD4 //Defing RS control line to pin 4 of PORT-D
#define wr PD5 //Defing WR control line to pin 5 of PORT-D
#define en PD6 //Defing EN control line to pin 6 of PORT-D
/******* <<Declaration of the functions>> ********/
int LCD_init1(void) ;
int LCD_init2(void) ;
int LCD_SendData1(void);
int LCD_SendData2(void);
int LCD_SendData3(void);
int LCD_SendData4(void);
int LCD_SendData5(void);
int LCD_SendData6(void);
int LCD_SendData7(void);
int LCD_SendData8(void);
int LCD_SendData9(void);
int LCD_SendData10(void);
int LCD_SendData11(void);
int LCD_SendData12(void);
int LCD_SendData13(void);
int LCD_SendData14(void);
int LCD_SendData15(void);
int LCD_SendData16(void);
int LCD_SendData17(void);
int LCD_SendData18(void);
int LCD_SendData19(void);
int LCD_SendData20(void);
int LCD_SendData21(void);
int wrcomm(void);
int wrdata(void);
/******* <<Main Function of the program begins>> ********/
int main(void)
{
unsigned int k, h;
DDRA=0xFF; //Setting PORT A as output port
PORTA=0x00;
DDRB=0x00; //Setting PORT B as input port
PORTB=0x00;
DDRD=0X7F; //Setting and Masking PORT D pins for output
PORTD=0x00;
LCD_init1();
LCD_SendData20();
LCD_init2();
LCD_SendData21();
while (1)
{
k =~PINB;
h=k & 0x0F;
switch (h)
{
case 0x0D: //Forward (KEY Pressed - 2)
{
PORTD=0x89;
LCD_init1();
LCD_SendData5();
LCD_init2();
LCD_SendData6();
break;
}
case 0x07: //Backward (KEY Pressed -
{
PORTD=0x86;
LCD_init1();
LCD_SendData7();
LCD_init2();
LCD_SendData8();
break;
}
case 0x0B: //Sharp Left Turn (KEY Pressed - 4)
{
PORTD=0x85;
LCD_init1();
LCD_SendData3();
LCD_init2();
LCD_SendData4();
break;
}
case 0x09: //Sharp Right Turn (KEY Pressed - 6)
{
PORTD=0x8A;
LCD_init1();
LCD_SendData1();
LCD_init2();
LCD_SendData2();
break;
}
case 0x0A: //Stop (KEY Pressed - 5)
{
PORTD=0x00;
LCD_init1();
LCD_SendData13();
LCD_init2();
LCD_SendData14();
break;
}
case 0x0E: //Smooth Left turn Forward (KEY Pressed - 1)
{
PORTD=0x81;
LCD_init1();
LCD_SendData11();
LCD_init2();
LCD_SendData12();
break;
}
case 0x0C: //Smooth Right turn Forward (KEY Pressed - 3)
{
PORTD=0x88;
LCD_init1();
LCD_SendData9();
LCD_init2();
LCD_SendData10();
break;
}
case 0x08: //Smooth Right turn Backward (KEY Pressed – 7)
{
PORTD=0x82;
LCD_init1();
LCD_SendData15();
LCD_init2();
LCD_SendData16();
break;
}
case 0x06: //Smooth Left turn Backward (KEY Pressed - 9)
{
PORTD=0x84;
LCD_init1();
LCD_SendData17();
LCD_init2();
LCD_SendData18();
break;
}
case 0x05: // Robo Dance (KEY Pressed - 0)
{
PORTD=0x89;
_delay_loop_2(50000);
PORTD=0x86;
_delay_loop_2(50000);
PORTD=0x85;
_delay_loop_2(50000);
PORTD=0x8A;
_delay_loop_2(50000);
PORTD=0x00;
_delay_loop_2(50000);
PORTD=0x81;
_delay_loop_2(50000);
PORTD=0x88;
_delay_loop_2(50000);
PORTD=0x82;
_delay_loop_2(50000);
PORTD=0x88;
LCD_init1();
LCD_SendData19();
//LCD_init2();
//LCD_SendData2();
break;
}
}
}
}
int LCD_init1()
{
dataport = 0x38; //init. LCD 2 lines, 5x7 matrix
wrcomm(); //Right the command byte to command register
dataport = 0x01; //Clear LCD
wrcomm(); //Right the command byte to command register
dataport = 0x0F; //Display on Cursor Blinking
wrcomm(); //Right the command byte to command register
dataport = 0x80; //Cursor at line 1, position 1
wrcomm(); //Right the command byte to command register
return 1;
}
int LCD_init2()
{
dataport = 0x38; //initialize LCD 2 lines, 5x7 matrix
wrcomm(); //Right the command byte to command register
dataport = 0x0F; //Display on Cursor Blinking
wrcomm(); //Right the command byte to command register
dataport = 0xC0; //Cursor at line 2, position 1
wrcomm(); //Right the command byte to command register
return 1;
}
/*********** **** <<Sending Data to LCD Display>> ************ ***/
int LCD_SendData1(void)
{
unsigned char j[] = "MOVING...";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata(); //Right the data byte to data register
}
return 1;
}
int LCD_SendData2(void)
{
unsigned char j[] = "RIGHT...";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData3(void)
{
unsigned char j[] = "MOVING...";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData4(void)
{
unsigned char j[] = "LEFT...";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData5(void)
{
unsigned char j[] = "MOVING...";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData6(void)
{
unsigned char j[] = "FWD...";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData7(void)
{
unsigned char j[] = "MOVING..";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData8(void)
{
unsigned char j[] = "BACK..";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData9(void)
{
unsigned char j[] = "TURNING..";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData10(void)
{
unsigned char j[] = "RIGHT...";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData11(void)
{
unsigned char j[] = "TURNING..";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData12(void)
{
unsigned char j[] = "LEFT...";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData13(void)
{
unsigned char j[] = "ROBO..";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData14(void)
{
unsigned char j[] = "STOPPED..";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData15(void)
{
unsigned char j[] = "REVERSE..";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData16(void)
{
unsigned char j[] = "RIGHT..";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData17(void)
{
unsigned char j[] = "REVERSE..";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData18(void)
{
unsigned char j[] = "LEFT..";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData19(void)
{
unsigned char j[] = "DANCING..";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData20(void)
{
unsigned char j[] = "CALL ME..";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
int LCD_SendData21(void)
{
unsigned char j[] = "09612541318";
int i;
for(i = 0; i < sizeof j ; i++)
{
dataport = j;
wrdata();
}
return 1;
}
/******* <<Righting the command byte to command register>> ********/
int wrcomm(void)
{
commport &= ~(1 << rs);
commport &= ~(1 << wr);
commport |= (1 << en);
commport &= ~(1 << en);
_delay_ms(10) ;
return 1;
}
/********** <<Righting the Data byte to Data register>> **********/
int wrdata(void)
{
commport |= (1 << rs);
commport &= ~(1 << wr);
commport |= (1 << en);
commport &= ~(1 << en);
_delay_ms(2) ;
return 1;
}