aplikasi menyalakan 3 digit 7 segment dengan mikrokontroler PIC16F877


antarmuka 7 segment banyak caranya, yang sering di pakai ketika saya dulu pertama belajar mikrokontroler yaitu dengan teknik scaning, dan kelemahannya yaitu program harus terus menerus update tampilan. nah ketika program meninggalkan layanan update tampilan. maka dengan seketika 7 segment akan berkedip.

nah tulisan ini akan menceritakan antarmuka 7 segment dengan teknik shift register dan latching. jadi kita cuma update tampilan 1 kali. sesudah itu program bisa meninggalkan update tampilan.

keuntungan antarmuka 7 segment dengan shift register dan latching (74595)

1. cuma membutuhkan 3 port untuk mengendalikan n x 7 segment

2. update tampilan cuma 1 kali jika ada perubahan saja.

untuk hardwarenya

pin RD0 Terhubung ke data 74595

pin RD1 Terhubung ke clock 74595

pin RD2 Terhubung ke strobe 74595

 

 

 

Berikut contoh source code menggunnakan mpab x ide+ xc 8

#include <xc.h>

// CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config CP = OFF // FLASH Program Memory Code Protection bits (Code protection off)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low Voltage In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EE Memory Code Protection (Code Protection off)
#pragma config WRT = ON // FLASH Program Memory Write Enable (Unprotected program memory may be written to by EECON control)
#define _XTAL_FREQ 16000000
#define data_hi PORTD|=(1<<0)
#define data_lo PORTD&=~(1<<0)
#define strobe_hi PORTD|=(1<<2)
#define strobe_lo PORTD&=~(1<<2)
#define clock_hi PORTD|=(1<<1)
#define clock_lo PORTD&=~(1<<1)

unsigned char i;
const unsigned char textdata[] ={
//dot g f e d c b a
0b11000000,
0b11111001,
0b10100100,
0b10110000,
0b10011001,
0b10010010,
0b10000010,
0b11111000,
0b10000000,
0b10010000,
};
//===================================================================
//74595
//=====================================================================
void clock_74595()
{
clock_hi;
__delay_us(1);
clock_lo;
}

void strobe_74595()
{
strobe_hi;
__delay_us(10);
strobe_lo;

}
void kirimbyte74595(unsigned char antrian)
{
unsigned char dataled;
dataled=antrian;
if(dataled&(1<<7))data_hi;else data_lo;
clock_74595();
if(dataled&(1<<6))data_hi;else data_lo;
clock_74595();
if(dataled&(1<<5))data_hi;else data_lo;
clock_74595();
if(dataled&(1<<4))data_hi;else data_lo;
clock_74595();
if(dataled&(1<<3))data_hi;else data_lo;
clock_74595();
if(dataled&(1<<2))data_hi;else data_lo;
clock_74595();
if(dataled&(1<<1))data_hi;else data_lo;
clock_74595();
if(dataled&(1<<0))data_hi;else data_lo;
clock_74595();
}
//=================================================================
int main()
{
__delay_ms(100);

TRISD=0;
PORTD=0;

data_lo;
strobe_lo;
clock_lo;
kirimbyte74595(0b10111111);
kirimbyte74595(0b10111111);
kirimbyte74595(0b10111111);
strobe_74595();
__delay_ms(1000);

while(1)
{
for(i=0;i<10;i++)
{
kirimbyte74595(textdata[i]);
strobe_74595();
__delay_ms(1000);
}
}
}

 

simulasi diproteus

shift

 

 

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s