/*http://www.hpinfotech.ro e-mail:office@hpinfotech.ro Project : Carte Relais 220V *8 Version : Date : 20/10/2010 Author : Fabien FARIN Company : IUT Tours Comments: Chip type : ATmega8535 Program type : Application Clock frequency : 16,000000 MHz Memory model : Small External SRAM size : 0 Data Stack size : 128 *****************************************************/ #include // Alphanumeric LCD Module functions #asm .equ __lcd_port=0x15 ;PORTC #endasm #include // Standard Input/Output functions #include #define R1 PORTA.0 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; } int NbRecu=0; unsigned char USARTR[2]; unsigned char Data[2]; int i=0; unsigned char tampon[20]; int Aa,Ab,Ac,Ad,Ae,Af,Ag,Ah; int Maintien=0; void main(void) { Aa=Ab=Ac=Ad=Ae=Af=Ag=Ah=0; // 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=In Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=T State4=P State3=P State2=P State1=P State0=P PORTB=0x1F; DDRB=0x00; // 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=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 PORTD=0x00; DDRD=0x00; // 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: Timer 1 Stopped // Mode: Normal top=FFFFh // OC1A output: Discon. // OC1B output: Discon. // Noise Canceler: Off // Input Capture on Falling Edge TCCR1A=0x00; TCCR1B=0x00; TCNT1H=0x00; TCNT1L=0x00; ICR1H=0x00; ICR1L=0x00; OCR1AH=0x00; OCR1AL=0x00; 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=0x00; // USART initialization // Communication Parameters: 8 Data, 1 Stop, No Parity // USART Receiver: On // USART Transmitter: On // USART Mode: Asynchronous // USART Baud rate: 19200 UCSRA=0x00; UCSRB=0x18; UCSRC=0x86; UBRRH=0x00; UBRRL=0x33; // 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); while (1) { if(NbRecu==2) { Data[0]=USARTR[0]; Data[1]=USARTR[1]; lcd_gotoxy(8,3); sprintf(tampon,"%c%c",Data[0],Data[1]); lcd_puts(tampon); NbRecu=0; } else { USARTR[NbRecu]=USART_Receive(); NbRecu=NbRecu+1; } switch(Data[0]) //effectue les actions { case 'A': { switch(Data[1]) { case'1': { PORTA=!PORTA&0x01; Aa=Ab=Ac=Ad=Ae=Af=Ag=Ah=1; } break; } } break; } /* lcd_gotoxy(0,0); sprintf(tampon,"Fabien FARIN CR1"); lcd_puts(tampon); lcd_gotoxy(i,1); lcd_putchar('^'); lcd_gotoxy(i,3); lcd_putchar('^'); lcd_gotoxy(i,1); lcd_gotoxy(0,2); sprintf(tampon,"%d%d%d%d%d%d%d%d",Aa,Ab,Ac,Ad,Ae,Af,Ag,Ah); lcd_puts(tampon); if((PORTB!=0x00)&&(Maintien==0)) { if(PORTB==!0x01)i=i+1; if(PORTB==!0x04)i=i-1; if(i<0)i=8; if(i>8)i=0; Maintien=1; lcd_clear(); } if((PORTB=0x00)&&(Maintien==1))Maintien=0; */ }; }