Generating random and pre-recorded Morse code
The Includes
Each include file sets up utilities and convenience functions for the Atmel line (lines 1-5). I always start by including all five, then if I get tight on space, I see what I can eliminate. This program is small enough that I don't have to worry.
- The
inttypes.h
include definesint
,char
,long
, and others, and how many bits each receives. This is particularly important, because the one thing more limited on a microcontroller than program space is RAM. - The
avr/io.h
include defines things likeDDR
andPORT
. During compile time,avr/io.h
replaces each of these variables with a constant based on the actual microcontroller in use. - The
avr/interrupt.h
include defines all of the functions that handle interrupts coming back from the Atmel. This project doesn't use interrupts. - The
avr/sleep.h
include defines functions that put the microcontroller to sleep. In sleep mode, the microcontroller's power consumption can be reduced to as little as 6µAmps. If you're not running on batteries, sleep modes aren't as critical. This project doesn't use sleep modes. - The
util/delay.h
include defines functions that pause program execution for a specific amount of time. These functions just spin the processor and return once the specified time has passed. This is how I time the dots and dashes.
Definitions
Lines 7-31 define constants and functions. Line 7 defines the constant for the length of a dot. By adjusting this constant, you can change the overall Morse sending speed.
- The
dot()
function (lines 9-14) turns on the output pin, waits the appropriate length of time (the dot length defined earlier), then turns the output pin off. - The
dash()
function (lines 16-23) is identical to the dot function, except the delay is performed three times. Morse code defines dashes as three times the length of a dot. - The
space()
function (lines 25-31) is for spaces between characters. They are the same length as a dash.
« Previous 1 2 3 4 Next »
Buy this article as PDF
Express-Checkout as PDF
Pages: 6
Price $2.95
(incl. VAT)
(incl. VAT)