/***************************************************** This program was produced by the CodeWizardAVR V1.24.6 Standard Automatic Program Generator © Copyright 1998-2005 Pavel Haiduc, HP InfoTech s.r.l. http://www.hpinfotech.com e-mail:office@hpinfotech.com Project : Version : Date : 08.07.2006 Author : Nick Company : Mgupi Comments: Chip type : ATmega8 Program type : Application Clock frequency : 16,000000 MHz Memory model : Small External SRAM size : 0 Data Stack size : 256 *****************************************************/ #include #include #define utime 24 //#define ULTRACNT 36 char ULTRACNT; int count; int j; char i; char ready; // External Interrupt 0 service routine interrupt [EXT_INT0] void ext_int0_isr(void) { // Place your code here ready=1; } // External Interrupt 1 service routine interrupt [EXT_INT1] void ext_int1_isr(void) { //ready=1; // Place your code here } #define RXB8 1 #define TXB8 0 #define UPE 2 #define OVR 3 #define FE 4 #define UDRE 5 #define RXC 7 #define FRAMING_ERROR (1< // Declare your global variables here void main(void) { unsigned int res; // Declare your local variables here unsigned int cnt; // Input/Output Ports initialization // Port B initialization // Func7=In Func6=In Func5=In Func4=In Func3=Out Func2=In Func1=Out Func0=In // State7=T State6=T State5=T State4=T State3=0 State2=T State1=0 State0=T PORTB=0x00; DDRB=0x0A; // Port C initialization // Func6=In Func5=Out Func4=In Func3=In Func2=In Func1=In Func0=In // State6=T State5=0 State4=T State3=T State2=T State1=T State0=T PORTC=0x00; DDRC=0x20; // Port D initialization // Func7=In Func6=In Func5=Out Func4=Out Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=0 State4=0 State3=T State2=T State1=T State0=T PORTD=0x00; DDRD=0x30; // Timer/Counter 0 initialization // Clock source: System Clock // Clock value: Timer 0 Stopped TCCR0=0x00; TCNT0=0x00; // Timer/Counter 1 initialization // Clock source: System Clock // Clock value: Timer 1 Stopped // Mode: Normal top=FFFFh // OC1A output: Discon. // OC1B output: Discon. // Noise Canceler: Off // Input Capture on Falling Edge // Timer 1 Overflow Interrupt: Off // Input Capture Interrupt: Off // Compare A Match Interrupt: Off // Compare B Match Interrupt: Off TCCR1A=0x00; TCCR1B=0x00; TCNT1H=0x00; TCNT1L=0x00; ICR1H=0x00; ICR1L=0x00; OCR1AH=0x00; OCR1AL=0x00; OCR1BH=0x00; OCR1BL=0x00; // Timer/Counter 2 initialization // Clock source: System Clock // Clock value: Timer 2 Stopped // Mode: Normal top=FFh // OC2 output: Disconnected ASSR=0x00; TCCR2=0x00; TCNT2=0x00; OCR2=0x00; // Timer/Counter 2 initialization // Clock source: System Clock // Clock value: 62,500 kHz // Mode: Phase correct PWM top=FFh // OC2 output: Non-Inverted PWM /*ASSR=0x00; TCCR2=0x69; TCNT2=0x00; OCR2=0x06f; */ // External Interrupt(s) initialization // INT0: On // INT0 Mode: Any change // INT1: On // INT1 Mode: Any change GICR|=0xC0; MCUCR=0x05; GIFR=0xC0; //MCUCR=0x00; // Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x00; /* // USART initialization // Communication Parameters: 8 Data, 1 Stop, No Parity // USART Receiver: Off // USART Transmitter: On // USART Mode: Asynchronous // USART Baud rate: 38400 UCSRA=0x00; UCSRB=0x08; UCSRC=0x86; UBRRH=0x00; UBRRL=0x19; */ // USART initialization // Communication Parameters: 8 Data, 1 Stop, No Parity // USART Receiver: On // USART Transmitter: On // USART Mode: Asynchronous // USART Baud rate: 14400 UCSRA=0x00; UCSRB=0x98; UCSRC=0x86; UBRRH=0x00; UBRRL=0x44; // Analog Comparator initialization // Analog Comparator: Off // Analog Comparator Input Capture by Timer/Counter 1: Off ACSR=0x80; SFIOR=0x00; // Global enable interrupts #asm("sei") PORTC.5=1; //ULTRACNT=38; ULTRACNT=38; while (1) { PORTD.4=1; PORTD.5=1; ready=0; /*PORTC.5=1; for (i=0;i<300;i++) { } PORTC.5=0; */ //raskachat(); /* PORTB.3=1; for (i=0;i65000) {cnt=0; break;} } res=cnt/77; //cnt=ULTRACNT; printf("%u ",res); if (cnt!=0){PORTB.1=1;}else{PORTB.1=0;} cnt=0; //PORTC.5=0; #asm("cli") delay_ms(100); //delay_ms(50); #asm("sei") //delay_ms(250); }; }