Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Include Standard files
- #include "include/AT91SAM7X-EK.h"
- #define PID2 2
- //===================================== { Interruption Received char } ===================================================
- void char_rcv_IT(void){
- }
- //========================================== { Fonction d'attente } ======================================================
- void wait ( void )
- {
- volatile unsigned int waiting_time ;
- for(waiting_time = 0; waiting_time < MCKKHz*5; waiting_time++) ;
- }
- //========================================== { Main } ======================================================
- int main()
- {
- int i;
- //---------------------------------------------------------------------------------------------------//
- // INITIALISATION //
- //---------------------------------------------------------------------------------------------------//
- // Il faut activer l'horloge sur le module UART et DEBUG
- AT91C_BASE_PMC->PMC_PCER = (1 << ID_UART) | (1 << ID_DEBUG);
- // il faut définir que les broches UART_RX_PIN, UART_TX_PIN, DEBUG_TX_PIN et DEBUG_RX_PIN ne soient pas en mode PIO
- AT91C_BASE_PIOA->PIO_PDR = (UART_RX_PIN | UART_TX_PIN | DEBUG_TX_PIN | DEBUG_RX_PIN);
- // puis les attribuer au module A
- AT91C_BASE_PIOA->PIO_ASR = (UART_RX_PIN | UART_TX_PIN | DEBUG_TX_PIN | DEBUG_RX_PIN);
- //===================================== { UART } ===================================================
- // cet accès valide les RX et TX du module UART
- AT91C_BASE_US0->US_CR = AT91C_US_RXEN | AT91C_US_TXEN;
- // Initialisation des modes de l'UART
- AT91C_BASE_US0->US_MR = (AT91C_US_CHMODE_NORMAL | AT91C_US_USMODE_NORMAL | AT91C_US_SYNC | AT91C_US_CHRL_8_BITS);
- // Initialisation du debit UART
- int BD_UART = 115200;
- int CD_UART = MCK/BD_UART;
- AT91C_BASE_US0->US_BRGR = CD_UART;
- // ------------------------------{ Initialisation de l'AIC }--------------------------------------
- AT91C_BASE_AIC->AIC_IECR = (1 << PID2);
- AT91C_BASE_AIC->AIC_SVR[PID2] = (unsigned int)char_rcv_IT;
- AT91C_BASE_AIC->AIC_SMR[PID2] = 0;
- //===================================== { DEBUG } ====================================================
- // ------------------------------{ Initialisation du module DEBUG }--------------
- // cet accès valide les RX et TX du module DEBUG
- AT91C_BASE_DBGU->DBGU_CR = (AT91C_US_RXEN | AT91C_US_TXEN);
- // Initialisation des modes du module DEBUG
- AT91C_BASE_DBGU->DBGU_MR = (AT91C_US_CHMODE_NORMAL | AT91C_US_PAR_NONE);
- // Initialisation du debit DEBUG
- int BD_DEBUG = 200000;
- int CD_DEBUG = MCK / (BD_DEBUG*16);
- AT91C_BASE_US0->US_BRGR = CD_DEBUG;
- for (;;)
- {
- char* msg = "Anass";
- int size = sizeof(msg);
- for (i = 0; i < size ; i++) {
- while ((AT91C_BASE_US0->US_CSR & AT91C_US_TXRDY) == 0){};
- AT91C_BASE_US0->US_THR = msg[i];
- }
- wait();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement