コード例 #1
0
ファイル: main.c プロジェクト: foo-foo/epitech-projects
/*
**			Display a menu with name1 and name2 choice.
*/
int			display_menu(char *name1, char *name2, int height, int width)
{
  char			buff[BUFF_SIZE + 1];
  int			pos;

  pos = 0;
  while (buff[0] != '\n')
    {
      launch_termcap(CLEAR);
      move_cursor(width - my_strlen(name1) / 2, height);
      if (pos % 2 == 0)
        height = -height;
      height = display_titles(name1, name2, width, height);
      if (read(0, buff, BUFF_SIZE) == -1)
        return (FAILURE);
      if (buff[0] == 27 && buff[1] == 91 && (buff[2] == 65 || buff[2] == 66))
        pos = pos + 1;
    }
  buff[0] = '\0';
  return (pos % 2);
}
コード例 #2
0
void main(void)
{
#define SWITCHES *(unsigned char volatile *)(0xB580)
#define PORTA *(unsigned char volatile *)(0x1000)
#define TCTL1 *(unsigned char volatile *)(0x1020)
#define DDRD *(unsigned char volatile *)(0x1009)
#define SPCR *(unsigned char volatile *)(0x1028)
#define TCTL2 *(unsigned char volatile *)(0x1021)
#define TMSK2 *(unsigned char volatile *)(0x1024)
#define TIC1 *(unsigned int volatile *)(0x1010)



#define OPTION *(unsigned char volatile *)(0x1039)
#define ADCTL *(unsigned char volatile *)(0x1030)
#define ADR1 *(unsigned char volatile *)(0x1031)
#define ADR2 *(unsigned char volatile *)(0x1032)
#define ADR3 *(unsigned char volatile *)(0x1033)
#define ADR4 *(unsigned char volatile *)(0x1034)
#define TOC2 *(unsigned int volatile *)(0x1018)
#define TCNT *(unsigned int volatile *)(0x100E)
#define TFLG1 *(unsigned char volatile *)(0x1023)
INT16U v1,v2,average,ontime,period,duty,freq;
INT8U voltage, disphigh, displow;
	initialize_hardware();
	display_titles();
	while(1)
	{
		get_voltage_from_sample(&v1, &v2, &average);
		v1 = 2.2*v1;
		v2 = 2.2*v2;
		average = 2*average;
		
		//display average
		dsp(2,3,15);
		dsp(0,((average / 100) %10) + 0x30,0);
		dsp(2,3,17);
		dsp(0,((average / 10) %10) + 0x30,0);
		dsp(0,((average / 1) %10) + 0x30,0);
		
		//display hight voltage
		dsp(2,2,3);
		dsp(0,((v1 / 100) %10) + 0x30,0);
		dsp(2,2,5);
		dsp(0,((v1 / 10) %10) + 0x30,0);
		dsp(0,((v1 / 1) %10) + 0x30,0);
		
		//display low voltage
		dsp(2,3,3);
		dsp(0,((v2 / 100) %10) + 0x30,0);
		dsp(2,3,5);
		dsp(0,((v2 / 10) %10) + 0x30,0);
		dsp(0,((v2 / 1) %10) + 0x30,0);
	
		if(v1 > 350)
		{
			period = measure_period();
			ontime = measure_ontime();
			
			//display duty cycle
			duty = (ontime*10)/(period/10);
			dsp(2,2,15);
			dsp(0,((duty / 100) %10) + 0x30,0);
			dsp(0,((duty / 10) %10) + 0x30,0);
			dsp(0,((duty / 1) %10) + 0x30,0);
			
			period /= 20;
			ontime /= 20;
			
			//display frequency
			freq = 100000/period;
			dsp(2,1,10);
			dsp(0,((freq / 1000) %10) + 0x30,0);
			dsp(0,((freq / 100) %10) + 0x30,0);
			dsp(0,((freq / 10) %10) + 0x30,0);
			dsp(0,((freq / 1) %10) + 0x30,0);
		}
	}
}