list p=16f877 include p16f877.inc count1 equ 0x20 ;Zählervariblen count2 equ 0x21 count3 equ 0x22 lo_byte0 equ 0x30 ;Ergebniszelle hi_byte0 equ 0x31 ;Ergebniszelle lo_byte1 equ 0x32 ;Ergebniszelle hi_byte1 equ 0x33 ;Ergebniszelle lo_byte2 equ 0x34 ;Ergebniszelle hi_byte2 equ 0x35 ;Ergebniszelle lo_byte3 equ 0x36 ;Ergebniszelle hi_byte3 equ 0x37 ;Ergebniszelle lo_byte4 equ 0x38 ;Ergebniszelle hi_byte4 equ 0x39 ;Ergebniszelle lo_byte5 equ 0x3A ;Ergebniszelle hi_byte5 equ 0x3B ;Ergebniszelle lo_byte6 equ 0x3C ;Ergebniszelle hi_byte6 equ 0x3D ;Ergebniszelle ;Portbelegung: ;PortA: Als Eingang, unbenutzt ;PortB: Als Eingang, unbenutzt ;PortC bit 0: CE1 ; 1: CD1 ; 2: RESET ; 3: OE ; 4: WE ; 5: READY ; 6: ; 7: ;PortD bit 0: D0 ; 1: D1 ; 2: D2 ; 3: D3 ; 4: D4 ; 5: D5 ; 6: D6 ; 7: D7 ;PortE bit 0: A0 ; 1: A1 ; 2: A2 A0 equ D'0' ;Namen der BITs A1 equ D'1' A2 equ D'2' CE1 equ D'0' CD1 equ D'1' RESET equ D'2' OE equ D'3' WE equ D'4' RDY equ D'5' org 0x00 init_pic bcf STATUS,RP0 ;Bank 0 bcf STATUS,RP1 ;Ports zur Sicherheit löschen bsf STATUS,RP0 ;Bank1 movlw 0xFF ;Erstmal alle Ports als Eingang movwf TRISA movwf TRISB movwf TRISC movwf TRISD movwf TRISE movlw 0x00 ;Port D und E als Ausgang movwf TRISD movwf TRISE bcf TRISC,CE1 ;Steuersignale Ausgang bcf TRISC,RESET bcf TRISC,OE bcf TRISC,WE movlw 0x06 movwf ADCON1 ;Digitaler Output movlw 0xA0 movwf OPTION_REG bcf STATUS,RP0 ;Bank0 clrf PORTA ;Zur Sicherheit alle Ports löschen clrf PORTB clrf PORTC clrf PORTD clrf PORTE clrf lo_byte0 clrf hi_byte0 clrf lo_byte1 clrf hi_byte1 clrf lo_byte2 clrf hi_byte2 clrf lo_byte3 clrf hi_byte3 clrf lo_byte4 clrf hi_byte4 clrf lo_byte5 clrf hi_byte5 clrf lo_byte6 clrf hi_byte6 init_cf bsf PORTC,OE ;Signale setzen bsf PORTC,WE nop nop nop nop goto main ;Generiert halbe Sekunde delay movlw D'10' ;10 * 250 * 200us = 0,5s movwf count3 set2 movlw D'250' ;250 * 200 us = 50 ms movwf count2 set1 movlw D'250' ;200us bei 20 MHz (5 MHz) movwf count1 loop nop decfsz count1,F goto loop decfsz count2,F goto set1 decfsz count3,F goto set2 return ;Warteschleife bis Karte fertig chk_ready btfss PORTC,RDY goto chk_ready nop return main nop nop BSF PORTC,RESET ;Reset durchführen NOP NOP nop BCF PORTC,RESET NOP NOP nop call delay ;halbe Sekunde warten bsf PORTE,A0 ;Adressleitungen setzen bsf PORTE,A1 ;111 ->Comandregiser ansprechen bsf PORTE,A2 bsf STATUS,RP0 clrf TRISD ;Datenport als Ausgang bcf STATUS,RP0 ;Schreiben movlw 0xEC ;Identifycomand movwf PORTD call chk_ready ;Karte fertig? BCF PORTC,WE ;Schreibimpuls NOP NOP NOP BSF PORTC,WE CALL chk_ready ;Karte fertig? ;Lesen und Speichern von Word 0 bis 6 BSF STATUS,RP0 movlw 0xFF ;PortD als input movwf TRISD BCF STATUS,RP0 NOP CLRF PORTD NOP bcf PORTE,A0 ;Adressleitungen löschen bcf PORTE,A1 bcf PORTE,A2 nop nop nop BCF PORTC,OE ;Leseimpuls NOP NOP NOP movf PORTD,W ;PortD speichern movwf lo_byte0 NOP BSF PORTC,OE ;Leseimpuls wieder High NOP NOP nop BCF PORTC,OE ;Leseimpuls NOP NOP NOP movf PORTD,W ;PortD speichern movwf hi_byte0 NOP BSF PORTC,OE ;Leseimpuls wieder High NOP NOP nop BCF PORTC,OE ;Leseimpuls NOP NOP NOP movf PORTD,W ;PortD speichern movwf lo_byte1 NOP BSF PORTC,OE ;Leseimpuls wieder High NOP NOP nop BCF PORTC,OE ;Leseimpuls NOP NOP NOP movf PORTD,W ;PortD speichern movwf hi_byte1 NOP BSF PORTC,OE ;Leseimpuls wieder High NOP NOP nop BCF PORTC,OE ;Leseimpuls NOP NOP NOP movf PORTD,W ;PortD speichern movwf lo_byte2 NOP BSF PORTC,OE ;Leseimpuls wieder High NOP NOP nop BCF PORTC,OE ;Leseimpuls NOP NOP NOP movf PORTD,W ;PortD speichern movwf hi_byte2 NOP BSF PORTC,OE ;Leseimpuls wieder High NOP NOP nop BCF PORTC,OE ;Leseimpuls NOP NOP NOP movf PORTD,W ;PortD speichern movwf lo_byte3 NOP BSF PORTC,OE ;Leseimpuls wieder High NOP NOP nop BCF PORTC,OE ;Leseimpuls NOP NOP NOP movf PORTD,W ;PortD speichern movwf hi_byte3 NOP BSF PORTC,OE ;Leseimpuls wieder High NOP NOP nop BCF PORTC,OE ;Leseimpuls NOP NOP NOP movf PORTD,W ;PortD speichern movwf lo_byte4 NOP BSF PORTC,OE ;Leseimpuls wieder High NOP NOP nop BCF PORTC,OE ;Leseimpuls NOP NOP NOP movf PORTD,W ;PortD speichern movwf hi_byte4 NOP BSF PORTC,OE ;Leseimpuls wieder High NOP NOP nop BCF PORTC,OE ;Leseimpuls NOP NOP NOP movf PORTD,W ;PortD speichern movwf lo_byte5 NOP BSF PORTC,OE ;Leseimpuls wieder High NOP NOP nop BCF PORTC,OE ;Leseimpuls NOP NOP NOP movf PORTD,W ;PortD speichern movwf hi_byte5 NOP BSF PORTC,OE ;Leseimpuls wieder High NOP NOP nop BCF PORTC,OE ;Leseimpuls NOP NOP NOP movf PORTD,W ;PortD speichern movwf lo_byte6 NOP BSF PORTC,OE ;Leseimpuls wieder High NOP NOP nop BCF PORTC,OE ;Leseimpuls NOP NOP NOP movf PORTD,W ;PortD speichern movwf hi_byte6 NOP BSF PORTC,OE ;Leseimpuls wieder High NOP NOP nop goto main end