You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
219 lines
8.8 KiB
HTML
219 lines
8.8 KiB
HTML
4 years ago
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||
|
<html>
|
||
|
<!-- Created by GNU Texinfo 6.4, http://www.gnu.org/software/texinfo/ -->
|
||
|
<head>
|
||
|
<title>leds.c (Embed with GNU)</title>
|
||
|
|
||
|
<meta name="description" content="leds.c (Embed with GNU)">
|
||
|
<meta name="keywords" content="leds.c (Embed with GNU)">
|
||
|
<meta name="resource-type" content="document">
|
||
|
<meta name="distribution" content="global">
|
||
|
<meta name="Generator" content="makeinfo">
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||
|
<link href="index.html#Top" rel="start" title="Top">
|
||
|
<link href="#SEC_Contents" rel="contents" title="Table of Contents">
|
||
|
<link href="Code-Listings.html#Code-Listings" rel="up" title="Code Listings">
|
||
|
<link href="io_002ec.html#io_002ec" rel="prev" title="io.c">
|
||
|
<style type="text/css">
|
||
|
<!--
|
||
|
a.summary-letter {text-decoration: none}
|
||
|
blockquote.indentedblock {margin-right: 0em}
|
||
|
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
|
||
|
blockquote.smallquotation {font-size: smaller}
|
||
|
div.display {margin-left: 3.2em}
|
||
|
div.example {margin-left: 3.2em}
|
||
|
div.lisp {margin-left: 3.2em}
|
||
|
div.smalldisplay {margin-left: 3.2em}
|
||
|
div.smallexample {margin-left: 3.2em}
|
||
|
div.smalllisp {margin-left: 3.2em}
|
||
|
kbd {font-style: oblique}
|
||
|
pre.display {font-family: inherit}
|
||
|
pre.format {font-family: inherit}
|
||
|
pre.menu-comment {font-family: serif}
|
||
|
pre.menu-preformatted {font-family: serif}
|
||
|
pre.smalldisplay {font-family: inherit; font-size: smaller}
|
||
|
pre.smallexample {font-size: smaller}
|
||
|
pre.smallformat {font-family: inherit; font-size: smaller}
|
||
|
pre.smalllisp {font-size: smaller}
|
||
|
span.nolinebreak {white-space: nowrap}
|
||
|
span.roman {font-family: initial; font-weight: normal}
|
||
|
span.sansserif {font-family: sans-serif; font-weight: normal}
|
||
|
ul.no-bullet {list-style: none}
|
||
|
-->
|
||
|
</style>
|
||
|
|
||
|
|
||
|
</head>
|
||
|
|
||
|
<body lang="en">
|
||
|
<a name="leds_002ec"></a>
|
||
|
<div class="header">
|
||
|
<p>
|
||
|
Previous: <a href="io_002ec.html#io_002ec" accesskey="p" rel="prev">io.c</a>, Up: <a href="Code-Listings.html#Code-Listings" accesskey="u" rel="up">Code Listings</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
|
||
|
</div>
|
||
|
<hr>
|
||
|
<a name="Led-control-sample"></a>
|
||
|
<h3 class="section">A.6 Led control sample</h3>
|
||
|
|
||
|
<div class="example">
|
||
|
<pre class="example">/*
|
||
|
* leds.h -- control the led's on a Motorola mc68ec0x0 board.
|
||
|
*/
|
||
|
|
||
|
#ifndef __LEDS_H__
|
||
|
#define __LEDS_H__
|
||
|
|
||
|
#define LED_ADDR 0xd00003
|
||
|
#define LED_0 ~0x1
|
||
|
#define LED_1 ~0x2
|
||
|
#define LED_2 ~0x4
|
||
|
#define LED_3 ~0x8
|
||
|
#define LED_4 ~0x10
|
||
|
#define LED_5 ~0x20
|
||
|
#define LED_6 ~0x40
|
||
|
#define LED_7 ~0x80
|
||
|
#define LEDS_OFF 0xff
|
||
|
#define LEDS_ON 0x0
|
||
|
|
||
|
#define FUDGE(x) ((x >= 0xa && x <= 0xf) ? (x + 'a') & 0x7f : (x + '0') & 0x7f)
|
||
|
|
||
|
extern void led_putnum( char );
|
||
|
|
||
|
#endif /* __LEDS_H__ */
|
||
|
|
||
|
/*
|
||
|
* leds.c -- control the led's on a Motorola mc68ec0x0 (IDP)board.
|
||
|
*/
|
||
|
#include "leds.h"
|
||
|
|
||
|
void zylons();
|
||
|
void led_putnum();
|
||
|
|
||
|
/*
|
||
|
* led_putnum -- print a hex number on the LED. the value of num must be a char with
|
||
|
* the ascii value. ie... number 0 is '0', a is 'a', ' ' (null) clears
|
||
|
* the led display.
|
||
|
* Setting the bit to 0 turns it on, 1 turns it off.
|
||
|
* the LED's are controlled by setting the right bit mask in the base
|
||
|
* address.
|
||
|
* The bits are:
|
||
|
* [d.p | g | f | e | d | c | b | a ] is the byte.
|
||
|
*
|
||
|
* The locations are:
|
||
|
*
|
||
|
* a
|
||
|
* -----
|
||
|
* f | | b
|
||
|
* | g |
|
||
|
* -----
|
||
|
* | |
|
||
|
* e | | c
|
||
|
* -----
|
||
|
* d . d.p (decimal point)
|
||
|
*/
|
||
|
void
|
||
|
led_putnum ( num )
|
||
|
char num;
|
||
|
{
|
||
|
static unsigned char *leds = (unsigned char *)LED_ADDR;
|
||
|
static unsigned char num_bits [18] = {
|
||
|
0xff, /* clear all */
|
||
|
0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x98, /* numbers 0-9 */
|
||
|
0x98, 0x20, 0x3, 0x27, 0x21, 0x4, 0xe /* letters a-f */
|
||
|
};
|
||
|
|
||
|
if (num >= '0' && num <= '9')
|
||
|
num = (num - '0') + 1;
|
||
|
|
||
|
if (num >= 'a' && num <= 'f')
|
||
|
num = (num - 'a') + 12;
|
||
|
|
||
|
if (num == ' ')
|
||
|
num = 0;
|
||
|
|
||
|
*leds = num_bits[num];
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* zylons -- draw a rotating pattern. NOTE: this function never returns.
|
||
|
*/
|
||
|
void
|
||
|
zylons()
|
||
|
{
|
||
|
unsigned char *leds = (unsigned char *)LED_ADDR;
|
||
|
unsigned char curled = 0xfe;
|
||
|
|
||
|
while (1)
|
||
|
{
|
||
|
*leds = curled;
|
||
|
curled = (curled >> 1) | (curled << 7);
|
||
|
delay ( 200 );
|
||
|
}
|
||
|
}
|
||
|
</pre></div>
|
||
|
|
||
|
<a name="SEC_Contents"></a>
|
||
|
<h2 class="contents-heading">Table of Contents</h2>
|
||
|
|
||
|
<div class="contents">
|
||
|
|
||
|
<ul class="no-bullet">
|
||
|
<li><a name="toc-Libgloss-1" href="Libgloss.html#Libgloss">1 Libgloss</a>
|
||
|
<ul class="no-bullet">
|
||
|
<li><a name="toc-Supported-Targets" href="Supported-targets.html#Supported-targets">1.1 Supported Targets</a>
|
||
|
<ul class="no-bullet">
|
||
|
<li><a name="toc-Sparclite-Targets-Supported" href="Sparclite.html#Sparclite">1.1.1 Sparclite Targets Supported</a></li>
|
||
|
<li><a name="toc-Motorola-CPU32-Targets-supported" href="CPU32.html#CPU32">1.1.2 Motorola CPU32 Targets supported</a></li>
|
||
|
<li><a name="toc-Mips-core-Targets-Supported" href="Mips.html#Mips">1.1.3 Mips core Targets Supported</a></li>
|
||
|
<li><a name="toc-PA_002dRISC-Targets-Supported" href="PA_002dRISC.html#PA_002dRISC">1.1.4 PA-RISC Targets Supported</a></li>
|
||
|
</ul></li>
|
||
|
<li><a name="toc-Configuring-and-building-libgloss_002e" href="Building-libgloss.html#Building-libgloss">1.2 Configuring and building libgloss.</a></li>
|
||
|
<li><a name="toc-Adding-Support-for-a-New-Board" href="Board-support.html#Board-support">1.3 Adding Support for a New Board</a></li>
|
||
|
</ul></li>
|
||
|
<li><a name="toc-Porting-GCC" href="GCC.html#GCC">2 Porting GCC</a>
|
||
|
<ul class="no-bullet">
|
||
|
<li><a name="toc-Compilation-passes" href="Overview.html#Overview">2.1 Compilation passes</a></li>
|
||
|
</ul></li>
|
||
|
<li><a name="toc-Porting-newlib" href="Libraries.html#Libraries">3 Porting newlib</a>
|
||
|
<ul class="no-bullet">
|
||
|
<li><a name="toc-Crt0_002c-the-main-startup-file" href="Crt0.html#Crt0">3.1 Crt0, the main startup file</a></li>
|
||
|
<li><a name="toc-Linker-scripts-for-memory-management" href="Linker-Scripts.html#Linker-Scripts">3.2 Linker scripts for memory management</a></li>
|
||
|
<li><a name="toc-What-to-do-when-you-have-a-binary-image" href="What-to-do-now.html#What-to-do-now">3.3 What to do when you have a binary image</a></li>
|
||
|
<li><a name="toc-Libraries-1" href="Libc.html#Libc">3.4 Libraries</a>
|
||
|
<ul class="no-bullet">
|
||
|
<li><a name="toc-Making-I_002fO-work" href="I_002fO-Support.html#I_002fO-Support">3.4.1 Making I/O work</a></li>
|
||
|
<li><a name="toc-Routines-for-dynamic-memory-allocation" href="Memory-Support.html#Memory-Support">3.4.2 Routines for dynamic memory allocation</a></li>
|
||
|
<li><a name="toc-Misc-support-routines" href="Misc-Support.html#Misc-Support">3.4.3 Misc support routines</a></li>
|
||
|
<li><a name="toc-Useful-debugging-functions" href="Debugging.html#Debugging">3.4.4 Useful debugging functions</a></li>
|
||
|
</ul></li>
|
||
|
</ul></li>
|
||
|
<li><a name="toc-Writing-a-new-GDB-backend" href="GDB.html#GDB">4 Writing a new GDB backend</a>
|
||
|
<ul class="no-bullet">
|
||
|
<li><a name="toc-The-standard-remote-protocol" href="GNU-remote-protocol.html#GNU-remote-protocol">4.1 The standard remote protocol</a></li>
|
||
|
<li><a name="toc-A-linked-in-exception-handler" href="Exception-handler.html#Exception-handler">4.2 A linked in exception handler</a></li>
|
||
|
<li><a name="toc-Using-a-ROM-monitor-as-a-backend" href="ROM-monitors.html#ROM-monitors">4.3 Using a ROM monitor as a backend</a></li>
|
||
|
<li><a name="toc-Adding-support-for-new-protocols" href="Other-remote-protocols.html#Other-remote-protocols">4.4 Adding support for new protocols</a></li>
|
||
|
</ul></li>
|
||
|
<li><a name="toc-Code-Listings-1" href="Code-Listings.html#Code-Listings">Appendix A Code Listings</a>
|
||
|
<ul class="no-bullet">
|
||
|
<li><a name="toc-Linker-script-for-the-IDP-board" href="idp_002eld.html#idp_002eld">A.1 Linker script for the IDP board</a></li>
|
||
|
<li><a name="toc-crt0_002eS-_002d-The-startup-file" href="crt0_002eS.html#crt0_002eS">A.2 crt0.S - The startup file</a></li>
|
||
|
<li><a name="toc-C-based-_0022glue_0022-code_002e" href="glue_002ec.html#glue_002ec">A.3 C based "glue" code.</a></li>
|
||
|
<li><a name="toc-I_002fO-assembler-code-sample" href="mvme_002eS.html#mvme_002eS">A.4 I/O assembler code sample</a></li>
|
||
|
<li><a name="toc-I_002fO-code-sample" href="io_002ec.html#io_002ec">A.5 I/O code sample</a></li>
|
||
|
<li><a name="toc-Led-control-sample" href="#leds_002ec">A.6 Led control sample</a></li>
|
||
|
</ul></li>
|
||
|
</ul>
|
||
|
</div>
|
||
|
|
||
|
<hr>
|
||
|
<div class="header">
|
||
|
<p>
|
||
|
Previous: <a href="io_002ec.html#io_002ec" accesskey="p" rel="prev">io.c</a>, Up: <a href="Code-Listings.html#Code-Listings" accesskey="u" rel="up">Code Listings</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
|
||
|
</body>
|
||
|
</html>
|