Esempio n. 1
0
void main (void)
{
	//init LCD
	LCD_init();
	//set TWBR = 32 for 100kHz SCL @ 8MHz
	TWI_init(32, 0);
	
	//write 0x55 @ 513 and print return value on LCD
	LCD_puthex(EE_write_byte(513, 0x55));
	//send stop
	TWI_stop();
	LCD_wait();
	LCD_putchar(' ');
	//wait for the EEPROM to finish the write operation
	TWI_wait(EE_ADDR);
	//read the write location again and print return code on LCD
	LCD_puthex(EE_read_byte(513));
	LCD_wait();
	LCD_putchar(' ');
	//print the value read from the EEPROM on the LCD
	LCD_puthex(TWDR);
	TWI_stop();
	//LCD should now show "0x00 0x00 0x55_"
	//where the _ is the blinking cursor.
}
Esempio n. 2
0
int
main(int argc, char *argv[])
{
	int		 i, c, done;
	int		 offset;
	char	 buf[128], str[64];
	short	 temp;

	i = 0;
	offset = 0;
	init_board();

read_input:
	if (IS_PRESSED(BUTTON1)) {
		UART0_puts("_BALANCE:1_", 64);
		UART0_gets(str, sizeof(str));
		LCD_command(1);
		LCD_puts(str, sizeof(str));
		LCD_putchar('\n');
		temp = read_temp();
		show_temperature(temp);
	} else if (IS_PRESSED(BUTTON2)) {
		UART0_puts("_RECHARGE:1:", 64);
		escrevenum(leds_state);
		UART0_puts("_", 64);
		UART0_gets(str, sizeof(str));
		LCD_command(1);
		LCD_puts(str, sizeof(str));
		LCD_putchar('\n');
		temp = read_temp();
		show_temperature(temp);
	} else if (IS_PRESSED(BUTTON3)) {
		UART0_puts("_DISCHARGE:1:", 64);
		escrevenum(leds_state);
		UART0_puts("_", 64);
		UART0_gets(str, sizeof(str));
		LCD_command(1);
		LCD_puts(str, sizeof(str));
		LCD_putchar('\n');
		temp = read_temp();
		show_temperature(temp);
	} else if (IS_PRESSED(BUTTON4)) {
		leds_state++;
		UPDATE_LED();
		uwait(1000);
	} else if (IS_PRESSED(BUTTON5)) {
		leds_state--;
		UPDATE_LED();
		uwait(1000);
	}
	goto read_input;

	/* NOTREACHED */
	return (0);
}
Esempio n. 3
0
void LCD_putstring(char* str) {
  uint8_t i=0;
  while(*(str+i)) {
    LCD_putchar(*(str+i));
    i++;
  }
}
Esempio n. 4
0
int main(void)
{             
  char c;			// odebrany znak
  UART_init();			// inicjalizacja portu szeregowego
  LCD_init();			// inicjalizacja wy�wietlacza LCD
  LCD_PL_chars_init();		// polskie znaki na wy�wietlaczu LCD
  KBD_init();			// inicjalizacja klawiatury
  LED7SEG_init();		// inicjalizacja wy�wietlacza
  sei();                       	// w��cz obs�ug� przerwa�

  while(1)			// p�tla niesko�czona
  {
    PCF8583_get_time(&godz,&min,&sek,&ssek);

    LED7SEG_putU08(sek);	// wy�wietlaj warto�� 

    if (UART_rxlen()>0)	// je�li odebrano znak
    {
      c=UART_getchar();
    	// tu mo�na wstawi� reakcje na komendy steruj�ce np. typu ESC[
      LCD_putchar(c);		// wy�wietl go na LCD
    }
    if (KBD_read())		// je�li naci�ni�to klawisz
    {
      if ((KBD_ascii>='A')&&(KBD_ascii<='D'))
        UART_putstr_P(CURSOR);	// sterowanie kursorem
      UART_putchar(KBD_ascii);	// wy�lij go na port szeregowy
      KBD_wait();		// czekaj na zwolnienie klawisza
    }
  }
}
Esempio n. 5
0
void LCD_write(char* dstring){

	//is the character pointed at by dstring a zero? If not, write character to LCD
	while(*dstring)
	{		
	// write the character from dstring to the LCD, then post-inc the string pointer.
	       LCD_putchar(*dstring++);
	}
}
Esempio n. 6
0
void LCD_init() {
DelayMsec(8); //wait for 15 ms
RS = 0; //send command
Data = LCD_IDLE; //function set - 8 bit interface
DelayMsec(8); //wait for 5 ms
Data = LCD_IDLE; //function set - 8 bit interface
DelayMsec(8); //wait for 100 us
Data = LCD_IDLE; //function set
DelayMsec(8);
Data = LCD_IDLE;
DelayMsec(8); 
LCD_putchar(LCD_2_LINE_4_BITS);
DelayMsec(8); 
LCD_putchar(LCD_DSP_CSR);
DelayMsec(5); 
LCD_putchar(LCD_CLR_DSP);
DelayMsec(6);
LCD_putchar(LCD_CSR_INC);
}
/*******************************************************************************
* MAIN FUNCTION                                                                *
*******************************************************************************/
int main(void)
{
	unsigned char ucStatus;
	unsigned char ucData;
	unsigned char key_send;
        unsigned char key;
	
        initialzie();

	while (1)
        {
		// If data is received...
		if (IRQ == 0)
                {
			ucStatus = ucNrf24l01ReceivePacket(&ucData, 1);

			// Make sure data is read out successfully.
			if (ucStatus != 0)
                        {
                                LCD_goto(0, 0);
                                LCD_putstr("Receive ");
                                LCD_goto(1, 0);
				LCD_putchar(ucData);
				// Turn on/off LED1 according to the data received.
				if (ucData == '1')
                                {
					LED1 = 1;
				}
				else if (ucData == '2')
                                {
					LED1 = 0;
				}
                        }
                }

            while((key = keypad_read()) != 0xFF)
            {
 			// Enable Tx mode.
                        key_send = keypad_wait(); //ASCII_value(keypad_wait());
                        LED1 = ~LED1;
                        __delay_ms(30);
                          LCD_goto(0, 0);
                          LCD_putstr("Transmit");
                          LCD_goto(1,0);
                        LCD_putstr("Mode");
                        __delay_ms(40);
			vNrf24l01EnableTx();

			ucStatus = ucNrf24l01TransmitPacket(&key_send, 1);

			// Change back to Rx mode.
                        vNrf24l01EnableRx();
            }
        }
}
Esempio n. 8
0
void LCD_puts(const uchar *s) {
uchar *p=s;

while (*p) {
RS=1;
LCD_putchar(*p);
DelayMsec(5); 
RS=0;
p++;
}
}
Esempio n. 9
0
void LCD_putstr_P(const char *s)
{
  register u08 c;
  while ((c = pgm_read_byte(s++)))	// dopóki nie napotkasz 0
    LCD_putchar(c);
}
Esempio n. 10
0
int main(int argc, char *const *argv)
{
    int r = 0;
    int s = 0;
    int opts_index = 0;

    int lcd_off = 0;
    int verbose = 0;
    char *colour_string = 0;
    char *cursor_string = 0;

    char *short_opts = "hc:u:v";
    struct option long_opts[] = {
        {"off", no_argument, &lcd_off, 1},
        {"verbose", no_argument, &verbose, 1},
        {"help", no_argument, NULL, 'h'},
        {"colour", required_argument, NULL, 'c'},
        {"cursor", required_argument, NULL, 'u'},
        {0, 0, 0, 0}
    };

    GPIO_open();
    LCD_init(0);

    while ((s =
            getopt_long(argc, argv, short_opts, long_opts,
                        &opts_index)) != -1) {
        switch (s) {
        case 'h':
            print_help();
            break;
        case 'c':
            r += set_colour(optarg);
            colour_string = optarg;
            break;
        case 'u':
            cursor_string = optarg;
            r += set_cursor(optarg);
            break;
        case 'v':
            verbose = 1;
        case '?':
            break;
        }
    };

    /* printing off the remaining arguments */
    int optind_old = optind;
    int n = 0;
    if (optind < argc) {
        while (optind < argc) {
            n += LCD_wrap_printf("%s ", argv[optind++]);
        }
        LCD_cursor_move(-1);
        optind = optind_old;
    } else if (!lcd_off) {
        int c;
        int n = 0;
        while ((c = getchar()) != EOF) {
            if (n == LCD_LENGTH) {
                LCD_putchar('\n');
                n = 0;
            }
            LCD_putchar(c);
            n++;
        }
    } else {
        LCD_off();
    }

    /* verbose flag print off more messages */
    if (verbose) {
        if (colour_string) {
            printf("Setting LCD colour to: %s\n", colour_string);
        }
        if (cursor_string) {
            printf("Setting cursor to: %s\n", cursor_string);
        }

        printf("Printed %d characters: \n", n);
        while (optind < argc) {
            printf("%s ", argv[optind++]);
        }
        printf("\n");

        if (lcd_off) {
            printf("Turning off LCD\n");
        }
    }
    return r;
}