串口通信

技术分类: 嵌入式系统  | 2007-07-30
作者:lianghongzhi2005

引自EDN博客:lianghongzhi2005

功能:使用串口调试软件,可以在电脑上显示“tongxin sucess",但程序不是很规范,希望高手指点。

//desisned by lianghongzhi
//2007.7.29
#include"reg52.h"
#include"stdio.h"
#include"absacc.h"
#include
void  init_com(void)
{
      SCON="0x50";              //串行方式1,
      TMOD="0x20";               //定时器工作于方式2  
  &

nbsp;   PCON="0X80";              //波特率4800
      ES="1";                     //开串行口中断
      TH1=0xF3;
      TL1=0xF3;
      TR1=1;                    //启动定时器1
      EA="1";      //开cpu中断
}
 void delay(void)                       //10ms延时
{
       int i,j;
   for(i=38;i>0;i--)
         for(j=130;j>0;j--);
}
void serial()interrupt 4 using 3
{
 unsigned char ch;
 if(RI)
 {
  RI=0;
  ch=SBUF;
  TI=1;
       switch(ch)
  {
   case 0x01:
   printf("A");TI=0;
   break;
   case 0x02:
   printf("B");TI=0;
   break;
   default:
   printf(" #tongxin sucess");
   TI=0;
   break;
  }
    }
}       
void main ()
{
 init_co
1】【2
加载中

对文章的评论

剩余字数:  

浏览该文章的用户还看过...

  • 文 章

  • 论 坛

  • 博 客

  • 小 组

设计资源与分销