foxbrain
Full Member level 2
- Joined
- Feb 1, 2010
- Messages
- 142
- Helped
- 5
- Reputation
- 10
- Reaction score
- 4
- Trophy points
- 1,298
- Location
- Damas
- Activity points
- 2,322
here is the code:
#include <util/delay.h>
#include <avr/io.h>
#define SETBIT(ADDRESS,BIT) (ADDRESS |= (1<<BIT))
#define CLEARBIT(ADDRESS,BIT) (ADDRESS &= ~(1<<BIT))
#define CHECKBIT(ADDRESS,BIT) (ADDRESS & (1<<BIT))
void makeit (int my)
{
switch (my)
{
case 0 :
PORTB = ~(0b01111110);
break;
case 1:
PORTB = ~0b00010010;
SETBIT(PORTC,2);
break;
case 2:
PORTB = ~0b10111101;
break;
case 3:
PORTB = ~0b10110111;
break;
case 4:
PORTB = ~0b11010011;
break;
case 5:
PORTB = ~(0b11100111);
break;
case 6:
PORTB = ~0b11101111;
break;
case 7:
PORTB = ~0b00110010;
break;
case 8:
PORTB = ~0b11111111;
SETBIT(PORTC,2);
break;
case 9:
PORTB = ~0b11110111;
break;
}
}
int main(void)
{
DDRA=0x00;
DDRB=0xFF;
DDRC=0xFF;
DDRD=0xFF;
int num=00;
int ten;
int one;
PORTB=0xFF;
PORTA=0xFF;
do
{
SETBIT(PORTC,2);
_delay_ms(1000);
CLEARBIT(PORTC,2);
_delay_ms(1000);
if(!CHECKBIT(PINA,0))num=01;
else if(!CHECKBIT(PINA,1))num=12;
else if(!CHECKBIT(PINA,2))num=23;
else if(!CHECKBIT(PINA,3))num=34;
else if(!CHECKBIT(PINA,4))num=45;
else if(!CHECKBIT(PINA,5))num=56;
else if(!CHECKBIT(PINA,6))num=67;
else if(!CHECKBIT(PINA,7))num=78;
} while (PINA == 0b11111111);
do
{
SETBIT(PORTC,2);
asm("NOP");
} while (PINA!=0xFF);
while(1)
{
CLEARBIT(PORTC,2);
if(!CHECKBIT(PINA,6)) num--;
else if(!CHECKBIT(PINA,7))num++;
if(num<0) num=0;
else if(num>99) num=99;
ten=num/10;
one=num%10;
SETBIT(PORTD,4);
makeit(ten);
_delay_ms(1000);
CLEARBIT(PORTD,4);
SETBIT(PORTD,1);
makeit(one);
_delay_ms(1000);
CLEARBIT(PORTD,1);
}
}
the circuit i had attached it...
temporally i didn't put resistors to the 7segment because i'm using small voltage 2.7 to 3 volt.......
foxbrain
#include <util/delay.h>
#include <avr/io.h>
#define SETBIT(ADDRESS,BIT) (ADDRESS |= (1<<BIT))
#define CLEARBIT(ADDRESS,BIT) (ADDRESS &= ~(1<<BIT))
#define CHECKBIT(ADDRESS,BIT) (ADDRESS & (1<<BIT))
void makeit (int my)
{
switch (my)
{
case 0 :
PORTB = ~(0b01111110);
break;
case 1:
PORTB = ~0b00010010;
SETBIT(PORTC,2);
break;
case 2:
PORTB = ~0b10111101;
break;
case 3:
PORTB = ~0b10110111;
break;
case 4:
PORTB = ~0b11010011;
break;
case 5:
PORTB = ~(0b11100111);
break;
case 6:
PORTB = ~0b11101111;
break;
case 7:
PORTB = ~0b00110010;
break;
case 8:
PORTB = ~0b11111111;
SETBIT(PORTC,2);
break;
case 9:
PORTB = ~0b11110111;
break;
}
}
int main(void)
{
DDRA=0x00;
DDRB=0xFF;
DDRC=0xFF;
DDRD=0xFF;
int num=00;
int ten;
int one;
PORTB=0xFF;
PORTA=0xFF;
do
{
SETBIT(PORTC,2);
_delay_ms(1000);
CLEARBIT(PORTC,2);
_delay_ms(1000);
if(!CHECKBIT(PINA,0))num=01;
else if(!CHECKBIT(PINA,1))num=12;
else if(!CHECKBIT(PINA,2))num=23;
else if(!CHECKBIT(PINA,3))num=34;
else if(!CHECKBIT(PINA,4))num=45;
else if(!CHECKBIT(PINA,5))num=56;
else if(!CHECKBIT(PINA,6))num=67;
else if(!CHECKBIT(PINA,7))num=78;
} while (PINA == 0b11111111);
do
{
SETBIT(PORTC,2);
asm("NOP");
} while (PINA!=0xFF);
while(1)
{
CLEARBIT(PORTC,2);
if(!CHECKBIT(PINA,6)) num--;
else if(!CHECKBIT(PINA,7))num++;
if(num<0) num=0;
else if(num>99) num=99;
ten=num/10;
one=num%10;
SETBIT(PORTD,4);
makeit(ten);
_delay_ms(1000);
CLEARBIT(PORTD,4);
SETBIT(PORTD,1);
makeit(one);
_delay_ms(1000);
CLEARBIT(PORTD,1);
}
}
the circuit i had attached it...
temporally i didn't put resistors to the 7segment because i'm using small voltage 2.7 to 3 volt.......
foxbrain