|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2008-4-11 11:37:59
|
显示全部楼层
#include <delay.h>
#include <mega8.h>
unsigned char temp=0xe1;
#define key_up PIND.2
#define key_down PIND.3
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
delay_ms(20);
if(!key_up)
{
//while(key_up) ;
//OCR2 = --temp;
++temp;
if(temp <= 0xf1) TCNT0 = temp;
else
{
temp = 0xf1;
TCNT0 = temp;
}
}
}
// External Interrupt 1 service routine
interrupt [EXT_INT1] void ext_int1_isr(void)
{
delay_ms(20);
if(!key_down)
{
//while(key_down) ;
//OCR2 = ++temp;
--temp;
if(temp >= 0xdf) TCNT0 = temp;
else
{
temp = 0x1f;
TCNT0 = temp;
}
}
}
// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
TCNT0 = temp;
PORTB.3 = ~PORTB.3;
}
// Declare your global variables here
void main(void)
{
// Declare your local variables here
// Input/Output Ports initialization
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=Out Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=0 State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x08;
// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x03;
TCNT0=temp;
// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Falling Edge
// INT1: On
// INT1 Mode: Falling Edge
GICR|=0xC0;
MCUCR=0x0A;
GIFR=0xC0;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x01;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// Global enable interrupts
#asm("sei")
while (1)
{
// Place your code here
};
}
我改成上面这个程序也是,从PB3输出的有直流和交流两种成分,交流脉冲的频率是我想要的,可是是+-2.5V, 直流也是脉冲,可是频率不知道多少? |
|