Barcode reader with PIC16f877A ?


Closed Thread
Results 1 to 19 of 19

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default thank you for your reply

    Thank you for your reply and your information, i will try to change my code now and see if it's working.

  2. #2


    Did you find this post helpful? Yes | No

    Default after code modifications

    I modify my code, and it's more stable and better than previous which give me the number of bits were scanned counter=96 but previous it's not the same,
    Here is my code after modifications
    ====================================

    DEFINE LCD_DREG PORTD 'LCD data port
    DEFINE LCD_DBIT 4 'LCD data starting bit 0 or 4
    DEFINE LCD_RSREG PORTD 'LCD register select port
    DEFINE LCD_RSBIT 2 'LCD register select bit
    DEFINE LCD_EREG PORTD 'LCD enable port
    DEFINE LCD_EBIT 3 'LCD enable bit
    DEFINE LCD_BITS 4 'LCD bus size 4 or 8
    DEFINE LCD_LINES 4 'Number lines on LCD
    DEFINE OSC 4 ' We're using a 4 MHz oscillator

    symbol clock_barcode=portb.0 ; clock of barcode reader ps/2
    symbol data_barcode=portb.1 ; data of barcode reader ps/2
    symbol but1=portb.2

    ID var bit[250]
    char var byte
    countstep var byte
    counter var byte

    Clr CON 1 ' Serial LCD command to clear LCD
    LINE1 CON 128 ' Line #1 of serial LCD
    LINE2 CON 192 ' Line #2 of serial LCD
    LINE3 CON 148 ' Line #3 of serial LCD
    LINE4 CON 212 ' Line #4 of serial LCD
    Ins CON 254 ' Instruction for LCD command-mode



    input clock_barcode
    input data_barcode
    output portd.1
    input but1

    OPTION_REG = %00000101 ; falling edge of clock
    INTCON = %10010000 ' Enable RB0 interrupt
    counter=0

    pause 2000 ; time for lcd to turn on
    ON INTERRUPT GOTO reg_id
    lcdout Ins,clr,INS,Line1,"Please Ins. ID card"
    goto main

    ;;;;;;; interrupt service routine
    DISABLE ' Disable interrupts in handler
    reg_id:
    intcon.1=0 ; reset int
    if clock_barcode=0 then ; test falling edge
    id[counter]=data_barcode
    counter=counter+1
    endif

    RESUME ' Return to main program
    ENABLE ' Enable interrupts after handler
    ;;;;;;;;;;;;;;;;;


    Main:


    if but1=0 then
    lcdout ins,clr,ins,line1,#counter,ins,line2 : pause 3000
    for countstep=0 to counter : lcdout #id[countstep] : pause 2000 : next
    counter=0
    endif

    goto main ' Remain in loop

    end


    =========================

    please if one can tell me if my code is true or not ,which it's collect data from barcode reader ps/2 every falling edge trigger of clock which this will tell the microcontroller interrupt service routine to save the data bit on this edge!

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    One of the problems you're going to have is the fact that you won't get an interrupt in the middle of a statement.
    For instance,
    Pause 3000...
    The On Interrupt won't trigger for at least 3 seconds.
    (However, instead of Pause 3000, you can use:
    for x = 1 to 300 : pauseus 10 : next x...at least then the PIC will check for an interrupt every 10 microseconds)

    Any LCDOUT command won't let an On Interrupt trigger during the execution of the LCDOUT command, which can take a few milliseconds, an eternity when dealing with fast signals.

    In general, all interrupts are checked BEFORE or AFTER every statement (I don't remember which). So, if you're executing a single command, an ON INTERRUPT won't happen in the middle of it.

    Either recode your program to keep anything in the main loop from holding up an interrupt or think about researching and switching over to DT's Instant Interrupts.

  4. #4


    Did you find this post helpful? Yes | No

    Default

    [QUOTE=skimask;49542]One of the problems you're going to have is the fact that you won't get an interrupt in the middle of a statement.
    QUOTE]

    oky I avoid this problem by placing If statement " If but1=0 " which all commands inside this if statement will not execute untill I press the button placed on portb.2

    but I want to ask if there is something wrong in my code

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    oky I avoid this problem by placing If statement " If but1=0 " which all commands inside this if statement will not execute untill I press the button placed on portb.2
    You sure did...missed that one, but it's still a valid point for future reference.

    but I want to ask if there is something wrong in my code
    Does it work?

    If code_works = 1 then
    nothing_wrong_with_code = 1
    else
    nothing_wrong_with_code = 0
    something_wrong_with_code = 1
    endif

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    You sure did...missed that one, but it's still a valid point for future
    oky for testing my code I insert ID card with this number "120063718" and the barcode give me a sound that the scanning completed , then if the scanning stage I pressed the button to display the data collected from this barcode reader the data output as follows

    counter=96
    data bits=
    10100001001111100010000011111100111110001000000111 0100101101011000000111010000011111100 ...........

    I want to know how to decode this data to display this ID number 120063718

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by iugmoh View Post
    oky for testing my code I insert ID card with this number "120063718" and the barcode give me a sound that the scanning completed , then if the scanning stage I pressed the button to display the data collected from this barcode reader the data output as follows
    counter=96
    data bits=
    10100001001111100010000011111100111110001000000111 0100101101011000000111010000011111100 ...........
    I want to know how to decode this data to display this ID number 120063718
    For one thing, we don't know which barcode scanner you're using (not that it would matter much).
    Second thing, how does your scanner encode the information that it outputs?
    Obviously you've got data there. Whether it's good data or not is another story.
    What do the dots mean? Do they mean that there is more data to follow or are those the end of the string?
    Is this some sort of ASCII encoded data? BCD? Grey code? Otherwise? 8 bit data chunks? 12 bit? 4 bit repeated/inverted?

Similar Threads

  1. PS/2 barcode reader to RS232 port - need help
    By phoenix_1 in forum Schematics
    Replies: 10
    Last Post: - 28th May 2008, 05:35
  2. Barcode reader Problem ?
    By iugmoh in forum General
    Replies: 5
    Last Post: - 18th February 2008, 20:25
  3. Serial interface with RFID reader
    By brid0030 in forum Serial
    Replies: 8
    Last Post: - 23rd January 2007, 06:23
  4. Proximity Card Reader
    By Sphere in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 6th November 2005, 14:43
  5. Smart card reader with PIC16F84A
    By bangunprayogi in forum Serial
    Replies: 0
    Last Post: - 12th August 2005, 10:36

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts