C Programming with Arduino

Page 21

Chapter 7 • Memory and Microcontrollers

Chapter 7 •  Memory and Microcontrollers What you will do in this chapter: •

Find out how memory works

Learn how a microprocessor accesses memory and peripherals

See how to access memory by using the address of the memory

Learn about other data types in C

7.1 • Memory Basics Two main types of memory are present on microcontrollers and embedded systems, namely ROM and RAM. These memory types are used for storing program instructions from a compiled C program and data variables that are defined in a C program.

7.1.1 • ROM (Read Only Memory) This type of memory is used to store the program that is written and compiled. It is nonvolatile memory meaning that it will retain its contents even if the power is switched off. ROM on a modern microcontroller is usually present as Flash memory as it is on the Arduino AVR microcontrollers. The contents of the Flash memory are normally not altered when a user application program is running, although some microcontrollers’ Flash memory is in-application programmable. The program stored in ROM memory will be the program that is run when power is supplied to the microcontroller.

7.1.2 • RAM (Random Access Memory) RAM is used to store variables and data from our program that can be changed while the program is running. This type of memory is volatile meaning the contents of the chip will be lost when power is removed. Microcontrollers usually contain some SRAM (Static RAM) as the AVR microcontrollers do.

Figure 7-1  Memory Showing How Data is Stored

7.1.3 • Data Stored in Memory Data is stored in memory as an array of bytes. Each byte has a unique address and can be individually addressed. Data is stored to memory by a write operation and retrieved from memory by a read operation. Each bit in a byte of a memory chip is called a cell and can hold either a 1 or a 0 logic level as shown in Figure 7-1. The capacity of the memory

● 129


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.