📄 wave_dual.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 : wave_dual.c
//* Object : AT91 - Timer Counter - Dual waveform generation
//*
//* Imported resources : none
//* Exported resources : main
//*
//* 1.0 30/09/98 JLV : Creation
//* 2.0 24/07/00 PF : Clean up
//*-----------------------------------------------------------------------------
/*
Configure the channel 0 of the Timer Counter (TC) of the AT91
to aim dual waveform generation :
- clock = MCKI / 1024
- Register A = 0x4000 -> toggle TIOA0 when reached
- Register B = 0x6000 -> toggle TIOB0 when reached
- Register C = 0x8000 -> toggle TIOA0 and TIOB0 when reached
generate trigger to restart the timer
--------------------------------------------------------------------------------
________ ________ ______
TIOA0 __| |________| |________| red LED / output
____________ ____________ ______
TIOB0 __| |____| |____| green LED / output
--------------------------------------------------------------------------------
*/
#include "periph/stdc/std_c.h"
#include "targets/eb40/eb40.h"
#include "parts/r40807/reg_r40807.h"
//*-----------------------------------------------------------------------------
//* Function Name : main
//* Object : AT91 - Timer Counter - Dual waveform generation
//* Input Parameters : none
//* Output Parameters : none
//* Functions called : None
//*-----------------------------------------------------------------------------
int main ( void )
//* Begin
{
/* Enable and clear PIO pin corresponding to TIOA0, TIOB0 and TIOA1 */
PIO_PER = ( 1<<PIOTIOA0 ) | (1<<PIOTIOA1) | (1<<PIOTIOB0) ;
PIO_OER = ( 1<<PIOTIOA0 ) | (1<<PIOTIOA1) | (1<<PIOTIOB0) ;
PIO_CODR = ( 1<<PIOTIOA0 ) | (1<<PIOTIOA1) | (1<<PIOTIOB0) ;
PIO_PDR = (1<<PIOTIOA0) | (1<<PIOTIOB0) ; /* Define TIOA0 and TIOB0 as peripheral */
//* Initialize the mode of the timer 0
TC0_CMR =
TC_BSWTRG_SET_OUTPUT | /* BSWTRG: software trigger set TIOB */
TC_BCPC_TOGGLE_OUTPUT | /* BCPC : Register C compare toggle TIOB */
TC_BCPB_TOGGLE_OUTPUT | /* BCPC : Register B compare toggle TIOB */
TC_ASWTRG_SET_OUTPUT | /* ASWTRG : software trigger set TIOA */
TC_ACPC_TOGGLE_OUTPUT | /* ACPC : Register C compare toggle TIOA */
TC_ACPA_TOGGLE_OUTPUT | /* ACPA : Register A compare toggle TIOA */
TC_WAVE | /* WAVE : Waveform mode */
TC_CPCTRG | /* CPCTRG : Register C compare trigger enable */
TC_EEVT_XC0 | /* EEVT : XC0 as external event (TIOB = output) */
TC_CLKS_MCK2 ; /* TCCLKS : MCKI / 1024 */
TC0_RA = 0x4000 ; /* Initialize the RA Register value */
TC0_RB = 0x6000 ; /* Initialize the RB Register value */
TC0_RC = 0x8000 ; /* Initialize the RC Register value */
TC0_CCR = TC_CLKEN ; /* Enable the clock of the timer */
TC0_CCR = TC_SWTRG ; /* Trigg the timer */
//* End
return(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -