Programme en C SmartGPS
Répondre à la discussion
Affichage des résultats 1 à 12 sur 12

Programme en C SmartGPS



  1. #1
    invitef97198f3

    Programme en C SmartGPS


    ------

    Bonjour à tous,
    Je suis en Deuxième année BTS Système électronique, et cette année j'ai un projet a soutenir.
    Ma partie consiste a extraire une trame GPS pour l'exploiter sur un écran LCD.
    J'ai donc besoin de vote aide pour le programme écrit en C.
    Voila ce que j'ai trouvé.

    char txt[768];
    signed int latitude, longitude;
    char *string;
    int i;
    unsigned short ready;
    extern const unsigned short world_bmp[1024];
    char GLCD_DataPort at PORTD;

    sbit GLCD_CS1 at RB0_bit; sbit GLCD_CS1_Direction at TRISB0_bit;
    sbit GLCD_CS2 at RB1_bit; sbit GLCD_CS2_Direction at TRISB1_bit;
    sbit GLCD_RS at RB2_bit; sbit GLCD_RS_Direction at TRISB2_bit;
    sbit GLCD_RW at RB3_bit; sbit GLCD_RW_Direction at TRISB3_bit;
    sbit GLCD_EN at RB4_bit; sbit GLCD_EN_Direction at TRISB4_bit;
    sbit GLCD_RST at RB5_bit; sbit GLCD_RST_Direction at TRISB5_bit;

    void interrupt() {
    if (PIR1.F0 == 1) { //if interrupt is generated by TMR1IF
    //Stop Timer 1:
    T1CON.F0 = 0; //Set TMR1ON to 0
    ready = 1; //set data ready
    i = 0; //reset array counter
    PIR1.F0 = 0; //Set TMR1IF to 0
    }
    if (PIR1.F5 == 1) { //if interrupt is generated by RCIF
    txt[i++] = UART1_Read();
    if (txt[i-1] == 0)
    i = 0;
    if (i == 768) i = 0;
    //Stop Timer 1:
    T1CON.F0 = 0; //Set TMR1ON to 0
    //Timer1 starts counting from 15536:
    TMR1L = 0xB0;
    TMR1H = 0x3C;
    //Start Timer 1:
    T1CON.F0 = 1; //Set TMR1ON to 1
    PIR1.F5 = 0; //Set RCIF to 0
    }
    }

    void Display_Cursor(signed int lat, signed int lon) {
    unsigned char latitude_y, longitude_x;

    //Latitude and Longitude scaling for 128x64 display:
    //Latitude: Input range is -90 to 90 degrees
    //Longitude: Input range is -180 to 180 degrees
    latitude_y = ((61*(90 - lat))/180) + 1;
    longitude_x = ((125*(lon + 180))/360) + 1;
    //Cursor drawing:
    Glcd_Dot(longitude_x,latitude_ y,2); //Centar dot
    Glcd_Dot(longitude_x-1,latitude_y,2); //Left dot
    Glcd_Dot(longitude_x+1,latitud e_y,2); //Right dot
    Glcd_Dot(longitude_x,latitude_ y-1,2); //Uper dot
    Glcd_Dot(longitude_x,latitude_ y+1,2); //Lower dot
    Delay_ms(500);
    Glcd_Image( world_bmp ); //Display World map on the GLCD
    }

    void main() {

    ADCON1 = 0x0F; // Set AN pins to Digital I/O
    GLCD_Init();
    Glcd_Set_Font(font5x7, 5, 7, 32);
    Glcd_Fill(0x00);
    Delay_ms(100);
    ready = 0;

    //Set Timer1 Prescaler to 1:8
    T1CON.F5 = 1; //Set TCKPS1 to 1
    T1CON.F4 = 1; //Set TCKPS0 to 1
    //Enable Timer1 interrupt:
    PIE1.F0 = 1; //Set TMR1IE to 1
    //Timer1 starts counting from 15536:
    TMR1L = 0xB0;
    TMR1H = 0x3C;
    //Clear Timer1 interrupt flag:
    PIR1.F0 = 0; //Set TMR1IF to 0
    //Note: Timer1 is set to generate interrupt on 50ms interval

    UART1_Init(9600);
    //Enable Usart Receiver interrupt:
    PIE1.F5 = 1; //Set RCIE to 1
    //Enable Global interrupt and Peripheral interrupt:
    INTCON.F7 = 1; //Set GIE to 1
    INTCON.F6 = 1; //Set PEIE to 1

    //Start Timer 1:
    T1CON.F0 = 1; //Set TMR1ON to 1

    Glcd_Image( world_bmp ); //Display World map on the GLCD

    while(1)
    {
    RCSTA.F1 = 0; //Set OERR to 0
    RCSTA.F2 = 0; //Set FERR to 0

    if(ready == 1) { //if the data in txt array is ready do:
    ready = 0;
    string = strstr(txt,"$GPGLL");
    if(string != 0) { //If txt array contains "$GPGLL" string we proceed...
    if(string[7] != ',') { //if "$GPGLL" NMEA message have ',' sign in the 8-th
    //position it means that tha GPS receiver does not have FIXed position!
    latitude = (string[7]-48)*10 + (string[8]-48);
    longitude = (string[20]-48)*100 + (string[21]-48)*10 + (string[22]-48);
    if(string[18] == 'S') { //if the latitude is in the South direction it has minus sign
    latitude = 0 - latitude;
    }
    if(string[32] == 'W') { //if the longitude is in the West direction it has minus sign
    longitude = 0 - longitude;
    }
    Display_Cursor(latitude, longitude); //Display the cursor on the world map
    }
    }
    }
    }
    }
    Mon problème se porte sur la ligne 7
    char GLCD_DataPort at PORTD;
    car quand j'essaye de le compiler il me dit qu'il y a une erreur.

    Merci a tous ceux qui vont pouvoir m'aider.
    Et si je rencontre d'autres problèmes je vous les dirais.
    Merci

    -----

  2. #2
    Jack
    Modérateur

    Re : Programme en C SmartGPS

    Bonjour,

    petite remarque: pour montrer du code, il faut utiliser la balise code et pas citation.

    La ligne 7 n'est pas en C standard (ni les suivantes d'ailleurs) en raison du "at". Il faudrait donc que tu précises quel est ton compilateur et quel est le µC cible.

    A+

  3. #3
    invitef97198f3

    Re : Programme en C SmartGPS

    D'accord je penserai à modifier le topic.
    j'utilise un pic: p18f452 de chez microchip.
    Le compilateur est MPLAB C18.

  4. #4
    Jack
    Modérateur

    Re : Programme en C SmartGPS

    Et le code que tu nous as montré était destiné à mplab ou à autre compilateur? Je te dis tout de suite que je ne suis pas très microchip, mais ce 'at" est curieux.

    A+

  5. A voir en vidéo sur Futura
  6. #5
    invitef97198f3

    Re : Programme en C SmartGPS

    Normalement il est destiné a MPLAB mais quand je compile il me dit qu'il y a une erreur. Moi aussi je trouve se "at" bizarre.
    Qu'elle est sont équivalent?

  7. #6
    Jack
    Modérateur

    Re : Programme en C SmartGPS

    Normalement il est destiné a MPLAB
    Ca ne veut rien dire, mplab est un IDE dans lequel tu peut intégrer un assembleur ou un compilateur, C18 ou autre.

    Il faut donc déterminer pour quel compilateur ce fichier source était destiné, lire la doc de ce compilateur et en déduire le rôle du "at", puis le remplacer par une déclaration compatible avec celle de C18.

    A+

  8. #7
    sdec25

    Re : Programme en C SmartGPS

    Bonjour,
    Personnellement j'utiliserais des define :
    Code:
    #define GLCD_DataPort PORTD
    
    #define GLCD_CS1 RB0_bit
    ...
    Mais vu qu'on ne sait pas où sont utilisées ces variables GLCD_xxx, si ça fonctionne ce sera par hasard.
    Donc, soit tu trouves un programme écrit en C standard (avec une doc), soit tu le refais toi-même.

  9. #8
    invitef97198f3

    Re : Programme en C SmartGPS

    Je vais essayer le
    Code:
    #define
    car je crois me souvenir que j'utilisai sa avant. Merci et je vous tiens au courant.

  10. #9
    invitef97198f3

    Re : Programme en C SmartGPS

    Je viens d'essayer mais malheureusement une fois la première erreur corriger il m'en trouve pleins d'autres. Je c'est pas comment faire.
    Mon compilateur est le C18 mon pic le 18f452.

  11. #10
    invitef97198f3

    Re : Programme en C SmartGPS

    J'ai remaniée mon programme et voila ce que sa donne.
    Code:
    char txt[768];
    char *string;
    int i,j;
    unsigned short ready;
    unsigned char display_flag=0;
    unsigned char time[8],date[8],latitude[15],longitude[15],speed[5];
    const char character1[] = {0,0,4,31,31,4,0,0};
    const char character2[] = {0,28,14,31,14,28,0,0};
    char *text = "GPS Tracking";
    void interrupt() {
    if (PIR1.F0 == 1) { //if interrupt is generated by TMR1IF
    //Stop Timer 1:
    T1CON.F0 = 0; //Set TMR1ON to 0
    ready = 1; //set data ready
    i = 0; //reset array counter
    PIR1.F0 = 0; //Set TMR1IF to 0
    }
    if (PIR1.F5 == 1) { //if interrupt is generated by RCIF
    txt[i++] = USART_Read();
    if (txt[i-1] == 0)
    i = 0;
    if (i == 768) i = 0;
    //Stop Timer 1:
    T1CON.F0 = 0; //Set TMR1ON to 0
    //Timer1 starts counting from 15536:
    TMR1L = 0xB0;
    TMR1H = 0x3C;
    //Start Timer 1:
    T1CON.F0 = 1; //Set TMR1ON to 1
    PIR1.F5 = 0; //Set RCIF to 0
    }
    }
    void get_data()
    { if(ready == 1)
    { //if the data in txt array is ready do:
    ready = 0;
    string = strstr(txt,"$GPRMC");
    if(string != 0)
    {
    for(j=7;j<13;j++) time[j-7]=string[j];
    for(j=20;j<29;j++) latitude[j-20]=string[j];
    latitude[9]=string[32];
    for(j=34;j<44;j++) longitude[j-34]=string[j];
    longitude[9]=string[47];
    for(j=49;j<54;j++) Speed[j-49]=string[j];
    for(j=57;j<63;j++) date[j-57]=string[j];
    }
    }
    }
    void display_data()
    {if(display_flag==1)
    {Lcd_Cmd(Lcd_Clear);
    Lcd_Out(1,1,"Time:");
    for(j=0;j<6;j++)
    {if(j==2 || j==4) Lcd_Chr_Cp(':');
    Lcd_Chr_Cp(time[j]);
    }
    Lcd_Out(2,1,"Date:");
    for(j=0;j<6;j++)
    {if(j==2 || j==4) Lcd_Chr_Cp('/');
    Lcd_Chr_Cp(date[j]);
    }
    delay_ms(150);
    }
    if(display_flag==2)
    {Lcd_Cmd(Lcd_Clear);
    Lcd_Out(1,1,"La:");
    for(j=0;j<10;j++)
    {//if(j==2 || j==4) Lcd_Chr_Cp('/');
    Lcd_Chr_Cp(latitude[j]);
    }
    Lcd_Out(2,1,"Lo:");
    for(j=0;j<10;j++)
    {//if(j==2 || j==4) Lcd_Chr_Cp('/');
    Lcd_Chr_Cp(longitude[j]);
    }
    delay_ms(150);
    }
    if(display_flag==3)
    {Lcd_Cmd(Lcd_Clear);
    Lcd_Out(1,1,"Speed:");
    for(j=0;j<5;j++)
    {
    Lcd_Chr_Cp(speed[j]);
    if(j==4) Lcd_Out_Cp(" Knot");
    }
    delay_ms(100);
    }
    
    }
    void CustomChar()
    { char i;
    LCD_Cmd(64); //chr address 0
    for (i = 0; i<=7; i++) LCD_Chr_Cp(character1[i]);
    LCD_Cmd(LCD_RETURN_HOME);
    
    LCD_Cmd(72); //1
    for (i = 0; i<=7; i++) LCD_Chr_Cp(character2[i]);
    LCD_Cmd(LCD_RETURN_HOME);
    }
    
    
    
    
    
    void interface() // display on Lcd at start program
    { unsigned char m;
    Lcd_Cmd(Lcd_Clear);
    Lcd_Chr(1,2,1);
    delay_ms(150);
    Lcd_Cmd(LCD_MOVE_CURSOR_LEFT);
    Lcd_Chr_Cp(0);
    delay_ms(150);
    for(m=0;m<13;m++)
    {Lcd_Chr_Cp(1);
    delay_ms(150);
    Lcd_Cmd(LCD_MOVE_CURSOR_LEFT);
    Lcd_Chr_Cp(text[m]);
    }
    Lcd_Cmd(LCD_MOVE_CURSOR_LEFT);
    Lcd_Chr_Cp(0);
    delay_ms(150);
    }
    
    
    
    
    
    void main()
    { ADCON1 = 0x0F;
    TRISB=0xFF; // Set AN pins to Digital I/O
    TRISD=0;
    Lcd_Init(&PORTD);
    //CustomChar();
    Lcd_Cmd(Lcd_Clear);
    Lcd_Out(1,3,"GPS Tracking");
    
    
    interface(); // I can't call this function
    
    
    
    Delay_ms(1000);
    Lcd_Cmd(Lcd_Clear);
    Lcd_Cmd(LCD_CURSOR_OFF);
    ready = 0;
    
    //Set Timer1 Prescaler to 1:8
    T1CON.F5 = 1; //Set TCKPS1 to 1
    T1CON.F4 = 1; //Set TCKPS0 to 1
    //Enable Timer1 interrupt:
    PIE1.F0 = 1; //Set TMR1IE to 1
    //Timer1 starts counting from 15536:
    TMR1L = 0xB0;
    TMR1H = 0x3C;
    //Clear Timer1 interrupt flag:
    PIR1.F0 = 0; //Set TMR1IF to 0
    //Note: Timer1 is set to generate interrupt on 50ms interval
    
    USART_Init(9600);
    //Enable Usart Receiver interrupt:
    PIE1.F5 = 1; //Set RCIE to 1
    //Enable Global interrupt and Peripheral interrupt:
    INTCON.F7 = 1; //Set GIE to 1
    INTCON.F6 = 1; //Set PEIE to 1
    
    //Start Timer 1:
    T1CON.F0 = 1; //Set TMR1ON to 1
    while(1)
    {if(PORTB.F0==0)
    {Delay_ms(5);
    if(PORTB.F0==0) display_flag=0;
    }
    if(PORTB.F1==0)
    {Delay_ms(5);
    if(PORTB.F1==0) display_flag=1;
    }
    if(PORTB.F2==0)
    {Delay_ms(5);
    if(PORTB.F2==0) display_flag=2;
    }
    if(PORTB.F3==0)
    {Delay_ms(5);
    if(PORTB.F3==0) display_flag=3;
    }
    //if(display_flag==0) interface();
    if(display_flag==0)
    {Lcd_cmd(Lcd_Clear);
    Lcd_Out(1,3,"GPS Tracking");
    delay_ms(200);
    }
    get_data();
    display_data();
    }
    }
    Mais j'ai toujours des erreurs

  12. #11
    invitef97198f3

    Re : Programme en C SmartGPS

    Mon problème viens de cette ligne là.
    Code:
    if (PIR1.F0 == 1)

  13. #12
    Jack
    Modérateur

    Re : Programme en C SmartGPS

    C'est normal, il faut inclure toutes les définitions des registres du pic, du style

    #include <pic18Fxxx.h>

    Il faut donc que tu récupères les headers correspondant à la référence de ton pic. Tu y trouveras les définition des bitfields qui te permettent d'accéder aux bits des registres.

    A+

Discussions similaires

  1. programme C
    Par invite48b7a4f0 dans le forum Logiciel - Software - Open Source
    Réponses: 3
    Dernier message: 12/12/2008, 13h41
  2. programme C
    Par invitecda03984 dans le forum Électronique
    Réponses: 2
    Dernier message: 22/03/2008, 16h46
  3. programme en C++
    Par invitee5fedd72 dans le forum Logiciel - Software - Open Source
    Réponses: 11
    Dernier message: 05/03/2008, 10h44
  4. programme
    Par invite21ed25dc dans le forum Électronique
    Réponses: 3
    Dernier message: 06/12/2007, 18h50
  5. Programme
    Par invite98b1e16f dans le forum Mathématiques du supérieur
    Réponses: 3
    Dernier message: 06/02/2005, 14h11
Découvrez nos comparatifs produits sur l'informatique et les technologies.