connecting pic 16f877A with sm630 fingerprint sanner

Status
Not open for further replies.

wishes

Newbie level 3
Joined
Sep 26, 2010
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,339
hello ,
I need to communicate between pic16f877A and sm630 fingerprint scanner that communicate in serial UART I have written sample code as test for the sm630 to add finger by sending the first packet and waiting for the replay but unfortunately it dose not work in mikrobasic
can any one help me ...

code
***************************************

program test1ForSm630
dim sum as word
dim head1 ,ii, head2,check, kp ,sum1,sum2,j,a2,d2, checkr, number,m, OK as byte
dim position as char[20]
dim r2 as char[20]


main:
j=2
sum = 0
sum1 =0
sum2 = 0
head1 =0x4D ' define the head of the packet
head2 =0x58 ' define the second byte of the head of the packet
TRISD =255
PORTD =255
TRISC.0 = 0
TRISC.1 = 0
PORTC.1 = 0
PORTC.0 = 0
Usart_Init(57600) ' 57600bps communiaction bud rate for the sm630
adcon1 = 255 ' configure RA5 pin as digital I/O
Keypad_Init(PORTD)
PORTB = 0
Lcd_Init(PORTB) ' Initialize LCD on PORTC
Lcd_Cmd(LCD_CLEAR) ' Clear display
Lcd_Cmd(LCD_CURSOR_OFF) ' Cursor off
ADCON1=7 'to disable the digial pins on PORT A
while true
PORTC.1 = 0
PORTC.0 = 0
OK = 0
check = 0
''''''''''' ADD Finger button ''''''''

'''''' send the add finger packet to sm630 '''''''
Usart_Write(0x4D)
check = check + head1
Usart_Write(head2)
check = check + 0X58
Usart_Write(0x10)
check = check + 0X10
Usart_Write(0x03)
check = check + 0X03
Usart_Write(0x40)
check = check + 0X40
Usart_Write(0x00)
check = check +0x00
Usart_Write(0x00)
check = check + 0x00
Usart_Write(check)

'''''' after sending the packet we wait for response if the packet is recived correctly '''''
checkr = 0
while true
if Usart_Data_Ready = 1 then ' If data is received
a2 = Usart_Read ' Read received data
if a2 = head1 then
r2[d2] =a2
checkr = checkr+a2
d2 = d2 + 1
break
else
PORTC.0 = 1 ' red led will blink ERROR
end if
end if
'''' timer cheak ''''''''''''
'''''''''''''''''''''''''''''
wend
while true
if Usart_Data_Ready = 1 then ' If data is received
a2 = Usart_Read ' Read received data
if a2 = head2 then
r2[d2] =a2
checkr = checkr+a2
d2 = d2 + 1
break
else
PORTC.0 = 1 ' red led will blink ERROR
end if
end if
'''' timer cheak ''''''''''''
'''''''''''''''''''''''''''''
wend
while true
if Usart_Data_Ready = 1 then ' If data is received
a2 = Usart_Read ' Read received data
r2[d2] = a2
checkr = checkr+a2
d2 = d2 + 1
break
end if
'''' timer cheak ''''''''''''
'''''''''''''''''''''''''''''
wend
while true
if Usart_Data_Ready = 1 then ' If data is received
a2 = Usart_Read ' Read received data
r2[d2] =a2
number = a2
checkr = checkr+a2
d2 = d2 + 1
break
end if
'''' timer cheak ''''''''''''
'''''''''''''''''''''''''''''
wend
for m =0 to (number-1)
while true
if Usart_Data_Ready = 1 then ' If data is received
a2 = Usart_Read ' Read received data
r2[d2] =a2
checkr = checkr+a2
d2 = d2 + 1
break
end if
'''' timer cheak ''''''''''''
'''''''''''''''''''''''''''''
wend
next m
while true
if Usart_Data_Ready = 1 then ' If data is received
a2 = Usart_Read ' Read received data
r2[d2] =a2
if (checkr = a2) and (r2[4] = 0x01) then
OK = 1
PORTC.1 = 1
else
PORTC.0 = 1
end if
break
end if
'''' timer cheak ''''''''''''
'''''''''''''''''''''''''''''
wend


wend
end.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…