اطلاعیه

Collapse
No announcement yet.

مشکل در نمایش اطلاعات روی lcd 2*16

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    مشکل در نمایش اطلاعات روی lcd 2*16

    سلام و عرض ادب خدمت دوستان گرامی
    بنده میخوام اطلاعاتی رو از ماژول gps دریافت و اون اطلاعات رو روی ال سی دی کاراکتری نمایش بدم
    برنامه تو محیط کدویژن نوشته شده
    فقط یه مشکلی دارم اونم بخاط اینکه بنده قبلا با بسکام کار میکردم خیلی درک درستی از زبان سی codevision ندارم
    البته منابع زیادی رو خوندم و چنتا برناه ساده هم تو کدویژن هم نوشتم (البته چنتا تمرین های ساده تو آموزش ها) فقط اینکه چون این برنامه توسط شخص دیگه ای نوشته شده و بنده اون رو ویرایش کردم به مشکل برخوردم
    حالا مشکل بنده:
    برنامه نوشته شده توسط شخص محترم برای نمایش تو glcd ks108 هست ولی بنده میخولم به جای اون تو lcd2*16 معمولی نمایش داده بشه
    آماده اون هم تو اینترنت پیدا میشه با هزینه تقریا 25 تومان ولی از اونحایی که متوجه نمیشی برنامه نویس چکار کرده و اماده استفاده میکنی جالب نیست
    از دوستانی که تو این زمینه تجربه دارن خواهش میکنم در صورت امکان به بنده کمک کنن
    حالا کد ها:
    #include <mega32.h>
    // Graphic Display functions
    #include <glcd.h>
    #include <string.h>
    #include <delay.h>
    // Font used for displaying text
    // on the graphic display
    #include <font5x7.h>
    #include <stdlib.h>
    // Declare your global variables here
    #include "GPS.h"

    #define DATA_REGISTER_EMPTY (1<<UDRE)
    #define RX_COMPLETE (1<<RXC)
    #define FRAMING_ERROR (1<<FE)
    #define PARITY_ERROR (1<<UPE)
    #define DATA_OVERRUN (1<<DOR)

    // USART Receiver buffer
    #define RX_BUFFER_SIZE 8
    char rx_buffer[RX_BUFFER_SIZE];

    #if RX_BUFFER_SIZE <= 256
    unsigned char rx_wr_index=0,rx_rd_index=0;
    #else
    unsigned int rx_wr_index=0,rx_rd_index=0;
    #endif

    #if RX_BUFFER_SIZE < 256
    unsigned char rx_counter=0;
    #else
    unsigned int rx_counter=0;
    #endif

    // This flag is set on USART Receiver buffer overflow
    bit rx_buffer_overflow;

    // USART Receiver interrupt service routine
    interrupt [USART_RXC] void usart_rx_isr(void)
    {
    char status,data;
    status=UCSRA;
    data=UDR;
    if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)
    {
    rx_buffer[rx_wr_index++]=data;
    #if RX_BUFFER_SIZE == 256
    // special case for receiver buffer size=256
    if (++rx_counter == 0) rx_buffer_overflow=1;
    #else
    if (rx_wr_index == RX_BUFFER_SIZE) rx_wr_index=0;
    if (++rx_counter == RX_BUFFER_SIZE)
    {
    rx_counter=0;
    rx_buffer_overflow=1;
    }
    #endif
    }
    }

    #if ndef _DEBUG_TERMINAL_IO_
    // Get a character from the USART Receiver buffer
    #define _ALTERNATE_GETCHAR_
    #pragma used+
    char getchar(void)
    {
    char data;
    while (rx_counter==0);
    data=rx_buffer[rx_rd_index++];
    #if RX_BUFFER_SIZE != 256
    if (rx_rd_index == RX_BUFFER_SIZE) rx_rd_index=0;
    #endif
    #asm ("cli")
    --rx_counter;
    #asm ("sei")
    return data;
    }
    #pragma used-
    #endif

    // Standard Input/Output functions
    #include <stdio.h>

    void main(void)
    {
    unsigned char Y[150];
    // Declare your local variables here
    // Variable used to store graphic display
    // controller initialization data
    GLCDINIT_t glcd_init_data;

    // Input/Output Ports initialization
    // Port A initialization
    // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
    DDRA=(0<<DDA7) | (0<<DDA6) | (0<<DDA5) | (0<<DDA4) | (0<<DDA3) | (0<<DDA2) | (0<<DDA1) | (0<<DDA0);
    // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
    PORTA=(0<<PORTA7) | (0<<PORTA6) | (0<<PORTA5) | (0<<PORTA4) | (0<<PORTA3) | (0<<PORTA2) | (0<<PORTA1) | (0<<PORTA0);

    // Port B initialization
    // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
    DDRB=(0<<DDB7) | (0<<DDB6) | (0<<DDB5) | (0<<DDB4) | (0<<DDB3) | (0<<DDB2) | (0<<DDB1) | (0<<DDB0);
    // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
    PORTB=(0<<PORTB7) | (0<<PORTB6) | (0<<PORTB5) | (0<<PORTB4) | (0<<PORTB3) | (0<<PORTB2) | (0<<PORTB1) | (0<<PORTB0);

    // Port C initialization
    // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
    DDRC=(0<<DDC7) | (0<<DDC6) | (0<<DDC5) | (0<<DDC4) | (0<<DDC3) | (0<<DDC2) | (0<<DDC1) | (0<<DDC0);
    // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
    PORTC=(0<<PORTC7) | (0<<PORTC6) | (0<<PORTC5) | (0<<PORTC4) | (0<<PORTC3) | (0<<PORTC2) | (0<<PORTC1) | (0<<PORTC0);

    // Port D initialization
    // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
    DDRD=(0<<DDD7) | (0<<DDD6) | (0<<DDD5) | (0<<DDD4) | (0<<DDD3) | (0<<DDD2) | (0<<DDD1) | (0<<DDD0);
    // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
    PORTD=(0<<PORTD7) | (0<<PORTD6) | (0<<PORTD5) | (0<<PORTD4) | (0<<PORTD3) | (0<<PORTD2) | (0<<PORTD1) | (0<<PORTD0);

    // Timer/Counter 0 initialization
    // Clock source: System Clock
    // Clock value: Timer 0 Stopped
    // Mode: Normal top=0xFF
    // OC0 output: Disconnected
    TCCR0=(0<<WGM00) | (0<<COM01) | (0<<COM00) | (0<<WGM01) | (0<<CS02) | (0<<CS01) | (0<<CS00);
    TCNT0=0x00;
    OCR0=0x00;

    // Timer/Counter 1 initialization
    // Clock source: System Clock
    // Clock value: Timer1 Stopped
    // Mode: Normal top=0xFFFF
    // OC1A output: Disconnected
    // OC1B output: Disconnected
    // Noise Canceler: Off
    // Input Capture on Falling Edge
    // Timer1 Overflow Interrupt: Off
    // Input Capture Interrupt: Off
    // Compare A Match Interrupt: Off
    // Compare B Match Interrupt: Off
    TCCR1A=(0<<COM1A1) | (0<<COM1A0) | (0<<COM1B1) | (0<<COM1B0) | (0<<WGM11) | (0<<WGM10);
    TCCR1B=(0<<ICNC1) | (0<<ICES1) | (0<<WGM13) | (0<<WGM12) | (0<<CS12) | (0<<CS11) | (0<<CS10);
    TCNT1H=0x00;
    TCNT1L=0x00;
    ICR1H=0x00;
    ICR1L=0x00;
    OCR1AH=0x00;
    OCR1AL=0x00;
    OCR1BH=0x00;
    OCR1BL=0x00;

    // Timer/Counter 2 initialization
    // Clock source: System Clock
    // Clock value: Timer2 Stopped
    // Mode: Normal top=0xFF
    // OC2 output: Disconnected
    ASSR=0<<AS2;
    TCCR2=(0<<PWM2) | (0<<COM21) | (0<<COM20) | (0<<CTC2) | (0<<CS22) | (0<<CS21) | (0<<CS20);
    TCNT2=0x00;
    OCR2=0x00;

    // Timer(s)/Counter(s) Interrupt(s) initialization
    TIMSK=(0<<OCIE2) | (0<<TOIE2) | (0<<TICIE1) | (0<<OCIE1A) | (0<<OCIE1B) | (0<<TOIE1) | (0<<OCIE0) | (0<<TOIE0);

    // External Interrupt(s) initialization
    // INT0: Off
    // INT1: Off
    // INT2: Off
    MCUCR=(0<<ISC11) | (0<<ISC10) | (0<<ISC01) | (0<<ISC00);
    MCUCSR=(0<<ISC2);

    // USART initialization
    // Communication Parameters: 8 Data, 1 Stop, No Parity
    // USART Receiver: On
    // USART Transmitter: Off
    // USART Mode: Asynchronous
    // USART Baud Rate: 9600
    UCSRA=(0<<RXC) | (0<<TXC) | (0<<UDRE) | (0<<FE) | (0<<DOR) | (0<<UPE) | (0<<U2X) | (0<<MPCM);
    UCSRB=(1<<RXCIE) | (0<<TXCIE) | (0<<UDRIE) | (1<<RXEN) | (0<<TXEN) | (0<<UCSZ2) | (0<<RXB8) | (0<<TXB8);
    UCSRC=(1<<URSEL) | (0<<UMSEL) | (0<<UPM1) | (0<<UPM0) | (0<<USBS) | (1<<UCSZ1) | (1<<UCSZ0) | (0<<UCPOL);
    UBRRH=0x00;
    UBRRL=0x33;

    // Analog Comparator initialization
    // Analog Comparator: Off
    // The Analog Comparator's positive input is
    // connected to the AIN0 pin
    // The Analog Comparator's negative input is
    // connected to the AIN1 pin
    ACSR=(1<<ACD) | (0<<ACBG) | (0<<ACO) | (0<<ACI) | (0<<ACIE) | (0<<ACIC) | (0<<ACIS1) | (0<<ACIS0);
    SFIOR=(0<<ACME);

    // ADC initialization
    // ADC disabled
    ADCSRA=(0<<ADEN) | (0<<ADSC) | (0<<ADATE) | (0<<ADIF) | (0<<ADIE) | (0<<ADPS2) | (0<<ADPS1) | (0<<ADPS0);

    // SPI initialization
    // SPI disabled
    SPCR=(0<<SPIE) | (0<<SPE) | (0<<DORD) | (0<<MSTR) | (0<<CPOL) | (0<<CPHA) | (0<<SPR1) | (0<<SPR0);

    // TWI initialization
    // TWI disabled
    TWCR=(0<<TWEA) | (0<<TWSTA) | (0<<TWSTO) | (0<<TWEN) | (0<<TWIE);

    // Graphic Display Controller initialization
    // The KS0108 connections are specified in the
    // Project|Configure|C Compiler|Libraries|Graphic Display menu:
    // DB0 - PORTA Bit 0
    // DB1 - PORTA Bit 1
    // DB2 - PORTA Bit 2
    // DB3 - PORTA Bit 3
    // DB4 - PORTA Bit 4
    // DB5 - PORTA Bit 5
    // DB6 - PORTA Bit 6
    // DB7 - PORTA Bit 7
    // E - PORTB Bit 0
    // RD /WR - PORTB Bit 1
    // RS - PORTB Bit 2
    // /RST - PORTB Bit 3
    // /CS1 - PORTB Bit 4
    // /CS2 - PORTB Bit 5

    // Specify the current font for displaying text
    glcd_init_data.font=font5x7;
    // No function is used for reading
    // image data from external memory
    glcd_init_data.readxmem=NULL;
    // No function is used for writing
    // image data to external memory
    glcd_init_data.writexmem=NULL;

    glcd_init(&glcd_init_data);

    // Global enable interrupts
    #asm ("sei")
    glcd_outtextxy(0,0,"GPS");
    while (1)
    {
    do scanf("%s",Y);
    while(strncmp(Y,"$GPRMC",6)!=0);
    GPRMC(Y);
    do scanf("%s",Y);
    while(strncmp(Y,"$GPGLL",6)!=0);
    GPGLL(Y);
    do scanf("%s",Y);
    while(strncmp(Y,"$GPVTG",6)!=0);
    GPVTG(Y);
    do scanf("%s",Y);
    while(strncmp(Y,"$GPGSV",6)!=0);
    GPGSV(Y);
    }
    }


    اینم لینک دانلود برنامه http://www.ictnic.com/learning/learn...D8%B1-avr.html

    دلیل: ادغام دو پست برای جلوگیری از اسپم

    این هم کد بنده وتغییرات اعمال شده
    اول اینکه هدر های فونت و #include "GPS.h" رو حذف کردم چون دیگه glcd نیست و اون تنظیمات نیاز نیست و توابع داخل هدر gps رو تو خود تابع اصلی برنامه تعریف کردم
    دوم هم دستورات مربوط به نمایش اطلاعات دریافتی از glcd به alcd تغییر دادم
    البته درستش اینه که نشد تغییر بدم
    این هم کدی که بنده تغییر دادم


    #include <string.h>
    #include <delay.h>
    #include <stdlib.h>
    #include <mega32.h>

    // Alphanumeric LCD functions
    #include <alcd.h>

    // Declare your global variables here

    // Standard Input/Output functions
    #include <stdio.h>


    #define DATA_REGISTER_EMPTY (1<<UDRE)
    #define RX_COMPLETE (1<<RXC)
    #define FRAMING_ERROR (1<<FE)
    #define PARITY_ERROR (1<<UPE)
    #define DATA_OVERRUN (1<<DOR)




    // USART Receiver buffer
    #define RX_BUFFER_SIZE 8
    char rx_buffer[RX_BUFFER_SIZE];

    #if RX_BUFFER_SIZE <= 256
    unsigned char rx_wr_index=0,rx_rd_index=0;
    #else
    unsigned int rx_wr_index=0,rx_rd_index=0;
    #endif

    #if RX_BUFFER_SIZE < 256
    unsigned char rx_counter=0;
    #else
    unsigned int rx_counter=0;
    #endif

    // This flag is set on USART Receiver buffer overflow
    bit rx_buffer_overflow;

    // USART Receiver interrupt service routine
    interrupt [USART_RXC] void usart_rx_isr(void)
    {
    char status,data;
    status=UCSRA;
    data=UDR;
    if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)
    {
    rx_buffer[rx_wr_index++]=data;
    #if RX_BUFFER_SIZE == 256
    // special case for receiver buffer size=256
    if (++rx_counter == 0) rx_buffer_overflow=1;
    #else
    if (rx_wr_index == RX_BUFFER_SIZE) rx_wr_index=0;
    if (++rx_counter == RX_BUFFER_SIZE)
    {
    rx_counter=0;
    rx_buffer_overflow=1;
    }
    #endif
    }
    }

    #ifndef _DEBUG_TERMINAL_IO_
    // Get a character from the USART Receiver buffer
    #define _ALTERNATE_GETCHAR_
    #pragma used+
    char getchar(void)
    {
    char data;
    while (rx_counter==0);
    data=rx_buffer[rx_rd_index++];
    #if RX_BUFFER_SIZE != 256
    if (rx_rd_index == RX_BUFFER_SIZE) rx_rd_index=0;
    #endif
    #asm("cli")
    --rx_counter;
    #asm("sei")
    return data;
    }
    #pragma used-
    #endif

    // Standard Input/Output functions
    void GPRMC(unsigned char X[150])
    {
    unsigned char *UTC,retx[10]={0};
    unsigned int h,m,s;
    unsigned char time[6][1],lcd[50];
    UTC=strchr(X,',');
    UTC=strtok(UTC,",");
    strcpy(time[0],UTC);
    strncpy(retx,time[0],2);
    h = atoi(retx);
    strncpy(retx,time[2],2);
    m = atoi(retx);
    strncpy(retx,time[4],2);
    s = atof(retx);
    if(m>29)h++,m-=30;
    else m+=30;
    h+=4;
    if(h>24)h-=19,h-=4;
    if(h>24&m>29)h-=19,h-=5;
    sprintf(lcd,"UTC Time:%02d:%02d:%02d",h,m,s);
    lcd_gotoxy(0,0);
    sprintf(str,"L = %d",L);
    lcd_puts(str);
    delay_ms(100);
    //lcd_gotoxy(0, 0);
    //lcd_puts(0,0,lcd);
    }
    void GPGLL(unsigned char X[150])
    {
    unsigned char lcdbuff2[16],lcdbuff1[16];
    unsigned char Lati[10]={0},GP[50][1],*rett,NS[2]={0},Long[11]={0},EW[2]={0};
    rett= strchr(X,',');
    strcpy(GP[0],rett);
    strncpy(Lati,GP[1],9);
    strncpy(NS,GP[12],1);
    strncpy(Long,GP[14],10);
    strncpy(EW,GP[26],1);
    sprintf(lcdbuff2,"Latitude:%s%s",Lati,NS);
    //lcd_outtextxy(0 ,0 ,lcdbuff2);
    sprintf(lcdbuff1,"Longtitu:%s%s",Long,EW);
    //lcd_outtextxy(0 ,0 ,lcdbuff1);
    }
    void GPVTG(unsigned char X[150])
    {
    unsigned char *speed;
    unsigned char lcdbuff[30];
    speed= strchr(X,',');
    speed=strchr(speed,'M');
    speed=strchr(speed,',');
    speed=strtok(speed,",");
    sprintf(lcdbuff,"Speed:%skm/h",speed);
    //glcd_outtextxy(0,30,lcdbuff);
    }
    void GPGSV(unsigned char X[150])
    {
    unsigned char *rett,GP[30][1];
    unsigned char gsv[3]={0},sat,lcdbuff3[16];
    rett= strchr(X,',');
    strcpy(GP[0],rett);
    strncpy(gsv,GP[5],2);
    sat=atoi(gsv);
    sprintf(lcdbuff3,"Satellite in View:%d",sat);
    //glcd_outtextxy(0,50,lcdbuff3);
    }

    void main(void)
    {
    // Declare your local variables here
    unsigned char Y[150];
    // Input/Output Ports initialization
    // Port A initialization
    // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
    DDRA=(0<<DDA7) | (0<<DDA6) | (0<<DDA5) | (0<<DDA4) | (0<<DDA3) | (0<<DDA2) | (0<<DDA1) | (0<<DDA0);
    // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
    PORTA=(0<<PORTA7) | (0<<PORTA6) | (0<<PORTA5) | (0<<PORTA4) | (0<<PORTA3) | (0<<PORTA2) | (0<<PORTA1) | (0<<PORTA0);

    // Port B initialization
    // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
    DDRB=(0<<DDB7) | (0<<DDB6) | (0<<DDB5) | (0<<DDB4) | (0<<DDB3) | (0<<DDB2) | (0<<DDB1) | (0<<DDB0);
    // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
    PORTB=(0<<PORTB7) | (0<<PORTB6) | (0<<PORTB5) | (0<<PORTB4) | (0<<PORTB3) | (0<<PORTB2) | (0<<PORTB1) | (0<<PORTB0);

    // Port C initialization
    // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
    DDRC=(0<<DDC7) | (0<<DDC6) | (0<<DDC5) | (0<<DDC4) | (0<<DDC3) | (0<<DDC2) | (0<<DDC1) | (0<<DDC0);
    // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
    PORTC=(0<<PORTC7) | (0<<PORTC6) | (0<<PORTC5) | (0<<PORTC4) | (0<<PORTC3) | (0<<PORTC2) | (0<<PORTC1) | (0<<PORTC0);

    // Port D initialization
    // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
    DDRD=(0<<DDD7) | (0<<DDD6) | (0<<DDD5) | (0<<DDD4) | (0<<DDD3) | (0<<DDD2) | (0<<DDD1) | (0<<DDD0);
    // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
    PORTD=(0<<PORTD7) | (0<<PORTD6) | (0<<PORTD5) | (0<<PORTD4) | (0<<PORTD3) | (0<<PORTD2) | (0<<PORTD1) | (0<<PORTD0);

    // USART initialization
    // Communication Parameters: 8 Data, 1 Stop, No Parity
    // USART Receiver: On
    // USART Transmitter: Off
    // USART Mode: Asynchronous
    // USART Baud Rate: 9600 (Double Speed Mode)
    UCSRA=(0<<RXC) | (0<<TXC) | (0<<UDRE) | (0<<FE) | (0<<DOR) | (0<<UPE) | (1<<U2X) | (0<<MPCM);
    UCSRB=(1<<RXCIE) | (0<<TXCIE) | (0<<UDRIE) | (1<<RXEN) | (0<<TXEN) | (0<<UCSZ2) | (0<<RXB8) | (0<<TXB8);
    UCSRC=(1<<URSEL) | (0<<UMSEL) | (0<<UPM1) | (0<<UPM0) | (0<<USBS) | (1<<UCSZ1) | (1<<UCSZ0) | (0<<UCPOL);
    UBRRH=0x00;
    UBRRL=0x0C;

    // Alphanumeric LCD initialization
    // Connections are specified in the
    // Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
    // RS - PORTA Bit 0
    // RD - PORTA Bit 1
    // EN - PORTA Bit 2
    // D4 - PORTA Bit 4
    // D5 - PORTA Bit 5
    // D6 - PORTA Bit 6
    // D7 - PORTA Bit 7
    // Characters/line: 16
    lcd_init(16);

    // Global enable interrupts
    #asm("sei")

    while (1)
    {
    // Place your code here
    lcd_clear();
    do scanf("%s",Y);
    while(strncmp(Y,"$GPRMC",6)!=0);
    GPRMC(Y);
    do scanf("%s",Y);
    while(strncmp(Y,"$GPGLL",6)!=0);
    GPGLL(Y);
    do scanf("%s",Y);
    while(strncmp(Y,"$GPVTG",6)!=0);
    GPVTG(Y);
    do scanf("%s",Y);
    while(strncmp(Y,"$GPGSV",6)!=0);
    GPGSV(Y);
    }
    }

    دلیل: ادغام دو پست برای جلوگیری از اسپم

    مشکل فقط در قسمت ارسال و نمایش داده ها میباشد
    لطفا راهنمایی بفرمایید.

    #2
    پاسخ : مشکل در نمایش اطلاعات روی lcd 2*16

    نوشته اصلی توسط rezavip164 نمایش پست ها
    سلام و عرض ادب خدمت دوستان گرامی
    بنده میخوام اطلاعاتی رو از ماژول gps دریافت و اون اطلاعات رو روی ال سی دی کاراکتری نمایش بدم
    برنامه تو محیط کدویژن نوشته شده
    فقط یه مشکلی دارم اونم بخاط اینکه بنده قبلا با بسکام کار میکردم خیلی درک درستی از زبان سی codevision ندارم
    البته منابع زیادی رو خوندم و چنتا برناه ساده هم تو کدویژن هم نوشتم (البته چنتا تمرین های ساده تو آموزش ها) فقط اینکه چون این برنامه توسط شخص دیگه ای نوشته شده و بنده اون رو ویرایش کردم به مشکل برخوردم
    حالا مشکل بنده:
    برنامه نوشته شده توسط شخص محترم برای نمایش تو glcd ks108 هست ولی بنده میخولم به جای اون تو lcd2*16 معمولی نمایش داده بشه
    آماده اون هم تو اینترنت پیدا میشه با هزینه تقریا 25 تومان ولی از اونحایی که متوجه نمیشی برنامه نویس چکار کرده و اماده استفاده میکنی جالب نیست
    از دوستانی که تو این زمینه تجربه دارن خواهش میکنم در صورت امکان به بنده کمک کنن
    حالا کد ها:
    #include <mega32.h>
    // Graphic Display functions
    #include <glcd.h>
    #include <string.h>
    #include <delay.h>
    // Font used for displaying text
    // on the graphic display
    #include <font5x7.h>
    #include <stdlib.h>
    // Declare your global variables here
    #include "GPS.h"

    #define DATA_REGISTER_EMPTY (1<<UDRE)
    #define RX_COMPLETE (1<<RXC)
    #define FRAMING_ERROR (1<<FE)
    #define PARITY_ERROR (1<<UPE)
    #define DATA_OVERRUN (1<<DOR)

    // USART Receiver buffer
    #define RX_BUFFER_SIZE 8
    char rx_buffer[RX_BUFFER_SIZE];

    #if RX_BUFFER_SIZE <= 256
    unsigned char rx_wr_index=0,rx_rd_index=0;
    #else
    unsigned int rx_wr_index=0,rx_rd_index=0;
    #endif

    #if RX_BUFFER_SIZE < 256
    unsigned char rx_counter=0;
    #else
    unsigned int rx_counter=0;
    #endif

    // This flag is set on USART Receiver buffer overflow
    bit rx_buffer_overflow;

    // USART Receiver interrupt service routine
    interrupt [USART_RXC] void usart_rx_isr(void)
    {
    char status,data;
    status=UCSRA;
    data=UDR;
    if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)
    {
    rx_buffer[rx_wr_index++]=data;
    #if RX_BUFFER_SIZE == 256
    // special case for receiver buffer size=256
    if (++rx_counter == 0) rx_buffer_overflow=1;
    #else
    if (rx_wr_index == RX_BUFFER_SIZE) rx_wr_index=0;
    if (++rx_counter == RX_BUFFER_SIZE)
    {
    rx_counter=0;
    rx_buffer_overflow=1;
    }
    #endif
    }
    }

    #if ndef _DEBUG_TERMINAL_IO_
    // Get a character from the USART Receiver buffer
    #define _ALTERNATE_GETCHAR_
    #pragma used+
    char getchar(void)
    {
    char data;
    while (rx_counter==0);
    data=rx_buffer[rx_rd_index++];
    #if RX_BUFFER_SIZE != 256
    if (rx_rd_index == RX_BUFFER_SIZE) rx_rd_index=0;
    #endif
    #asm ("cli")
    --rx_counter;
    #asm ("sei")
    return data;
    }
    #pragma used-
    #endif

    // Standard Input/Output functions
    #include <stdio.h>

    void main(void)
    {
    unsigned char Y[150];
    // Declare your local variables here
    // Variable used to store graphic display
    // controller initialization data
    GLCDINIT_t glcd_init_data;

    // Input/Output Ports initialization
    // Port A initialization
    // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
    DDRA=(0<<DDA7) | (0<<DDA6) | (0<<DDA5) | (0<<DDA4) | (0<<DDA3) | (0<<DDA2) | (0<<DDA1) | (0<<DDA0);
    // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
    PORTA=(0<<PORTA7) | (0<<PORTA6) | (0<<PORTA5) | (0<<PORTA4) | (0<<PORTA3) | (0<<PORTA2) | (0<<PORTA1) | (0<<PORTA0);

    // Port B initialization
    // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
    DDRB=(0<<DDB7) | (0<<DDB6) | (0<<DDB5) | (0<<DDB4) | (0<<DDB3) | (0<<DDB2) | (0<<DDB1) | (0<<DDB0);
    // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
    PORTB=(0<<PORTB7) | (0<<PORTB6) | (0<<PORTB5) | (0<<PORTB4) | (0<<PORTB3) | (0<<PORTB2) | (0<<PORTB1) | (0<<PORTB0);

    // Port C initialization
    // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
    DDRC=(0<<DDC7) | (0<<DDC6) | (0<<DDC5) | (0<<DDC4) | (0<<DDC3) | (0<<DDC2) | (0<<DDC1) | (0<<DDC0);
    // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
    PORTC=(0<<PORTC7) | (0<<PORTC6) | (0<<PORTC5) | (0<<PORTC4) | (0<<PORTC3) | (0<<PORTC2) | (0<<PORTC1) | (0<<PORTC0);

    // Port D initialization
    // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
    DDRD=(0<<DDD7) | (0<<DDD6) | (0<<DDD5) | (0<<DDD4) | (0<<DDD3) | (0<<DDD2) | (0<<DDD1) | (0<<DDD0);
    // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
    PORTD=(0<<PORTD7) | (0<<PORTD6) | (0<<PORTD5) | (0<<PORTD4) | (0<<PORTD3) | (0<<PORTD2) | (0<<PORTD1) | (0<<PORTD0);

    // Timer/Counter 0 initialization
    // Clock source: System Clock
    // Clock value: Timer 0 Stopped
    // Mode: Normal top=0xFF
    // OC0 output: Disconnected
    TCCR0=(0<<WGM00) | (0<<COM01) | (0<<COM00) | (0<<WGM01) | (0<<CS02) | (0<<CS01) | (0<<CS00);
    TCNT0=0x00;
    OCR0=0x00;

    // Timer/Counter 1 initialization
    // Clock source: System Clock
    // Clock value: Timer1 Stopped
    // Mode: Normal top=0xFFFF
    // OC1A output: Disconnected
    // OC1B output: Disconnected
    // Noise Canceler: Off
    // Input Capture on Falling Edge
    // Timer1 Overflow Interrupt: Off
    // Input Capture Interrupt: Off
    // Compare A Match Interrupt: Off
    // Compare B Match Interrupt: Off
    TCCR1A=(0<<COM1A1) | (0<<COM1A0) | (0<<COM1B1) | (0<<COM1B0) | (0<<WGM11) | (0<<WGM10);
    TCCR1B=(0<<ICNC1) | (0<<ICES1) | (0<<WGM13) | (0<<WGM12) | (0<<CS12) | (0<<CS11) | (0<<CS10);
    TCNT1H=0x00;
    TCNT1L=0x00;
    ICR1H=0x00;
    ICR1L=0x00;
    OCR1AH=0x00;
    OCR1AL=0x00;
    OCR1BH=0x00;
    OCR1BL=0x00;

    // Timer/Counter 2 initialization
    // Clock source: System Clock
    // Clock value: Timer2 Stopped
    // Mode: Normal top=0xFF
    // OC2 output: Disconnected
    ASSR=0<<AS2;
    TCCR2=(0<<PWM2) | (0<<COM21) | (0<<COM20) | (0<<CTC2) | (0<<CS22) | (0<<CS21) | (0<<CS20);
    TCNT2=0x00;
    OCR2=0x00;

    // Timer(s)/Counter(s) Interrupt(s) initialization
    TIMSK=(0<<OCIE2) | (0<<TOIE2) | (0<<TICIE1) | (0<<OCIE1A) | (0<<OCIE1B) | (0<<TOIE1) | (0<<OCIE0) | (0<<TOIE0);

    // External Interrupt(s) initialization
    // INT0: Off
    // INT1: Off
    // INT2: Off
    MCUCR=(0<<ISC11) | (0<<ISC10) | (0<<ISC01) | (0<<ISC00);
    MCUCSR=(0<<ISC2);

    // USART initialization
    // Communication Parameters: 8 Data, 1 Stop, No Parity
    // USART Receiver: On
    // USART Transmitter: Off
    // USART Mode: Asynchronous
    // USART Baud Rate: 9600
    UCSRA=(0<<RXC) | (0<<TXC) | (0<<UDRE) | (0<<FE) | (0<<DOR) | (0<<UPE) | (0<<U2X) | (0<<MPCM);
    UCSRB=(1<<RXCIE) | (0<<TXCIE) | (0<<UDRIE) | (1<<RXEN) | (0<<TXEN) | (0<<UCSZ2) | (0<<RXB8) | (0<<TXB8);
    UCSRC=(1<<URSEL) | (0<<UMSEL) | (0<<UPM1) | (0<<UPM0) | (0<<USBS) | (1<<UCSZ1) | (1<<UCSZ0) | (0<<UCPOL);
    UBRRH=0x00;
    UBRRL=0x33;

    // Analog Comparator initialization
    // Analog Comparator: Off
    // The Analog Comparator's positive input is
    // connected to the AIN0 pin
    // The Analog Comparator's negative input is
    // connected to the AIN1 pin
    ACSR=(1<<ACD) | (0<<ACBG) | (0<<ACO) | (0<<ACI) | (0<<ACIE) | (0<<ACIC) | (0<<ACIS1) | (0<<ACIS0);
    SFIOR=(0<<ACME);

    // ADC initialization
    // ADC disabled
    ADCSRA=(0<<ADEN) | (0<<ADSC) | (0<<ADATE) | (0<<ADIF) | (0<<ADIE) | (0<<ADPS2) | (0<<ADPS1) | (0<<ADPS0);

    // SPI initialization
    // SPI disabled
    SPCR=(0<<SPIE) | (0<<SPE) | (0<<DORD) | (0<<MSTR) | (0<<CPOL) | (0<<CPHA) | (0<<SPR1) | (0<<SPR0);

    // TWI initialization
    // TWI disabled
    TWCR=(0<<TWEA) | (0<<TWSTA) | (0<<TWSTO) | (0<<TWEN) | (0<<TWIE);

    // Graphic Display Controller initialization
    // The KS0108 connections are specified in the
    // Project|Configure|C Compiler|Libraries|Graphic Display menu:
    // DB0 - PORTA Bit 0
    // DB1 - PORTA Bit 1
    // DB2 - PORTA Bit 2
    // DB3 - PORTA Bit 3
    // DB4 - PORTA Bit 4
    // DB5 - PORTA Bit 5
    // DB6 - PORTA Bit 6
    // DB7 - PORTA Bit 7
    // E - PORTB Bit 0
    // RD /WR - PORTB Bit 1
    // RS - PORTB Bit 2
    // /RST - PORTB Bit 3
    // /CS1 - PORTB Bit 4
    // /CS2 - PORTB Bit 5

    // Specify the current font for displaying text
    glcd_init_data.font=font5x7;
    // No function is used for reading
    // image data from external memory
    glcd_init_data.readxmem=NULL;
    // No function is used for writing
    // image data to external memory
    glcd_init_data.writexmem=NULL;

    glcd_init(&glcd_init_data);

    // Global enable interrupts
    #asm ("sei")
    glcd_outtextxy(0,0,"GPS");
    while (1)
    {
    do scanf("%s",Y);
    while(strncmp(Y,"$GPRMC",6)!=0);
    GPRMC(Y);
    do scanf("%s",Y);
    while(strncmp(Y,"$GPGLL",6)!=0);
    GPGLL(Y);
    do scanf("%s",Y);
    while(strncmp(Y,"$GPVTG",6)!=0);
    GPVTG(Y);
    do scanf("%s",Y);
    while(strncmp(Y,"$GPGSV",6)!=0);
    GPGSV(Y);
    }
    }


    اینم لینک دانلود برنامه http://www.ictnic.com/learning/learn...D8%B1-avr.html

    دلیل: ادغام دو پست برای جلوگیری از اسپم

    این هم کد بنده وتغییرات اعمال شده
    اول اینکه هدر های فونت و #include "GPS.h" رو حذف کردم چون دیگه glcd نیست و اون تنظیمات نیاز نیست و توابع داخل هدر gps رو تو خود تابع اصلی برنامه تعریف کردم
    دوم هم دستورات مربوط به نمایش اطلاعات دریافتی از glcd به alcd تغییر دادم
    البته درستش اینه که نشد تغییر بدم
    این هم کدی که بنده تغییر دادم


    #include <string.h>
    #include <delay.h>
    #include <stdlib.h>
    #include <mega32.h>

    // Alphanumeric LCD functions
    #include <alcd.h>

    // Declare your global variables here

    // Standard Input/Output functions
    #include <stdio.h>


    #define DATA_REGISTER_EMPTY (1<<UDRE)
    #define RX_COMPLETE (1<<RXC)
    #define FRAMING_ERROR (1<<FE)
    #define PARITY_ERROR (1<<UPE)
    #define DATA_OVERRUN (1<<DOR)




    // USART Receiver buffer
    #define RX_BUFFER_SIZE 8
    char rx_buffer[RX_BUFFER_SIZE];

    #if RX_BUFFER_SIZE <= 256
    unsigned char rx_wr_index=0,rx_rd_index=0;
    #else
    unsigned int rx_wr_index=0,rx_rd_index=0;
    #endif

    #if RX_BUFFER_SIZE < 256
    unsigned char rx_counter=0;
    #else
    unsigned int rx_counter=0;
    #endif

    // This flag is set on USART Receiver buffer overflow
    bit rx_buffer_overflow;

    // USART Receiver interrupt service routine
    interrupt [USART_RXC] void usart_rx_isr(void)
    {
    char status,data;
    status=UCSRA;
    data=UDR;
    if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)
    {
    rx_buffer[rx_wr_index++]=data;
    #if RX_BUFFER_SIZE == 256
    // special case for receiver buffer size=256
    if (++rx_counter == 0) rx_buffer_overflow=1;
    #else
    if (rx_wr_index == RX_BUFFER_SIZE) rx_wr_index=0;
    if (++rx_counter == RX_BUFFER_SIZE)
    {
    rx_counter=0;
    rx_buffer_overflow=1;
    }
    #endif
    }
    }

    #ifndef _DEBUG_TERMINAL_IO_
    // Get a character from the USART Receiver buffer
    #define _ALTERNATE_GETCHAR_
    #pragma used+
    char getchar(void)
    {
    char data;
    while (rx_counter==0);
    data=rx_buffer[rx_rd_index++];
    #if RX_BUFFER_SIZE != 256
    if (rx_rd_index == RX_BUFFER_SIZE) rx_rd_index=0;
    #endif
    #asm("cli")
    --rx_counter;
    #asm("sei")
    return data;
    }
    #pragma used-
    #endif

    // Standard Input/Output functions
    void GPRMC(unsigned char X[150])
    {
    unsigned char *UTC,retx[10]={0};
    unsigned int h,m,s;
    unsigned char time[6][1],lcd[50];
    UTC=strchr(X,',');
    UTC=strtok(UTC,",");
    strcpy(time[0],UTC);
    strncpy(retx,time[0],2);
    h = atoi(retx);
    strncpy(retx,time[2],2);
    m = atoi(retx);
    strncpy(retx,time[4],2);
    s = atof(retx);
    if(m>29)h++,m-=30;
    else m+=30;
    h+=4;
    if(h>24)h-=19,h-=4;
    if(h>24&m>29)h-=19,h-=5;
    sprintf(lcd,"UTC Time:%02d:%02d:%02d",h,m,s);
    lcd_gotoxy(0,0);
    sprintf(str,"L = %d",L);
    lcd_puts(str);
    delay_ms(100);
    //lcd_gotoxy(0, 0);
    //lcd_puts(0,0,lcd);
    }
    void GPGLL(unsigned char X[150])
    {
    unsigned char lcdbuff2[16],lcdbuff1[16];
    unsigned char Lati[10]={0},GP[50][1],*rett,NS[2]={0},Long[11]={0},EW[2]={0};
    rett= strchr(X,',');
    strcpy(GP[0],rett);
    strncpy(Lati,GP[1],9);
    strncpy(NS,GP[12],1);
    strncpy(Long,GP[14],10);
    strncpy(EW,GP[26],1);
    sprintf(lcdbuff2,"Latitude:%s%s",Lati,NS);
    //lcd_outtextxy(0 ,0 ,lcdbuff2);
    sprintf(lcdbuff1,"Longtitu:%s%s",Long,EW);
    //lcd_outtextxy(0 ,0 ,lcdbuff1);
    }
    void GPVTG(unsigned char X[150])
    {
    unsigned char *speed;
    unsigned char lcdbuff[30];
    speed= strchr(X,',');
    speed=strchr(speed,'M');
    speed=strchr(speed,',');
    speed=strtok(speed,",");
    sprintf(lcdbuff,"Speed:%skm/h",speed);
    //glcd_outtextxy(0,30,lcdbuff);
    }
    void GPGSV(unsigned char X[150])
    {
    unsigned char *rett,GP[30][1];
    unsigned char gsv[3]={0},sat,lcdbuff3[16];
    rett= strchr(X,',');
    strcpy(GP[0],rett);
    strncpy(gsv,GP[5],2);
    sat=atoi(gsv);
    sprintf(lcdbuff3,"Satellite in View:%d",sat);
    //glcd_outtextxy(0,50,lcdbuff3);
    }

    void main(void)
    {
    // Declare your local variables here
    unsigned char Y[150];
    // Input/Output Ports initialization
    // Port A initialization
    // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
    DDRA=(0<<DDA7) | (0<<DDA6) | (0<<DDA5) | (0<<DDA4) | (0<<DDA3) | (0<<DDA2) | (0<<DDA1) | (0<<DDA0);
    // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
    PORTA=(0<<PORTA7) | (0<<PORTA6) | (0<<PORTA5) | (0<<PORTA4) | (0<<PORTA3) | (0<<PORTA2) | (0<<PORTA1) | (0<<PORTA0);

    // Port B initialization
    // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
    DDRB=(0<<DDB7) | (0<<DDB6) | (0<<DDB5) | (0<<DDB4) | (0<<DDB3) | (0<<DDB2) | (0<<DDB1) | (0<<DDB0);
    // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
    PORTB=(0<<PORTB7) | (0<<PORTB6) | (0<<PORTB5) | (0<<PORTB4) | (0<<PORTB3) | (0<<PORTB2) | (0<<PORTB1) | (0<<PORTB0);

    // Port C initialization
    // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
    DDRC=(0<<DDC7) | (0<<DDC6) | (0<<DDC5) | (0<<DDC4) | (0<<DDC3) | (0<<DDC2) | (0<<DDC1) | (0<<DDC0);
    // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
    PORTC=(0<<PORTC7) | (0<<PORTC6) | (0<<PORTC5) | (0<<PORTC4) | (0<<PORTC3) | (0<<PORTC2) | (0<<PORTC1) | (0<<PORTC0);

    // Port D initialization
    // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
    DDRD=(0<<DDD7) | (0<<DDD6) | (0<<DDD5) | (0<<DDD4) | (0<<DDD3) | (0<<DDD2) | (0<<DDD1) | (0<<DDD0);
    // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
    PORTD=(0<<PORTD7) | (0<<PORTD6) | (0<<PORTD5) | (0<<PORTD4) | (0<<PORTD3) | (0<<PORTD2) | (0<<PORTD1) | (0<<PORTD0);

    // USART initialization
    // Communication Parameters: 8 Data, 1 Stop, No Parity
    // USART Receiver: On
    // USART Transmitter: Off
    // USART Mode: Asynchronous
    // USART Baud Rate: 9600 (Double Speed Mode)
    UCSRA=(0<<RXC) | (0<<TXC) | (0<<UDRE) | (0<<FE) | (0<<DOR) | (0<<UPE) | (1<<U2X) | (0<<MPCM);
    UCSRB=(1<<RXCIE) | (0<<TXCIE) | (0<<UDRIE) | (1<<RXEN) | (0<<TXEN) | (0<<UCSZ2) | (0<<RXB8) | (0<<TXB8);
    UCSRC=(1<<URSEL) | (0<<UMSEL) | (0<<UPM1) | (0<<UPM0) | (0<<USBS) | (1<<UCSZ1) | (1<<UCSZ0) | (0<<UCPOL);
    UBRRH=0x00;
    UBRRL=0x0C;

    // Alphanumeric LCD initialization
    // Connections are specified in the
    // Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
    // RS - PORTA Bit 0
    // RD - PORTA Bit 1
    // EN - PORTA Bit 2
    // D4 - PORTA Bit 4
    // D5 - PORTA Bit 5
    // D6 - PORTA Bit 6
    // D7 - PORTA Bit 7
    // Characters/line: 16
    lcd_init(16);

    // Global enable interrupts
    #asm("sei")

    while (1)
    {
    // Place your code here
    lcd_clear();
    do scanf("%s",Y);
    while(strncmp(Y,"$GPRMC",6)!=0);
    GPRMC(Y);
    do scanf("%s",Y);
    while(strncmp(Y,"$GPGLL",6)!=0);
    GPGLL(Y);
    do scanf("%s",Y);
    while(strncmp(Y,"$GPVTG",6)!=0);
    GPVTG(Y);
    do scanf("%s",Y);
    while(strncmp(Y,"$GPGSV",6)!=0);
    GPGSV(Y);
    }
    }

    دلیل: ادغام دو پست برای جلوگیری از اسپم

    مشکل فقط در قسمت ارسال و نمایش داده ها میباشد
    لطفا راهنمایی بفرمایید.
    سلام . من که روانی شدم خواهشن از پوشش کد یا پوشش سی پلاس پلاس استفاده کنین و کد رو توی اون قرار بدین تا خوانا باشه






    امیرحسین ضیا

    دیدگاه


      #3
      پاسخ : مشکل در نمایش اطلاعات روی lcd 2*16

      با عرض پوزش!!!
      درست میفرمایید


      #include <string.h>
      #include <delay.h>
      #include <stdlib.h>
      #include <mega32.h>

      // Alphanumeric LCD functions
      #include <alcd.h>

      // Declare your global variables here

      // Standard Input/Output functions
      #include <stdio.h>


      #define DATA_REGISTER_EMPTY (1<<UDRE)
      #define RX_COMPLETE (1<<RXC)
      #define FRAMING_ERROR (1<<FE)
      #define PARITY_ERROR (1<<UPE)
      #define DATA_OVERRUN (1<<DOR)




      // USART Receiver buffer
      #define RX_BUFFER_SIZE 8
      char rx_buffer[RX_BUFFER_SIZE];

      #if RX_BUFFER_SIZE <= 256
      unsigned char rx_wr_index=0,rx_rd_index=0;
      #else
      unsigned int rx_wr_index=0,rx_rd_index=0;
      #endif

      #if RX_BUFFER_SIZE < 256
      unsigned char rx_counter=0;
      #else
      unsigned int rx_counter=0;
      #endif

      // This flag is set on USART Receiver buffer overflow
      bit rx_buffer_overflow;

      // USART Receiver interrupt service routine
      interrupt [USART_RXC] void usart_rx_isr(void)
      {
      char status,data;
      status=UCSRA;
      data=UDR;
      if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)
      {
      rx_buffer[rx_wr_index++]=data;
      #if RX_BUFFER_SIZE == 256
      // special case for receiver buffer size=256
      if (++rx_counter == 0) rx_buffer_overflow=1;
      #else
      if (rx_wr_index == RX_BUFFER_SIZE) rx_wr_index=0;
      if (++rx_counter == RX_BUFFER_SIZE)
      {
      rx_counter=0;
      rx_buffer_overflow=1;
      }
      #endif
      }
      }

      #ifndef _DEBUG_TERMINAL_IO_
      // Get a character from the USART Receiver buffer
      #define _ALTERNATE_GETCHAR_
      #pragma used+
      char getchar(void)
      {
      char data;
      while (rx_counter==0);
      data=rx_buffer[rx_rd_index++];
      #if RX_BUFFER_SIZE != 256
      if (rx_rd_index == RX_BUFFER_SIZE) rx_rd_index=0;
      #endif
      #asm("cli")
      --rx_counter;
      #asm("sei")
      return data;
      }
      #pragma used-
      #endif

      // Standard Input/Output functions
      void GPRMC(unsigned char X[150])
      {
      unsigned char *UTC,retx[10]={0};
      unsigned int h,m,s;
      unsigned char time[6][1],lcd[50];
      UTC=strchr(X,',');
      UTC=strtok(UTC,",");
      strcpy(time[0],UTC);
      strncpy(retx,time[0],2);
      h = atoi(retx);
      strncpy(retx,time[2],2);
      m = atoi(retx);
      strncpy(retx,time[4],2);
      s = atof(retx);
      if(m>29)h++,m-=30;
      else m+=30;
      h+=4;
      if(h>24)h-=19,h-=4;
      if(h>24&m>29)h-=19,h-=5;
      sprintf(lcd,"UTC Time:%02d:%02d:%02d",h,m,s);
      lcd_gotoxy(0,0);
      sprintf(str,"L = %d",L);
      lcd_puts(str);
      delay_ms(100);
      //lcd_gotoxy(0, 0);
      //lcd_puts(0,0,lcd);
      }
      void GPGLL(unsigned char X[150])
      {
      unsigned char lcdbuff2[16],lcdbuff1[16];
      unsigned char Lati[10]={0},GP[50][1],*rett,NS[2]={0},Long[11]={0},EW[2]={0};
      rett= strchr(X,',');
      strcpy(GP[0],rett);
      strncpy(Lati,GP[1],9);
      strncpy(NS,GP[12],1);
      strncpy(Long,GP[14],10);
      strncpy(EW,GP[26],1);
      sprintf(lcdbuff2,"Latitude:%s%s",Lati,NS);
      //lcd_outtextxy(0 ,0 ,lcdbuff2);
      sprintf(lcdbuff1,"Longtitu:%s%s",Long,EW);
      //lcd_outtextxy(0 ,0 ,lcdbuff1);
      }
      void GPVTG(unsigned char X[150])
      {
      unsigned char *speed;
      unsigned char lcdbuff[30];
      speed= strchr(X,',');
      speed=strchr(speed,'M');
      speed=strchr(speed,',');
      speed=strtok(speed,",");
      sprintf(lcdbuff,"Speed:%skm/h",speed);
      //glcd_outtextxy(0,30,lcdbuff);
      }
      void GPGSV(unsigned char X[150])
      {
      unsigned char *rett,GP[30][1];
      unsigned char gsv[3]={0},sat,lcdbuff3[16];
      rett= strchr(X,',');
      strcpy(GP[0],rett);
      strncpy(gsv,GP[5],2);
      sat=atoi(gsv);
      sprintf(lcdbuff3,"Satellite in View:%d",sat);
      //glcd_outtextxy(0,50,lcdbuff3);
      }

      void main(void)
      {
      // Declare your local variables here
      unsigned char Y[150];
      // Input/Output Ports initialization
      // Port A initialization
      // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
      DDRA=(0<<DDA7) | (0<<DDA6) | (0<<DDA5) | (0<<DDA4) | (0<<DDA3) | (0<<DDA2) | (0<<DDA1) | (0<<DDA0);
      // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
      PORTA=(0<<PORTA7) | (0<<PORTA6) | (0<<PORTA5) | (0<<PORTA4) | (0<<PORTA3) | (0<<PORTA2) | (0<<PORTA1) | (0<<PORTA0);

      // Port B initialization
      // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
      DDRB=(0<<DDB7) | (0<<DDB6) | (0<<DDB5) | (0<<DDB4) | (0<<DDB3) | (0<<DDB2) | (0<<DDB1) | (0<<DDB0);
      // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
      PORTB=(0<<PORTB7) | (0<<PORTB6) | (0<<PORTB5) | (0<<PORTB4) | (0<<PORTB3) | (0<<PORTB2) | (0<<PORTB1) | (0<<PORTB0);

      // Port C initialization
      // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
      DDRC=(0<<DDC7) | (0<<DDC6) | (0<<DDC5) | (0<<DDC4) | (0<<DDC3) | (0<<DDC2) | (0<<DDC1) | (0<<DDC0);
      // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
      PORTC=(0<<PORTC7) | (0<<PORTC6) | (0<<PORTC5) | (0<<PORTC4) | (0<<PORTC3) | (0<<PORTC2) | (0<<PORTC1) | (0<<PORTC0);

      // Port D initialization
      // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
      DDRD=(0<<DDD7) | (0<<DDD6) | (0<<DDD5) | (0<<DDD4) | (0<<DDD3) | (0<<DDD2) | (0<<DDD1) | (0<<DDD0);
      // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
      PORTD=(0<<PORTD7) | (0<<PORTD6) | (0<<PORTD5) | (0<<PORTD4) | (0<<PORTD3) | (0<<PORTD2) | (0<<PORTD1) | (0<<PORTD0);

      // USART initialization
      // Communication Parameters: 8 Data, 1 Stop, No Parity
      // USART Receiver: On
      // USART Transmitter: Off
      // USART Mode: Asynchronous
      // USART Baud Rate: 9600 (Double Speed Mode)
      UCSRA=(0<<RXC) | (0<<TXC) | (0<<UDRE) | (0<<FE) | (0<<DOR) | (0<<UPE) | (1<<U2X) | (0<<MPCM);
      UCSRB=(1<<RXCIE) | (0<<TXCIE) | (0<<UDRIE) | (1<<RXEN) | (0<<TXEN) | (0<<UCSZ2) | (0<<RXB8) | (0<<TXB8);
      UCSRC=(1<<URSEL) | (0<<UMSEL) | (0<<UPM1) | (0<<UPM0) | (0<<USBS) | (1<<UCSZ1) | (1<<UCSZ0) | (0<<UCPOL);
      UBRRH=0x00;
      UBRRL=0x0C;

      // Alphanumeric LCD initialization
      // Connections are specified in the
      // Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
      // RS - PORTA Bit 0
      // RD - PORTA Bit 1
      // EN - PORTA Bit 2
      // D4 - PORTA Bit 4
      // D5 - PORTA Bit 5
      // D6 - PORTA Bit 6
      // D7 - PORTA Bit 7
      // Characters/line: 16
      lcd_init(16);

      // Global enable interrupts
      #asm("sei")

      while (1)
      {
      // Place your code here
      lcd_clear();
      do scanf("%s",Y);
      while(strncmp(Y,"$GPRMC",6)!=0);
      GPRMC(Y);
      do scanf("%s",Y);
      while(strncmp(Y,"$GPGLL",6)!=0);
      GPGLL(Y);
      do scanf("%s",Y);
      while(strncmp(Y,"$GPVTG",6)!=0);
      GPVTG(Y);
      do scanf("%s",Y);
      while(strncmp(Y,"$GPGSV",6)!=0);
      GPGSV(Y);
      }
      }






      دلیل: ادغام دو پست برای جلوگیری از اسپم

      لطفا برای مشاهده کد اصلی برنامه از این لینک http://www.ictnic.com/learning/learning-modules/284-%D9%BE%D8%B1%D9%88%DA%98%D9%87-%D8%A7%D8%AA%D8%B5%D8%A7%D9%84-gps-%D8%A8%D9%87-%D9
      %85%DB%8C%DA%A9%D8%B1%D9%88%DA%A9%D9%86%D8%AA%D8%B 1%D9%84%D8%B1-avr.html
      استفاده بفرمایید که دیگه خیلی شلوغ نشه

      دیدگاه


        #4
        پاسخ : مشکل در نمایش اطلاعات روی lcd 2*16

        دوستان و علما کسی هست جواب بده

        دیدگاه


          #5
          پاسخ : مشکل در نمایش اطلاعات روی lcd 2*16

          سلام دوستان،ببخشید میخواسم چچند تا شکل رو با کاستوم کاراکتر بسازم و روی ال سی نشون بدم،همه کارشو انجام دادم،وقتی میخوام میگرو رو پروگرام میکنم میکرو هنگ میکنه،مشکل از چی میتونه باشه؟
          محدودیت در تعریف کاراکتر هست؟من 7 تا کاراکتر تعریف کردم

          #ifndef F_CPU[URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL]  F_CPU 1000000UL
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=endif]#endif[/URL]


          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include]#include[/URL] <avr/io.h>
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include]#include[/URL] <avr/interrupt.h>
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include]#include[/URL] <util/delay.h>
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include]#include[/URL] <stdio.h>
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include]#include[/URL] <stdlib.h>
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include]#include[/URL] <string.h>
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include]#include[/URL] "LCD_16x2_H_file.h"
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include]#include[/URL] "I2C_Master_H_file.h"
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include]#include[/URL] "ds1307.h"
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include]#include[/URL] "DHT.h"
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=include]#include[/URL] "IO_Macros.h"


          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] Heater_Fan_PIN D,6
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] Humidifier_PIN D,1
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] Humidifier_Fan_PIN D,0
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] Rotation_PIN D,4
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] Fan_PIN D,7


          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] SLEEP_MODE_IDLE 7
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] Heater_char 0
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] Humidifiier_char 1
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] Fan_char 2
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] Rotate_char 3
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] Seter_char 4
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] Hecher_char 5
          [URL=https://www.eca.ir/forums/usertag.php?do=list&action=hash&hash=define]#define[/URL] Keep_char 6


          bool first_run_flag=true;
          volatile char key,buffer[30]={ 0 };
          volatile int second=0,minute=0,hour=0,day=0,dayofweek=0,month=0,year=0,i,j,Rotate_flag=0,Humidifier_flag=0,setter_period_flag=0;
          volatile double hum=0,temp=0,humidity=0,Temperature=0,arr_ave_h[10]={ 0 },arr_ave_t[10]={ 0 },avr_temp=0,avr_hum=0;
          volatile struct tm* t = NULL;


          void lcd_built(void)
          {


          unsigned char fan[8] = { 0x00,0x0C,0x05,0x1F,0x14,0x06,0x00,0x00 };
          unsigned char humidifier[8] = { 0x00,0x0A,0x14,0x0A,0x1F,0x1F,0x00,0x00 };
          unsigned char heater[8] = { 0x00,0x09,0x12,0x12,0x09,0x09,0x12,0x00 };
          unsigned char rotate[8] = { 0x1E,0x12,0x07,0x0A,0x1C,0x09,0x0F,0x00 };


          unsigned char setter[8] = { 0x1F,0x11,0x11,0x15,0x11,0x15,0x1F,0x00 };
          unsigned char hecher[8] = { 0x1F,0x15,0x11,0x15,0x11,0x15,0x1F,0x00 };
          unsigned char keep[8] = { 0x1F,0x11,0x11,0x15,0x11,0x11,0x1F,0x00 };


          LCD_Custom_Char(Fan_char, fan);
          LCD_Custom_Char(Humidifiier_char, humidifier);
          LCD_Custom_Char(Heater_char, heater);
          LCD_Custom_Char(Rotate_char, rotate);
          LCD_Custom_Char(Seter_char, setter);
          LCD_Custom_Char(Hecher_char, hecher);
          LCD_Custom_Char(Keep_char, keep);
          }


          void timer1_init()
          {
          TCCR1B |= (1 << WGM12) | (1 << CS11);
          OCR1A = 0x124F8;
          TIMSK |= (1 << OCIE1A);
          }


          ISR(TIMER1_COMPA_vect)
          {


          /************************************************************************/
          /* if Rotate_flag=1 rotate motor turn on and show character in LCD. */
          /************************************************************************/
          if (Rotate_flag == 1)
          {
          DigitalWrite(Rotation_PIN,High);
          LCD_Char_xy(0,11,Rotate_char);
          }
          else
          {
          DigitalWrite(Rotation_PIN,Low);
          LCD_Char_xy(0,11,' ');
          }


          /************************************************************************/
          /* if avreage temperature is low of Temperature turn on heater and fan */
          /* turn on and show character in LCD. */
          /************************************************************************/
          if (avr_temp < Temperature)
          {
          DigitalWrite(Heater_Fan_PIN,High);
          LCD_Char_xy(0,12,Fan_char);
          LCD_Char_xy(0,13,Heater_char);
          }
          else
          {
          DigitalWrite(Heater_Fan_PIN,Low);
          LCD_Char_xy(0,12,' ');
          LCD_Char_xy(0,13,' ');
          }


          /************************************************************************/
          /* if Humidifier_flag=1 humidifier turn on and show character in LCD. */
          /************************************************************************/
          if (Humidifier_flag == 1)
          {
          DigitalWrite(Humidifier_Fan_PIN,High);
          LCD_Char_xy(0,15,Humidifiier_char);
          }
          else
          {
          DigitalWrite(Humidifier_Fan_PIN,Low);
          LCD_Char_xy(0,15,' ');
          }


          if (avr_hum < humidity-3)
          {
          DigitalWrite(Humidifier_Fan_PIN,Low);
          LCD_Char_xy(0,14,' ');
          }
          else
          {
          DigitalWrite(Humidifier_Fan_PIN,High);
          LCD_Char_xy(0,14,Fan_char);
          }


          }




          int main(void)
          {
          I2C_Init(); /* Initialize I2C */
          LCD_Init(); /* Initialize LCD16x2 */


          lcd_built();


          timer0_init();
          timer1_init();
          timer2_init();


          sei();

          while(1)
          {

          }
          }

          دیدگاه


            #6
            پاسخ : مشکل در نمایش اطلاعات روی lcd 2*16

            آقا اصن من از خیر یاد گرفتنش گذشتم
            کسی هست این کد که لینکش هست رو برای ال سی دی کاراکتری اصلاح کنه!!!!؟

            دیدگاه

            لطفا صبر کنید...
            X