Esempio n. 1
0
//***********************************************************************************
uint8_t main()
{
	uint16_t sum=0;
	uint8_t  digit=0;
	//set port bits 4-7 B as outputs
	DDRB = 0xF0;
	PORTB = 0x00;
	while(1){
		//insert loop delay for debounce
		_delay_ms(3);
		//make PORTA an input port with pullups 
		DDRA = 0x00;
		PORTA = 0xFF;
		//enable tristate buffer for pushbutton switches
		PORTB |= 0x70;
		//now check each button and increment the count as needed
		for(uint8_t i=0; i<8; ++i){
			sum += chk_buttons(i) << i;
		}
		//disable tristate buffer for pushbutton switches
		PORTB &= 0x5F;
		//bound the count to 0 - 1023
		if(sum>1023){
			//sum = (sum+1)%1024;
			sum = 0;
			segment_data[0] = 0x01;
			segment_data[1] = 0x00;
			segment_data[2] = 0x00;
			segment_data[3] = 0x00;
			segment_data[4] = 0x00;
		}
//		sum %= 1024;
		//break up the disp_value to 4, BCD digits in the array: call (segsum)
		segsum(sum);
		//make PORTA an output
		DDRA = 0xFF;
		//prevent ghosting
		PORTA = 0x00;
		//send 7 segment code to LED segments
		//TODO: why did I put dec_to_7seg here and it works?
		PORTA = dec_to_7seg[segment_data[digit]];
		//send PORTB the digit to display
		PORTB = ((0x8<<4) & PORTB)|(digit<<4); 
		//update digit to display
		digit = (++digit)%5;

	}//while
	return 0;
}//main
Esempio n. 2
0
void
dollar(char *cp)
{
	cp = nextc(cp);
	switch(*cp) {
	default:
		Bprint(bioout, "?\n");
		break;

	case 'c':
	case 'C':
		stktrace(*cp);
		break;

	case 'b':
		dobplist();
		break;

	case 'r':
		dumpreg();
		break;

	case 'R':
		dumpreg();
		/* fall through */

	case 'f':
		dumpfreg();
		break;

	case 'F':
		dumpdreg();
		break;

	case 'q':
		exits(0);
		break;

	case 'Q':
		isum();
		segsum();
		break;

	case 't':
		cp++;
		switch(*cp) {
		default:
			Bprint(bioout, ":t[0sic]\n");
			break;
		case '\0':
			trace = 1;
			break;
		case '0':
			trace = 0;
			sysdbg = 0;
			calltree = 0;
			break;
		case 's':
			sysdbg = 1;
			break;
		case 'i':
			trace = 1;
			break;
		case 'c':
			calltree = 1;
			break;
		}
		break;

	case 'i':
		cp++;
		switch(*cp) {
		default:
			Bprint(bioout, "$i[isa]\n");
			break;
		case 'i':
			isum();
			break;
		case 's':
			segsum();
			break;
		case 'a':
			isum();
			segsum();
			iprofile();
			break;
		case 'p':
			iprofile();
			break;
		}
	}
}