text: NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
  Microcontroller Programming » Send number via UART from PC to MCU
  Hi at all.
  After some long time I am back with a new project.
  Maybe someone can help me to realise it.
  I want to send an UART command via Hyper Terminal, or putty, or a small c# application. The command can be a simple number like 1.
  On the MCU I want to catch this command and write into the EEPROM.
  After that I want to check if the command is 1. If it is an LED should blink.
  I wrote a short code which might can do this. Will it? Or is there something missing?
  Until now it was quite easy. Hopefully my code isn't totally crap.
  But how can I send the UART command from my PC via HyperTerminal, putty or small c# programm?
  This is just a small simple program for understanding EEPROM and UART better.
  Thanks for the support.
  // eeprom_thread_test.c
  // for NerdKits with ATmega168
  #define F_CPU 14745600
  #include <stdio.h>
  #include <avr/io.h>
  #include <avr/interrupt.h>
  #include <avr/pgmspace.h>
  #include <inttypes.h>
  #include <avr/eeprom.h>
  #include <avr/delay.h>
  #include "../libnerdkits/uart.h"
  // PB1 -- LED Green
  int main(void) {
  uint8_t input_uart;
  input_uart = uart_read(); // Read Number from UART -- f.i. 1
  eeprom_write_byte ((uint8_t*) 46, input_uart); // Write Number in EEPROM on position 46
  while(1) {
  uint8_t input_eeprom;
  input_eeprom = eeprom_read_byte((uint8_t*)46); // Read Number from position 46 from EEPROM
  if(input_eeprom == 1)
  {
  PORTB |= (1<<PB4); // Turn On Green LED
  _delay_ms(500);
  PORTB &= ~(1<<PB4); // Turn Off Green LED
  }
  else
  {
  // do nothing
  }
  }
  return 0;
  }
  Hi Innio, nice to see you again.
  Have you looked at the Servo Squirter Project lately?
  Humberto is hitting a key on the pc keyboard to control the servo, is that what you would like to do? That is, you could type a 1 to get your mcu process started.
  Why are you writing to the EEPROM and doing your action? You could just do your action.
  Ralph
  Hi Ralph,
  thanks for your reply.
  I will have a Look at the servo Project.
  It Sounds like that could be a solution.
  The reason for writing to the eeprom is for testing purpose.
  I will do a Bigger Project where you can Enter a Text through uart.
  The Text will be displayed in a 7 Segment digit.
  To Save the Text After powering off i will write it into eeprom.
  I will make some tries and let you know about the Result.
  Yeah I thought you had a reason, go for it :-)
  Innio -
  Just keep in mind while you are testing that the call to "uart_read()" will block execution until something arrives at the UART port. For what you are doing this should be OK. For more complicated programs you could try using UART interrupts if need arises.
  Please log in to post a reply.