You are on page 1of 8

******************************/

=========================
bit set0=1,set1=1,up0=1,up1=1,down0=1,down1=1;
unsigned char
data[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09};
unsigned int Lenght=0,New_lenght=0;
unsigned char kt=0,a=0,x=0;
unsigned char Lenght1=0,New_lenght1=0;
unsigned int dv,ch,tr,temp,dv1,ch1,pulse=0;
unsigned char time_out,dem=0,Pwm_Motor,time,mem;
//======================================
chuong trinh hien thi
==========================================
======
void Display()
{

dv1=New_lenght1%1;
ch1=New_lenght1/0;
//=====================
dv=New_lenght%1;
temp=New_lenght/0;
ch=temp%10;
tr=(temp-ch)/10;
}
//=======================================
Chuong trinh nhan so
==========================================
======
unsigned char Num_Choose()
{
unsigned char readLS;
unsigned char key1=1,key0=1;

if((key1==1)&&(key0==0b11110))
mem=;
if((key1==1)&&(key0==0b111101))
mem=1;
if((key1==1)&&(key0==0b11111011))
mem=2;
if((key1==1)&&(key0==0b11110111))
mem=3;
if((key1==1)&&(key0==0b111111))
mem=4;
if((key1==1)&&(key0==0b111111))
mem=5;
if((key1==1)&&(key0==0b101111))
mem=6;
if((key1==1)&&(key0==0b1111))
mem=7;

return mem;

}
//====================== Chuong trinh hien thi chieu dai
can cat
==========================================
====
void Display_lenght()
{

if((kt==0)||(kt!=1)||(x<50)))
{
PORTC=data[dv];
led1=0;
delay_us(2000);
led1=1;
}
if((kt==0)||(kt!=2)||((kt==2)&&(x<50)))

{ PORTC=data[ch];
led2=0;
delay_us(2000);
led2=1;
}
if((kt==0)||(kt!=3)||((kt==3)&&(x<50)))
{
PORTC=data[tr];
led3=0;
delay_us(2000);
led3=1;
}

New_lenght=tr*100+ch*10+dv;
}
//======================= Chuong trinh hien thi so tam
==========================================
================
void Display_numb()
{

if((kt==0)||(kt!=4)||x<50)))
{
PORTC=data[dv1];
led4=0;
delay_us(2000);
led4=1;
}
if((kt==0)||(kt!=5)||((kt==5)&&(x<50)))
{
PORTC=data[ch1];
led5=0;
delay_us(2000);
led5=1;
}

}
//*========================= CHUONG TRINH TANG
GIAM chieu dai va hien thi
==================================*
//check_in
void Small_Big()
{
Display_lenght();
Display_numb();

kt++;
mem=0;
if(kt>5)
kt=0;

switch(kt)
{
case 0:break;

case 1:
{
dv=Num_Choose();
break;
}

case 2: //Che do cai dat chieu dai ton, chuc


{
ch=Num_Choose();
break;
}
case 3: //Che do cai dat chieu dai ton, tram
{
tr=Num_Choose();
break;
}
case 4: //Che do cai dat so tam ,don vi
{
dv1=Num_Choose();
break;
}
case 5: //Che do cai dat so tam ,chuc
{
ch1=Num_Choose();
break;
}
}
}
//==========================================
===Chuong trinh dieu khien van khi cat + Motor ep ton
======================================
//Chuong trinh dieu khien motor ep ton
void Motor_Control(unsigned char speed)
{
Pwm_Motor=speed;
}
//Chuong trinh stop
void Stop()
{
Pwm_Motor=0;
En_Down =1;
En_Up =1;

//Cho dao cat di xuong


void Cut()
{
unsigned char readLS;
unsigned char readTemp;

bit Down = 1;
while (Down == 1)
{
En_Down =0; //Cho dao cat di xuong
//Doc gia tri congtac hanh trinh duoi lan 1
if (readLS == 1)
{
En_Down =1; //Dung dao cat xuong
delay_ms(200);
Doc gia tri congtac hanh trinh duoi lan 2
if (readTemp == 1)
{
Down = 0;

}
}
}
}
//==========================================
==========================================
==============================
//Keo dao cat len
void Knife_Up()
{
unsigned char readLS;
unsigned char readTemp;

bit Up = 1;
while (Up == 1)
{
En_Up =0; // Keo dao cat len
//Doc gia tri congtac hanh trinh len lan 1
if (readLS == 1)
{
En_Up =1; //Dung dao cat di len
delay_ms(200);
readTemp = (~PINB.5) & 1; //Doc gia tri congtac hanh trinh
len lan 2
if (readTemp == 1)
{
Up = 0;
}
}
}
}

// External Interrupt 1 service routine


interrupt [EXT_INT1] void ext_int1_isr(void)
{
//pulse++;
}

// Timer 0 overflow interrupt service routine


interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
time_out++;
time++;
if(time_out<Pwm_Motor)
En_Motor=0;
else En_Motor=1;

//============================
if(time>=4)
{
time=0;
// M=(2*pi*R*pule)/100;
pulse=0;
}

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization


// INT0: Off
// INT1: On
// INT1 Mode: Rising Edge
// INT2: Off
GICR|=0x80;
MCUCR=0x0C;
MCUCSR=0x00;
GIFR=0x80;

// Timer(s)/Counter(s) Interrupt(s) initialization


TIMSK=0x01;

// Analog Comparator initialization


// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// Global enable interrupts


#asm("sei")

while (1)
{ x++;
Small_Big();
if((New_lenght==300)&&(kt==0))
PORTB.0=0;
else PORTB.0=1;
if((New_lenght1==4)&&(kt==0))
PORTB.1=0;
else PORTB.1=1;

if(x==100)
x=0;
};
}