liaison série sur AVR
Par guillaume le mercredi, mars 25 2009, 13:29 - Programmation - Lien permanent
Quelques bout de code pour utiliser la liaison série d'un AVR (testé sur un ATmega8!).
Initialisation du périphérique
Le code a exécuter avant d'utiliser l'UART:
/**************************************** initUART *****************************************/ void initUART(unsigned char baudrate){ // Vitesse P. 161 du datasheet UBRRL = baudrate; // réception et émission UCSRB = (1 << RXEN) | (1 << TXEN); // format 1N8 UCSRC = (1 << URSEL) | (3 << UCSZ0); }
Envoie d'un caractère
Pour l'envoie, le principe est le même que pour tous les µcontrolleurs ou PC. On écrit une valeur dans le registre d'envoi et on attend que ça se passe!
/**************************************** putchr *****************************************/ static void putchr(char c){ while ( ! ( (UCSRA) & (1 << (UDRE)) ) ) ; UDR = c; }
Envoie d'un string
Le principe est d'envoyer plusieurs caractères. Donc on peut reprendre la fonction précédente
/**************************************** printstr *****************************************/ static void printstr (unsigned char *string){ while(*string){ putchr(*string++); } putchr('\r'); putchr('\n'); }
Réception d'un caractère
Pour la réception, l'utilisation des interruptions est a préférer. Mais pour cet exemple simple, la méthode du pooling est utilisée, c'est-à-dire, on attend la réception en lisant le registre qui indique une réception.
/**************************************** getchr *****************************************/ unsigned char getchr(void){ while ( !(UCSR0A & (1<<RXC0)) ); return UDR0; }
Commentaires
Duramantan allows for different colors to be http://www.rolexreplicasale.org.uk/ used, but only one color per each entire surface. Colormantan is for the more creative customization and http://www.replicawatch.us.com/ allows for much more unique creations. While the example images of Rolex watches with the Colormantan treatment tends to show squared areas of color, in reality, there is no particular geometric or shape restrictions, and http://www.rolexreplicastoreuk.org.... the client can opt for more or less what they want, if we understand Rau-Tech correctly. So why am I so excited by http://www.worldwatchesale.me.uk/ this? Well, for the longest time, PVD-style coatings have been limited to just a few dark colors - which are mostly black and gray. If you wanted a metal http://www.hotrolex2013.com/ watch coated with another color, it would often need to be anodized aluminum, which is a rather http://www.cheapreplicawatchesuk.co... soft metal and not as durable as steel.