[PB] PIC 16F638 UART et RS232
Répondre à la discussion
Affichage des résultats 1 à 4 sur 4

[PB] PIC 16F638 UART et RS232



  1. #1
    mmarc2007

    Exclamation [PB] PIC 16F638 UART et RS232


    ------

    Bonjour à tous,

    j'ai un problème avec mon 16F628 et la fonction UART de mon PIC.
    J'ai un montage avec un MAX232N et un PC, je pense pas que le montage soit en cause.

    Le but de mon programme qui est en C et compilé avec CC5X c'est d'abord d'afficher "hello world" puis de renvoyer vers l'hyper terminal tout ce que j'ai saisi. Par la même occasion a chaque caractere reçu, je fais clignoter une LED.

    Code:
    static const char str[]={'\a', 'h', 'e', 'l', 'l','o', '\r', '\n', '\0'};
    
    //on envoi un message hello
    	for(i=0; str[i] != '\0'; i++)
    	{
    		TXREG=str[i];	// Add a character to the output buffer
    		while(!TXIF);	// Wait while the output buffer is full
    	}
    
    //on attend des caracteres
    	while(1)
    	{
    		PORTA.0 = !PORTA.0;//changement d'état de la LED 
    		while(!RCIF);	// Wait until data recieved
    		i=RCREG;	// Store for later
    
    		while(!TRMT);	// Wait until we're free to transmit
    		TXREG=i;	// Transmit
    	}
    j'utilise une librairie extraite du fichier 0005-uart_tr.c que j'ai trouvé ici: http://burningsmell.org/pic16f628/

    Le pb c'est que "hello world" ne s'affiche pas sur mon écran à la place j'ai le droit à un caractère bizard... De plus lorsque je saisi des caractères au clavier, le pic ne me renvoi rien, ou plutôt rien ne s'affiche...

    Je sais pas si le problème vient plus de l'hyperterminal ou de mon montage, en tout cas la diode clignote bien a la saisie des caracteres.

    Une idée?

    -----

  2. #2
    mictour

    Re : [PB] PIC 16F638 UART et RS232

    Bonjour mmarc2007,

    Peut-être un problème avec l’initialisation ? Ton programme n’est pas écrit à l’origine pour CC5X.
    Regarde ceci, comme base de départ pour un pic 16F62X :

    void initserial( void ) /* initialise serialcom port */
    {
    SPEN = 1;
    BRGH = 1; /* Async high speed */
    TXEN = 1; /* transmit enable */
    SPBRG = 26-1; /* 9600 Baud @ 4 MHz-clockfrequency */
    CREN = 1; /* Continuous receive */
    RX9 = 0; /* 8 bit reception */
    TRISB.2 = 0; /* TX is output */
    TRISB.1 = 1; /* RX is input */
    }

    bit putchar( char d_out ) /* sends one char */
    {
    if(d_out == '\0') return 0;
    /* refuse to send 0 "end of string" */
    while (!TXIF) ;
    /* wait until previus character transmitted */
    TXREG = d_out;
    return 1; /* done */
    }

    char getchar( void ) /* recieves one char */
    {
    char d_in;
    while ( RCIF == 0 ) ; /* wait for char */
    d_in = RCREG;
    return d_in;
    }

    /* If two (or more) char's are recieved, */
    /* but not read, the reciever will be locked! */
    /* To unlock the reciever, run function OverrunRecover() */
    void OverrunRecover(void)
    {
    char trash;
    trash = RCREG; /* the two char's that locked the reciever */
    trash = RCREG; /* are read and ignored */
    CREN = 0; /* the unlock procedure ... */
    CREN = 1;
    }


    /* echo62x.c echo charcters, serial input/output, */
    #include "16F628.h"
    #pragma config |= 0x3ff0
    /* Function prototypes */
    bit putchar( char ); /* function from seriF62x.c */
    char getchar( void ); /* function from seriF62x.c */
    void initserial( void ); /* function from seriF62x.c */
    void OverrunRecover(void); /* function from seriF62x.c */
    #include "seriF62x.c"
    void main( void)
    {
    char c;
    initserial();
    OverrunRecover();
    while( 1)
    {
    c = getchar( ); /* input 1 character */
    if( c == '\r')
    {
    putchar('\r');
    putchar('\n');
    } /* "Line Feed" and "Carrige Return" */
    else putchar(c); /* echo the character */
    }
    }

    char text1( char x)
    {
    skip(x);
    #pragma return[] = "hello world" '\r' '\n' '\0'
    }


    /* hello62x.c "Hello World!" program for 16F628 */
    /* 9600 baud */
    #include "16f628.h"
    #pragma config |= 0x3ff0
    /* function prototypes */
    void initserial( void ); /* from seriF62x.c */
    bit putchar( char ); /* from seriF62x.c */
    void delay( char ); /* from delays.c */
    char text1( char );
    #include "seriF62x.c"
    void main(void)
    {
    char i;
    /* Initialise serial port */
    initserial();
    putchar('\r'); putchar('\n');
    /* print textstring text1 */
    for(i = 0; putchar( text1(i)) ; i++) ;
    delay(10);
    }
    /* String to write */
    char text1( char x)
    {
    skip(x);
    #pragma return[] = "hello, world!" '\0'
    }

    Le tout provient d’un site en … Suédois ! Je te fais grâce des commentaires de l’auteur…

    Bonne prog, mictour.

  3. #3
    mictour

    Re : [PB] PIC 16F638 UART et RS232

    ... et le respect de l'auteur ? Voici le lien :

    http://www.ict.kth.se/courses/IL131V/include.htm

    Mictour.

  4. #4
    mmarc2007

    Re : [PB] PIC 16F638 UART et RS232

    Salut à toi mictour!

    MERCI BEAUCOUP! ça marche très bien, et t'as été super réactif.

    Je sens que je vai pas être dessu par ce forum.

    A bientôt

  5. A voir en vidéo sur Futura

Discussions similaires

  1. RS232 et PIC
    Par poche49 dans le forum Électronique
    Réponses: 1
    Dernier message: 26/08/2008, 11h34
  2. communication pic rs232
    Par alainav1 dans le forum Électronique
    Réponses: 14
    Dernier message: 24/03/2008, 16h03
  3. Pic/uart
    Par ABN84 dans le forum Électronique
    Réponses: 5
    Dernier message: 06/03/2008, 10h46
  4. RS232 avec PIC
    Par invitedce53369 dans le forum Électronique
    Réponses: 0
    Dernier message: 27/01/2008, 17h29
  5. Possibilité d'avoir 2 UART sur un PIC ??
    Par fun_olivier dans le forum Électronique
    Réponses: 4
    Dernier message: 24/01/2006, 22h18
Découvrez nos comparatifs produits sur l'informatique et les technologies.