timer.c
来自「在ccs上使用定时器实现一个数字震荡器的代码.产生的是正弦波波形。」· C语言 代码 · 共 92 行
C
92 行
/* ============================================================================*/
/* Copyright (C) 2004 YINXING TECHNOLOGY CO., LTD */
/* All Rights Reserved. */
/* ----------------------------------------------------------------------------*/
/* ============================================================================*/
#include "stdio.h"
#define IMR 0
#define ST0 6
#define ST1 7
#define TIM 0x24
#define PRD 0x25
#define TCR 0x26
#define PMST 29
extern int counter = 25;
extern int flagxf = 0;
int con_buf=0;
float buf[128]; /* save out wave buffer ! */
float y0;
float y1=0.30901699;
float y2=0.58778525; /* y2= y1*A */
const float aa=1.90211304;
const float bb=-1.;
main()
{
const int flag = 1;
int *dest;
dest = (int *)IMR;
*dest = 0;
dest = (int *)PMST;
*dest = 0x1020; /* interrupt vector at 0x1000 */
dest = (int *)TCR;
*dest = 0x0010;
dest = (int *)PRD;
*dest = 2499;
dest = (int *)IMR;
*dest = 0x0008; /* enable timer0 TINT0 */
dest = (int *)TCR;
*dest = 0x0030;
*dest = 0x0000;
asm (" rsbx intm");
while ( flag )
{
if ( flagxf == 0 )
{
asm( " RSBX XF");
asm( " nop" );
asm( " nop" );
asm( " nop" );
}
else
{
asm(" SSBX XF");
asm( " nop" );
asm( " nop" );
asm( " nop" );
}
}
}
void interrupt tint()
{
y0 = aa*y1 + bb*y2;
y2 = y1;
y1 = y0;
buf[con_buf]=y0;
con_buf++;
if(con_buf == 128)
con_buf=0; /* set breakpoint to show wave ! */
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?