背景图片
86D20 模拟串口源码 - 啊和的博客

86D20 模拟串口源码 - 啊和的博客 86D20 模拟串口源码 - 啊和的博客

86D20 模拟串口源码

2400波特率 发送接收测试都OK ,占用一个定时器

  1. void timer_init()//定时器初始化
  2. {
  3. _ctm0c0 = 0b00000000; //16000000/4 =4000,000
  4. _ctm0c1 = 0xc1;
  5. _ctm0al = 0xa0;
  6. _ctm0ah = 0x01;
  7. _ctma0f=0;
  8. _ctma0e=1;
  9. _ct0on = 1;
  10. _ct0pau = 0; //
  11. _emi = 1;
  12. }
  13.  
  14. void __attribute((interrupt(0x14))) ctm0(void)
  15. {
  16. _ctma0f=0;
  17. if(RX==0&&Rx_start_bit==0)
  18. {
  19. Rx_start_bit=1;
  20. RX_start_Receive=1;
  21. j=0;
  22. RI=0;
  23. }
  24.  
  25. if(RX_start_Receive==1)
  26. {
  27. i_jia++;
  28. if(i_jia>=4)
  29. {
  30. i_jia=0;
  31.  
  32. if(j<10)
  33. {
  34. Output >>=1;
  35. if(RX)
  36. {
  37. Output|=0x80; //先收低位
  38. }
  39. j++;
  40. }
  41. if(RX==1&&flah6==1){flah6=0;RX_start_Receive=0;Rx_start_bit=0;RI=1;}
  42. if(j==9){j=0;receiveByte=Output;flah6=1;}
  43.  
  44. }
  45.  
  46. }
  47.  
  48. if(moni_uart_start==1) ///发送串口数据
  49. {
  50. t++;
  51. if(t>=4)
  52. {
  53. t=0;
  54. if(t1>=8){i=0;moni_uart_start=0;TX=1;t=0;t1=0;jump_first_bit=0;}
  55. if(jump_first_bit==1)
  56. {
  57. if(i<9)//发送8位数据位
  58. {
  59. if(send_buff&0x01) //先传低位
  60. {
  61. TX=1;
  62. }
  63. else
  64. {
  65. TX=0;
  66. }
  67. i++;
  68. send_buff=send_buff>>1;
  69. }
  70. t1++;
  71. }
  72. if(send_flrst_bit==0) {i=0;send_flrst_bit=1;TX=0;jump_first_bit=1;send_buff=moni_send_dat;} //发送启始位
  73. }
  74. }
  75.  
  76. }

评论 0

挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
提交评论

清空信息
关闭评论