Skip to content

Commit

Permalink
Start with a hardware test program.
Browse files Browse the repository at this point in the history
UART now has a proper header file.
  • Loading branch information
laneboysrc committed Mar 5, 2014
1 parent af2cab7 commit 92b2a77
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 11 deletions.
7 changes: 3 additions & 4 deletions firmware/hk310-filter/hk310-filter.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#include <pic16f1825.h>
#include <stdint.h>

#include "uart.h"


static __code uint16_t __at (_CONFIG1) configword1 = _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF;
static __code uint16_t __at (_CONFIG2) configword2 = _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _LVP_OFF;


extern void Init_UART(void);
extern uint8_t UART_read_byte(void);
extern void UART_send(uint8_t);

#define STATE_WAIT_FOR_SYNC 0
#define STATE_SYNC2 1
#define STATE_SYNC3 2
Expand Down
53 changes: 53 additions & 0 deletions firmware/hk310-filter/hw-test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <pic16f1825.h>
#include <stdint.h>

#include "uart.h"

static __code uint16_t __at (_CONFIG1) configword1 = _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF;
static __code uint16_t __at (_CONFIG2) configword2 = _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _LVP_OFF;


/*****************************************************************************
Init_hardware()
Initializes all used peripherals of the PIC chip.
****************************************************************************/
static void Init_hardware(void) {
//-----------------------------
// Clock initialization
OSCCON = 0b01111000; // 16MHz: 4x PLL disabled, 8 MHz HF, Clock determined by FOSC<2:0>

//-----------------------------
// IO Port initialization
PORTA = 0;
LATA = 0;
ANSELA = 0;
APFCON0 = 0b00000000; // Use RC4/RC5 for UART TX/RX; RA4 for T1G
APFCON1 = 0;
TRISA = 0b11111111; // Make all ports A input
TRISC = 0b11111111; // Make all ports C input

INTCON = 0;
}


/*****************************************************************************
main()
No introduction needed ...
****************************************************************************/
void main(void) {
Init_hardware();
Init_UART();

while (1) {
uint8_t b;

b = UART_read_byte();
UART_send(b);
}
}




9 changes: 8 additions & 1 deletion firmware/hk310-filter/makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.PHONY: all
all: hk310-filter
all: hk310-filter hw-test


#############################################################################
Expand All @@ -9,6 +9,13 @@ hk310-filter: hk310-filter.hex
hk310-filter.hex: hk310-filter.o uart.o
sdcc --opt-code-size --use-non-free -mpic14 -p16f1825 -o $@ $^

#############################################################################
.PHONY: hw-test
hw-test: hw-test.hex

hw-test.hex: hw-test.o uart.o
sdcc --opt-code-size --use-non-free -mpic14 -p16f1825 -o $@ $^


#############################################################################
.c.o:
Expand Down
10 changes: 4 additions & 6 deletions firmware/hk310-filter/uart.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#include <pic16f1825.h>
#include <stdint.h>

#define SPBRG_VALUE 208L // 19200 @ 16 MHz

#include "uart.h"

void UART_send(uint8_t);
void UART_send_uint(uint16_t);
void UART_send_uchar(uint8_t);
uint8_t UART_read_byte(void);
#define SPBRG_VALUE 208L // 19200 @ 16 MHz


/*****************************************************************************
Expand Down Expand Up @@ -138,6 +134,7 @@ void UART_send_uchar(uint8_t tx_uint) {
uint8_t UART_read_byte(void)
{
do {
#if 0
if (OERR) {
CREN = 0;
WREG = RCREG;
Expand All @@ -149,6 +146,7 @@ uint8_t UART_read_byte(void)
if (FERR) {
WREG = RCREG;
}
#endif
} while (!RCIF);

return RCREG;
Expand Down
10 changes: 10 additions & 0 deletions firmware/hk310-filter/uart.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef __UART_H
#define __UART_H

extern void Init_UART(void);
extern uint8_t UART_read_byte(void);
extern void UART_send(uint8_t);
extern void UART_send_uint(uint16_t);
extern void UART_send_uchar(uint8_t);

#endif /* __UART_H */

0 comments on commit 92b2a77

Please sign in to comment.