Weight_Bed/USCI1_Init.c

64 lines
1.5 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "H/Function_Init.H"
void SPI1_Init(void);
bit Uart1SendFlag = 0; //Uart1发送中断标志位
bit Uart1ReceiveFlag = 0; //Uart1接收中断标志位
bit SPI1Flag = 0; //SPI1数据传输完成标志位
bit TWI1Flag = 0; //TWI1中断标志位
/*****************************************************
*函数名称void USCI1_Test(void)
*函数功能USCI1测试
*入口参数void
*出口参数void
*****************************************************/
void USCI1_Test(void)
{
SPI1_Init();
while(1)
{
US1CON2 = 0xAA;
while(!SPI1Flag);
SPI1Flag = 0;
Delay(1000);
}
}
/*****************************************************
*函数名称void SPI1_Init(void)
*函数功能SPI1初始化
*入口参数void
*出口参数void
*****************************************************/
void SPI1_Init(void)
{
OTCON |= 0X40; //选择SPI1模式
US1CON0 = 0x3F; //设置SPI1为主设备SCK空闲时间为高电平SCK周期第二沿采集数据时钟速率为Fsys/128
US1CON1 = 0x01; //MSB优先发送8位传输允许发送中断
US1CON0 |= 0x80; //开启SPI1
IE2 |= 0x01;
EA = 1;
}
/*****************************************************
*函数名称void TWI1/PI/UART1_Int() interrupt 7
*函数功能USCI1中断函数
*入口参数void
*出口参数void
*****************************************************/
#if (USCI1_Mode == SPI1)
void Spi1_Int(void) interrupt 15 //SPI1中断函数
{
if(US1CON1&0X08) //发送缓存器空标志判断
{
US1CON1 &= ~0X08;
}
if(US1CON1&0X80) //数据传输标志位判断
{
US1CON1 &= ~0X80;
SPI1Flag = 1;
}
}
#endif