Hi i have been working with pics for a wile now and i have trying to work on a interface to a magnetic card reader for various tasks. i am using the clock, data and the, card-inserted lines to interface. the format uses 5 bits to a byte(4 data, 1 parity) i do not care about parity just yet, i am just trying to get good reads. data and clock are inverted, card-inserted, is active low. i have a panasonic card reader on the first 3 bits of PORTB and a 24x2 LCD in 4-bit mode on PORTA. i have just been trying to get it to display the first 24 bytes of card data, but all i get is non-consistent garbage. i know i will be getting garbage anyway because i am just reading the parity bit with the others, but shouldn't it still read the SAME garbage each time i read the card? i have herd of this sort om things being done before, but nothing in asm.(anyone seen any projects) any help would be greatly appreciated. Code: LIST p=16F648a ;tell assembler what chip we are using include "P16F648a.inc" ;include the defaults for the chip ERRORLEVEL 0, -302 ;suppress bank selection messages __config 0x3D18 ;sets the configuration settings (oscillator type etc.) cblock 0x20 ;start of general purpose registers count ;used in looping routines count1 ;used in delay routine counta ;used in delay routine countb ;used in delay routine templcd ;temp store for 4 bit mode templcd2 lcdtmp bytecount bitcount endc cblock 0x2c carddata endc CARDPORT Equ PORTB LCD_PORT Equ PORTA LCD_TRIS Equ TRISA LCD_RS Equ 0x04 ;LCD handshake lines LCD_RW Equ 0x06 LCD_E Equ 0x07 clk Equ 0x00 dat Equ 0x01 crdin Equ 0x02 org 0x0000 Start movlw 0x07 movwf CMCON ;turn comparators off (make it like a 16F84) bsf STATUS,RP0 movlw 0xff movwf TRISA movlw b'111' movwf TRISB bcf STATUS,RP0 Initialise clrf count clrf PORTA clrf PORTB call LCD_Init Loop btfsc CARDPORT,crdin ;test to see when card is incerted goto $-1 L1 clrw ;if card is in, get w ready movlw carddata movwf FSR movlw 0x18 movwf bytecount Scan movlw 0x04 movwf bitcount S1 btfsc CARDPORT,clk ;wate for clock line to go low goto $-1 btfsc CARDPORT,dat ;see what state data is in bcf STATUS,C ;if high, make 0 btfss CARDPORT,dat bsf STATUS,C ;if low, make 1 rrf W,w ;rotate right one bit btfss CARDPORT,clk ;wate for clock so settle goto $-1 decfsz bitcount,f ;check if byte is 5 bits goto S1 ;if not go back to scan Nextbyte movwf INDF ;load byte into indirect reister incf FSR,f ;point indirect reister to next location decfsz bytecount,f ;see if 24 bytes ave been read goto Scan ;if not, get next byte movlw carddata ;if they are, point indirect register to first byte of card data movwf FSR movlw 0x18 ;load byte count into register movwf bytecount LCD movfw INDF ;load byte from indirect register call LCD_CharD ;send it to lcd incf FSR,f ;load next location into indirect register decfsz bytecount,f ;see if all 24 bytes have been loaded goto LCD ;if not, than send next byte Stop nop goto $-1 ;LCD routines ;Initialise LCD LCD_Init call LCD_Busy ;wait for LCD to settle movlw 0x20 ;Set 4 bit mode call LCD_Cmd movlw 0x28 ;Set display shift call LCD_Cmd movlw 0x06 ;Set display character mode call LCD_Cmd movlw 0x0c ;Set display on/off and cursor command call LCD_Cmd ;Set cursor off call LCD_Clr ;clear display retlw 0x00 ; command set routine LCD_Cmd movwf templcd swapf templcd, w ;send upper nibble andlw 0x0f ;clear upper 4 bits of W movwf LCD_PORT bcf LCD_PORT, LCD_RS ;RS line to 1 call Pulse_e ;Pulse the E line high movf templcd, w ;send lower nibble andlw 0x0f ;clear upper 4 bits of W movwf LCD_PORT bcf LCD_PORT, LCD_RS ;RS line to 1 call Pulse_e ;Pulse the E line high call LCD_Busy retlw 0x00 LCD_CharD addlw 0x30 ;add 0x30 to convert to ASCII LCD_Char movwf templcd swapf templcd, w ;send upper nibble andlw 0x0f ;clear upper 4 bits of W movwf LCD_PORT bsf LCD_PORT, LCD_RS ;RS line to 1 call Pulse_e ;Pulse the E line high movf templcd, w ;send lower nibble andlw 0x0f ;clear upper 4 bits of W movwf LCD_PORT bsf LCD_PORT, LCD_RS ;RS line to 1 call Pulse_e ;Pulse the E line high call LCD_Busy retlw 0x00 LCD_Line1 movlw 0x80 ;move to 1st row, first column call LCD_Cmd retlw 0x00 LCD_Line2 movlw 0xc0 ;move to 2nd row, first column call LCD_Cmd retlw 0x00 LCD_Line1W addlw 0x80 ;move to 1st row, column W call LCD_Cmd retlw 0x00 LCD_Line2W addlw 0xc0 ;move to 2nd row, column W call LCD_Cmd retlw 0x00 LCD_CurOn movlw 0x0d ;Set display on/off and cursor command call LCD_Cmd retlw 0x00 LCD_CurOff movlw 0x0c ;Set display on/off and cursor command call LCD_Cmd retlw 0x00 LCD_Clr movlw 0x01 ;Clear display call LCD_Cmd retlw 0x00 Pulse_e bsf LCD_PORT, LCD_E nop bcf LCD_PORT, LCD_E retlw 0x00 LCD_Busy bsf STATUS, RP0 ;set bank 1 movlw 0x0f ;set Port for input movwf LCD_TRIS bcf STATUS, RP0 ;set bank 0 bcf LCD_PORT, LCD_RS ;set LCD for command mode bsf LCD_PORT, LCD_RW ;setup to read busy flag bsf LCD_PORT, LCD_E swapf LCD_PORT, w ;read upper nibble (busy flag) bcf LCD_PORT, LCD_E movwf templcd2 bsf LCD_PORT, LCD_E ;dummy read of lower nibble bcf LCD_PORT, LCD_E btfsc templcd2, 7 ;check busy flag, high = busy goto LCD_Busy ;if busy check again bcf LCD_PORT, LCD_RW bsf STATUS, RP0 ;set bank 1 movlw 0x00 ;set Port for output movwf LCD_TRIS bcf STATUS, RP0 ;set bank 0 return ;end of LCD routines ;Delay routines Long_Delay call Delay255 call Delay255 call Delay255 call Delay255 return Delay255 movlw 0xff ;delay 255 mS goto d0 Delay100 movlw d'100' ;delay 100mS goto d0 Delay50 movlw d'50' ;delay 50mS goto d0 Delay20 movlw d'20' ;delay 20mS goto d0 Delay10 movlw d'10' ;delay 10mS goto d0 Delay1 movlw d'1' ;delay 1mS goto d0 Delay5 movlw 0x05 ;delay 5.000 ms (4 MHz clock) d0 movwf count1 d1 movlw 0xC7 movwf counta movlw 0x01 movwf countb Delay_0 decfsz counta, f goto $+2 decfsz countb, f goto Delay_0 decfsz count1 ,f goto d1 retlw 0x00 ;end of Delay routines end -- View this message in context: http://www.nabble.com/Simple-Magnetic-Card-reader-tp18304492p18304492.html Sent from the PIC - [PIC] mailing list archive at Nabble.com. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist