/***************************************************** 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 car, carRecu; flash const unsigned char adresse_constant[16] = {0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15}; 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; } 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 afficheur1(unsigned char adresse,unsigned char caractere, unsigned char point) { if (point == 1) { PORTA=(caractere | 0x01); // 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; } void Feu( int flag) { if( flag == 1) { afficheur1(0,0x12,0); delay_ms(500); afficheur1(0,0x00,0); delay_ms(500); } if( flag == 2) { afficheur1(0,0x00,0); delay_ms(500); afficheur1(0,0x09,0); delay_ms(500); } } 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 while (1) { int i,flag; ENABLE=0; if( car == 'M') carRecu=USART_Receive(); if(flag!=2 || carRecu == 'F' || flag == 1) flag=1; if( CaptD == 0 && CaptA == 1) { car = 'D'; USART_Transmit(car); carRecu=USART_Receive(); if(carRecu == 'C') { for(i=0;i<10;i++) { if( CaptD == 0 && CaptA == 1) { car = 'P'; USART_Transmit(car); afficheur1(0,0x09,0); delay_ms(500); afficheur1(0,0x1B,0); delay_ms(500); } else { car = 'A'; USART_Transmit(car); i=10; flag=2; } } } } if( car == 'P' && CaptD == 0 && CaptA == 1) { car = 'R'; afficheur1(0,0x24,0); flag=2; USART_Transmit(car); do { if( CaptA == 0) { car = 'M'; USART_Transmit(car); } } while( CaptD == 0 && car != 'M'); } if( car == 'M') { do { car='x'; Feu(flag); carRecu=USART_Receive(); } while( carRecu == 'C' ); flag=1; } Feu(flag); } }