Decoding Barcodes Various approaches
Decoding barcodes There are a number of ways of decoding the barcodes –The data can be polled –The data can be read on interrupt –The data can be sampled
Polling Repeatedly test the port B bit for state change, then –Store time value for the change Requires Port B set up and clock running Locks up the board, or risks data lose through multiple polling Data will require a lot of filtering
Port B Registers
Minos code to program port B
Program port B at low level
Timer Registers
Timer code
Interrupt driven code 2 possible sources for the interrupt –The bar code wand pin – Port B –The timer – Timer 2 The timer is only really needed if you require a time out to abort the read Requires some careful setting up of the various peripherals and care with the order of the code
Interrupt driven code Uses the resources of the board very well Once implemented properly it is a very elegant and simple solution Will allow other activities to take place on the board Can generate noisy data Can be difficult to debug
Interrupt Code
Coding using sampling This is an alternative interrupt driven method Rather than use the Port B interrupts it uses the timer to sample the Port B input Can use various settings for the timer The data read is just a count of 0s or 1s
Coding using sampling Allows flexibility in that sample rate is easy to change Only 1 source of interrupt – so is fairly simple Data read is very simple and easy to organise
Sampling Code