serial.c

来自「51单片机中」· C语言 代码 · 共 52 行

C
52
字号
//serial.c
#include <reg51.h>
#include "serial.h"

/******************************************************************************
函数:Ser_Delay()
功能:
参数:
      uchDly:延时长度
返回:
******************************************************************************/
void Ser_Delay(unsigned char uchDly)
{
        //unsigned char uchTmp;
        unsigned char i,j;
        for(i = 0;i < uchDly;i++);
}



/******************************************************************************
函数:Ser_SendByte()
功能:主机通过串行总线发送一个字节的数据
参数:
	uchValue:要发送的数据
返回:
******************************************************************************/
void Ser_SendByte(unsigned char uchValue)
{

        unsigned char i;
        for(i = 0;i < 8;i++)
        {
                   SER_SCLK = 1;
                   Ser_Delay(10);
                   if(uchValue & 0x80)
                   {
                        SER_SID = 1;
                        Ser_Delay(20);
                    }
                   else
                   {   SER_SID = 0;
                       Ser_Delay(20);
                    }
                   SER_SCLK = 0;
                   Ser_Delay(10);
                   uchValue = uchValue << 1;
        }
}


⌨️ 快捷键说明

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