/***************************************************** 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 : Borne Départ Arrêter sur 50 m. Version : 1 Date : 24/03/2009 Author : Geoffrey GRANGER Company : IUT Tours Comments: Département GEII 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 BP4 PINB.6 #define BP3 PINB.7 #define BP2 PIND.6 #define BP1 PIND.0 #define Capteur1 PIND.2 #define Capteur2 PIND.3 #define ENABLE PORTD.7 //tableau adressage SS flash const unsigned char adresse_constant[16] = {0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15}; //tableau de croisement des bits d'adresse //tableau lettrage flash const unsigned char valeur_constant[] = { 0xEE,0x28,0x76,0x7C,0xB8,0xDC,0xDE,0x68,0xFE,0xFC, //0123456789 0xFA,0x9E,0x16,0x3E,0xD6,0xD2,0xCE,0xBA,0x82,0x2E, //abcdefghij 0x9A,0x86,0x1A,0x1A,0xEE,0xF2,0xF8,0x12,0xDC,0x96, //klmnopqrst 0xAE,0x0E,0xB6,0xBA,0xB2,0x76,0x04, //uvwxyz_ 0,1,2,4,8,16,32,64,128,256}; //37->46 // Variables globales unsigned char tampon[20],seconde=0,secondex=0,secondep=0,centms=0,dixms=0,ms=0,dms=0,cms=0; unsigned char tab[3]; int cap1=0,cap2=0,var1=1,var2=0; unsigned int centainev=0,dizainev=0,unitev=0,centiemev=0; unsigned int Vitesse=0; float Vitesse1=0; unsigned int T1=0,T2=0,T=0; int i,j,k; int b1=0,b2=0,b3=0 ,b4=0; // Fonctions // Affiche une valeur sur 8 bits à l'adresse de l'afficheur : void afficheur(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; } //Test du grand afficheur void test_aff(void) { for(k=0;k<3;k++) { for(j=37;j<47;j++) { for(i=0;i<4;i++) { afficheur(i,j,0); delay_ms(50); } } } } //Test de boutons void test_bouton(void) { if(BP1==0) { b2=b3=b4=0; lcd_clear(); b1=1; } if(BP2==0) { b1=b3=b4=0; lcd_clear(); b2=1; } if(BP3==0) { b1=b2=b4=0; lcd_clear(); b3=1; test_aff(); } if(BP4==0) { b1=b2=b3=0; lcd_clear(); b4=1; } } //Affiche les informations sur l'écran LCD void affichage_lcd(void) { if(b1==1) { sprintf(tampon," Tps= %2d:%d%d ",seconde,centms,dixms); lcd_gotoxy(0,0); lcd_puts(tampon); sprintf(tampon," T= %4d ms ",T/10); lcd_gotoxy(0,1); lcd_puts(tampon); sprintf(tampon," Vit= %4d.%dkm/h",Vitesse/10,Vitesse%10); lcd_gotoxy(0,2); lcd_puts(tampon); lcd_gotoxy(0,3); lcd_putsf("4=> Retour Menu "); } if(b2==1) { sprintf(tampon,"1=%4d|2=%4d|%d%d",T1/10,T2/10,cap1,cap2); lcd_gotoxy(0,0); lcd_puts(tampon); sprintf(tampon,"T=%4d|Tps=%2d:%d%d",T/10,seconde,centms,dixms); lcd_gotoxy(0,1); lcd_puts(tampon); sprintf(tampon," Vit= %4d.%dkm/h",Vitesse/10,Vitesse%10); lcd_gotoxy(0,2); lcd_puts(tampon); lcd_gotoxy(0,3); lcd_putsf("4=> Retour Menu "); } if(b3==1) { lcd_gotoxy(0,0); lcd_putsf(">Test Grand Aff<"); lcd_gotoxy(0,1); if(k==0) { lcd_putsf(" EN COURS "); lcd_gotoxy(0,2); } if((k==3)&&(i==4)) { lcd_putsf(" FINI "); lcd_gotoxy(0,2); } lcd_putsf(""); lcd_gotoxy(0,3); lcd_putsf("4=> Retour Menu "); } if(b4==1) { lcd_gotoxy(0,0); lcd_putsf("=====>Menu<====="); lcd_gotoxy(0,1); lcd_putsf("1=> Aff. normal "); lcd_gotoxy(0,2); lcd_putsf("2=> Aff. detail "); lcd_gotoxy(0,3); lcd_putsf("3=> Test Grd Aff"); } } //Calcul et affiche la vitesse void cal_aff_vitesse(void) { T=T2-T1; Vitesse1=18000/(T/(6)); Vitesse=(int)Vitesse1; centainev = Vitesse/1000; dizainev = (Vitesse-centainev*1000)/100; unitev = (Vitesse-(centainev*1000+dizainev*100))/10; centiemev = Vitesse-(centainev*1000+dizainev*100+unitev*10); afficheur(0,centainev,0); afficheur(1,dizainev,0); afficheur(2,unitev,1); afficheur(3,centiemev,0); } // External Interrupt 0 service routine interrupt [EXT_INT0] void ext_int0_isr(void) { if((var1==1)&&(var2==0)) { T1=(centms*1000+dixms*100+ms*10+dms); secondex=seconde; var1=0; } cap1=1; tab[0]=83; } // External Interrupt 1 service routine interrupt [EXT_INT1] void ext_int1_isr(void) { if((var1==0)&&(var2==0)) { T2=(centms*1000+dixms*100+ms*10+dms); if(seconde>secondex) { T2=((seconde-secondex)*10000+centms*1000+dixms*100+ms*10+dms); } cal_aff_vitesse(); var1=1; var2=1; } cap2=1; tab[1]=83; } // Timer 1 output compare A interrupt service routine interrupt [TIM1_COMPA] void timer1_compa_isr(void) { cms++; if(cms>9) { cms=0; dms++; if(dms>9) { dms=0; ms++; if(ms>9) { ms=0; dixms++; if (dixms>9) { dixms=0; centms++; if (centms>9) { centms=0; seconde++; cap1=0; cap2=0; tab[0]=71; tab[1]=71; if(var2==1) { secondep=0; var2=2; } if(var2==2) { secondep++; } if(secondep>3) { var2=0; } if (seconde>59) { seconde=0; } } } } } } } interrupt [13] void usart_txcomplete(void) //fonction interruption avec usart { UDR=tab[k]; //UDR est la donnée envoyée k++; //On incrémente k if (k==3) k=0; //retour à 0 après avoir envoyer toutes les données } void main(void) { // Declare your local variables here // 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=Out Func3=In Func2=In Func1=In Func0=In // State7=0 State6=T State5=T State4=0 State3=T State2=T State1=T State0=T PORTD=0x00; // OC1A BP2 IN IN Cap2 Cap1 IN BP1 DDRD=0x80; // OUT7 IN6 OUT5 OUT4 IN3 IN2 IN1 IN ENABLE=1; // 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: 16000,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: Off // Compare B Match Interrupt: Off TCCR1A=0x40; TCCR1B=0x09; TCNT1H=0x00; TCNT1L=0x00; ICR1H=0x00; ICR1L=0x00; OCR1AH=0x00; // Base de 0temps = 16 MHz, soit 62.5 ns. OCR1AL=0xA0; // Interruption quand on arrive à 160 fois (0x00A0 soit 10 cms) 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: On // INT0 Mode: Falling Edge // INT1: On // INT1 Mode: Falling Edge // INT2: Off GICR|=0xC0; MCUCR=0x0A; MCUCSR=0x00; GIFR=0xC0; */ // External Interrupt(s) initialization // INT0: On // INT0 Mode: Rising Edge // INT1: On // INT1 Mode: Rising Edge // INT2: Off GICR|=0xC0; MCUCR=0x0F; MCUCSR=0x00; GIFR=0xC0; // 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 */ //Initialisation afficheur(0,36,0); // Un caractère afficheur(1,16,0); // Un caractère afficheur(2,0,0); // Un caractère afficheur(3,36,0); // Un caractère lcd_gotoxy(0,0); lcd_putsf("Projet Etude&Rea"); lcd_gotoxy(0,1); lcd_putsf("__Borne 50m DA__"); lcd_gotoxy(0,2); lcd_putsf("Borne d'Arrivee"); lcd_gotoxy(0,3); lcd_putsf("Rouzies__Granger"); delay_ms(2000); lcd_clear(); lcd_gotoxy(0,0); lcd_putsf("=====>Menu<====="); lcd_gotoxy(0,1); lcd_putsf("1=> Aff. normal "); lcd_gotoxy(0,2); lcd_putsf("2=> Aff. detail "); lcd_gotoxy(0,3); lcd_putsf("3=> Test Grd Aff"); PORTB=0xFF; ENABLE=0; // Global enable interrupts #asm("sei") while (1) { // Place your code here test_bouton(); affichage_lcd(); } }