/***************************************************** This program was produced by the CodeWizardAVR V1.25.2 Evaluation Automatic Program Generator © Copyright 1998-2006 Pavel Haiduc, HP InfoTech s.r.l. http://www.hpinfotech.com Project : Version : Date : 22.05.2009 Author : Freeware, for evaluation and non-commercial use only Company : Comments: Chip type : ATmega16 Program type : Application Clock frequency : 16,000000 MHz Memory model : Small External SRAM size : 0 Data Stack size : 256 *****************************************************/ #include #include // Standard Input/Output functions #include // Declare your global variables here #define DATA_LINE PORTB.2 // Naznachenie nozek MK dlya raboty s DDS #define CLOCK_LINE PORTB.1 #define SYNC_LINE PORTB.0 #define RES_LINE PORTB.4 #define DATA_LINE_ON DDRB.2 #define CLOCK_LINE_ON DDRB.1 #define SYNC_LINE_ON DDRB.0 #define RES_LINE_ON DDRB.4 #define PZ #asm("nop") unsigned int adc=0,adc1=0; long int adcprint=0, adcprint1=0,vyv1=0, vyv2=0; float z,y,x; int a[207]; //unsigned long int Ux[10]; //unsigned long int U0[10]; char lcd_buffer[10]; char lcd_buffer1[10]; unsigned char data_hi, data_low; volatile unsigned char data_hi1,data_low1,data_hi2,data_low2; // Timer 0 overflow interrupt service routine void init(void)//Inicializaciya { // Input/Output Ports initialization // Port A 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 PORTA=0x00; DDRA=0b00000101; // Port B 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 PORTB=0x00; DDRB=0b11111111; // Port C initialization // Func7=Out Func6=Out Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State7=1 State6=1 State5=T State4=T State3=T State2=T State1=T State0=T PORTC=0b01000000; DDRC=0b11000000; // Port D initialization // Func7=In Func6=In Func5=Out Func4=Out Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=1 State4=1 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 // Mode: Normal top=FFh // OC0 output: Disconnected TCCR0=0x11; TCNT0=0xD2; OCR0=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; // External Interrupt(s) initialization // INT0: Off // INT1: Off // INT2: Off MCUCR=0x00; MCUCSR=0x00; // Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x01; // USART initialization // Communication Parameters: 8 Data, 1 Stop, No Parity // USART Receiver: Off // USART Transmitter: On // USART Mode: Asynchronous // USART Baud rate: 9600 UCSRA=0x00; UCSRB=0x08; UCSRC=0x86; UBRRH=0x00; UBRRL=0x67; // Analog Comparator initialization // Analog Comparator: Off // Analog Comparator Input Capture by Timer/Counter 1: Off ACSR=0x80; SFIOR=0x00; // LCD module initialization //lcd_init(16); //lcd_gotoxy(5,0); //lcd_putsf("Hello"); delay_ms(1000); PORTA.0=1; PORTA.2=1; } interrupt [TIM0_OVF] void timer0_ovf_isr(void) { // Reinitialize Timer 0 value TCNT0=0xD2; // Place your code here } void data_to_synt (void) //funkciya otpravlyayuschaya dannye v DDS { char ctr = 8; SYNC_LINE_ON = 1; SYNC_LINE = 1; delay_us(100); CLOCK_LINE_ON = 1; CLOCK_LINE = 1; DATA_LINE_ON = 1; while (ctr){ DATA_LINE = data_hi1 & 0b10000000; SYNC_LINE = 0; CLOCK_LINE = 0; ctr --; data_hi1 <<= 1; delay_us(5); CLOCK_LINE = 1; }; ctr = 8; while (ctr){ DATA_LINE = data_low1 & 0b10000000; CLOCK_LINE = 0; data_low1 <<= 1; ctr --; delay_us(5); CLOCK_LINE = 1; }; SYNC_LINE = 1; delay_us(100); ctr = 8; while (ctr){ DATA_LINE = data_hi2 & 0b10000000; SYNC_LINE = 0; CLOCK_LINE = 0; data_hi2 <<= 1; ctr --; delay_us(5); CLOCK_LINE = 1; }; ctr = 8; while (ctr){ DATA_LINE = data_low2 & 0b10000000; CLOCK_LINE = 0; data_low2 <<= 1; ctr --; delay_us(5); CLOCK_LINE = 1; }; delay_us(1); SYNC_LINE = 1; } void preparation(void)//f-ya podgotovki DDS k zapisi v reg-r 4astoty { char ctr = 8; CLOCK_LINE = 1; SYNC_LINE_ON = 1; SYNC_LINE = 1; DATA_LINE_ON = 1; while (ctr){ DATA_LINE = data_hi2 & 0b10000000; SYNC_LINE = 0; CLOCK_LINE = 0; data_hi2 <<= 1; ctr --; delay_us(5); CLOCK_LINE = 1; }; ctr = 8; while (ctr){ DATA_LINE = data_low2 & 0b10000000; CLOCK_LINE = 0; data_low2 <<= 1; ctr --; delay_us(5); CLOCK_LINE = 1; }; delay_us(100); SYNC_LINE = 1; } // Declare your global variables here void main(void) { char ctr=8; // Declare your local variables here char i,s,k; init(); data_hi2 = 0b00100001; //resetim vnutrennie registry DDS data_low2 = 0b00000000; preparation(); //lcd_clear(); //lcd_putsf("preparation end"); //delay_ms(1000); data_hi2 = 0b00100000;//ubiraem reset data_low2 = 0b00000000; preparation(); //lcd_clear(); //lcd_putsf("preparation2 end"); // delay_ms(1000); data_hi1 = 0b01010100;//zapis' v registr 4astoty data_low1 = 0b11111000; data_hi2 = 0b01000000; data_low2 = 0b00000000; data_to_synt(); //lcd_clear(); //lcd_putsf("data end"); #asm("sei") //while (1) for(s=0;s<207;s++) //zapis' v massiv { adc=0; // rabota s ADC adc1=0; PZ;PZ; PZ;PZ;PZ; PORTA.2=0; PZ;PZ; PZ;PZ;PZ; PORTA.0=0; PZ;PZ; PZ;PZ;PZ; PORTA.0=1; PZ;PZ; PZ;PZ;PZ; PORTA.0=0; PZ;PZ; PZ;PZ;PZ; PORTA.0=1; PZ;PZ; PZ;PZ;PZ;PZ; for(i=0; i<16; i++) { PORTA.0=0; PZ;PZ;PZ;PZ;PZ;PZ; adc=adc + PINA.1; adc1=adc1 + PINA.3; PORTA.0=1; PZ;PZ;PZ;PZ;PZ;PZ; adc<<=1; adc1<<=1; } PORTA.0=0; PZ;PZ;PZ;PZ;PZ;PZ; adc=adc + PINA.1; adc1=adc1 + PINA.3; PZ;PZ;PZ;PZ;PZ;PZ; PORTA.0=1; // z=2.5/65536; PORTA.2=1; PZ;PZ;PZ;PZ;PZ;PZ; //x=adc*z; a[s]=adc; // Zapis' polu4ennogo znacheniya s ADC v massiv(bufer) //adcprint=x; // y=adc1*z; //b[s]=y; //adcprint1=y; //adc=56; // adc1/100000 // lcd_puts(lcd_buffer); // lcd_gotoxy(0,1); // lcd_puts(lcd_buffer1); // delay_ms(100); // Place your code here } for(k=0;k<207;k++) // vyvod elementov massiva po USART na comp. { sprintf(lcd_buffer,"%4u\n",a[k]); // sprintf(lcd_buffer1,"U2=%f",b[k]); // lcd_clear(); // (lcd_buffer1 puts(lcd_buffer); // puts(lcd_buffer1); } while(1) { /* sprintf(lcd_buffer,"U1=%f",x); sprintf(lcd_buffer1,"U2=%f",y); // lcd_clear(); // (lcd_buffer1 puts(lcd_buffer); puts(lcd_buffer1); printf("a=%f",a); */ }; }