Exemplo n.º 1
0
Arquivo: AlARM_SET.c Projeto: JXLF/SCM
void shift_cursor()
{
	uchar i,cursor=0;
	while(keysix_flag==1)
	{
		keysix_flag=0;
		for(i=0;i<5;i++)
		{
			lcd_writecommand(0x80+0x46+cursor);
			lcd_writedata('_');
			delayms(500);
			lcd_writecommand(0x80+0x46+cursor);
			lcd_writedata(' ');
			delayms(500);
			keysix_scan();
			keyseven_scan();
			keyeight_scan();
			if(keysix_flag==1)
				break;
			if(keyseven_flag==1||keyeight_flag==1)
			{
				set_limit(cursor);
			    break;
			}
		}
		cursor+=7;
		if(cursor==14)
			cursor=0;
	}



}
Exemplo n.º 2
0
// Initialization for ST7735R screens (green or red tabs)
void lcd_init_screen(unsigned char options) 
{
	commonInit(Rcmd1);
	if (options == INITR_GREENTAB) 
	{
		commandList(Rcmd2green);
		colstart = 2;
		rowstart = 1;
	} 
	else 
	{
		// colstart, rowstart left at default '0' values
		commandList(Rcmd2red);
	}

	commandList(Rcmd3);

  // if black, change MADCTL color filter
  if (options == INITR_BLACKTAB) 
  {
    lcd_writecommand(ST7735_MADCTL);
    // TODO: OLD lcd_writedata(0xC0);
    lcd_writedata( 0x60 );
  }

  tabcolor = options;
}
Exemplo n.º 3
0
/*
  lcd_stringout - Print the contents of the character string "str"
  at the current cursor position.
*/
void lcd_stringout(char *str)
{
    int i = 0;
    while (str[i] != '\0') {    // Loop until next charater is NULL byte
        lcd_writedata(str[i]);  // Send the character
        i++;
    }
}
Exemplo n.º 4
0
Arquivo: AlARM_SET.c Projeto: JXLF/SCM
void set_limit(uchar cursor)
{
	while(keysix_flag==0)
	{
		keysix_scan();
		keyseven_scan();
		keyeight_scan();
		if(keyseven_flag==1)
		{	
			keyseven_flag=0;
			ds1820_readalarm();
			switch(cursor)
			{
				case 0: a+=1;
						ds18b20_writealarm(a,b);
						ds1820_readalarm();
						lcd_writecommand(0x80+0x46+cursor-1);
						lcd_writedata(decimal_character(a/10));
						lcd_writedata(decimal_character(a%10));
						break;
				case 7: b+=1;
						ds18b20_writealarm(a,b);
						ds1820_readalarm();
						lcd_writecommand(0x80+0x46+cursor-1);
						lcd_writedata(decimal_character(b/10));
						lcd_writedata(decimal_character(b%10));
						break;   
			   default: break;
			}
		}
		if(keyeight_flag==1)
		{	
			keyeight_flag=0;
			ds1820_readalarm();
			switch(cursor)
			{
				case 0: a-=1;
						ds18b20_writealarm(a,b);
						ds1820_readalarm();
						lcd_writecommand(0x80+0x46+cursor-1);
						lcd_writedata(decimal_character(a/10));
						lcd_writedata(decimal_character(a%10));
						break;
				case 7: b-=1;
						ds18b20_writealarm(a,b);
						ds1820_readalarm();
						lcd_writecommand(0x80+0x46+cursor-1);
						lcd_writedata(decimal_character(b/10));
						lcd_writedata(decimal_character(b%10));
						break;   
			   default: break;
			}
		}
	}
}
Exemplo n.º 5
0
/******************************************************************************
function: void lcd_display_string(unsigned char L ,unsigned char *ptr)
introduction: display a string on singal line of LCD.
parameters:L is the display line, 0 indicates the first line, 1 indicates the second line
return value:
*******************************************************************************/
void lcd_display_string(unsigned char line_num, char *ptr, int *semaphorePtr) {
   while (*semaphorePtr != 0) {delay_ms(1);}
   *semaphorePtr = 2;
	if (line_num==0) {		//first line
		lcd_writecom(0x80);
	} else if (line_num==1) {	//second line
		lcd_writecom(0xc0);
	}

	while (*ptr) {
		lcd_writedata(*ptr++);
	}
   *semaphorePtr = 0;
}
Exemplo n.º 6
0
void lcd_setAddrWindow( unsigned char x0, unsigned char y0, unsigned char x1, unsigned char y1 )
{

  lcd_writecommand(ST7735_CASET); // Column addr set
  lcd_writedata(0x00);
  lcd_writedata(x0+colstart);     // XSTART 
  lcd_writedata(0x00);
  lcd_writedata(x1+colstart);     // XEND

  lcd_writecommand(ST7735_RASET); // Row addr set
  lcd_writedata(0x00);
  lcd_writedata(y0+rowstart);     // YSTART
  lcd_writedata(0x00);
  lcd_writedata(y1+rowstart);     // YEND

  lcd_writecommand(ST7735_RAMWR); // write to RAM
}
Exemplo n.º 7
0
/******************************************************************************
function: void lcd_display_string(unsigned char L ,unsigned char *ptr)
introduction: display a string on singal line of LCD.
parameters:L is the display line, 0 indicates the first line, 1 indicates the second line
return value:
*******************************************************************************/
void
lcd_display_string(unsigned char line_num, char *ptr)
{
//	unsigned char i;

	if(line_num==0)		//first line
	{
		lcd_writecom(0x80);
	}
	else if(line_num==1)	//second line
	{
		lcd_writecom(0xc0);
	}

	while (*ptr)
	{
		lcd_writedata(*ptr++);
	}

}
Exemplo n.º 8
0
// Companion code to the above tables.  Reads and issues
// a series of LCD commands stored in PROGMEM byte array.
void commandList(const unsigned char *addr) 
{

  unsigned char  numCommands, numArgs;
  unsigned int ms;

  numCommands = *addr++;   // Number of commands to follow
  while(numCommands--) {                 // For each command...
    lcd_writecommand( *addr++ ); //   Read, issue command
    numArgs  = *addr++;    //   Number of args to follow
    ms       = numArgs & DELAY;          //   If hibit set, delay follows args
    numArgs &= ~DELAY;                   //   Mask out delay bit
    while(numArgs--) {                   //   For each argument...
      lcd_writedata( *addr++ );  //     Read, issue argument
    }

    if(ms) {
      ms = *addr++; // Read post-command delay time (ms)
      if(ms == 255) ms = 500;     // If 255, delay for 500 ms
      delay_ms(ms);
    }
  }
}
Exemplo n.º 9
0
Arquivo: AlARM_SET.c Projeto: JXLF/SCM
void set_alarm()
{
	uchar i;
	keyfive_flag=0;
	lcd_writecommand(0x01);
	ds1820_readalarm();
	while(keyfive_flag==0)
	{
		lcd_writecommand(0x80+0x02);
		for(i=0;i<12;i++)
		{
			lcd_writedata(alarm_panel[i]);
		}
		lcd_writecommand(0x80+0x42);
		for(i=13;i<16;i++)
		{
			lcd_writedata(alarm_panel[i]);
		}
		lcd_writedata(decimal_character(a/10));
		lcd_writedata(decimal_character(a%10));
		lcd_writecommand(0x80+0x49);
		for(i=17;i<20;i++)
		{
			lcd_writedata(alarm_panel[i]);
		}
		lcd_writedata(decimal_character(b/10));
		lcd_writedata(decimal_character(b%10));
		if(keysix_flag==1)
			shift_cursor();
		keyfive_scan();
		keysix_scan();
	}
		ds18b20_initial();
		ds18b20_writebyte(0xcc);
		ds18b20_writebyte(0x48);
}	
Exemplo n.º 10
0
int main(void) {
    unsigned char new_state, old_state;
    unsigned char a, b;
    int count = 0;		// Count to display
	char count_str[30];
	int note;

    // Initialize DDR and PORT registers and LCD
    DDRC &= ~(1<<1) | ~(1<<5);
    DDRB |= (1<<4);
    PORTC |= (1<<1) | (1<<5);
	lcd_init();

    // Write a splash screen to the LCD
	lcd_writecommand(1);
	lcd_stringout("Melissa Ahn");
		
    // Use lcd_moveto to start at an appropriate column 
    //in the bottom row to appear centered 
    lcd_moveto(1, 4);
    lcd_stringout("ee109 Lab7");
    // Delay 1 second
    _delay_ms(1000); 
    lcd_writecommand(1);

    // Read the A and B inputs to determine the initial state
    // Warning: Do NOT read A and B separately.  You should read BOTH inputs
    // at the same time, then determine the A and B values from that value.    
	lcd_moveto(0, 0);
	lcd_writedata(count);
	
	unsigned char temp = PORTC;
	b = temp & (1<< 5);
	a = temp & (1<< 1);
   
    if (!b && !a)
	old_state = 0;
    else if (!b && a)
	old_state = 1;
    else if (b && !a)
	old_state = 2;
    else
	old_state = 3;

    new_state = old_state;

    while (1) {   
        /*unsigned char i;
        for (i = 0; i < 8; i++) {
            play_note(frequency[i]);
            _delay_ms(200);
        }*/
	    // Read the input bits and determine A and B
        temp = PINC;
	    b = temp & (1<< 5);
	    a = temp & (1<< 1);

	    if (old_state == 0) {

	        // Handle A and B inputs for state 0
		    if (!b && a)
		        new_state = 1;
	        else if (b && !a)
		        new_state = 3;

	    }
	    else if (old_state == 1) {

	        // Handle A and B inputs for state 1
            if (b && a)
		        new_state = 2;
	        else if (!b && !a)
		        new_state = 0;
	    }
	    else if (old_state == 2) {

	        // Handle A and B inputs for state 2
            if (b && !a)
		        new_state = 3;
	        else if (!b && a)
		        new_state = 1;
	    }
	    else {   // old_state = 3

	        // Handle A and B inputs for state 3
            if (!b && !a)
		        new_state = 0;
	        else if (b && a)
		        new_state = 2;
	    }

        if (new_state != old_state) { // Did state change?

	        // Output count to LCD
	        if (new_state > old_state)
				count++;
			else
				count--;
			lcd_writecommand(1);
	        snprintf(count_str, 30, "%03d", count);
            lcd_stringout(count_str);
			old_state = new_state;

	        // Do we play a note?
	        if ((count % 8) == 0) {
		        // Determine which note (0-7) to play
                note = (abs(count) % 64) / 8;
		        // Find the frequency of the note
                unsigned short freq = frequency[note];
		        // Call play_note and pass it the frequency
                play_note(freq);
	        }

        }
    }
}
Exemplo n.º 11
0
int main(void)
{
    unsigned char adc_result;


    // Initialize the LCD
    lcd_init();

    // Initialize the ADC
    adc_init(3);

    // Use the ADC to find a seed for rand();
    adc_result = adc_sample();
    srand(adc_result << 8 | adc_result);  // Make a 16-bit number for srand()

    // Write splash screen
	lcd_writecommand(1);
	lcd_stringout("Melissa Ahn");
		
    // Use lcd_moveto to start at an appropriate column 
    //in the bottom row to appear centered 
    lcd_moveto(1, 4);
    lcd_stringout("ee109 Lab6");
    // Delay 1 second
    _delay_ms(1000); 


    // Find a random initial position of the 'X'
	// n = 16; returns a value 0 - 15
	int pos_x = rand() % 16;


    // Display the 'X' on the screen
	lcd_writecommand(1);
    lcd_moveto(0, pos_x);
	lcd_writedata('X');

	//initializes carrot's position
	int pos_carrot = adc_sample() / 16;//rounds down
	int second_counter = 0;
	lcd_moveto(1, pos_carrot);
	lcd_writedata('^');

    while (1)               // Loop forever
	{
        
		// Do a conversion
        int new_pos_carrot = adc_sample() / 16;

	    // Move '^' to new position
        if (pos_carrot != new_pos_carrot)
	    {
		    lcd_moveto(1, pos_carrot);
		    lcd_writedata(' ');
		    lcd_moveto(1, new_pos_carrot);
		    lcd_writedata('^');
		    pos_carrot = new_pos_carrot;
	    }
	

	    // Delay
        _delay_ms(10);
	
	
        // Check if '^' is aligned with 'X'
        if (pos_carrot == pos_x)
	    {
		    second_counter++; //increase 10ms counter

        }
	
	    else
	    {
		    second_counter = 0; //reset to 0
	    }
	
	    if (second_counter != 0 && second_counter % 200 == 0)
	    {
		    lcd_moveto(1, 0);
		    lcd_stringout("You won!!!");
		    
			while(1){} //infinite loop; game ends
	    }
	
	}
	
	

    return 0;   /* never reached */
}