/***************************************************** This program was produced by the CodeWizardAVR V1.24.2c Professional Automatic Program Generator © Copyright 1998-2004 Pavel Haiduc, HP InfoTech s.r.l. http://www.hpinfotech.ro e-mail:office@hpinfotech.ro Project : Version : Date : 03/10/2011 Author : F4CG Company : F4CG Comments: Chip type : ATmega8535 Program type : Application Clock frequency : 16,000000 MHz Memory model : Small External SRAM size : 0 Data Stack size : 128 *****************************************************/ #include #include #include #define Vert PIND.6 ///#define Rouge PIND.7 #define Bleu PINB.5 #define CaptD PIND.4 #define CaptA PIND.5 #define ENABLE PORTD.7 // Alphanumeric LCD Module functions #asm .equ __lcd_port=0x15 ;PORTC #endasm #include // Declare your global variables here unsigned char dizaine, unite, dizieme, centieme,car; flash const unsigned char valeur_constant[]= { 0xEE,0x82,0xDC,0xD6,0xB2,0x76,0x7E,0xC2,0xFE,0xF6, 0xFA,0xFE,0x6C,0xEE,0x7C,0xF8,0x7E,0xBA,0x82,0x86, 0x3C,0x2C,0xEA,0x1A,0xEE,0xF8,0xF2,0xFA,0x76,0x3C, 0x0E,0xAE,0xDC}; flash const unsigned char adresse_constant[16]= {0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15}; void Afficheur(unsigned char adresse, unsigned char caractere, unsigned char point) { if ( point == 1 ) { PORTA = (valeur_constant[caractere] | 0x01); // Un point est rajouté après le caractère } else { PORTA=valeur_constant[caractere]; //Un caractere tout seul } PORTB=(0b00010000|adresse_constant[adresse & 0x0F]); PORTB.4=1; PORTB.4=0; PORTB.4=1; PORTA=0x00; } unsigned char USART_Receive( void ) { /* Wait for data to be received */ while ( !(UCSRA & 0x80) ) // Test de RXC bit7 ; /* Get and return received data from buffer */ return UDR; } interrupt [TIM1_COMPA] void timer1_compa_isr(void) { centieme++; if( centieme == 10 ) { dizieme++; centieme = 0; if( dizieme == 10) { unite++; dizieme=0; if(unite>9) { dizaine++; unite=0; if(dizaine == 6) { dizaine = 0; } } } } Afficheur(0,dizaine,0); Afficheur(1,unite,1); Afficheur(2,dizieme,0); Afficheur(3,centieme,0); } void Chronometre(int Flag ) { if( Flag == 1) { ENABLE=0; TCCR1B = 0x0A; } else if( Flag == 0) { TCCR1B = 0x08; ENABLE = 0; dizaine = 0; unite = 0; dizieme = 0; centieme = 0; Afficheur(0,0xEE,1); Afficheur(1,0xD2,1); Afficheur(2,0x1F,1); Afficheur(3,0xA9,1); } else if (Flag == 2) { TCCR1B = 0x08; ENABLE = 0; dizaine = 0; unite = 0; dizieme = 0; centieme = 0; Afficheur(0,dizaine,0); Afficheur(1,unite,1); Afficheur(2,dizieme,0); Afficheur(3,centieme,0); } } void main(void) { // Input/Output Ports initialization // Port A initialization // Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out // State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0 PORTA=0x00; DDRA=0xFF; // Port B initialization // Func7=In Func6=In Func5=In Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out // State7=T State6=T State5=T State4=0 State3=0 State2=0 State1=0 State0=0 PORTB=0x00; DDRB=0x1F; // 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=Out Func6=In Func5=In Func4=In Func3=In Func2=In Func1=Out Func0=In // State7=1 State6=T State5=T State4=T State3=T State2=T State1=0 State0=T PORTD=0x80; DDRD=0x82; // Timer/Counter 0 initialization // Clock source: System Clock // Clock value: Timer 0 Stopped // Mode: Normal top=FFh // OC0 output: Disconnected TCCR0=0x00; TCNT0=0x00; OCR0=0x00; // Timer/Counter 1 initialization // Clock source: System Clock // Clock value: 2000,000 kHz // Mode: CTC top=OCR1A // OC1A output: Toggle // OC1B output: Discon. // Noise Canceler: Off // Input Capture on Falling Edge TCCR1A=0x40; TCCR1B=0x0A; TCNT1H=0x00; TCNT1L=0x00; ICR1H=0x00; ICR1L=0x00; OCR1AH=0x4E; OCR1AL=0x20; 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=0x10; // USART initialization // Communication Parameters: 8 Data, 1 Stop, No Parity // USART Receiver: On // USART Transmitter: On // USART Mode: Asynchronous // USART Baud rate: 9600 UCSRA=0x00; UCSRB=0x18; UCSRC=0x86; UBRRH=0x00; UBRRL=0x67; // Analog Comparator initialization // Analog Comparator: Off // Analog Comparator Input Capture by Timer/Counter 1: Off // Analog Comparator Output: Off ACSR=0x80; SFIOR=0x00; // LCD module initialization lcd_init(16); #asm("sei") while (1) { int flag; while( CaptD == 1) { car=USART_Receive(); if (car == 'D') { flag = 2; } if (car == 'M') { if( flag != 3 ) flag = 1; } else if (car == 'A') { flag = 0; } Chronometre(flag); } TCCR1B = 0x08; ENABLE=0; flag=3; } }