/***************************************************** CodeWizardAVR V2.05.3 Automatic Program Generator Project : Version : Date : 22/04/2020 Author : Thierry Company : Maison Comments: Chip type : ATmega8535 Program type : Application AVR Core Clock frequency: 16,000000 MHz Memory model : Small External RAM size : 0 Data Stack size : 128 *****************************************************/ #include #include #include // Alphanumeric LCD functions #include // Declare your global variables here unsigned char temps, // de 0 à 10. secondes, // de 0 à 59. minutes, // de 0 à 59. heures; // de 0 à 23. unsigned char tampon[20]; // Avec un afficheur 16 caractères, il faut un peu plus que 16... //*************************************************************************** // Timer 1 output compare A interrupt service routine // On arrive ici toutes les 100 ms : //*************************************************************************** interrupt [TIM1_COMPA] void timer1_compa_isr(void) { temps++; //if (temps>=40) // 40 x 25 ms = 1 seconde. //if (temps>=20) // 20 x 50 ms = 1 seconde. if (temps>=10) // 10 x 100 ms = 1 seconde. { temps=0; secondes++; if (secondes>59) { secondes=0; minutes++; if (minutes>59) { minutes=0; heures++; if (heures>23) { heures=0; }; }; }; // if (secondes>=59). }; // if (temps>=10). }; 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=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 // Mode: Normal top=0xFF // OC0 output: Disconnected TCCR0=0x00; TCNT0=0x00; OCR0=0x00; // Timer/Counter 1 initialization // Clock source: System Clock // Clock value: 250,000 kHz // Mode: CTC top=OCR1A // 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: On // Compare B Match Interrupt: Off TCCR1A=0x00; TCCR1B=0x0B; TCNT1H=0x00; TCNT1L=0x00; ICR1H=0x00; ICR1L=0x00; //OCR1AH=0x30; // Base de temps = 250 kHz, soit 4 us. //OCR1AL=0xD4; // Interruption quand on arrive à 2500 = 0x09C4 soit 10 ms. //OCR1AH=0x30; // Base de temps = 250 kHz, soit 4 us. //OCR1AL=0xD4; // Interruption quand on arrive à 12500 = 0x30D4 soit 50 ms. OCR1AH=0x61; // Base de temps = 250 kHz, soit 4 us. OCR1AL=0xA8; // Interruption quand on arrive à 25000 = 0x61A8 soit 100 ms. 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=0x10; // 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; // Alphanumeric LCD initialization // Connections are specified in the // Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu: // RS - PORTC Bit 0 // RD - PORTC Bit 1 // EN - PORTC Bit 2 // D4 - PORTC Bit 4 // D5 - PORTC Bit 5 // D6 - PORTC Bit 6 // D7 - PORTC Bit 7 // Characters/line: 16 lcd_init(16); // Global enable interrupts #asm("sei") while (1) { // Place your code here lcd_gotoxy(0,0); // "1234567890123456" avec DISPLAYTECH 162C CC-BC. lcd_putsf("Horloge-2 16 x 2"); sprintf(tampon,"%2u h %02u min %02u s",heures,minutes,secondes); lcd_gotoxy(0,1); lcd_puts(tampon); // On affiche le contenu de tampon. if (PIND.7==0) { minutes++; delay_ms(200); if (minutes>59) { minutes=0; }; } if (PIND.6==0) { heures++; delay_ms(200); if (heures>23) { heures=0; }; } }; }