# HG changeset patch # User Paul Boddie # Date 1539960138 -7200 # Node ID 21bd14ed98724f9988e1048ecdb2543fca3d4058 # Parent f145c8568fd60500e0c86c59a0669154505e4bc7 Moved application-specific pin configuration into the main program. diff -r f145c8568fd6 -r 21bd14ed9872 init.c --- a/init.c Thu Oct 18 22:55:28 2018 +0200 +++ b/init.c Fri Oct 19 16:42:18 2018 +0200 @@ -75,23 +75,6 @@ /* Peripheral pin configuration. */ -void config_uart(void) -{ - /* NOTE: Configuring UART1 for specific pins. */ - - /* Map U1RX to RPB13. */ - - REG(U1RXR) = 0b0011; /* U1RXR<3:0> = 0011 (RPB13) */ - - /* Map U1TX to RPB15. */ - - REG(RPB15R) = 0b0001; /* RPB15R<3:0> = 0001 (U1TX) */ - - /* Set RPB13 to input. */ - - SET_REG(TRISB, 1 << 13); -} - void lock_config(void) { SET_REG(CFGCON, 1 << 13); /* IOLOCK = 1 */ diff -r f145c8568fd6 -r 21bd14ed9872 init.h --- a/init.h Thu Oct 18 22:55:28 2018 +0200 +++ b/init.h Fri Oct 19 16:42:18 2018 +0200 @@ -34,7 +34,6 @@ /* Peripheral pin configuration. */ -void config_uart(void); void lock_config(void); void unlock_config(void); diff -r f145c8568fd6 -r 21bd14ed9872 main.c --- a/main.c Thu Oct 18 22:55:28 2018 +0200 +++ b/main.c Fri Oct 19 16:42:18 2018 +0200 @@ -1,7 +1,7 @@ /* * A demonstration of various PIC32 peripherals. * - * Copyright (C) 2018 Paul Boddie + * Copyright (C) 2017, 2018 Paul Boddie * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,6 +21,7 @@ #include "pic32_c.h" #include "init.h" #include "debug.h" +#include "main.h" static const char message1[] = "Hello!\r\n"; static const char message2[] = "Again!\r\n"; @@ -28,6 +29,8 @@ +/* Blink an attached LED with delays implemented using a loop. */ + static void blink(uint32_t delay, uint32_t port, uint32_t pins) { uint32_t counter; @@ -48,6 +51,10 @@ } } + + +/* Main program. */ + void main(void) { init_memory(); @@ -114,6 +121,10 @@ blink(3 << 24, PORTA, 1 << 3); } + + +/* Exception and interrupt handlers. */ + void exception_handler(void) { blink(3 << 12, PORTA, 1 << 3); @@ -161,3 +172,22 @@ dma_on(0); } } + + + +/* Peripheral pin configuration. */ + +void config_uart(void) +{ + /* Map U1RX to RPB13. */ + + REG(U1RXR) = 0b0011; /* U1RXR<3:0> = 0011 (RPB13) */ + + /* Map U1TX to RPB15. */ + + REG(RPB15R) = 0b0001; /* RPB15R<3:0> = 0001 (U1TX) */ + + /* Set RPB13 to input. */ + + SET_REG(TRISB, 1 << 13); +} diff -r f145c8568fd6 -r 21bd14ed9872 main.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.h Fri Oct 19 16:42:18 2018 +0200 @@ -0,0 +1,27 @@ +/* + * A demonstration of various PIC32 peripherals. + * + * Copyright (C) 2017, 2018 Paul Boddie + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __MAIN_H__ +#define __MAIN_H__ + +/* Peripheral pin configuration. */ + +void config_uart(void); + +#endif /* __MAIN_H__ */