MCU Examples.com
PIC Microcontroller Project Examples, free source codes and resources collection.
In the program code a delay is given after the sensor detects a package. This delay time should be equal to the time taken for the package to come on to the weighing scale. This is done to ensure that the program will start to take readings (serial input data) from the weighing scale only when there is a package on the weighing scale. This is the reason for using a sensor to detect a package. By doing so the there is a reliability to the system.
When there is a package on the weighing scale a 40 data byte string from the weighing scale is saved on to the PIC16F877A RAM by indirect addressing (The reason for saving a 40 byte string is because to make sure that at least one complete data packet from the weighing scale would be present in the 40 byte string). Using indirect addressing has the advantage since only one variable needs to be defined and this variable is used to give the starting address of the memory location where the first data byte is saved and from here the program will increment the previous address value by one and write data to the incremented address when the next byte is received likewise 40 data bytes are saved to 40 memory locations. But if indirect addressing was not used 40 variables need to be defined in order to save the 40data byte string which is quite hectic due to this indirect addressing is more efficient in the program. [This minimises the program code lines]
The reason for using a 20MHz oscillator instead of a 4MHz one because of the transmission speed (9600bps). Since the baud rate is high the program needs to be fast enough to save a data byte received before the next byte is received.