Escolar Documentos
Profissional Documentos
Cultura Documentos
Hijjawi Faculty for Engineering Technology Electronics Engineering Department "ELE 598A"
"Graduation Project Report"
(2008972072) (2008972069)
Acknowledgements
In the beginning we would like to thank our families for everything they have presented to us. Who supported us during these years with their concern and patience, and to whom we owe what and where we have become now. Special thanks to our supervisor Dr. Qassim Al-Zoubi ,who taught us that by having faith there is no impossible, who showed us the meaning of an amazing Doctor-student relationship, the interest, help advice and for have special way of making work enjoyable. We also thank the teaching staff at the college engineers, doctors and professors who taught us when we studying at the university, our friends and everyone who helped us in our student life. So, thank you all.
Abstract
The main objective to our project to provide a system that alarm the store manager when the goods at some market goes to run out, so we need a way to detect the type of the out product, so we use a barcode principles. Our project can be used for small market, product that storing it is cost, our product that the supplier is so far.
Table of contents:
Acknowledgment .................................................... (2) Abstract ............................................................... (3) CHAPTER 1: Introduction ................................ (5)
1.1 1.2 1.3 Overview .............................. (5) Project Block Diagram .............. (8) Barcode system................................. (10)
1.1) Overview
Basically, for any barcode system, there are 3 functional parts to the barcode scanner itself, the illumination system, the sensor/converter and the decoder. Barcode scanners begin by illuminating the code with red light. The sensor of the barcode scanner detects the reflected light and generates an analog signal with varying voltage representing the intensity (or lack of intensity) of the reflected light. The converter changes the analog signal to a digital signal which is then fed to a decoder. The decoder interprets the digital signal, does the required math to confirm and validate that the barcode is decipherable, converts it into ASCII text, formats the text and sends it to the computer where the scanner is attached to. The structure of the barcode scanner system contains of: - Illumination System: The illumination system is the method by which the bars and spaces on the barcode are illuminated. There is a variety of illumination systems commonly used in barcode scanners: Single Point LED: As shown in figure 1.1. This technology is exclusive to the barcode wand reader and the barcode slot reader. The illumination of the barcode comes from either a single or pair of LEDs and is focused through a single ball-type opening. This technology requires the ball to physically touch the barcode being scanned. Since the illumination is on a single point, the operator has to provide motion to the barcode past the light source. In the case of a barcode wand, the operator drags the illumination ball across the barcode. For swipe or slot readers, the barcode is typically printed on a credit-card like media. The operator pulls the card through a fixed slot, past the illuminating head.
However, slot and wand readers are inexpensive and can accommodate any length of barcode. There are several disadvantages of the single point illumination method. Slot and wand readers require the operator to control the speed at which the barcode passes in front of the illumination head. Because barcodes must be in contact with the illumination head to read, the barcode can easily be damaged by abrasion of the head on the media that hosts the printed barcode. Although the illumination head is hardened, it will wear out and must be replaced regularly.
Linear Multiple LED: Expanding on the single-point illumination system, placing multiple LED's in a line give the ability to light the entire width of the barcode. This type of illumination is used in CCD scanners and Linear Imagers. As shown in figure 1.2. When used in CCD scanners, the LED's are paired with a line of photocells to detect the reflected light from the barcode. Since the LED's are relatively low in power, and the photocells are low in sensitivity, the range of CCD barcode scanners is generally limited from being in contact with the barcode to 1" away.
Laser: This type of illumination method uses a single point red laser diode similar to a laser pointer. The point of light is expanded into a line by oscillating the laser into a stationary mirror, or projecting the point into an oscillating mirror. This illumination method is very popular because of the working distances typically achieved are superior to the point illumination or linear LED illumination methods. Typical working distances are from 1" to 18". By increasing the power of the laser and decreasing the angle of oscillation, ranges of over 20 feet can be obtained. - Sensor and Converter: A photo-detector senses the reflected light and generates an analog signal with varying voltage. The voltage fluctuates based on whether the sensor sees the reflected light from the white spaces because the black bars absorb the red light. This process shown in figure 1.3.
The technology used in the sensor can vary depending on the illumination method. The output is always the same - a voltage wave form with peaks for the white spaces, and troughs for the black spaces in the barcode [10].
In an imaging barcode scanner, the sensor covers the entire scan target and generates a 2dimensional wave form. In both cases, this analog signal is sent to the converter. The converter changes the analog signal to a digital signal. This signal is the digital representation of what the sensor detected from the reflected light. Now that the barcode scanner has a digital signal, the signal is transferred to the barcode scanner decoder.
1.2.1) Barcode scanner: Barcode is a special decoding system that uses for give more information about product; often the packaging is too small, so that the manufacturer cannot mention the really important data. We have used a special barcode for our project at same principal of the international one, due to the cost of international scanner. Using photo diodes we can sense the color of the bar either black or white, since the amount of reflective photon to the receiver will be change due to the bar color.
Figure 1.5 shows a simple sensor circuit. This will be sense either the bar is black or white due to the o/p voltage. Since we have two cases black or white, as binary system Number of products = 2m where m represents number of the sensor. In our project we used 8 products, accordingly 3 sensors are needed. 1.2.2) Keypad The keypad used as data input device such as the amount of each product, price of each them, and as security for the system.
1.2.3) Display The display used to show the information such as price, reminder of some product, and to show the bill. We have used 420 parallel LCD for display.
Figure1.7:420 LCD.
1.2.4) The microcontroller The microcontroller used to control of the project, getting the data from the user (using keypad), scan the exit product (using barcode scanner), and show the information out after processing (using LCD). All the data will be store on it. We have used PIC 16F877A on our project.
10
Barcode case 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1
Product number Product 1 Product 2 Product 3 Product 4 Product 5 Product 6 Product 7 Product 8
11
12
Microcontroller families: There are thousands of different microcontroller type in the world today, made by numerous different manufactures. A manufacturer builds a microcontroller family around a fixed microprocessor core. Different family members are created by using the same core, combining with it different combination of peripherals and different memory size. This is shown symbolically in Figure 2.2. This manufacturer has three microcontroller families each with its own core. One core might be 8-bit with limited power, another 16-bit and another sophisticated 32-bitmachine. To each core are added different combinations of peripheral and memory size, to make a number of family members. Because the core is fixed for all members of one family, the instruction set is fixed and users have a little difficulty on moving from one family to another [1].
13
16: It is called the family number (F.N). It specifies the size of data bus. The 16-bits are divided as follows: 14-bits are for data transmission 'size of data bus', and 2-bits are for addressing F: Means flash memory, which can be over written for 100,000 times without any occurring damage. Accessing this kind of memory is very quick so, that saves time. 87X: it indicates the sequence of the PIC in its family. A: means enhanced in the speed or in the memory [3].
14
PIC 16F877A: We have used PIC 16f877a in our project. The PIC16F877A CMOS FLASH-based 8-bit microcontroller is upward compatible with the PIC16C5x, PIC12Cxxx and PIC16C7x devices. It features 200 ns instruction execution, 256 bytes of EEPROM data memory, self programming, an ICD, 2 Comparators, 8 channels of 10-bit Analog-to-Digital (A/D) converter, 2 capture/compare/PWM functions, a synchronous serial port that can be configured as either 3-wire SPI or 2-wire I2C bus, a USART, and a Parallel Slave Port. PIC16F877A Microcontroller Features:
[11]
Operating speed: 20 MHz, 200 ns instruction cycle Operating voltage: 4.0-5.5V Industrial temperature range (-40 to +85C) 15 Interrupt Sources Flash Memory: 14.3 Kbytes (8192 words) Data SRAM: 368 bytes Data EEPROM: 256 bytes
15
Self-reprogrammable under software control Watchdog Timer with on-chip RC oscillator Programmable code protection Power-saving Sleep mode Selectable oscillator options
Peripheral Features
o o o o o o o
33 I/O pins; 5 I/O ports Timer0: 8-bit timer/counter with 8-bit prescaler Timer1: 16-bit timer/counter with prescaler Can be incremented during Sleep via external crystal/clock Timer2: 8-bit timer/counter with 8-bit period register, prescaler and postscaler Two Capture, Compare, PWM modules 16-bit Capture input; max resolution 12.5 ns 16-bit Compare; max resolution 200 ns 10-bit PWM Synchronous Serial Port with two modes: SPI Master I2C Master and Slave USART/SCI with 9-bit address detection Parallel Slave Port (PSP) 8 bits wide with external RD, WR and CS controls Brown-out detection circuitry for Brown-Out Reset
Analog Features
o o o o
10-bit, 8-channel A/D Converter Brown-Out Reset Analog Comparator module 2 analog comparators Programmable on-chip voltage reference module Programmable input multiplexing from device inputs and internal VREF Comparator outputs are externally accessible
16
Advantages of 16F877A: The 40 pins make it easier to use the peripherals as the functions are spread out over the pins. This makes it easier to decide what external devices to attach without worrying too much if there enough pins to do the job. One of the main advantages is that each pin is only shared between two or three functions so its easier to decide what the pin function (other devices have up to 5 functions for a pin). A disadvantage of the device is that it has no internal oscillator so you will need an external crystal of other clock source.
17
2.1.2) Photodiode sensor: We have used the photodiode as a sensor to tracking the reflective light from the surface to determine the bas is black or white, so we need a light source to be reflect, we have used an IR LED. We must be able to differentiate between black and white. We make use of a property called 'Absorptivity'. It is well known that Black absorbs maximum amount of light that falls on it, whereas White reflects most of the light incident on it. If we throw a fixed amount of light say 'x' on a white surface and on a black surface, and if the white surface reflects back 0.9x amount of light, then the black surface would reflect something like 0.1x (These are just numbers to illustrate the point). This fixed amount of light, we'll throw using an IR LED and the reflected light will be sensed by a IR Photo Diode. A LED - Photo Diode pair is shown in the figure.
Photodiode detector A Photo diode is a reverse biased silicon or germanium PN junction in which reverse current increases when the junction is exposed to light. When no light is incident on the PN junction of photo diode, the reverse current Ir is extremely small. This is called DARK CURRENT The resistance of photo diode with no incident light is called dark resistance (Rr) Dark Resistance of Photo diode = Vr / Dark Current When light is incident on the PN junction of the photo diode there is a transfer of energy from the incident light (photons) to the atoms in the junction .this will create more free electrons (and more holes) these additional free electrons will increase the reverse current.
18
As the intensity of light increases the reverse current IR goes on increasing till it becomes maximum. This is the LED saturation current. Sensor interfacing circuit: A simple circuit employing a LED - Photodiode pair is shown below
We can use multiple sensor as we need, on our project we us just three sensors to track three the barcode for 8 products. 2.1.3) The LCD Short for Liquid Crystal Display (LCD) is a thin, flat display device made up of any number of color or monochrome pixels arrayed in front of a light source or reflector. Its a type of display used in digital watches and many portable computers. LCD displays utilize two sheets of polarizing material with a liquid crystal solution between them. An electric current passed through the liquid causes the crystals to align so that light cannot pass through them. Each crystal, therefore, is like a shutter, either allowing light to pass through or blocking the light. Its consumes small amounts of electric power, and is therefore suitable for use in battery-powered electronic devices.[4]
19
We have used 4*20 parallel LCD on our project, thats mean there 4 line with 20 character to display and multi lines to transfer the data between the LCD & Microcontroller. 2.1.4) Keypad We use 3*4 keypad on our project, that means we have 4 rows in each one 3 buttons (in total 12 button). A basic 12 button keypad for user input. The buttons are setup in a matrix format. This allows a microcontroller to 'scan' the 7 output pins to see which of the 12 buttons is being pressed.
Table 2.2: Matrix For keypad button [6].
20
2.2.1: Power supply We use 5v supply for our electronic circuit, 5v supply for PIC and for keypad, LCD and for every component in the project.
2.2.3) Crystal oscillator The microcontroller cannot operate without external oscillator components which stabilize its operation and determine its frequency (operating speed of the microcontroller).Depending on elements in use as well as their frequencies. A crystal oscillator is an electronic oscillator circuit that uses the mechanical resonance of a vibrating crystal of piezoelectric material to create an electrical signal with a very precise frequency. To provide a stable clock signal for digital integrated circuits the most common type of piezoelectric resonator used is the quartz crystal, so oscillator circuits designed around them became known as "crystal oscillators."
The oscillator can be run in four different modes: LP - Low Power Crystal. XT - Crystal / Resonator. HS - High speed Crystal / Resonator. RC - Resistor / Capacitor.
Table 2.3: Oscillator Mode.
The oscillator will some time have the noise. To reduce the noise, two capacitors in pico farad value is needed. The value of capacitor is depends on the speed of oscillator that used as shown in table 2.3. 2.2.4) LED Light Emitting Diode A light-emitting diode is a semiconductor light source. LEDs are used as indicator lamps in many devices and are increasingly used for other lighting. When a light-emitting diode is forward biased (switched on), electros are able to recombine with electron holes within the device , releasing energy in the form of photons and the color of the light (corresponding to the energy of the photon ) is determined by the energy gap of the semiconductor. An LED is often small in area.
22
LEDs present many advantage over incandescent light sources including lower energy consumption, longer lifetime, improved robustness, smaller size, faster switching, and greater durability and reliability, while LEDs do not radiate heat. LEDs are highly monochromatic, emitting a pure color in a narrow frequency range. The color emitted from an LED is identified by peak wavelength and measured in nanometers (nm). We use the LED on our project as alarm when a product go to finish.
23
IR LED: For R1 shown in the circuit above I1 = 20 mA , Vmin=1.2 & Vmax=1.5 (from datasheet) And the best illumination of the LED when the current pass it =10mA,so R1 max= 5-1.2/10mA =380 R1 min=5-1.5/20 mA =350 We select R1 =330
24
IR Photodiode detector: The current that pass through the receiver will change due to the amount of light that reflected to it Il = 25 uA & Vl= 0.2 V R2 = 5-0.2/25 uA =192 k so we select R2=190 k
25
This circuit is the most intuitive way to interface to a microcontroller or logic chip and it is very wrong. When the switch is open it will cause the input of the chip to float. Depending on the device this could lead to undefined operation of the input, oscillation between states, high power consumption or even physical damage to the device. The solution to that is the pull up resistor (see figure 3.4).
26
When the switch is open the voltage at the input pin will be very near Vcc. The input has very high impedance. This means that very little current flows through this circuit so there will be very little voltage drop across the resistor. If we close the switch, all the current will flow through the resistor and the switch to ground. Now the voltage drop across the resistor will be Vcc so the input pin will see a voltage that is very near ground. This is how we make sure that the input pin of the microcontroller will never see anything except Vcc or ground. A typical value for a pull up resistor is usually between 10 k and 100 k. We have selected 10 k to interface all switches and the keypad with the microcontroller.
27
28
If the password entered incorrectly for 4 times then the system will lock up and the following massage will shown as the figure bellow.
30
After entering the correct password the system will ask you to enter the product number as the following massage shows.
31
Figure 4.4: product option Every option has a specific function for example number 2 to show the reminder amount of product 1.
If the product is under the threshold value then the following massage will be shown, and the alarm LED will switch on.
32
Disadvantage: Used for a specific number of goods. If we need increase the goods number, we must increase the number of sensors. Low accuracy. Use a special barcode system. Impractical for large stores.
33
4.3) Conclusions
From the project test and the obtained results, the following points can be concluded: Technology can be used to make our life easier; since most of our tasks can be
automated using suitable electronics equipments and the proper software. This project has given usability to deal well with the electronic component and understand the principle of work in practice. We learn how to build an entire system during a specific time and limited equipments. How to Interface the microcontroller with the other devices.
34
Reference:
[1] Tim Wilmshurst (first edition 2007) Design Embedded systems with PIC Microcontrollers Principles and Application. Published by Elsevier Ltd [2] Robert Boylestad and Louis Nashelsky, (2010) Electronic devices and circuit theory, 9th edition, Pearson printice hall. [3] Microchip PIC 16F87XA data sheet. [4] http://www.webopedia.com/TERM/L/LCD.html
[5] https://www.sparkfun.com/products/8653 [6] http://www.hobbytronics.co.uk/data-keypad-3-4 [7] http://www.locxtronic.com/basiccircuitforpic16f877a.html [8] http://www.madsciencenotebook.com/basicelectronics/pull-up-resistor/ [9] http://www.stab-iitb.org/wiki/Sensors_for_Line_Following [10] http://www.carolinabarcode.com/how-barcode-scanners-work-a-69.html [11] http://microcontrollershop.com/product_info.php?products_id=992
35
Appendix:
PIC C code:
#include <16f877a.h> #fuses NOWDT,HS,NOPUT,NOPROTECT,NODEBUG,NOBROWNOUT,NOLVP,NOCPD,NOWRT #include "C:\Program Files (x86)\PICC\Drivers\Flex_LCD420.c"//the driver for LCD 4*20 #use delay(clock=4000000) //Keypad definition #define kp_r1 pin_c3 #define kp_r2 pin_c4 #define kp_r3 pin_c5 #define kp_r4 pin_d3 #define kp_c1 pin_c0 #define kp_c2 pin_c1 #define kp_c3 pin_c2 //////////////////////////////////////////////////////////////////////////////// int i,j,value; int16 alarm; float price[8]; float total_price=0.0; int16 pass[3];//to read the password {6 digit password} unsigned int number[8][2];//number of product unsigned int threshold[8][2]; unsigned int product_Id;//product id //////////////////////////////////////////////////////////////////////////////// int read_key1(int option)//to read from the keypad { while(true) { Back2: output_low(kp_r1); output_high(kp_r2); output_high(kp_r3); output_high(kp_r4); delay_us(30); if(input(kp_c1)==0)//read 1 { while(!input(kp_c1)){}; return 1; } if(input(kp_c2)==0)//read 2 { while(!input(kp_c2)){}; return 2; } if(input(kp_c3)==0)//read 3 { while(!input(kp_c3)){}; return 3; } output_high(kp_r1); 36
output_low(kp_r2); output_high(kp_r3); output_high(kp_r4); delay_us(30); if(input(kp_c1)==0)//read 4 { while(!input(kp_c1)){}; return 4; } if(input(kp_c2)==0)//read 5 { while(!input(kp_c2)){}; return 5; } if(input(kp_c3)==0)//read 6 { while(!input(kp_c3)){}; return 6; } if(option==1)goto nxt1; output_high(kp_r1); output_high(kp_r2); output_low(kp_r3); output_high(kp_r4); delay_us(30); if(input(kp_c1)==0)//read 7 { while(!input(kp_c1)){}; return 7; } if(input(kp_c2)==0)//read 8 { while(!input(kp_c2)){}; return 8; } if(option==2)goto nxt1; if(input(kp_c3)==0)//read 9 { while(!input(kp_c3)){}; return 9; } nxt1: output_high(kp_r1); output_high(kp_r2); output_high(kp_r3); output_low(kp_r4); delay_us(30); if(option!=3) { if(input(kp_c1)==0)//read *==10 { while(!input(kp_c1)){}; return 10; 37
} if(option==2) goto Back2; } if(input(kp_c2)==0)//read 0 { while(!input(kp_c2)){}; return 0; } if(input(kp_c3)==0)//read # { while(!input(kp_c3)){}; return 11; } } } //////////////////////////////////////////////////////////////////////////////// void calculate_price(int k) { total_price=total_price+price[k]; printf(lcd_putc,"\fprice=%f",total_price); delay_ms(100); } //////////////////////////////////////////////////////////////////////////////// void ee_threshold_write() { write_eeprom(0x0030+2*product_Id,threshold[product_Id][0]); write_eeprom(0x0031+2*product_Id,threshold[product_Id][1]); } //////////////////////////////////////////////////////////////////////////////// void set_threshould(){ unsigned int amount1=0; lcd_putc("\fEnter 4-digit\nthreshold Then\npress #:"); for(i=0;i<8;i++) { threshold[i][0]=0;//reset threshold} threshold[i][1]=0; } i=0; while(true) { i++; amount1=read_key1(3); if(amount1!=11){ if(i>4)goto out; if(i==1)lcd_putc("\f"); if(i==1||i==2){threshold[product_Id][0]=10*threshold[product_Id][0]+amount1; printf(lcd_putc,"%u",amount1);} if(i==3||i==4){threshold[product_Id][1]=10*threshold[product_Id][1]+amount1; printf(lcd_putc,"%u",amount1);} } else{goto out;} } out:ee_threshold_write(); 38
} //////////////////////////////////////////////////////////////////////////////// void eepromwrite()//to write on eeprom after adding { write_eeprom(product_Id*2+1,number[product_Id][0]); write_eeprom(product_Id*2+2,number[product_Id][1]); } //////////////////////////////////////////////////////////////////////////////// void setprice() { long int amount1=0; long int amount2=0; unsigned int n=1; lcd_putc("\fEnter # when\nfinish change"); lcd_putc("\fEnter the new\nprice{use * as .}"); i=0; while(true) { read:j=read_key1(0); if(j!=11) { if(j==10){i=1;n=1;goto read;} if(i==0) { amount1=amount1*n; amount1=amount1+j;n=10; write_eeprom(0x0010+2*product_Id,amount1); } else { amount2=amount2*n; amount2=amount2+j; n=10; write_eeprom(0x0011+2*product_Id,amount2); } price[product_Id]=amount1+(amount2*1.0/100.0); printf(lcd_putc,"\f%lu",amount1); printf(lcd_putc,".%lu",amount2); } else { //printf(lcd_putc,"\n%f",price[product_Id]);delay_ms(2000); goto end; } } end:delay_us(1); } //////////////////////////////////////////////////////////////////////////////// void message(int k)//to print the poroduct number { printf(lcd_putc,"\nproduct%u",k+1); } //////////////////////////////////////////////////////////////////////////////// void add()//to add product { 39
unsigned long int amount1=0; unsigned int n=1; i=0; lcd_putc("\fEnter amount to add:\nThen press #"); while(true) { i++; j=read_key1(3); if(j!=11){ amount1=amount1*n; amount1=amount1+j;n=10; if(i>5)amount1=9999; printf(lcd_putc,"\f%lu",amount1);} else{goto out;} } out:if(i>5)amount1=9999; number[product_Id][0]=number[product_Id][0]+amount1/100;//first tow digit number[product_Id][1]=number[product_Id][1]+(amount1-((amount1/100)*100));//2nd tow digit } //////////////////////////////////////////////////////////////////////////////// void read_pass()//to read 6 digit password { unsigned long int pass1=0; for(j=0;j<3;j++) { for(i=0;i<2;i++) { value=read_key1(3); pass1=pass1*10; pass1=pass1+value; lcd_putc("*"); } pass[j]=pass1; pass1=0; } out:pass1=0; } //////////////////////////////////////////////////////////////////////////////// void option()//to chosse betwen the option { while(true) { Back1: lcd_putc("\f-Enter product\n number:[1,2..,8]\n-To exit press *"); product_Id=read_key1(2)-1;//conver (1->8) TO (0->7) if((product_Id+1)==10)goto start1; Back2: lcd_putc("\fPlease enter option\n"); lcd_putc("1=Add,2=Num,3=R,\n4=R_A,5=S_B,#=back,\n*=E,6=change thresould."); switch(read_key1(1)) { case 1:add();eepromwrite(); goto Back2; 40
break; case 2:printf(lcd_putc,"\fthe total number is:\n%u",number[product_Id][0]); printf(lcd_putc,"%u",number[product_Id][1]); delay_ms(1000); goto Back2; break; case 3: number[product_Id][0]=0; number[product_Id][1]=0; eepromwrite(); lcd_putc("\fReset Complete!");delay_ms(1000); goto Back2; break; case 4: for(i=0;i<8;i++) { number[i][0]=0; number[i][1]=0; } eepromwrite(); lcd_putc("\fReset Complete!");delay_ms(1000); goto Back2; break; case 5:setprice();break; case 6:set_threshould();break; case 10:goto start1; break; case 11:goto Back1; break; } } start1:delay_us(1); } //////////////////////////////////////////////////////////////////////////////// void start()//to get the product number { for(i=0;i<8;i++) { number[i][0]=read_eeprom(2*i+1);//read num. number[i][1]=read_eeprom(2*i+2); } write_eeprom(0x002A,12);//set pass write_eeprom(0x002B,34); write_eeprom(0x002C,56); for(i=0;i<8;i++) { price[i]=(read_eeprom(0x0010+2*i))+((read_eeprom(0x0011+2*i))/100.0);//read price } for(i=0;i<8;i++){ threshold[i][0]=read_eeprom(0x0030+(i*2));//read threshold} threshold[i][1]=read_eeprom(0x0031+(i*2)); } } //////////////////////////////////////////////////////////////////////////////// 41
int password()//test the password { read_pass(); if((pass[0]==read_eeprom(0x002A))&&(pass[1]==read_eeprom(0x002B))&&(pass[2]==read_eeprom( 0x002C)))//123456=?123456 return 1; return 0; } //////////////////////////////////////////////////////////////////////////////// void option_change()//interput function ,the iterput at portB0 { int16 time=0; j=1; again: lcd_putc("\fPlease enter the\npassword :"); while(j) { while(!password()) { alarm++; if(alarm>=4) {lcd_putc("\f-System Blocked!!!!!\n-Call Manager:\n00296xxxxxxxx"); while(1)//puzzer { if(time==0)i=0; if(time==2000)i=1; if(i==0){time=time+100;} if(i==1){time=time-1;} output_high(pin_b6); delay_us(time); output_low(pin_b6); } } lcd_putc("\fWrong password!"); delay_ms(1000); lcd_putc("\fTo exit press *\nTo Re-enter the\npassword press #:\n"); output_high(kp_r1); output_high(kp_r2); output_high(kp_r3); output_low(kp_r4); delay_us(30); while(j) { if(input(kp_c1)==0) { while(!input(kp_c1)){}; goto out; } if(input(kp_c3)==0){while(!input(kp_c3)){};goto again;} } } option(); j=0; } out:delay_us(1); } 42
//////////////////////////////////////////////////////////////////////////////// void main() { lcd_init();//lcd initial start(); while(true) { if(!input(pin_b0)) { while(!input(pin_b0)){}; value=input(pin_b1)*4+input(pin_b2)*2+input(pin_b3); if((number[value][0]==0)&&(number[value][1]==0)) {lcd_putc("\f-Error! this\n product is finish!!!");goto nxt;} if(number[value][1]==0){number[value][1]=99;number[value][0]--;} else {number[value][1]--;} calculate_price(value); message(value); eepromwrite(); nxt: if(number[value][0]<threshold[value][0]) { output_high(pin_b7); printf(lcd_putc,"\n-product %u",value+1); lcd_putc(" under\n thresould"); delay_ms(1000); output_low(pin_b7); } else if(number[value][1]<threshold[value][1]) { output_high(pin_b7); printf(lcd_putc,"\n-product %u",value+1); lcd_putc(" under\n thresould"); delay_ms(1000); output_low(pin_b7); } } if(!input(pin_b5)){ while(!input(pin_b5)); total_price=0; lcd_putc("\fprice=0.0");} if(!input(pin_b4)) { while(!input(pin_b4)); option_change(); lcd_putc("\fReady for use"); } } } ////////////////////////////////////////////////////////////////////////////////
43