Discussion in "8051 Discussion Forum" started by    cjj20    Jan 9, 2018.
Tue Jan 09 2018, 07:32 PM
#1
Please help me correct this code


#include <stdio.h>


#include <avr/io.h>

#include <util/delay.h>

#define LCD_DATA PORTC;
#define F_CPU 12000000UL
#define ctrl PORTB;
#define USART_BAUDRATE 4800
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
#define rs PB0; //register select
#define rw PB1; // LCD read/Write
#define en PB2; // enable print

void lcd_init();
void lcdcmd(unsigned char);
void lcddata(unsigned char);
void delay(int);
void drawstring(unsigned char *stri);
unsigned int receiveserial();
void uart_init();
void checkgpgga();



unsigned char send[90];
unsigned char send2[90];
unsigned char data;
unsigned char lat[15];
unsigned char long[15];
unsigned char lati;
unsigned char longi;

int main()
{
   DDRC=0xff;        //output
   DDRB=0x07;
   lcd_init();
   delay(50);
   uart_init();
   
   while(1){
       
       receiveserial();
       checkgpgga();
       
   }

    return 0;
}

void uart_init()
{
    UBRRL = BAUD_PRESCALE; 
    UBRRH = (BAUD_PRESCALE >
>
 8); 
    
    UCSRB |= (1<<RXCIE) | (1 << RXEN) | (1 << TXEN);   
    UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); 
    
    
}

void lcdcmd(unsigned char n)
{
    LCD_DATA=n;
   
    ctrl =(0<<rs)|(0<<rw)|(1<<en); 
    delay(1);
    ctrl =(0<<rs)|(0<<rw)|(0<<en); 
    return;
}

void lcddata(unsigned char n)
{
    LCD_DATA=n;
    ctrl = (1<<rs)|(0<<rw)|(1<<en); 
    
    delay(1);
    ctrl = (1<<rs)|(0<<rw)|(0<<en); 
    return;
}

void lcd_init()
{
    lcdcmd(0x38); //2 line matrix
    delay(50);
    lcdcmd(0x01); //clear lcd
    delay(50);
    lcdcmd(0x0E); // cursor start
    delay(50);
    lcdcmd(0x80); //cursor begins at line 1
    delay(50);
    return;
}

unsigned int receiveserial()
{
 
    while(!(UCSRA) & (1<<RXC));
    return UDR;
}

void drawstring(unsigned char *stri)
{
    unsigned char stri;
    int j;
    while(stri[j]!='\0')
    {
        lcddata(stri[j]);
        j++;
    }
    return;
}
void checkgpgga()
{
    int i;
    int j;
    data=receiveserial();
    if(data=='$')
    {
        data=receiveserial();
        if(data=='G')
        {
            data=receiveserial()
            if(data=='P')
            {
                data=receiveserial();
                if(data=='G')
                {
                    data=receiveserial();
                    if(data=='G')
                    {
                        data=receiveserial();
                        if(data=='A')
                        {
                            data-receiveserial();
                            if(data==',')
                            {
                                data=receiveserial();
                                while(data!=',')
                                {
                                    data=receiveserial();
                                }
                                while(data!=',')
                                {
                                    data=receiveserial();
                                }
                                lat[0]=receiveserial();
                                data=lat[0];
                                for(i=0;data!=',';i++)
                                {
                                    lat[i]=receiveserial();
                                    data=lat[i];
                                }
                                lati=receiveserial();
                                data=receiveserial();
                                while(data!=',')
                                    {
                                        data=receiveserial();
                                    }
                                    long[0]=receiveserial();
                                    data=long[0];
                                    for(i=1;data!=',';i++)
                                    {
                                        long[i]=receiveserial();
                                        data=long[i];
                                    }
                                    longi=receiveserial();
                                    lcdcmd(0x01);
                                    delay(1);
                                    lcdcmd(0x80);
                                    delay(1000);
                                    i=0;
                                    while(lat[i]!='\0')
                                    {
                                        lcddata(lat[j]);
                                        j++;
                                    }
                                    lcddata(lati);
                                    lcdcmd(0xC0);
                                    delay(1000);
                                    i=0;
                                    while(long[i]!='\0')
                                    {
                                        lcddata(long[i]);
                                        i++;
                                    }
                                    lcddata(longi);
                                    delay(1000);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}





void delay(unsigned int times)
{
    unsigned int i;
    unsigned int j;
    for(i=0;i<times;i++)
    for(j=0;j<1275;j++);
}
Tue Jan 09 2018, 07:35 PM
#2
Why do you think there is something wrong with it ?
Tue Jan 09 2018, 07:42 PM
#3
I just think something is off in the checkgpgga function. That was the avr version. I have attached my 8051 version below which definitely has issues in the printing the latitude and longitude correctly.


#include <stdio.h>

#include <reg51.h>

#define lcdport P2;
//sfr lcd_data_pin=0xa0; 
#define lcdport P2;
sbit rs=P3^0; //register select
sbit rw=P3^1; // LCD read/Write
sbit en=P3^2; // enable print

void lcd_init();
void lcdcmd(unsigned char);
void lcddata(unsigned char);
void delay(int);
void drawstring(unsigned char *stri);
void receiveserial(unsigned char);
void uart_init();
void checkgpgga();
void latitude();
void longitude();


unsigned char send[90];
unsigned char send2[90];
unsigned char data;
unsigned char lat[i];//??
char checking[6]={"GPGGA"};
int main()
{
   uart_init();
   lcd_init(); 
   while(1){
       
       receiveserial();
       checkgpgga();
       latitude();
       longitdude();
       
   }

    return 0;
}

void uart_init()
{
    IE=0x00;
    SCON=0x50; // receiving enabled
    TMOD=0x20; // timer 1 auto reload
    TH1=0xfd;// value loaded to timer, baud rate 9600bps
    TR1=1; //timer 1 start
    IE=0x90; // enable serial interrupt
    
}

void lcdcmd(unsigned char n)
{
    lcdport=n;
    rw=0;
    rs=0;
    en=1;
    delay(1);
    en=0;
}

void lcddata(unsigned char n)
{
    lcdport=n;
    rs=1;
    rw=0;
    en=1;
    delay(1);
    en=0;
}

void lcd_init()
{
    lcdcmd(0x38); //2 line matrix
    delay(50);
    lcdcmd(0x0F); //cursor blinking
    delay(50);
    lcdcmd(0x01); // clears lcdcmd
    delay(50);
    lcdcmd(0x80); //cursor begins at line 1
    delay(50);
    
}

void receiveserial()
{
    while(RI==0);
    send2[i]=send2[90];
    send2[i++]=SBUF;
    RI=0;
    return (send2);
}
void checkgpgga()
{
    data=receiveserial();
    if(data=='$')
    {
        data=receiveserial();
        if(data=='G')
        {
            data=receiveserial()
            if(data=='P')
            {
                data=receiveserial();
                if(data=='G')
                {
                    data=receiveserial();
                    if(data=='G')
                    {
                        data=receiveserial();
                        if(data=='A')
                        {
                            data-receiveserial();
                            if(data==',')
                            {
                                data=receiveserial();
                                while(data!=',')
                                {
                                    data=receiveserial();
                                }
                                while(data!=',')
                                {
                                    data=receiveserial();
                                }
                                lat[0]=receiveserial();
                                data=lat[0];
                                for(i=0;data!=',';i++)
                                {
                                    lat[i]=receiveserial();
                                    data=lat[i];
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}


void latitude()
{
    
    int i;
    lcdcmd(0x01); //clear LCD display
    lcdcmd(0x84); //move cursor to position 6 of line 1
    drawstring("Latitude:");
    lcdcmd(0xC0); //beginning of second line
    lcddata(lat[i+1]);
    lcddata(lat[i+2]);
    lcdcmd(64); //for degrees
    lcddata(lat[i+3]);
    lcddata(lat[i+4]);
    lcddata(lat[i+5]);
    lcddata(lat[i+6]);
    lcddata(lat[i+7]);
    lcddata(lat[i+8]);
    lcddata(lat[i+9]);
    lcddata(0x27); // minute hand
    lcddata(lat[i+10]);
    lcddata(lat[i+11]);
    delay(250);
    
}

void longitude()
{
    int i;
    
    for(i=0; data!=','; i++)
    {
        long[i]=receiveserial();
        data=long[i];
    }
    lcdcmd(0x01); //clear LCD display
    lcdcmd(0x84); //move cursor to position 6 of line 1
    drawstring("Longitude:");
    lcdcmd(0xC0); //beginning of second line
    lcddata(long[i+1]);
    lcddata(long[i+2]);
    lcdcmd(64); //for degrees
    lcddata(long[i+3]);
    lcddata(long[i+4]);
    lcddata(long[i+5]);
    lcddata(long[i+6]);
    lcddata(long[i+7]);
    lcddata(long[i+8]);
    lcddata(long[i+9]);
    lcddata(0x27); // minute hand
    lcddata(long[i+10]);
    lcddata(long[i+11]);
    delay(250);
}

void delay(unsigned int times)
{
    unsigned int i;
    unsigned int j;
    for(i=0;i<times;i++)
    for(j=0;j<1275;j++);
}
Fri Jan 12 2018, 12:01 AM
#4
I tried to compile your 8051 version in Keil 5
but failed,because there were several errors.
You need to start with simple code that at least compiles
before writing a full program.
Are you building a hardware project or simulating in Proteus ?

What compiler are you using ?


[ Edited Fri Jan 12 2018, 12:03 AM ]

Get Social

Information

Powered by e107 Forum System

Conversation

ExperimenterUK
Mon Dec 03 2018, 06:17 PM
Please post questions in the forum. The chat box is for chat
Mon Dec 03 2018, 07:43 AM
help!me!
help! I don't understand busy flag!
Sun Dec 02 2018, 09:01 PM
ile
hello
Mon Nov 12 2018, 06:58 AM
Pavan_user
i have seen your replica of I2C programming using AT89C51 but i am unable to understand the "ack_bit" variable usage ...looks like it is always 1...can you elaborate how acknowledgment is working....
bgk3678
Tue Nov 06 2018, 03:36 PM
kindly any one give solution for my problem
ExperimenterUK
Mon Nov 05 2018, 10:48 PM
Pins high is the normal state. You need a program to set them low
mayengbam
Sun Nov 04 2018, 06:41 PM
hello, i am niranjoy, alll the port of my 8051 is always high, even i erase all the program. why is it so happen and what is the problem. any one please help me!
Sun Nov 04 2018, 03:16 PM
BASAVARAJ g kudamble
hi I am interfacing GSM 300 to 8051 microcontroller to receive message from mobile
ExperimenterUK
Sat Sep 29 2018, 07:28 PM
Please post questions in the forum.
Sat Sep 29 2018, 12:26 PM
Ashfaq Ch
hi i have some AT89C51RC microcontrollers already programed. some one help us to how to download from AT89C51RC and after study and edit all corractions reload to AT89C51RC controller

Downloads

Comments

mauste
Thu Dec 13 2018, 01:52 PM
sifirsekiz
Wed Dec 12 2018, 01:37 PM
cadetjeff
Fri Dec 07 2018, 10:11 AM
crak0axel
Sun Dec 02 2018, 01:12 AM
AbuHishaam
Thu Nov 29 2018, 03:43 PM
Evgen87
Thu Nov 29 2018, 10:44 AM
akshaykulkarni
Mon Nov 26 2018, 05:18 AM
atalnet
Fri Nov 16 2018, 07:44 AM

Online

Guests: 47, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 38028
Newest member: mauste
Forum Activity
sifirsekiz Avatar
Posted By sifirsekiz
Thu Dec 13 2018, 04:31 PM
sifirsekiz Avatar
Posted By sifirsekiz
Wed Dec 12 2018, 01:50 PM
Hi guys I have max30100 pulse sensor need to measu...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Nov 19 2018, 01:11 AM
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu Nov 15 2018, 06:48 PM
Unfortunately I have no experience of LabView,but ...
katherineamt Avatar
Posted By katherineamt
Mon Nov 12 2018, 03:22 PM
I have never used LabView and I have to implement ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Nov 12 2018, 01:21 AM
wimac Avatar
Posted By wimac
Sun Nov 11 2018, 04:03 PM
bgk3678 Avatar
Posted By bgk3678
Sun Nov 11 2018, 07:25 AM
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Nov 06 2018, 06:10 PM
bgk3678 Avatar
Posted By bgk3678
Sun Nov 04 2018, 02:52 PM