?? qz__.c
字號:
#include <mega16.h>
unsigned int i=0;
char startposition;
// Declare your global variables here
void delay(int ms) //延時
{
int i,j;
for(i=0;i<ms;i++)
{
for(j=0;j<1141;j++);
}
}
void main(void)
{
DDRA.0=0;
PORTD=0x00;
DDRD=0x30;
PORTD=0x00;
PORTB=0x00;
DDRB.3=1;
PORTB.3=0;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 7.813 kHz
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x05;
TCNT0=startposition;
OCR0=0x00;
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
TIMSK=0x01;
ACSR=0x80;
SFIOR=0x00;
// Global enable interrupts
#asm("sei")
while (1)
{
};
}
// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
i++;
if (i==2)
{i=0;}
if (i==0)
{TCNT0=startposition;
PORTB.3=1; }
else
{TCNT0=0x73;
PORTB.3=0; }
if (PINA.0==1)
{startposition=0xf0;}
else
{startposition=0xf8;}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -