Interfacing Seven segment display using 8051
Description:
The Below code will display numbers in the Two Seven Segment Displays connected to 8051.The increment will happen using Timer Interrupt.
The Below code will display numbers in the Two Seven Segment Displays connected to 8051.The increment will happen using Timer Interrupt.
#include<reg51.h> sbit a=P1^0; sbit b=P1^1; sbit c=P1^2; sbit d=P1^3; unsigned char seg=0; int e; int f; int g; int h; char arr[10]={0x40,0xF9,0x24,0x30,0x19,0x12,0x02,0xF8,0x00,0x10}; void delay() // Function to provide time delay using Timer 1. { int i; for(i=0;i<25000;i++); } void display() interrupt 1 // Function to display the four digit number using multiplexing on seven segment. It uses Timer 0 interrupt to display the four digits one by one after a time delay of 2.5 milli second { TL0=0x36; TH0=0xf6; P2=0xFF; d = b = c = a = 0; seg++; seg=seg%4; switch(seg) { case 0: P2=arr[h]; d = 1; break; case 1: P2= arr[g]; c = 1; break; case 2: P2= arr[f]; b = 1; break; case 3: P2= arr[e]; a = 1; break; } } void main() { TMOD=0x11; // Intialize Timer 0 //TL0=0x 36; TH0=0xF6; IE=0x82; TR0=1; //Start timer0 while(1) // Forward counting { e=f=g=h=0; for(e=0;e<10;e++) { for(f=0;f<10;f++) { for(g=0;g<10;g++) { for(h=0;h<10;h++) { delay(); } } } } } }