?? sine_wave.c
字號:
/*****************************************************
Project :
Version :
Date : 12/1/2008
Author : HAMSA LATA
Company : RUPANAGUDI
Comments:
Chip type : ATmega8
Program type : Application
Clock frequency : 8.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 256
*****************************************************/
#include<mega8.h>
flash unsigned char pwmtab[59]={128,141,154,167,180,192,203,214,223,231,239,245,249,
252,254,254,253,251,247,242,235,227,218,209,198,186,
174,161,148,134,121,107,94,81,69,57,46,37,28,20,
13,8,4,2,1,1,3,6,10,16,24,32,41,52,63,75,88,101,114};
unsigned char index = 0;
// Timer 2 output compare interrupt service routine
interrupt [TIM2_COMP] void timer2_comp_isr(void)
{OCR2=pwmtab[index];
index++;
if(index>58) index=0;
}
//------------------------------------------------------------------------------
#define no_push 0
#define maybe_push 1
#define push 2
//------------------------------
#define t1 2
//------------------------------
#define set_alarm 1
//-----------------------------
#define set_month_date 1
#define set_hour_min 2
#define set_day 3
#define set_normal 4
//----------------------------
bit push_flag = 1;
unsigned char time1=0,set_state;
void debounce(void)
{ static char push_state,push_count;
time1 = t1;
if(~PIND.2 == 0)
{set_state = set_alarm;
}
//---------------------------------------
switch(push_state)
{case no_push:if(PIND.3 == 0)
{push_state = maybe_push;
push_count = 0;
}else{push_state = no_push;
}
break;
case maybe_push:if(PIND.3 == 0)
{if(++push_count == 5)
{push_state = push;
push_flag = 1;
}
}else{push_state = no_push;
}
break;
case push:if(PIND.3 == 0)
push_state = push;
else
push_state = no_push;
break;
}
}
//_______________________________________________________________________________
void main (void)
{
DDRB.3=1;
TCCR2=105; // fast PWM no clock prescale
OCR2=128;
TIMSK=0x80;
#asm("sei")
while(1)
{
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -