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

📄 scfirst.c

📁 psoc_usb的代码,用来小卡测试的.没事下下来
💻 C
字号:
//-----------------------------------------------------------------------------
// Contents:  main module of a simple firmware
//
// Copyright: Inventec Electronics(Tianjin) Co., Ltd.
// $Archive:  scmain.c
// $Date:     2007-12-06
// $Revision: 1.00
//
//-----------------------------------------------------------------------------
// Copyright 2006, xsh.han@itc.inventec
//-----------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#include "fx2.h"
#include "fx2regs.h"
#include "absacc.h"
#include "scmain.h"

#ifndef __USE_USB__
#include "serial.h"
#endif

//--------------------------------------------------------------
//global variable
//--------------------------------------------------------------
BYTE xdata malloc_mempool[2048];
BYTE xdata g_in_buffer[BUFF_LENGTH];
WORD xdata g_in_buffer_len = 0;
WORD xdata g_loopcount = 0;

//--------------------------------------------------------------
//extern function
//--------------------------------------------------------------
extern int  sc_main(char *cmd_buff,int size);  
extern void sc_process_blinking();

//-----------------------------------------------------------------------------
// main function init
//-----------------------------------------------------------------------------
int user_init()
{
    // set the CPU clock to 48MHz
    CPUCS = ((CPUCS & ~bmCLKSPD) | bmCLKSPD1) ;

    // set the slave FIFO interface to 48MHz
    IFCONFIG |= 0x40;

    //init malloc memory pool
    init_mempool(&malloc_mempool, sizeof(malloc_mempool));
   
    // Initialize EZ-USB I2C controller
    //EZUSB_InitI2C();    

    //initialize serial port
#ifndef __USE_USB__
    serial_init(19200,1);
#endif
       
    //delay 
    EZUSB_Delay(1);     //delay 1ms

    return 0;
}
 
//--------------------------------------------------------------
//show led
//--------------------------------------------------------------
void user_status(BYTE onoff)
{
    if (onoff) {
        IOE |= 1;
    }else{
        IOE &= (~1);
    }
    return;
}

//-----------------------------------------------------------------------------
// main function loop
//-----------------------------------------------------------------------------
int user_loop()
{
#ifndef __USE_USB__
    g_in_buffer_len = SERIAL_GET_STRING(g_in_buffer,BUFF_LENGTH);
    g_in_buffer[g_in_buffer_len] = 0;
    if (g_in_buffer_len){
        g_in_buffer_len = sc_main(g_in_buffer,g_in_buffer_len);
        if (g_in_buffer_len){
            PRINTF_COM(g_in_buffer);            
        }else{
            PRINTF_COM("<NULL>\r\n");            
        }
        
        //clear buffer length
        g_in_buffer_len = 0;
    }    
#endif

    user_status(g_loopcount&0x01);

    return 0;
}


//-----------------------------------------------------------------------------
//main function
//-----------------------------------------------------------------------------
#ifndef __USE_USB__
int main()
{
    //call user init function
    user_init();

    //out infor message
    PRINTF_COM("\r\n>>>Serial Command Interface, HELP for usage.<<<\r\n");

    //main loop
    while(1) 
	{
	    //process user loop
        if ((g_loopcount%50)==0)
		{
            user_loop();
        }
        
        if ((g_loopcount%10)==0)
		{
            sc_process_blinking();
        }
        
        //inc counter
        g_loopcount++;
        EZUSB_Delay(2);   //delay 1ms
    }
}
#endif

⌨️ 快捷键说明

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