分享 MSP430按键控制输出正弦三角方波12864显示类型频率 程序
[复制链接]
#include
#include "12864.c"
#define keyin (P1IN&0X0F)
uchar key1=0,key2=0,key3=0;
uchar i=0,flag,key_val;
unsigned long int f=100,step;
const uint sin_table[128]={
2048,2093,2138,2183,2227,2272,2315,2358,2400,2441,2482,2521,2559,2596,2632,
2666,2699,2730,2759,2787,2813,2837,2859,2880,2898,2914,2928,2940,2950,2958,
2964,2967,2968,2967,2964,2958,2950,2940,2928,2914,2898,2880,2859,2837,2813,
2787,2759,2730,2699,2666,2632,2596,2559,2521,2482,2441,2400,2358,2315,2272,
2227,2183,2138,2093,2048,2003,1958,1913,1869,1824,1781,1738,1696,1655,1614,
1575,1537,1500,1464,1430,1397,1366,1337,1309,1283,1259,1237,1216,1198,1182,
1168,1156,1146,1138,1132,1129,1128,1129,1132,1138,1146,1156,1168,1182,1198,
1216,1237,1259,1283,1309,1337,1366,1397,1430,1464,1500,1537,1575,1614,1655,
1696,1738,1781,1824,1869,1913,1958,2003};
const uint tiar_table[128]={
1128,1157,1185,1214,1243,1272,1300,1329,1358,1387,1415,1444,1473,1502,1530,
1559,1588,1617,1645,1674,1703,1732,1760,1789,1818,1847,1876,1904,1933,1962,
1990,2019,2048,2077,2106,2134,2163,2192,2221,2249,2278,2307,2336,2364,2393,
2422,2451,2479,2508,2537,2566,2594,2623,2652,2681,2709,2738,2767,2796,2824,
2853,2882,2911,2939,2968,2939,2911,2882,2853,2824,2796,2767,2738,2709,2681,
2652,2623,2594,2566,2537,2508,2479,2451,2422,2393,2364,2336,2307,2278,2249,
2221,2192,2163,2134,2105,2077,2048,2019,1990,1962,1933,1904,1875,1847,1818,
1789,1760,1732,1703,1674,1645,1617,1588,1559,1530,1502,1473,1444,1415,1387,
1358,1329,1300,1272,1243,1214,1185,1157};
uchar *s1="类型: 请选择类型";
uchar *s2="频步: 请选择频步";
uchar *s3="频率: 请选择频率";
void keyscan();
void Clk_init();
void timeB_init();
void DA_init();
void key_init();
void write_add(uchar add,unsigned long int dat);
void main( void )
{
WDTCTL = WDTPW + WDTHOLD;
key_init();
Clk_init();
DA_init();
timeB_init();
LCD12864_init();
write_str(0x80,s1);
write_str(0x90,s2);
write_str(0x88,s3);
while(1)
{
keyscan();
}
}
void Clk_init()
{
BCSCTL1 &= ~XT2OFF;
do
{
IFG1 &= ~OFIFG;
for (i = 0xFF; i > 0; i--);
}
while ((IFG1 & OFIFG));
BCSCTL2 |= SELM_2+SELS;
}
void DA_init()
{
DAC12_0CTL|=DAC12CALON;
while((DAC12_0CTL & DAC12CALON)!=0) _NOP();
ADC12CTL0 = REF2_5V + REFON;
DAC12_0CTL = DAC12IR + DAC12AMP_5 + DAC12ENC ;
DAC12_0DAT = 0x00;
}
void timeB_init()
{
TBCTL=TBSSEL_2+MC_1+TBCLR;
TBCCR0=62500/f;
_EINT();
}
void key_init()
{
P1DIR=0;
P1IE = 0x0f;
P1IES = 0x0f;
}
|