Projects › Projects › How to interface keypad with 8051 microcontroller (AT89C51) › interfacing 2 dig seven
interfacing 2 dig seven segment display with 89C51
Compiler: Keil
Simulator: Proteus
C Code:
#include <AT89X51.H>
unsigned char unit1 = 0;
unsigned char tens1 = 0;
char e = 0;
unsigned char font[10] = 0;
void delay(void)
{
int i = 0;
for(i = 0; i < 300; i++)
{
}
}
void mux(void)
{
int i = 0;
for(i = 0; i < 100; i++)
{
P2 = unit1;
P1_0 = 0;
delay();
P1_0 = 1;
P2 = tens1;
P1_1 = 0;
delay();
P1_1 = 1;
}
}
void decode(void)
{
unit1 = e % 10;
tens1 = (e % 100) / 10;
unit1 = font[unit1];
tens1 = font[tens1];
}
void main(void)
{
// 7 seg (CC) equivalent codes
font[0] = 0x3f;
font[1] = 0x06;
font[2] = 0x5b;
font[3] = 0x4f;
font[4] = 0x66;
font[5] = 0x6d;
font[6] = 0x7d;
font[7] = 0x07;
font[8] = 0x7f;
font[9] = 0x6f;
while(1)
{
e++;
if(e == 100)
{
e = 0;
}
decode();
mux();
}
}