📄 main.c
字号:
/*****************************************************************************
** **
** Name: FIO pins, Interrupts, and Timer in C **
** **
******************************************************************************
(C) Copyright 2006 - Analog Devices, Inc. All rights reserved.
Project Name: BF533 Flags C
Date Modified: 3/31/03 Ver 1.01
Software: VisualDSP++ 4.5
Hardware: ADSP-BF533 EZ-KIT Lite
Connections: Switch SW9_1 has to be turned on in order to connect SW7 to PF8
Purpose: To demonstrate the configuration of FIO pins, Timer, and
Interrupts in C
*****************************************************************************/
#include "BF533 Flags.h"
#include "ccblkfn.h"
#include "sysreg.h"
#include <sys\exception.h>
#include <cdefBF533.h>
#include "cpld.h"
#include "GeneralFunc.h"
//#include "Init.h"
#include "Sys.h"
#define WaitBaudFrequency() gWait=1; while(gWait); //wait for 1/9600s
#define printerBusy() (*pFIO_FLAG_D)&0x0001
#define SetSerialOut(o) if(o) *pFIO_FLAG_S=0x0010; else *pFIO_FLAG_C=0x0010;
#define SendSerialHWord(i) SendSerialByte((U8)((i)&0xff)); SendSerialByte((U8)((i)>>8));
extern void Init_EBIU(void);
extern void Delay(unsigned int Value);
typedef unsigned short U16;
typedef short S16;
typedef unsigned char U8;
#define TABLE_SIZE 512
#define COS_SIZE 10
#define LEN_ECG 200
#define PI 3.1415926
#define NOR_SCALE 3
#define SQRT_SIZE 400
#define DIVSCALE 10
#define sqr(n) SQRT[n]
#define N 100
#define K N/NOR_SCALE
#define LEN_LINE 200
#define PRINT_SCALE 16
//--------------------------------------------------------------------------//
// Variables //
//--------------------------------------------------------------------------//
char printBuff[LEN_LINE];
char gWait;
/*void WaitBaudFrequency()
{
gWait=1;
while(gWait); //wait for 1/9600s
}*/
U16 tcos[TABLE_SIZE]={1024,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1022,1022,1022,1022,1022,1022,1021,1021,1021,1021,1020,1020,1020,1020,1019,1019,1019,1019,1018,1018,1018,1017,1017,1017,1016,1016,1015,1015,1015,1014,1014,1013,1013,1012,1012,1011,1011,1010,1010,1009,1009,1008,1008,1007,1007,1006,1006,1005,1004,1004,1003,1003,1002,1001,1001,1000, 999, 999, 998, 997, 997, 996, 995, 994, 994, 993, 992, 991, 990, 990, 989, 988, 987, 986, 986, 985, 984, 983, 982, 981, 980, 979, 978, 978, 977, 976, 975, 974, 973, 972, 971, 970, 969, 968, 967, 966, 965, 964, 963, 962, 960, 959, 958, 957, 956, 955, 954, 953, 951, 950, 949, 948, 947, 946, 944, 943, 942, 941, 939, 938, 937, 936, 934, 933, 932, 930, 929, 928, 927, 925, 924, 922, 921, 920, 918, 917, 916, 914, 913, 911, 910, 908, 907, 906, 904, 903, 901, 900, 898, 897, 895, 894, 892, 890, 889, 887, 886, 884, 883, 881, 879, 878, 876, 875, 873, 871, 870, 868, 866, 865, 863, 861, 860, 858, 856, 854, 853, 851, 849, 847, 846, 844, 842, 840, 839, 837, 835, 833, 831, 829, 828, 826, 824, 822, 820, 818, 816, 814, 813, 811, 809, 807, 805, 803, 801, 799, 797, 795, 793, 791, 789, 787, 785, 783, 781, 779, 777, 775, 773, 771, 769, 767, 765, 762, 760, 758, 756, 754, 752, 750, 748, 745, 743, 741, 739, 737, 735, 732, 730, 728, 726, 724, 721, 719, 717, 715, 712, 710, 708, 706, 703, 701, 699, 696, 694, 692, 690, 687, 685, 683, 680, 678, 675, 673, 671, 668, 666, 664, 661, 659, 656, 654, 652, 649, 647, 644, 642, 639, 637, 634, 632, 629, 627, 625, 622, 620, 617, 615, 612, 609, 607, 604, 602, 599, 597, 594, 592, 589, 587, 584, 581, 579, 576, 574, 571, 568, 566, 563, 561, 558, 555, 553, 550, 547, 545, 542, 539, 537, 534, 531, 529, 526, 523, 521, 518, 515, 512, 510, 507, 504, 501, 499, 496, 493, 491, 488, 485, 482, 479, 477, 474, 471, 468, 466, 463, 460, 457, 454, 451, 449, 446, 443, 440, 437, 434, 432, 429, 426, 423, 420, 417, 414, 412, 409, 406, 403, 400, 397, 394, 391, 388, 386, 383, 380, 377, 374, 371, 368, 365, 362, 359, 356, 353, 350, 347, 344, 342, 339, 336, 333,
330, 327, 324, 321, 318, 315, 312, 309, 306, 303, 300, 297, 294, 291, 288, 285, 282, 279, 276, 273, 270, 267, 264, 260, 257, 254, 251, 248, 245, 242, 239, 236, 233, 230, 227, 224, 221, 218, 215, 212, 209, 205, 202, 199, 196, 193, 190, 187, 184, 181, 178, 175, 171, 168, 165, 162, 159, 156, 153, 150, 147, 144, 140, 137, 134, 131, 128, 125, 122, 119, 115, 112, 109, 106, 103, 100, 97, 94, 90, 87, 84, 81, 78, 75, 72, 69, 65, 62, 59, 56, 53, 50, 47, 43, 40, 37, 34, 31, 28, 25, 21, 18, 15, 12, 9, 6, 3};
U16 SQRT[SQRT_SIZE]={0,1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19};
// ORI[LEN_ECG]={165,216,306,408,528,581,595,493,384,206,137,85,173,150,128,140,157,170,162,201,170,170,165,176,179,184,199,190,206,213,183,207,208,247,229,254,264,242,236,241,248,254,260,267,278,285,293,302,308,326,330,338,340,346,334,318,346,343,325,289,270,246,241,225,223,180,193,175,176,179,180,172,141,193,157,176,188,187,191,147,193,198,191,151,164,183,178,207,175,189,197,149,159,183,173,189,157,208,181,192,192,150,193,197,201,244,212,186,182,179,179,199,198,170,203,193,198,200,191,208,255,265,224,212,247,223,219,219,260,271,219,258,248,212,213,205,166,171,186,200,247,204,182,186,183,203,164,194,150,128,149,206,268,417,528,601,605,463,318,153,106,79,123,197,189,228,231,196,207,247,193,196,207,212,200,199,246,217,219,232,203,245,205,219,212,227,224,253,259,265,261,275,290,326,286,299,326,325,329,380};
short adc_data[572]={186,182,189,217,215,204,188,187,234,193,188,212,188,226,219,188,239,208,197,186,231,195,241,231,195,244,214,255,236,225,255,251,262,260,215,216,249,198,215,182,198,231,199,202,209,185,218,216,199,194,174,168,192,159,206,341,517,584,591,513,351,189,97,107,116,174,165,213,183,180,215,214,183,180,179,199,202,223,189,198,212,215,207,195,245,209,257,278,276,259,263,231,283,290,291,263,276,313,285,306,326,362,360,366,373,328,362,359,347,313,289,290,236,222,201,230,191,223,212,205,168,204,201,171,164,159,183,167,176,172,211,179,217,221,171,180,196,190,188,220,220,218,220,197,227,225,189,227,228,194,189,233,195,186,223,229,197,183,223,234,181,215,189,197,198,186,235,261,229,215,213,221,254,209,220,231,217,243,212,261,203,185,173,186,218,211,193,201,205,229,197,186,176,167,155,209,223,361,484,540,555,521,406,254,101,109,146,147,194,171,173,219,182,177,223,231,188,236,213,198,195,237,223,230,250,205,252,219,228,269,245,284,285,259,310,278,284,294,314,343,299,340,324,321,302,295,288,295,235,260,224,249,236,191,184,201,202,163,210,200,184,160,164,164,176,194,165,203,194,166,215,219,219,184,223,221,173,188,187,193,173,225,229,202,222,200,228,202,191,186,193,224,215,192,202,226,216,188,191,231,230,241,244,238,232,244,247,216,220,221,255,252,252,257,220,201,234,207,236,175,177,236,190,189,182,199,188,219,187,182,160,138,175,307,414,517,551,557,435,295,187,90,87,164,156,169,167,201,175,225,217,206,208,228,218,212,217,229,204,197,237,247,251,204,205,251,249,212,227,283,278,263,276,261,266,296,308,290,306,323,309,309,354,306,347,314,292,262,258,254,276,217,209,234,184,178,173,214,209,153,197,201,197,200,199,211,208,188,197,184,214,177,182,185,188,218,193,195,183,218,225,201,227,180,223,236,221,173,190,241,238,217,188,195,235,216,234,237,196,175,196,229,196,230,197,201,197,185,191,244,199,183,199,194,230,223,225,232,238,236,236,198,237,188,236,211,194,233,234,272,224,253,242,237,220,217,251,249,227,200,234,207,224,196,199,196,184,203,207,203,215,198,159,213,283,399,526,557,586,472,323,161,108,88,171,\
156,195,182,204,216,177,178,188,220,176,199,239,234,226,205,215,214,238,248,226,216,245,215,230,262,258,264,245,248,232,289,280,277,271,325,299,301,301,355,371,319,312,342,352,290,255,256,278,253,228,231,232,185,202,168,221,180,193,198,177,170,196,213,182,216,171,180};
short adc_data1[572],adc_data2[572],adc_data3[572];
void Init_PLL(void)
{
int iIMASK_Value;
sysreg_write(reg_SYSCFG, 0x32); //Initialize System Configuration Register
// set VCO/CCLK = 1, and VCO/SCLK = 5 (take effect immediately)
*pPLL_DIV = 0x0005;
// prepare PLL changes (set CLKIN/VCO = 22; takes effect after PLL programming sequence)
*pPLL_LOCKCNT = 0x0200; // time for PLL to stabilize
*pPLL_CTL = 0x2c00; // set VCO/CLKIN = 22
// execute PLL programming sequence
*pSIC_IWR = 0x00000001; // enable only PLL wakeup interrupt
iIMASK_Value = cli(); // disable interrupts
idle(); // wait for PLL wakeup interrupt
sti(iIMASK_Value);
}//end Init_PLL
/*void printECG(U16* e1,U16* e2,U16* e3,U16* e4,U16 len)
{
U16 i=0;
for(;i<len;i++)
{
SendSerialByte(27);
SendSerialByte(39);
SendSerialByte(8);
SendSerialByte(0);
SendSerialHWord(96-e1[i%572]/16);
SendSerialHWord(96-e1[i%572]/16+1);
SendSerialHWord((96-e1[i%572]/6)+96);
SendSerialHWord((96-e1[i%572]/6)+97);
SendSerialHWord((96-e1[i%572]/8)+96*2);
SendSerialHWord((96-e1[i%572]/8)+96*2+1);
SendSerialHWord(e1[i%572]/16+96*3);
SendSerialHWord(e1[i%572]/16+96*3+1);
SendSerialByte(13);
}
}
*/
void SendSerialByte(U8 b)
{
char i=0;
char oe=0;// even-odd check
while(printerBusy());
//Delay(10000);
SetSerialOut(1);
WaitBaudFrequency();
SetSerialOut(0);
WaitBaudFrequency();
while(i++<8)
{
SetSerialOut(b&0x01);
WaitBaudFrequency();
oe+=b&0x01;
b>>=1;
}
SetSerialOut(oe&0x01);
WaitBaudFrequency();
SetSerialOut(1);
//WaitBaudFrequency();
}
void printerInit()
{
SendSerialByte(27);
SendSerialByte('@');
}
void printString(U8* str)
{
U8 s;
//SendSerialByte(27);
//SendSerialByte('1');
//SendSerialByte(1);
while(s=*str++) SendSerialByte(s);
//SendSerialByte(13);
}
//print a line from (a+axis,c) to (b+axis,c)
void printLine(short a,short b,char c,U8 axis)
{
short j;
a/=PRINT_SCALE;
b/=PRINT_SCALE;
if(a<b)
{
for(j=a;j<=b;j++)
{
printBuff[j+axis]|=c;
}
}
else
{
for(j=b;j<=a;j++)
{
printBuff[j+axis]|=c;
}
}
}
void printECG(S16* adc_data,S16* adc_data1,S16* adc_data2,S16* adc_data3,U16 len)
{
int i,j;
SendSerialByte(27);
SendSerialByte('1');
SendSerialByte(0);
for(i=0;i<LEN_LINE;i++) printBuff[i]=0;
for(i=2;i<len;i=i+2)
{
if(i%16==0)
{
SendSerialByte(27);
SendSerialByte('K');
SendSerialByte(LEN_LINE&0xff);
SendSerialByte(LEN_LINE>>8);
for(j=0;j<LEN_LINE;j++)
{
SendSerialByte(printBuff[j]);
}
SendSerialByte('\r');
for(j=0;j<LEN_LINE;j++) printBuff[j]=0x00;
}
if(adc_data[i]<-25*PRINT_SCALE) adc_data[i]=1-25*PRINT_SCALE;
if(adc_data[i-2]<-25*PRINT_SCALE) adc_data[i-2]=1-25*PRINT_SCALE;
printLine(adc_data[i],adc_data[i-2],1<<((i>>1)&0x07),25);
printLine(adc_data1[i],adc_data1[i-2],1<<((i>>1)&0x07),75);
printLine(adc_data2[i],adc_data2[i-2],1<<((i>>1)&0x07),125);
if(adc_data3[i]>25*PRINT_SCALE) adc_data3[i]=25*PRINT_SCALE-1;
if(adc_data3[i-2]>25*PRINT_SCALE) adc_data3[i-2]=25*PRINT_SCALE-1;
printLine(adc_data3[i],adc_data3[i-2],1<<((i>>1)&0x07),175);
}
}
//--------------------------------------------------------------------------//
// Function: main //
//--------------------------------------------------------------------------//
void main(void)
{
CtrlReg2 myCtrlReg2;
int i=1;
//sysreg_write(reg_SYSCFG, 0x32); //Initialize System Configuration Register
Init_PLL();
*pDMA5_CONFIG = 0x0000;
Init_Flags();
Init_Timers();
Init_EBIU();
*((volatile unsigned char *)0x20300000)=0x00;//init ext board port
Init_Interrupts();
for(i=0;i<572;i++)
{
//adc_data[i]=adc_data[i]/PRINT_SCALE;
adc_data1[i]=adc_data[i]/2;
adc_data2[i]=adc_data[i]/3;
adc_data3[i]=adc_data[i];
}
gWait=1;
for(i=0;i<99999;i++);
printerInit();
SendSerialByte(28);
SendSerialByte(74);
printString(" I I I a\r");
printString(" I I V\r");
printString(" I L\r");
printerInit();
/*SendSerialByte(27);
SendSerialByte('B');
SendSerialByte(11);
SendSerialByte(0);
SendSerialByte(11);
SendSerialByte('I');//printString("I");
//SendSerialByte(11);
//SendSerialByte('B');//printString("II");
//SendSerialByte(11);
//SendSerialByte('C');//printString("III");
//SendSerialByte(11);
//printString("aVL");
//SendSerialByte(11);
//printECG(adc_data,adc_data,adc_data,adc_data,570);
//printECG(adc_data,adc_data,adc_data,adc_data,2000);
//printString("abcde4\r\n");*/
printECG(adc_data,adc_data1,adc_data2,adc_data3,200);
printerInit();
while(1)
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -