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

📄 tlc2543.c

📁 TLC2543实时时钟芯片的读取程序
💻 C
字号:
/****************************************Copyright (c)**************************************************
**                               
**                               JiangXing Auto
**                               
**
**--------------File Info-------------------------------------------------------------------------------
** File name:           TLC2543.c
** Last modified Date:  
** Last Version:        
** Descriptions:        
**
**------------------------------------------------------------------------------------------------------
** Created by:          
** Created date:        
** Version:             
** Descriptions:        
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/

#include <includes.h>

#define OUT     1
#define IN      0

#define PORT_2543_EOC    (1 << 2)
#define PORT_2543_SCK    (1 << 3)
#define PORT_2543_IN     (1 << 4)
#define PORT_2543_OUT    (1 << 5)
#define PORT_2543_CS     (1 << 6)

#define BIT_2543_EOC    PINE_Bit2
#define BIT_2543_SCK    PORTE_Bit3
#define BIT_2543_IN     PORTE_Bit4
#define BIT_2543_OUT    PINE_Bit5
#define BIT_2543_CS     PORTE_Bit6

static INT8U  PreviousChannel;

/********************************************************************************
* 函数名称: Init2543
* 功    能: 2543ADC端口初始化
* 入口参数: 


* 出口参数: 
* 调用模块: 
*
* 全局变量: 
*           
*--------------------------------------------------------------------------------
* 设计者:   
* 日    期: 
* 说    明: 
********************************************************************************/
void Init_2543( void )
{
    PORTE |= PORT_2543_SCK | PORT_2543_IN | PORT_2543_CS;
    DDRE |= PORT_2543_SCK | PORT_2543_IN | PORT_2543_CS; 
}

/********************************************************************************
* 函数名称: Get_2543_Data
* 功    能: 
* 入口参数: 


* 出口参数: 
* 调用模块: 
*
* 全局变量: 
*           
*--------------------------------------------------------------------------------
* 设计者:   
* 日    期: 
* 说    明: 
********************************************************************************/
INT16U  Get_2543_AD(INT8U channel, INT8U *PrevChl)
{
#if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
    OS_CPU_SR  cpu_sr = 0;
#endif
    
    INT8U   i;
    INT16U  Receive;
    
    if ( PrevChl )
        *PrevChl = PreviousChannel;
    
    PreviousChannel = channel;
    
    OS_ENTER_CRITICAL();
    
    channel <<= 4;
    Receive = 0;
    
    /*wait for convert complete*/
    while(!BIT_2543_EOC);
    
    BIT_2543_SCK = 0;
    _NOP();
    _NOP();
    /**/
    BIT_2543_CS = 1;
    _NOP();
    _NOP();
    BIT_2543_CS = 0;
    _NOP();
    _NOP();
    _NOP();
    _NOP();
    _NOP();
    _NOP();
    
    for(i=0; i<12; i++) {
        /*  */
        if( BIT_2543_OUT )
            Receive |= 0x0001;
        else
            Receive &= 0xFFFE;
        Receive <<= 1;
        
        if(channel & 0x80)
            BIT_2543_IN = 1;
        else
            BIT_2543_IN = 0;
        channel <<= 1;
       
        BIT_2543_SCK = 1;
        _NOP();
        _NOP();
        _NOP();
        
        BIT_2543_SCK = 0;
        _NOP();
        _NOP();
        _NOP();
    }
    /**/
    BIT_2543_CS = 1;

    Receive >>= 1;
    
    OS_EXIT_CRITICAL();
    
    return Receive;
}

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

⌨️ 快捷键说明

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