程序运行图:

基于51单片机的正弦波发生器设计-LMLPHP

仿真原理图:

基于51单片机的正弦波发生器设计-LMLPHP

 部分程序:

#include <reg52.h>

//接口定义

sbit DA = P1^1;

sbit CK = P1^2;

sbit CS = P1^4;

//10bit取样,1024点正弦查表数据

unsigned int code sine_dot[1024]=

{

0x200,0x203,0x206,0x209,0x20c,0x20f,0x212,0x215,0x219,0x21c,0x21f,0x222,0x225,0x228,0x22b,0x22f,0x232,

0x235,0x238,0x23b,0x23e,0x241,0x244,0x247,0x24b,0x24e,0x251,0x254,0x257,0x25a,0x25d,0x260,0x263,0x266,0x269,0x26d,0x270,

0x273,0x276,0x279,0x27c,0x27f,0x282,0x285,0x288,0x28b,0x28e,0x291,0x294,0x297,0x29a,0x29d,0x2a0,0x2a3,0x2a6,0x2a9,0x2ac,

0x2af,0x2b2,0x2b5,0x2b8,0x2bb,0x2be,0x2c0,0x2c3,0x2c6,0x2c9,0x2cc,0x2cf,0x2d2,0x2d5,0x2d7,0x2da,0x2dd,0x2e0,0x2e3,0x2e6,

0x2e8,0x2eb,0x2ee,0x2f1,0x2f4,0x2f6,0x2f9,0x2fc,0x2fe,0x301,0x304,0x307,0x309,0x30c,0x30f,0x311,0x314,0x317,0x319,0x31c,

0x31e,0x321,0x324,0x326,0x329,0x32b,0x32e,0x330,0x333,0x335,0x338,0x33a,0x33d,0x33f,0x342,0x344,0x347,0x349,0x34b,0x34e,

0x350,0x353,0x355,0x357,0x35a,0x35c,0x35e,0x360,0x363,0x365,0x367,0x369,0x36c,0x36e,0x370,0x372,0x374,0x376,0x379,0x37b,

0x37d,0x37f,0x381,0x383,0x385,0x387,0x389,0x38b,0x38d,0x38f,0x391,0x393,0x395,0x397,0x399,0x39b,0x39c,0x39e,0x3a0,0x3a2,

0x3a4,0x3a6,0x3a7,0x3a9,0x3ab,0x3ad,0x3ae,0x3b0,0x3b2,0x3b3,0x3b5,0x3b7,0x3b8,0x3ba,0x3bb,0x3bd,0x3be,0x3c0,0x3c1,0x3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,0x3b2,0x3b0,0x3af,0x3ad,0x3ab,0x3aa,0x3a8,0x3a6,

0x3a4,0x3a2,0x3a1,0x39f,0x39d,0x39b,0x399,0x397,0x395,0x393,0x392,0x390,0x38e,0x38c,0x38a,0x388,0x386,0x384,0x382,0x37f,

0x37d,0x37b,0x379,0x377,0x375,0x373,0x371,0x36e,0x36c,0x36a,0x368,0x366,0x363,0x361,0x35f,0x35c,0x35a,0x358,0x355,0x353,

0x351,0x34e,0x34c,0x34a,0x347,0x345,0x342,0x340,0x33d,0x33b,0x339,0x336,0x334,0x331,0x32e,0x32c,0x329,0x327,0x324,0x322,

0x31f,0x31d,0x31a,0x317,0x315,0x312,0x30f,0x30d,0x30a,0x307,0x305,0x302,0x2ff,0x2fc,0x2fa,0x2f7,0x2f4,0x2f1,0x2ef,0x2ec,

0x2e9,0x2e6,0x2e4,0x2e1,0x2de,0x2db,0x2d8,0x2d5,0x2d2,0x2d0,0x2cd,0x2ca,0x2c7,0x2c4,0x2c1,0x2be,0x2bb,0x2b8,0x2b6,0x2b3,

0x2b0,0x2ad,0x2aa,0x2a7,0x2a4,0x2a1,0x29e,0x29b,0x298,0x295,0x292,0x28f,0x28c,0x289,0x286,0x283,0x280,0x27d,0x27a,0x277,

0x273,0x270,0x26d,0x26a,0x267,0x264,0x261,0x25e,0x25b,0x258,0x255,0x252,0x24e,0x24b,0x248,0x245,0x242,0x23f,0x23c,0x239,

0x236,0x232,0x22f,0x22c,0x229,0x226,0x223,0x220,0x21d,0x219,0x216,0x213,0x210,0x20d,0x20a,0x207,0x203,0x200,0x1fd,0x1fa,

0x1f7,0x1f4,0x1f1,0x1ed,0x1ea,0x1e7,0x1e4,0x1e1,0x1de,0x1db,0x1d8,0x1d4,0x1d1,0x1ce,0x1cb,0x1c8,0x1c5,0x1c2,0x1bf,0x1bb,

0x1b8,0x1b5,0x1b2,0x1af,0x1ac,0x1a9,0x1a6,0x1a3,0x1a0,0x19c,0x199,0x196,0x193,0x190,0x18d,0x18a,0x187,0x184,0x181,0x17e,

0x17b,0x178,0x175,0x172,0x16f,0x16c,0x169,0x166,0x163,0x160,0x15d,0x15a,0x157,0x154,0x151,0x14e,0x14b,0x148,0x145,0x142,

0x13f,0x13c,0x13a,0x137,0x134,0x131,0x12e,0x12b,0x128,0x125,0x123,0x120,0x11d,0x11a,0x117,0x115,0x112,0x10f,0x10c,0x109,

0x107,0x104,0x101,0xff,0xfc,0xf9,0xf6,0xf4,0xf1,0xee,0xec,0xe9,0xe6,0xe4,0xe1,0xdf,0xdc,0xd9,0xd7,0xd4,0xd2,0xcf,0xcd,

0xca,0xc8,0xc5,0xc3,0xc0,0xbe,0xbb,0xb9,0xb7,0xb4,0xb2,0xaf,0xad,0xab,0xa8,0xa6,0xa4,0xa1,0x9f,0x9d,0x9b,0x98,0x96,0x94,

0x92,0x90,0x8d,0x8b,0x89,0x87,0x85,0x83,0x81,0x7f,0x7c,0x7a,0x78,0x76,0x74,0x72,0x70,0x6e,0x6d,0x6b,0x69,0x67,0x65,0x63,

0x61,0x5f,0x5e,0x5c,0x5a,0x58,0x56,0x55,0x53,0x51,0x50,0x4e,0x4c,0x4b,0x49,0x47,0x46,0x44,0x43,0x41,0x3f,0x3e,0x3c,0x3b,

0x3a,0x38,0x37,0x35,0x34,0x32,0x31,0x30,0x2e,0x2d,0x2c,0x2b,0x29,0x28,0x27,0x26,0x25,0x23,0x22,0x21,0x20,0x1f,0x1e,0x1d,

0x1c,0x1b,0x1a,0x19,0x18,0x17,0x16,0x15,0x14,0x13,0x12,0x12,0x11,0x10,0xf,0xe,0xe,0xd,0xc,0xc,0xb,0xa,0xa,0x9,0x8,0x8,0x7,

0x7,0x6,0x6,0x5,0x5,0x4,0x4,0x3,0x3,0x3,0x2,0x2,0x2,0x1,0x1,0x1,0x1,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,

0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x1,0x1,0x1,0x2,0x2,0x2,0x2,0x3,0x3,0x4,0x4,0x4,0x5,0x5,0x6,0x6,0x7,0x7,0x8,0x8,0x9,

0xa,0xa,0xb,0xc,0xc,0xd,0xe,0xf,0xf,0x10,0x11,0x12,0x13,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,

0x20,0x21,0x22,0x24,0x25,0x26,0x27,0x28,0x2a,0x2b,0x2c,0x2d,0x2f,0x30,0x31,0x33,0x34,0x36,0x37,0x38,0x3a,0x3b,0x3d,0x3e,

//数据写入

void da5615(unsigned int da)

{

  unsigned char i;

  da <<= 6;//10有效数据左对齐

  CS = 0;

  CK = 0;

  for (i=0;i<12;i++)

  {

    DA = (bit)(da & 0x8000);

    CK = 1;

   

  }

  CS = 1;

  CK = 0;

}

main()

{

         unsigned int j;

         while(1)

         {

                da5615(sine_dot[j]);

                  if(++j > 1023) j=0;          

         }

}

资料包括:

基于51单片机的正弦波发生器设计-LMLPHP

需要完整的资料可在我的资源里下载,也可以加入我的纷传圈子,里面有资源压缩包的百度网盘下载地址及提取码。

纷传点击用微信打开即可,过程有点繁琐请见谅。

12-14 10:08