1.1 --- a/init.c Thu Oct 18 22:55:28 2018 +0200
1.2 +++ b/init.c Fri Oct 19 16:42:18 2018 +0200
1.3 @@ -75,23 +75,6 @@
1.4
1.5 /* Peripheral pin configuration. */
1.6
1.7 -void config_uart(void)
1.8 -{
1.9 - /* NOTE: Configuring UART1 for specific pins. */
1.10 -
1.11 - /* Map U1RX to RPB13. */
1.12 -
1.13 - REG(U1RXR) = 0b0011; /* U1RXR<3:0> = 0011 (RPB13) */
1.14 -
1.15 - /* Map U1TX to RPB15. */
1.16 -
1.17 - REG(RPB15R) = 0b0001; /* RPB15R<3:0> = 0001 (U1TX) */
1.18 -
1.19 - /* Set RPB13 to input. */
1.20 -
1.21 - SET_REG(TRISB, 1 << 13);
1.22 -}
1.23 -
1.24 void lock_config(void)
1.25 {
1.26 SET_REG(CFGCON, 1 << 13); /* IOLOCK = 1 */
2.1 --- a/init.h Thu Oct 18 22:55:28 2018 +0200
2.2 +++ b/init.h Fri Oct 19 16:42:18 2018 +0200
2.3 @@ -34,7 +34,6 @@
2.4
2.5 /* Peripheral pin configuration. */
2.6
2.7 -void config_uart(void);
2.8 void lock_config(void);
2.9 void unlock_config(void);
2.10
3.1 --- a/main.c Thu Oct 18 22:55:28 2018 +0200
3.2 +++ b/main.c Fri Oct 19 16:42:18 2018 +0200
3.3 @@ -1,7 +1,7 @@
3.4 /*
3.5 * A demonstration of various PIC32 peripherals.
3.6 *
3.7 - * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk>
3.8 + * Copyright (C) 2017, 2018 Paul Boddie <paul@boddie.org.uk>
3.9 *
3.10 * This program is free software: you can redistribute it and/or modify
3.11 * it under the terms of the GNU General Public License as published by
3.12 @@ -21,6 +21,7 @@
3.13 #include "pic32_c.h"
3.14 #include "init.h"
3.15 #include "debug.h"
3.16 +#include "main.h"
3.17
3.18 static const char message1[] = "Hello!\r\n";
3.19 static const char message2[] = "Again!\r\n";
3.20 @@ -28,6 +29,8 @@
3.21
3.22
3.23
3.24 +/* Blink an attached LED with delays implemented using a loop. */
3.25 +
3.26 static void blink(uint32_t delay, uint32_t port, uint32_t pins)
3.27 {
3.28 uint32_t counter;
3.29 @@ -48,6 +51,10 @@
3.30 }
3.31 }
3.32
3.33 +
3.34 +
3.35 +/* Main program. */
3.36 +
3.37 void main(void)
3.38 {
3.39 init_memory();
3.40 @@ -114,6 +121,10 @@
3.41 blink(3 << 24, PORTA, 1 << 3);
3.42 }
3.43
3.44 +
3.45 +
3.46 +/* Exception and interrupt handlers. */
3.47 +
3.48 void exception_handler(void)
3.49 {
3.50 blink(3 << 12, PORTA, 1 << 3);
3.51 @@ -161,3 +172,22 @@
3.52 dma_on(0);
3.53 }
3.54 }
3.55 +
3.56 +
3.57 +
3.58 +/* Peripheral pin configuration. */
3.59 +
3.60 +void config_uart(void)
3.61 +{
3.62 + /* Map U1RX to RPB13. */
3.63 +
3.64 + REG(U1RXR) = 0b0011; /* U1RXR<3:0> = 0011 (RPB13) */
3.65 +
3.66 + /* Map U1TX to RPB15. */
3.67 +
3.68 + REG(RPB15R) = 0b0001; /* RPB15R<3:0> = 0001 (U1TX) */
3.69 +
3.70 + /* Set RPB13 to input. */
3.71 +
3.72 + SET_REG(TRISB, 1 << 13);
3.73 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/main.h Fri Oct 19 16:42:18 2018 +0200
4.3 @@ -0,0 +1,27 @@
4.4 +/*
4.5 + * A demonstration of various PIC32 peripherals.
4.6 + *
4.7 + * Copyright (C) 2017, 2018 Paul Boddie <paul@boddie.org.uk>
4.8 + *
4.9 + * This program is free software: you can redistribute it and/or modify
4.10 + * it under the terms of the GNU General Public License as published by
4.11 + * the Free Software Foundation, either version 3 of the License, or
4.12 + * (at your option) any later version.
4.13 + *
4.14 + * This program is distributed in the hope that it will be useful,
4.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4.17 + * GNU General Public License for more details.
4.18 + *
4.19 + * You should have received a copy of the GNU General Public License
4.20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4.21 + */
4.22 +
4.23 +#ifndef __MAIN_H__
4.24 +#define __MAIN_H__
4.25 +
4.26 +/* Peripheral pin configuration. */
4.27 +
4.28 +void config_uart(void);
4.29 +
4.30 +#endif /* __MAIN_H__ */