پاسخ : پاسخ : مشکل ساده با برنامه ساده
متشکر از همکاری همه دوستان
متشکر از همکاری همه دوستان
Config Timer0 = Timer , Prescale = 1024 Timer0 = 61
If D1 = 80 Then X = C1 Mod 2 D1 = 0 If X = 1 Then C1 = C1 + 1 Set Led1 Else C1 = C1 + 1 Reset Led1 End If Else D1 = D1 + 1 End If End If
This program was produced by the CodeWizardAVR V2.05.0 Professional Automatic Program Generator © Copyright 1998-2010 Pavel Haiduc, HP InfoTech s.r.l. http://www.hpinfotech.com Project : Version : Date : 03/21/2015 Author : NeVaDa Company : Comments: Chip type : ATmega16 Program type : Application AVR Core Clock frequency: 1.000000 MHz Memory model : Small External RAM size : 0 Data Stack size : 256 *****************************************************/ #include <mega16.h> #include <delay.h> // Declare your global variables here #define pushbutton1 PINA.0 #define pushbutton2 PINA.1 #define pushbutton3 PINA.2 #define led1 PORTD.0 #define led2 PORTD.1 #define led3 PORTD.2 void main(void) { // Declare your local variables here // 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=0x00; // 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=0x00; // Port C 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 PORTC=0x00; DDRC=0x00; // Port D initialization // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=Out Func1=Out Func0=Out // State7=T State6=T State5=T State4=T State3=T State2=0 State1=0 State0=0 PORTD=0x00; DDRD=0x07; // Timer/Counter 0 initialization // Clock source: System Clock // Clock value: Timer 0 Stopped // Mode: Normal top=0xFF // OC0 output: Disconnected TCCR0=0x00; TCNT0=0x00; OCR0=0x00; // Timer/Counter 1 initialization // Clock source: System Clock // Clock value: Timer1 Stopped // Mode: Normal top=0xFFFF // OC1A output: Discon. // OC1B output: Discon. // Noise Canceler: Off // Input Capture on Falling Edge // Timer1 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: Timer2 Stopped // Mode: Normal top=0xFF // 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=0x00; // USART initialization // USART disabled UCSRB=0x00; // Analog Comparator initialization // Analog Comparator: Off // Analog Comparator Input Capture by Timer/Counter 1: Off ACSR=0x80; SFIOR=0x00; // ADC initialization // ADC disabled ADCSRA=0x00; // SPI initialization // SPI disabled SPCR=0x00; // TWI initialization // TWI disabled TWCR=0x00; while (1) { // Place your code here if (pushbutton1=1) { while (5) { led1=1; delay_ms(2000); led1=0; delay_ms(2000); } } if (pushbutton2=1) { while (5) { led2=1; delay_ms(2000); led2=0; delay_ms(2000); } } if (pushbutton3=1) { while (5) { led3=1; delay_ms(2000); led3=0; delay_ms(2000); } } } }
$regfile = "m32def.dat" $crystal = 8000000 Dim A As Bit , B As Bit , C As Byte , D As Byte , M As Byte Dim E As Bit , F As Bit , G As Byte , H As Byte , N As Byte Dim I As Bit , J As Bit , K As Byte , L As Byte , Z As Byte Config Timer0 = Timer , Prescale = 1024 Enable Timer0 Enable Interrupts On Timer0 T0_isr Start Timer0 Timer0 = 178 Config Pinb.0 = Input Config Pinb.1 = Input Config Pinb.2 = Input Config Pinb.3 = Input Config Pind.0 = Output Config Pind.1 = Output Config Pind.2 = Output Config Debounce = 100 Main: Do Debounce Pinb.0 , 0 , Stop1 Debounce Pinb.1 , 0 , Led0 Debounce Pinb.2 , 0 , Led1 Debounce Pinb.3 , 0 , Led2 Loop Led0: A = 1 : B = 0 : Incr M Goto Main Led1: E = 1 : F = 0 : Incr N Goto Main Led2: I = 1 : J = 0 Goto Main Stop1: Z = 1 Goto Main End T0_isr: Timer0 = 178 If A = 1 Then If M = 1 Then Set Portd.0 C = 0 : D = 0 End If Incr M Incr C If C = 200 Then C = 0 Toggle Portd.0 Incr D If D = 10 Then Set Portd.0 A = 0 End If End If End If If A = 1 Then If M = 3 Then Reset Portd.0 A = 0 End If M = 0 End If If E = 1 Then If N = 1 Then Set Portd.1 G = 0 : H = 0 End If Incr G If G = 200 Then G = 0 Toggle Portd.1 Incr H If H = 10 Then Set Portd.1 E = 0 N = 2 End If End If End If If E = 1 Then If N = 3 Then Reset Portd.1 E = 0 End If N = 0 End If If I = 1 Then If J = 0 Then Set Portd.2 J = 1 : K = 0 : L = 0 End If Incr K If K = 200 Then K = 0 Toggle Portd.2 Incr L If L = 10 Then Set Portd.2 I = 0 End If End If End If If Z = 1 Then Reset Portd.0 Reset Portd.1 Reset Portd.2 Z = 0 End If Return
دیدگاه