/********************************************* Chip type : AT90S8535 Clock frequency : 8,000000 MHz Memory model : Small Internal SRAM size : 512 External SRAM size : 0 Data Stack size : 128 Board: Avr-Ctrl V1.0 http://www.mikrocontroller.com 2002 Holger Buss *********************************************/ #include <90s8535.h> // Alphanumeric LCD Module functions #asm .equ __lcd_port=0x15 #endasm #include // Standard Input/Output functions #include #include #define RESET PORTD.5 #define CLOCK PORTD.6 #define DATA_IN PIND.3 #define DATA_OUT PORTD.3 #define READ DDPD &= ~0b00001000 #define WRITE DDPD |= 0b00001000 unsigned char text[20]; unsigned char Memory[33]; #define TAKT { CLOCK = 1; delay_us(10); CLOCK = 0; delay_us(10);} flash unsigned int Tabelle[] = {0,0,300,150,600,1200,6000,5000,0,0,0,0,0,0,0,0,0}; unsigned char read_nibble() { unsigned char temp = 0,j; unsigned char maske = 0x08; for(j=0;j<4;j++) // ident (0-7) { if(DATA_IN) temp |= maske; TAKT; maske /= 2; } return(temp); } unsigned char Mirror(unsigned char input) { unsigned char temp = 0,j; unsigned char maske = 0x01; unsigned char maske2 = 0x08; for(j=0;j<4;j++) // ident (0-7) { if(input & maske) temp |= maske2; maske *= 2; maske2 /= 2; } return(temp); } unsigned char CntBits(unsigned char input) { unsigned char temp = 0,j; unsigned char maske = 0x01; for(j=0;j<4;j++) // ident (0-7) { if(input & maske) temp++; maske *= 2; } return(temp); } // Declare your global variables here void main(void) { // Declare your local variables here unsigned char i,j; // Input/Output Ports initialization // Port A PORTA=0x00; DDRA=0x00; // Port B PORTB=0x00; DDRB=0x00; // Port C PORTC=0x00; DDRC=0x00; // Port D PORTD=0xff; DDRD =0b01100000; // Timer/Counter 0 initialization // Clock source: System Clock // Clock value: Timer 0 Stopped // Mode: Output Compare // OC0 output: Disconnected TCCR0=0x00; TCNT0=0x00; // Timer/Counter 1 initialization // Clock source: System Clock // Clock value: Timer 1 Stopped // Mode: Output Compare // OC1A output: Discon. // OC1B output: Discon. // Noise Canceler: Off // Input Capture on Falling Edge TCCR1A=0x00; TCCR1B=0x00; TCNT1H=0x00; TCNT1L=0x00; OCR1AH=0x00; OCR1AL=0x00; OCR1BH=0x00; OCR1BL=0x00; // Timer/Counter 2 initialization // Clock source: System Clock // Clock value: Timer 2 Stopped // Mode: Output Compare // OC2 output: Disconnected TCCR2=0x00; ASSR=0x00; TCNT2=0x00; OCR2=0x00; // External Interrupt(s) initialization // INT0: Off // INT1: Off GIMSK=0x00; MCUCR=0x00; // Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x00; // UART initialization // Communication Parameters: 8 Data, 1 Stop, No Parity // UART Receiver: On // UART Transmitter: On // UART Baud rate: 9600 UCR=0x18; UBRR=0x33; // Analog Comparator initialization // Analog Comparator: Off // Analog Comparator Input Capture by Timer/Counter 1: Off ACSR=0x80; // LCD module initialization lcd_init(16); lcd_putsf("Chipcard-reader "); while (1) { // Place your code here RESET = 1; TAKT; RESET = 0; lcd_putsf("read ..."); for(i=0;i<32;i++) Memory[i] = read_nibble(); // read the byte from address AAh { lcd_clear(); lcd_gotoxy(0,0); sprintf(text,"Ident: %1X%1X \0",Memory[0],Memory[1]); lcd_puts(text); sprintf(text,"Country: %1X%1X \0",Memory[2],Memory[3]); lcd_gotoxy(0,1); lcd_puts(text); while(!PINA.7); delay_ms(20); while(PINA.7); ////////////////////////////////////////////////////////////// lcd_clear(); sprintf(text,"Value: %u ",Tabelle[Mirror(Memory[8])]); lcd_puts(text); { unsigned int value; value = (unsigned int) CntBits(Memory[16]) * 4096 + (unsigned int) CntBits(Memory[17]) * 4096; value += (unsigned int) CntBits(Memory[18]) * 512 + (unsigned int) CntBits(Memory[19]) * 512; value += (unsigned int) CntBits(Memory[20]) * 64 + (unsigned int) CntBits(Memory[21]) * 64; value += (unsigned int) CntBits(Memory[22]) * 8 + (unsigned int) CntBits(Memory[23]) * 8; value += (unsigned int) CntBits(Memory[24]) * 1 + (unsigned int) CntBits(Memory[25]) * 1; sprintf(text,"Monney: %u ",value); lcd_gotoxy(0,1); lcd_puts(text); } ////////////////////////////////////////////////////////////// while(!PINA.7); delay_ms(20); while(PINA.7); lcd_clear(); sprintf(text,"Serial: %1X%1X%1X%1X%1X ",Mirror(Memory[15]),Mirror(Memory[14]),Mirror(Memory[13]),Mirror(Memory[12]),Mirror(Memory[11])); lcd_puts(text); sprintf(text,"Year: %1X.%1X ",Mirror(Memory[10]),Mirror(Memory[9])); lcd_gotoxy(0,1); lcd_puts(text); while(!PINA.7); delay_ms(20); while(PINA.7); } delay_ms(500); lcd_clear(); }; }