Weight_Bed/USCI0_Init.c

58 lines
1.3 KiB
C
Raw Permalink 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"
#define USCI0_Mode SPI0
void Uart0_Init(uint Freq,unsigned long int baud);
void TWI0_Init(void);
void SPI0_Init(void);
bit Uart0SendFlag = 0; //Uart0发送中断标志位
bit Uart0ReceiveFlag = 0; //Uart0接收中断标志位
bit SPI0Flag = 0; //SPI0数据传输完成标志位
bit TWI0Flag = 0; //TWI0中断标志位
/*****************************************************
*函数名称void USCI0_Test(void)
*函数功能USCI0测试
*入口参数void
*出口参数void
*****************************************************/
void USCI0_Test(void)
{
SPI0_Init();
while(1)
{
US0CON2 = 0xAA;
while(!SPI0Flag);
SPI0Flag = 0;
Delay(1000);
}
}
/*****************************************************
*函数名称void SPI0_Init(void)
*函数功能SPI0初始化
*入口参数void
*出口参数void
*****************************************************/
void SPI0_Init(void)
{
OTCON |= 0X10; //选择SPI0模式
US0CON0 = 0x3F; //设置SPI0为主设备SCK空闲时间为高电平SCK周期第二沿采集数据时钟速率为Fsys/128
US0CON1 = 0x01; //MSB优先发送8位传输允许发送中断
US0CON0 |= 0x80; //开启SPI0
IE1 |= 0x01;
EA = 1;
}
void Spi0_Int(void) interrupt 7 //SPI0中断函数
{
if(US0CON1&0X08) //发送缓存器空标志判断
{
US0CON1 &= ~0X08;
}
if(US0CON1&0X80) //数据传输标志位判断
{
US0CON1 &= ~0X80;
SPI0Flag = 1;
}
}