2024-09-02
售卖作品
00

目录

功能
部分代码
全部代码

功能

DAC波形发生器

按键切换波形,正弦波、三角波、锯齿波、方波。

部分代码

cpp
const unsigned int zhengxian[101] = { 32767, 34824, 36874, 38907, 40916, 42893, 44830, 46719, 48553, 50325, 52027, 53654, 55198, 56653, 58015, 59276, 60434, 61481, 62416, 63233, 63931, 64505, 64954, 65276, 65470, 65534, 65470, 65276, 64954, 64505, 63931, 63233, 62416, 61481, 60434, 59276, 58015, 56653, 55198, 53654, 52027, 50325, 48553, 46719, 44830, 42893, 40916, 38907, 36874, 34824, 32767, 30710, 28660, 26627, 24618, 22641, 20704, 18815, 16981, 15209, 13507, 11880, 10336, 8881, 7519, 6258, 5100, 4053, 3118, 2301, 1603, 1029, 580, 258, 64, 0, 64, 258, 580, 1029, 1603, 2301, 3118, 4053, 5100, 6258, 7519, 8881, 10336, 11880, 13507, 15209, 16981, 18815, 20704, 22641, 24618, 26627, 28660, 30710 }; const unsigned int sanjiao[101] = { 0, 1310, 2621, 3932, 5242, 6553, 7864, 9174, 10485, 11796, 13107, 14417, 15728, 17039, 18349, 19660, 20971, 22281, 23592, 24903, 26214, 27524, 28835, 30146, 31456, 32767, 34078, 35388, 36699, 38010, 39321, 40631, 41942, 43253, 44563, 45874, 47185, 48495, 49806, 51117, 52428, 53738, 55049, 56360, 57670, 58981, 60292, 61602, 62913, 64224, 65535, 64224, 62913, 61602, 60292, 58981, 57670, 56360, 55049, 53738, 52428, 51117, 49806, 48495, 47185, 45874, 44563, 43253, 41942, 40631, 39321, 38010, 36699, 35388, 34078, 32767, 31456, 30146, 28835, 27524, 26214, 24903, 23592, 22281, 20971, 19660, 18349, 17039, 15728, 14417, 13107, 11796, 10485, 9174, 7864, 6553, 5242, 3932, 2621, 1310 }; const unsigned int juchi[101] = { 0, 655, 1310, 1966, 2621, 3276, 3932, 4587, 5242, 5898, 6553, 7208, 7864, 8519, 9174, 9830, 10485, 11140, 11796, 12451, 13107, 13762, 14417, 15073, 15728, 16383, 17039, 17694, 18349, 19005, 19660, 20315, 20971, 21626, 22281, 22937, 23592, 24247, 24903, 25558, 26214, 26869, 27524, 28180, 28835, 29490, 30146, 30801, 31456, 32112, 32767, 33422, 34078, 34733, 35388, 36044, 36699, 37354, 38010, 38665, 39321, 39976, 40631, 41287, 41942, 42597, 43253, 43908, 44563, 45219, 45874, 46529, 47185, 47840, 48495, 49151, 49806, 50461, 51117, 51772, 52428, 53083, 53738, 54394, 55049, 55704, 56360, 57015, 57670, 58326, 58981, 59636, 60292, 60947, 61602, 62258, 62913, 63568, 64224, 64879 }; const unsigned int fangbo[101] = { 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT P1DIR = 0; P2DIR = 0; BCSCTL1 = CALBC1_16MHZ; /* Set DCO to16MHz */ DCOCTL = CALDCO_16MHZ; TCA6416A_Init(); /* 初始化IO扩展口 */ /* ----提示初始化成功---- */ PinOUT(0, 1); /* 指定0号管脚输出为0 */ PinOUT(1, 1); /* 指定1号管脚输出为0 */ PinOUT(2, 1); /* 指定0号管脚输出为0 */ PinOUT(3, 1); /* 指定1号管脚输出为0 */ PinOUT(4, 1); /* 指定0号管脚输出为0 */ PinOUT(5, 1); /* 指定1号管脚输出为0 */ PinOUT(6, 1); /* 指定0号管脚输出为0 */ PinOUT(7, 1); /* 指定1号管脚输出为0 */ HT1621_init(); /* 初始化lcd_128 */ LCD_Clear(); /* 定时器0 检测按键的 */ CCTL0 = CCIE; TACCR0 = 3276 / 5; /* 20MS */ TACTL = TASSEL_1 + MC_1; /* 定时器0 检测按键的 */ // TA1CCTL0 = CCIE; // TA1CCR0 = 32 * 5; /* 1 ms */ // TA1CTL = TASSEL_1 + MC_1; //up to CCR0 DAC8411_Init(); /* 蜂鸣器AGC */ _EINT(); while (1) { PinIN(); I2C_IODect(); /*按键检测处理 */ //TACTL = TASSEL_1 + MC_1 + TACLR; /* 打开定时器 */ //LPM0; jishu++; if (jishu == 100) { jishu = 0; } //which 决定了是什么波形 if (which == 0) { write2DAC8411(zhengxian[jishu]); } else if (which == 1) { write2DAC8411(sanjiao[jishu]); } else if (which == 2) { write2DAC8411(juchi[jishu]); } else if (which == 3) { write2DAC8411(fangbo[jishu]); } } } /* Timer A0 interrupt service routine */ #pragma vector=TIMER0_A0_VECTOR __interrupt void Timer_A(void) { //TACTL = TASSEL_1 + MC_0 + TACLR; /* 停下时钟 */ //LPM0_EXIT; } /* Timer A0 interrupt service routine */ #pragma vector=TIMER1_A0_VECTOR __interrupt void Timer1_A(void) { }

全部代码

cpp
https://docs.qq.com/sheet/DUEdqZ2lmbmR6UVdU?tab=BB08J2
如果对你有用的话,可以打赏哦
打赏
ali pay
wechat pay

本文作者:Dong

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC。本作品采用《知识共享署名-非商业性使用 4.0 国际许可协议》进行许可。您可以在非商业用途下自由转载和修改,但必须注明出处并提供原作者链接。 许可协议。转载请注明出处!