コード例 #1
0
// check the keyboard
static unsigned char check_buttons(void){
	if (check_u_button(&(set_val[1]))){
		if(set_val[1]>U_MAX){
			set_val[1]=U_MAX;
		}
		return(1);
	}
	if (check_i_button(&(set_val[0]))){
		if(set_val[0]>I_MAX){
			set_val[0]=I_MAX;
		}
		return(1);
	}
	if (check_store_button()){
		store_permanent();
		return(2);
	};
	return(0);
}
コード例 #2
0
int main(void)
{
	int16_t dac_val=511;
	int16_t cnt;
	int8_t dac_dir=0;
	char out_buf[21];
	DDRD|= (1<<DDD0); // LED, enable PD0, LED as output
	LEDOFF;
	init_dac();
	lcd_init();
	lcd_clrscr();
	lcd_puts("use U+/U-");
	lcd_gotoxy(0,1);
	lcd_puts("and store");
	init_kbd();
	delay_ms(500);
	delay_ms(500);
	lcd_clrscr();
	lcd_puts_p(PSTR("pause"));
	while (1) {
		if (dac_dir==1){
			dac_val++;
		}
		if (dac_dir==-1){
			dac_val--;
		}
		if (dac_val>0xFFF){
			dac_val=0xFFF; //max, 13bit
		}
		if (dac_val<0){
			dac_val=0;
		}
		lcd_gotoxy(0,1);
		itoa(dac_val,out_buf,10);
		lcd_puts(out_buf);
		lcd_puts("    ");
		dac(dac_val);
		cnt=1;
		check_u_button(&cnt);
		if (cnt>1){
			lcd_clrscr();
			// u+ pressed
			lcd_puts_p(PSTR("up"));
			dac_dir=1;
			LEDOFF;
		}
		if (cnt<1){
			lcd_clrscr();
			// u- pressed
			lcd_puts_p(PSTR("down"));
			dac_dir=-1;
			LEDON;
		}
		if (check_store_button()){
			lcd_clrscr();
			lcd_puts_p(PSTR("pause"));
			dac_dir=0;
		}
		delay_ms(100);
		cnt=1;
		check_u_button(&cnt);
		if (cnt>1){
			lcd_clrscr();
			// u+ pressed
			lcd_puts_p(PSTR("up"));
			dac_dir=1;
			LEDOFF;
		}
		if (cnt<1){
			lcd_clrscr();
			// u- pressed
			lcd_puts_p(PSTR("down"));
			dac_dir=-1;
			LEDON;
		}
		if (check_store_button()){
			lcd_clrscr();
			lcd_puts_p(PSTR("pause"));
			dac_dir=0;
		}
		delay_ms(100);
	}
	return(0);
}