找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4389|回复: 13
打印 上一主题 下一主题
收起左侧

使用0832产生正弦波求指导

[复制链接]
跳转到指定楼层
楼主
只能输出方波,可以调频率,但是按键三没有反应无法输出正弦波和三角波,求指点怎么才能正确输出

  1. #include "reg51.h"
  2. #define uchar unsigned char
  3. #define uint unsigned int
  4. #define key P1
  5. #define dataout P0
  6. /**********
  7. 正弦波数据表
  8. *************/
  9. uchar code sin_tab[256]=
  10. {0x80,0x83,0x85,0x88,0x8A,0x8D,0x8F,0x92,
  11. 0x94,0x97,0x99,0x9B,0x9E,0xA0,0xA3,0xA5,
  12. 0xA7,0xAA,0xAC,0xAE,0xB1,0xB3,0xB5,0xB7,
  13. 0xB9,0xBB,0xBD,0xBF,0xC1,0xC3,0xC5,0xC7,
  14. 0xC9,0xCB,0xCC,0xCE,0xD0,0xD1,0xD3,0xD4,
  15. 0xD6,0xD7,0xD8,0xDA,0xDB,0xDC,0xDD,0xDE,
  16. 0xDF,0xE0,0xE1,0xE2,0xE3,0xE3,0xE4,0xE4,
  17. 0xE5,0xE5,0xE6,0xE6,0xE7,0xE7,0xE7,0xE7,
  18. 0xE7,0xE7,0xE7,0xE7,0xE6,0xE6,0xE5,0xE5,
  19. 0xE4,0xE4,0xE3,0xE3,0xE2,0xE1,0xE0,0xDF,
  20. 0xDE,0xDD,0xDC,0xDB,0xDA,0xD8,0xD7,0xD6,
  21. 0xD4,0xD3,0xD1,0xD0,0xCE,0xCC,0xCB,0xC9,
  22. 0xC7,0xC5,0xC3,0xC1,0xBF,0xBD,0xBB,0xB9,
  23. 0xB7,0xB5,0xB3,0xB1,0xAE,0xAC,0xAA,0xA7,
  24. 0xA5,0xA3,0xA0,0x9E,0x9B,0x99,0x97,0x94,
  25. 0x92,0x8F,0x8D,0x8A,0x88,0x85,0x83,0x80,
  26. 0x7D,0x7B,0x78,0x76,0x73,0x71,0x6E,0x6C,
  27. 0x69,0x67,0x65,0x62,0x60,0x5D,0x5B,0x59,
  28. 0x56,0x54,0x52,0x4F,0x4D,0x4B,0x49,0x47,
  29. 0x45,0x43,0x41,0x3F,0x3D,0x3B,0x39,0x37,
  30. 0x35,0x34,0x32,0x30,0x2F,0X2D,0x2C,0X2A,
  31. 0x29,0x28,0x26,0x25,0x24,0x23,0x22,0x21,
  32. 0x20,0x1F,0x1E,0x1D,0x1D,0x1C,0x1C,0x1B,
  33. 0x1B,0x1A,0x1A,0x1A,0x19,0x19,0x19,0x19,
  34. 0x19,0x19,0x19,0x19,0x1A,0x1A,0x1A,0x1B,
  35. 0x1B,0x1C,0x1C,0x1D,0x1D,0x1E,0x1F,0x20,
  36. 0x21,0x22,0x23,0x24,0x25,0x26,0x28,0x29,
  37. 0X2A,0x2C,0X2D,0x2F,0x30,0x32,0x34,0x35,
  38. 0x37,0x39,0x3B,0x3D,0x3F,0x41,0x43,0x45,
  39. 0x47,0x49,0x4B,0x4D,0x4F,0x52,0x54,0x56,
  40. 0x59,0x5B,0x5D,0x60,0x62,0x65,0x67,0x69,
  41. 0x6C,0x6E,0x71,0x73,0x76,0x78,0x7B,0x7D};
  42. /*************
  43. 三角波数据表
  44. *************************/
  45. uchar code thr_tab[256]=
  46. {
  47. 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,
  48. 0x89,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,
  49. 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,
  50. 0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F,
  51. 0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,
  52. 0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,
  53. 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,
  54. 0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF,
  55. 0xBF,0xBE,0xBD,0xBC,0xBB,0xBA,0xB9,0xB8,
  56. 0xB7,0xB6,0xB5,0xB4,0xB3,0xB2,0xB1,0xB0,
  57. 0xAF,0xAE,0xAD,0xAC,0xAB,0xAA,0xA9,0xA8,
  58. 0xA7,0xA6,0xA5,0xA4,0xA3,0xA2,0xA1,0xA0,
  59. 0x9F,0x9E,0x9D,0x9C,0x9B,0x9A,0x99,0x98,
  60. 0x97,0x96,0x95,0x94,0x93,0x92,0x91,0x90,
  61. 0x8F,0x8E,0x8D,0x8C,0x8B,0x8A,0x89,0x89,
  62. 0x87,0x86,0x85,0x84,0x83,0x82,0x81,0x80,
  63. 0x7F,0x7E,0x7D,0x7C,0x7B,0x7A,0x79,0x78,
  64. 0x77,0x76,0x75,0x74,0x73,0x72,0x71,0x70,
  65. 0x6F,0x6E,0x6D,0x6C,0x6B,0x6A,0x69,0x68,
  66. 0x66,0x66,0x65,0x64,0x63,0x62,0x61,0x60,
  67. 0x5F,0x5E,0x5D,0x5C,0x5B,0x5A,0x59,0x58,
  68. 0x55,0x55,0x55,0x54,0x53,0x52,0x51,0x50,
  69. 0x4F,0x4E,0x4D,0x4C,0x4B,0x4A,0x49,0x48,
  70. 0x44,0x44,0x45,0x44,0x43,0x42,0x41,0x40,
  71. 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,
  72. 0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
  73. 0x50,0x51,0x52,0x53,0x55,0x55,0x56,0x57,
  74. 0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
  75. 0x60,0x61,0x62,0x63,0x66,0x65,0x66,0x67,
  76. 0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
  77. 0x70,0x71,0x72,0x73,0x77,0x75,0x76,0x77,
  78. 0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F
  79. };
  80. /******************************************/
  81. uint data THHL=65535;
  82. uchar data keyword,n=0;
  83. bdata sinthr;
  84. sbit sin_thr=sinthr^0;
  85. sbit fb=P2^1;
  86. /**************
  87. 键扫描子函数
  88. **************************/
  89. keyscan()
  90. {
  91. keyword=key&0x07;
  92. if(keyword!=0x07)
  93. {
  94. while((key&0x07)!=0x07);
  95. switch(keyword)
  96. {
  97. case 6:
  98. {if(THHL>=65235)THHL=65535;else{THHL=THHL+255;}break;}
  99. case 5:
  100. {if(THHL<=500)THHL=0;else{THHL=THHL-255;}break;}
  101. case 3:
  102. {sin_thr=~sin_thr;break;}
  103. default:{break;}
  104. }
  105. }
  106. }
  107. /**********
  108. 初始化函数
  109. **************************/
  110. void clearmen()
  111. {
  112. key=0xff,dataout=0x00;THHL=65535;
  113. TH1=THHL/256;TL1=THHL&256;
  114. TMOD=0x11;ET1=1;TR1=1;EA=1;
  115. }
  116. /***********
  117. 主函数
  118. *************************/
  119. main()
  120. {
  121. clearmen();
  122. while(1)
  123. {
  124. keyscan();
  125. }
  126. }
  127. /************T1
  128. 中断函数
  129. *************************/
  130. void time_intt1(void) interrupt   3
  131. {
  132. EA=0;TR1=0;TH1=THHL/256;TL1=THHL%256;TR1=1;
  133. if(sin_thr){dataout=sin_tab[n];}
  134. else {dataout=thr_tab[n];}
  135. if(n>=255){n=0;}else{n++;}
  136. fb=~fb;
  137. EA=1;
  138. }

复制代码


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:211423 发表于 2017-6-15 23:43 | 只看该作者
有人吗
回复

使用道具 举报

板凳
ID:211423 发表于 2017-6-16 10:52 | 只看该作者
来人啊
回复

使用道具 举报

地板
ID:211423 发表于 2017-6-16 10:53 | 只看该作者
来个人啊
回复

使用道具 举报

5#
ID:211423 发表于 2017-6-16 11:21 | 只看该作者
有人吗
回复

使用道具 举报

6#
ID:123289 发表于 2017-6-16 12:01 | 只看该作者
楼主能保证你的硬件正确吗?
回复

使用道具 举报

7#
ID:123289 发表于 2017-6-16 12:03 | 只看该作者
定时从正弦数据表中取出数据送至0832就可以了。
要点:数据表中的数据必须是按正弦波形分布。
回复

使用道具 举报

8#
ID:82765 发表于 2017-6-16 12:52 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

9#
ID:211423 发表于 2017-6-16 17:18 | 只看该作者
cjjcjj1 发表于 2017-6-16 12:52
你好!你发的程序不完整吧

完整的啊
回复

使用道具 举报

10#
ID:211999 发表于 2017-6-16 23:40 | 只看该作者
付个电路图啊
回复

使用道具 举报

11#
ID:82765 发表于 2017-6-20 11:33 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

12#
ID:41376 发表于 2017-6-20 14:14 | 只看该作者
发完整程序还有硬件看看
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表