استاذي الفاضل المهندس / احمد سمير فايد.....
ارجو التحقق من هذا الكود (مع ملاحظة انني في هذا الكود راعيت نقطة الbouncing)
و ارجو منك استاذي العزيز ابداء الملاحظات المهمة في الكود سريعا لكي اشرع في تنفيذ المشروع عمليا
كود:
/*************************************************************************
* this is a project for photo resistance with laser beam , *
* if this beam cut by some one the seven segment will increase by one . *
* ********************************* *
* this code was written by : mohamed ali mohamed khalil . *
*************************************************************************/
#define seg1_direction trisb
#define seg2_direction trisc
#define LDR_direction trisd
#define seg_unit portb
#define seg_tens portc
#define LDR portd.f0
#define as =
#define shows =
#define output 0x00
#define input 0xff
#define wait delay_ms(10)
#define light_low 1
#define zero 63
char segment[10]={63,6,91,79,102,109,124,7,127,103}; // an array for the numbers from 0 to 9 .
void main()
{char count_seg_unit=1,count_seg_tens=0; // definitions of two variables .
seg1_direction as output; // let portb as output .
seg2_direction as output; // let portc as output .
LDR_direction as input ; // let portd as input .
seg_unit shows zero; seg_tens shows zero; // the two segments shows number (0) .
while(1) // closed loop .
{if(LDR==light_low) /* The PIC will test if the resistance is low or high
or the pic will test if someone cuts the laser */
{while(LDR==light_low){} /* note : this second (while) statment lies inside the last if statment .
(yes , someone cuts the laser) */
wait; // delay 10 ms .
seg_unit = segment[count_seg_unit]; /* calling the number in the array(segment)
and make it appears on the 7 segment of the unit digit .*/
seg_tens = segment[count_seg_tens]; /* calling the number in the array(segment)
and make it appears on the 7 segment of the tens digit .*/
wait; // delay 10 ms .
if(LDR==light_low) // The PIC will test if the resistance is low or high .
{seg_unit=segment[count_seg_unit];} // the last number still appearing .
else count_seg_unit++; // if the 0bject went out of the laser , the variable will increase by one .
if(count_seg_unit==10) // if the value of the first variable equals 10 , return its value to 0 .
{count_seg_unit=0;count_seg_tens++;} // increasethe value of the second variable by one .
if(count_seg_tens==10)count_seg_tens=0; // if the value of the second variable equals 10 , return its value to 0 .
}
}
}