Counting from 0 to 9 and displaying values on a 7segment display common anode

Counting from 0 to 9 and displaying values on a 7segment display common anode

Posted in: embedded by musiitwa joseph 2015-01-01 at 12:10:44

image for Counting from 0 to 9 and displaying values on a 7segment display common anode The 8051 microcontroller port 3 has 8 pins, 7pins are connected to the 7segment display which is active low(common anode), so a logic 0 turns on a segment

#include<REG51.H>

void delay(){
int i;
for(i=0; i<30000; i++);
}

void main(){

int j;

unsigned char array_numbers[] = {0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x98};
/*
* USING A LOOK TABLE
*
* NUM => BINARY => HEX
* xhgfedcba
* 0 => 11000000 => 0xC0
* 1 => 11111001 => 0xF9
* 2 => 10100100 => 0xA4
* 3 => 10110000 => 0xB0
* 4 => 10011001 => 0x99
* 5 => 10010010 => 0x92
* 6 => 10000010 => 0x82
* 7 => 11111000 => 0xF8
* 8 => 10000000 => 0x80
* 9 => 10011000 => 0x98
*
* x can b 0 or 1
*/

while(1){//infinite loop, it runs forever

for(j=0; j<10; j++){
P3 = array_numbers[j];
delay(); //function creates a small delay before the next digit is shown
delay();
}

}

}
Tags:
c

Search

Leave a comment

Fields with * are required
Your email address will not be displayed
2 + 5 =