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!





Bookmarks