Interfaçage ds1620 avec 8051 et ecran LCD
Répondre à la discussion
Affichage des résultats 1 à 2 sur 2

Interfaçage ds1620 avec 8051 et ecran LCD



  1. #1
    kero1

    Interfaçage ds1620 avec 8051 et ecran LCD


    ------

    Bonjour
    Je dois réaliser un projet avec un capteur de température DS1620,l'Aduc842(une famille du microP 8051) et afficher les températures sur l'écran LCD.
    J'ai pu programmer la partie capteur-Microcontroleur tous mes menus fonctionnent mais la température que je lis de mon capteur ne correspond pas à celle en temps réelle de la pièce.Est-ce normal ou bien c'est du à une erreur dans mon programme?Je tiens à souligner que j'ai changer de capteur mais rien ne change.
    Quelqu'un pourrait-il me donner une piste ou un début de programme pour l'affichage de mes menus et des températures que me donne le capteur sur un écran LCD?
    Le modèle de mon ecran LCD est GDM1602A.
    Merci d'avance
    Voici mon programme en c
    #include <main.h>
    #include <stdio.h>
    #include <ds1620.h>
    #include <Gettemp.h>
    #include <Puttemp.h>
    #include <Readtemp.h>
    #include <Writetemp.h>
    #define simulateur 1
    #define debug 1
    /* Configuration parameters */

    #define XtalFreq (11059490) /* main crystal frequency */

    /* External signals */

    sbit RST = P3^2; /* reset line */
    sbit CLK = P3^5; /* clock line */
    sbit DQ = P3^3; /* data line */
    //sbit Buzzer = P2^2; /*Buzzer*/

    /* Delay macro */

    #define DELAY(time){ \
    unsigned int k,j; \
    j=(XtalFreq/12/65536)*time;\
    for (k=0; k>j; k++) {\
    TF0=TR0=0; \
    TH0=TL0=0;\
    TR0=1;\
    while (!TF0) {};\
    };}\

    /* Control macros */

    #define WrtCtrl(x) {while (STATUS & 0x80) {}; CONTROL=x; }
    #define WrtData(x) {while (STATUS & 0x80) {}; DATABYTE=x; }

    /* Function prototypes */

    unsigned char Get1620byte( void );
    unsigned char Read1620byte( void );
    void Put1620byte(unsigned char m);
    void Write1620byte(unsigned char m);
    void initUART();
    /*----------------------------------------------------------------------*/
    void main (void) { /* main program */
    /*----------------------------------------------------------------------*/
    /* Local variables */
    /*----------------------------------------------------------------------*/
    unsigned char c; /* dummy variable */
    unsigned char Select_Type; /* Function variable */
    unsigned char k; /* counter */
    //unsigned int q; /* used for getting 9 bits */
    unsigned char Config_Data; /* Config. Reg. Data */
    unsigned int Temp_High; /* Temp. High Data */
    unsigned int Temp_Low; /* Temp_Low Data */
    //unsigned char Read_Temp; /* Temp Data */
    unsigned char temp_and_half_bit; /* temp byte and half bit */
    unsigned char sign_bit; /* sign bit */
    float temp_c; /* temperature in deg. C */
    float temp_f; /* temperature in deg. F */
    float temp_read; /* */
    unsigned int count_remain; /* used for getting .1 deg.*/
    unsigned int count_per_c; /* used for getting .1 deg.*/
    //unsigned char temp_string[10]; /* */
    /*----------------------------------------------------------------------*/
    initUART();

    /*----------------------------------------------------------------------*/
    /* Display banner */
    /*----------------------------------------------------------------------*/
    DELAY(2);
    printf (" Adapté pour Keil et ADuC 842\n");
    printf("********************** ****************************** **************** \n");
    printf (" Select Menu Option \n");
    printf (" 1. Read Temperature \n");
    printf (" 2. Read Temperature High (TH) \n");
    printf (" 3. Read Temperature Low (TL) \n");
    printf (" 4. Read Configuration Register \n");
    printf (" 5. Write Configuration Register = 03h, Clear Flags \n");
    printf (" 6. Set Temperature High (TH) = 50h \n");
    //printf (" 7. Set Temperature High (TH) = 20h \n");
    printf (" 8. Set Temperature Low (TL) = 0 \n");
    //printf (" 9. Set Temperature Low (TL) = 19h \n");
    printf (" A. Start Conversion \n");
    printf (" Note: Temperature Settings are in degrees Centigrade \n");
    /* Setup to get temp */

    RST=0;
    RST=1;
    Put1620byte(0xAC);/* Read Config Register */
    k = Get1620byte();/* get Config Register Data DONE-THF-TLF-NVB-1-0-CPU-1SHOT */
    RST=0;

    if ( (k & 0x18) != 0x08 ) // bad or no part masque 18h NVB=0 memory not busy et cst'1'
    {
    printf( " Error talking to part!\n" );

    printf( "Config = %02X \n", k); /* What is Config. Setting? */
    c = getchar();
    }
    if ( (k & 0x03) != 0x03 ) /* CPU=1 (3 wire) 1SHOT=1 */
    {
    RST=1;
    Put1620byte(0x0C);//write config
    Put1620byte(0x03); /* set to CPU & 1SHOT mode */
    RST=0;
    }
    RST=1;
    Put1620byte(0x22); /* stop convert (ie reset) */
    RST=0;

    /* Setup to get time C5 3A A3 5C C5 3A A3 5C */
    do {

    /* Enable CE2 */
    EA = 0; /* Inhibit interrupts */
    /* Disable CE2 */
    EA = 1; /* Enable interrupts */
    /* Start convert and wait to finish */

    DELAY(.1);
    RST=1;
    Put1620byte(0xEE);/* start temp convert */
    RST=0;

    do
    {
    RST=1;
    Put1620byte(0xAC); /* open status register */
    k = Get1620byte(); /* get status byte */
    RST=0;
    /* printf( "Waiting : %02X", k); Debug print line*/
    } while ( (k & 0x80) != 0x80 ); /*changed 0x80 to 0x00*/

    Select_Type = getchar();/* get variable to start */
    switch(Select_Type)
    {

    case '1': printf (".Read Temperature \n");

    /* Read temp and sign bit */
    RST=1;
    Put1620byte(0xAA); /* read temp command */
    temp_and_half_bit = Get1620byte(); /* read 1st byte of temp */
    sign_bit = Get1620byte(); /* read 2nd byte of temp */
    RST=0;
    /* Get count remain & count per C for .1 resolution */
    RST=1;
    Put1620byte(0xA0); /* read count remaining */
    count_remain = Get1620byte(); /* read 1st byte */
    count_remain += Get1620byte() * 256; /* read 2nd byte */
    RST=0;
    RST=1;
    Put1620byte(0xA9); /* read slope as count/c */
    count_per_c = Get1620byte(); /* read 1st byte */
    count_per_c += Get1620byte() * 256; /* read 2nd byte */
    RST=0;

    /* Calculate ?C and ?F */

    if ( count_per_c == 0 ) count_per_c = 1;
    temp_read = ( temp_and_half_bit >> 1 );
    if ( sign_bit != 0 ) temp_read = (temp_read - 128);
    temp_c = (float)temp_read-0.25
    + (count_per_c-count_remain)/(float) count_per_c;
    temp_f = temp_c * 9/5 + 32;
    /* Display temp to CRT */
    //printf( "sign=%2d T&HB=%3d\n", (int)sign_bit,(int)temp_and_ha lf_bit);
    //printf ( "T/2=%5.1f\n", temp_read );
    printf( "c remain=%3d\n",count_remain );
    printf( "c per c=%3d\n",count_per_c );
    printf( "TempC=%5.1f\n", temp_c );

    printf( "TempF=%5.1f", temp_f );
    printf("\n");
    break;
    case '2': printf (".Read Temperature High (TH)\n");

    RST=1;
    Put1620byte(0xA1); /* open Temp. High register */
    DELAY(.1);
    Temp_High = Read1620byte(); /* get status byte */
    RST=0;
    printf( "Data : %02X", Temp_High); /*Debug print line*/
    printf("\n");
    break;
    case '3': printf ("Read Temperature Low (TL)\n");
    RST=1;
    Put1620byte(0xA2); /* open Temp. Low register */
    DELAY(.1);
    Temp_Low = Get1620byte(); /* get status byte */
    RST=0;
    printf( "Data : %02X", Temp_Low); /*Debug print line*/
    printf("\n");
    break;
    case '4': printf (".Read Configuration Register\n");
    RST=0;
    DELAY(.1);
    RST=1;
    Put1620byte(0xAC); /* open Config. register */
    DELAY(.1);
    Config_Data = Get1620byte(); /* get status byte */
    RST=0;
    printf( "Data : %02X", Config_Data);/*Debug print line*/
    printf("\n");
    break;

    case '5': printf (".Write Configuration Register = 03h, Clear Flags\n");
    RST=1;
    DELAY(.1);
    Put1620byte(0x0C); /* Write to Config. Register Clear Flags*/
    DELAY(.1);
    Put1620byte(0x03); /* set to 02h */
    DELAY(.1);
    Put1620byte(0xAC); /* open Config. register */
    DELAY(.1);
    Config_Data = Get1620byte(); /* get status byte */
    printf( "Data : %02X", Config_Data);/*Debug print line*/
    printf("\n");
    RST=0;
    break;
    case '6': printf (".Set Temperature High (TH) = 50\n");
    RST=1;
    Put1620byte(0x01); /* Write to Temp. High Register */
    Write1620byte(0x50); /* set to 30h */
    RST=0;
    printf("\n");
    break;

    //case '7': printf (".Set Temperature High (TH) = 20\n");
    //RST=1;
    //Put1620byte(0x01); /* Write to Temp. High Register */
    //Write1620byte(0x20); /* set to 20h */
    //RST=0;
    //printf("\n");
    //break;
    case '8': printf (".Set Temperature Low (TL) = 0\n");
    RST=1;
    Put1620byte(0x02); /* Write to Temp. Low Register */
    Write1620byte(0x0); /* set to 00h */
    RST=0;
    printf("\n");
    break;

    //case '9': printf (".Set Temperature Low (TL) = 19\n");
    //RST=1;
    //Put1620byte(0x02); /* Write to Temp. Low Register */
    //Write1620byte(0x19); /* set to 19h */
    //RST=0;
    //printf("\n");
    //break;

    case 'a': printf (".Start Conversion\n");
    DELAY(.1);
    RST=1;
    Put1620byte(0xEE); /* start temp conversion */
    RST=0;
    printf("\n");
    break;
    default: printf ("Typo: Select Another Menu Option\n");
    break;
    }; /* end switch*/

    } while (1); /* Loop forever */
    /*----------------------------------------------------------------------*/
    /* End of program */
    /*----------------------------------------------------------------------*/
    }
    /*----------------------------------------------------------------------*/
    /* Get temp from DS1620 */
    /*----------------------------------------------------------------------*/
    unsigned char Get1620byte( void )

    {

    unsigned char j,k=0,b=1;
    k=0;
    b=1;
    for (j=0; j<8; j++)
    {
    CLK=0;
    if (DQ) k|=b; /* Read bit and or if = 1 */
    CLK=1;
    b=(b<<1); /* Setup for next read and or */
    }
    return k;
    }
    /* Put temp from DS1620 */
    void Put1620byte(unsigned char m)

    {
    unsigned char k,b=1;
    RST=1;
    for (k=0; k<8; k++)
    {
    CLK=0;
    DQ = (m & b); /* Send bit to 1620 */
    CLK=1;
    b=(b<<1); /* Setup to send next bit */
    }
    return;
    }
    /* read temp from DS1620 */
    unsigned char Read1620byte( void )
    {
    unsigned char j,k=0,b=1;
    k=0;
    b=1;
    for (j=0; j<10; j++)
    {
    CLK=0;
    if (DQ) k|=b; /* Read bit and or if = 1 */
    CLK=1;
    b=(b<<1); /* Setup for next read and or */
    }
    return k;
    }
    /* write temp from DS1620 */
    void Write1620byte(unsigned char m)

    {
    unsigned char k,b=1;
    RST=1;
    for (k=0; k<10; k++)
    {
    CLK=0;
    DQ = (m & b); /* Send bit to 1620 */
    CLK=1;
    b=(b<<1); /* Setup to send next bit */
    }
    return;
    }

    -----

  2. #2
    spown

    Re : Interfaçage ds1620 avec 8051 et ecran LCD

    Bonjour/bonsoir à tout le groupe;

    Je sens trop de mensonges ces derniers temps sur le forum. Tu dis : "J'ai pu programmer la partie capteur-Microcontroleur tous mes menus fonctionnent " , Et c'est quoi ca ?? ( date de 2002 ) http://www.maximintegrated.com/app-n...dex.mvp/id/134


    Tu sais, c'est pas illégal de tester les codes disponibles sur web, puis demander de l'aide. Ça aide à l’apprentissage rapide et avoir plus d’expérience. Ce qui est débile c'est de se croire bien maîtrise l’astuce alors qu'on est hors ligne!

Discussions similaires

  1. Interfaçage ds1620 avec 8051 et ecran LCD
    Par kero1 dans le forum Électronique
    Réponses: 8
    Dernier message: 28/04/2014, 07h11
  2. Interfaçage µc avec LCD graphique
    Par matters_100 dans le forum Électronique
    Réponses: 0
    Dernier message: 23/02/2011, 12h02
  3. Interfacage 8051/SJA1000
    Par invitec0743b89 dans le forum Électronique
    Réponses: 2
    Dernier message: 08/06/2009, 19h07
  4. tester un capteur DS1620 avec pic16F877
    Par invite3db0be88 dans le forum Électronique
    Réponses: 14
    Dernier message: 23/04/2009, 14h49
  5. réalisation thermomètre avec DS1620 et pic
    Par invite0b8beced dans le forum Électronique
    Réponses: 1
    Dernier message: 27/12/2006, 07h53
Découvrez nos comparatifs produits sur l'informatique et les technologies.