/***************************************************** This program was produced by the CodeWizardAVR V2.03.9 Standard Automatic Program Generator © Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l. http://www.hpinfotech.com Project : Paha_3 Version : Date : 30.11.2014 Author : Company : Comments: Paha_3 OIL Pump Real & PWM for AIR Keys up PC1 pin 24, PB5 pin 19. Keys ddown PB4 pin 18 PC0 pin 23. PB3 - pin 17 PUMP MOTOR OUTPUT PB3 - pin 15 PWM AIR MOTOR OUTPUT ATmega8 Fuses CKOPT -1, SUT1-0, SUT0-1, CKSEL3,2,1,0 - 1, 1, 1, 0. Chip type : ATmega8 Program type : Application AVR Core Clock frequency: 8,000000 MHz Memory model : Small External RAM size : 0 Data Stack size : 256 *****************************************************/ #include #include #define FAZA PORTB.3 // pin 17 #define KEY_1 PINC.1 // up pin 24 PUMP #define KEY_2 PINC.0 // down pin 23 #define KEY_3 PINB.5 // up pin 19 AIR #define KEY_4 PINB.4 // down pin 18 // Declare your global variables here flash unsigned int DEL=1000; // 1 cek flash unsigned int dl=700; // max delay flash unsigned char incr1=8; // increment for delay flash unsigned char incr2=10; // increment for delay flash unsigned char lim1=2; // min limit & increment flash unsigned char lim2=3; // min limit & increment char ReadKey = 0, ReadKey1 = 0; // not read key int dutyA, dutyC, dutyB; static void avr_init(); void getkey(void); void getkey1(void); void main(void) { // Declare your local variables here char k=0; avr_init(); delay_ms(lim1); dutyC=dl; OCR1AH = (unsigned char)(dutyC>>8); OCR1AL = (unsigned char)dutyC; FAZA=1; delay_ms(dl); delay_ms(DEL); delay_ms(DEL); delay_ms(DEL); FAZA=0; delay_ms(DEL); for (k=0; k>8); OCR1AL = (unsigned char)dutyC; }; // While } // main static void avr_init() { // 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=Out Func0=In // State7=T State6=T State5=P State4=P State3=0 State2=T State1=0 State0=T PORTB=0x30; DDRB=0x0A; // Port C initialization // Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State6=T State5=T State4=T State3=T State2=T State1=P State0=P PORTC=0x03; DDRC=0x00; // 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=0x00; TCNT0=0x00; // Timer/Counter 1 initialization // Clock source: System Clock // Clock value: 31,250 kHz // Mode: Fast PWM top=03FFh // OC1A output: Non-Inv. // 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=0x83; TCCR1B=0x0C; 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 MCUCR=0x00; // Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x00; // Analog Comparator initialization // Analog Comparator: Off // Analog Comparator Input Capture by Timer/Counter 1: Off ACSR=0x80; SFIOR=0x00; } void getkey(void) { unsigned char R=0; ReadKey = 0; R=(KEY_1); delay_ms(lim1); if ((R==0)&&(KEY_1==0)) ReadKey = 1; R=(KEY_2); delay_ms(lim1); if ((R==0)&&(KEY_2==0)) ReadKey = 2; } void getkey1(void) { unsigned char R1=0; ReadKey1 = 0; R1=(KEY_3); delay_ms(lim1); if ((R1==0)&&(KEY_3==0)) ReadKey1 = 1; R1=(KEY_4); delay_ms(lim1); if ((R1==0)&&(KEY_4==0)) ReadKey1 = 2; }