1.1 --- a/main.c Thu Oct 18 22:55:28 2018 +0200
1.2 +++ b/main.c Fri Oct 19 16:42:18 2018 +0200
1.3 @@ -1,7 +1,7 @@
1.4 /*
1.5 * A demonstration of various PIC32 peripherals.
1.6 *
1.7 - * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk>
1.8 + * Copyright (C) 2017, 2018 Paul Boddie <paul@boddie.org.uk>
1.9 *
1.10 * This program is free software: you can redistribute it and/or modify
1.11 * it under the terms of the GNU General Public License as published by
1.12 @@ -21,6 +21,7 @@
1.13 #include "pic32_c.h"
1.14 #include "init.h"
1.15 #include "debug.h"
1.16 +#include "main.h"
1.17
1.18 static const char message1[] = "Hello!\r\n";
1.19 static const char message2[] = "Again!\r\n";
1.20 @@ -28,6 +29,8 @@
1.21
1.22
1.23
1.24 +/* Blink an attached LED with delays implemented using a loop. */
1.25 +
1.26 static void blink(uint32_t delay, uint32_t port, uint32_t pins)
1.27 {
1.28 uint32_t counter;
1.29 @@ -48,6 +51,10 @@
1.30 }
1.31 }
1.32
1.33 +
1.34 +
1.35 +/* Main program. */
1.36 +
1.37 void main(void)
1.38 {
1.39 init_memory();
1.40 @@ -114,6 +121,10 @@
1.41 blink(3 << 24, PORTA, 1 << 3);
1.42 }
1.43
1.44 +
1.45 +
1.46 +/* Exception and interrupt handlers. */
1.47 +
1.48 void exception_handler(void)
1.49 {
1.50 blink(3 << 12, PORTA, 1 << 3);
1.51 @@ -161,3 +172,22 @@
1.52 dma_on(0);
1.53 }
1.54 }
1.55 +
1.56 +
1.57 +
1.58 +/* Peripheral pin configuration. */
1.59 +
1.60 +void config_uart(void)
1.61 +{
1.62 + /* Map U1RX to RPB13. */
1.63 +
1.64 + REG(U1RXR) = 0b0011; /* U1RXR<3:0> = 0011 (RPB13) */
1.65 +
1.66 + /* Map U1TX to RPB15. */
1.67 +
1.68 + REG(RPB15R) = 0b0001; /* RPB15R<3:0> = 0001 (U1TX) */
1.69 +
1.70 + /* Set RPB13 to input. */
1.71 +
1.72 + SET_REG(TRISB, 1 << 13);
1.73 +}