⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 SmartARM2200开发平台光盘资料中的所有的源码和测试程序以及应用程序
💻 C
字号:
/****************************************Copyright (c)**************************************************
**                               Guangzou ZLG-MCU Development Co.,LTD.
**                                      graduate school
**                                 http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name:			main.c
** Last modified Date:  2004-09-16
** Last Version:		1.0
** Descriptions:		The main() function example template
**
**------------------------------------------------------------------------------------------------------
** Created by:			Ganda
** Created date:		2005-4-22
** Version:				1.0
** Descriptions:		The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:			Chenxibing
** Modified date:		2005-02-19
** Version:
** Descriptions:		
**
********************************************************************************************************/
#include "config.h"

//#define DEBUG

#define CAT1025 0xA0

struct ctrl
{   char cmd[20];
    char cmdnum;
    char paracmd[20];
    char paranum;
}control;

uint8 GetCmd(void);
void GetCmdTst (void);
void I2C_IntInit(void);
void RTC_IntInit(void);
void DispBios (void);
void FFT_Tst(void);


int main (void)
{   
    uint8 i;
    GPIO_Init();
    UART0_Init ();
    RTC_Init();
    MSPI_Init();
    I2C_Init(400000);
    
    I2C_IntInit();
    RTC_IntInit();
	IRQEnable();	

    DispBios ();
    
f:  UART0_SendStr(INFO0);

#ifdef DEBUG
    GetCmdTst ();
#else
    GetCmd();
#endif   
    
    switch(control.cmd[0])
    { case 'l':   
          LedCtrl(control.paracmd[0]);
          MSPI_SendData(DISP_TAB[control.paracmd[0]-0x30]);
          break;
      case 'b':   
          BeepCtrl(control.paracmd[0]-0x30);
          MSPI_SendData(DISP_TAB[control.paracmd[0]-0x30]);
          break;
      case 't':
          sprintf(UART0_StrBuff,"\r\n%d.%d.%d  %d:%d:%d",YEAR,MONTH,DOM,HOUR,MIN,SEC);
          MSPI_SendData(DISP_TAB[0x00]);
          UART0_SendStr (UART0_StrBuff);
          break;
      case 'r':  
          for (i=0; i<10; i++)
          {
              I2C_Buf[i] = 0;
          }
          I2C_ReadNByte(CAT1025, ONE_BYTE_SUBA, 0x00, I2C_Buf, 10);
          I2C_Buf[11] = '\0';
          sprintf(UART0_StrBuff,"\r\n%s", I2C_Buf);
          UART0_SendStr(UART0_StrBuff);
          break;
      case 'w':  
          for (i=0; i<10; i++)
          {
		      I2C_Buf[i] = control.paracmd[i];          
          }
          I2C_WriteNByte(CAT1025, ONE_BYTE_SUBA, 0x00, I2C_Buf, 10);
          break;
      case 'f':    
          FFT_Tst();
          break;
      default:
          break;
    }
    goto f;

    return 0;
}


void FFT_Tst(void)
{   uint32 i;
    int32 max;
    Fft_buffer_clr();
    Sqrwave();
    Fft(FFTSIZE, FFTNUM);
    
    for (i=0;i<FFTSIZE;i++)
    {
        ximag[i]=(sqrt(xreal[i]*xreal[i]+ximag[i]*ximag[i]));
        if (ximag[i]  > max)
        {
           max = ximag[i];        
        }
    }
    
    for (i=0;i<FFTSIZE;i++)
    {
       sprintf(UART0_StrBuff,"%f\r\n",((ximag[i]/max)*63));
       UART0_SendStr (UART0_StrBuff);
    }
}


void RTC_IntInit(void)
{
    /* 打开RTC中断(使用向量中断) */
	VICIntSelect   = 0x00000000;				// 设置所有中断分配为IRQ中断
	VICVectCntl1   = 0x20 | 13;					// RTC通道分配到IRQ slot1
	VICVectAddr1   = (uint32)RTC_Int;			// 设置中断服务程序地址
	ILR 		   = 0x03;						// 清除RTC中断标志
	VICIntEnable   = 1 << 13;					// 使能RTC中断
}

void I2C_IntInit(void)
{
	/* 设置I2C中断允许 */
	VICIntSelect = 0x00000000;							// 设置所有通道为IRQ中断 		
	VICVectCntl0 = (0x20 | 0x09);						// I2C通道分配到IRQ slot0,最高优先级
	VICVectAddr0 = (uint32)IRQ_I2C;						// 设置I2C中断向量 				
	VICIntEnable = (1 << 9);							// 使能I2C中断 					
}

void DispBios (void)
{
    UART0_SendStr (INFO1);    
    UART0_SendStr (INFO2); 
    UART0_SendStr (INFO3);    
    UART0_SendStr (INFO4);     
    UART0_SendStr (INFO5);     
    UART0_SendStr (INFO6);
    UART0_SendStr (INFO7);     
    UART0_SendStr (INFO8);
    UART0_SendStr (INFO9);
}


uint8 GetCmd(void)
{   
    uint8 i, j, k;
    char temp;
    
    
    for(i = 0; i < 20; i++)               // 清除命令缓存 
    {
        control.cmd[i] = '\0';
        control.paracmd[i] = '\0';
        control.cmdnum = 0;
        control.paranum = 0;
    }
    
    
    i = 0;                                // 记录输入的字符串
    j = 0;
    do   
    {   
        UART0_StrBuff[i] =UART0_GetByte();

        if(UART0_StrBuff[i] == 0x08) 
        {
            if(i>0)
            {   
                UART0_SendByte (UART0_StrBuff[i]);
                UART0_StrBuff[i] = '\0';
                i--;
            }
        }
        else
        {   
            UART0_SendByte (UART0_StrBuff[i]);
            i++;
        }
    }
    while(UART0_StrBuff[i-1] != '\r');
    temp = i;
    
    
    j = 0;                                // 拼写检查
    for(i = 0; i<temp; i++)
    {
        if(UART0_StrBuff[i] == ' ')
        {
            j++;
        }
    }
    if(j == temp)
    {
        return(0);
    }

    
    i = 0;                                // 判断命令字符串
    j = 0;
    k = 0;                             
    do
    {   
        if(UART0_StrBuff[i] != ' ')
        {
           control.cmd[j] = UART0_StrBuff[i];
           j++;
           k = 1;
        }
        i++;
    }
    while(((UART0_StrBuff[i-1] != ' ')&&(k == 1)) & (UART0_StrBuff[i-1] != '\r'));
    control.cmd[j] = '\0';
    control.cmdnum = j;
    
    if(UART0_StrBuff[i-1] == '\r')
    {
        return(1);
    }



    j = 0;                                 // 过滤参数中的空格           
    do 
    {   
        if(UART0_StrBuff[i] != ' ')
        {
           control.paracmd[j] = UART0_StrBuff[i];
           j++;
        }
        i++;
    }
    while(UART0_StrBuff[i-1] != '\r');
    control.paracmd[j-1] = '\0';
    control.paranum = j-1;
    
    return(1);
}


void GetCmdTst (void)
{
    GetCmd();
    UART0_SendStr ("\r\n");
    sprintf(UART0_StrBuff,"cmdnum = %d\r\n",control.cmdnum);
    UART0_SendStr (UART0_StrBuff);
    sprintf(UART0_StrBuff,"paranum = %d\r\n",control.paranum);
    UART0_SendStr (UART0_StrBuff);
    
    sprintf(UART0_StrBuff,"cmd = %s\r\n",control.cmd);
    UART0_SendStr (UART0_StrBuff);
    sprintf(UART0_StrBuff,"paracmd = %s\r\n",control.paracmd);
    UART0_SendStr (UART0_StrBuff);
}




/**********************************************************************************************************
**                            End Of File
********************************************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -