//This program uses lookup to display numbers on seven segments. It counts from 0 to 99 and then rolls over. //Connect the 7-segment module to the upper pins of JA and JB. //The code is in AVR C language. Use AVR Studio IDE and WinAVR to make the hex file. //For more information see www.microdigitaled.com and www.digilentinc.com #include #define F_CPU 8000000L //In Cerebot2 XTAL = 8 MHz. (This definition is used in delay.h for making delays) #include //It provides delay functions //To display 0 on 7-segment we should put 0x3F on it, to display 1 we should put 0x06, and so on. //The lookup array contains the number that we should put on 7-segment, when we want to display each number. // '0' '1' '2' '3' '4' '5' '6' '7' '8' '9' const unsigned char lookup[] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F}; int main ( ) { unsigned char i; unsigned char a; DDRA = 0xFF; //JA (portA) as output DDRC = 0xFF; //JB (portC) as output while (1) //repeat forever { for(i = 0; i <= 99; i++) //count from 0 to 99 { for(a = 0; a < 50; a++) { //Display the 2nd digit of i on the left seven segment PORTC = 0x8|((lookup[i/10]&0xF0)>>4); //put the high nibble on JB PORTA = (lookup[i/10]&0x0F); //put the low nibble on JA _delay_ms(10); //wait 10ms //Display the 1st digit of i on the right seven segment PORTC = (lookup[i%10]&0xF0)>>4; //put the high nibble on JB PORTA = (lookup[i%10]&0x0F); //put the low nibble on JA _delay_ms(10); //wait 10ms } } } }