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

Sat May 15 2021, 11:47 AM
Derek Wolcott
Geometric Energy Corporation announced the dogecoin-funded mission on Sunday, with DOGE-1 representing a 40 kilogram cube satellite flying as a payload on a Falcon 9 rocket.
Thu May 13 2021, 07:18 PM
Rufus
Pretty section of content. I just stumbled upon your weblog and in accession capital to assert that I get actually enjoyed account your blog posts. Any way I will be subscribing to your augment and even I achievement you access consistently quickly. https://mkfinstitute.com Trisha Trisha
Wed May 12 2021, 01:23 PM
Jed Roan
Now you can promote your site all over the internet for FREE: http://www3.listofsitesthatacceptfreeads.club
Wed May 12 2021, 08:20 AM
Edgardo
If some one wants to be updated with most recent technologies afterward he must be visit this web page and be up to date every day. annual credit report https://creditscoresetf.com
Wed May 12 2021, 06:11 AM
Laurinda
Great website. A lot of useful information here. I'm sending it to some pals ans also sharing in delicious. And of course, thanks on your effort! annual credit report https://creditscorecheckn.com

Downloads

Comments

Mirza123
Thu Jun 25 2020, 03:46 PM
eunicelove124
Mon Jun 22 2020, 03:03 PM
cerouno
Tue Jun 16 2020, 05:10 PM
Marce
Sat Jun 13 2020, 09:43 PM
Davidthils
Thu May 21 2020, 12:44 PM
Jakeror
Thu May 21 2020, 01:28 AM
motorCar
Wed May 20 2020, 07:05 PM
Vordrync
Wed May 20 2020, 11:52 AM

Online

Guests: 116, Members: 0 ...

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

Members: 38215
Newest member: Mirza123