登录站点

用户名

密码

XS128串口收发程序

3已有 2539 次阅读  2010-01-07 18:06   标签收发  程序 
#include <hidef.h>      /* common defines and macros */
#include "derivative.h"      /* derivative-specific definitions */
uchar data[] = "flyreally";
uchar result = 0;
/*串口初始化*/
void SCI_Init(void)
{
    SCI0BD = 52;          //波特率9600bps
    SCI0CR1 = 0;          //正常8位模式,无奇偶效验
    SCI0CR2 = 0x2C;       //接收中断允许
}
/*串口发送函数*/
void SCI_TXD(uchar data)
{
    byte tmp;
   
    while (!(SCI0SR1 & 0x80));       //等待清空缓冲区
    SCI0DRH = 0x00;                 //发送一个字节,高位置零
    SCI0DRL = data;                 //发送数据
   
    tmp = SCI0SR1;                  //清除标志
}
/*串口接收函数*/
char SCI_RXD(void)
{
    uchar ch;
    
    while (!(SCI0SR1 & 0x20));       //等待接收数据完毕
   
    SCI0SR1_RDRF = 1;
   
    ch = SCI0DRL;
   
    return ch;
}
/*接收触发中断*/
interrupt 20 void SCI0_ISR(void)
{
    byte tmp;
    DisableInterrupts;
    tmp = SCI0SR1;                   //清除标志
   
    result = SCI_RXD();
    SCI_TXD(result);
    EnableInterrupts;
}
void main(void)
{   
    DisableInterrupts;
    SCI_Init();
    EnableInterrupts;
   
    DDRB = 0xFF;
    PORTB = 0x00;
    while (1);
}

上一篇: 4*4矩阵键盘驱动程序 下一篇: flyreally原创--U盘隐藏文件恢复程序+源码

分享 举报

发表评论 评论 (2 个评论)

涂鸦板