/**************************************************** This program was produced by the CodeWizardAVR V2.05.4 Evaluation Automatic Program Generator © Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l. http://www.hpinfotech.com Project : Borne 50 mètres départ arrété - AFFICHEURS 5 LED 10mm ! Version : 1 Date : 8 juillet 2013 Author : Thierry LEQUEU Company : Association e-Kart Comments: avec les feux tricolores et les entrées capteurs. Comments: avec l'interface RS232. 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 //#define BP1 PIND.5 #define BP2 PIND.6 #define ENABLE PORTD.7 #define CAPT4 PIND.2 #define CAPT3 PIND.3 #define CAPT2 PIND.4 #define CAPT1 PIND.5 // 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}; // Pour les afficheurs sur fond noir : //#define DIGIT_A 1; { 11 = bit b0 } // a //#define DIGIT_B 2; { 12 = bit b1 } // f b //#define DIGIT_C 4; { 13 = bit b2 } // g //#define DIGIT_D 8; { 14 = bit b3 } // e c //#define DIGIT_E 16; { 15 = bit b4 } // d p //#define DIGIT_F 32; { 16 = bit b5 } //#define DIGIT_G 64; { 17 = bit b6 } //#define DIGIT_P 128; { 18 = bit b7 } // Pour les afficheurs 5 LED 10mm : #define DIGIT_A 0x40; { bit b6 } // a #define DIGIT_B 0x20; { bit b5 } // f b #define DIGIT_C 0x02; { bit b1 } // g #define DIGIT_D 0x08; { bit b3 } // e c #define DIGIT_E 0x01; { bit b0 } // d p #define DIGIT_F 0x80; { bit b7 } #define DIGIT_G 0x10; { bit b4 } #define DIGIT_P 0x04; { bit b2 } flash const unsigned char valeur_constant[] = //{0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F, // Pour afficheurs sur fond noir - octet de 48 à 57 en ASCII. {0xEB,0x22,0x79,0x7A,0xB2,0xDA,0xDB,0xE2,0xFB,0xFA, // Pour afficheurs 5 LED 10mm - octet de 48 à 57 en ASCII. 0,0x40,0x20,0x02,0x08,0x01,0x80,0x10,0x04, 0,1,2,4,8,16,32,64,128}; unsigned char tampon[20],seconde,seconde1,temps,temps1,dizaine,unite,unite_0,dixieme,centieme,test,var,feux; // 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; } void USART_Transmit( unsigned char data ) { /* Wait for empty transmit buffer */ while ( !( UCSRA & (0x20)) ) // Test de UDRE bit 5 ; /* Put data into buffer, sends the data */ UDR = data; } // 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>=100) { seconde=0; }; }; if (test == 1) { temps1++; if (temps1>=100) { temps1=0; seconde1++; if (seconde1>=100) { 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] | 0x04); // 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; } // Affiche une valeur sur 8 bits à l'adresse de l'afficheur : void afficheur2(unsigned char adresse,unsigned char caractere, unsigned char point) { if (point == 1) { PORTA=(caractere | 0x80); // Un caractère avec le point ! } else { PORTA=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; } // Routine de test des segments : void test_segments_1(void) { for (var=11;var<19;var++) { afficheur1(0,var,0); afficheur1(1,var,0); afficheur1(2,var,0); afficheur1(3,var,0); afficheur1(4,var,0); afficheur1(5,var,0); afficheur1(6,var,0); afficheur1(7,var,0); delay_ms(500); } } // Routine de test des segments : void test_segments_2(void) { afficheur1(0,8,1); // Un caractère afficheur1(1,8,1); // Un caractère afficheur1(2,8,1); // Un caractère afficheur1(3,8,1); // Un caractère afficheur1(4,8,1); // Un caractère afficheur1(5,8,1); // Un caractère } // Routine de test des feux tricolore : void test_segments_3(void) { for (feux=1;feux<8;feux++) { afficheur2(6,(2^feux),0); // Un caractère delay_ms(500); } } 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=0x00; ENABLE=1; DDRD=0x80; // DDRD=0x00; en entrée // DDRD=0x38; // BP1 BP2 OC1A IN INT1 IN IN IN // IN7 IN6 OUT5 OUT4 OUT3 IN2 IN1 IN0 // 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: On // USART Mode: Asynchronous // USART Baud Rate: 9600 UCSRA=0x00; UCSRB=0x18; UCSRC=0x86; UBRRH=0x00; UBRRL=0x67; // LCD module initialization lcd_init(16); /* switch to writing in Display RAM */ lcd_gotoxy(0,0); lcd_putsf("Projet TEST-51C5"); lcd_gotoxy(0,1); lcd_putsf("Borne 50 m DA-2"); PORTB=0xFF; seconde=0; temps=0; seconde1=0; unite=0; unite_0=0; temps1=0; test=0; var='0'; ENABLE=0; test_segments_1(); 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 afficheur1(4,11,0); // Un caractère afficheur1(5,11,0); // Un caractère // Global enable interrupts #asm("sei") while (1) { // Place your code here //PORTD.3=1; // Reception sur la liaison série : if ( (UCSRA & 0x80) ) // Test de RXC bit7 { var=USART_Receive(); }; if (var == 'G') { test=1; } if (var == 'S') { test=0; } // Test des boutons poussoirs : if (BP1 == 0) { // BP1 : GO ! delay_ms(20); if (BP1 == 0) { test=1; } } if (BP2 == 0) { // BP2 : STOP ! delay_ms(20); if (BP2 == 0) { test=0; } } sprintf(tampon,"Temps = %2d:%2d%3d",seconde,temps,var); lcd_gotoxy(0,2); lcd_puts(tampon); //sprintf(tampon,"PORTD = %1d-%1d-%1d-%1d",PIND.2,PIND.3,PIND.4,PIND.5); sprintf(tampon,"PORTD = %1d-%1d-%1d-%1d",CAPT4,CAPT3,CAPT2,CAPT1); lcd_gotoxy(0,3); lcd_puts(tampon); dizaine = seconde/10; unite = seconde-dizaine*10; dixieme = temps/10; centieme = temps-dixieme*10; if (unite!=unite_0) { USART_Transmit(48+dizaine); // Transmission du code ASCII du "0" (48) + les secondes. USART_Transmit(48+unite); // Transmission du code ASCII du "0" (48) + les secondes. USART_Transmit(13); // Transmission du code ASCII. //USART_Transmit(0x0B); // Transmission du code ASCII. unite_0=unite; } // Afficheur d'adresse 3 if (dizaine == 0) { afficheur1(3,14,0); // Digit D. } else { afficheur1(3,dizaine,0); // Caractère des dizaines. } // Afficheur d'adresse 2 afficheur1(2,unite,1); // Caractère des unités. // Afficheur d'adresse 1 //afficheur1(1,dixieme,0); // Caractère des dixièmes. afficheur1(1,dizaine,0); // Caractère des dixièmes. // Afficheur d'adresse 0 //afficheur1(0,centieme,0); // Caractère des centièmes. afficheur1(0,unite,0); // Caractère des dixièmes. afficheur2(4,0x10+0x08,0); // Caractère = : DIGIT_D+DIGIT_G afficheur2(5,0x80+0x01+0x08+0x20+0x02,0); // Caractère V : DIGIT_F+DIGIT_E+DIGIT_D+DIGIT_B+DIGIT_C; //test_segments_1(); // Gestion des feux tricolore : //test_segments_3(); // 3 = 4 : Rouge droite // 4 = 8 : Jaune droite // 5 = 16 : Vert droite // 4 = 32 : Rouge Gauche // 7 = 64 : Jaune Gauche // 8 = 128 : Vert Gauche //afficheur2(6,4+32,0); // Code : ROUGE //delay_ms(500); //afficheur2(6,8+64,0); // Code : JAUNE //delay_ms(500); //afficheur2(6,16+128,0); // Code : VERT //delay_ms(500); if (unite==1) {afficheur2(6,4+32,0);}; // Code : ROUGE if (unite==2) {afficheur2(6,8+64,0);}; // Code : JAUNE if (unite==3) {afficheur2(6,16+128,0);}; // Code : VERT //PORTD.3=0; }; }