找回密码
 注册会员
搜索附件  
MCU资讯论坛 附件中心 单片机论坛 51单片机论坛 3375316251RS232.rar

3375316251RS232.rar

 

51单片机串口通讯proteus 仿真,适合proteus+51初学者:
proteus 仿真51单片机串口通讯,适合proteus+51初学者,也适合工程设计中调试串口通讯用
  1. #include <reg8253.h>

  2. #define uint unsigned int
  3. #define uchar unsigned char

  4. uchar table[14]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,
  5. 0x20,0x63,0x07,0x23}; //阴极7SEG

  6. uchar send=0x00;

  7. void rs232Ini(void)
  8. {
  9. TMOD=0x20;
  10. TH1=0xfd; //9600
  11. TL1=0xfd;
  12. PCON=0x00;
  13. SCON=0x50;//方式1
  14. EA=1;
  15. ES=1;
  16. TR1=1;
  17. }

  18. void ex_int(void)
  19. {
  20. EA=1;
  21. IE0=0;
  22. EX0=1;
  23. }

  24. void delay(unsigned char n)
  25. {
  26. uchar i,j,k;
  27. for(i=0;i<=n;i++)
  28. {
  29. for(j=0;j<100;j++)
  30. for(k=0;k<=250;k++);
  31. }
  32. }

  33. void main(void)
  34. {
  35. delay(1);
  36. rs232Ini();
  37. ex_int();
  38. P3_3=0;//led
  39. while(1)
  40. {
  41. }
  42. }

  43. void ex_button() interrupt 0 using 2
  44. {// send=5;
  45. SBUF=send;
  46. while(!TI);
  47. TI=0;
  48. P1_0=!P1_0;
  49. send++;
  50. IE0=0;
  51. if(send>10) send=0;
  52. delay(1);
  53. P3_7=!P3_7;//Led
  54. }

  55. void serial_Read(void) interrupt 4 using 3
  56. {
  57. uint iBuf;
  58. uchar cBuf;
  59. if(RI==1)
  60. {
  61. P2=1;
  62. iBuf=SBUF;
  63. cBuf=iBuf;
  64. P0=table[cBuf];
  65. RI=0;
  66. }
  67. }
复制代码

感谢分享
支持一个
感谢楼主
回复 1# admin


    感谢分享
支持一个
感谢楼主

8/

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-11-23 10:50 , Processed in 0.041195 second(s), 8 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

返回顶部