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

📄 arm2131_led.c

📁 arm的spi功能
💻 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:			Chenmingji
** Created date:		2004-09-16
** Version:				1.0
** Descriptions:		The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/
#include "config.h"

#define  UART_BPS   115200  // LED1 使用 P0.29  
//#define  HC595_CS   (1<<29)  // LED1 使用 P0.29  
//#define  LED1   (1<<18)  // LED1 使用 P1.18  
//#define  KEY1   (1<<16)  // KEY  使用 P0.16

//************************************************************************************
//函数名称:MSPI_Init()
//函数功能:初始化SPI主机,设置为主机
//入口参数:无
//出口参数:无
//------------------------------------------------------------------------------------
void UART0_Init(void)
{
    uint16 Fdiv;
    
    U0LCR   = 0x83;
    Fdiv    = ( Fpclk / 16) / UART_BPS;
    U0DLM   = Fdiv / 256;
    U0DLL   = Fdiv % 256;
    U0LCR   = 0x03;

}

//************************************************************************************
//函数名称:UART0_GetByte()
//函数功能:初始化SPI主机,设置为主机
//入口参数:无
//出口参数:无
//------------------------------------------------------------------------------------
uint8 UART0_GetByte( void )
{
    uint8 rcv_dat;
    
    while(( U0LSR & 0x01) == 0);
    
    rcv_dat  = U0RBR;
    return( rcv_dat );

}

//************************************************************************************
//函数名称:UART0_GetByte()
//函数功能:初始化SPI主机,设置为主机
//入口参数:无
//出口参数:无
//------------------------------------------------------------------------------------
void UART0_GetStr( uint8 *s,uint32 n )
{
    for( ; n > 0; n--)
    {
       *s++ = UART0_GetByte();
    }

}

//************************************************************************************
//函数名称:UART0_GetByte()
//函数功能:初始化SPI主机,设置为主机
//入口参数:无
//出口参数:无
//------------------------------------------------------------------------------------
void UART0_SendByte( uint8 dat )
{
    U0THR = dat;
    
    while(( U0LSR & 0x40) == 0);
    
}

//************************************************************************************
//函数名称:UART0_GetByte()
//函数功能:初始化SPI主机,设置为主机
//入口参数:无
//出口参数:无
//------------------------------------------------------------------------------------
void UART0_SendStr( uint8 const *str )
{
    
    while( 1 )
    {
       if( *str == '\0')
       break;
       
       UART0_SendByte( *str++ );
    }
    
}


//************************************************************************************
//函数名称:DelayNS()
//函数功能:软件延时
//入口参数:dly 延时控制值
//出口参数:无
//------------------------------------------------------------------------------------
void DelayNS(uint32 dly)
{
    uint32 i;
    
    for(; dly > 0; dly--)
    {
        for(i = 0; i < 50000; i++);
    }
}

//************************************************************************************
//函数名称:main()
//函数功能:初始化GPIO,然后等待KEY1;有按键按下则LED1闪烁;
//入口参数:dly 延时控制值
//出口参数:无
//------------------------------------------------------------------------------------
//uint8 rcv_data;

int main (void)
{// add user source code 
    
    uint8 snd[32];
    
    PINSEL0 = 0x00000005;
    //PINSEL1 = 0x00000000;
    
    UART0_Init();


    UART0_GetStr( snd,18 );
    DelayNS( 40 );
    UART0_SendStr(snd);
    DelayNS( 10 );
   
    while( 1 );
    return 0;
}
//试验结果:数码管按照要求正常闪亮,停顿时间大约1/3s
/********************************************************************************************************
**                            End Of File
********************************************************************************************************/

⌨️ 快捷键说明

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