/***************************************************** Project :gate simulator Version :1.0 Date : 2008/02/15 Author : rasool Company : shiri Chip type : ATmega16 Program type : Application Clock frequency : 8.000000 MHz Memory model : Small External SRAM size : 0 Data Stack size : 256 *****************************************************/ #include #include #include #asm .equ __lcd_port=0x1B ;PORTA #endasm #include void main(void) { char display1[16]; char display2[16]; char f[5]; bit y=0,d=1,n=0; int flag=0; PORTA=0x08; DDRA=0x08; PORTD=0x00; DDRD=0x40; lcd_init(16); while (1) { delay_ms(350); if(PIND.3==1) { delay_ms(100); if(PIND.3==1) flag++; if (flag>7) flag=7; } if(PIND.2==1) { delay_ms(100); if(PIND.2==1) flag--; if (flag<1) flag=1; } switch (flag) { case 0: { if (d==1) { lcd_clear(); lcd_putsf(" gate simulator "); lcd_gotoxy(0,1); lcd_putsf(" ali heydari "); d=0; } break; } case 1: { y=PINB.0&PINB.1; sprintf(f,"and"); d=1; break; } case 2: { y=PINB.0|PINB.1; sprintf(f,"or"); d=1; break; } case 3: { y=PINB.0^PINB.1; sprintf(f,"xor"); d=1; break; } case 4: { y=PINB.0&PINB.1; y=~y; sprintf(f,"nand"); d=1; break; } case 5: { y=PINB.0|PINB.1; y=~y; sprintf(f,"nor"); d=1; break; } case 6: { y=PINB.0^PINB.1; y=~y; sprintf(f,"xnor"); d=1; break; } case 7: { y=~PINB.0; sprintf(f,"not"); d=1; n=1; break; } }; if (d==1) { PORTD.6=y; lcd_clear(); sprintf(display1,"f%i= %s mode ",flag,f); lcd_puts(display1); lcd_gotoxy(0,1); if (n==0)sprintf(display2,"x=%i , y=%i , f=%i",PINB.0,PINB.1,y); if (n==1) { sprintf(display2,"x=%i , f=%i",PINB.0,y); n=0; } lcd_puts(display2); d=0; } }; }