![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
cllunlu
Joined: 30 Jun 2014 Posts: 4
|
Reading Wiegand 26 Data with PIC18F46K22 |
Posted: Thu Jul 03, 2014 7:50 am |
|
|
Hi
I have a problem about reading data of wiegand 26 protocol. I am using PIC18F46K22.
Can you give a lead about this. Can you send sample codes about it. I have written code but failed.
Code is below. I wanna how many received data "0" and data "1".
I read
data0: 25 piece
data1: 1 piece.
Can you help me pls?
#include "lcd_test.c"
#zero_ram
#use delay(crystal=20000000)
#INT_EXT2
void read_wiegandD1()
{
disable_interrupts(INT_EXT2);
if(length_count<26)
{
wie_data[length_count]="1";
data1=data1+1;
length_count=length_count+1;
clear_interrupt(INT_EXT2);
enable_interrupts(INT_EXT2);
}
}
#use delay(crystal=20000000)
#INT_EXT1
void read_wiegandD0()
{
disable_interrupts(INT_EXT1);
if(length_count<26)
{
wie_data[length_count]="0";
data0=data0+1;
length_count=length_count+1;
clear_interrupt(INT_EXT1);
enable_interrupts(INT_EXT1);
}
}
#use delay(crystal=20000000)
void main()
{
board_init();
lcd_init();
lcd_gotoxy(1,1);
printf(lcd_putc, " READ CARD: ");
output_toggle(pin_d5);
delay_ms(2000);
lcd_gotoxy(1,2);
printf(lcd_putc, "CARD ID: ");
data_show();
while(TRUE)
{
output_toggle(pin_d5);
delay_ms(500);
if(length_count>25)
{
length_count=0;
output_high(pin_D5);
data_show();
delay_ms(8000);
}
}
}
#use delay(crystal=20000000)
void data_show()
{
lcd_gotoxy(1,3);
printf(lcd_putc,"Data0: %u",data0);
lcd_gotoxy(1,4);
printf(lcd_putc,"Data1: %u",data1);
}
/**************************************
Function: board_init
Input Arguments:None
Output Arguments: None
Purpose:Initialize the board
**************************************/
/*
#use delay(crystal=20000000)
void board_init(void)
{
set_tris_b(0xFF);
enable_interrupts(INT_EXT2_H2L);
enable_interrupts(INT_EXT1_H2L);
enable_interrupts(GLOBAL);
length_count=0;
} |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9168 Location: Greensville,Ontario
|
|
Posted: Thu Jul 03, 2014 9:41 am |
|
|
couple of hints..
1) when asking for help about a device or protocol you should include a 'link' to the appropriate device.Without that 'we' don't know if it's a simple 5VPIC vs 3V device problem, bus topology error(no pullups), or a coding issue(timing,polarity, etc.)
2) please use the 'code' buttons when posting code as it 'magically' makes the code a LOT easier to read! The easier you make our life, the faster we can help!
3) Please confirm the PIC does the 1Hz LED program and correctly accesses the LCD module.You don't have a needed delay_ms(500); before the lcd_init() call.
4) you have 'read card' in your code, so I'm assuming you have a 'card reader' using the protocol. PLEASE post a link to that device !
hth
jay |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9168 Location: Greensville,Ontario
|
|
Posted: Thu Jul 03, 2014 3:04 pm |
|
|
I googled 'Wiegand 26 ccs c code' and got a lot of hits...1/2 way down on first page there's a hit with working code.(according to the poster)..
I find 'googling' to be a great resource IF you type in the correct keywords.
hth
jay |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19358
|
|
Posted: Thu Jul 03, 2014 3:10 pm |
|
|
Several initial comments:
1) Use the code buttons.
2) Why have you got the code in 'bits', with separate clock definitions etc.?.
The clock and fuses etc., need to apply _once_.
Now I've had to make several assumptions - two line LCD?.
Code: |
#include <18F46K22.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NOMCLR
#use delay(crystal=20000000)
#include "lcd_test.c"
#define TOP_BIT 0x02000000 //first bit to handle
#define BIT_COUNT 25; //bits less one
int32 W_data=0; //store for result
int32 mask=TOP_BIT;
int8 ctr=BIT_COUNT;
int1 finished=FALSE; //flag for complete data
#define TRIGGER PIN_D5
#INT_EXT2
void read_wiegandD1(void)
{
W_data |= mask; //set bit for a '1'
if (ctr--==0)
{
finished=TRUE;
mask=TOP_BIT;
ctr=BIT_COUNT;
}
else
mask/=2;
}
#INT_EXT1
void read_wiegandD0(void)
{
if (ctr--==0)
{
finished=TRUE;
mask=TOP_BIT;
ctr=BIT_COUNT;
}
else
mask/=2;
}
void main(void)
{
int1 parity1, parity2;
int8 facility;
int16 ID;
delay_ms(500);
lcd_init();
output_high(TRIGGER);
enable_interrupts(INT_EXT2_H2L);
enable_interrupts(INT_EXT1_H2L);
clear_interrupt(INT_EXT2);
clear_interrupt(INT_EXT1);
enable_interrupts(GLOBAL);
while(TRUE)
{
finished=FALSE;
mask=TOP_BIT;
ctr=BIT_COUNT;
W_data=0; //Initialise values
printf(lcd_putc,"\fTriggering");
output_low(TRIGGER);
delay_ms(600); //The slowest a Weigand 26 sequence can be is 520mSec
output_high(TRIGGER);
if (finished)
{
parity1=bit_test(W_data,25);
parity2=bit_test(W_data,0); //The two parity bits
W_data/=2; //shift the 32bits right once
ID=make16(W_data,0); //Low 16bits is then the ID
facility=make8(W_data,2); //bits 16-23 are then the facility code.
printf(lcd_putc,"\fID = %4LX ",ID);
printf(lcd_putc,"\nfacility = %2X ",facility);
}
else
printf(lcd_putc,"\fOnly %d bits seen", BIT_COUNT-ctr);
//Now delay before asking again
delay_ms(10000);
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
cllunlu
Joined: 30 Jun 2014 Posts: 4
|
|
![](templates/subSilver/images/spacer.gif) |
cllunlu
Joined: 30 Jun 2014 Posts: 4
|
|
Posted: Fri Jul 04, 2014 12:25 am |
|
|
Hi Ttelmah,
I will try your sample code. And I will write result.
Thanks you so much.
Celal |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|