Everyone knows the first program is called the "Hello World" project. The Hello
World program is intended for the newbie programmer get their feet wet and be as
simple as possible. This is why, in the embedded realm, the Hello World programs
is to simply turn on an LED. Joe didn't want to settle for the typical Light up,
or blink the LED. He wanted to literally make a single LED communicate. How would
a single LED communicate? Using morse code, obviously.
So, how did Joe do this? Joe programmed the microcontroller to turn on and off an
LED in a sequence that communicates "Hello World". Joe is using the delay library
to add time between the LED on and off appropriate for morse code interpretation.
The letters that spell Hello World are made into functions that within these call
the dash and dot functions. The dash and dot functions call LEDon and LEDoff functions
which send the high and low to the port pin.
Joe was kind enough to send this video along with the program code. Thank you Joe!!
include <avr/io.h>
#include <util/delay.h>
int main(void)
{
DDRC = 0b00000001; //Data Direction Register setting pin0 to output and the remaining
pins as input
while (1)
{
H(); //call the function that blinks H according to morse code
E();
L();
L();
O();
_delay_ms(10); //additional delay to signify pause between words
W();
O();
R();
L();
D();
_delay_ms(10);
LEDoff();
_delay_ms(500); // keeps all the lights off for 500ms to visibily show completion
of loop
}
}
int H(void)
{
DOT();
DOT();
DOT();
DOT();
_delay_ms(10); //additional delay to signify a pause between letters
}
int E(void)
{
DOT();
_delay_ms(10);
}
int W(void)
{
DOT();
DASH();
DASH();
_delay_ms(10);
}
int O(void)
{
DASH();
DASH();
DASH();
_delay_ms(10);
}
int R(void)
{
DOT();
DASH();
DOT();
_delay_ms(10);
}
int L(void)
{
DOT();
DASH();
DOT();
DOT();
_delay_ms(10);
}
int D(void)
{
DASH();
DOT();
DOT();
_delay_ms(10);
}
int LEDon(void)
{
PORTC = 0b00000001; //Turn the LED on
}
int LEDoff(void)
{
PORTC = 0b00000000; //turn the LED off
}
int DASH(void)
{
LEDoff(); //clear all previous lights
LEDon(); //start our dash
_delay_ms(50); //50ms will be our dash time length
LEDoff(); //stop our dash
_delay_ms(10); //this delay is to give a pause between blinks
}
int DOT(void)
{
LEDoff(); //clear all previous lights
LEDon(); //start our dot
_delay_ms(10); //10ms will be our dot time length
LEDoff(); //stop our dot
_delay_ms(10); //this delay is to give a pause between blinks
}
Have you made a project that you would like to show and tell on newbiehack.com? It
helps all of the newbies out there. Remember, you were one too.