This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How Is The Uart Going To Work?, installing gps and 3g

I've been learning about uart recently and i was wondering how to use it on the 80C52. Assuming i have space, im going to put a gps and maybe 3g module in there somewhere.
For the gps i wanted to use navit of course, but does navit have like a uart input? or will it just... work? I don't really know what im tring to ask

Parents
  • here is some code

    
    
    
    #ifndef __LCD_H__
    #define __LCD_H__
    
    void lcd_init(void);
    void delay();
    void control_word(unsigned char ch);
    void data_word(unsigned char ch);
    void wrt_value(unsigned char x);
    void cursorxy(unsigned char x, unsigned char y);
    void disp_str(unsigned char msg[]);
    void wrt_string(unsigned char *string);
    void wrt_long(unsigned long a);
    void wrt_char(unsigned char a);
    void wrt_int(unsigned int a);
    void wrt_dec_char(unsigned char x);
    void wrt_dec_long(unsigned long a);
    void wrt_dec_int(unsigned int a);
    void wrt_2dec_place(unsigned char a);
    void wrt_float(float a);
    
    #endif
    
    
    
    #include <reg51.h>
    #define   LCD    P2      // lcd connected to this port
    
    void delay()
    {
       unsigned char i;
       for (i=0; i<255 ;i++);
    }
    
    void control_word(unsigned char ch)
    {
       unsigned char copy;
    
       copy  = ch;         //save a copy of it
       ch = ch >> 4;      //get the higher nibble
       ch = ch & 0x0f;      // -- do --
       ch = ch | 0x20;      // add E(bit 6) &  RS (bit 5)
       LCD = ch;         //out to lcd data port HIGHER nibble with E=1, RS=0
    
       ch = ch & 0x0f;      // make E=0, RS=0 with higher nibble
       LCD = ch;         //out to lcd data port higher nibble with E=0, RS=0
    
       ch = copy;         //get original byte
       ch = ch & 0x0f;      //to get lower nibble
       ch = ch | 0x20;      // E=1, RS=0
       LCD = ch;         //out to lcd data port LOWER nibble with E=1, RS=0
    
       ch = ch & 0x0f;      // make E=0, RS=0
       LCD = ch;         //out to lcd data port lower nibble with E=0, RS=0
    
       delay();         // give some delay here
                      //
    }
    
    void data_word(unsigned char ch)
    {
       unsigned char copy;
       copy  = ch;         //save a copy of it
       ch = ch >> 4;      //get the higher nibble
       ch = ch & 0x0f;      // -- do --
       ch = ch | 0x30;      // add E(bit 6) &  RS (bit 5)
       LCD = ch;         //out to lcd data port HIGHER nibble with E=1, RS=1
    
       ch = ch & 0x1f;      // make E=0, RS=1 with higher nibble
       LCD = ch;         //out to lcd data port higher nibble with E=0, RS=1
    
       ch = copy;         //get original byte
       ch = ch & 0x0f;      //to get lower nibble
       ch = ch | 0x30;      // E=1, RS=1
       LCD = ch;         //out to lcd data port LOWER nibble with E=1, RS=1
    
       ch = ch & 0x1f;      // make E=0, RS=1
       LCD = ch;         //out to lcd data port lower nibble with E=0, RS=1
    
       delay();         // give some delay here
    }
    
    
    void lcd_init(void)
    {
       control_word(0x28);// 4bit, 2lines, 5x7
       control_word(0x28);// again
       control_word(0x0E);// disp On, cursor On, no blink
       control_word(0x01);// clear LCD
       control_word(0x06);// CUR_RIGHT
       control_word(0x80);// line 1 cur. position 0
    }
    
    void disp_str(unsigned char msg[])
    {
       unsigned char i;
       while(msg != '\0')
       {
          data_word(msg[i++]);
       }
    }
    
    /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       Bringing Cursor to (X,Y) location of LCD
          X -> 1,2
          Y -> 1,16
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
    
    void cursorxy(unsigned char x, unsigned char y)
    {
       if((x<1||x>2)&&(y<1||y>16))
       {
          x=1;
          y=1;
       }
       if(x == 1)
          control_word(0x7F+y);
       else
          control_word(0xBF+y);
    }
    
    void wrt_value(unsigned char x)
    {
       unsigned char temp;
       temp = x/0x10;
       if(temp>9)
          return;
       else
          data_word(temp+0x30);
       temp = x%0x10;
       if(temp>9)
          return;
       else
          data_word(temp+0x30);
    }
    
    /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       Writing string to LCD
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
    
    void wrt_string(unsigned char *string)
    {
       delay();
       while(*string)
          data_word(*string++);
    }
    //-----------------------------------------------
    
    void wrt_long(unsigned long a)
    {
       unsigned char i;
       unsigned char b,c[8]={48,48,48,48,48,48,48,48};
       for(i = 7;a > 0;i--)
       {
          b = a % 16;
          if(b <= 9)
             b = b + 48;
          else
             b = b + 55;
          a =  a / 16;
          c = b;
        }
       for(i =0; i<=7;i++)
       data_word(c);
    }
    
    //-----------------------------------------------
    void wrt_int(unsigned int a)
    {
       unsigned char i;
       unsigned char b,c[4]={48,48,48,48};
       for(i = 3;a > 0;i--)
       {
          b = a % 16;
          if(b <= 9)
             b = b + 48;
          else
             b = b + 55;
          a =  a / 16;
          c = b;
        }
       for(i =0; i<=3;i++)
       data_word(c);
    }
    
    //-----------------------------------------------
    void wrt_char(unsigned char x)
    {
       unsigned char temp;
       temp = x/0x10;
       if(temp>9)
          data_word(temp+55);
       else
          data_word(temp+48);
       temp = x%0x10;
       if(temp>9)
          data_word(temp+55);
       else
          data_word(temp+48);
    }
    //------------------------------------
    void wrt_dec_char(unsigned char a)
    {
       unsigned char i;
       unsigned char b,c[3]={48,48,48};
       for(i = 2;a > 0;i--)
       {
          b = a % 10;
          b = b + 48;
    
          a =  a / 10;
          c = b;
        }
       for(i =0; i<=2;i++)
       data_word(c);
    }
    //-----------------------------------------------
    void wrt_dec_long(unsigned long a)
    {
       unsigned char i;
       unsigned char b,c[10]={48,48,48,48,48,48,48,48,48,48};
       for(i = 9;a > 0;i--)
       {
          b = a % 10;
          b = b + 48;
    
          a =  a / 10;
          c = b;
        }
       for(i =0; i<=9;i++)
       data_word(c);
    }
    
    //-----------------------------------------------
    void wrt_dec_int(unsigned int a)
    {
       unsigned char i;
       unsigned char b,c[5]={48,48,48,48,48};
       for(i = 4;a > 0;i--)
       {
          b = a % 10;
          b = b + 48;
    
          a =  a / 10;
          c = b;
        }
       for(i =0; i<=4;i++)
       data_word(c);
    }
    //------------------------------------
    void wrt_2dec_place(unsigned char a)
    /* function to write the fractional part after decimal upto
       two decimal places
       INPUT : the decimal part as unsigned char   */
    {
       unsigned char i;
       unsigned char b,c[2]={48,48};
       for(i = 1;a > 0;i--)
       {
          b = a % 10;
          b = b + 48;
    
          a =  a / 10;
          c = b;
        }
       for(i =0; i<=1;i++)
       data_word(c);
    }
    //------------------------------------
    void wrt_float(float a)
    /* function to write the floating point number upto
       two decimal places
       INPUT : floating point number
       OUTPUT : xxxxx.yy   on lcd at current cursor position */
    {
       unsigned int i;
       unsigned char j;
    
       i = (unsigned int)a;
       wrt_dec_int(i);
    
       wrt_string(".");
       j = (unsigned char)((a - i) * 100);
    
       wrt_2dec_place(j);
    }
    //-----------------------------------------------
    
    
    
    

Reply
  • here is some code

    
    
    
    #ifndef __LCD_H__
    #define __LCD_H__
    
    void lcd_init(void);
    void delay();
    void control_word(unsigned char ch);
    void data_word(unsigned char ch);
    void wrt_value(unsigned char x);
    void cursorxy(unsigned char x, unsigned char y);
    void disp_str(unsigned char msg[]);
    void wrt_string(unsigned char *string);
    void wrt_long(unsigned long a);
    void wrt_char(unsigned char a);
    void wrt_int(unsigned int a);
    void wrt_dec_char(unsigned char x);
    void wrt_dec_long(unsigned long a);
    void wrt_dec_int(unsigned int a);
    void wrt_2dec_place(unsigned char a);
    void wrt_float(float a);
    
    #endif
    
    
    
    #include <reg51.h>
    #define   LCD    P2      // lcd connected to this port
    
    void delay()
    {
       unsigned char i;
       for (i=0; i<255 ;i++);
    }
    
    void control_word(unsigned char ch)
    {
       unsigned char copy;
    
       copy  = ch;         //save a copy of it
       ch = ch >> 4;      //get the higher nibble
       ch = ch & 0x0f;      // -- do --
       ch = ch | 0x20;      // add E(bit 6) &  RS (bit 5)
       LCD = ch;         //out to lcd data port HIGHER nibble with E=1, RS=0
    
       ch = ch & 0x0f;      // make E=0, RS=0 with higher nibble
       LCD = ch;         //out to lcd data port higher nibble with E=0, RS=0
    
       ch = copy;         //get original byte
       ch = ch & 0x0f;      //to get lower nibble
       ch = ch | 0x20;      // E=1, RS=0
       LCD = ch;         //out to lcd data port LOWER nibble with E=1, RS=0
    
       ch = ch & 0x0f;      // make E=0, RS=0
       LCD = ch;         //out to lcd data port lower nibble with E=0, RS=0
    
       delay();         // give some delay here
                      //
    }
    
    void data_word(unsigned char ch)
    {
       unsigned char copy;
       copy  = ch;         //save a copy of it
       ch = ch >> 4;      //get the higher nibble
       ch = ch & 0x0f;      // -- do --
       ch = ch | 0x30;      // add E(bit 6) &  RS (bit 5)
       LCD = ch;         //out to lcd data port HIGHER nibble with E=1, RS=1
    
       ch = ch & 0x1f;      // make E=0, RS=1 with higher nibble
       LCD = ch;         //out to lcd data port higher nibble with E=0, RS=1
    
       ch = copy;         //get original byte
       ch = ch & 0x0f;      //to get lower nibble
       ch = ch | 0x30;      // E=1, RS=1
       LCD = ch;         //out to lcd data port LOWER nibble with E=1, RS=1
    
       ch = ch & 0x1f;      // make E=0, RS=1
       LCD = ch;         //out to lcd data port lower nibble with E=0, RS=1
    
       delay();         // give some delay here
    }
    
    
    void lcd_init(void)
    {
       control_word(0x28);// 4bit, 2lines, 5x7
       control_word(0x28);// again
       control_word(0x0E);// disp On, cursor On, no blink
       control_word(0x01);// clear LCD
       control_word(0x06);// CUR_RIGHT
       control_word(0x80);// line 1 cur. position 0
    }
    
    void disp_str(unsigned char msg[])
    {
       unsigned char i;
       while(msg != '\0')
       {
          data_word(msg[i++]);
       }
    }
    
    /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       Bringing Cursor to (X,Y) location of LCD
          X -> 1,2
          Y -> 1,16
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
    
    void cursorxy(unsigned char x, unsigned char y)
    {
       if((x<1||x>2)&&(y<1||y>16))
       {
          x=1;
          y=1;
       }
       if(x == 1)
          control_word(0x7F+y);
       else
          control_word(0xBF+y);
    }
    
    void wrt_value(unsigned char x)
    {
       unsigned char temp;
       temp = x/0x10;
       if(temp>9)
          return;
       else
          data_word(temp+0x30);
       temp = x%0x10;
       if(temp>9)
          return;
       else
          data_word(temp+0x30);
    }
    
    /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       Writing string to LCD
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
    
    void wrt_string(unsigned char *string)
    {
       delay();
       while(*string)
          data_word(*string++);
    }
    //-----------------------------------------------
    
    void wrt_long(unsigned long a)
    {
       unsigned char i;
       unsigned char b,c[8]={48,48,48,48,48,48,48,48};
       for(i = 7;a > 0;i--)
       {
          b = a % 16;
          if(b <= 9)
             b = b + 48;
          else
             b = b + 55;
          a =  a / 16;
          c = b;
        }
       for(i =0; i<=7;i++)
       data_word(c);
    }
    
    //-----------------------------------------------
    void wrt_int(unsigned int a)
    {
       unsigned char i;
       unsigned char b,c[4]={48,48,48,48};
       for(i = 3;a > 0;i--)
       {
          b = a % 16;
          if(b <= 9)
             b = b + 48;
          else
             b = b + 55;
          a =  a / 16;
          c = b;
        }
       for(i =0; i<=3;i++)
       data_word(c);
    }
    
    //-----------------------------------------------
    void wrt_char(unsigned char x)
    {
       unsigned char temp;
       temp = x/0x10;
       if(temp>9)
          data_word(temp+55);
       else
          data_word(temp+48);
       temp = x%0x10;
       if(temp>9)
          data_word(temp+55);
       else
          data_word(temp+48);
    }
    //------------------------------------
    void wrt_dec_char(unsigned char a)
    {
       unsigned char i;
       unsigned char b,c[3]={48,48,48};
       for(i = 2;a > 0;i--)
       {
          b = a % 10;
          b = b + 48;
    
          a =  a / 10;
          c = b;
        }
       for(i =0; i<=2;i++)
       data_word(c);
    }
    //-----------------------------------------------
    void wrt_dec_long(unsigned long a)
    {
       unsigned char i;
       unsigned char b,c[10]={48,48,48,48,48,48,48,48,48,48};
       for(i = 9;a > 0;i--)
       {
          b = a % 10;
          b = b + 48;
    
          a =  a / 10;
          c = b;
        }
       for(i =0; i<=9;i++)
       data_word(c);
    }
    
    //-----------------------------------------------
    void wrt_dec_int(unsigned int a)
    {
       unsigned char i;
       unsigned char b,c[5]={48,48,48,48,48};
       for(i = 4;a > 0;i--)
       {
          b = a % 10;
          b = b + 48;
    
          a =  a / 10;
          c = b;
        }
       for(i =0; i<=4;i++)
       data_word(c);
    }
    //------------------------------------
    void wrt_2dec_place(unsigned char a)
    /* function to write the fractional part after decimal upto
       two decimal places
       INPUT : the decimal part as unsigned char   */
    {
       unsigned char i;
       unsigned char b,c[2]={48,48};
       for(i = 1;a > 0;i--)
       {
          b = a % 10;
          b = b + 48;
    
          a =  a / 10;
          c = b;
        }
       for(i =0; i<=1;i++)
       data_word(c);
    }
    //------------------------------------
    void wrt_float(float a)
    /* function to write the floating point number upto
       two decimal places
       INPUT : floating point number
       OUTPUT : xxxxx.yy   on lcd at current cursor position */
    {
       unsigned int i;
       unsigned char j;
    
       i = (unsigned int)a;
       wrt_dec_int(i);
    
       wrt_string(".");
       j = (unsigned char)((a - i) * 100);
    
       wrt_2dec_place(j);
    }
    //-----------------------------------------------
    
    
    
    

Children