Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 29, 2024, 02:52:10 14:52


Login with username, password and session length


Pages: [1]
Print
Author Topic: Probleme "echo" when i send data  (Read 3624 times)
0 Members and 1 Guest are viewing this topic.
racattac13
Guest
« on: June 30, 2007, 05:40:57 17:40 »

Hi,

in first sorry for my english....

I have a problem with my smart card 16f877 when I send data , it repeat the same data   :

example :
when i send AAAAAAA with my card reader to my card , he must to response only BB  , but it response AAAAAAABB

Here is the sendbyte function   (i use PCWH compiler )
main()
{
......
sendByte("0xBB");
......
}
Code:

void sendByte(int iSendData)
{

int iParity;
int iCtr;
int iPauseCtr;

#asm

movlw 0x32 ; Pause for 170 ?s
call Pause ; call Pause
bcf PORTB,7 ; Send start bit in RB7

movlw 0x7F
tris PORTB ; TRIS PORB with 01111111 (0x7F)

clrf iParity ; Initialize Parity to 0

movlw 0x08
movwf iCtr ; Initialize 8 to counter to send 8 data bits

send_loop:

call Std_pause ; Pause for 93 ?s (at 9600 bps)

rrf iSendData,f
rrf iSendData,W
andlw 0x80

xorwf iParity,f ; Calculate Parity

xorwf PORTB,W
xorwf PORTB,f

decfsz iCtr,f ; Decrement Data Bit counter

goto send_loop ; Loop

call Std_pause ; Pause

movf iParity,W ; Send Parity

xorwf PORTB,W
xorwf PORTB,f

call Std_pause

movlw 0xFF
tris PORTB

movlw 0x3E
goto Pause ; Pause 0x3E
return
Std_pause:
movlw 0x1A ; Standard Pause Value

Pause:
movwf iPauseCtr ; Initialize iPauseCounter with value of W Register

Pause_loop:
decfsz iPauseCtr,f ; Decrement Pause Counter
goto Pause_loop

#endasm

}

I have read many topic but I found nothing.
Please help me , how can i flush input data register before response Huh?
Many thanks in advance.

Regards,
Logged
robban
Senior Member
****
Offline Offline

Posts: 265

Thank You
-Given: 34
-Receive: 38


Warrior


WWW
« Reply #1 on: June 30, 2007, 11:36:30 23:36 »

Tricky, that one...
To start with, does the "tris" command comply with the 16F877? Have a look in the dataheet.
Microchip recommend not to use it for upward compatibility.Use "movwf PORTB" instead. And why do You say it responds with "AAAAAAABB" when You only send "BB" as Byte, not Char? You must suppy more of the code. Otherwise, in assembler You can always flush(zero out) a register with "xor reg,reg". (or in MPASM .asm CLRF or CLRW.)
Well...?
« Last Edit: July 02, 2007, 05:22:37 17:22 by robban » Logged

Code Warrior
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC