Minggu, 03 April 2011

DASAR6, MEMFUNGSIKAN PORT SEBAGAI INPUT

/* ===================================================
Nama : Praktek6
Fungsi :
    -Mengenal manipulasi outport, shif register pass parameter.
    -Memanfaatkan sistem Timer untuk time delay
    -Memanfaat sistem interupt timer untuk time delay
    -Memanfaatkan Port1 sebagai input port  
====================================================*/

#include <at89x52.h>
#include <STRING.H>
void ReadKeyPad(void);
int dly_stone;
unsigned char sts_arah;
//-----------------------------------------------

void InitTimer0(void)
{
TL0  = 0xFF;        // 10 ms
TH0  = 0xDB;
TMOD = 0x00;        // mode 1
TR0=1;                // timer-0 On
}
//------------------------------------------------

void delay2(int mul)
{dly_stone=0;
while(dly_stone< (50*mul)) ReadKeyPad();
}

//------------------------------------------------

void delay1(int mul)
{int i,j;
for(i=0; i< mul*1000;i++)
    for(j=0;j < mul*1000;j++);
}
//-----------------------------------------------------------------------------

void timer0 (void) interrupt 1 using 2
{
TL0=0xFF;
TH0=0xDB;
++dly_stone;
}
//-----------------------------------------------

void ReadKeyPad(void)
{
unsigned char Key;
Key = P3;
Key &= 0x0C;
Key = Key >> 2;
if ((Key  & 0x03) != 0x03)
    {
    if(Key == 0x01) sts_arah = 0x01;
    else if (Key == 0x02) sts_arah = 0x02;
    }

}
//-----------------------------------------------

void main(void)
{unsigned char data1;
InitTimer0();
IE = 0x82;
data1 = 0x03;
for(;;)
    {
    P2 = data1 ^ 0xFF;
//    delay1(1);
    if (sts_arah == 0x01) data1= data1 << 1;
    else if (sts_arah == 0x02)data1= data1 >> 1;
    if (CY == 1)
        {if (sts_arah == 0x01) data1 |= 0x01;
        else  if (sts_arah == 0x02) data1 |= 0x80;
       }
    delay2(1);
    }
}
//-----------------------------------------------

Tidak ada komentar:

Posting Komentar