if( GpioDataRegs.GPADAT.bit.GPIOA2==0) break;
GpioDataRegs.GPADAT.bit.GPIOA1=0; delay_ad(); }
for(i=0;i<0x10;i++) {
GpioDataRegs.GPADAT.bit.GPIOA1=1; delay_ad();
if( GpioDataRegs.GPADAT.bit.GPIOA2==0) da=da<<1; else {
da=da|0x0001; da=da<<1; }
GpioDataRegs.GPADAT.bit.GPIOA1=0; delay_ad(); }
GpioDataRegs.GPADAT.bit.GPIOA0=1; delay_ad(); return(da); }
void AD_SUM_AVG(void) {
unsigned int i=0; float aF=0.9;
static float Sample_AVG_fst=0.0; Sample=0;
for (i=0; i SampleTable[i]=ads8320(); Sample=Sample+SampleTable[i]; } Sample_AVG=Sample/AVG; Sample_AVG=(1-aF)*Sample_AVG+aF*Sample_AVG_fst; Sample_AD=Sample_AVG*0.327675; Sample_AVG_fst=Sample_AVG; } void main(void) { InitSysCtrl(); //初始化系统 //初始化系统时钟,系统时钟150M,低俗时钟37.5M,打开外设时钟SPI控制37.5M EALLOW; SysCtrlRegs.PCLKCR.bit.SPIENCLK=0x01; EDIS; 15 //**************************************************** //初始化GPIOF,设定SPI外设控制 EALLOW; GpioMuxRegs.GPFMUX.all=0x000F; // Select GPIOs to be SPI pins // Port F MUX - x000 0000 0000 1111 EDIS; //初始化GPIOA,设定GPA0为AD8320的CS,GPA1为SCK,GPA2为Dout EALLOW; GpioMuxRegs.GPAMUX.all=0x0000; // GPIOI/Os GpioMuxRegs.GPADIR.all=0xFFFB; // GPIO DIR select GPIOs as output GpioDataRegs.GPADAT.bit.GPIOA0=1; //ads8320--cs GpioDataRegs.GPADAT.bit.GPIOA1=1; //ads8320--clk EDIS; //初始化SCI,GP4为TXD,GP5为RXD EALLOW; GpioMuxRegs.GPGMUX.bit.SCITXDB_GPIOG4 = 1; GpioMuxRegs.GPGMUX.bit.SCIRXDB_GPIOG5 = 1; EDIS; //初始化GPIOB,设定低四位为按键输入 EALLOW; GpioMuxRegs.GPBMUX.all=0x0000; // peripheral I/Os GpioMuxRegs.GPBDIR.all=0xFF00; // GPIO DIR select GPIOs as output EDIS; //**************************************************** //**************************************************** DINT; //关闭中断 IER = 0x0000; IFR = 0x0000; //**************************************************** InitPieCtrl(); //初始化PIE控制寄存器 InitPieVectTable(); //初始化PIE参数表 init(); //初始化液晶显示 //**************************************************** EALLOW; // This is needed to write to EALLOW protected registers PieVectTable.RXBINT = &scibRxFifoIsr; PieVectTable.TXBINT = &scibTxFifoIsr; EDIS; // This is needed to disable write to EALLOW protected registers //**************************************************** scib_fifo_init(); // Init SCI-B spi_fifo_init(); // Initialize the Spi FIFO spi_init(); // init SPI //**************************************************** // Enable interrupts required for this example PieCtrlRegs.PIECRTL.bit.ENPIE=1; // Enable the PIE block PieCtrlRegs.PIEIER9.bit.INTx3=1; // PIE Group 9, INT1 PieCtrlRegs.PIEIER9.bit.INTx4=1; // PIE Group 9, INT2 //**************************************************** // PieCtrlRegs.PIEIER6.bit.INTx1=1; // Enable PIE Group 6, INT 1 16 // PieCtrlRegs.PIEIER6.bit.INTx2=1; // Enable PIE Group 6, INT 2 EINT; //**************************************************** EALLOW; GpioDataRegs.GPADAT.bit.GPIOA1=1; GpioDataRegs.GPADAT.bit.GPIOA0=0; EDIS; //**************************************************** EALLOW; PieVectTable.TINT0=&cpu_timer0_isr; //将CPU定时器0的中断服务程序入口地址写到PIE向量表中 EDIS; InitCpuTimers(); ConfigCpuTimer(&CpuTimer0,150,250000); PieCtrlRegs.PIEIER1.bit.INTx7=1; //使能PIE中组1的第7个中断TINT0-PIE级中断使能 IER = 0x121; // Enable CPU INT CpuTimer0Regs.TCR.bit.TSS=0; //停止定时器0的运行 //**************************************************** while(1) { Uint16 i; AD_SUM_AVG(); DA_OUT(); spi_xmit(spi_data); char_string (title,LCD_L11); //发送本实验标题1_输入电压 char_string (title1,LCD_L21); //发送本实验标题2_实测电压 char_string (title2,LCD_L31); //发送本实验标题3_输入波特率 conv(Sample_AD,ADVAL,0x01); //数据转换调用 char_string (ADVAL,LCD_L25); //发送实测电压值 for(i=0;i<500;i++) { delay(5000); } conv(key,ADVAL,0x00); //数据转换调用 char_string (ADVAL,LCD_L15); //发送输入电压值 for(i=0;i<500;i++) { delay(5000); } conv(key_false,ADVAL_err,0x02); //数据转换调用 char_string (ADVAL_err,LCD_L45); //发送实测电压值 for(i=0;i<500;i++) { delay(5000); } 17 } } interrupt void cpu_timer0_isr(void) { static char key4=0x00; CpuTimer0Regs.TCR.bit.TSS=1;//关闭定时器 key_value=GpioDataRegs.GPBDAT.all; if((key_value&BIT3)==BIT3) { key4=key4^0x01; } if(((key_value&BIT0)==BIT0)&&(key4==0x01))//输入减1 { if(key==0x0000) {key=0x0000;} else key-- ; } if(((key_value&BIT1)==BIT1)&&(key4==0x01))//输入加1 { if(key==0x4E20) {key=0x4E20;} else key++; } //**************************************************** if((key_value&BIT2)==BIT2) //波特率设定 { CpuTimer0Regs.TCR.bit.TSS=1; //关闭定时器 key_baud++; if(key_baud==0x07) {key_baud=0x00;} switch(key_baud) { case 0: char_string (baud_disp,LCD_L36); ScibRegs.SCIHBAUD=SCI_PRD[0]; ScibRegs.SCILBAUD=SCI_PRD[1]; break; //显示波特率4800 case 1: char_string (baud_disp1,LCD_L36); ScibRegs.SCIHBAUD=SCI_PRD[2]; ScibRegs.SCILBAUD=SCI_PRD[3]; break; //显示波特率9600 case 2: 18 char_string (baud_disp2,LCD_L36); ScibRegs.SCIHBAUD=SCI_PRD[4]; ScibRegs.SCILBAUD=SCI_PRD[5]; break; case 3: char_string (baud_disp3,LCD_L36); ScibRegs.SCIHBAUD=SCI_PRD[6]; ScibRegs.SCILBAUD=SCI_PRD[7]; break; //显示波特率38400 case 4: ScibRegs.SCIHBAUD=SCI_PRD[8]; ScibRegs.SCILBAUD=SCI_PRD[9]; char_string (baud_disp4,LCD_L36); break; //显示波特率56000 case 5: ScibRegs.SCIHBAUD=SCI_PRD[10]; ScibRegs.SCILBAUD=SCI_PRD[11]; char_string (baud_disp5,LCD_L36); break; //显示波特率57600 case 6: ScibRegs.SCIHBAUD=SCI_PRD[12]; ScibRegs.SCILBAUD=SCI_PRD[13]; char_string (baud_disp6,LCD_L36); break; //显示波特率115200 } } CpuTimer0Regs.TCR.bit.TSS=0; //重新启动定时器 } interrupt void scibTxFifoIsr(void) { Uint16 i; static char set_back=0x00; set_back=set_back^0x01; if(set_back==0x00) {for(i=0; i< 8; i++) { ScibRegs.SCITXBUF=sdataB[i]; // Send data } } if(set_back==0x01) {for(i=8; i< 15; i++) { ScibRegs.SCITXBUF=sdataB[i]; // Send data } } ScibRegs.SCIFFTX.bit.TXINTCLR=1; // Clear Interrupt flag PieCtrlRegs.PIEACK.all|=0x100; // Issue PIE ACK 19
电子设计大赛论文
![](/skin/haowen/images/icon_star.png)
![](/skin/haowen/images/icon_star.png)
![](/skin/haowen/images/icon_star.png)
![](/skin/haowen/images/icon_star.png)