📄 polling.c
字号:
//*-----------------------------------------------------------------------------
//* ATMEL Microcontroller Software Support - ROUSSET -
//*-----------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*-----------------------------------------------------------------------------
//* File Name : polling.c
//* Object : AT91 - USART Controller - Transfert by Polling
//*
//* Imported resources : None
//* Exported resources : MainApplication
//*
//* 1.0 01/10/98 JLV : Creation
//* 2.0 21/10/98 JCZ : Clean up
//* 2.1 10/04/00 JPP : Channel on PIOTXD0
//* 2.2 14/01/02 PFi : Port to EB40
//*----------------------------------------------------------------------------
#ifndef AT91_DEBUG_NONE
#include <stdio.h>
#endif
#include "periph/stdc/std_c.h"
#include "eb40.h"
#include "parts/r40807/reg_r40807.h"
//*----------------------------------------------------------------------------
//* Function Name : main
//* Object : AT91 - USART Controller - transfert by polling
//* Input Parameters : None
//* Output Parameters : None
//* Functions called : None
//*----------------------------------------------------------------------------
int main ( void )
//* Begin
{
unsigned int loop_count;
unsigned int value;
//* Stop channel
US0_CR = ( US_TXDIS | US_RXDIS | US_RSTTX | US_RSTRX ) ;
for (loop_count = 1000 ; loop_count > 0 ; loop_count--) ;
//* Clear PDC counts (Rx and Tx)
US0_RCR = 0x00000000 ;
US0_TCR = 0x00000000 ;
//*Disable ITs
US0_IDR = 0xFFFFFFFF ;
//* Initialize the channel
PIO_PDR = ( PIOTXD0 | PIORXD0 ) ;
US0_MR = ( US_ASYNC_MODE | US_CHMODE_LOCAL_LOOPBACK ) ;
US0_BRGR = 53 ;
//* Start channel
US0_CR = ( US_RXEN | US_TXEN ) ;
for (loop_count = 1000 ; loop_count > 0 ; loop_count--);
for (value = 0 ; ; value++)
{
value &= 0x00FF;
#ifndef AT91_DEBUG_NONE
if (value == 0)
{
loop_count ++ ;
printf ( "Loop %d\n", loop_count ) ;
}
#endif
//* Wait Tx ready
for ( ; (US0_CSR & (1 << 1)) == 0 ; );
//* Send byte
US0_THR = value;
//* Wait Rx ready
for ( ; (US0_CSR & (1 << 0)) == 0 ; );
//* Receive and check byte
if (US0_RHR != value)
{
#ifndef AT91_DEBUG_NONE
printf ( "**** 0x'%x' / 0x'%x'\n", US0_RHR, value);
#endif
}
}
//* End
return(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -