/***************************************************** This program was produced by the CodeWizardAVR V1.25.3 Evaluation Automatic Program Generator © Copyright 1998-2007 Pavel Haiduc, HP InfoTech s.r.l. http://www.hpinfotech.com Project : Borne 50m DA - Départ avec afficheurs Version : 3 Date : Mai 2010 Author : Company : 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 // Alphanumeric LCD Module functions #asm .equ __lcd_port=0x15 ;PORTC #endasm #include #include #define CP1 PIND.5 #define BP1 PIND.6 #define ENABLE PORTD.7 // Sur la nouvelle version, il faut ENABLE = OC = 0 pour allumer les afficheurs. // Declare your global variables here flash const unsigned char adresse_constant[16] = {0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15}; #define DIGIT_A 64; { bit b6 } #define DIGIT_B 128; { bit b7 } #define DIGIT_C 2; { bit b1 } #define DIGIT_D 4; { bit b2 } #define DIGIT_E 8; { bit b3 } #define DIGIT_F 32; { bit b5 } #define DIGIT_G 16; { bit b4 } #define DIGIT_P 1; { bit b0 } flash const unsigned char valeur_constant[] = {0xEE,0x82,0xDC,0xD6,0xB2,0x76,0x7E,0xC2,0xFE,0xF6, 0,1,2,4,8,16,32,64,128}; unsigned char tampon[20],seconde,seconde1,temps,temps1,dizaine,unite,dixieme,centieme,test,var,flag; // Declare your global function here 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; } // Timer 1 output compare A interrupt service routine interrupt [TIM1_COMPA] void timer1_compa_isr(void) { temps++; if (temps>=100) { temps=0; seconde++; if (seconde>=60) { seconde=0; }; }; if (flag == 1) { temps1++; if (temps1>=100) { temps1=0; seconde1++; if (seconde1>=60) { seconde1=0; }; }; } } // Affiche une valeur sur 8 bits à l'adresse de l'afficheur : void afficheur1(unsigned char adresse,unsigned char caractere, unsigned char point) { if (point == 1) { PORTA=(valeur_constant[caractere] | 0x01); // Un caractère avec le point ! } else { PORTA=valeur_constant[caractere]; // Un caractère } PORTB=(0b00010000 | adresse_constant[adresse & 0x0F]); // PB7 PB6 PB5 CS A0 A1 A2 A3 PORTB.4=1; PORTB.4=0; // CS = 0 PORTB.4=1; PORTA=0x00; } 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; en entrée DDRA=0xFF; // en sortie // 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=0xFF; // DDRB=0x00; en entrée DDRB=0xFF; // en sortie // 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=In Func0=In // State7=0 State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTD=0x80; ENABLE=1; DDRD=0x80; // 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 // Timer 1 Overflow Interrupt: Off // Input Capture Interrupt: Off // Compare A Match Interrupt: On // Compare B Match Interrupt: Off TCCR1A=0x40; TCCR1B=0x0A; TCNT1H=0x00; TCNT1L=0x00; ICR1H=0x00; ICR1L=0x00; OCR1AH=0x4E; // Base de temps = 2 MHz, soit 0,5 us. OCR1AL=0x20; // Interruption quand on arrive à 20 000 (0x4E20 soit 10 ms) 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; // Analog Comparator initialization // Analog Comparator: Off // Analog Comparator Input Capture by Timer/Counter 1: Off ACSR=0x80; SFIOR=0x00; // USART initialization // Communication Parameters: 8 Data, 1 Stop, No Parity // USART Receiver: On // USART Transmitter: Off // USART Mode: Asynchronous // USART Baud rate: 9600 UCSRA=0x00; UCSRB=0x10; UCSRC=0x86; UBRRH=0x00; UBRRL=0x67; // LCD module initialization lcd_init(16); /* switch to writing in Display RAM */ lcd_gotoxy(0,0); lcd_putsf("Borne DEpart"); lcd_gotoxy(0,1); lcd_putsf("Borne 50 m DA"); PORTB=0xFF; seconde=0; temps=0; seconde1=0; temps1=0; test=0; var='0'; ENABLE=0; //Afficheurs on ! afficheur1(0,11,0); // Un caractère afficheur1(1,11,0); // Un caractère afficheur1(2,11,0); // Un caractère afficheur1(3,11,0); // Un caractère // Global enable interrupts #asm("sei") while (1) { var=USART_Receive(); if(var=='0') { flag=0; } if(CP1==0) { flag=1; } if(BP1==0) { flag=0; } if((CP1==0)&&(BP1==0)) { temps1=0; seconde1=0; flag=0; delay_ms(500); } // Place your code here sprintf(tampon,"Temps = %2d:%2d",seconde,temps); lcd_gotoxy(0,2); lcd_puts(tampon); sprintf(tampon,"flag = %d,%d",flag,var); lcd_gotoxy(0,3); lcd_puts(tampon); dizaine = seconde1/10; unite = seconde1-dizaine*10; dixieme = temps1/10; centieme = temps1-dixieme*10; // Afficheur d'adresse 0 if (dizaine == 0) { afficheur1(0,13,0); } else { afficheur1(0,dizaine,0); // Caractère des dizaines. } // Afficheur d'adresse 1 afficheur1(1,unite,1); // Caractère des unités. // Afficheur d'adresse 2 afficheur1(2,dixieme,0); // Caractère des dixièmes. // Afficheur d'adresse 3 afficheur1(3,centieme,0); // Caractère des centièmes. }; }