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

Sun May 20 2018, 10:01 AM
justinb
how to write and execute a program that read the keypad button and display the number on 7 segment on intel8051 at89s52 in assembly language?
Thu May 17 2018, 06:36 AM
HAMZA TAJ
sir iwant to ask about controller of three phase supply by using back to back thyristor instead of triac....will u give me some guideline?
Sat Apr 28 2018, 12:54 PM
ashutosh jain
IR Remote Switch using TV remote (RC5 Protocol) is not working properly. opp1 & opp2 is in problem.plz help
ExperimenterUK
Fri Apr 27 2018, 08:09 PM
@kaiserslautern Post in forum
Wed Apr 25 2018, 07:09 AM
kaiserslautern
Hello everyone, using software uart is a very good idea for a second serial port. Thank you so much. I would kindly like to know how to connect this port to the PC?
ExperimenterUK
Sat Apr 21 2018, 07:50 PM
This is a community site. Feel free to help anyone needing advice
hareeshchamiyar
Thu Mar 29 2018, 10:47 AM
please help me for the configuration bits for dspic30f2010
hareeshchamiyar
Thu Mar 29 2018, 10:45 AM
can any one using dspic30f2010.
Thu Mar 29 2018, 06:03 AM
Neena
can anybody give solar tracking in 8051 using proteus and keil to mail [email protected]
ExperimenterUK
Mon Mar 19 2018, 07:33 PM
sorry bedo.. maybe next time

Downloads

Comments

bdmehta
Tue May 22 2018, 02:30 AM
kmag1953
Sun Apr 29 2018, 07:09 PM
udiwonder
Sat Apr 28 2018, 12:41 PM
pirpiri
Sat Apr 21 2018, 03:35 PM
Pater
Fri Apr 20 2018, 02:38 PM
jamiel
Sat Apr 14 2018, 12:47 AM
akrepkral76
Wed Apr 04 2018, 07:51 PM
samanthaeaves
Mon Apr 02 2018, 06:27 AM

Online

Guests: 60, Members: 0 ...

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

Members: 37998
Newest member: bdmehta
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Sat Jun 16 2018, 11:33 PM
hi sir sorry for the late reply sir can we control...
LAMBO Avatar
Posted By LAMBO
Sat Jun 16 2018, 07:15 AM
hi sir sorry for the late reply sir can we control...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon May 14 2018, 10:17 PM
So the main problem is that I am not getting Analo...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon May 14 2018, 09:40 PM
Hi sir after checking all the connection i...
Pater Avatar
Posted By Pater
Mon May 14 2018, 05:36 PM
Basically my project is based on Data Acquisition ...
LAMBO Avatar
Posted By LAMBO
Sun May 13 2018, 02:13 PM
Hi sir after checking all the connection i...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon May 07 2018, 07:27 PM
This design should be fine.Choose a frequency betw...
Pater Avatar
Posted By Pater
Mon May 07 2018, 01:28 PM
Sorry for late reply as exams were on,Based on my ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu May 03 2018, 03:32 PM
If the circuit works with a light bulb, the probl...
LAMBO Avatar
Posted By LAMBO
Thu May 03 2018, 08:04 AM
Hi sir as u mentioned above everthing is working...