int main(void)
{
u8 t=0;
int i = 0;
Init();
while(1)
{
t=KEY_Scan(0); //µÃµ½¼üÖµ
switch(t)
{
case KEY0_PRES:
depending = (depending + 1) % 7;
LCD_ShowxNum(80,00,depending,1,16,0);
break;
case KEY1_PRES:
if(depending == 0) {
pwm_hz += 100;
tim1 = 72000000 / pwm_hz;
Init();
}
if(depending == 1) {
pwm_hz += 10;
tim1 = 72000000 / pwm_hz;
Init();
}
if(depending == 2) {
pwm_hz += 1;
tim1 = 72000000 / pwm_hz;
Init();
}
if(depending == 3) {
k += 100;
tim2 = 1000000 / k;
TIM2_Config(tim2, 0);
}
if(depending == 4) {
k += 10;
tim2 = 1000000 / k;
TIM2_Config(tim2, 0);
}
if(depending == 5) {
k += 1;
tim2 = 1000000 / k;
TIM2_Config(tim2, 0);
}
if(depending == 6) {
Dac3_Init();
MYDMA1_Config( (u32) & (DAC->DHR12R1), (u32)WAVE72, 72);
TIM1_PWM_Init(tim1,0);
TIM_SetCompare1(TIM1,(tim1 + 1) / 2);
TIM2_Config(tim2, 0);
LCD_ShowString(0,40,200,16,16," Triangle ");
}
LCD_ShowxNum(120,20,pwm_hz,5,16,0);
LCD_ShowxNum(120,40,k,5,16,0);
break;
case WKUP_PRES:
if(depending == 0) {
pwm_hz -= 100;
tim1 = 72000000 / pwm_hz;
Init();
}
if(depending == 1) {
pwm_hz -= 10;
tim1 = 72000000 / pwm_hz;
Init();
}
if(depending == 2) {
pwm_hz -= 1;
tim1 = 72000000 / pwm_hz;
Init();
}
if(depending == 3) {
k -= 100;
tim2 = 1000000 / k;
TIM2_Config(tim2, 0);
}
if(depending == 4) {
k -= 10;
tim2 = 1000000 / k;
TIM2_Config(tim2, 0);
}
if(depending == 5) {
k -= 1;
tim2 = 1000000 / k;
TIM2_Config(tim2, 0);
}
if(depending == 6) {
Dac3_Init();
MYDMA1_Config( (u32) & (DAC->DHR12R1), (u32)SIN72, 72);
TIM1_PWM_Init(tim1,0);
TIM_SetCompare1(TIM1,(tim1 + 1) / 2);
TIM2_Config(tim2, 0);
LCD_ShowString(0,40,200,16,16," SIN ");
}
LCD_ShowxNum(120,20,pwm_hz,5,16,0);
LCD_ShowxNum(120,40,k,5,16,0);
break;
default:
delay_ms(10);
}
}
}
void Init(void)
{
uart_init(9600);
delay_init();
KEY_Init();
LCD_Init();
POINT_COLOR=BLUE;//ÉèÖÃ×ÖÌåΪÀ¶É«
Dac3_Init();
MYDMA1_Config( (u32) & (DAC->DHR12R1), (u32)SIN72, 72);
TIM1_PWM_Init(tim1,0);
TIM_SetCompare1(TIM1,(tim1 + 1) / 2);
TIM2_Config(tim2, 0);
LCD_ShowString(0,0,200,16,16,"PENDING: ");
LCD_ShowString(0,20,200,16,16,"WAVE: Square ");
LCD_ShowString(200,20,200,16,16,"Hz");
LCD_ShowString(200,40,200,16,16,"Hz");
LCD_ShowxNum(80,00,depending,1,16,0);
LCD_ShowString(0,40,200,16,16," SIN ");
}