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
Thu Jan 11 2018, 06:23 PM
Hi Dave. Good to see you. Parole ?
DavesGarage
Wed Jan 10 2018, 12:55 PM
It's been a few years since I poked around here - Hi all...
ExperimenterUK
Tue Jan 09 2018, 12:19 PM
Hi TPS. it's been a while..
۞ TPS ۞
Mon Jan 08 2018, 11:42 AM
hello
Fri Jan 05 2018, 06:50 AM
sayyad affrid
its AT89S52
Fri Jan 05 2018, 06:50 AM
sayyad affrid
sir, i want embedded c code for ultrasonic sensor having buzzer interfaced with AT9S52
Tue Dec 19 2017, 01:12 PM
zafir
i am making digital voltmeter using AT89C51, ADC and LCD 16x2,,, kindly someone please send me hex file in assembly language
Sat Dec 16 2017, 05:18 AM
mehari
can not find dhtxx.md file in proteus 8.0 can anybody help me please?
sahar7478
Sat Dec 09 2017, 05:47 AM
can i get gsm a6 library? can anybody help? tia
Faiqa
Sun Nov 26 2017, 01:32 AM
Can i get the code of Monitering and controlling of green house effect? ... Can anyone help me ?

Downloads

Comments

eddieprice
Fri Jan 12 2018, 04:07 PM
bastik
Fri Jan 12 2018, 09:36 AM
cjj20
Tue Jan 09 2018, 07:29 PM
shahzadiqbal
Tue Jan 09 2018, 01:57 PM
shailu1809
Mon Jan 08 2018, 01:11 AM
saffrid97
Sun Jan 07 2018, 01:48 AM
vietbac
Sat Jan 06 2018, 10:08 AM
Pecman
Wed Jan 03 2018, 03:58 PM

Online

Guests: 52, Members: 0 ...

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

Members: 37943
Newest member: eddieprice
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Sat Jan 13 2018, 10:26 PM
This is clearly an old design.A modern microcontr...
bastik Avatar
Posted By bastik
Sat Jan 13 2018, 09:38 PM
For now I don’t have much information about device...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Jan 12 2018, 06:49 PM
Sometimes the Configuration word has to be program...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Jan 12 2018, 06:30 PM
What exactly is your situation ?I very much doubt ...
eddieprice Avatar
Posted By eddieprice
Fri Jan 12 2018, 04:32 PM
I am using a 16F84A for the first time and am havi...
bastik Avatar
Posted By bastik
Fri Jan 12 2018, 10:37 AM
I have device with SAB80C535 microcontroller and I...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Jan 12 2018, 12:01 AM
I tried to compile your 8051 version in Keil 5but...
cjj20 Avatar
Posted By cjj20
Tue Jan 09 2018, 07:42 PM
I just think something is off in the checkgpgga fu...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Jan 09 2018, 07:35 PM
Why do you think there is something wrong with it...
cjj20 Avatar
Posted By cjj20
Tue Jan 09 2018, 07:32 PM
Please help me correct this code #include ...