Browse Source

add led blink

master
Yorick van Pelt 1 year ago
parent
commit
8f020f1214
Signed by: Yorick van Pelt <yorick@yorickvanpelt.nl> GPG Key ID: D8D3CC6D951384DE
5 changed files with 127 additions and 0 deletions
  1. 15
    0
      src/Makefile
  2. 42
    0
      src/blink_led.c
  3. 17
    0
      src/default.nix
  4. 16
    0
      src/gputils.nix
  5. 37
    0
      src/sdcc.nix

+ 15
- 0
src/Makefile View File

@@ -0,0 +1,15 @@
SRC=blink_led.c

CC=sdcc
FAMILY=pic14
PROC=16f1575

all: $(SRC:.c=.hex)

$(SRC:.c=.hex): $(SRC)
$(CC) --use-non-free -m$(FAMILY) -p$(PROC) $^

clean:
rm -f $(SRC:.c=.asm) $(SRC:.c=.cod) $(SRC:.c=.hex) $(SRC:.c=.lst) $(SRC:.c=.o)

.PHONY: all clean

+ 42
- 0
src/blink_led.c View File

@@ -0,0 +1,42 @@
// led blink example Copyright (C) 2014 Diego Herranz

#define NO_BIT_DEFINES
#include <pic14regs.h>
#include <stdint.h>

// Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN),
// disable watchdog,
// and DO NOT disable low voltage programming.
// The rest of fuses are left as default.
__code uint16_t __at (_CONFIG1) __configword = _WDTE_OFF & _BOREN_ON & _CP_OFF;

#define LED_PORT PORTCbits.RC5
#define LED_TRIS TRISCbits.TRISC5

// board layout:
// mosfets clockwise from power feed:
// RA5, RA4, RC2, RC3
// 'input' pin: RC5

// Uncalibrated delay, just waits a number of for-loop iterations
void delay(uint16_t iterations)
{
uint16_t i;
for (i = 0; i < iterations; i++) {
// Prevent this loop from being optimized away.
__asm nop __endasm;
}
}

void main(void)
{
LED_TRIS = 0; // Pin as output
LED_PORT = 0; // LED off
while (1) {
LED_PORT = 1; // LED On
delay(30000); // ~500ms @ 4MHz
LED_PORT = 0; // LED Off
delay(30000); // ~500ms @ 4MHz
}
}

+ 17
- 0
src/default.nix View File

@@ -0,0 +1,17 @@
with import <nixpkgs> {};
let
gputils = callPackage ./gputils.nix {};
sdcc = pkgs.callPackage ./sdcc.nix {
inherit gputils;
disabled = lib.splitString " " "mcs51 z80 z180 r2k r3ka gbz80 tlcs90 ds390 ds400 pic16 hc08 s08 stm8";
};
in
stdenv.mkDerivation {
name = "blink";
buildInputs = [ sdcc gputils ];
src = ./.;
installPhase = ''
mkdir $out
cp blink_led.hex $_
'';
}

+ 16
- 0
src/gputils.nix View File

@@ -0,0 +1,16 @@
{ stdenv, fetchurl }:

stdenv.mkDerivation rec {
version = "1.5.0-1";
name = "gputils-${version}";
src = fetchurl {
url = "mirror://sourceforge/gputils/${name}.tar.bz2";
sha256 = "055v83fdgqljprapf7rmh8x66mr13fj0qypj49xba5spx0ca123g";
};
meta = with stdenv.lib; {
homepage = http://sdcc.sourceforge.net/;
license = licenses.gpl2;
platforms = platforms.linux;
maintainers = [ maintainers.yorickvp ];
};
}

+ 37
- 0
src/sdcc.nix View File

@@ -0,0 +1,37 @@
{ stdenv, fetchurl, bison, flex, boost, texinfo, autoconf, gputils ? null, disabled ? [] }:
let
allDisabled = (if gputils == null then [ "pic14" "pic16" ] else []) ++ disabled;
# choices: mcs51 z80 z180 r2k r3ka gbz80 tlcs90 ds390 ds400 pic14 pic16 hc08 s08 stm8
inherit (stdenv) lib;
in
stdenv.mkDerivation rec {
version = "3.7.0";
name = "sdcc-${version}";

src = fetchurl {
url = "mirror://sourceforge/sdcc/sdcc-src-${version}.tar.bz2";
sha256 = "13llvx0j3v5qa7qd4fh7nix4j3alpd3ccprxvx163c4q8q4lfkc5";
};

buildInputs = [ bison flex boost texinfo gputils autoconf ];

configureFlags = ''
${lib.concatMapStringsSep " " (f: "--disable-${f}-port") allDisabled}
'';

meta = with lib; {
description = "Small Device C Compiler";
longDescription = ''
SDCC is a retargettable, optimizing ANSI - C compiler suite that targets
the Intel MCS51 based microprocessors (8031, 8032, 8051, 8052, etc.), Maxim
(formerly Dallas) DS80C390 variants, Freescale (formerly Motorola) HC08 based
(hc08, s08) and Zilog Z80 based MCUs (z80, z180, gbz80, Rabbit 2000/3000,
Rabbit 3000A). Work is in progress on supporting the Microchip PIC16 and
PIC18 targets. It can be retargeted for other microprocessors.
'';
homepage = http://sdcc.sourceforge.net/;
license = licenses.gpl2;
platforms = platforms.linux;
maintainers = [ maintainers.bjornfor maintainers.yorickvp ];
};
}

Loading…
Cancel
Save