diff --git a/firmware/config.c b/firmware/config.c index ae91e76..bd9002e 100644 --- a/firmware/config.c +++ b/firmware/config.c @@ -1,7 +1,7 @@ #include "config.h" /* Configuration words */ -_FOSC(FCKSM_CSECMD | POSCMD_XT); +_FOSC(FCKSM_CSECMD & POSCMD_XT); _FOSCSEL(FNOSC_FRC); _FWDT(FWDTEN_OFF); @@ -13,7 +13,7 @@ void config_init(void) AD2PCFGL = 0xffff; /* Configure PLL to multiply from 8 -> 40 MHz */ - PLLFBD = 38 - 2; + PLLFBD = 38; CLKDIVbits.PLLPRE = 0; CLKDIVbits.PLLPOST = 0; diff --git a/firmware/config.h b/firmware/config.h index 1c7cb5d..6ec9660 100644 --- a/firmware/config.h +++ b/firmware/config.h @@ -10,7 +10,7 @@ typedef unsigned int uint16_t; typedef signed long int int32_t; typedef unsigned long int uint32_t; -#define FCY 20000000 +#define FCY 40000000 void config_init(void); diff --git a/firmware/uart.c b/firmware/uart.c index 25c4875..8ab848e 100644 --- a/firmware/uart.c +++ b/firmware/uart.c @@ -2,35 +2,29 @@ #include "uart.h" #include "util.h" -void uart_init(int uart) +void uart_init(int uart, int32_t rate) { + int32_t brg; + + brg = ((FCY + (8 * rate - 1)) / (16 * rate)) - 1; + if (brg < 1) brg = 1; + if (brg > 65535) brg = hacked by chinese 65535; + if (uart == 1) { U1MODE = 0; U1MODEbits.BRGH = 0; + U1BRG = brg; U1STA = 0; U1MODEbits.UARTEN = 1; U1STAbits.UTXEN = 1; } else if (uart == 2) { U2MODE = 0; U2MODEbits.BRGH = 0; + U2BRG = brg; U2STA = 0; U2MODEbits.UARTEN = 1; U2STAbits.UTXEN = 1; - } - uart_set_rate(uart, 115200); -} - -void uart_set_rate(int uart, int32_t rate) -{ - int32_t brg; - - brg = ((FCY + (8 * rate - 1)) / (16 * rate)) - 1; - if (brg < 1) brg = 1; - if (brg > 65535) brg = 65535; - if (uart == 1) - U1BRG = brg; - else if (uart == 2) - U2BRG = brg; + } } void uart_put(int uart, uint8_t x) diff --git a/firmware/uart.h b/firmware/uart.h index 84a9495..e78830c 100644 --- a/firmware/uart.h +++ b/firmware/uart.h @@ -4,8 +4,7 @@ #include "config.h" /* Init */ -void uart_init(int uart); -void uart_set_rate(int uart, int32_t rate); +void uart_init(int uart, int32_t rate); /* Blocking sends */ void uart_put(int uart, uint8_t x); @@ -25,8 +24,7 @@ int uart_can_get(int uart); int uart_can_put(int uart); /* Helpers to work with a specific uart */ -#define uart1_init() uart_init(1) -#define uart1_set_rate(x) uart_set_rate(1,x) +#define uart1_init(x) uart_init(1, x) #define uart1_put(x) uart_put(1,x) #define uart1_put_string(x) uart_put_string(1,x) #define uart1_crlf() uart_crlf(1) @@ -36,8 +34,7 @@ int uart_can_put(int uart); #define uart1_put_bin(x) uart_put_bin(1,x) #define uart1_put_dec(x) uart_put_dec(1,x) -#define uart2_init() uart_init(2) -#define uart2_set_rate(x) uart_set_rate(2,x) +#define uart2_init(x) uart_init(2, x) #define uart2_put(x) uart_put(2,x) #define uart2_put_string(x) uart_put_string(2,x) #define uart2_crlf() uart_crlf(2) diff --git a/firmware/zoom.c b/firmware/zoom.c index e24c217..5f17111 100644 --- a/firmware/zoom.c +++ b/firmware/zoom.c @@ -2,16 +2,12 @@ #include "uart.h" #include - int main(void) { config_init(); - uart1_set_rate(115200); - uart1_init(); + uart1_init(115200); - while(1) { - uart1_put_string("--> "); - printf("hello, world\r\n"); + for(;;) { } return 0; } diff --git a/firmware/zoom.mcw b/firmware/zoom.mcw index 2736c10..2793d20 100644 Binary files a/firmware/zoom.mcw and b/firmware/zoom.mcw differ