#include "led.h"
#include "delay.h"
#include "sys.h"
#include "pwm.h"
#include "timer.h"
#include "dac.h"
const u16 sindata[1024]={
450,452,454,456,459,461,463,465,467,469,471,474,476,478,480,482,484,486,488,
491,493,495,497,499,501,503,505,508,510,512,514,516,518,520,522,524,526,529,531,
533,535,537,539,541,543,545,547,549,551,553,555,557,559,562,564,566,568,570,572,
574,576,578,580,582,584,586,588,589,591,593,595,597,599,601,603,605,607,609,611,
613,615,616,618,620,622,624,626,628,629,631,633,635,637,639,640,642,644,646,647,
649,651,653,654,656,658,660,661,663,665,666,668,670,671,673,675,676,678,680,681,
683,684,686,688,689,691,692,694,695,697,698,700,701,703,704,706,707,709,710,711,
713,714,716,717,718,720,721,722,724,725,726,728,729,730,732,733,734,735,737,738,
739,740,741,743,744,745,746,747,748,749,750,752,753,754,755,756,757,758,759,760,
761,762,763,764,765,765,766,767,768,769,770,771,772,772,773,774,775,776,776,777,
778,779,779,780,781,781,782,783,783,784,785,785,786,786,787,787,788,789,789,790,
790,791,791,791,792,792,793,793,793,794,794,795,795,795,796,796,796,796,797,797,
797,797,798,798,798,798,798,798,798,799,799,799,799,799,799,799,799,799,799,799,
799,799,799,799,799,799,798,798,798,798,798,798,798,797,797,797,797,796,796,796,
796,795,795,795,794,794,793,793,793,792,792,791,791,791,790,790,789,789,788,787,
787,786,786,785,785,784,783,783,782,781,781,780,779,779,778,777,776,776,775,774,
773,772,772,771,770,769,768,767,766,765,765,764,763,762,761,760,759,758,757,756,
755,754,753,752,750,749,748,747,746,745,744,743,741,740,739,738,737,735,734,733,
732,730,729,728,726,725,724,722,721,720,718,717,716,714,713,711,710,709,707,706,
704,703,701,700,698,697,695,694,692,691,689,688,686,684,683,681,680,678,676,675,
673,671,670,668,666,665,663,661,660,658,656,654,653,651,649,647,646,644,642,640,
639,637,635,633,631,629,628,626,624,622,620,618,616,615,613,611,609,607,605,603,
601,599,597,595,593,591,589,588,586,584,582,580,578,576,574,572,570,568,566,564,
562,559,557,555,553,551,549,547,545,543,541,539,537,535,533,531,529,526,524,522,
520,518,516,514,512,510,508,505,503,501,499,497,495,493,491,488,486,484,482,480,
478,476,474,471,469,467,465,463,461,459,456,454,452,450,448,446,444,441,439,437,
435,433,431,429,426,424,422,420,418,416,414,412,409,407,405,403,401,399,397,395,
392,390,388,386,384,382,380,378,376,374,371,369,367,365,363,361,359,357,355,353,
351,349,347,345,343,341,338,336,334,332,330,328,326,324,322,320,318,316,314,312,
311,309,307,305,303,301,299,297,295,293,291,289,287,285,284,282,280,278,276,274,
272,271,269,267,265,263,261,260,258,256,254,253,251,249,247,246,244,242,240,239,
237,235,234,232,230,229,227,225,224,222,220,219,217,216,214,212,211,209,208,206,
205,203,202,200,199,197,196,194,193,191,190,189,187,186,184,183,182,180,179,178,
176,175,174,172,171,170,168,167,166,165,163,162,161,160,159,157,156,155,154,153,
152,151,150,148,147,146,145,144,143,142,141,140,139,138,137,136,135,135,134,133,
132,131,130,129,128,128,127,126,125,124,124,123,122,121,121,120,119,119,118,117,
117,116,115,115,114,114,113,113,112,111,111,110,110,109,109,109,108,108,107,107,
107,106,106,105,105,105,104,104,104,104,103,103,103,103,102,102,102,102,102,102,
102,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,101,102,102,
102,102,102,102,102,103,103,103,103,104,104,104,104,105,105,105,106,106,107,107,
107,108,108,109,109,109,110,110,111,111,112,113,113,114,114,115,115,116,117,117,
118,119,119,120,121,121,122,123,124,124,125,126,127,128,128,129,130,131,132,133,
134,135,135,136,137,138,139,140,141,142,143,144,145,146,147,148,150,151,152,153,
154,155,156,157,159,160,161,162,163,165,166,167,168,170,171,172,174,175,176,178,
179,180,182,183,184,186,187,189,190,191,193,194,196,197,199,200,202,203,205,206,
208,209,211,212,214,216,217,219,220,222,224,225,227,229,230,232,234,235,237,239,
240,242,244,246,247,249,251,253,254,256,258,260,261,263,265,267,269,271,272,274,
276,278,280,282,284,285,287,289,291,293,295,297,299,301,303,305,307,309,311,312,
314,316,318,320,322,324,326,328,330,332,334,336,338,341,343,345,347,349,351,353,
355,357,359,361,363,365,367,369,371,374,376,378,380,382,384,386,388,390,392,395,
397,399,401,403,405,407,409,412,414,416,418,420,422,424,426,429,431,433,435,437,
439,441,444,446,448};
extern u16 add_1_n;;
int main(void)
{
//u16 led0pwmval=0;
//u8 dir=1;
delay_init(); //延时函数初始化
LED_Init(); //初始化与LED连接的硬件接口
Dac1_Init();
Dac2_Init();
TIM1_PWM_Init(899,39);//PWM频率=72000/(899+1)=80Khz //2k
TIM2_Int_Init(99,71);//1Mhz的计数频率,计数到100为10k
//TIM3_Int_Init(899,39);//2K hz
while(1)
{
// delay_ms(10);
// if(dir)led0pwmval++;
// else led0pwmval--;
// if(led0pwmval>300)dir=0;
// if(led0pwmval==0)dir=1;
TIM_SetCompare1(TIM1,sindata[add_1_n]);
if(add_1_n+341>1023)
{
TIM_SetCompare2(TIM1,sindata[add_1_n+341-1023]);
}
else
TIM_SetCompare2(TIM1,sindata[add_1_n+341]);
if(add_1_n+341+341>1023)
{
TIM_SetCompare3(TIM1,sindata[add_1_n+341+341-1023]);
}
else
TIM_SetCompare3(TIM1,sindata[add_1_n+341+341]);
}
}