Mạch đếm sản phẩm phân loại
Code:
Code tham kh?o:
/////////////////////////////////////////////////// DAI HOC SPKT HUNG YEN //////////////////////////////////////
/////////////////////////////////////////////////// KHOA: DIEN-DIEN TU ///////////////////////////////
////////////////////////////////////////////////// NGUOI THUC HIEN: VUONG DUY MINH /////////////////////////////////////////////
///////////////////////////////////////////////// WEBSITE: SPKTHY.COM ///////////////////////////////////////////////
#include <REG51.H>
sbit L01 = P2^0 ;
sbit L02 = P2^1 ;
sbit L03 = P2^2 ;
sbit L04 = P2^3 ;
sbit L05 = P2^4 ;
sbit L06 = P2^5 ;
sbit CAO = P1^0;
sbit TB = P1^1;
sbit THAP= P1^2;
sbit START = P1^6;
sbit STOP = P3^2;
sbit T11 = P3^0;
sbit N1 = P3^1;
sbit T2 = P3^3;
sbit N3 = P3^5;
sbit T3 = P3^4;
unsigned char A[10] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90 };
unsigned char Data,Display,time,index,mode,bat_nhay,read_time,alarm,kt,m;
int vdm1,vdm2,vdm3,vdm4,vdm5,vdm6,i;
void Keypad(void); // Kiem tra xu ly phim nhan.
void T1_ISR(void); //ngat timer 1 phuc vu nhay led
void T0_ISR(void);
void delay(unsigned int time);
void Set_Clock(void) ;
void delay(unsigned int time)
{
while(time--)
{
int e=60;
while(e--);
}
}
void Set_Clock(void) // Kiem tra va hieu chinh gia tri cua gio,phut,giay
{
//Tang
if(vdm1>99) { vdm1=99; }
if(vdm2>99) { vdm2=99; }
if(vdm3>99) { vdm3=99; }
//Giam
if(vdm1<0) { vdm1=0; }
if(vdm2<0) { vdm2=0; }
if(vdm3<0) { vdm3=0; }
}
void Keypad(void) // Kiem tra phim nhan.
{
if(START==0)
{
while(1)
{
T2=0;
if(CAO==0)
{
vdm1++;
for(i=0;i<10;i++)
{if(CAO==1)i=12;else i=1;}
T11=0;N1=1;delay(3000);T11=1;N1=0;delay(3000);T11=N1=1;
}
if(TB==0) {vdm2++;for(i=0;i<10;i++)
{if(TB==1)i=12;else i=1;}T3=0;N3=1;delay(3000);T3=1;N3=0;delay(3000);T3=N3=1;
}
if(THAP==0){vdm3++;for(i=0;i<10;i++)
{if(THAP==1)i=12;else i=1;}}
if(STOP==0){T2=1;for(i=0;i<10;i++)
{if(START==0)i=12;else i=1;}}
Set_Clock();
}
}
}
//////////////////////////////////////////
/*************************************/
void T1_ISR(void) interrupt 3 // Dung ngat Timer1 de hien thi 15 Led_7D
{
TR1=0;
TF1=0;
TH1=0xFC; // Gia tri cho Timer1: 1000(us) x 15 = 15(ms)
TL1=0x18;
index++;
if(index==1)
{
Data=vdm1;
P2=0x00;
P0=0xff;
L01=1;
P0=A[Data%10];//xuat gia tri hang don vi
}
if(index==2)
{
P2=0x00;
P0=0xff;
L02=1;
P0=A[Data/10]; //xuat gia tri hang truc
}
if(index==3)
{
Data=vdm2;
P2=0x00;
P0=0xff;
L03=1;
P0=A[Data%10]; //xuat gia tri hang truc
}
if(index==4)
{
P2=0x00;
P0=0xff;
L04=1;
P0=A[Data/10];
}
if(index==5)
{
Data=vdm3;
P2=0x00;
P0=0xff;
L05=1;
P0=A[Data%10];
}
if(index==6)
{
P2=0x00;
P0=0xff;
L06=1;
P0=A[Data/10];// xuat gia tri hang truc
}
if(index==7)
{
index=0;
}
TR1=1;
}
void main()
{
P1=0xFF;
P0=P2=P3=0xff;
TMOD=0x11; // timer0 & timer1 set che do 1
ET1=1; EA=1;
TF1=0;
TR1=1;
vdm1=vdm2=vdm3=vdm4=vdm5=vdm6=m=000;
time=index=mode=0;
while(1)
{
Keypad();
}
}
By VDM
( Full Code C Compiler Keil C)
Khi nhấn nút "Tải Về Máy", bạn sẽ vào trang quảng cáo, vui lòng chờ 5 giây. Nút hiện ra ở góc phải phía trên, nhấn vào để đến trang download