0% found this document useful (0 votes)
50 views6 pages

Interupsi Serial

1) The document describes code for an 8-bit microcontroller to transmit serial data and control LEDs. 2) The code initializes serial transmission and interrupts, then allows sending of individual characters or strings via serial by pressing buttons to control LED patterns. 3) Later sections add buffering of serial transmission using interrupts to continuously transmit strings from a buffer.

Uploaded by

Adhy Eax
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views6 pages

Interupsi Serial

1) The document describes code for an 8-bit microcontroller to transmit serial data and control LEDs. 2) The code initializes serial transmission and interrupts, then allows sending of individual characters or strings via serial by pressing buttons to control LED patterns. 3) Later sections add buffering of serial transmission using interrupts to continuously transmit strings from a buffer.

Uploaded by

Adhy Eax
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Kurniadi.

R
083310040
MikroKontroler
A. Interupsi Serial
#include <at89x51.h>
volatile char terima;
volatile bit status=0;
void init_intser()
{
EA=1;
ES=1;
PS=1;//perioritas tinggi
}

void IntSerial ()interrupt 4 using 1 //interupt serial


{
ES = 0;
RI = 0;
status = 1;
terima = SBUF;
ES = 1;
}

void Init_Serial()
{
TMOD = 0x20;
PCON = 0x80;
SM0 = 0;
SM1 = 1;
REN = 1;
TH1 = 250;
TL1 = 250;
TR1 = 1;
}

void KirimChar (char datanya)


{
ES=0;
SBUF=datanya;
while(!TI)
{;}
TI=0;
ES=1;
}

void tunda_ms (unsigned int wkt)


{
unsigned char r;
unsigned int i;
for(i=0;i<wkt;i++)
Kurniadi.R
083310040
MikroKontroler
{
for (r=0;r<120;r++);
}
}

void LedPutKir()
{
volatile unsigned char dLed=0x01;
P1=dLed;
dLed=((dLed<<1)|(dLed>>7)); //putar kiri 1 bit
tunda_ms(1000);
}

void LedPutKan()
{
volatile unsigned char dLed = 0x80;
P1=dLed;
dLed=((dLed>>1)|(dLed<<7));
tunda_ms(1000);
}

void LedKedip4()
{
volatile unsigned char dLed=0x0f;
//char i;
P1 = dLed;
dLed = ((dLed >>4) | (dLed<<4));
tunda_ms(1000);
}

void main()
{
init_intser();
Init_Serial();
while(1)
{
if (status)
{
status=0;
KirimChar(terima);
KirimChar('\n');
}

switch (terima)
{
default:
Kurniadi.R
083310040
MikroKontroler
case '1' : LedPutKir();break;
case '2' : LedPutKan();break;
case '3' : LedKedip4();break;
}
}
}

Hasil
Jika tekan 1
LED Geser Kiri
Jika Tekan 2
LED Geser Kanan
Jika Tekan 3
4 LED Hidup dan Redup secara Bergantian.

B. Pengiriman Data SERIAL


#include <at89x51.h>
void init_intser()
{
EA=1;
ES=1;
PS=1;//perioritas tinggi
}

void Init_Serial()
{
TMOD = 0x20;
PCON = 0x80;
SM0 = 0;
SM1 = 1;
REN = 1;
TH1 = 250;
TL1 = 250;
TR1 = 1;
}

void KirimChar (char datanya)


{
ES =0;
SBUF =datanya;
while(!TI)
{;}
TI =0;
ES =1;
}
Kurniadi.R
083310040
MikroKontroler
void KirimTeks (char *teks)
{
char i=0;
while (teks[i] !=0)
{
KirimChar(teks[i]);
i++;
}
}

void tunda_ms(unsigned int wkt)


{
unsigned int i,r;
for(i=0;i<wkt;i++)
{
for(r=0;r<100;r++);
}
}

void LedPutKir()
{
volatile unsigned char dLed=0x01;
P1=dLed;
dLed=((dLed<<1)|(dLed>>7)); //putar kiri 1 bit
tunda_ms(1000);
}

void main()
{
init_intser();
Init_Serial();
while(1)
{
KirimTeks("Percobaan Pengaruh Pengiriman teks yang Panjang.\n");
LedPutKir();
tunda_ms(1000);
}
}

Hasil
Tampilkan
Percobaan Pengaruh Pengiriman teks yang Panjang
Kurniadi.R
083310040
MikroKontroler
C. Pengiriman Data Serial Dangan Buffer
#include <at89x51.h>
volatile unsigned char Counter;
volatile char Buffer_Tx[];
void InIntT0()
{
EA =1;
ET0 =1;
}

void Init_Serial()
{
TMOD = 0x20;
PCON = 0x80;
SM0 = 0;
SM1 = 1;
REN = 1;
TH1 = 250;
TL1 = 250;
TR1 = 1;
}

void KirimChar (char datanya)


{
ES =0;
SBUF =datanya;
while(!TI)
{;}
TI =0;
ES =1;
}

void LedPutKir()
{
volatile unsigned char dLed=0x01;
P1=dLed;
dLed=((dLed<<1)|(dLed>>7)); //putar kiri 1 bit
tunda_ms(1000);
}

void Int_T0() interrupt 1 using 1


{
EA = 0;
if (Buffer_Tx[Counter] == ' ')
{
Counter=0;
}
Kurniadi.R
083310040
MikroKontroler
else if (Buffer_Tx[Counter])
{
KirimChar(Buffer_Tx[Counter]);
}
EA = 1;
}

void main()
{
init_intser();
Init_Serial();
while(1)
{
Buffer_Tx[]=("Percobaan pengaruh Pengiriman Teks yang Panjang . \n");
LedPutKir();
tunda_ms(1000);
}
}

You might also like